<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="员工" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入员工姓名" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="部门" prop="deptId">
        <treeselect style="width: 250px" :default-expand-level="1" v-model="queryParams.deptId" :options="deptOptions"
          :normalizer="normalizer" placeholder="选择部门" />
      </el-form-item>
      <el-form-item label="职位" prop="postId">
        <el-select v-model="queryParams.postId" placeholder="请选择" style="width: 250px">
          <el-option v-for="item in postOptions" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="holidayList">
      <el-table-column label="序号" type="index" width="50"align="center"/>
      <el-table-column label="员工" align="center" prop="name" min-width="100" />
      <el-table-column label="部门" align="center" prop="deptName" min-width="100" />
      <el-table-column label="职位" align="center" prop="position" min-width="100" />
      <el-table-column label="入职日期" align="center" prop="entryDate" min-width="150" />
      <el-table-column label="员工状态" align="center" prop="employeeStatus" min-width="100">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.EMPLOYEE_STATUS" :value="scope.row.employeeStatus" />
        </template>
      </el-table-column>
      <el-table-column label="基准天数" align="center" prop="baseAnnualLeave" min-width="100" />
      <el-table-column label="已使用天数" align="center" prop="usedAnnualLeave" min-width="100" />
      <el-table-column label="剩余天数" align="center" prop="remainingAnnualLeave" min-width="100" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-detail" @click="handleDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 详情对话框 -->
    <el-dialog :title="title" :visible.sync="openDetail" width="800px" append-to-body>
      <div class="widget-wrapper">
    <div class="widget-list">
      <div class="fx-field x-grid-col-12">
        <div class="field-label">
          <div class="field-name">员工</div>
        </div>
        <div class="field-component">
          <span :title="form.name">{{ form.name }}</span>
        </div>
      </div>
      <div class="fx-field x-grid-col-12">
        <div class="field-label">
          <div class="field-name">部门</div>
        </div>
        <div class="field-component">
          <span :title="form.deptName">{{ form.deptName }}</span>
        </div>
      </div>
      <div class="fx-field x-grid-col-12">
        <div class="field-label">
          <div class="field-name">职位</div>
        </div>
        <div class="field-component">
          <span :title="form.position">{{ form.position }}</span>
        </div>
      </div>
      <div class="fx-field x-grid-col-12">
        <div class="field-label">
          <div class="field-name">入职日期</div>
        </div>
        <div class="field-component">
          <span :title="form.entryDate">{{ form.entryDate }}</span>
        </div>
      </div>
      <div class="fx-field x-grid-col-12">
        <div class="field-label">
          <div class="field-name">员工状态</div>
        </div>
        <div class="field-component">
          <span :title="form.employeeStatus">
            <dict-tag :type="DICT_TYPE.EMPLOYEE_STATUS" :value="form.employeeStatus"/>
          </span>
        </div>
      </div>
     
      <div class="fx-field x-grid-col-12">
        <div class="field-label">
          <div class="field-name">基准天数</div>
        </div>
        <div class="field-component">
          <span>{{ form.baseAnnualLeave }}</span>
        </div>
      </div>
      <div class="fx-field x-grid-col-12">
        <div class="field-label">
          <div class="field-name">已使用天数</div>
        </div>
        <div class="field-component">
          <span>{{ form.usedAnnualLeave }}</span>
        </div>
      </div>


      <div class="fx-field x-grid-col-12">
        <div class="field-label">
          <div class="field-name">剩余天数</div>
        </div>
        <div class="field-component">
          <span>{{ form.remainingAnnualLeave }}</span>
        </div>
      </div>
    </div>
  </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSimplePosts } from "@/api/system/post";
import { listHoliday, getHoliday } from "@/api/personnel/holiday/index";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listDept } from "@/api/system/dept";
import { DICT_TYPE } from '@/utils/dict'
export default {
  name: "SystemDictType",
  components: {
    Treeselect,
  },
  data() {
    return {
      postOptions: [],
      // 部门列表
      deptOptions: [], // 部门属性结构
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      holidayList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      openDetail: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        name: undefined,
        deptId: undefined,
        postId: undefined,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
    this.getListDept();
  },
  methods: {
    /** 查询部门列表 */
    getListDept() {
      listDept().then(response => {
        this.deptOptions = this.handleTree(response.data, "id");
      });
      listSimplePosts().then(response => {
        // 处理 postOptions 参数
        this.postOptions = [];
        this.postOptions.push(...response.data);
      });
    },
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      };
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      listHoliday(this.queryParams).then(response => {
        this.holidayList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.files = [],
      this.form = {
        name: undefined,
        deptId: undefined,
        position: undefined,
        employeeStatus: undefined,
        gender: undefined,
        birthday: undefined,
        contactNumber: undefined,
        email: undefined,
        education: undefined,
        workExperience: undefined,
        startDate: undefined,
        fileIdList: undefined,
        remarks: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id;
      getHoliday(id).then(response => {
        this.form = response.data;
        this.openDetail = true;
        this.title = "详情";
      });
    },
  }
};
</script>
<style lang="scss" scoped>
.widget-wrapper>.widget-list {
  display: flex;
  flex-wrap: wrap;
}

.x-grid-col-6 {
  width: 50%;
}

.x-grid-col-12 {
  width: 100%;
}

.fx-field {
  line-height: 20px;
  padding: 7px 12px 12px;
  position: relative;
}

.fx-field .field-label {
  word-wrap: break-word;
  color: #141e31;
  display: flex;
  font-weight: 600;
  line-height: 20px;
  padding: 5px 0;
  position: relative;
  word-break: break-word;
}

.fx-field .field-label .field-required {
  color: #eb5050;
  margin-left: -6px;
  position: relative;
}

.fx-field .field-label .field-name {
  overflow: hidden;
}

.field-component {
  word-wrap: break-word;
  background: #f5f6f8;
  border-radius: 2px;
  color: #141e31;
  font-size: 14px;
  line-height: 20px;
  min-height: 32px;
  padding: 6px 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

ul {
  padding-left: 0px !important;
}

.el-tag+.el-tag {
  margin-left: 10px;
}
</style>