<template>
  <div class="page-body">
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
        <div class="col-3">
          <q-input @input="resetSearch" clearable standout="bg-primary text-white" class="col-6 q-pr-lg q-pr-lg"
            v-model="qMsg.Name" label="名称" maxlength="20" @clear="resetSearch" />
        </div>
        <div class="col-3">
          <q-select @input="resetSearch" clearable multiple standout="bg-primary text-white" option-value="SId"
            option-label="SName" v-model="qMsg.School_Ids" :options="schoolOptions" emit-value map-options label="校区"
            @clear="resetSearch" />
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :loading="loading" no-data-label="暂无相关数据" flat class="sticky-column-table" :pagination='qMsg'
        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" @click="addModule(null)" label="新增班次" />
          </div>
        </template>
        <template v-slot:bottom>
          <q-pagination class="full-width justify-end" v-model="qMsg.pageIndex" color="primary" :max="pageCount"
            :input="true" @input="changePage" />
        </template>
        <template v-slot:body-cell-optioned="props">
          <q-td :props="props" style="width:200px;">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" @click="addModule(props.row)"
              label="编辑" />
            <q-btn flat size="xs" icon="edit" color="negative" style="font-weight:400" @click="delClass(props.row.Id)"
              label="删除" />
          </q-td>
        </template>
      </q-table>
      <AddClassList v-if="isShowsetForm" @close="closeruleset" :save-obj="ruleObj" @success="refreshRule"
        :schoolOptions="schoolOptions">
      </AddClassList>
    </div>
  </div>
</template>
<script>
  import {
    qyeryDutyFrequencyPage,
    removeFrequency,
  } from '../../api/duty/index';
  import {
    getSchoolDropdown
  } from '../../api/school/index'; //获取校区列表
  import AddClassList from './addClassList';
  export default {
    components: {
      AddClassList
    },
    data() {
      return {
        loading: false,
        isShowsetForm: false,
        ruleObj: {}, //传入参数
        schoolOptions: [],
        columns: [{
            name: 'SchoolName',
            label: '学校名称',
            field: 'SchoolName',
            align: 'left'
          },
          {
            name: 'Name',
            label: '班次名称',
            field: 'Name',
            align: 'left',
          },
          {
            name: 'StartTime',
            label: '开始时间',
            field: 'StartTime',
            align: 'left',
          },
          {
            name: 'EndTime',
            label: '结束时间',
            field: 'EndTime',
            align: 'left',
          },
          {
            name: 'CreateByName',
            label: '创建人',
            field: 'CreateByName',
            align: 'left',
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'QuestionId'
          }
        ],
        qMsg: {
          pageIndex: 1,
          pageSize: 10,
          rowsPerPage: 10,
          Name: "",
          School_Ids: [],
        },
        pageCount: 0,
        dataList: [],
      }
    },
    created() {
      this.getCompanyList();
    },
    mounted() {
      this.getList();
    },
    methods: {
      //重新查询
      resetSearch() {
        this.qMsg.pageIndex = 1;
        this.getList();
      },
      //翻页
      changePage(val) {
        this.qMsg.pageIndex = val;
        this.getList();
      },
      //获取班次分页数据
      getList() {
        qyeryDutyFrequencyPage(this.qMsg).then(res => {
          if (res.Code == 1) {
            this.dataList = res.Data.PageData;
            this.pageCount = res.Data.PageCount;
          }
        })
      },
      //删除班次
      delClass(id) {
        let that = this
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定删除？',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          removeFrequency({
            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();
      },
      //1启用 2禁用 3删除
      getStart(item, type) {
        let msg = {
          RuleId: item.Id,
          Type: type
        }
        SetOKRRuleState(msg).then(res => {
          if (res.Code == 1) {
            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;
          }
        })
      },
    }
  }
</script>
<style lang="sass">
  @import url('~assets/css/table.sass')
</style>