<template>
  <div class="page-body">
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat
        class="sticky-column-table no-bottom-table" separator="none" :data="dataList" :columns="columns" row-key="name">
        <template v-slot:top>
          <div class="col-2 q-table__title">意向度</div>
          <q-space />
          <div class="page-option">
            <q-btn color="accent" size="sm" class="q-mr-md" icon="add" label="新增阶段" @click="addObj(null)" />
          </div>
        </template>
        <template v-slot:body-cell-ConfigType="props">
          <q-td :props="props">
            <div>
              <q-btn flat icon="edit" color="accent" style="font-weight:400" label="编辑" @click="addObj(props.row)" />
              <q-btn flat icon="delete" color="negative" class="q-mr-xs" label="删除" @click="deletePurpose(props.row)" />
            </div>
          </q-td>
        </template>
      </q-table>
    </div>
    <stuconfig-form v-if="isShowStuConfigForm" :save-obj="stuConfigObj" @close="closeForm" @success="refreshPage">
    </stuconfig-form>
  </div>
</template>
<script>
  import {
    getStuPurposeList,
    removeStuPurpose,
  } from '../../api/system/index'
  import stuconfigForm from '../../components/system/stuconfig-form'
  export default {
    meta: {
      title: "意向度"
    },
    components: {
      stuconfigForm
    },
    data() {
      return {
        columns: [{
            name: '编号',
            label: 'Id',
            field: row => row.Id,
            align: 'left'
          }, {
            name: 'ConfigName',
            required: true,
            label: '名称',
            align: 'left',
            field: row => row.ConfigName
          },
          {
            name: 'SortNum',
            required: true,
            label: '排序',
            align: 'left',
            field: row => row.SortNum
          },
          {
            name: 'ConfigType',
            label: '操作',
            field: 'ConfigType'
          }
        ],
        msg: {
          rowsPerPage: 100
        },
        dataList: [],
        loading: true,
        isShowStuConfigForm: false,
        stuConfigObj: {}
      }
    },
    mounted() {
      this.getList()
    },
    methods: {
      deletePurpose(item) {
        let delMsg = {
          Id: item.Id
        };
        let tipMsg = `是否删除【` + item.ConfigName + `】？`
        this.$q.dialog({
          title: '提示信息',
          message: tipMsg,
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          removeStuPurpose(delMsg).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '删除成功！',
                position: 'top'
              })
              this.getList();
            }
          })
        }).onCancel(() => {

        });
      },
      getList() {
        this.loading = true;
        getStuPurposeList({
          ConfigType: 1
        }).then(res => {
          this.loading = false;
          if (res.Code == 1) {
            this.dataList = res.Data;
          }
        })
      },
      closeForm() {
        this.isShowStuConfigForm = false
      },
      refreshPage() {
        this.getList();
      },
      addObj(obj) {
        if (obj) {
          this.stuConfigObj = obj
        } else {
          this.stuConfigObj = null
        }
        this.isShowStuConfigForm = true;
      }
    },
  }

</script>

<style lang="sass">
  @import url('~assets/css/table.sass')

</style>
