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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
<template>
  <div class="product">
    <div class="borrower" v-for="(item, index) in contractArr" :key="index">
      <p class="title">
        <span></span>
        基础合同信息
      </p>
      <el-form :model="contractForm[index]" :rules="rules" ref="contractForm" size="small" inline label-width="165px">
        <div class="form">
          <el-form-item label="基础合同签署方名称" v-if="contractArr[index].signatoryName.visible" prop="signatoryName"
            :class="{ isDifferent: item.signatoryName.isDifferent }">
            <el-input v-model="contractForm[index].signatoryName"
              :disabled="!contractArr[index].signatoryName.writeAble"></el-input>
          </el-form-item>
          <el-form-item label="基础合同签署方统一信用代码" v-if="contractArr[index].signatoryCode.visible" prop="signatoryCode"
            :class="{ isDifferent: item.signatoryCode.isDifferent }">
            <el-input v-model="contractForm[index].signatoryCode"
              :disabled="!contractArr[index].signatoryCode.writeAble"></el-input>
          </el-form-item>
          <el-form-item label="基础合同签署方法人名称" v-if="contractArr[index].signatoryUserName.visible" prop="signatoryUserName"
            :class="{ isDifferent: item.signatoryUserName.isDifferent }">
            <el-input v-model="contractForm[index].signatoryUserName"
              :disabled="!contractArr[index].signatoryUserName.writeAble"></el-input>
          </el-form-item>
          <el-form-item label="基础合同签署方法人身份证" v-if="contractArr[index].signatoryCertId.visible" prop="signatoryCertId"
            :class="{ isDifferent: item.signatoryCertId.isDifferent }">
            <el-input v-model="contractForm[index].signatoryCertId"
              :disabled="!contractArr[index].signatoryCertId.writeAble"></el-input>
          </el-form-item>
          <el-form-item label="基础合同签署方法人手机号" v-if="contractArr[index].signatoryPhone.visible" prop="signatoryPhone"
            :class="{ isDifferent: item.signatoryPhone.isDifferent }">
            <el-input v-model="contractForm[index].signatoryPhone"
              :disabled="!contractArr[index].signatoryPhone.writeAble"></el-input>
          </el-form-item>
          <el-form-item label="收款人名称" v-if="contractArr[index].receivingName.visible" prop="receivingName"
            :class="{ isDifferent: item.receivingName.isDifferent }">
            <el-input v-model="contractForm[index].receivingName"
              :disabled="!contractArr[index].receivingName.writeAble"></el-input>
          </el-form-item>
          <el-form-item label="收款人银行账户名称" v-if="contractArr[index].receivingBankName.visible" prop="receivingBankName"
            :class="{ isDifferent: item.receivingBankName.isDifferent }">
            <el-input v-model="contractForm[index].receivingBankName"
              :disabled="!contractArr[index].receivingBankName.writeAble"></el-input>
          </el-form-item>
          <el-form-item label="收款人银行账户开户行" v-if="contractArr[index].receivingBank.visible" prop="receivingBank"
            :class="{ isDifferent: item.receivingBank.isDifferent }">
            <el-input v-model="contractForm[index].receivingBank"
              :disabled="!contractArr[index].receivingBank.writeAble"></el-input>
          </el-form-item>
          <el-form-item label="收款人银行账户账号" v-if="contractArr[index].receivingAccount.visible" prop="receivingAccount"
            :class="{ isDifferent: item.receivingAccount.isDifferent }">
            <el-input v-model="contractForm[index].receivingAccount"
              :disabled="!contractArr[index].receivingAccount.writeAble"></el-input>
          </el-form-item>
 
 
          <!-- 通讯地址(省) -->
          <el-form-item label="签署方地址(省份)" v-if="contractArr[index].signatoryProvince.visible" prop="signatoryProvince"
            :class="{ isDifferent: item.signatoryProvince.isDifferent }">
            <el-select v-model="contractForm[index].signatoryProvince" filterable clearable
              :disabled="!contractArr[index].signatoryProvince.writeAble" placeholder="支持输入搜索选择" @change="
                getprovince(
                  contractForm[index].signatoryProvince,
                  'signatoryCityList',
                  contractForm[index],
                  function (arr) {
                    signatoryCityList = arr;
                  }
                )
              ">
              <el-option v-for="(item, index) in provinceList" :key="index" :label="item.itemname" :value="item.itemno">
              </el-option>
            </el-select>
          </el-form-item>
 
          <!-- 通讯地址(市) -->
          <el-form-item label="签署方地址(城市)" v-if="contractArr[index].signatoryCity.visible" prop="signatoryCity"
            :class="{ isDifferent: item.signatoryCity.isDifferent }">
            <el-select v-model="contractForm[index].signatoryCity" filterable clearable
              :disabled="!contractArr[index].signatoryCity.writeAble" placeholder="支持输入搜索选择">
              <el-option v-for="(item, index) in signatoryCityList" :key="index" :label="item.itemname"
                :value="item.itemno"></el-option>
            </el-select>
          </el-form-item>
 
          <!-- 通讯地址(详细) -->
          <el-form-item label="签署方详细地址" v-if="contractArr[index].signatoryAddress.visible" prop="signatoryAddress"
            :class="{ isDifferent: item.signatoryAddress.isDifferent }">
            <el-input v-model="contractForm[index].signatoryAddress"
              :disabled="!contractArr[index].signatoryAddress.writeAble"></el-input>
          </el-form-item>
        </div>
 
      </el-form>
 
      <el-button type="primary" icon="el-icon-circle-plus-outline" v-if="applyInfo.phaseNo <= '0060' && !isReadonly"
        @click="addContractLine" size="medium">新增</el-button>
      <el-table stripe :data="contractInfoList" style="margin-top: 30px" highlight-current-row :cell-style="cell"
        :header-cell-style="{ background: '#f5f5f5', color: '#222222' }">
        <el-table-column min-width="200">
          <template slot="header">
            <span>
              <span style="padding-left: 8px">合同编号</span>
            </span>
          </template>
          <template slot-scope="{ row }">
            <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.contractNo
            }}</span>
            <el-input style="padding-left: 15px" size="small" v-show="row.isEdit" v-model="row.contractNo"
              placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column min-width="200">
          <template slot="header">
            <span>
              <!-- <span class="red-star">*</span> -->
              <span style="padding-left: 8px">合同名称</span>
            </span>
          </template>
          <template slot-scope="{ row }">
            <span style="padding-left: 8px" v-show="!row.isEdit">{{
                row.contractName
            }}</span>
            <el-input style="padding-left: 15px" size="small" v-show="row.isEdit" v-model="row.contractName"
              placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column min-width="200">
          <template slot="header">
            <span>
              <span style="padding-left: 8px">应收账款债务人</span>
            </span>
          </template>
          <template slot-scope="{ row }">
            <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.obligorName
            }}</span>
            <!-- <el-input style="padding-left: 15px" size="small" v-show="row.isEdit" v-model="row.obligorName"
              placeholder="请输入"></el-input> -->
 
               
          <el-select size="small" v-show="row.isEdit" v-model="row.obligorNo" @change="changeObligor(row)" filterable placeholder="请选择">
            <el-option
              v-for="(item,index) in enpAdmitInList"
              :key="index"
              :label="item.enterprisename"
              :value="item.serialno">
            </el-option>
          </el-select>
              <!-- <el-select></el-select> -->
          </template>
        </el-table-column>
        <!-- <el-table-column min-width="200">
          <template slot="header">
            <span>
              <span style="padding-left: 8px">签署方地址(省份)</span>
            </span>
          </template>
          <template slot-scope="{ row }">
            <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.signatoryProvinceCn
            }}</span>
            <el-select v-show="row.isEdit" v-model="row.signatoryProvince" filterable clearable placeholder="支持输入搜索选择"
              @change="
                getprovince(
                  row.signatoryProvince,
                  'signatoryCityList',
                  row,
                  function (arr) {
                    signatoryCityList = arr;
                  }
                )
              ">
              <el-option v-for="(item, index) in provinceList" :key="index" :label="item.itemname" :value="item.itemno">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column min-width="200">
          <template slot="header">
            <span>
              <span style="padding-left: 8px">签署方地址(城市)</span>
            </span>
          </template>
          <template slot-scope="{ row }">
            <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.signatoryCityCn
            }}</span>
            <el-select v-show="row.isEdit" v-model="row.signatoryCity" filterable clearable placeholder="支持输入搜索选择">
              <el-option v-for="(item, index) in signatoryCityList" :key="index" :label="item.itemname"
                :value="item.itemno"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column min-width="200">
          <template slot="header">
            <span>
              <span style="padding-left: 8px">签署方详细地址</span>
            </span>
          </template>
          <template slot-scope="{ row }">
            <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.signatoryAddress
            }}</span>
            <el-input v-show="row.isEdit" v-model="row.signatoryAddress"></el-input>
          </template>
        </el-table-column> -->
        <el-table-column min-width="200">
          <template slot="header">
            <span>
              <span style="padding-left: 8px">合同金额</span>
            </span>
          </template>
          <template slot-scope="{ row }">
            <!-- <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.contactAmount
            }}</span>
            <el-input v-show="row.isEdit" v-model="row.contactAmount"></el-input> -->
            <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.contactAmount !== '' ? formatMoney(row.contactAmount) : "--"
            }}</span>
            <el-input size="small" v-show="row.isEdit" v-model="row.contactAmount" placeholder="请输入"
              @blur="row.contactAmount = formatMoney(row.contactAmount)"></el-input>
          </template>
        </el-table-column>
        <el-table-column min-width="200">
          <template slot="header">
            <span>
              <span style="padding-left: 8px">基础交易合同暂定总价</span>
            </span>
          </template>
          <template slot-scope="{ row }">
            <!-- <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.tempTotalAmt
            }}</span>
            <el-input v-show="row.isEdit" v-model="row.tempTotalAmt "></el-input> -->
            <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.tempTotalAmt !== '' ? formatMoney(row.tempTotalAmt) : "--"
            }}</span>
            <el-input size="small" v-show="row.isEdit" v-model="row.tempTotalAmt" placeholder="请输入"
              @blur="row.tempTotalAmt = formatMoney(row.tempTotalAmt)">
            </el-input>
          </template>
        </el-table-column>
        <el-table-column min-width="200">
          <template slot="header">
            <span>
              <span style="padding-left: 8px">签署日期</span>
            </span>
          </template>
          <template slot-scope="{ row }">
            <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.signedDate
            }}</span>
            <el-date-picker v-show="row.isEdit" v-model="row.signedDate" type="date" format="yyyy/MM/dd"
              value-format="yyyy/MM/dd" placeholder="选择日期">
            </el-date-picker>
          </template>
        </el-table-column>
 
        <el-table-column min-width="200">
          <template slot="header">
            <span>
              <span style="padding-left: 8px">合同有效截止日期</span>
            </span>
          </template>
          <template slot-scope="{ row }">
            <span style="padding-left: 15px" v-show="!row.isEdit">{{
                row.signedEndDate
            }}</span>
            <el-date-picker v-show="row.isEdit" v-model="row.signedEndDate" type="date" format="yyyy/MM/dd"
              value-format="yyyy/MM/dd" placeholder="选择日期">
            </el-date-picker>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="110" v-if="applyInfo.phaseNo <= '0060' && !isReadonly">
          <template slot-scope="scope">
            <el-button type="text" @click.native="handleEdit(scope.row)" v-if="!scope.row.isEdit">修改</el-button>
            <el-button type="text" @click.native="handleSave(scope.row, scope.$index)" v-else>保存</el-button>
            <el-button type="text" @click.native="handleCancel(scope.row, scope.$index)" v-if="scope.row.isCancel">取消
            </el-button>
            <el-button type="text" @click.native="handleDelete(scope.row, scope.$index)" v-else>删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="height:30px"></div>
    <!-- 贷款合同信息 -->
    <!-- <loanContactList :applyInfo="applyInfo" v-if="applyInfo.phaseNo == '0060'" /> -->
 
    <!-- 中登网登记信息 -->
    <registerInfo :applyInfo="applyInfo" v-if="applyInfo.phaseNo >= '0060'" />
 
    <div :class="[applyInfo.phaseNo >= '0040' ? 'fixedBtn' : 'btn']">
      <el-button size="medium" plain @click="saveDraft"
        v-if="(applyInfo.phaseNo == '0040' || applyInfo.phaseNo == '0010') && !isReadonly">保存草稿</el-button>
      <el-button size="medium" plain @click="save" v-if="applyInfo.phaseNo > '0040' && writeAble">保存</el-button>
      <el-button size="medium" plain @click="prevStep"
        v-if="(applyInfo.phaseNo == '0040' || applyInfo.phaseNo == '0010' || applyInfo.phaseNo == '0060') && !isReadonly">
        上一步</el-button>
      <el-button size="medium" plain @click="prevStep" v-else>上一步
      </el-button>
      <el-button size="medium" type="primary" @click="submit()"
        v-if="(applyInfo.phaseNo == '0040' || applyInfo.phaseNo == '0010' || applyInfo.phaseNo == '0060') && !isReadonly">
        下一步</el-button>
      <el-button size="medium" type="primary" @click="nextPage()" v-else>下一步
      </el-button>
    </div>
  </div>
