<template>
  <el-dialog
      :title="title"
      width="500px"
      center
      :wrapperClosable="false"
      :visible.sync="visible"
      :before-close="handleClose">
    <div class="page-dialog">
      <div class="btn-box" style="height: 200px">
        <el-button size="small" plain type="info" v-if="result.status==='FAIL'">生成失败</el-button>
        <el-button size="small" plain type="success" @click="handleClick" v-else-if="result.status==='SUCCESS'">点击下载
        </el-button>
        <el-button size="small" plain type="primary" v-else-if="result.status==='PROCESS'">生成中...</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import BlockHeader from "@/components/byh/componments/blockHeader";
import * as moment from "moment";

export default {
  name: 'SettleReport',
  components: {
    BlockHeader
  },
  props: {
    title: {
      type: String,
      required: true,
    },
    visible: {
      type: Boolean,
      required: true
    },
    params: {
      type: Object,
      required: true
    },
  },
  data() {
    return {
      //FAIL：失败
      //SUCCESS ：成功
      //PROCRSS：处理中
      result: {},
      form: {
        batchNumber: '',
        capitalCode: '',
        certNo: "",
        certName: "",
        loanNo: ""
      }
    }
  },

  async created() {
    const params = this.params;
    // console.log(params, '很多信息');
    if (params.loanNo) {
      const {capitalCode, clientName, certNo,idCard, loanNo,externalNo} = params;
      this.form.capitalCode = capitalCode;
      this.form.certNo = idCard;
      this.form.certName = clientName;
      //this.form.loanNo = loanNo;
      this.form.loanNo = externalNo;
      await this.init()
    }
  },
  methods: {
    headerStyle() {
      return "tableHeaderStyle";
    },
    async init() {
      const res = await this.$$post('/back/settleReport', this.form);
      const {success, result} = res.data;
      if (success && result !== null) {
        this.result = result;
      }
    },
    /*日期*/
    dateFormats: function (row, column) {
      let date = row[column.property]
      if (date === undefined) {
        return ''
      }
      return moment(date).format("YYYY-MM-DD")
    },
    handleClose() {
      this.$emit("handleClose");
    },
    handleClick() {
      const url = this.result.fileUrl;
      window.open(url, "_blank");
    }
  }
}
</script>

<style>
.btn-box {
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
