<template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <!-- <el-form-item label="工作日ID" prop="workdayId">
        <el-input
          v-model="queryParams.workdayId"
          placeholder="请输入工作日ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
        <el-form-item label="年份" prop="year">
          <el-select v-model="queryParams.year" placeholder="请选择年份" clearable>
            <el-option v-for="item in year_select" :key="item.value" :label="item.value"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="月份" prop="month">

          <el-select v-model="queryParams.month" placeholder="请选择月份" clearable>
            <el-option v-for="item in month_select" :key="item.value" :label="item.value"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <!-- <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
        </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"

        >修改</el-button> -->
      <!-- <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
            @click="handleDelete">删除</el-button>
        </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"

        >导出</el-button>
      </el-col> -->

      <ele-pro-table ref="tableRef" :columns="columns" :datasource="scheduleList" row-key="id"
       @columns-change="handleColumnChange"
        :cacheKey="cacheKeyUrl"
        @selection-change="handleSelectionChange">
        <template v-slot:toolbar>
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
            @click="handleDelete">删除</el-button>
        </template>
        <template v-slot:day01="{ row }">
          <el-switch v-model="row.day01" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 1)"></el-switch>
        </template>
        <template v-slot:day02="{ row }">
          <el-switch v-model="row.day02" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 2)"></el-switch>
        </template>
        <template v-slot:day03="{ row }">
          <el-switch v-model="row.day03" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 3)"></el-switch>
        </template>
        <template v-slot:day04="{ row }">
          <el-switch v-model="row.day04" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 4)"></el-switch>
        </template>
        <template v-slot:day05="{ row }">
          <el-switch v-model="row.day05" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 5)"></el-switch>
        </template>
        <template v-slot:day06="{ row }">
          <el-switch v-model="row.day06" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 6)"></el-switch>
        </template>
        <template v-slot:day07="{ row }">
          <el-switch v-model="row.day07" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 7)"></el-switch>
        </template>
        <template v-slot:day08="{ row }">
          <el-switch v-model="row.day08" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 8)"></el-switch>
        </template>
        <template v-slot:day09="{ row }">
          <el-switch v-model="row.day09" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 9)"></el-switch>
        </template>
        <template v-slot:day10="{ row }">
          <el-switch v-model="row.day10" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 10)"></el-switch>
        </template>
        <template v-slot:day11="{ row }">
          <el-switch v-model="row.day11" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 11)"></el-switch>
        </template>
        <template v-slot:day12="{ row }">
          <el-switch v-model="row.day12" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 12)"></el-switch>
        </template>
        <template v-slot:day13="{ row }">
          <el-switch v-model="row.day13" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 13)"></el-switch>
        </template>
        <template v-slot:day14="{ row }">
          <el-switch v-model="row.day14" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 14)"></el-switch>
        </template>
        <template v-slot:day15="{ row }">
          <el-switch v-model="row.day15" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 15)"></el-switch>
        </template>
        <template v-slot:day16="{ row }">
          <el-switch v-model="row.day16" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 16)"></el-switch>
        </template>
        <template v-slot:day17="{ row }">
          <el-switch v-model="row.day17" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 17)"></el-switch>
        </template>
        <template v-slot:day18="{ row }">
          <el-switch v-model="row.day18" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 18)"></el-switch>
        </template>
        <template v-slot:day19="{ row }">
          <el-switch v-model="row.day19" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 19)"></el-switch>
        </template>
        <template v-slot:day20="{ row }">
          <el-switch v-model="row.day20" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 20)"></el-switch>
        </template>
        <template v-slot:day21="{ row }">
          <el-switch v-model="row.day21" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 21)"></el-switch>
        </template>
        <template v-slot:day22="{ row }">
          <el-switch v-model="row.day22" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 22)"></el-switch>
        </template>
        <template v-slot:day23="{ row }">
          <el-switch v-model="row.day23" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 23)"></el-switch>
        </template>
        <template v-slot:day24="{ row }">
          <el-switch v-model="row.day24" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 24)"></el-switch>
        </template>
        <template v-slot:day25="{ row }">
          <el-switch v-model="row.day25" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 25)"></el-switch>
        </template>
        <template v-slot:day26="{ row }">
          <el-switch v-model="row.day26" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 26)"></el-switch>
        </template>
        <template v-slot:day27="{ row }">
          <el-switch v-model="row.day27" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 27)"></el-switch>
        </template>
        <template v-slot:day28="{ row }">
          <el-switch v-model="row.day28" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 28)"></el-switch>
        </template>
        <template v-slot:day29="{ row }">
          <el-switch v-model="row.day29" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 29)"></el-switch>
        </template>
        <template v-slot:day30="{ row }">
          <el-switch v-model="row.day30" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 30)"></el-switch>
        </template>
        <template v-slot:day31="{ row }">
          <el-switch v-model="row.day31" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(row, 31)"></el-switch>
        </template>
        <template v-slot:action="{ row }">
          <el-popconfirm class="ele-action" title='是否确认删除此数据？' @confirm="handleDelete(row)">
            <template v-slot:reference>
              <el-link type="danger" :underline="false" icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>



      <!-- 添加或修改APS月度班制排班对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="75%" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-row>
            <el-col :span="8">

              <!-- <el-form-item label="工作日ID" prop="workdayId">
              <el-input v-model="form.workdayId" placeholder="请输入工作日ID" />
            </el-form-item> -->
            </el-col>
            <el-col :span="8">
              <!-- <el-form-item label="年份" prop="year">
            <el-input v-model="form.year" placeholder="请输入年份" />
            </el-form-item> -->
              <el-form-item label="年份" prop="year">
                <el-select v-model="form.year" placeholder="请选择年份">
                  <el-option v-for="item in year_select" :key="item.value" :label="item.value"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>

            </el-col>

            <el-col :span="8">
              <!-- <el-form-item label="月份" prop="month">
            <el-input v-model="form.month" placeholder="请输入月份" />
            </el-form-item> -->
              <el-form-item label="月份" prop="month">

                <el-select v-model="form.month" placeholder="请选择月份">
                  <el-option v-for="item in month_select" :key="item.value" :label="item.value"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第1日是否工作" prop="day01">
                <el-radio-group v-model="form.day01">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第2日是否工作" prop="day02">
                <el-radio-group v-model="form.day02">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第3日是否工作" prop="day03">
                <el-radio-group v-model="form.day03">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第4日是否工作" prop="day04">
                <el-radio-group v-model="form.day04">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第5日是否工作" prop="day05">
                <el-radio-group v-model="form.day05">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第6日是否工作" prop="day06">
                <el-radio-group v-model="form.day06">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第7日是否工作" prop="day07">
                <el-radio-group v-model="form.day07">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第8日是否工作" prop="day08">
                <el-radio-group v-model="form.day08">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第9日是否工作" prop="day09">
                <el-radio-group v-model="form.day09">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第10日是否工作" prop="day10">
                <el-radio-group v-model="form.day10">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第11日是否工作" prop="day11">
                <el-radio-group v-model="form.day11">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第12日是否工作" prop="day12">
                <el-radio-group v-model="form.day12">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第13日是否工作" prop="day13">
                <el-radio-group v-model="form.day13">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第14日是否工作" prop="day14">
                <el-radio-group v-model="form.day14">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第15日是否工作" prop="day15">
                <el-radio-group v-model="form.day15">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第16日是否工作" prop="day16">
                <el-radio-group v-model="form.day16">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第17日是否工作" prop="day17">
                <el-radio-group v-model="form.day17">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第18日是否工作" prop="day18">
                <el-radio-group v-model="form.day18">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第19日是否工作" prop="day19">
                <el-radio-group v-model="form.day19">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第20日是否工作" prop="day20">
                <el-radio-group v-model="form.day20">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第21日是否工作" prop="day21">
                <el-radio-group v-model="form.day21">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第22日是否工作" prop="day22">
                <el-radio-group v-model="form.day22">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第23日是否工作" prop="day23">
                <el-radio-group v-model="form.day23">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第24日是否工作" prop="day24">
                <el-radio-group v-model="form.day24">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第25日是否工作" prop="day25">
                <el-radio-group v-model="form.day25">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第26日是否工作" prop="day26">
                <el-radio-group v-model="form.day26">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第27日是否工作" prop="day27">
                <el-radio-group v-model="form.day27">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第28日是否工作" prop="day28">
                <el-radio-group v-model="form.day28">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第29日是否工作" prop="day29">
                <el-radio-group v-model="form.day29">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第30日是否工作" prop="day30">
                <el-radio-group v-model="form.day30">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="第31日是否工作" prop="day31">
                <el-radio-group v-model="form.day31">
                  <el-radio v-for="dict in workday_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import { listSchedule, getSchedule, delSchedule, addSchedule, updateSchedule } from "@/api/aps_workday_schedule/schedule";
