<template>
  <el-dialog
    title="结清证明"
    width="700px"
    center
    :wrapperClosable="false"
    :visible.sync="visible"
    :before-close="handleClose"
  >
    <div class="page-dialog">
      <div class="settleType">
        <el-form :inline="true">
          <el-form-item label="结清证明类型模板">
            <template v-if="loanSign==='XH'">
              <el-select v-model="reportType" placeholder="请选择结清模板">
                <el-option
                    label="借款主体结清证明模板"
                    value="loanReport"
                ></el-option>
                <el-option
                    label="服务费主体结清证明模版-云腾"
                    value="ytServiceReport"
                ></el-option>
                <el-option
                    label="服务费主体结清证明模版-纳宇"
                    value="nyServiceReport"
                ></el-option>
              </el-select>
            </template>
            <template v-else>
              <el-select v-model="reportType" placeholder="请选择结清模板">
                <el-option
                    label="借款主体结清证明模板"
                    value="loanReport"
                ></el-option>
                <el-option
                    label="服务费主体结清证明模版"
                    value="serviceReport"
                ></el-option>
              </el-select>
            </template>

          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="generateReport"
              >生成结清证明</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div>
        <el-table :data="tableData" border style="width: 100%">
          <el-table-column prop="settleTypeStr" align="center" label="结清类型">
          </el-table-column>
          <el-table-column prop="operator" align="center" label="操作人">
          </el-table-column>
          <el-table-column prop="operationDate" align="center" label="操作时间">
          </el-table-column>
        </el-table>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      required: true,
    },
    visible: {
      type: Boolean,
      required: true,
    },
    params: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      reportType: "",
      tableData: [],
      certName: "",
      loanNo: "",
      loanSign:''
    };
  },
  created() {
    const params = this.params;
    console.log(params, "啦啦啦啦啦啦啦");
    if (params.loanNo) {
      const { clientName, loanSign,externalNo } = params;
      this.certName = clientName;
      this.loanSign = loanSign;
      this.loanNo = externalNo;
      this.queryReport(externalNo);
    }
  },
  methods: {
    //查询生成报告
    queryReport(externalNo) {
      this.$$get(`/loan/selectGenerate?loanNo=${externalNo}`).then((res) => {
        console.log(res, "报告");
        if (res.data.code == 200) {
          this.tableData = res.data.result;
        }
      });
    },
    //生成结清报告
    generateReport() {
      this.$confirm("是否确认生成", "", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 确定
          console.log(this.reportType, "模板类型");
          if (!this.reportType) {
            this.$message("请选择报告类型!");
            return;
          }
          const params = {};
          params.settleType = this.reportType;
          params.loanNo = this.loanNo;
          params.operator = localStorage.getItem("loginName");
         this.$$post(`/loan/generateSettleReport`, params).then((res) => {
            if (res.data.code == 200) {
              this.queryReport();
              this.$message({
                type: "success",
                message: "已生成!",
              });
            }else{
                this.$message(res.data.message)
            }
          });
        })
        .catch(() => {
          // 取消
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },

    handleClose() {
      this.$emit("handleClose");
    //   window.location.reload()
    },
  },
};
</script>

<style scoped>
</style>
