<style lang="scss" scoped>
  .chooseSchool {
    width: 160px;
    color: #FFF;
    border-radius: 3px;
    overflow: hidden;
  }

</style>


<template>
  <div class="page-body">
    <div class="page-content">
      <q-table :loading="loading" no-data-label="暂无相关数据" flat class="sticky-column-table" :pagination='pagination'
        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" style="display:flex">
            <q-btn color="accent" size="sm" class="q-mr-md" @click="addModule(null)" label="新增" />
            <q-select dense filled v-model="School_Id" label-color="grey-11" clearable bg-color="primary" emit-value
              map-options :options="schoolOptions" label="选择校区" option-label="SName" option-value="SId"
              class="chooseSchool" @input="changeSchool">
            </q-select>
          </div>
        </template>
        <template v-slot:bottom>
        </template>
        <template v-slot:body-cell-optioned="props">
          <q-td :props="props" style="width:200px;">
            <q-btn flat size="xs" icon="edit" color="negative" style="font-weight:400" @click="delSet(props.row.Id)"
              label="删除" />
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" @click="addModule(props.row)"
              label="编辑" />
            </q-btn>
          </q-td>
        </template>
      </q-table>
      <AddDutySet v-if="isShowsetForm" @close="closeruleset" :save-obj="ruleObj" @success="refreshRule"
        :frequencyOptions="frequencyOptions" :schoolOptions="schoolOptions" :EmployeeListOption="EmployeeListOption">
      </AddDutySet>
    </div>
  </div>
</template>
<script>
  import {
    getDutyConfigList,
    getDutyFrequencyList,
    removeDutyConfig
  } from '../../api/duty/index';
  import {
    getSchoolDropdown
  } from '../../api/school/index'; //获取校区列表
  import {
    queryEmployee
  } from '../../api/users/user'; //获取业务员
  import AddDutySet from './addDutySet';
  export default {
    components: {
      AddDutySet
    },
    data() {
      return {
        School_Id: "",
        loading: false,
        isShowsetForm: false,
        ruleObj: {}, //传入参数
        pagination: {
          rowsPerPage: 0
        },
        schoolOptions: [],
        frequencyOptions: [],
        EmployeeListOption: [],
        columns: [{
            name: 'EmployeeName',
            label: '值班管理员：',
            field: 'EmployeeName',
            align: 'left'
          },
          {
            name: 'MachineCode',
            label: '值班机器码：',
            field: 'MachineCode',
            align: 'left',
          },
          {
            name: 'ShiftsName',
            label: '班次：',
            field: 'ShiftsName',
            align: 'left',
          },
          {
            name: 'SchoolName',
            label: '校区',
            field: 'SchoolName',
            align: 'left',
          },
          {
            name: 'SendName',
            label: '抄送人员',
            field: 'SendName',
            align: 'left',
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'Id'
          }
        ],
        dataList: [],
      }
    },
    mounted() {
      this.getList();
      this.getCompanyList();
      this.getDutyFrequencyList();
      this.getEmployee(0);
    },
    methods: {
      //获取数据
      getList() {
        getDutyConfigList({
          School_Id: this.School_Id
        }).then(res => {
          if (res.Code == 1) {
            this.dataList = res.Data;
          }
        })
      },
      //删除班次
      delSet(id) {
        let that = this
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定删除？',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          removeDutyConfig({
            Id: id.toString()
          }).then((res) => {
            that.$q.notify({
              icon: 'iconfont icon-chenggong',
              timeout: 2000,
              message: res.Message,
              position: 'top'
            })
            that.getList()
          })
        }).onCancel(() => {});
      },
      //关闭弹窗
      closeruleset() {
        this.isShowsetForm = false;
      },
      //刷新列表
      refreshRule() {
        this.getList();
      },
      //新增
      addModule(obj) {
        if (obj) {
          this.ruleObj = obj
        } else {
          this.ruleObj = null
        }
        this.isShowsetForm = true
      },
      //获取校区列表
      getCompanyList() {
        getSchoolDropdown({}).then(res => {
          if (res.Code == 1) {
            this.schoolOptions = res.Data;
          }
        })
      },
      //获取班次列表
      getDutyFrequencyList() {
        getDutyFrequencyList({}).then(res => {
          if (res.Code == 1) {
            this.frequencyOptions = res.Data;
          }
        })
      },
      changeSchool() {
        this.getList();
      },
      //获取业务员
      getEmployee(id) {
        var qMsg = {
          Dept_Id: 0
        }
        qMsg.Dept_Id = id;
        queryEmployee(qMsg).then(res => {
          if (res.Code == 1) {
            this.EmployeeListOption = res.Data;
          }
        }).catch(() => {})
      },
    }
  }

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

</style>