</template>
<script>
// 基础合同信息
import {
  qryBaseContractDetail,
  qryBaseContractList,
  getDictionaryList,
  updateBaseContract,
  getProvinceCodeList,
  delBaseContractInfo,
  saveOrUpdateBaseInfo,
  submitBaseInfo,
  qryEnterpriseList
} from "@/api/product";
import common from "@/utils/common";
import loanContactList from "./loanContactList";
import registerInfo from "./registerInfo";
 
export default {
  components: { loanContactList, registerInfo },
  data() {
    return {
      applyInfo: this.$store.state.product.applyInfo,
      applyMenu: this.$store.state.product.applyMenu,
      isUploadAble: false,
      initialArr: [], //初始化数据
      contractForm: [],
      contractArr: [],
      // borrowertypeList: [],
      provinceList: [],
      signatoryCityList: [],
      receivingBankNameList: [],//银行名称列表,下拉选项
      rules: {},
      writeAble: false,
      contractInfoList: [],
      enpAdmitInList: [],
    };
  },
  computed: {
    isReadonly() {
      return this.$parent._data.applyMenu[this.$parent._data.activeIndex].readonly == 'Y'
    }
  },
  async created() {
    const { applyInfo } = this;
    this.$parent._data.loading = true;
    this.isUploadAble = applyInfo.phaseNo <= "0040" ? false : true;
    // 查询基础合同信息信息
    let result = await this.getBaseContractDetail();
    result = this.compareFields(result);
    this.getBorrowerData(result);
 
    this.contractInfoList = await this.getBaseContractList()
 
    this.writeAble = this.contractArr[0].signatoryName.writeAble || this.contractArr[0].signatoryUserName.writeAble;
    //基础合同信息类型选项
    // this.borrowertypeList = await this.qryDictionaryList("BorrowerType");
    // this.receivingBankNameList = await this.qryDictionaryList("receivingBankName");
    this.qryEnterpriseList()
    this.$parent._data.loading = false;
  },
  methods: {
    //单元格css
    cell({ row, column, rowIndex, columnIndex }) {
      const { applyInfo, index } = this;
      const { refuseFlag } = applyInfo;
      if (refuseFlag == 1) {
        const { houseInfoBatch } = this.$store.state.product.fields;
        const { propertyList } = houseInfoBatch[index];
        for (let i = 0; i < propertyList.length; i++) {
          const object = propertyList[i];
          for (const key in object) {
            if (row[key] != object[key] && column.property == key) {
              return { color: "#222", "font-weight": "700" };
            }
          }
        }
      }
    },
    // 金额格式化
    formatMoney(value) {
      if (value) {
        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;
      } else {
        return value
      }
    },
    //金额变成数字
    moneyFomatNumber(number, n) {
      if (!number) return ''
      if (typeof number == 'number') return number
      if (number != null && number != "" && number != undefined) {
        number = number.replace(/,/g, ""); //去除千分位的','
        if (isNaN(number)) {
          //判断是否是数字
          number = "0";
        } else {
          number = Math.round(number * Math.pow(10, n)) / Math.pow(10, n); //n幂
          number = number.toString();
        }
      } else {
        number = "0";
      }
      //a.indexOf(x,y);返回x值在a字符串值中从y位置开始检索首次出现的位置
      var numLength = number.indexOf(".");
      //判断传递的值是整数增加小数点再补"0"
      if (numLength < 0) {
        numLength = number.length;
        number += ".";
      }
      //不足n位小数的,循环补"0"
      while (number.length <= numLength + n) {
        number += "0";
      }
      return number;
    },
 
    async qryEnterpriseList() {
      const enpAdmitInList = await qryEnterpriseList({})
      this.enpAdmitInList = enpAdmitInList.result
    },
    changeObligor(row) {
      let data =  this.enpAdmitInList.find(res=> res.serialno == row.obligorNo) 
      row.obligorName = data.enterprisename
    },
    compareFields(result) {
      const { applyInfo } = this;
      const { refuseFlag } = applyInfo;
      if (refuseFlag == 1) {
        const { customerInfo } = this.$store.state.product.fields;
        for (const key in customerInfo) {
          if (result[key].value != customerInfo[key]) {
            result[key]["isDifferent"] = true;
          }
        }
      }
      return result;
    },
    // 处理数据,将数据重新排列
    async getBorrowerData(result) {
      const { applyInfo } = this;
      const { phaseNo } = applyInfo;
      this.contractForm = [];
      this.initialArr = [];
      this.contractArr = [];
      this.contractArr.push(result);
      // 取数组第一个作为校验规则
      this.contractArr.forEach((val, index) => {
        if (index == 0) {
          for (const key in val) {
            this.rules[key] = [];
            // 自定义规则校验
            switch (key) {
              // case "contactAmount":
              //   this.rules[key].push(common.validate("amount"));
              //   break;
              case "signedDate":
                this.rules[key].push({
                  required: true,
                  message: "请输入日期",
                  trigger: "change",
                });
                break;
              default:
                break;
            }
            // 必填校验
            if (val[key].required) {
              this.rules[key].push({
                required: true,
                message: `请输入${val[key].filedDescription}`,
                trigger: "change",
              });
            }
            if (this.isReadonly) {
              val[key].writeAble = false
            }
          }
        }
        const obj = {};
        for (const key in val) {
          obj[key] = val[key].value;
        }
        this.contractForm.push(obj);
        this.initialArr.push(Object.assign({}, obj));
      });
      // 判断如果是贷款就要添加下面的逻辑
      if (phaseNo >= "0040") {
        // 获取省枚举值
        getProvinceCodeList({}).then((res) => {
          this.provinceList = res.result;
        });
        // 根据省获取市
        this.contractForm[0].signatoryProvince
          ? (this.signatoryCityList = await common.qryCityCodeList(
            this.contractForm[0].signatoryProvince
          ))
          : "";
      }
    },
    // 查询基础合同信息
    getBaseContractDetail() {
      return new Promise((resolve) => {
        qryBaseContractDetail({
          relativeSerialNo: this.applyInfo.serialNo,
        }).then((res) => {
          resolve(res.result);
        });
      });
    },
    // 查询基础合同信息
    getBaseContractList() {
      return new Promise((resolve) => {
        qryBaseContractList({
          relativeSerialNo: this.applyInfo.serialNo,
        }).then((res) => {
          resolve(res.result);
        });
      });
    },
    // 保存基础合同信息接口
    handleUpdateBaseContract(form) {
      // form.applyserialno = this.applyInfo.serialNo;
      form.relativeSerialNo = this.applyInfo.serialNo;
      return new Promise((resolve) => {
        updateBaseContract(form).then((res) => {
          resolve(res);
        });
      });
    },
 
    // 保存基础合同信息草稿
    handleSubmitBaseInfo(form) {
      // form.applyserialno = this.applyInfo.serialNo;
      form.relativeSerialNo = this.applyInfo.serialNo;
      return new Promise((resolve) => {
        submitBaseInfo(form).then((res) => {
          resolve(res);
        });
      });
    },
    handleSaveOrUpdateBaseInfo(form) {
      // form.applyserialno = this.applyInfo.serialNo;
      form.relativeSerialNo = this.applyInfo.serialNo;
      return new Promise((resolve) => {
        saveOrUpdateBaseInfo(form).then((res) => {
          resolve(res);
        });
      });
    },
    qryDictionaryList(code) {
      return new Promise((resolve) => {
        getDictionaryList({
          codeNo: code,
        }).then((res) => {
          resolve(res.result);
        });
      });
    },
    addContractLine() {
      for (let i = 0; i < this.contractInfoList.length; i++) {
        if (this.contractInfoList[i].isEdit) {
          this.$message.warning("请先保存当前凭证信息再新增");
          return;
        }
      }
      this.contractInfoList.unshift({
        "contractNo": "",
        "contractName": "",
        "obligorName": "",
        "contactAmount": "",
        "tempTotalAmt": "",
        "signedDate": "",
        "tempTotalAmt": '4,000,000.00',
        "signedEndDate": "",
        "isEdit": true,
      });
    },
    //保存选中应收账款明细
    async handleSave(row, index) {
      // if (!row.contractNo) {
      //   this.$message.warning("应收账款名称不能为空");
      //   return;
      // }
      // if (!row.pjpamentendday) {
      //   this.$message.warning("应收账款到期日不能为空");
      //   return;
      // }
 
      for (let i = 0; i < this.contractInfoList.length; i++) {
        if (
          index != i &&
          row.billname == this.contractInfoList[i].contractNo &&
          row.billtype == this.contractInfoList[i].contractName
        ) {
          this.$message.warning("合同已存在,请重新填写");
          return;
        }
      }
      if (this.applyInfo.serialNo) {
        row.relativeSerialNo = this.applyInfo.serialNo;
 
        row.contactAmount = this.moneyFomatNumber(row.contactAmount, 2);
        row.tempTotalAmt = this.moneyFomatNumber(row.tempTotalAmt, 2);
        // 同步返回保存是否成功
        const res = await this.handleUpdateBaseContract(row);
        if (res.code == "00") {
          this.contractInfoList = await this.getBaseContractList()
          this.$message.success("保存成功");
        } else {
          return;
        }
      }
    },
 
    //修改选中应收账款明细
    handleEdit(row) {
      for (let i = 0; i < this.contractInfoList.length; i++) {
        if (this.contractInfoList.length > 1 && this.contractInfoList[i].isEdit) {
          this.$message.warning("请先保存当前合同");
          return;
        }
      }
      this.$set(row, "isEdit", true);
      this.$set(row, "isCancel", true);
    },
 
    //取消选中应收账款明细
    handleCancel(row, index) {
      const arr = [];
      for (let i = 0; i < this.initialArr.length; i++) {
        if (i == index) {
          for (const key in row) {
            if (
              key != "isEdit" &&
              key != "isCancel" &&
              row[key] != this.initialArr[i][key]
            ) {
              arr.push(key);
            }
          }
        }
      }
      if (arr.length) {
        common.comfirm("提示", "当前有数据未保存,是否放弃保存?", () => {
          this.$set(row, "isEdit", false);
          this.$set(row, "isCancel", false);
          arr.forEach((val) => {
            for (const key in this.initialArr[index]) {
              if (this.initialArr[index].hasOwnProperty(val)) {
                this.creditLineArray[index][key] = this.initialArr[index][key];
              }
            }
          });
        });
      } else {
        this.$set(row, "isEdit", false);
        this.$set(row, "isCancel", false);
      }
    },
    //删除选中应收账款明细
    async handleDelete(row, index) {
      if (!row.isEdit) {
        common.comfirm(
          "提示",
          `请确认是否需要删除:${row.contractNo}?`,
          async () => {
            if (row.contractNo) {
              const res = await this.del(row.contractId);
              if (res.code == "00") {
                this.$message.success("删除成功");
                this.contractInfoList = await this.getBaseContractList()
              }
            }
          }
        );
      } else {
        this.contractInfoList = await this.getBaseContractList()
      }
    },
    // 删除接口
    del(contractId) {
      return new Promise((resolve) => {
        delBaseContractInfo({
          contractId: contractId,
        }).then((res) => {
          resolve(res);
        });
      });
    },
    // 下一页
    nextPage() {
      // 调用父组件的查询左侧tab的方法
      this.$parent.updateApplyTabTree("基础合同信息");
    },
    // 提交
    async submit() {
      if (!common.validateForm(this.$refs.contractForm).flag) return;
      this.$parent._data.loading = true;
      const res = await this.handleSaveOrUpdateBaseInfo(this.contractForm[0]);
      if (res.code == "00") {
        const result = await this.getBaseContractDetail();
        this.getBorrowerData(result);
        this.nextPage();
      }
      this.$parent._data.loading = false;
    },
    // 保存需要校验数据完整性
    async save() {
      if (!common.validateForm(this.$refs.contractForm).flag) return;
      this.$parent._data.loading = true;
      // 保存
      const res = await this.handleSaveOrUpdateBaseInfo(this.contractForm[0]);
      // 保存成功查询列表数据
      if (res.code == "00") {
        const result = await this.getBaseContractDetail();
        // 将数据重新排列
        this.getBorrowerData(result);
        this.$message.success("保存成功");
      }
      this.$parent._data.loading = false;
    },
    // 保存草稿
    async saveDraft() {
      this.$parent._data.loading = true;
      const params = this.contractForm[0];
 
      const res = await this.handleSubmitBaseInfo({
        ...params,
        relativeSerialNo: params.applyserialno,
      });
      // 保存成功查询列表数据
      if (res.code == "00") {
        const result = await this.getBaseContractDetail();
        // 将数据重新排列
        this.getBorrowerData(result);
        this.$message.success("保存成功");
        // 保存草稿需要调用父组件的查询左侧tab的方法
        // this.$parent.getApplyTabTree();
      }
      this.$parent._data.loading = false;
    },
    // 上一步或上一页
    prevStep() {
      this.applyMenu.forEach((val, index) => {
        if (val.tabname == "基础合同信息") {
          common.tabInfo(
            this.applyMenu[index - 1].tabname,
            this.applyInfo.flowno,
            this
          );
        }
      });
    },
  },
 
  beforeRouteLeave(to, from, next) {
    for (let i = 0; i < this.contractForm.length; i++) {
      for (const key in this.contractForm[i]) {
        if (this.initialArr[i].hasOwnProperty(key)) {
          if (this.contractForm[i][key] != this.initialArr[i][key]) {
            // 页面有数据未保存
            common.comfirm(
              "提示",
              "当前页面有数据未保存,是否放弃保存?",
              () => {
                next();
              }
            );
            return;
          }
        }
      }
    }
    next();
  },
};
</script>