<template>
  <div>
    <div style="margin-top: 15px" class="app-container">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="58px"
      >
        <el-form-item label="月份" prop="month">
          <el-date-picker
            clearable
            @change="changeTime"
            v-model="queryParams.month"
            type="month"
            value-format="YYYY-MM"
            placeholder="请选择月份"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="handleQuery"
            ><el-icon><Search /></el-icon>查询</el-button
          >
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="0.5">
          <!-- <el-button
          type="primary"
          plain
          icon="Refresh"
          size="mini"
          @click="lastAutomaticallyDutyHandler()"
          >根据上月排班
        </el-button> -->
          <el-button
            type="primary"
            v-hasPermi="['duty:data:create']"
            plain
            icon="List"
            size="mini"
            @click="ArrangeDuty()"
            >安排值班
          </el-button>
        </el-col>
        <!--      <el-col :span="0.5">
              <el-button
                @click="generateDuty"
                type="success"
                style="float: left"
                plain
                icon="Tickets"
                size="mini"
                >生成值班</el-button
              >
            </el-col>-->
        <el-col :span="0.5">
          <el-button
            @click="scheduling"
            type="primary"
            style="float: left"
            plain
            icon="Checked"
            size="mini"
            v-hasPermi="['system:rules:query']"
            >值班规则</el-button
          >
        </el-col>
        <el-col :span="0.5">
          <el-button
            type="warning"
            style="float: left"
            plain
            size="mini"
            icon="UploadFilled"
            @click="handleExport"
            v-hasPermi="['duty:duty:export']"
            >导出</el-button
          ></el-col
        >
        <!-- <el-col :span="0.5">
        <el-button
          @click="dutyAdjust"
          type="primary"
          style="float: left"
          plain
          icon="Plus"
          size="mini"
          >调班规则</el-button
        >
      </el-col> -->

        <right-toolbar
          style="margin-right: 30px"
          :showSearch="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table style="margin: 0 10px; height: 67.2vh" :data="dutyList">
        <el-table-column
          width="150"
          label="日期"
          align="center"
          prop="dutyDate"
        >
          <template #default="scope">
            <span>{{ parseTime(scope.row.dutyDate, "{y}年{m}月{d}日") }}</span>
          </template>
        </el-table-column>
        <el-table-column width="100" label="星期" align="center" prop="week" />
        <el-table-column label="白天" align="center" prop="dutyDay" />
        <el-table-column label="夜晚" align="center" prop="dutyNight" />
        <el-table-column label="应急值班" align="center" prop="dutyEmergency" />
        <el-table-column label="带班干部" align="center" prop="dutyLeader" />
        <el-table-column label="值班司机" align="center" prop="dutyDriver" />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template #default="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['duty:duty:edit']"
              ><el-icon><Edit /></el-icon>编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <el-dialog
        title="编辑值班人员"
        v-model="open"
        width="70%"
        style="height: 650px"
        append-to-body
      >
        <el-form ref="form" :model="form" :rules="rules" label-width="50px">
          <div style="display: flex">
            <el-form-item prop="month">
              <div style="font-size: 15px">月份： {{ form.month }}</div>
            </el-form-item>
            <el-form-item prop="dutyDate">
              <div style="font-size: 15px; margin: 0 20px">
                日期： {{ form.dutyDate }}
              </div>
            </el-form-item>
            <el-form-item prop="week">
              <div style="font-size: 15px">星期：{{ form.week }}</div>
            </el-form-item>
          </div>

          <el-divider content-position="center">值班人员信息</el-divider>

          <el-table
            style="margin-top: 30px"
            :data="duty_status"
            :row-class-name="rowYDutyPersonIndex"
            @selection-change="handleYDutyPersonSelectionChange"
            ref="yDutyPerson"
          >
            <el-table-column label="值班类型" align="center" prop="label">
            </el-table-column>
            <el-table-column
              label="值班人员"
              width="500"
              prop="nickName"
              align="center"
            >
            </el-table-column>
            <el-table-column align="center" label="操作">
              <!-- v-if="
                  scope.row.value != 0 &&
                  scope.row.value != 1 &&
                  scope.row.value != 3
                " -->
              <template #default="scope">
                <el-button
                  @click="select(scope.row, true)"
                  size="mini"
                  type="primary"
                  >选择</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-form>
        <div style="margin-left: 55vw; margin-top: 50px" class="dialog-footer">
          <el-button @click="cancel">取 消</el-button>

          <el-button type="primary" @click="submitForm">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog
        title="编辑调班规则"
        v-model="openAdjust"
        width="70%"
        style="height: 700px"
        append-to-body
      >
        <el-form
          ref="form"
          :model="adjustForm"
          :rules="rules"
          label-width="50px"
        >
          <el-divider content-position="center">调班人员信息</el-divider>

          <el-table
            style="margin-top: 30px"
            :data="duty_adjust"
            :row-class-name="rowYDutyPersonIndex"
            @selection-change="handleYDutyPersonSelectionChange"
            ref="yDutyPerson"
          >
            <el-table-column label="id" align="center" v-if="false" prop="id" />
            <el-table-column
              label="userId"
              align="center"
              v-if="false"
              prop="userId"
            />
            <el-table-column label="调班时间" align="center" prop="week">
            </el-table-column>
            <el-table-column
              label="调班人员"
              width="700"
              prop="name"
              align="center"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column align="center" label="操作">
              <template #default="scope">
                <el-button
                  v-if="scope.row.value != 0 && scope.row.value != 1"
                  @click="select(scope.row, false)"
                  size="mini"
                  type="primary"
                  >选择</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-form>
        <div style="margin-left: 55vw; margin-top: 40px" class="dialog-footer">
          <el-button @click="cancel">取 消</el-button>

          <el-button type="primary" @click="adjustSubmitForm">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="选择值班人员" v-model="dialogVisible" width="1000px">
        <el-row :gutter="20">
          <el-col style="overflow-x: scroll" :span="6">
            <div style="display: flex">
              <div
                style="font-size: 17px; margin-left: 10px; margin-bottom: 10px"
              >
                所属部门
              </div>
            </div>

            <div class="head-container">
              <el-tree
                style="font-size: 15px; width: 235px"
                :data="deptOptions"
                :props="{ label: 'label', children: 'children' }"
                :expand-on-click-node="false"
                :filter-node-method="filterNode"
                ref="dept"
                node-key="id"
                highlight-current
                default-expand-all
                @node-click="handleNodeClick"
                :current-node-key="currentNodeKey"
                :default-expanded-keys="expandedKeys"
              />
            </div>
          </el-col>
          <el-col style="margin-left: 10px; margin-top: 32px" :span="16">
            <!-- 联系人列表 -->
            <el-form
              :model="queryParams3"
              ref="queryForm"
              :inline="true"
              v-show="showSearch"
              label-width="68px"
            >
              <el-form-item label="用户昵称" prop="nickName">
                <el-input
                  v-model="queryParams3.nickName"
                  placeholder="请输入用户昵称"
                  clearable
                  @keyup.enter.native="handleQuery11"
                />
              </el-form-item>

              <el-form-item>
                <el-button type="primary" size="mini" @click="handleQuery11"
                  ><el-icon><Search /></el-icon>搜索</el-button
                >
                <el-button size="mini" @click="resetQuery11"
                  ><el-icon><RefreshRight /></el-icon>重置</el-button
                >
              </el-form-item>
            </el-form>

            <el-table
              style="height: 400px; overflow: auto"
              v-loading="loading1"
              :row-key="getRowKeys"
              ref="multipleTable3"
              :data="userList"
              @selection-change="handleSelectionChange1"
            >
              <el-table-column
                :selectable="getSelectable"
                :reserve-selection="true"
                type="selection"
                width="50"
                align="center"
              />
              <el-table-column
                label="用户昵称"
                align="center"
                key="nickName"
                prop="nickName"
                v-if="columns[2].visible"
                :show-overflow-tooltip="true"
              />
              <el-table-column
                label="所属部门"
                align="center"
                key="deptName"
                prop="dept.deptName"
                v-if="columns[3].visible"
                :show-overflow-tooltip="true"
              />
            </el-table>
            <pagination
              v-show="total1 > 0"
              :total="total1"
              :page-sizes="[10, 20, 30, 50, 100, 300]"
              v-model:page="queryParams3.pageNum"
              v-model:limit="queryParams3.pageSize"
              @pagination="getList1"
            />
          </el-col>
        </el-row>
        <div style="margin-left: 40vw; margin-top: 40px" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="okDuty">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog
        :title="dutyTitle"
        width="80%"
        style="height: 750px"
        v-model="actOpen"
      >
        <!-- 动态引入组件-->
        <act-form
          v-if="actOpen"
          :month="queryParams.month"
          @dialogOr="getValue"
          @submit="
            () => {
              handleQuery();
            }
          "
          @cancel="() => (actOpen = false)"
        ></act-form>
      </el-dialog>

      <el-dialog
        v-model="openDate"
        title="安排值班"
        width="500"
        :before-close="handleClose"
      >
        <el-form
          ref="ruleFormRef1"
          style="max-width: 600px; padding: 0 20px"
          :model="ruleForm1"
          :rules="rules1"
          label-width="140px"
          class="demo-ruleForm"
          :size="formSize1"
          status-icon
        >
          <el-form-item label="开始值班日期" prop="valueDate">
            <el-date-picker
              v-model="ruleForm1.valueDate"
              type="date"
              placeholder="请选择开始值班日期"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              :disabled-date="disabledDate"
            /> </el-form-item
        ></el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button @click="openDate = false">取消</el-button>
            <el-button type="primary" @click="okDutyDate"> 确定 </el-button>
          </div>
        </template>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  listDuty,
  getDuty,
  delDuty,
  addDuty,
  updateDuty,
  dutyButton,
  saveDuties,
  getDutyAdjust,
  editAdjust,
} from "@/api/beOnDuty";
import {
  automaticallyDuty,
  lastAutomaticallyDuty,
  toGenerateDutyData,
  toCheckExistDutyData,
} from "@/api/beOnDuty/dutyRules";
import { useDict } from "@/utils/dict";
import { listDuty11, deptTreeSelect2 } from "@/api/system/user";
import actForm from "@/views/beOnDuty/dutyRules";
// let props = defineProps(["dialogOr"]);
export default {
  name: "Duty",
  components: { actForm },
  data() {
    return {
      valueDate: "",
      ruleForm1: {},
      rules1: {
        valueDate: [
          {
            required: true,
            message: "请选择开始值班日期",
            trigger: "change",
          },
        ],
      },
      openDate: false,
      deptOptions: [],
      userList: [],
      queryParams3: {
        pageNum: 1,
        pageSize: 300,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: 100,
      },
      //提交数据
      dataList: [],
      dialogVisible: false,
      month: null,
      dutyDate: null,
      week: null,
      monthSelect: null,
      duty_status: useDict("duty_status").duty_status,
      // 遮罩层
      // loading: true,
      // 选中数组
      ids: [],
      value1: "",
      userId: [],
      // 子表选中数据
      checkedYDutyPerson: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      names: [],
      dutyPeopleList: [],
      // 值班表格数据
      dutyList: [],
      // 值班人员表格数据
      yDutyPersonList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 35,
        month: null,
        dutyDate: null,
        week: null,
      },
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined,
        nickName: undefined,
      },
      columns: [
        { key: 0, label: `用户编号`, visible: true },
        { key: 1, label: `用户名称`, visible: true },
        { key: 2, label: `用户昵称`, visible: true },
        { key: 3, label: `部门`, visible: true },
        { key: 4, label: `手机号码`, visible: true },
        { key: 5, label: `状态`, visible: true },
        { key: 6, label: `创建时间`, visible: true },
      ],
      nowDate: null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      userDeptName: [],
      MonthFirstDay: "",
      MonthLastDay: "",
      dutyListone: [],
      index: null,
      selection1: [],

      //排班
      actOpen: false,
      dutyTitle: "",
      dialogFlag: "",
      actForm: null,
      detail: { month: null },

      //调班
      openAdjust: false,
      // 表单参数
      adjustForm: {},
      duty_adjust: useDict("week_name").duty_adjust,
      dutyAdjustList: [],
      selectFlag: true,
    };
  },
  created() {
    this.getYearMonth();
    this.getList1();
    this.getDeptTree();
    this.handleQuery();
  },
  methods: {
    getValue(val) {
      if (val == true) {
        this.actOpen = false;
      } else {
        this.actOpen = true;
      }
    },
    disabledDate(time) {
      // 获取今天的日期，不包括时间
      const today = new Date();
      today.setHours(0, 0, 0, 0);
      // 禁用所有早于今天的日期
      return time.getTime() < today.getTime();
    },
    okDutyDate() {
      console.log(this.ruleForm1.valueDate);
      this.$refs["ruleFormRef1"].validate((valid) => {
        if (valid) {
          toCheckExistDutyData(this.ruleForm1.valueDate)
            .then((res) => {
              if (res.data == 1) {
                // this.$message.error("该月已有值班排班，是否覆盖？");
                this.$confirm("所选日期已有值班排班数据，是否覆盖？", "警告", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
                }).then(() => {
                  return toGenerateDutyData(this.ruleForm1.valueDate).then(
                    (res) => {
                      if (res.code == 200) {
                        this.$message.success("排班成功");
                        this.queryParams.month =
                          this.ruleForm1.valueDate.substring(0, 7);
                        console.log(this.queryParams.month);
                        this.handleQuery();
                        this.openDate = false;
                      }
                    }
                  );
                });
              } else {
                toGenerateDutyData(this.ruleForm1.valueDate).then((res) => {
                  if (res.code == 200) {
                    this.$message.success("排班成功");
                    this.queryParams.month = this.ruleForm1.valueDate.substring(
                      0,
                      7
                    );
                    console.log(this.queryParams.month);
                    this.handleQuery();
                    this.openDate = false;
                  }
                });
              }
            })
            .catch((err) => {
              console.log(err);
            });
        }
      });
    },
    ArrangeDuty() {
      this.openDate = true;
    },
    handleQuery11() {
      this.getList1();
    },
    resetQuery11() {
      this.queryParams3.nickName = undefined;
      this.getList1();
    },
    getUser(msg) {
      this.actOpen = msg;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id;
      this.open = true;
      getDuty(id).then((response) => {
        this.form = response.data;
        this.title = "修改值班";
        this.month = response.data.month;
        this.dutyDate = response.data.dutyDate;
        this.week = response.data.week;
        this.id = response.data.id;
        this.dutyPeopleList = response.data.yDutyPersonList;
        for (let i = 0; i < this.duty_status.length; i++) {
          for (let j = 0; j < this.dutyPeopleList.length; j++) {
            if (this.duty_status[i].value == this.dutyPeopleList[j].status) {
              this.duty_status[i].nickName.push(this.dutyPeopleList[j].name);
              this.duty_status[i].ids.push(this.dutyPeopleList[j]);
            }
          }
        }
      });

      for (let i = 0; i < this.duty_status.length; i++) {
        this.duty_status[i]["nickName"] = [];
        this.duty_status[i]["ids"] = [];
      }
    },

    /** 修改按钮操作 */
    dutyAdjust() {
      this.openAdjust = true;
      getDutyAdjust().then((response) => {
        this.duty_adjust = response.rows;
        this.adjustForm = response.rows;
        //this.dutyPeopleList = response.data.yDutyPersonList;
        /*for (let i = 0; i < this.duty_adjust.length; i++) {
                      for (let j = 0; j < this.dutyAdjustList.length; j++) {
                        if (this.duty_status[i].value == this.dutyAdjustList[j].status) {
                          this.duty_status[i].nickName.push(this.dutyAdjustList[j].name);
                          this.duty_status[i].ids.push(this.dutyAdjustList[j]);
                        }
                      }
                    }*/
      });

      /*for (let i = 0; i < this.duty_adjust.length; i++) {
                  this.duty_adjust[i]["nickName"] = [];
                  this.duty_adjust[i]["ids"] = [];
                }*/
    },

    scheduling() {
      // 月份
      if (this.queryParams.month == null) {
        this.$modal.msgWarning("请选择查看的月份");
        return;
      }
      this.dutyTitle = "设置排班规则";
      this.actOpen = true;
    },

    //确定值班人员
    async submitForm() {
      let formArr = {};
      let idsData = [];
      idsData = this.duty_status
        .map((item) => {
          return item.ids.concat();
        })
        .flat()
        .filter((item) => item !== undefined);
      const mergedArray = [];
      const combinedArray = [].concat(...idsData);
      for (let i = 0; i < combinedArray.length; i++) {
        mergedArray.push(combinedArray[i]);
      }
      this.yDutyPersonList = mergedArray;
      formArr = {
        id: this.id,
        month: this.month, //月份
        dutyDate: this.dutyDate, //日期
        week: this.week, //星期
        yDutyPersonList: this.yDutyPersonList,
      };
      let { code } = await saveDuties(formArr);
      if (code == 200) {
        this.$modal.msgSuccess("编辑成功");
        this.open = false;
        this.getList();
      }
    },

    //确定调班人员
    async adjustSubmitForm() {
      let adjustDate = [];
      console.log(this.duty_adjust);
      for (let i = 0; i < this.duty_adjust.length; i++) {
        let adjustedItem = { ...this.duty_adjust[i] };
        adjustDate.push(adjustedItem);
        if (
          this.duty_adjust[i].name != null &&
          typeof this.duty_adjust[i].name != "string"
        ) {
          adjustDate[i].name = adjustedItem.name[0];
          adjustDate[i].userId = adjustedItem.userId[0];
        }
      }
      console.log(this.duty_adjust);
      let { code } = await editAdjust(adjustDate);
      if (code == 200) {
        this.$modal.msgSuccess("编辑成功");
        this.openAdjust = false;
        this.getList();
      }
    },

    // 勾选值班人员
    handleSelectionChange1(selection) {
      this.selection1 = [];
      this.selection1 = selection;
      selection = [];
      this.single = this.selection.length !== 1;
      this.multiple = !this.selection.length;
    },
    //确认勾选值班人员
    okDuty() {
      if (this.selectFlag) {
        this.index.ids = [];
        this.index.nickName = [];
        this.index.ids.push(
          this.selection1.map((item) => ({
            userId: item.userId,
            nickName: item.nickName,
            status: this.index.value,
          }))
        );
        this.index.nickName.push(
          this.selection1.map((item) => item.nickName).join(",")
        );
      } else {
        this.index.ids = [];
        this.index.name = [];
        this.index.userId = [];
        this.index.ids.push(
          this.selection1.map((item) => ({
            userId: item.userId,
            name: item.nickName,
          }))
        );
        this.index.name.push(
          this.selection1.map((item) => item.nickName).join(",")
        );
        this.index.userId.push(
          this.selection1.map((item) => item.userId).join(",")
        );
      }
      this.dialogVisible = false;
      this.queryParams3.nickName = "";
    },
    // 选择
    select(index, selectFlag) {
      this.selectFlag = selectFlag;
      this.dialogVisible = true;
      this.index = index;
      this.$nextTick(() => {
        this.$refs.multipleTable3.clearSelection();
      });
      let arrUser = null;
      if (selectFlag) {
        arrUser = index.nickName.map((item) => item);
      } else {
        if (!index.name) {
          index.name = [];
        } else {
          if (typeof index.name === "string") {
            index.name = index.name.split(",");
          }
        }
        arrUser = index.name.map((item) => item);
      }
      if (arrUser.length == 1) {
        arrUser = arrUser[0].split(",");
      }
      this.userList.forEach((row) => {
        if (arrUser.indexOf(row.nickName) != -1) {
          setTimeout(() => {
            this.$refs.multipleTable3.toggleRowSelection(row, true);
          }, 400);
        }
      });
    },

    // 搜索
    search() {
      this.getList();
    },
    // 重置
    reset() {
      this.queryParams3.nickName = "";
      this.getList();
      this.userList.forEach((row) => {
        if (row.nickName == index.nickName) {
          this.$refs.multipleTable3.toggleRowSelection(row);
        }
      });
    },
    getRowKeys(row) {
      return row.userId;
    },
    //分页
    handleSizeChange2(newPage) {
      this.queryParams3.pageSize = newPage;
      this.getList1();
    },
    handleCurrentChange2(val) {
      this.queryParams3.pageNum = val;
      this.getList1();
    },
    // /** 节点单击事件 */
    handleNodeClick(data) {
      this.queryParams3.deptId = data.id;
      this.handleQuery1();
    },
    // /** 搜索按钮操作 */
    handleQuery1() {
      this.queryParams3.pageNum = 1;
      this.getList1();
    },
    // // 值班数据
    async getList1() {
      this.loading = true;
      await listDuty11(
        this.addDateRange(this.queryParams3, this.dateRange)
      ).then((res) => {
        this.loading = false;
        this.userList = res.rows;
        this.total1 = res.total;
      });
      this.selection = [];
    },
    // /** 查询部门下拉树结构 */
    async getDeptTree() {
      await deptTreeSelect2().then((response) => {
        this.deptOptions = response.data;
      });
    },
    async dutyButton() {
      let { rows } = await dutyButton(this.queryParams);
      this.dutyList = rows;
    },
    changeTime(val) {
      this.queryParams.month = val;
    },
    async generateDuty() {
      // 月份
      if (this.queryParams.month == null) {
        this.$modal.msgWarning("请选择生成值班的月份");
        return;
      }
      this.$modal.loading("生成中...");
      try {
        // this.dutyButton();
        // setInterval(this.handleQuery(), 6000);
        await automaticallyDuty(this.queryParams.month);
        this.handleQuery();
      } finally {
        this.$modal.closeLoading();
      }
    },
    //获取当前年月
    getYearMonth() {
      var date = new Date();
      this.queryParams.month = date;
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      this.getMonthLength(year, month);
      month = month < 10 ? "0" + month : month;
      this.queryParams.month = year + "-" + month;
    },
    async lastAutomaticallyDutyHandler() {
      // 月份
      if (this.queryParams.month == null) {
        this.$modal.msgWarning("请选择当前的月份");
        return;
      }
      this.$modal.loading("生成中...");
      try {
        await lastAutomaticallyDuty(this.queryParams.month);
        this.handleQuery();
      } finally {
        this.$modal.closeLoading();
      }
    },
    //获取月天数
    getMonthLength(year, month) {
      let day = new Date(year, month, 0).getDate();
    },
    // /** 查询值班列表 */
    getList() {
      listDuty(this.queryParams).then((response) => {
        this.dutyList = response.rows;
        this.total = response.total;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.actOpen = false;
      this.openAdjust = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        month: null,
        dutyDate: null,
        week: null,
        createTime: null,
        createBy: null,
        remark: null,
      };
      this.yDutyPersonList = [];
      this.resetForm("form");
      this.dataList = [];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // 月份
      if (this.queryParams.month == null) {
        this.$modal.msgWarning("请选择查看的月份");
        return;
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加值班";
    },

    /** 值班人员序号 */
    rowYDutyPersonIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },

    /** 导出按钮操作 */
    handleExport() {
      // 月份
      if (this.queryParams.month == null) {
        this.$modal.msgWarning("请选择要导出的月份");
        return;
      }
      this.download(
        "duty/duty/exportDuty",
        {
          yearMonth: this.queryParams.month,
        },
        `${this.queryParams.month}月值班表.xlsx`
      );
    },
  },
};
</script>
