<template>
  <div class="app-container">
    <el-form ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="岗位名称：">
        <el-input
          v-model="queryParams.postName"
          placeholder="请输入岗位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在部门：">
        <el-cascader
          style="width: 300px"
          v-model="unitId1"
          :options="postOptions"
          @change="handleChange"
        >
        </el-cascader>
      </el-form-item>
      <el-form-item label="是否涉密：">
        <el-select
          v-model="queryParams.isConfidential"
          placeholder="请选择是否涉密"
          clearable
        >
          <el-option label="是" value="是"></el-option>
          <el-option label="否" value="否"></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 border v-loading="loading" :data="tableData" height="calc(100% - 150px)">
      <el-table-column label="序号" align="center" width="80">
        <template slot-scope="scope">
          <span>{{
            scope.$index + 1 + (queryParams.pageNum - 1) * queryParams.pageSize
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="版本号" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.versionNo ? scope.row.versionNo : '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所在单位" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.unitId ? scope.row.unitId : '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所在部门" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.deptName ? scope.row.deptName : '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="岗位名称" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.postName ? scope.row.postName : '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否涉密" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{
            scope.row.isConfidential ? scope.row.isConfidential : '--'
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="直接上级" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{
            scope.row.directSuperior ? scope.row.directSuperior : '--'
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="直接下级" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{
            scope.row.directSubordinate ? scope.row.directSubordinate : '--'
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="管辖人数" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{
            scope.row.subordinateCount ? scope.row.subordinateCount : '--'
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="编制/修订日期"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.revisionDate
              ? scope.row.revisionDate
              : scope.row.creationDate || '-'
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ initStatus(scope.row.status) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120"
      >
        <template slot-scope="scope">

           <el-button type="text" @click="$router.push(
                `/postResponsibility/postResponsibilityOrganizationLook?id=${scope.row.id}&type=3`
              )">查看</el-button>

          <!--
          非一期的功能
          <el-button type="text" @click="doDownload(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"
    />
  </div>
</template>

<script>
import { postCheckListList, deptTree , exportFun } from '@/api/allApi/index.js'
import FileSaver from "file-saver";
export default {
  name: 'PostResponsibilityMeun',

  data() {
    return {
      queryParams: {
        postName: '',
        deptId: '',
        isConfidential: '',
        status: 3,
        pageNum: 1,
        pageSize: 10
      },
      unitId1: [],
      tableData: [],
      total: 0,
      loading: false,
      showSearch: true,
      postOptions: []
    }
  },

  mounted() {
    this.initDeptTree()
    this.getList()
  },

  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true
      postCheckListList(this.queryParams).then((response) => {
        this.tableData = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.unitId1 = []
      this.queryParams = {
        postName: '',
        deptId: '',
        isConfidential: '',
        status: 3,
        pageNum: 1,
        pageSize: 10
      }
      this.handleQuery()
    },
    initStatus(val) {
      switch (val) {
        case 0:
          return '待提交'
        case 1:
          return '待审核'
        case 2:
          return '审核中'
        case 3:
          return '通过'
        case 4:
          return '驳回'
      }
    },
    // 选择部门
    handleChange(value) {
      this.queryParams.deptId = value[value.length - 1]
    },
    async initDeptTree() {
      const res = await deptTree()
      if (res.code !== 200) return this.$message.error(res.msg)
      this.postOptions = res.data
    },
    // 下载
    async doDownload(row){
      const  res  = await exportFun(row.id)
      const aBlob = new Blob([res]);
      FileSaver.saveAs(aBlob, "责任制清单.xlsx");
    },
  }
}
</script>

<style lang="scss" scoped>
</style>
