<template>
  <div class="container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true" label-width="80px">
      <el-form-item label="转正人" prop="employeeName">
        <el-input v-model="queryParams.loginName" placeholder="转正人" clearable style="width: 250px"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="员工编号" prop="employeeName">
        <el-input v-model="queryParams.loginId" placeholder="员工编号" clearable style="width: 250px"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="部门" prop="employeeName">
        <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="position">
        <el-select v-model="queryParams.position" placeholder="请选择"
        style="width: 250px">
          <el-option v-for="item in posOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="转正日期" prop="employeeName">
        <el-date-picker style="width: 250px" value-format="yyyy-MM-dd" v-model="queryParams.conversionDate" type="date" placeholder="入职日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审批状态" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" placeholder="审批状态" clearable style="width: 250px">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/>
        </el-select>
      </el-form-item>
      <el-form-item label="申请人"prop="employeeName">
        <el-input v-model="queryParams.creator" placeholder="申请人" clearable style="width: 250px"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
    
      <el-form-item label="申请时间" prop="employeeName">
        <el-date-picker
      v-model="queryParams.createTime"
      style="width: 250px"
      type="datetime"
      value-format="yyyy-MM-dd HH:mm:ss"
      placeholder="选择申请时间">
    </el-date-picker>
      </el-form-item>
      <el-form-item label="">
        <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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" icon="el-icon-download" @click="handleExport" :loading="exportLoading"
                   v-hasPermi="['system:role:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @row-click="handdle">
      <el-table-column label="转正人" prop="loginName" min-width="120" />
      <el-table-column label="员工编号" prop="loginId" min-width="150" />
      <el-table-column label="部门" prop="deptId" min-width="150" />
      <el-table-column label="职位" prop="position" min-width="150" />
      <el-table-column label="转正日期" prop="conversionDate" min-width="100" />
      <el-table-column label="审批状态" prop="auditStatus" min-width="150" />
      <el-table-column label="申请人" prop="creator" min-width="150" />
      <el-table-column label="创建时间" align="center" prop="createTime" min-width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </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="续签申请(修改)" :visible.sync="openEdit" width="800px" append-to-body>
      <edit :id="id"></edit>
    </el-dialog>
    <!-- 详情 -->
    <el-dialog title="续签申请(详情)" :visible.sync="openDetail" width="800px" append-to-body>
      <detail :id="id"></detail>
    </el-dialog>
  </div>
</template>

<script>
import { getListData,exportList }  from "@/api/oa/turnJust"
import detail from "./detail.vue";
import edit from "./edit.vue";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listDept } from "@/api/system/dept";

export default {
  name: "SystemRole",
  components: {
    detail,
    edit,
    Treeselect,
  },
  data() {
    return {
      detailLoading:false,
        posOptions: [],
      id:'',
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      dataList: [],
      openEdit: false,
      openDetail: false,
      // 部门列表
      deptOptions: [], // 部门属性结构
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        employeeName: undefined,
        position: undefined,
        employeePhone: undefined,
        auditStatus: undefined,
        createTime: []
      },
    };
  },
  created() {
    this.getList();
    this.getListDept();
  },
  methods: {
      /** 查询部门列表 */
      getListDept() {
      listDept().then(response => {
        this.deptOptions = this.handleTree(response.data, "id");
      });
    },
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      };
    },
    handdle(row) {
      this.id = row.id;
      if(row.auditStatus==0){
        this.openEdit = true;
      }else{
        this.openDetail = true;
      }
    },
    closeEdit() {
      this.openEdit = false;
      this.getList();
    },

    /** 查询列表 */
    getList() {
      this.loading = true;
      getListData(this.queryParams).then(
        response => {
          this.dataList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },



 



    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有数据项?').then(function() {
          this.exportLoading = true;
          return exportList(queryParams);
        }).then(response => {
          this.$download.excel(response, '通用审批数据.xls');
          this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
