<template>
  <div class="verify-total">
    <el-table :data="tableData" border>
      <el-table-column
        prop="enterpriseName"
        label="企业名称"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="hdName"
        label="发现问题"
        width="160"
      ></el-table-column>
      <el-table-column
        prop="hdRectificationDate"
        label="整改日期"
        width="140"
      ></el-table-column>
      <el-table-column label="整改后照片路径" width="140">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="transferUrl(scope.row.hdRectificationPic)"
            :preview-src-list="[transferUrl(scope.row.hdRectificationPic)]"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" width="140">
        <template slot-scope="scope">
          <div v-if="scope.row.verifyStatus === 1">审核已通过</div>
          <div v-else-if="scope.row.verifyStatus === 2">审核未通过</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="160">
        <template slot-scope="scope">
          <el-button type="warning" @click="approve(scope.row)"
            >审核通过</el-button
          >
          <el-button type="danger" @click="nopass(scope.row)"
            >审核未通过</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="curPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="curPageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalElements"
    >
    </el-pagination>
  </div>
</template>

<script>
import { getAllDangerToVerify, verifyDanger } from "@/api/secFound.js";
export default {
  data() {
    return {
      curPage: 1,
      curPageSize: 10,
      tableData: [],
      totalElements: 0
    };
  },
  mounted() {
    this.initAllVerifyDanger();
  },
  methods: {
    initAllVerifyDanger() {
      getAllDangerToVerify({
        page: this.curPage - 1,
        size: this.curPageSize
      }).then(res => {
        console.log(res, "getAllDangerToVerify getAllDangerToVerify");
      });
    },
    handleSizeChange(val) {
      this.curPageSize = val;
      this.initAllVerifyDanger();
    },
    handleCurrentChange(val) {
      this.curPage = val;
      this.initAllVerifyDanger();
    },
    approve(row) {
      verifyDanger({
        id: row.id,
        status: 1
      }).then(
        res => {
          this.$message({
            type: "success",
            message: "审核已通过"
          });
          // this.initAllVerifyDanger()
        },
        () => {
          this.$message.error("审核失败");
        }
      );
    },
    nopass(row) {
      verifyDanger({
        id: row.id,
        status: 2
      }).then(
        res => {
          this.$message({
            type: "success",
            message: "已设置审核未通过"
          });
        },
        () => {
          this.$message.error("审核失败");
        }
      );
    },
    transferUrl(hdPic) {
      if (hdPic) {
        return (
          "/hd_rectification_pic_to_verify/" +
          hdPic.split("/hd_rectification_pic_to_verify/")[1]
        );
      } else {
        return null;
      }
    }
  }
};
</script>

<style lang="scss">
.verify-total {
}
</style>
