<template>
  <div class="constraint" v-loading="loading">
    <search :type="3" @search:task="updateParams($event)" />
    <el-table
      :data="dataList"
      border
      highlight-current-row
      :height="tableHeight"
      ref="table"
    >
      <el-table-column type="index" label="序号" align="center" width="50">
      </el-table-column>
      <el-table-column
        label="申请部门"
        align="center"
        width="150"
        prop="applyDeptName"
      ></el-table-column
      ><el-table-column
        label="申请时间"
        align="center"
        width="120"
        prop="createTime"
      ></el-table-column
      ><el-table-column
        label="申请理由"
        align="center"
        width="100"
        prop="note"
      ></el-table-column>
      <el-table-column
        label="考核指标"
        width="100"
        align="center"
        prop="quota"
      ></el-table-column>

      <el-table-column
        label="考核内容和计分细则"
        align="center"
        width="400"
        prop="content"
      ></el-table-column>
      <el-table-column
        label="小条内容"
        align="center"
        width="220"
        prop="itemContent"
      ></el-table-column>
      <el-table-column
        label="分值"
        min-width="60"
        align="center"
        prop="points"
      ></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="第一牵头部门" width="120" 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="120" align="center">
        <template slot-scope="{ row }">
          <span>
            <pre>{{ row.leaderDeptList | formatList }}</pre>
          </span>
        </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="100" align="center">
        <template slot-scope="{ row }">
          <span>
            <pre>{{ row.cooperateDeptList | formatList }}</pre>
          </span>
        </template>
      </el-table-column>

      <el-table-column label="配合部门责任领导" width="150" align="center">
        <template slot-scope="{ row }">
          <pre>{{ row.cooperatePrincipalList | formatList }}</pre>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="85" align="center">
        <template slot-scope="{ row }">
          <el-link type="primary" v-if="row.status == 0">审核中</el-link>
          <el-link type="primary" v-if="row.status == 1">审核通过</el-link>
          <el-link type="primary" v-if="row.status == 2">已驳回</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()"
    />
  </div>
</template>

<script>
import search from "../../search";
import { mapGetters } from "vuex";
import api from "@/api/second/coordinationManage/cooperateList";
export default {
  components: {
    search,
  },
  data() {
    return {
      searchParams: {},
      dataList: [],
      tableHeight: document.documentElement.clientHeight - 305,
      page: {
        page: 1,
        limit: Math.floor(
          (document.documentElement.clientHeight - 305 - 45) / 45
        ),
      },
      count: 0,
      showEdit: false,
      loading: false,
    };
  },
  computed: {
    ...mapGetters(["formatDep", "user"]),
  },
  created() {
    this.getDataList();
  },
  methods: {
    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.searchParams.leaderDept = this.user.user.deptId
      api
        .getConstraintDataList(Object.assign({}, this.page, this.searchParams))
        .then((res) => {
          let data = res.data.data;
          this.count = data.total;
          this.dataList = data.records;
        })
        .catch((e) => {
          this.dataList = [];
          this.count = 0;
        })
        .finally(() => {
          this.loading = false;
        });
    },
  },
  filters: {
    formatList(val) {
      if (val) {
        return val.join("\n");
      }
    },
  },
};
</script>

<style scoped>
.warning {
  display: flex;
  margin-bottom: 20px;
}
</style>