<template>
  <div class="assessing-content ele-body">
    <el-card
      shadow="never"
      v-loading="loading"
      element-loading-background="rgba(255, 255, 255, 1)"
    >
      <search :type="3" @search:task="updateParams($event)" />
      <!-- <div class="operating">
        <el-button size="small" type="primary">导出</el-button>
      </div> -->
      <el-table
        highlight-current-row
        :data="dataList"
        :height="tableHeight"
        border
        :span-method="arraySpanMethod"
        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="quota"
        ></el-table-column>
        <el-table-column
          label="考核内容和计分细则"
          min-width="250"
          align="center"
          prop="content"
        ></el-table-column>
        <el-table-column
          label="小条内容"
          min-width="400"
          align="center"
          prop="itemContent"
        ></el-table-column>
        <el-table-column
          label="分值"
          width="50"
          align="center"
          prop="points"
        ></el-table-column>
        <el-table-column
          label="区牵头单位"
          width="95"
          align="center"
          prop="leaderUnit"
        >
          <template slot-scope="{ row }">
            <pre>{{ row.leaderUnit }}</pre>
          </template>
        </el-table-column>
        <el-table-column label="第一牵头部门" width="150" align="center">
          <template slot-scope="{ row }">
            <pre>{{ row.leaderDeptList | formatList }}</pre>
          </template>
        </el-table-column>
        <el-table-column
          label="第一牵头部门责任领导"
          width="170"
          align="center"
        >
          <template slot-scope="{ row }">
            <pre>{{ row.leaderPrincipalList | formatList }}</pre>
          </template>
        </el-table-column>
        <el-table-column label="其他牵头部门" width="130" align="center">
          <template slot-scope="{ row }">
            <pre>{{ row.otherDeptList | formatList }}</pre>
          </template>
        </el-table-column>
        <el-table-column
          label="其他牵头部门责任领导"
          width="170"
          align="center"
        >
          <template slot-scope="{ row }">
            <pre>{{ row.otherPrincipalList | formatList }}</pre>
          </template>
        </el-table-column>
        <el-table-column
          label="配合部门"
          width="100"
          align="center"
          prop="cooperateDept"
        >
          <template slot-scope="{ row }">
            <pre>{{ row.cooperateDeptList | formatList }}</pre>
          </template>
        </el-table-column>
        <el-table-column
          label="配合部门责任领导"
          width="150"
          align="center"
          prop="cooperateDeptList"
        >
          <template slot-scope="{ row }">
            <pre>{{ row.cooperatePrincipalList | formatList }}</pre>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100" align="center">
          <template slot-scope="{ row }">
            <!-- <router-link
              :to="{
                name: 'segmentation',
                params: { id: row.rigidityConstraintId, type: 3 },
              }"
              >分项</router-link
            > -->
            <el-link @click="toSegmentation(row)" type="primary"
              ><i class="el-icon-setting"></i>小条设置</el-link
            >
          </template>
        </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"
        :flat="true"
        @current-change="getDataList()"
      />
    </el-card>
  </div>
</template>

<script>
import search from "../search";
import api from "@/api/second/segmentation/constraint";
import apiSummary from "@/api/second/taskSummary";
import { mergeSpan } from "@/utils/mixin";
export default {
  components: {
    search,
  },
  data() {
    return {
      searchParams: {},
      dataList: [{ quota1: "sdewfdewd" }],
      loading: false,
      form: {},
      quota1List: [],
      quota2List: [],
      count: 0,
      tableHeight: document.documentElement.clientHeight - 260,
      page: {
        page: 1,
        limit: Math.floor(
          (document.documentElement.clientHeight - 260 - 45) / 45
        ),
      },
    };
  },
  mixins: [
    mergeSpan([
      { name: "quota", col: [1] },
      { name: "content", col: [2, 12] },
    ]),
  ],
  created() {
    this.getDataList();
    let page = this.page;
    page.page = this.$store.state.base.currentPage || 1;
    this.$store.commit("base/SET_CURRENT_PAGE", null);
    this.page = page;
  },
  methods: {
    toSegmentation(row) {
      this.$store.commit("base/SET_CURRENT_PAGE", this.page.page);
      this.$router.push({
        name: "segmentation",
        params: { id: row.rigidityConstraintId, type: 3 },
      });
    },
    updateParams(data) {
      this.searchParams = data;
      this.resetCurrentPage();
      this.getDataList();
    },
    resetCurrentPage() {
      let page = this.page;
      page.page = 1;
      this.page = page;
    },
    getDataList() {
      try {
        this.$refs.table.bodyWrapper.scrollTop = 0;
      } catch (e) {}
      this.loading = true;
      apiSummary
        .getContraintList(Object.assign({}, this.page, this.searchParams))
        .then((res) => {
          let data = res.data.data;
          this.count = data.total;
          this.dataList = this.reduceData(data.records);
        })
        .catch((e) => {
          this.dataList = [];
        })
        .finally(() => {
          this.loading = false;
        });
    },
  },
  filters: {
    formatList(val) {
      if (val) {
        return val.join("\n");
      }
    },
  },
};
</script>

<style scoped>
a {
  text-decoration: none;
  color: #66b1ff;
}
</style>