<template>
  <div class="app-container" id="workReport">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="月份" prop="leaveDate">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          type="monthrange"
          range-separator="-"
          start-placeholder="开始月份"
          end-placeholder="结束月份"
          value-format="yyyy-MM"
          @change="onChangeTime"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="序号" align="center" width="80" type="index">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="月份" align="center" prop="month" width="100"/>
      <el-table-column label="部门名称" align="center" prop="orgName" :show-overflow-tooltip="true" width="240">
      </el-table-column>
      <el-table-column label="轮休人数" align="center" width="180">
        <template slot-scope="scope">
        <span class="clickable" @click="handleClick('轮休',scope.row)" style="color: blue; cursor: pointer;">
          {{ scope.row.leaveNum }}
        </span>
        </template>
      </el-table-column>
      <el-table-column label="临时外出人数" align="center" width="180">
        <template slot-scope="scope">
        <span class="clickable" @click="handleClick('临时外出',scope.row)" style="color: blue; cursor: pointer;">
          {{ scope.row.outNum }}
        </span>
        </template>
      </el-table-column>
      <el-table-column label="出差人数" align="center" width="180">
        <template slot-scope="scope">
        <span class="clickable" @click="handleClick('出差报备',scope.row)" style="color: blue; cursor: pointer;">
          {{ scope.row.businessTripNum }}
        </span>
        </template>
      </el-table-column>
      <el-table-column label="请假人数" align="center" width="180">
        <template slot-scope="scope">
        <span class="clickable" @click="handleClick('请假',scope.row)" style="color: blue; cursor: pointer;">
          {{ scope.row.holidayNum }}
        </span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" :show-overflow-tooltip="true" width="100">
        <template slot-scope="scope">
          <!-- 使用三元运算符判断 examineStatus 是否为 null -->
          <span>{{ scope.row.status !== null ? '已核对' : '未处理' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding" >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.isCheck==='1'"
            size="mini" type="primary"
            v-hasPermi="['flow:holiday:edit']"
            @click="handleUpdate(scope.row)"
          >核对</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="65%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-row type="flex" align="middle">
          <el-form-item label="姓名：" :label-width="'80px'">
            <el-input v-model="form.userName" style="width: 200px;" maxlength="50"></el-input>
          </el-form-item>
          <el-form-item label="审批状态" prop="examineStatus" v-if="this.title === '轮休人员' || this.title === '临时外出人员'" :label-width="'80px'">
            <el-select v-model="form.examineStatus" placeholder="审批状态" style="width: 200px;">
              <el-option v-for="item in examineStatusList" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-button type="primary" style="margin-left: 10px; margin-top: -20px;" icon="el-icon-search" size="mini" @click="handleQuerys">搜索</el-button>
        </el-row>
      </el-form>
      <el-table v-loading="loading" :data="tableDialogList" @selection-change="handleSelectionChange" @row-click="handleRowClick">
        <el-table-column label="序号" align="center" width="70" type="index">
          <template slot-scope="scope">
            <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="姓名" align="center" prop="userName" width="90"/>
        <el-table-column label="职务" align="center" prop="postName" :show-overflow-tooltip="true" width="170">
        </el-table-column>
        <el-table-column label="所属部门" align="center" prop="orgName" width="180"/>
        <el-table-column label="申请时间" align="center" prop="createTime" width="160"/>
        <el-table-column label="开始时间" align="center" prop="startDate" width="160"/>
        <el-table-column label="结束时间" align="center" prop="endDate" width="160"/>
        <el-table-column label="时长（天）" align="center" prop="leaveDuration" :show-overflow-tooltip="true" width="100"/>
        <el-table-column label="审批状态" align="center" prop="examineStatus" width="100" v-if="tableDialogList.some(row => row.type === '轮休' || row.type === '临时外出')">
          <template slot-scope="scope">
            <span v-if="scope.row.examineStatus === '0'">待审核</span>
            <span v-else-if="scope.row.examineStatus === '1'">已通过</span>
            <!-- 可以添加更多的条件来处理其他可能的状态 -->
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="totalDialog>0"
        :total="totalDialog"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
      />
    </el-dialog>

    <el-dialog :visible.sync="isEdit" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="核对意见：" prop="checkRemark">
              <el-input type="textarea" v-model="form.checkRemark" maxlength="50"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row >
          <el-col :span="24">
            <el-form-item label="流程：" prop="content">
              <el-input type="textarea" v-model="form.content" :readonly="true" maxlength="200"></el-input>
            </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-dialog :title="title" :visible.sync="isView" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名：" prop="userName">
              <el-input v-model="form.userName" :readonly="true"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="职位：" prop="postName">
              <el-input v-model="form.postName" :readonly="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="所属部门:" prop="orgId">
              <el-select v-model="form.orgId" @change="changDept">
                <el-option
                  v-for="item in orgList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="出行人:" prop="orgHeadUserIdList">
              <el-select v-model="form.orgHeadUserIdList" multiple placeholder="部门负责人" filterable clearable style="width: 100%;">
                <el-option
                  v-for="item in personOptions"
                  :key="item.userIds"
                  :label="item.userName"
                  :value="item.userIds"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="出差开始时间：" prop="leaveStartDate">
              <el-date-picker
                v-model="form.leaveStartDate" :clearable="false"
                type="date" value-format="yyyy-MM-dd" style="width: 100%;" @change="handleDateChange"
                placeholder="出差开始时间" :pickerOptions="startPickerOptions">
              </el-date-picker>
            </el-form-item>
          </el-col>
<!--          <el-col :span="4">
            <el-form-item prop="leaveStartInterval" label-width="0px">
              <el-select v-model="form.leaveStartInterval" style="width: 80%;margin-left: 10px;"
                         @change="handleDateChange">
                <el-option
                  v-for="item in timeStatusList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>-->
          <el-col :span="12">
            <el-form-item label="出差结束时间:" prop="leaveEndDate">
              <el-date-picker
                v-model="form.leaveEndDate" :clearable="false"
                type="date" value-format="yyyy-MM-dd" style="width: 100%;" @change="handleDateChange"
                placeholder="出差结束时间" :pickerOptions="endPickerOptions">
              </el-date-picker>
            </el-form-item>
          </el-col>
<!--          <el-col :span="4">
            <el-form-item prop="leaveEndInterval" label-width="0px">
              <el-select v-model="form.leaveEndInterval" style="width: 80%;margin-left: 10px;"
                         @change="handleDateChange">
                <el-option
                  v-for="item in timeStatusList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="出差时长(天)：" prop="leaveDuration">
              <el-input v-model="form.leaveDuration" :readonly="true"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="地点：" prop="location">
              <el-input v-model="form.location" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="是否请示领导同意：" prop="isAgree">
              <el-radio-group v-model="form.isAgree">
                <el-radio
                  v-for="item in isAgreeList"
                  :key="item.id"
                  :label="item.id"
                >{{item.name}}</el-radio>
              </el-radio-group>


            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="代理主持工作人员：" prop="hostUserId">
              <el-select v-model="form.hostUserId" multiple  placeholder="人员角色" clearable>
                <el-option
                  v-for="item in userList"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId"
                />
              </el-select>

            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="休假事由：" prop="leaveReason">
              <el-input type="textarea" v-model="form.leaveReason" maxlength="200"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row >
          <el-col :span="24">
            <el-form-item label="备注：" prop="breamks">
              <el-input type="textarea" v-model="form.breamks" maxlength="200"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForms">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listWorkReport, getDetailsList, setCheck, getUserList, exportWorkReport} from "@/api/process/workReport";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {addEvection, getEvection, getPersonSelect, updateEvection} from "@/api/process/evection";
export default {
  name: "WorkReport",
  dicts: ['apply_status'],
  components: { Treeselect },
  data() {
    return {
      userInfo:this.$store.state.user,
      orgList:this.$store.state.user.orgList,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 总条数
      totalDialog: 0,
      // 表格数据
      tableList: [
        // {
        //   userName:"张三",
        //   orgName:"公司机关/分公司机关/×××项目部",
        //   createTime:"2024-08-28 17：28",
        //   leaveStartDate:"2024-08-29",
        //   leaveStartInterval:"1",
        //   leaveEndDate:"2024-08-29",
        //   leaveEndInterval:"2",
        //   leaveDuration:"1",
        //   examineStatus:"0",
        // }
      ],
      tableDialogList:[],
      searchConditions: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      isEdit: false,
      isView: false,
      userList:[],
      isAgreeList:[{id:'0',name:'否'},{id:'1',name:'是'}],
      timeStatusList:[{id:'1',name:"上午"},{id:'2',name:"下午"}],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startDate: undefined,
        endDate: undefined
      },
      personOptions:[],
      typeList:[{value:'1',label:'固定班制'},{value:'2',label:'自由工时'}],
      examineStatusList: [{id: '', name: '全部'}, {id: '0', name: '待审批'}, {id: '1', name: '已通过'}],
      attDayList:[{id:0,label:'周一'},{id:1,label:'周二'},{id:2,label:'周三'},{id:3,label:'周四'},{id:4,label:'周五'},{id:5,label:'周六'},{id:6,label:'周日'}],
      // 表单参数
      form: {
        userName: '',
        examineStatus:''
      },
      // 表单校验
      rules: {
        userName:[
          {required: true, message: "申请人不能为空", trigger: "blur" }
        ],
        postName:[
          {required: true, message: "职务不能为空", trigger: "blur" }
        ],
        orgId: [
          { required: true, message: "所属部门不能为空", trigger: "blur" }
        ],
        leaveStartDate: [
          { required: true, message: "外出开始时间不能为空", trigger: "blur" }
        ],
        /*leaveStartInterval: [
          { required: true, message: "不能为空", trigger: "change" }
        ],*/
        leaveEndDate: [
          { required: true, message: "外出结束时间不能为空", trigger: "blur" }
        ],
        leaveEndInterval: [
          { required: true, message: "不能为空", trigger: "change" }
        ],
        leaveDuration: [
          { required: true, message: "外出时长不能为空", trigger: "blur" }
        ],
        location:[
          { required: true, message: "是否请示领导不能为空", trigger: "blur" }
        ],
        isAgree:[
          { required: true, message: "是否请示领导不能为空", trigger: "blur" }
        ],
        hostUserId:[
          { required: true, message: "代理主持工作人员不能为空", trigger: "blur" }
        ],
        leaveReason: [
          { required: true, message: "外出事由不能为空", trigger: "blur" }
        ],
        checkRemark: [
          { required: true, message: "核对意见不能为空", trigger: "blur" }
        ]
      },
      // 开始日期选择限制
      startPickerOptions: {
          disabledDate: (v) => {
              if(this.form.leaveEndDate) {
                  return v.getTime() > new Date(this.form.leaveEndDate).getTime()
              }
          },
      },
      // 结束日期选择限制
      endPickerOptions: {
          disabledDate: (v) => {
              if(this.form.leaveStartDate) {
                  return v.getTime() < new Date(this.form.leaveStartDate).getTime() - 86400000; //  - 86400000是否包括当天
              }
          },
      },

    };
  },
  created() {
    this.getMonthDates();
    this.getList();
    this.getPersonSelect();
    this.getUserLists();
  },
  methods: {
    getMonthDates() {
      const now = new Date();
      const year = now.getFullYear();
      const month = now.getMonth();

      // 获取上个月的第一天
      const lastMonthFirstDay = new Date(year, month - 1, 1);
      // 获取上个月的最后一天
      const lastMonthLastDay = new Date(year, month, 0);

      // 格式化日期为 YYYY-MM
      const formatDate = (date) => {
        const y = date.getFullYear();
        const m = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以加1
        return `${y}-${m}`;
      };

      this.dateRange[0] = formatDate(lastMonthFirstDay);
      this.dateRange[1] = formatDate(lastMonthLastDay);
    },
    handleDateChange() {
      this.form.leaveStartInterval = 1;
      this.form.leaveEndInterval = 2;
      if (this.form.leaveStartDate && this.form.leaveEndDate) {
        let daysNumber = this.daysBetween(this.form.leaveStartDate, this.form.leaveEndDate)
        // console.log(daysNumber)
        if (this.form.leaveStartInterval == 1 && this.form.leaveEndInterval == 1) {
          this.form.leaveDuration = daysNumber + 0.5
        } else if (this.form.leaveStartInterval == 1 && this.form.leaveEndInterval == 2) {
          this.form.leaveDuration = daysNumber + 1
        } else if (this.form.leaveStartInterval == 2 && this.form.leaveEndInterval == 2) {
          this.form.leaveDuration = daysNumber + 0.5
        } else if (this.form.leaveStartInterval == 2 && this.form.leaveEndInterval == 1) {
          this.form.leaveDuration = daysNumber
        }
      }
    },

    daysBetween(date1, date2) {
      const oneDay = 24 * 60 * 60 * 1000;
      const date1Ms = new Date(date1).getTime()
      const date2Ms = new Date(date2).getTime()
      const diff = Math.abs(date1Ms - date2Ms); // 计算两日期的差值
      return diff / oneDay; // 返回天数
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      if(this.dateRange&&this.dateRange.length>0){
        this.queryParams.startDate=this.dateRange[0]
        this.queryParams.endDate=this.dateRange[1]
      }else{
        this.queryParams.startDate=undefined
        this.queryParams.endDate=undefined
      }
      listWorkReport(this.queryParams).then(response => {
          this.tableList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 人员选择下拉 */
    getPersonSelect() {
      getPersonSelect().then(response => {
        this.personOptions=response.data
        console.log("this.personOptions",this.personOptions);
      });
    },
    getUserLists(){
      const Id = this.$store.state.user.id;
      getUserList(Id).then(response => {
        this.userList = response.data.data;
        console.log("userList",this.userList)
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.isEdit = false;
      this.isView = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId:this.userInfo.id,
        userName:this.userInfo.name,
        orgId: undefined,
        leaveStartDate: undefined,
        leaveStartInterval:undefined,
        leaveEndDate: undefined,
        leaveEndInterval:undefined,
        leaveDuration:undefined,
        hostUserId:[],
        orgHeadUserIdList: [],
        travelers:[]
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.getMonthDates();
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.Id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    handleClick(type,row) {
      this.tableDialogList=[];
      this.form.userName = '';
      this.form.examineStatus='';
      // 处理点击事件
      this.open = true;
      if (type==='轮休'){
        this.title = "轮休人员";
      } else if (type==='临时外出'){
        this.title = "临时外出人员";
      } else if (type==='出差报备'){
        this.title = "出差人员";
      } else if (type==='请假'){
        this.title = "请假人数";
      }
      this.searchConditions={
        type:type,
        orgId:row.orgId,
        month:row.month
      }
      getDetailsList(this.searchConditions).then(response => {
        this.tableDialogList = response.rows;
        this.totalDialog = response.total;
        this.loading = false;
      })

    },
    /** 搜索按钮操作 */
    handleQuerys() {
      const queryData = {
        ...this.searchConditions, // 拷贝存储的条件
        userName: this.form.userName, // 添加用户输入的搜索条件
        examineStatus:this.form.examineStatus
      };
      getDetailsList(queryData).then(response => {
        this.tableDialogList = response.rows;
        this.totalDialog = response.total;
        this.loading = false;
      });
    },
    handleRowClick(row) {
      if (this.searchConditions.type==='出差报备'){
        getEvection(row.uuId).then(response => {
          this.form = response.data;
          let num = [];
          let numArr = this.form.hostUserId.split(",")
          numArr.forEach(function (item){
            num.push(parseInt(item));
          })
          this.$set(this.form,"hostUserId",num)
          if(this.form.travelers!=null){
            let arr = this.form.travelers.split(',')
            let nums = [];
            arr.forEach(function (item){
              nums.push(item.trim() + "");
            })
            this.$set(this.form,"orgHeadUserIdList",nums)
          }
          this.isView = true;
          this.title = "编辑";
        });
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const Id = row.id
      let content="";
      if (row.attCheckRemark!=null) {
        content=row.attCheckRemark;
      }
      if (row.chargeCheckRemark!=null) {
        content= content+"\n"+row.chargeCheckRemark;
      }
      if (row.wageCheckRemark!=null) {
        content= content+"\n"+row.wageCheckRemark;
      }
      console.log(content)
      this.isEdit = true;
      this.$set(this.form,"id",row.id);
      this.form.content=content;
    },
    //选择部门
    changDept(e){
      console.log(e)
      this.orgList.forEach(item=>{
        if(item.id==e){
          this.form.orgName = item.name
        }
      })
    },
    /** 提交按钮 */
    submitForm: function() {
      console.log(this.form)
      this.$refs["form"].validate(valid => {
        if (valid) {
          setCheck(this.form).then(response => {
                this.$modal.msgSuccess("核对成功");
                this.isEdit = false;
                this.getList();
          })
        }
      });
    },
    /** 修改按钮 */
    submitForms: function () {
      console.log(this.form)
      this.$refs["form"].validate(valid => {
        if (valid) {
          console.log(this.form)
          var list = this.form.hostUserId.join(",");
          // 将字符串分割成数组
          const userIdArray = list.split(',');
          // 检查数组中是否同时存在0和其他非0的值
          const containsZero = userIdArray.includes('0');
          const containsOtherValues = userIdArray.some(id => id !== '0');
          if (containsZero && containsOtherValues) {
            this.$modal.msgError("选择’/‘后不能在选择其他人员");
            return ;
          }
          this.form.hostUserId = list;
          var hostNameList = this.getSelectedUserNameEvecTion();
          this.form.hostUserName = hostNameList;

          var lists = this.form.orgHeadUserIdList.join(",");
          var idsArray = lists.split(",")
          const Ids = this.$store.state.user.id+"";
          const containsIds = idsArray.includes(Ids);
          var filteredIds;
          if(containsIds){
            //去掉它
            filteredIds = idsArray.filter(id => id !== Ids);
          }else{
            this.$modal.msgError("出行人需要添加申请人");
            return ;
          }
          console.log(filteredIds)
          this.form.travelers = filteredIds.join(",");
          console.log(this.form.travelers)
          var nameList = this.getSelectedUserNames(filteredIds);
          this.form.travelersName = nameList;

          this.form.examineStatus = 0
          updateEvection(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.isView = false;
            this.getList();
          });
        }
      });
    },

    getSelectedUserNames(filteredIds) {
      const selectedUserIds = filteredIds;
      const selectedUsers = this.personOptions.filter(option => selectedUserIds.includes(option.userIds));
      const selectedUserNames = selectedUsers.map(user => user.userName);
      return selectedUserNames.join(', ');
    },

    getSelectedUserNameEvecTion() {
      const selectedUserIdsStr = this.form.hostUserId;
      // 将字符串分割成字符串数组，并将每个元素转换为整数
      const selectedUserIds = selectedUserIdsStr.split(',').map(id => parseInt(id.trim(), 10));

      const selectedUsers = this.userList.filter(option => selectedUserIds.includes(option.userId));

      const selectedUserNames = selectedUsers.map(user => user.userName);

      return selectedUserNames.join(', ');
    },

    handleBack(row) {
      this.$modal.confirm('是否确认撤回该申请？').then(function() {
        let param = {
          id:row.id,
          examineStatus:'3',
        }
        changeHolidayStatus(param).then(response => {
          this.getList();
          this.$modal.msgSuccess("撤回成功");
        });
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const Ids = row.id;
      this.$modal.confirm('是否确认删除该申请？').then(function() {
        return delHoliday(Ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
        this.queryParams.exportType="查询";
      exportWorkReport(this.queryParams).then(res => {
          this.downloadFile({ fileName: `工作安排统计报表_${new Date().getTime()}.xlsx`, fileData: res, fileType: 'application/vnd.ms-excel;charset=utf-8' })
        })
    },

    onChangeTime(val){
      console.log(val)
      if(val.length > 0) {
        const [ val_1, val_2 ] = val;
        this.queryParams.startDate = val_1;
        this.queryParams.endDate = val_2;

      } else  {
        this.queryParams.startDate = '';
        this.queryParams.endDate = '';
      }
    }

  }
};
</script>
