<template>
  <div class="reward ele-body">
    <el-card>
      <search :type="2" @search:task="updateParams($event)" />
      <el-table
        highlight-current-row
        :data="dataList"
        border
        :height="tableHeight"
        :span-method="arraySpanMethod"
        @selection-change="selectionChange"
        v-loading="loading"
        ref="table"
      >
        <el-table-column
          type="index"
          width="50"
          align="center"
          label="编号"
        ></el-table-column>
        <el-table-column
          label="一级指标"
          min-width="80"
          align="center"
          prop="quota1"
        ></el-table-column>
        <el-table-column
          label="二级指标"
          min-width="80"
          align="center"
          prop="quota2"
        ></el-table-column>
        <el-table-column
          label="考核内容和计分规则"
          min-width="400"
          align="center"
          prop="content"
        ></el-table-column>
        <el-table-column
          label="封顶分值"
          min-width="80"
          align="center"
          prop="points"
        ></el-table-column>
        <el-table-column
          label="预计加分"
          min-width="80"
          align="center"
          prop="expectedPoints"
        ></el-table-column>
        <el-table-column
          label="区牵头单位"
          min-width="95"
          align="center"
          prop="leaderUnit"
        >
          <template slot-scope="{ row }">
            <pre>{{ row.leaderUnit }}</pre>
          </template>
        </el-table-column>
        <el-table-column label="牵头部门" min-width="80" align="center">
          <template slot-scope="{ row }">
            <pre>{{ row.leaderDeptList | formatList }}</pre>
          </template>
        </el-table-column>
        <el-table-column
          label="责任领导"
          min-width="80"
          align="center"
          prop="leaderPrincipalList"
        >
          <template slot-scope="{ row }">
            <pre>{{ row.leaderPrincipalList | formatList }}</pre>
          </template>
        </el-table-column>
        <el-table-column
          label="得分说明"
          min-width="100"
          align="center"
          prop="note"
        ></el-table-column>
      </el-table>
      <el-pagination
        :current-page.sync="page.page"
        :page-size="page.limit"
        :total="count"
        :background="true"
        layout="total, prev, pager, next, jumper"
        :pager-count="5"
        class="ele-pagination-circle"
        @current-change="getDataList()"
      />
    </el-card>
  </div>
</template>

<script>
import search from "../assessingTarget/search";
import { mergeSpan } from "@/utils/mixin";
import api from "../../api/summary/reward";
export default {
  name: "",
  data() {
    return {
      loading: false,
      tableHeight: document.documentElement.clientHeight - 265,
      dataList: [],
      count: 0,
      page: {
        page: 1,
        limit: Math.floor(
          (document.documentElement.clientHeight - 265 - 45) / 45
        ),
      },
      searchParams: {
        quota1: "",
        quota2: "",
        leaderDept: undefined,
        cooperateDept: undefined,
        quota: "",
        content: "",
        leaderUnit: "",
      },
    };
  },
  components: {
    search,
  },
  mixins: [
    mergeSpan([
      { name: "quota1", col: [1] },
      { name: "quota2", col: [2] },
    ]),
  ],
  created() {
    this.getDataList();
    this.$store.dispatch("base/getQuota1List", 1);
  },
  filters: {
    formatList(val) {
      if (val) {
        return val.join("\n");
      }
    },
  },
  methods: {
    updateParams(data) {
      this.searchParams = data;
      this.resetCurrentPage();
      this.getDataList();
    },
    resetCurrentPage() {
      let page = this.page;
      page.page = 1;
      this.page = page;
    },
    selectionChange(rows) {
      this.multipleSelection = rows;
    },
    getDataList(params) {
      try {
        this.$refs.table.bodyWrapper.scrollTop = 0;
      } catch (e) {}
      this.loading = true;
      api
        .getList(Object.assign({}, this.searchParams, this.page, params))
        .then((res) => {
          this.loading = false;
          let data = res.data.data.records;
          data = data.map((item) => {
            item.year = item.year + "";
            return item;
          });
          this.dataList = this.reduceData(data);
          this.count = res.data.data.total;
        })
        .catch(() => {
          this.loading = false;
          this.dataList = [];
          this.count = 0;
        });
    },
  },
};
</script>

<style>
</style>