import tabMixins from '@/mixins/tableColumnsMixin';

export default {
  mixins: [ tabMixins],

  name: "Schedule",
  // dicts: ['workday_status','year_select','month_select'],
  data() {
    return {
      cacheKeyUrl: 'c32a9c7d-aps-workday_schedule-index',
      workday_status: [{ "label": "工作", "value": "1" }, { "label": "休息", "value": "0" },],
      year_select: [
        { "value": 2025 }, { "value": 2026 }, { "value": 2027 }, { "value": 2028 }
      ],
      month_select: [
        { "value": 1 }, { "value": 2 }, { "value": 3 }, { "value": 4 },
        { "value": 5 }, { "value": 6 }, { "value": 7 }, { "value": 8 },
        { "value": 9 }, { "value": 10 }, { "value": 11 }, { "value": 12 },
      ],
      isAdd: 1,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // APS月度班制排班表格数据
      scheduleList: [],
      //年份选择列表
      yearOptions: [],
      //月份选择列表
      monthOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // workdayId: null,
        year: null,
        month: null,

        workdayCount: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // workdayId: [
        //   { required: true, message: "工作日ID不能为空", trigger: "blur" }
        // ],
        year: [
          { required: true, message: "年份不能为空", trigger: "blur" }
        ],
        month: [
          { required: true, message: "月份不能为空", trigger: "blur" }
        ],
      },
      columns: [
        {
          width: 45,
          type: 'selection',
          columnKey: 'selection',
          align: 'center',
          reserveSelection: true
        },
        {
          columnKey: 'index',
          label: '序号',
          type: 'index',
          width: 55,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'year',
          label: '年份',
          showOverflowTooltip: true,
          align: 'center',
          width: 120,
          fixed: 'left'
        },
        {
          prop: 'month',
          label: '月份',
          showOverflowTooltip: true,
          align: 'center',
          width: 100,
          fixed: 'left'
        },
        {
          prop: 'day01',
          label: '第1日是否工作',
          align: 'center',
          slot: 'day01',
          width: 120,
        },
        {
          prop: 'day02',
          label: '第2日是否工作',
          align: 'center',
          slot: 'day02',
          width: 120,
        },
        {
          prop: 'day03',
          label: '第3日是否工作',
          align: 'center',
          slot: 'day03',
          width: 120,
        },
        {
          prop: 'day04',
          label: '第4日是否工作',
          align: 'center',
          slot: 'day04',
          width: 120,
        },
        {
          prop: 'day05',
          label: '第5日是否工作',
          align: 'center',
          slot: 'day05',
          width: 120,
        },
        {
          prop: 'day06',
          label: '第6日是否工作',
          align: 'center',
          slot: 'day06',
          width: 120,
        },
        {
          prop: 'day07',
          label: '第7日是否工作',
          align: 'center',
          slot: 'day07',
          width: 120,
        },
        {
          prop: 'day08',
          label: '第8日是否工作',
          align: 'center',
          slot: 'day08',
          width: 120,
        },
        {
          prop: 'day09',
          label: '第9日是否工作',
          align: 'center',
          slot: 'day09',
          width: 120,
        },
        {
          prop: 'day10',
          label: '第10日是否工作',
          align: 'center',
          slot: 'day10',
          width: 120,
        },
        {
          prop: 'day11',
          label: '第11日是否工作',
          align: 'center',
          slot: 'day11',
          width: 120,
        },
        {
          prop: 'day12',
          label: '第12日是否工作',
          align: 'center',
          slot: 'day12',
          width: 130,
        },
        {
          prop: 'day13',
          label: '第13日是否工作',
          align: 'center',
          slot: 'day13',
          width: 130,
        },
        {
          prop: 'day14',
          label: '第14日是否工作',
          align: 'center',
          slot: 'day14',
          width: 130,
        },
        {
          prop: 'day15',
          label: '第15日是否工作',
          align: 'center',
          slot: 'day15',
          width: 130,
        },
        {
          prop: 'day16',
          label: '第16日是否工作',
          align: 'center',
          slot: 'day16',
          width: 130,
        },
        {
          prop: 'day17',
          label: '第17日是否工作',
          align: 'center',
          slot: 'day17',
          width: 130,
        },
        {
          prop: 'day18',
          label: '第18日是否工作',
          align: 'center',
          slot: 'day18',
          width: 130,
        },
        {
          prop: 'day19',
          label: '第19日是否工作',
          align: 'center',
          slot: 'day19',
          width: 130,
        },
        {
          prop: 'day20',
          label: '第20日是否工作',
          align: 'center',
          slot: 'day20',
          width: 130,
        },
        {
          prop: 'day21',
          label: '第21日是否工作',
          align: 'center',
          slot: 'day21',
          width: 130,
        },
        {
          prop: 'day22',
          label: '第22日是否工作',
          align: 'center',
          slot: 'day22',
          width: 130,
        },
        {
          prop: 'day23',
          label: '第23日是否工作',
          align: 'center',
          slot: 'day23',
          width: 130,
        },
        {
          prop: 'day24',
          label: '第24日是否工作',
          align: 'center',
          slot: 'day24',
          width: 130,
        },
        {
          prop: 'day25',
          label: '第25日是否工作',
          align: 'center',
          slot: 'day25',
          width: 130,
        },
        {
          prop: 'day26',
          label: '第26日是否工作',
          align: 'center',
          slot: 'day26',
          width: 130,
        },
        {
          prop: 'day27',
          label: '第27日是否工作',
          align: 'center',
          slot: 'day27',
          width: 130,
        },
        {
          prop: 'day28',
          label: '第28日是否工作',
          align: 'center',
          slot: 'day28',
          width: 130,
        },
        {
          prop: 'day29',
          label: '第29日是否工作',
          align: 'center',
          slot: 'day29',
          width: 130,
        },
        {
          prop: 'day30',
          label: '第30日是否工作',
          align: 'center',
          slot: 'day30',
          width: 130,
        },
        {
          prop: 'day31',
          label: '第31日是否工作',
          align: 'center',
          slot: 'day31',
          width: 130,
        },
        {
          prop: 'workdayCount',
          label: '当月工作日总数',
          align: 'center',
          fixed: 'right',
          width: 130,
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 150,
          align: 'center',
          resizable: false,
          slot: 'action',
          fixed: 'right'
        }
      ]

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询APS月度班制排班列表 */
    getList() {
      this.loading = true;
      listSchedule(this.queryParams).then(response => {
        this.scheduleList = response.data;
        // this.scheduleList.forEach(item=>{

        // })
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sequenceId: null,
        // workdayId: null,
        year: null,
        month: null,
        day01: 1,
        day02: 1,
        day03: 1,
        day04: 1,
        day05: 1,
        day06: 1,
        day07: 1,
        day08: 1,
        day09: 1,
        day10: 1,
        day11: 1,
        day12: 1,
        day13: 1,
        day14: 1,
        day15: 1,
        day16: 1,
        day17: 1,
        day18: 1,
        day19: 1,
        day20: 1,
        day21: 1,
        day22: 1,
        day23: 1,
        day24: 1,
        day25: 1,
        day26: 1,
        day27: 1,
        day28: 1,
        day29: 1,
        day30: 1,
        day31: 1,
        workdayCount: null
      };

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.year=null;
      this.queryParams.month=null;
      // this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sequenceId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.isAdd = 1;
      this.open = true;
      this.title = "添加APS月度班制排班";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.isAdd = 0;
      const sequenceId = row.sequenceId || this.ids
      getSchedule(sequenceId).then(response => {
        let obj = response.data.data;
        this.form = obj;
        this.open = true;
        this.title = "修改APS月度班制排班";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sequenceId != null) {
            delete this.form.workdayCount;
            updateSchedule(this.form).then(response => {
              this.$message.success("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSchedule(this.form).then(response => {
              this.$message.success("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sequenceIds = row.sequenceId || this.ids;
      this.$confirm('是否确认删除APS月度班制排班编号为"' + sequenceIds + '"的数据项？').then(function () {
        return delSchedule(sequenceIds);
      }).then(() => {
        this.getList();
        this.$message.success("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      // this.download('aps_workday_schedule/schedule/export', {
      //   ...this.queryParams
      // }, `schedule_${new Date().getTime()}.xlsx`)
    },
    // 用户状态修改
    handleStatusChange(row, index) {
      const dayKey = 'day' + (index > 9 ? index : '0' + index);
      const newStatus = row[dayKey] === 0 ? 0 : 1;
      row[dayKey] = newStatus;
      const text = newStatus === 0 ? "休息" : "正常";
      this.$confirm(`确认要将第 ${index} 天设为 "${text}" 状态吗？`)
        .then(() => {
          const node = {
            sequenceId: row.sequenceId,
            [dayKey]: newStatus,
          };
          return updateSchedule(node);
        })
        .then(() => {
          this.$message.success(text + "成功");
          this.getList();
        })
        .catch(() => {
          row[dayKey] = newStatus == 0 ? 1 : 0;
        });
    }

  }
};
</script>
