zhaoxiaoqiang1
2026-01-04 f1d30d03186c79ca2cbcfe60d6d2ce7d73fba97b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<template>
  <div class="trial">
    <el-dialog :visible.sync="trialVisible" center :modal-append-to-body="false" :close-on-click-modal='false' @close="closeDialog">
      <el-button type="primary" icon="el-icon-download" size="small" @click="exportExcel" v-no-more-click>导出Excel</el-button>
      <el-table 
        stripe
        id="trialData" 
        :max-height='528' 
        :data="trialData" 
        :header-cell-style="{background:'#f5f5f5',color:'#222222'}" 
        highlight-current-row
        v-loading="loading"
      >
        <el-table-column prop="periodno" label="期次" width="50"></el-table-column>
        <el-table-column prop="pstype" width="150" label="还款计划类型"></el-table-column>
        <el-table-column prop="paydate" width="120" label="应还日期"></el-table-column>
        <el-table-column prop="payprincipalamt" width="120" label="应还本金"></el-table-column>
        <el-table-column prop="waiveprincipalamt" width="120" label="调整本金"></el-table-column>
        <el-table-column prop="payinterestamt" width="120" label="应还利息"></el-table-column>
        <el-table-column prop="waiveinterestamt" width="120" label="调整利息"></el-table-column>
        <el-table-column prop="payinterestamtfee" width="120" label="应还费用"></el-table-column>
        <el-table-column prop="waivefee" width="120" label="调整费用"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="closeDialog">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { 
  trialRepaymentPlan,
} from '@/api/product'
import { setStorage,getStorage } from '@/utils/storage'
import FileSaver from "file-saver";
import XLSX from "xlsx";
export default {
  props:['visible'],
  data () {
    return {
      trialData:[],
      loading:false,
    }
  },
  computed: {
    trialVisible:{
      get(){
        return this.visible
      },
      set(){}
    }
  },
  created () {
    this.trialRepaymentPlan()
  },
  methods: {
    // 试算
    trialRepaymentPlan(){
      this.loading = true
      trialRepaymentPlan({
        serialno:this.$store.state.product.applyInfo.serialNo
      }).then(res=>{
        this.loading = false
        if(res.code=='00'){
          this.trialData = res.result.paymentScheduleRspList
          this.trialData.forEach(row => {
            for (const key in row) {
              if(
                key == 'payprincipalamt' ||
                key == 'waiveprincipalamt' ||
                key == 'payinterestamt' ||
                key == 'waiveinterestamt' ||
                key == 'payinterestamtfee' ||
                key == 'waivefee' 
              ){
                row[key] = this.formatMoney(row[key])
              }
            }
          });
        }
      })
    },
    closeDialog(){
      this.$emit('closeTrial',false)
    },
    //设置excel行高列宽
    auto_width (ws, data) {
      /*set worksheet max width per col*/
      const colWidth = data.map(row =>
        row.map(val => {
          /*if null/undefined*/
          return {
            wch: 15
          };
        })
      );
      /*start in the first row*/
      let resultc = colWidth[0];
      for (let i = 1; i < colWidth.length; i++) {
        for (let j = 0; j < colWidth[i].length; j++) {
          if (resultc[j]["wch"] < colWidth[i][j]["wch"]) {
            resultc[j]["wch"] = colWidth[i][j]["wch"];
          }
        }
      }
      ws["!cols"] = resultc;
      const rowHeight = data.map(row => {
        return {
          hpt: 15
        };
      });
      ws["!rows"] = rowHeight;
    },
    formatJson (filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    exportExcel() {
      const xlsxParam = { raw: true };//转换成excel时,使用原始的格式
      const wb = XLSX.utils.table_to_book(document.querySelector('#trialData'),xlsxParam);
      const filterVal = ['periodno', 'pstype','paydate', 'payprincipalamt','waiveprincipalamt','payinterestamt','waiveinterestamt','payinterestamtfee','waivefee'];  
      const data = this.formatJson(filterVal, this.trialData);
      this.auto_width(wb.Sheets.Sheet1, data);
      const wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        FileSaver.saveAs(
          new Blob([wbout], { type: "application/octet-stream;charset=utf-8" }),
          `${this.$store.state.product.applyInfo.customerName + '-' + this.$store.state.product.applyInfo.productName + '-' + this.$store.state.product.applyInfo.serialNo}.xlsx`
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    // 金额格式化
    formatMoney(value) {
      if (value||value === 0) {
        value =
          parseFloat((value + "").replace(/[^\d\.-]/g, "")).toFixed(2) + "";
        if (value == "NaN") return;
        let l = value
          .split(".")[0]
          .split("")
          .reverse();
        let r = value.split(".")[1];
        let t = "";
        for (let i = 0; i < l.length; i++) {
          t += l[i] + ((i + 1) % 3 === 0 && i + 1 !== l.length ? "," : "");
        }
        return (
          t
            .split("")
            .reverse()
            .join("") +
          "." +
          r
        );
      }
    },
  }
}
</script>
<style lang="stylus" scoped>
.trial
  &>>>.el-dialog
    width auto
    max-width calc(100% - 180px)
    min-width 850px
    max-height 100%
    overflow hidden
    margin 0 !important
    position absolute
    left 50%
    top 50%
    transform translate(-50%,-50%)
    .el-dialog__body
      padding 20px
      #trialData
        margin-top 20px
    .el-dialog__header
      padding 0
    .el-dialog__footer
      padding 0 0 20px
      .el-button
        width: 120px
        font-size: 14px
        line-height: 20px
        padding: 5px 0
</style>