<template>
  <div class="app-container" style="padding-top: 10px">
    <div class="tab_box">
      <span
        :class="seachForm.type === 1 ? `active` : ''"
        @click="changeType(1)"
      >
        职能管理部门
      </span>
      <span
        :class="seachForm.type === 2 ? `active` : ''"
        @click="changeType(2)"
      >
        生产运行部门
      </span>
    </div>
    <el-form ref="queryForm" size="small" :inline="true">
      <el-form-item label="选择年度：">
        <el-date-picker
          v-model="queryParams.year"
          style="width: 150px"
          type="year"
          placeholder="选择年度"
          format="yyyy 年"
          value-format="yyyy"
          :clearable="false"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="doSeach"
          >统计</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <div class="big_box">
      <div
        id="centerChart"
        class="echart"
        :style="{
          width: '98%',
          height: '100%',
        }"
      />
    </div> -->
    <h1>{{year}}年度排名</h1>

    <!-- <el-form size="small" :inline="true">
      <el-form-item label="部门名称：">
        <el-input v-model="seachForm.deptId" placeholder="请输入部门名称" />
      </el-form-item>
      <el-form-item label="岗位名称：">
        <el-input v-model="seachForm.postId" placeholder="请输入岗位名称" />
      </el-form-item>
      <el-form-item label="评分时间：">
        <el-date-picker
          v-model="ratingTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </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">
      <!-- <el-table-column label="序号" align="center" width="80" type="index">
      </el-table-column> -->
      <el-table-column label="排名" align="center"  width="100" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.rating ? scope.row.rating : '--' }}</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.postScore ? scope.row.postScore : 0
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="互评得分" align="center" v-if="seachForm.type === 1" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{
            scope.row.deptScore ? scope.row.deptScore : 0
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="日常得分" align="center" v-else show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{
            scope.row.deptScore ? scope.row.deptScore : 0
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总得分" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{
            scope.row.score ? scope.row.score : 0
          }}</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="lookDialogVisible = true"
            >查看</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>
    <!-- <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="seachForm.pageNum"
      :limit.sync="seachForm.pageSize"
      @pagination="getList"
    /> -->

    <!-- <h1 style="display: flex; align-items: center">
      互评汇总表

      <div v-if="seachForm.type === 2" class="center_color_box">
        最高值 <span class="red_box" />
      </div>
      <div v-if="seachForm.type === 2" class="center_color_box">
        最低值 <span class="green_box" />
      </div>
    </h1>
    <div class="summary_box" v-if="seachForm.type === 1">
      <SummaryTable />
    </div>

    <div class="summary_box" v-if="seachForm.type === 2">
      <SummaryColorTable />
    </div> -->

    <LookDialog
      :lookDialogVisible.sync="lookDialogVisible"
      @changeLookDialogVisible="changeLookDialogVisible"
    ></LookDialog>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import LookDialog from './lookDialog.vue'
