<template>
  <el-dialog
      width="70%"
      class="client-data-dialog"
      :title="title"
      :visible.sync="dialogVisible"
      :before-close="handleClose">

    <div class="page-dialog">
      <block-header title="借款信息"></block-header>
      <el-table
          border
          size="mini"
          :highlight-current-row="true"
          :header-row-class-name="headerStyle"
          :data="data" stripe style="width: 100%;">
        <el-table-column align="center" width="140" prop="loanNo" label="借款编号"></el-table-column>
        <el-table-column align="center"  prop="gmtCreated" label="申请日期" :formatter="dateFormats"></el-table-column>
        <el-table-column align="center"  prop="startDate" label="放款日期" :formatter="dateFormats"></el-table-column>
        <el-table-column align="center"  prop="raiseAmt" label="放款本金"></el-table-column>
        <el-table-column align="center"  prop="capitalCode" label="放款资方" :formatter="capitalCodeFormat"></el-table-column>
        <el-table-column align="center"  prop="status" label="借款单状态" :formatter="loanStatusFormat"></el-table-column>
        <el-table-column align="center"  prop="cancelMemo" label="备注"></el-table-column>
        <el-table-column align="center"  label="查看详情">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="addLoanDetail(scope.row.loanNo)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

  </el-dialog>
</template>

<script>
import BlockHeader from "@/components/byh/componments/blockHeader";
import * as moment from "moment";
export default {
  name: 'AddUserServiceDialog',
  components: {
    BlockHeader
  },
  props: {
    dialogVisible: {
      type: Boolean,
      required: true,
    },
    title: {
      type: String,
      required: true,
    },
    params: {
      type: Object,
      required: true
    },
  },
  data() {
    return {
      data: []
    }
  },
  async created() {
    const {clientNo} = this.params;
    const res = await this.$$post('/loan/getLoanListByClientNo/' + clientNo);
    const {success, result} = res.data;
    if (success && result !== null) {
      this.data = result;
    }
  },
  methods: {
    headerStyle() {
      return "tableHeaderStyle";
    },
    capitalCodeFormat: function (row, column) {
      let capitalCode = row['capitalCode'];
      return this.$enumUtils.toMsg('CapitalEnums', capitalCode);
    },
    /*日期*/
    dateFormats: function (row, column) {
      let date = row[column.property]
      if (date === undefined) {
        return ''
      }
      return moment(date).format("YYYY-MM-DD")
    },
    handleClose() {
      this.$emit("handleClose");
    },
    //根据借款信息查借款所有信息
    addLoanDetail(record) {
      this.isNeedAudit = true;
      this.$$get('/detail/customer/' + record).then(res => {
        if (res.data.code != 200) {
          // this.isShow = false;
          this.$message.error(res.data.message);
          return
        } else {
          //打开借款的面板
          this.activeNames = ['1', '2', '3', '4', '5', '8'];
          //还款计划
          if (res.data.result.planVo == null) {
            this.loanApplyList = [];
            this.isNeedAudit = false;
          } else {
            this.loanApplyList = res.data.result.planVo ? res.data.result.planVo : '';
            this.advanceLoanAmt.loanNo = res.data.result.applyVo.loanNo;
            this.advanceLoanAmt.bizType = res.data.result.applyVo.bizType;
            this.advanceLoanAmt.clientNo = res.data.result.applyVo.clientNo;
            this.clientNos = res.data.result.applyVo.clientNo;
            this.loanNos = res.data.result.applyVo.loanNo;
          }
          //借款信息
          if (res.data.result.loanVo == null) {
            this.loanVo = [];
          } else {
            this.loanVo = res.data.result.loanVo ? res.data.result.loanVo : '';
          }
          //借款信息放款信息
          this.loanModel = res.data.result.applyVo ? res.data.result.applyVo : '';
          //还款信息
          this.loanBackedData(res.data.result.applyVo.loanNo);
          //合同列表
          this.contractData(res.data.result.applyVo.loanNo);
        }

        //操作信息
        this.clientDailyInfo(res.data.result.applyVo.clientNo);

      }).catch(error => {
        this.$message.error(error || '网络异常，请稍后。。。');
      });
    },
  }
}
</script>

<style>

</style>
