<template>
  <div class="enter-safe-manage-wrapper">
    <div class="enter-safe-tools-wrapper">
      <el-input
        v-model="searchEnterName"
        placeholder="请输入企业名称"
        style="margin-right: 30px; width: 50%"
      ></el-input>
      <el-button type="success" @click="searchEnters">查找</el-button>
    </div>
    <div class="enter-safe-enter-list-wrapper">
      <el-table :data="enterCertifyList" border>
        <el-table-column prop="companyName" label="企业名称"></el-table-column>
        <el-table-column
          prop="emergencyPlan"
          label="应急预案证书数量"
        ></el-table-column>
        <el-table-column
          prop="dualSystem"
          label="双体系证书数量"
        ></el-table-column>
        <el-table-column
          prop="standardization"
          label="标准化证书数量"
        ></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="toEnterCertifies(scope.row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="currentPageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalElements"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { certifyEnters } from "@/api/certify.js";
export default {
  data() {
    return {
      searchEnterName: "",
      queryEnter: "",
      loading: false,
      enterList: [],
      enterCertifyList: [
        {
          companyName: "威海兴茂置业有限公司",
          companyId: 71522,
          emergencyPlan: 20,
          dualSystem: 10,
          standardization: 10,
        },
        {
          companyName: "中国石油天然气股份有限公司山东威海销售分公司",
          companyId: 71520,
          emergencyPlan: 20,
          dualSystem: 10,
          standardization: 10,
        },
        {
          companyName: "威海经济技术开发区洪氏家居生活馆",
          companyId: 71519,
          emergencyPlan: 15,
          dualSystem: 12,
          standardization: 11,
        },
        {
          companyName: "威海市教育局经济技术开发区教育服务中心",
          companyId: 71517,
          emergencyPlan: 8,
          dualSystem: 3,
          standardization: 1,
        },
      ],
      currentPage: 1,
      currentPageSize: 10,
      totalElements: 10,
    };
  },
  methods: {
    initMethod() {
      let params = {
        page: this.currentPage - 1,
        size: this.currentPageSize,
      };
      if (this.searchEnterName) {
        params.enterpriseName = this.searchEnterName;
      }
      certifyEnters(params).then((res) => {
        console.log(res.totalElements);
        /**
         * {
          companyName: '威海市教育局经济技术开发区教育服务中心',
          companyId: 71517,
          emergencyPlan: 8,
          dualSystem: 3,
          standardization: 1
        }
         */
        this.enterCertifyList = [
          ...res.content.map((item) => {
            return {
              companyName: item.enterpriseName,
              companyId: item.enterpriseId,
              emergencyPlan: item.emergencyPlanNum,
              dualSystem: item.dualSystemNum,
              standardization: item.standardizationNum,
            };
          }),
        ];
        this.totalElements = res.totalElements;
      });
    },
    remoteMethod(query) {
      if (query !== "") {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;
          this.enterList = [];
        });
      }
    },
    toEnterCertifies(row) {
      this.$router.push("/train/entercertifymanage/" + row.companyId);
    },
    handleSizeChange(val) {
      this.currentPageSize = val;
      this.initMethod();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.initMethod();
    },
    searchEnters() {
      this.initMethod();
    },
  },
  mounted() {
    this.initMethod();
  },
};
</script>

<style lang="scss" scoped>
.enter-safe-manage-wrapper {
  width: 80%;
  margin: 30px auto;
  border-radius: 30px;
  padding: 30px;
  box-shadow: 0 0 9px 1px #eee;
  .enter-safe-tools-wrapper {
    width: 80%;
    margin: 30px auto;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 0 9px 1px #eee;
    display: flex;
    align-items: center;
    justify-content: flex-start;
  }
  .enter-safe-enter-list-wrapper {
    width: 80%;
    margin: 30px auto;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 0 9px 1px #eee;
  }
}
</style>