<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!-- 人工核验数据 -->
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px" @submit.native.prevent>
          <el-form-item label="受理编号" prop="serialNumber">
            <el-input v-model="queryParams.serialNumber" placeholder="请输入受理编号" clearable style="width: 240px"
                      @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="manualVerifyList">
          <el-table-column label="受理编号" align="center" prop="serialNumber" width="160" />
          <el-table-column label="业务类型" align="center" prop="withType">
            <template slot-scope="scope">
              <span v-if="scope.row.withType === 1">个人</span>
              <span v-if="scope.row.withType === 2">企业</span>
            </template>
          </el-table-column>
          <el-table-column label="企业名称" align="center" prop="enterpriseName">
            <template slot-scope="scope">
              <span v-if="scope.row.withType === 2">{{ scope.row.enterpriseName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="联系人" align="center" prop="contacts" width="100"/>
          <el-table-column label="联系电话" align="center" prop="phone" width="120"/>
          <el-table-column label="事项名称" align="center" prop="materialName" :show-overflow-tooltip="true" />
          <el-table-column label="材料名称" align="center" prop="listName" :show-overflow-tooltip="true" />
          <el-table-column label="核验状态" align="center" prop="dealStatus">
            <template slot-scope="scope">
              <span v-if="scope.row.dealStatus === 1" style="color: green;">通过</span>
              <span v-else-if="scope.row.dealStatus === 2"><span style="color: red;">未通过</span>（原因：{{ scope.row.reason }}）</span>
              <span v-else>待核验</span>
            </template>
          </el-table-column>
          <el-table-column label="核验人" align="center" prop="userName">
            <template slot-scope="scope">
              <span v-if="scope.row.userName">{{ scope.row.userName }}（{{ scope.row.deptName }}）</span>
            </template>
          </el-table-column>
          <el-table-column label="核验时间" align="center" prop="verifyTime" width="160" />
          <el-table-column label="创建时间" align="center" prop="createTime" width="160" />
          <el-table-column label="操作" align="center" width="160" fixed="right" class-name="small-padding fixed-width">
            <template slot-scope="scope" v-if="scope.row.dealStatus !== 1 && scope.row.dealStatus !== 2">
              <el-button size="mini" type="text" icon="el-icon-check" @click="handleVerify(scope.row, 1)">通过</el-button>
              <el-button size="mini" type="text" icon="el-icon-close" @click="handleVerify(scope.row, 2)" style="color: red;">不通过</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getList"/>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {listManualVerify, updateManualVerify} from "@/api/matter/record";

export default {
  name: "Manual",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serialNumber: undefined,
        dealStatus: undefined
      },
      // 总条数
      total: 0,
      // 人工核验记录数据
      manualVerifyList: null,
    };
  },
  watch: {},
  created() {
    this.getList();
  },
  methods: {
    /** 查询人工核验记录数据 */
    getList() {
      this.loading = true;
      listManualVerify(this.queryParams).then(response => {
        this.manualVerifyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    verifyManual(params) {
      updateManualVerify(params).then((response) => {
        if (response.code == 200) {
          this.$modal.msgSuccess("核验成功");
          this.getList()
          return
        }
        this.$modal.msgError("核验失败")
      });
    },
    /** 核验 */
    handleVerify(data, status) {
      this.$confirm('您选择的核验结果是【' + (status == 1 ? '通过' : '不通过') + '】, 是否继续？', '温馨提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = {
          "id": data.id,
          "dealStatus": status
        }
        if (status === 2) {
          this.noPass(params)
        } else {
          this.verifyManual(params)
        }
      }).catch(() => {
      })
    },
    noPass(params) {
      this.$prompt('请输入不通过理由', '温馨提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        if (!value || !value.trim()) {
          this.$modal.msgError("理由不能为空")
          return
        }
        params.reason = value
        this.verifyManual(params)
      }).catch(() => {
      })
    }
  }
};
</script>
