<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-select @input="resetSearch" standout="bg-primary text-white" v-model="msg.DayType" :options="typeOpts"
            option-value="value" option-label="label" label="节假日类型" emit-value map-options />
        </div>
        <div class="col-3 Sysuser_Date">
          <q-field filled>
             <template v-slot:control>
              <el-date-picker v-model="dateList" @change="resetSearch()" value-format="yyyy-MM-dd" type="daterange" style="border:none;"
                 range-separator="至"  start-placeholder="开始日期"  end-placeholder="结束日期">
                 </el-date-picker>       
            </template>
          </q-field>
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-column-table"
        separator="none" :data="data" :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" icon="add" label="新增计划" @click="EditPlan(null)" />
          </div>
        </template>
        <!-- <template v-slot:body-cell-time="props">
          <q-td :props="props">
              {{props.row.StartTime}}/{{props.row.EndTime}}
          </q-td>
        </template> -->
        <template v-slot:body-cell-type="props">
          <q-td :props="props">
            <span v-if="props.row.DayType===1">节假日</span>
            <span v-if="props.row.DayType===2">工作日</span>
          </q-td>
        </template>
        <template v-slot:body-cell-optioned="props">
          <q-td :props="props">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-family:perfectFont" label="编辑"
              @click="EditPlan(props.row)" />
            <q-btn flat size="xs" icon="delete" color="accent" style="font-family:perfectFont" label="删除"
              @click="delHolidayPlan(props.row)" />
          </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>
      <VacationPlanForm v-if="isShowSchoolForm" :save-obj="objOption" @close="closeSchoolForm" @success="resetSearch">
      </VacationPlanForm>
    </div>
  </div>
</template>

<script>
  import {
    getHolidayPlanList,
    delHolidayPlan
  } from '../../api/scheduling/schedu'
  import VacationPlanForm from '../../components/schedul/vacationPlan-form'
  export default {
    meta: {
      title: "节假日计划表"
    },
    components: {
      VacationPlanForm
    },
    data() {
      return {
        columns: [{
            name: 'HolidayId',
            label: '编号',
            field: 'HolidayId',
            align: 'left',
          },

          {
            name: 'StartTime',
            label: '开始时间',
            align: 'left',
            field: 'StartTime'
          },
          {
            name: 'EndTime',
            label: '结束时间',
            align: 'left',
            field: 'EndTime'
          },
          {
            name: 'type',
            label: '计划类型',
            align: 'left',
            field: ''
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'SId'
          },
        ],
        data: [],
        loading: true,
        typeOpts: [{
            label: '不限',
            value: 0
          },
          {
            label: '节假日',
            value: 1
          },
          {
            label: '工作日',
            value: 2
          }
        ],
        dateList: [],
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          DayType: 0, //类型
          StartTime: "", //开始时间
          EndTime: "", //结束时间
        },
        pageCount: 0,
        objOption: {
          DayType: 0, //类型
          StartTime: "", //开始时间
          EndTime: "", //结束时间
        },
        isShowSchoolForm: false, //是否显示校区弹窗
      }
    },
    created() {

    },
    mounted() {
      this.getList()

    },
    methods: {
      getList() {
        this.msg.StartTime = this.dateList[0]
        this.msg.EndTime = this.dateList[1]
        this.loading = true
        getHolidayPlanList(this.msg).then(res => {
          this.loading = false
          console.log(185, res)
          if (res.Code === 1) {
            this.data = res.Data.PageData
            this.pageCount = res.Data.PageCount
          }
        }).catch(err => {
          this.loading = false
        })
      },

      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getList();
      },
      //分页改变
      changePage(val) {
        this.msg.pageIndex = val;
        this.getList()
      },

      //关闭校区弹窗
      closeSchoolForm() {
        this.isShowSchoolForm = false;
      },
      //新增、修改校区
      EditPlan(obj) {
        if (obj) {
          this.objOption = obj;
        } else {
          this.objOption = null;
        }
        this.isShowSchoolForm = true;
      },
      //删除计划
      delHolidayPlan(item){
        let that=this
        this.$q.dialog({
          title: '删除确认',
          message: '删除且无法恢复，你确定要删除吗',
          cancel: {
            label: "取消",
            flat: true
          },
          ok: {
            label: "确认",
            flat: true,
            focus: true,
            color: "negative"
          }
        }).onOk(() => {
            delHolidayPlan({HolidayId:item.HolidayId}).then(res=>{
              console.log(res)
              if(res.Code===1){
                this.$message.success("操作成功")
                that.resetSearch()
              }
            })
        })
      
      }
    }
  }

</script>

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

</style>
<style>
  .Sysuser_Date .el-range-editor .el-range-input {
    background-color: transparent;
    width: 100%;
    border: none;
  }

  .Sysuser_Date .el-range-editor.el-input__inner {
    background-color: transparent;
    width: 100%;
    border: none;
  }

  .el-date-range-picker {
    z-index:9999 !important;
  }

</style>
