<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['peopleChuRu:bdglLeave:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['peopleChuRu:bdglLeave:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['peopleChuRu:bdglLeave:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['peopleChuRu:bdglLeave:export']"
          >导出</el-button
        >
      </el-col>
      <!-- <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar> -->
    </el-row>

    <el-table
      v-loading="loading"
      :data="bdglLeaveList"
      @selection-change="handleSelectionChange"
      :header-cell-style="{ background: '#003C69', color: 'white' }"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="单位" align="center" prop="unitName" />
      <el-table-column label="请假人员" align="center" prop="peopleName" />

      <el-table-column
        label="请假开始时间"
        align="center"
        prop="startTime"
        width="100"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="请假结束时间"
        align="center"
        prop="endTime"
        width="100"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="请假类型" align="center" prop="leaveType" :formatter="qingJia"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.Leave_type"
            :value="scope.row.leaveType"
          />
        </template>
      </el-table-column>
      <el-table-column label="请假原因" align="center" prop="leaveReason" />
      <el-table-column
        label="离队时间"
        align="center"
        prop="departureTime"
        width="100"
      />
      <el-table-column
        label="归队时间"
        align="center"
        prop="returnTime"
        width="100"
      />
      <el-table-column label="是否归队" align="center" prop="isReturn" >
         <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_is"
            :value="scope.row.isReturn"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="一级审批人"
        align="center"
        prop="peopleName1"
        width="100"
      />
      <el-table-column
        label="一级审批状态"
        align="center"
        prop="peopleId2"
        width="100"
      >
        <template slot-scope="scope">
          <el-col v-if="scope.row.status1 == 0" style="color: #ffba00"
            >未审批</el-col
          >
          <el-col v-if="scope.row.status1 == 1" style="color: #13ce66"
            >已通过</el-col
          >
          <el-col
            v-if="scope.row.status1 == 2"
            :title="scope.row.reasons"
            style="color: #ff4949"
            >已驳回</el-col
          >
          <el-col
            v-if="scope.row.status1 == 3"
            :title="scope.row.bdglLeaveFus[0].specialApproval"
            style="color: #1f73d7"
            >特殊审批</el-col
          >
        </template></el-table-column
      >
      <el-table-column
        label="二级审批人"
        align="center"
        prop="peopleName2"
        width="100"
      />
      <el-table-column
        label="二级审批状态"
        align="center"
        prop="peopleId4"
        width="100"
      >
        <template slot-scope="scope">
          <el-col v-if="scope.row.status2 == 0" style="color: #ffba00"
            >未审批</el-col
          >
          <el-col v-if="scope.row.status2 == 1" style="color: #13ce66"
            >已通过</el-col
          >
          <el-col
            v-if="scope.row.status2 == 2"
            :title="scope.row.reasons"
            style="color: #ff4949"
            >已驳回</el-col
          >
          <el-col
            v-if="scope.row.status2 == 3"
            :title="scope.row.bdglLeaveFus[1].specialApproval"
            style="color: #1f73d7"
            >特殊审批</el-col
          >
        </template>
      </el-table-column>
      <el-table-column
        label="三级审批人"
        align="center"
        prop="peopleName3"
        width="100"
      />
      <el-table-column
        label="三级审批状态"
        align="center"
        prop="status2"
        width="100"
      >
        <template slot-scope="scope">
          <el-col v-if="scope.row.status3 == 0" style="color: #ffba00"
            >未审批</el-col
          >
          <el-col v-if="scope.row.status3 == 1" style="color: #13ce66"
            >已通过</el-col
          >
          <el-col
            v-if="scope.row.status3 == 2"
            :title="scope.row.reasons"
            style="color: #ff4949"
            >已驳回</el-col
          >
          <el-col v-if="scope.row.status3 == 3" style="color: #1f73d7"
            >特殊审批</el-col
          >
        </template>
        <!-- :title="scope.row.bdglLeaveFus[2].specialApproval" -->
      </el-table-column>
      <el-table-column
        label="四级审批人"
        align="center"
        prop="peopleName4"
        width="100"
      />
      <el-table-column
        label="四级审批状态"
        align="center"
        prop="status4"
        width="100"
      >
        <template slot-scope="scope">
          <el-col v-if="scope.row.status4 == 0" style="color: #ffba00"
            >未审批</el-col
          >
          <el-col v-if="scope.row.status4 == 1" style="color: #13ce66"
            >已通过</el-col
          >
          <el-col
            v-if="scope.row.status4 == 2"
            :title="scope.row.reasons"
            style="color: #ff4949"
            >已驳回</el-col
          >
          <el-col v-if="scope.row.status4 == 3" style="color: #1f73d7"
            >特殊审批</el-col
          >
          <!-- :title="scope.row.bdglLeaveFus[3].specialApproval" -->
        </template>
      </el-table-column>
      <el-table-column
        label="总审批状态"
        align="center"
        prop="contents"
        width="100"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="210"
      >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.common == '1'"
            size="btc"
            type="text"
            @click="handleUpdates(scope.row)"
            v-hasPermi="['peopleChuRu:bdglLeave:edit']"
            >审批</el-button
          >
          <el-button
            v-else-if="scope.row.common == '2'"
            size="mini"
            type="text"
            @click="handleUpdatess(scope.row)"
            v-hasPermi="['peopleChuRu:bdglLeave:edit']"
            >特殊审批</el-button
          >
          <el-button
            size="btu"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['peopleChuRu:bdglLeave:edit']"
            >修改</el-button
          >
          <el-button
            size="btd"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['peopleChuRu:bdglLeave:remove']"
            >删除</el-button
          >
          <el-button
            v-if="scope.row.common == '3'"
            size="btc"
            type="text"
            @click="handleGuiDui(scope.row)"
            v-hasPermi="['peopleChuRu:bdglLeave:edit']"
            >归队</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改人员请假对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        inline
      >
        <div class="jiben">基本信息</div>

        <el-form-item label="单位" prop="unitId">
          <treeselect
            v-model="form.unitId"
            :options="deptOptions"
            placeholder="请选择单位"
            @select="selectPeo"
            @open="blurSelect"
          />
        </el-form-item>
        <el-form-item label="请假人员" prop="peopleId">
          <!-- <el-input v-model="form.peopleId" placeholder="请输入请假人员" /> -->
          <el-select
            v-model="form.peopleId"
            placeholder="请输入请假人员"
            ref="headerSearchSelect"
          >
            <el-option
              v-for="(item, i) in renYuan"
              :key="i"
              :label="item.name"
              :value="item.id"
              @click.native="qingRen(item.name)"
              class="input_xiala"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="请假开始时间" prop="startTime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择请假开始时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="请假结束时间" prop="endTime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择请假结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="请假类型" prop="leaveType">
          <el-select v-model="form.leaveType" placeholder="请选择请假类型">
            <!-- <el-option label="请选择字典生成" value="" /> -->
            <el-option
              v-for="item in ziDian"
              :key="item.dictCode"
              :label="item.dictLabel"
              :value="item.dictValue"
              class="input_xiala"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="离队时间" prop="departureTime">
          <!-- <el-input v-model="form.departureTime" placeholder="请输入离队时间" /> -->
          <el-date-picker
            clearable
            size="small"
            v-model="form.departureTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请输入离队时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="归队时间" prop="returnTime">
          <!-- <el-input v-model="form.returnTime" placeholder="请输入归队时间" /> -->
          <el-date-picker
            clearable
            size="small"
            v-model="form.returnTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请输入归队时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="一级审批人" prop="peopleId2">
          <!-- <el-input v-model="form.peopleId2" placeholder="请输入二级审批人" /> -->
          <el-select
            v-model="form.peopleId1"
            filterable
            placeholder="请输入一级审批人"
            ref="abcdef"
          >
            <el-option
              v-for="(item, i) in yongHu"
              :key="i"
              :label="item.userName"
              :value="item.userId"
              @click.native="oneRen(item.userName)"
              class="input_xiala"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="二级审批人" prop="peopleId2">
          <!-- <el-input v-model="form.peopleId2" placeholder="请输入二级审批人" /> -->
          <el-select
            v-model="form.peopleId2"
            filterable
            placeholder="请输入二级审批人"
            ref="abcde"
          >
            <el-option
              v-for="(item, i) in yongHu"
              :key="i"
              :label="item.userName"
              :value="item.userId"
              @click.native="twoRen(item.userName)"
              class="input_xiala"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="三级审批人" prop="peopleId3">
          <!-- <el-input v-model="form.peopleId3" placeholder="请输入三级审批人" /> -->
          <el-select
            v-model="form.peopleId3"
            filterable
            placeholder="请输入三级审批人"
            ref="abcd"
          >
            <el-option
              v-for="(item, i) in yongHu"
              :key="i"
              :label="item.userName"
              :value="item.userId"
              @click.native="thereRen(item.userName)"
              class="input_xiala"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="四级审批人" prop="peopleId4">
          <!-- <el-input v-model="form.peopleId4" placeholder="请输入四级审批人" /> -->
          <el-select
            v-model="form.peopleId4"
            filterable
            placeholder="请输入四级审批人"
            ref="abc"
          >
            <el-option
              v-for="(item, i) in yongHu"
              :key="i"
              :label="item.userName"
              :value="item.userId"
              @click.native="fourRen(item.userName)"
              class="input_xiala"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <div class="jiben">请假原因</div>
        <el-form-item prop="leaveReason">
          <el-input
            v-model="form.leaveReason"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <div class="jiben" v-if="statussp == '1'">驳回原因</div>
        <el-form-item v-if="statussp == '1'" prop="reasons">
          <el-input
            v-model="form.reasons"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <div class="jiben" v-if="statussp == '2'">驳回原因</div>
        <el-form-item v-if="statussp == '2'" prop="reasons">
          <el-input
            v-model="form.reasons"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <div class="jiben" v-if="statussp == '2'">特殊审批原因</div>
        <el-form-item v-if="statussp == '2'" prop="reasons">
          <el-input
            v-model="form.specialApproval"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="statussp == '0'">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      <div v-if="statussp == '1'" class="dialog-footer" slot="footer">
        <el-button type="primary" @click="submitForms">通过</el-button>
        <el-button @click="boHui">驳回</el-button>
      </div>
    </el-dialog>

    <!--特殊审批对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="opens"
      width="500px"
      append-to-body
    >
      <el-form
        ref="forms"
        :model="form"
        :rules="rulesform"
        label-width="80px"
        inline
      >
        <el-form-item label="单位" prop="unitId">
          <treeselect
            v-model="form.unitId"
            :options="deptOptions"
            placeholder="选择单位"
            @select="selectPeo"
            @open="blurSelect"
          />
        </el-form-item>
        <el-form-item label="请假人员" prop="peopleId">
          <el-select
            v-model="form.peopleId"
            placeholder="请输入请假人员"
            ref="headerSearchSelect"
          >
            <el-option
              v-for="(item, i) in renYuan"
              :key="i"
              :label="item.name"
              :value="item.id"
              @click.native="qingRen(item.name)"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="请假开始时间" prop="startTime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择请假开始时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="请假结束时间" prop="endTime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择请假结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="请假类型" prop="leaveType">
          <el-select v-model="form.leaveType" placeholder="请选择请假类型">
            <el-option
              v-for="item in ziDian"
              :key="item.dictCode"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="离队时间" prop="departureTime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.departureTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请输入离队时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="归队时间" prop="returnTime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.returnTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请输入归队时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="一级审批人" prop="peopleId2">
          <el-select
            v-model="form.peopleId1"
            filterable
            placeholder="请输入一级审批人"
            ref="abcdef"
          >
            <el-option
              v-for="(item, i) in yongHu"
              :key="i"
              :label="item.nickName"
              :value="item.userId"
              @click.native="oneRen(item.nickName)"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="二级审批人" prop="peopleId2">
          <el-select
            v-model="form.peopleId2"
            filterable
            placeholder="请输入二级审批人"
            ref="abcde"
          >
            <el-option
              v-for="(item, i) in yongHu"
              :key="i"
              :label="item.nickName"
              :value="item.userId"
              @click.native="twoRen(item.nickName)"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="三级审批人" prop="peopleId3">
          <el-select
            v-model="form.peopleId3"
            filterable
            placeholder="请输入三级审批人"
            ref="abcd"
          >
            <el-option
              v-for="(item, i) in yongHu"
              :key="i"
              :label="item.nickName"
              :value="item.userId"
              @click.native="thereRen(item.nickName)"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="四级审批人" prop="peopleId4">
          <el-select
            v-model="form.peopleId4"
            filterable
            placeholder="请输入四级审批人"
            ref="abc"
          >
            <el-option
              v-for="(item, i) in yongHu"
              :key="i"
              :label="item.nickName"
              :value="item.userId"
              @click.native="fourRen(item.nickName)"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <div class="jiben">请假原因</div>
        <el-form-item prop="leaveReason">
          <el-input
            v-model="form.leaveReason"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <div class="jiben">驳回原因</div>
        <el-form-item prop="reasons">
          <el-input
            v-model="form.reasons"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <div class="jiben">特殊审批原因</div>
        <el-form-item prop="specialApproval">
          <el-input
            v-model="form.specialApproval"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div class="dialog-footer" slot="footer">
        <el-button type="primary" @click="TSsubmitForms">通过</el-button>
        <el-button @click="TSboHui">驳回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBdglLeave,
  getBdglLeave,
  delBdglLeave,
  addBdglLeave,
  updateBdglLeave,
  exportBdglLeave,
} from "@/api/peopleChuRu/bdglLeave";

import {
  getUser,
  getDept,
  getQuanBu,
} from "@/api/grassrootsregistration/bdglmeeting";
// 导入树形结构
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
// 查询字典
import { getDicts } from "@/api/system/dict/data";
export default {
  name: "BdglLeave",
  components: {
    Treeselect,
  },
   dicts: ["Leave_type", "sys_is"],
  data() {
    return {
      // 审批按钮状态 审批按钮状态1 修改为0,超级审批状态2
      statussp: "1",
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人员请假表格数据
      bdglLeaveList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示特殊权限弹出层
      opens: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        peopleId: null,
        unitId: null,
        startTime: null,
        endTime: null,
        leaveType: null,
        leaveReason: null,
        departureTime: null,
        returnTime: null,
        returnStatus: null,
        isReturn: null,
        updatetime: null,
        adminId: null,
        createtime: null,
        peopleId1: null,
        postId: null,
        peopleId2: null,
        peopleId3: null,
        peopleId4: null,
        status1: null,
        status2: null,
        status3: null,
        status4: null,
        contents: null,
        statusd: null,
        rejoin: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        unitId: [{ required: true, message: "单位不能为空", trigger: "blur" }],
        peopleId: [
          { required: true, message: "人员不能为空", trigger: "blur" },
        ],
        reasons: [
          { required: true, message: "请填写驳回原因", trigger: "blur" },
        ],
        leaveType: [
          { required: true, message: "请假类型不能为空", trigger: "blur" },
        ],
      },
      // 特殊审批表单验证
      rulesform: {
        reasons: [
          { required: true, message: "请填写驳回原因", trigger: "blur" },
        ],
        specialApproval: [
          {
            required: true,
            message: "审批原因不能为空",
            trigger: "blur",
          },
        ],
      },
      // 树形结构列表
      deptOptions: [],
      // 用户列表
      yongHu: [],
      // 人员列表
      renYuan: [],
      // 查询字典
      dictType: {
        dictType: "Leave_type",
      },
      // 字典的列表
      ziDian: [],
      // 审批状态
      ziDians: [],
      // 特殊审批通过验证
      trueng: true,
      // 归队数据
      guidui: {},
    };
  },
  created() {
    this.getList();
    // 字典查询数据
    this.getDicts("approve").then((response) => {
      this.ziDians = response.data;
    });
  },
  methods: {
    // 归队按钮
    handleGuiDui(row) {
      const id = row.id || this.ids;
      getBdglLeave(id).then((response) => {
        this.form = response.data;
      });
      this.$modal
        .confirm("是否确认归队人员的数据项？")
        .then(() => {
          if (this.form.id != null) {
            this.form.rejoin = "1";
            console.log(this.form, 1);
            updateBdglLeave(this.form).then((response) => {
              this.$modal.msgSuccess("归队成功");
              this.getList();
            });
          }
        })
        .catch(() => {});
    },
    // // 特殊审批按钮触发
    handleUpdatess(row) {
      this.statussp = "2";
      this.getBuMeng();
      // 获取字典类型
      this.getdict();
      this.reset();
      const id = row.id || this.ids;
      getBdglLeave(id).then((response) => {
        this.form = response.data;
        this.getYong(this.form.unitId);
        this.getRen(this.form.unitId);
        this.opens = true;
        this.title = "审批人员请假";
      });
    },
    // 审批按钮操作
    handleUpdates(row) {
      this.statussp = "1";
      this.getBuMeng();
      // 获取字典类型
      this.getdict();
      this.reset();
      const id = row.id || this.ids;
      getBdglLeave(id).then((response) => {
        this.form = response.data;
        this.getYong(this.form.unitId);
        this.getRen(this.form.unitId);
        this.open = true;
        this.title = "审批人员请假";
      });
    },
    // 让单位失去焦点
    blurSelect() {
      this.$refs.headerSearchSelect.blur();
      this.$refs.abc.blur();
      this.$refs.abcd.blur();
      this.$refs.abcde.blur();
      this.$refs.abcdef.blur();
    },
    // 重置表单人员
    ChongZhiRen() {
      (this.form.peopleId = null), (this.form.peopleId1 = null);
      this.form.peopleId2 = null;
      this.form.peopleId3 = null;
      this.form.peopleId4 = null;
    },
    // 查询请假类型
    getdict() {
      getDicts(this.dictType.dictType).then((res) => {
        this.ziDian = res.data;
      });
    },
    // 请假人选中
    qingRen(name) {
      this.form.peopleName = name;
    },
    // 一级审批人选中
    oneRen(name) {
      this.form.peopleName1 = name;
    },
    //二级审批人选中
    twoRen(name) {
      this.form.peopleName2 = name;
    },
    // 三级审批人选中
    thereRen(name) {
      this.form.peopleName3 = name;
    },
    // 四级审批人选中
    fourRen(name) {
      this.form.peopleName4 = name;
    },
    // 获取部门列表
    getBuMeng() {
      getDept().then((res) => {
        this.deptOptions = res.data;
      });
    },
    // 选择部门单位触发
    selectPeo(data) {
      this.ChongZhiRen();
      this.form.unitId = data.id;
      this.getYong(this.form.unitId);
      this.getRen(this.form.unitId, 0);
    },
    // 获取用户列表
    getYong(id) {
      getUser(id).then((res) => {
        this.yongHu = res.data;
      });
    },
    // 获取人员
    getRen(id, num) {
      getQuanBu(id, num).then((response) => {
        this.renYuan = response.data;
      });
    },
    /** 查询人员请假列表 */
    getList() {
      this.loading = true;
      listBdglLeave(this.queryParams).then((response) => {
        console.log(response);
        this.bdglLeaveList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    //审批通过按钮
    submitForms() {
      this.bdglLeaveList.forEach((item) => {
        if (item.shenPiJiBie == "一级") {
          this.form.status1 = 1;
          this.form.contents = "一级审批通过";
        } else if (item.shenPiJiBie == "二级") {
          this.form.status2 = 1;
          this.form.contents = "二级审批通过";
        } else if (item.shenPiJiBie == "三级") {
          this.form.status3 = 1;
          this.form.contents = "三级审批通过";
        } else if (item.shenPiJiBie == "四级") {
          this.form.status4 = 1;
          this.form.contents = "四级审批通过";
        }
      });
      updateBdglLeave(this.form).then((response) => {
        this.$modal.msgSuccess("审批成功");
        this.open = false;
        this.getList();
      });
    },
    // 审批驳回按钮
    boHui() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.bdglLeaveList.forEach((item) => {
            if (item.shenPiJiBie == "一级") {
              this.form.status1 = 2;
              return (this.form.contents = "一级审批驳回");
            } else if (item.shenPiJiBie == "二级") {
              this.form.status2 = 2;
              return (this.form.contents = "二级审批驳回");
            } else if (item.shenPiJiBie == "三级") {
              this.form.status3 = 2;
              return (this.form.contents = "三级审批驳回");
            } else if (item.shenPiJiBie == "四级") {
              this.form.status4 = 2;
              return (this.form.contents = "四级审批驳回");
            }
          });
          console.log(this.form);
          updateBdglLeave(this.form).then((response) => {
            this.$modal.msgSuccess("审批成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    //超级审批通过按钮
    TSsubmitForms() {
      this.$refs["forms"].validateField("specialApproval", (valid) => {
        if (!valid) {
          this.bdglLeaveList.forEach((item) => {
            if (item.shenPiJiBie == "一级") {
              this.form.status1 = 3;
              this.form.common = "1";
              this.form.contents = "一级审批通过";
            } else if (item.shenPiJiBie == "二级") {
              this.form.status2 = 3;
              this.form.common = "2";
              this.form.contents = "二级审批通过";
            } else if (item.shenPiJiBie == "三级") {
              this.form.status3 = 3;
              this.form.common = "3";
              this.form.contents = "三级审批通过";
            } else if (item.shenPiJiBie == "四级") {
              this.form.status4 = 3;
              this.form.common = "4";
              this.form.contents = "四级审批通过";
            }
          });
          if (this.form.id != null) {
            updateBdglLeave(this.form).then((response) => {
              this.$modal.msgSuccess("审批成功");
              this.opens = false;
              this.getList();
            });
          }
        }
      });
    },
    // 超级审批驳回按钮
    TSboHui() {
      this.$refs["forms"].validate((valid) => {
        if (valid) {
          this.bdglLeaveList.forEach((item) => {
            if (item.shenPiJiBie == "一级") {
              this.form.status1 = 2;
              this.form.common = "1";
              return (this.form.contents = "一级审批驳回");
            } else if (item.shenPiJiBie == "二级") {
              this.form.status2 = 2;
              this.form.common = "2";
              return (this.form.contents = "二级审批驳回");
            } else if (item.shenPiJiBie == "三级") {
              this.form.status3 = 2;
              this.form.common = "3";
              return (this.form.contents = "三级审批驳回");
            } else if (item.shenPiJiBie == "四级") {
              this.form.status4 = 2;
              this.form.common = "4";
              return (this.form.contents = "四级审批驳回");
            }
          });
          if (this.form.id != null) {
            updateBdglLeave(this.form).then((response) => {
              this.$modal.msgSuccess("审批成功");
              this.opens = false;
              this.getList();
            });
          }
        }
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        peopleId: null,
        unitId: null,
        startTime: null,
        endTime: null,
        leaveType: null,
        leaveReason: null,
        departureTime: null,
        returnTime: null,
        returnStatus: "0",
        isReturn: null,
        updatetime: null,
        adminId: null,
        createtime: null,
        peopleId1: null,
        postId: null,
        peopleId2: null,
        peopleId3: null,
        peopleId4: null,
        status1: null,
        status2: null,
        status3: null,
        status4: null,
        contents: null,
        statusd: null,
        rejoin: null,
        specialApproval: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.statussp = "0";
      (this.renYuan = []),
        // 获取单位树形
        this.getBuMeng();
      // 获取字典类型
      this.getdict();
      this.reset();
      this.open = true;
      this.title = "添加人员请假";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.statussp = "0";
      this.getBuMeng();
      // 获取字典类型
      this.getdict();
      this.reset();
      const id = row.id || this.ids;
      getBdglLeave(id).then((response) => {
        this.form = response.data;
        this.getYong(this.form.unitId);
        this.getRen(this.form.unitId);
        this.open = true;
        this.title = "修改人员请假";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBdglLeave(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else if (this.form.common != null) {
          } else {
            addBdglLeave(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除人员请假编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBdglLeave(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有人员请假数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportBdglLeave(queryParams);
        })
        .then((response) => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
<style scoped>
/* 对话框背景颜色 */
::v-deep .el-dialog {
  background: #004d86 !important;
  width: 800px !important;
}
::v-deep .el-textarea__inner {
  width: 920px;
  height: 104px;
  margin: auto;
}
::v-deep .el-dialog__header {
  border-bottom: 1px solid #718a9d;
}
::v-deep .el-dialog__title {
  color: #fff;
  font: 18px;
}
::v-deep .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
::v-deep .el-form-item__label {
  font: 16px;
  color: #fff;
  width: 100px !important;
}
::v-deep .el-input__inner {
  /* width: 200px !important;
  height: 36px; */
  background: transparent;
  color: #fff;
}
/* 单位框背景颜色 */
::v-deep .vue-treeselect__control {
  background: #004d86 !important;
}
/* 基本信息背景 */
.jiben {
  width: 920px;
  height: 32px;
  background-image: url(../../../images/小标题底.png);
  margin-bottom: 25px;
  color: #fff;
  padding-left: 16px;
  line-height: 32px;
}
/*调整表单间距 */
::v-deep .el-form-item__content {
  width: 200px;
}
::v-deep .el-input__inner {
  cursor: pointer !important;
}
/* 底部确定取消按钮 */
::v-deep .el-dialog__footer {
  padding: 30px 50px;
}
::v-deep .el-dialog__body {
  margin: 10px 30px 20px 30px;
  padding-top: 20px !important;
  box-sizing: border-box;
  /* padding: 30px 12px 30px 28px; */
}
.contents {
  padding: 0px 40px !important;
}
/* 下拉菜单 */
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
/* 下拉菜单字体/背景颜色 */
.el-select-dropdown__item.hover,
.el-select-dropdown__item:hover {
  background-color: #004d86;
  color: #fff;
}
.el-select-dropdown__item {
  color: #fff;
}
/* 时间选择 */
::v-deep .el-input--small .el-input__inner {
  width: 200px;
  height: 36px;
  line-height: 36px;
}
.el-date-editor.el-input {
  width: 200px;
  height: 36px;
  line-height: 36px;
}
::v-deep .el-date-editor.el-input .el-input__inner {
  height: 36px;
  line-height: 36px;
}
/* 单位框背景颜色 */
::v-deep .vue-treeselect__control {
  background: #004d86 !important;
  color: #fff;
}
/* 单位下拉菜单选中字体颜色 */
::v-deep .vue-treeselect__single-value {
  color: #fff !important;
}
/* 分页按钮 */
::v-deep .el-pagination.is-background .el-pager li {
  background-color: #004d86;
  color: #fff;
}
::v-deep .el-pagination.is-background .btn-next {
  background-color: #004d86;
  color: #fff;
}
/* 底部确定取消按钮 */
::v-deep .el-dialog__footer {
  padding: 18px 50px;
  margin-right: 42px;
}
/* 增加按钮弹框 */
::v-deep .el-dialog {
  width: 1060px !important;
}
::v-deep .el-dialog__body {
  padding: none !important;
}
/* 小手样式 */
::v-deep .el-table__cell {
  cursor: pointer;
}
.el-button--mini {
  width: 80px !important;
  border: 1px solid transparent;
  padding: 3px 8px;
  font-size: 14px;
  line-height: 1.5;
  border-radius: 3px;
  color: #fff;
  background-color: #1890ff;
}
</style>
