<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="props">
          <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-Group_Id="props">
          <q-td :props="props">
            <div>
              <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="编辑"
                @click="addObj(props.row)" />
              <q-btn flat size="xs" icon="delete" color="negative" class="q-mr-xs" label="删除"
                @click="deleteStage(props.row.Id)" />
            </div>
          </q-td>
        </template>
      </q-table>
    </div>
    <stage-form v-if="isShowStageForm" :save-obj="stageObj" @close="closestageForm" @success="refreshPage">
    </stage-form>
  </div>
</template>

<script>
  import {
    GetStageList,
    RemoveStage
  } from '../../api/system/index'
  import stageForm from '../../components/system/stage-form'
  export default {
    meta: {
      title: "客户阶段管理"
    },
    components: {
      stageForm
    },
    data() {
      return {
        columns: [{
            name: 'Id',
            label: 'Id',
            field: row => row.Id,
            align: 'left'
          },{
            name: 'No',
            label: '编号',
            field: 'No',
            align: 'left'
          },{
            name: 'StageName',
            required: true,
            label: '阶段名称',
            align: 'left',
            field: row => row.StageName
          },{
            name: 'Group_Id',
            label: '操作',
            field: 'Group_Id'
          }
        ],
        msg:{
          rowsPerPage: 100
        },
        dataList: [],
        loading: true,
        isShowStageForm: false,
        stageObj: {}
      }
    },
    mounted() {
      this.getList()
    },
    methods: {
      deleteStage(Id) {
        let delMsg = {
          Id: Id
        };
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定该阶段？',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          RemoveStage(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;
        GetStageList({}).then(res => {
          this.loading = false;
          if(res.Code==1){
            this.dataList = res.Data;
          }
        })
      },
      closestageForm() {
        this.isShowStageForm = false
      },
      refreshPage(){
        this.getList();
      },
      addObj(obj){
        if (obj) {
          this.stageObj = obj
        } else {
          this.stageObj = null
        }
        this.isShowStageForm = true;
      }
    },
  }

</script>

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

</style>