import {
  assessmentRatingList,
  assessmentRatingChart,
  assessmentRatingZN,
  assessmentRatingSC
} from '@/api/allApi/index.js'
import SummaryTable from './SummaryTable.vue'
import SummaryColorTable from './SummaryColorTable.vue'
export default {
  components: {
    LookDialog,
    SummaryTable,
    SummaryColorTable
  },
  data() {
    return {
      lookDialogVisible: false,
      queryParams: {
        year: ''
      },
      loading: false,
      tableData: [],
      seachForm: {
        deptId: '',
        postId: '',
        pageNum: 1,
        pageSize: 10,
        type: 1
      },
      ratingTime: [],
      total: 0,
      activeName: '职能管理部门',

      oneTitle:[],
      oneList:[],
      twoList: [],
      threeList: [],
    }
  },

  mounted() {
    this.queryParams.year = new Date().toLocaleDateString().split('/')[0]
    this.year = new Date().toLocaleDateString().split('/')[0]
    this.$nextTick(() => {
      // this.getList()
      // this.initCharts()
      this.initAssessmentRatingZN()
    })
  },

  methods: {  
    initCenterChartEcharts() {
      const option = {
        title: {
          text: `${this.queryParams.year}岗位评比问题数`,
          left: 'center'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        legend: {
          left: 'right'
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: this.oneList,
            axisPointer: {
              type: 'shadow'
            },
            axisLabel:{
                interval: 0,
                rotate: 20,             
            }
          }
        ],
        yAxis: [
          {
            type: 'value'
          },
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '部门',
            type: 'bar',
            data: this.twoList,
            barWidth: '40%',
            itemStyle: {
              color: '#61aeda'
            }
          },
          // {
          //   name: '岗位',
          //   type: 'line',
          //   data: [80, 80, 60, 98],
          //   itemStyle: {
          //     color: '#6dc8e1'
          //   }
          // }
        ]
      }
      const centerChart = echarts.init(document.getElementById('centerChart')) // 图标初始化
      centerChart.setOption(option) // 渲染页面
      // 随着屏幕大小调节图表
      window.addEventListener('resize', () => {
        centerChart.resize()
      })
    },
    initAssessmentRatingZN() {
      assessmentRatingZN(this.queryParams.year).then((res) => {
        if (res.code !== 200) return this.$message.error(res.msg)
        this.tableData = res.data

      })
    },
    initAssessmentRatingSC() {
      assessmentRatingSC(this.queryParams.year).then((res) => {
        if (res.code !== 200) return this.$message.error(res.msg)
        this.tableData = res.data
      })
    },
    doSeach() {
      // this.initCharts()
      if(this.seachForm.type === 1){
        this.initAssessmentRatingZN()
      }else {
        this.initAssessmentRatingSC()
      }
      this.year = this.queryParams.year
    },
    async initCharts() {

      let obj1 = {
        type: this.seachForm.type,
        year: this.queryParams.year
      }
      const req = await assessmentRatingChart(obj1)
      if (req.code !== 200) return this.$message.error(req.msg)
      this.oneList = req.data.map((item) => item.deptName)
      this.twoList = req.data.map((item) => item.num)

      setTimeout(() => {
        this.initCenterChartEcharts()
      }, 100)
    },
    changeType(type) {
      this.seachForm.type = type
      // this.initCharts()
      // this.getList()
      if(this.seachForm.type === 1){
        this.initAssessmentRatingZN()
      }else {
        this.initAssessmentRatingSC()
      }
    },
    /** 查询岗位列表 */
    getList() {
      this.loading = true
      assessmentRatingList(
        this.addDateRange(this.seachForm, this.ratingTime)
      ).then((res) => {
        this.tableData = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.seachForm.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.seachForm = {
        deptId: '',
        postId: '',
        pageNum: 1,
        pageSize: 10,
        type: 1
      }
      this.ratingTime = []
      this.getList()
    },
    changeLookDialogVisible(val) {
      this.lookDialogVisible = val
    }
  }
}
</script>

<style lang="scss" scoped>
* {
  box-sizing: border-box;
}
.big_box {
  height: 35vh;
  display: flex;
}

.tab_box {
  border-bottom: 1px solid #e0e0e0;
  margin-bottom: 15px;
  padding-bottom: 10px;

  span {
    margin-right: 20px;
    font-weight: 700;
    cursor: pointer;
  }

  .active {
    padding-bottom: 10px;
    border-bottom: 3px solid #1890ff;
  }
}

.center_color_box {
  margin-left: 50px;
  font-size: 17px;
  display: flex;
  align-items: center;
}

.red_box {
  display: inline-block;
  width: 80px;
  height: 40px;
  margin-left: 10px;
  background-color: #f00;
}
.green_box {
  display: inline-block;
  width: 80px;
  height: 40px;
  margin-left: 10px;
  background-color: #00c936;
}
</style>