<template>
  <div class="app-container">
    <div style="text-align: right">
      <el-button
        type="primary"
        @click="$router.back()"
        >返回</el-button
      >
    </div>
    <h3>
      岗位方案名称：{{
        `惠州石化${
          new Date().toLocaleDateString().split('/')[0]
        }年度岗位责任制检查问题岗位检查方案`
      }}
    </h3>

    <ul class="top_ul_box">
      <li class="top_li_box" v-for="(item, index) in topList" :key="index">
        <div>
          {{ item.name }}
        </div>
        <h1>{{ item.postNum }} 个</h1>
      </li>
    </ul>

    <h3>岗检问题：</h3>
    <el-form size="small" :inline="true">
      <el-form-item label="部门名称：">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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 :data="centerList" border>
      <el-table-column align="center" type="index" label="序号" width="80">
      </el-table-column>
      <el-table-column align="center" prop="deptName" label="部门" width="180">
      </el-table-column>
      <el-table-column align="center" prop="proportion" label="职责类别">
        <template #default="{ row }">
          <div
            v-for="(item, index) in row.children"
            :key="index"
            class="border_box"
          >
            {{ initType(item.dutyType) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="integrityProblem"
        label="完整性问题"
      >
        <template slot-scope="scope">
          <div
            v-for="(item, index) in scope.row.children"
            :key="index"
            class="border_box"
          >
            {{ item.problemComplete + '项' || `--` }}
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="good" label="适宜性问题">
        <template slot-scope="scope">
          <div
            v-for="(item, index) in scope.row.children"
            :key="index"
            class="border_box"
          >
            {{ item.problemSuitable + '项' || `--` }}
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="veryGood" label="有效性问题">
        <template slot-scope="scope">
          <div
            v-for="(item, index) in scope.row.children"
            :key="index"
            class="border_box"
          >
            {{ item.problemEffective + '项' || `--` }}
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="time" label="生成时间">
        <template slot-scope="scope">
          <span>{{
            scope.row.statisticsTime
              ? formatTime(scope.row.statisticsTime)
              : '--'
          }}</span>
        </template>
      </el-table-column>
    </el-table>

    <!-- <h3>岗检报告：</h3> -->
  </div>
</template>

<script>
import moment from 'moment'
import {
  historyCheckStatistics,
  historyDeptDetaailView
} from '@/api/allApi/index.js'
export default {
  name: 'PostCheckWebJobinspectionHistoryLook',

  data() {
    return {
      topList: [],
      queryParams: {
        deptName: ''
      },

      centerList: []
    }
  },

  mounted() {
    this.initOneList()
    this.initTwoList()
  },

  methods: {
    initOneList() {
      historyCheckStatistics().then((response) => {
        this.topList = response.data
      })
    },
    initTwoList() {
      historyDeptDetaailView(this.queryParams).then((response) => {
        this.centerList = response.data
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.initTwoList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        deptName: ''
      }
      this.handleQuery()
    },
    formatTime(time) {
      return moment(time).format('YYYY-MM-DD')
    },
    initType(val) {
      switch (val) {
        case 1:
          return '业务职责'
        case 2:
          return '党建及党风廉政'
        case 3:
          return '安全环保职责'
        case 4:
          return '合规保密职'
        case 5:
          return '任职资格与能力素质要求'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
ul {
  list-style: none;
}
.top_ul_box {
  display: flex;
  padding: 20px;
  border: 1px solid #c7c7c7;
  justify-content: space-between;

  .top_li_box {
    flex: 1;
    text-align: center;
    border-right: 1px solid #c7c7c7;
    padding: 20px;

    &:last-child {
      border-right: none;
    }

    h1 {
      font-size: 30px;
    }
  }
}
::v-deep .el-table--medium .el-table__cell {
  padding: 0;
}
::v-deep .el-table .cell.el-tooltip {
  padding: 0;
}
::v-deep .el-table .cell {
  padding: 0;
}
.border_box {
  padding: 5px 0;
  margin: 0;
  min-height: 35px;
  box-sizing: border-box;
  border-bottom: 1px solid #dfe6ec;
}
</style>