<template>
  <div class="page">
    <el-table
      ref="table"
      v-loading="loading"
      :data="tableData"
      border
    >
      <el-table-column label="批次名" prop="batchName" align="center">
      </el-table-column>
      <el-table-column label="门类实体" prop="tableChnName" align="center">
      </el-table-column>
      <el-table-column label="当前全宗" prop="fondsNoCode" align="center">
      </el-table-column>
      <el-table-column label="档案数量" width="90" prop="recordNums" align="center">
      </el-table-column>
      <el-table-column label="质检率" width="80" prop="inspectionPercent" align="center">
        <template slot-scope="scope">
          {{scope.row.inspectionPercent}}%
        </template>
      </el-table-column>
      <el-table-column label="质检数量" width="90" prop="inspectionNums" align="center">
      </el-table-column>
      <el-table-column label="结果" width="80" prop="isPassed" align="center">
        <template slot-scope="scope">
          <el-tag type="warning" size="mini" v-if="!scope.row.isPassed">未完成</el-tag>
          <el-tag type="danger" size="mini" v-if="scope.row.isPassed==='F'">不合格</el-tag>
          <el-tag type="success" size="mini" v-if="scope.row.isPassed==='T'">合格</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="质检人" width="90" prop="createdBy" align="center">
      </el-table-column>
      <el-table-column label="操作" align="center" width="160">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            @click="check(scope.row)"
            style="color: #67C23A; font-weight:700"
            >检查
          </el-button>
          <el-divider direction="vertical"></el-divider>
          <el-button
            type="text"
            size="mini"
            @click="question(scope.row)"
            style="color: #409eff; font-weight:700"
            >问题记录
          </el-button>
          <el-divider direction="vertical"></el-divider>
          <el-popconfirm
            title="确定删除这条数据吗？"
            @confirm="handleDelete(scope.row)"
          >
            <el-button
              type="text"
              size="mini"
              style="color: #F56C6C; font-weight:700"
              slot="reference"
            >
              删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      layout="total, prev, pager, next, sizes"
      :page-size="pagination.pageSize"
      :page-sizes="[10, 20, 30, 50]"
      :current-page="pagination.pageNum"
      :total="pagination.total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { message } from "@/utils/common";
import { qualityHaveSet } from '@/api/dataManagement/qualityCheck'

export default {
  props: {
    loading: {
      type: Boolean,
      default: () => true
    },
    tableData: {
      type: Array,
      default: () => []
    },
    pagination: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      
    };
  },
  computed: {
    ...mapState({
      entity: state => state.qualityCheck.entity,
    })
  },
  methods: {
    check(row){
      const params = {
        entityId: this.entity.entityId
      }
      qualityHaveSet(params).then(res => {
        if(res.code === '100'){
          if(res.body.i !== 0){
            this.$store.commit("qualityCheck/SET_PAGE_TYPE", 3); // 跳转检查页面
            this.$store.commit("qualityCheck/SET_BATCH_ROW", row);
          }else{
            message.warning('请先设置质检项')
          }
        }
      })
    },
    question(row){
      this.$store.commit("qualityCheck/SET_PAGE_TYPE", 4); // 跳转问题记录页面
      this.$store.commit("qualityCheck/SET_BATCH_ROW", row);
    },
    handleDelete(row){
      this.$emit("delete", row.id);
    },
    handleCurrentChange(val) {
      this.pagination.pageNum = val;
      this.$emit("getData");
    },
    handleSizeChange(val) {
      this.pagination.pageSize = val;
      this.pagination.pageNum = 1;
      this.$emit("getData");
    }
  }
};
</script>

<style lang="scss" scoped>

</style>
