<template>
  <div class="page-body">
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-column-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-Rate="props">
          <q-td>
            {{props.row.Rate}}%
          </q-td>
        </template>
        <template v-slot:body-cell-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>
        <template v-slot:bottom>
          <q-pagination class="full-width justify-end" v-model="msg.pageIndex" color="primary" :max="pageCount"
            :input="true" @input="changePage" />
        </template>
      </q-table>
    </div>
    <flow-form v-if="isShowFlowForm" :save-obj="flowObj" @close="closeflowForm" @success="refreshPage">
    </flow-form>
  </div>
</template>
<script>
  import {
    GetStudentAdvisorConfigPage,
    RemoveStudentAdvisorConfig
  } from '../../api/system/index'
  import flowForm from '../../components/system/flow-form'
  export default {
    meta: {
      title: "跟进状态管理"
    },
    components: {
      flowForm
    },
    data() {
      return {
        columns: [{
            name: 'Name',
            label: '名称',
            field: 'Name',
            align: 'left'
          }, {
            name: 'Num',
            label: '排序',
            field: 'Num',
            align: 'left'
          }, {
            name: 'Rate',
            label: '胜率',
            field: 'Rate',
            align: 'left'
          },
          {
            name: 'CreateByName',
            label: '创建人',
            field: 'CreateByName',
            align: 'left'
          },
          {
            name: 'CreateTimeStr',
            label: '创建时间',
            field: 'CreateTimeStr',
            align: 'left'
          },
          {
            name: 'Id',
            label: '操作',
            field: 'Id'
          }
        ],
        dataList: [],
        loading: true,
        isShowFlowForm: false,
        flowObj: {},
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          Name: ""
        },
        pageCount: 0
      }
    },
    mounted() {
      this.getList()
    },
    methods: {
      deleteStage(Id) {
        let delMsg = {
          Id: Id
        };
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定该阶段？',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          RemoveStudentAdvisorConfig(delMsg).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '删除成功！',
                position: 'top'
              })
              this.getList();
            }
          })
        }).onCancel(() => {

        });
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      getList() {
        this.loading = true;
        GetStudentAdvisorConfigPage(this.msg).then(res => {
          this.loading = false;
          if (res.Code == 1) {
            this.dataList = res.Data.PageData;
            this.pageCount = res.Data.PageCount;
          }
        })
      },
      closeflowForm() {
        this.isShowFlowForm = false
      },
      refreshPage() {
        this.getList();
      },
      addObj(obj) {
        if (obj) {
          this.flowObj = obj
        } else {
          this.flowObj = null
        }
        this.isShowFlowForm = true;
      }
    },
  }
</script>

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