zhaoxiaoqiang
2021-07-28 9e6e98a8c6541354619f15e81009082db8d3ad14
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
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
<!--
 * @Author: 小明丶
 * @Date: 2019-07-10 16:37:08
 * @LastEditors: 小明丶
 * @LastEditTime: 2020-12-04 16:28:09
 * @Description: 模板详情页面  逻辑比较复杂~
 -->
<template>
    <div class="template-detail-box">
        <header class="header flex-start-g" :style="{background:$store.state.lastColor}">
            <svg class="icon" aria-hidden="true" style="width:25px;height:44px;fill:#fff;" @click="$router.back()">
                <use xlink:href="#iconzuojiantou"></use>
            </svg>
            <h4 class="title text-center-g">{{tempId || merId ? '产品管理' : '新增模板'}}</h4>
        </header>
 
        <div class="temp-name">
            <v-cell v-if="merId" label="模板" disabled readonly isLink :value="tempIndex ===0 ? '无模板' : currentTemp.tempName"
                @click.native="openTempModal()"></v-cell>
            <v-cell v-else label="模板名称" v-model="info.tempName" max="20" placeholder="请输入模板名称"> </v-cell>
        </div>
 
        <div class="product-box">
            <!-- <v-cell v-if="!merId" label="商户匹配规则" :value="areaIndex ===0 ? '无匹配规则' : currentRules.name" max="20"
                placeholder="请输入模板名称" readonly disabled isLink @click.native="openAreaModal()" class="det-btn"></v-cell> -->
            <p  class="btn-d" v-if="activeVal !== 1 && !merId && detArr.length > 0" @click="showDet">查看详情</p>
            <v-cell v-if="!merId" label="商户匹配规则" :value="activeVal == 1 ? '无匹配规则' : activeVal == 2 ? '选择省份规则':'选择渠道规则'" max="20"
                placeholder="请输入模板名称" readonly disabled isLink @click.native="openAreaModal()"> </v-cell>
            <!-- 产品 -->
            <div v-for="item in info.prodInfList" :key="item.prodId"
                :class="merId && tempIndex!==0 ? 'bg-gray' : 'bg-fff'">
                <div v-if="item.isShow !==0" style="margin-top:10px;">
                    <div class="flex-between-g p-title" :class="merId && tempIndex!==0 ? 'bg-gray' : ''">
                        <p>{{item.prodName}}</p>
                        <p v-if="item.prodId == 30000006 || item.prodId == 30000011">{{item.capitalStatusName}}</p>
                        <van-switch v-model="item.status" :disabled="merId && tempIndex!==0" size="25px"
                            @change="changeChildStatus(item)" :active-color="$store.state.backColor" inactive-color="#eeecf7" />
                    </div>
                    <div class="slider" v-if="item.issueList.length"></div>
                    <div :class="item.status ? '' : 'bg-gray'" v-if="item.prodId != 30000014 && item.prodId != 30000008">
                        <div class="input-box">
                            <div class="item" v-for="(el,k) in item.issueList" :key="k">
                                <div class="left goujiclass">
                                    <p class="label">{{el.term}}期</p>
                                    <input type="number" v-model.number="el.fee" :class="item.status ? '' : 'bg-gray'"
                                        :disabled="!el.status || merId && tempIndex!==0" maxlength="5"
                                        :placeholder="`请为商户设置${el.term}期费率,范围(${el.feeMin}-${el.feeMax})%`">
                                </div>
                                <van-icon v-if="el.status" name="passed" :color="$store.state.backColor" size="22"
                                    @click="setChildStatus(item.status,el,false)" />
                                <div v-else class="circle" :style="{border:`1px solid ${$store.state.backColor}`}" @click="setChildStatus(item.status,el,true)"></div>
                            </div>
                        </div>
                        <div class="slider" v-if="item.contractList.length"></div>
                        <div class="hb-box">
                            <div class="item" v-for="(contract, j) in item.contractList" :key="j">
                                <div class="left">
                                    <p class="label">{{contract.name}}</p>
                                    <div class="info">
                                        <p>编号:{{contract.contNo}}</p>
                                        <p>套餐资费:{{contract.packagePrices}}元</p>
                                        <p class="btn" @click="lookDetails(contract)">查看详情</p>
                                    </div>
                                </div>
                                <van-icon v-if="contract.status" name="passed" :color="$store.state.backColor" size="22"
                                    @click="setChildStatus(item.status,contract,false)" />
                                <div v-else class="circle" :style="{border:`1px solid ${$store.state.backColor}`}" @click="setChildStatus(item.status,contract,true)"></div>
                            </div>
                        </div>
                    </div>
                    <!-- 商户收款 -->
                    <div :class="item.status ? '' : 'bg-gray'" v-if="item.prodId == 30000008">
                        <div class="input-box">
                            <div class="item" v-for="(el,k) in item.payMethods" :key="k">
                                <div class="left goujiclass">
                                    <p class="label" style="width:100px">{{el.payMethodName}}费率</p>
                                    <input type="number" style="text-algin:right" v-model.number="el.fee" :class="item.status ? '' : 'bg-gray'"
                                        disabled maxlength="5"
                                    >
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 花呗间联 -->
                    <div :class="item.status ? '' : 'bg-gray'" v-if="item.prodId == 30000014">
                        <div class="input-box">
                            <div  class="item-hbjl-box" v-for="(el,k) in item.issueList" :key="k">
                                    <p class="label">{{el.term}}期</p>
                                    <div>
                                        <div class="item-hbjl">
                                            <div class="left goujiclass">
                                                <input type="number" v-model.number="el.fee" :class="item.status ? '' : 'bg-gray'"
                                                    :disabled="!el.status || merId && tempIndex!==0" maxlength="5"
                                                    :placeholder="`请为商户设置${el.term}期费率,范围(${el.feeMin}-${el.feeMax})%`">
                                            </div>
                                            <!-- <van-icon v-if="el.status" name="passed" color="#896EDB" size="22"
                                                @click="setChildStatus(item.status,el,false)" />
                                            <div v-else class="circle" @click="setChildStatus(item.status,el,true)"></div> -->
                                        </div>
                                        <div  class="item-hbjl">
                                            <div class="left goujiclass">
                                                <input type="number" v-model.number="el.amt" :class="item.status ? '' : 'bg-gray'"
                                                    :disabled="!el.status || merId && tempIndex!==0" maxlength="5"
                                                    :placeholder="`请为商户设置固定收益金额,范围(${el.amtMin}-${el.amtMax})`">
                                            </div>
                                            <!-- <van-icon v-if="el.status" name="passed" color="#896EDB" size="22"
                                                @click="setChildStatus(item.status,el,false)" />
                                            <div v-else class="circle" @click="setChildStatus(item.status,el,true)"></div> -->
                                        </div>
                                    </div>
                                    <div>
                                        <van-icon v-if="el.status" name="passed" :color="$store.state.backColor" size="22"
                                                @click="setChildStatus(item.status,el,false)" />
                                        <div v-else class="circle" :style="{border:`1px solid ${$store.state.backColor}`}" @click="setChildStatus(item.status,el,true)"></div>
                                    </div>
                            </div>
                        </div>
                        <div class="slider" v-if="item.contractList.length"></div>
                        <div class="hb-box">
                            <div class="item" v-for="(contract, j) in item.contractList" :key="j">
                                <div class="left">
                                    <p class="label">{{contract.name}}</p>
                                    <div class="info">
                                        <p>编号:{{contract.contNo}}</p>
                                        <p>套餐资费:{{contract.packagePrices}}元</p>
                                        <p class="btn" @click="lookDetails(contract)">查看详情</p>
                                    </div>
                                </div>
                                <van-icon v-if="contract.status" name="passed" :color="$store.state.backColor" size="22"
                                    @click="setChildStatus(item.status,contract,false)" />
                                <div v-else class="circle" :style="{border:`1px solid ${$store.state.backColor}`}" @click="setChildStatus(item.status,contract,true)"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 选中模板详情 -->
        <van-popup v-model="showDetail">
            <div class="dialog-box">
                <header class="head">
                    <svg class="icon" aria-hidden="true" style="width:97px;height:97px;">
                        <use xlink:href="#iconshenpidanchuang"></use>
                    </svg>
                    <svg class="icon close" aria-hidden="true" style="width:26px;height:26px;fill:#fff;"
                        @click="showDetail =false;">
                        <use xlink:href="#iconcha"></use>
                    </svg>
 
                </header>
                <div class="det-box dialog-content" v-if="tempId && detArr.length > 0">
                    <p>
                        <span>当前匹配规则:</span>
                        <span class="det-span" v-for="(e,i) in detArr" :key="i">{{e.name}}</span>
                    </p>
                </div>
                <div class="det-box dialog-content" v-if="detArr.length == 0">
                    <p style="text-align:center;line-height:125px">
                        <span>规则匹配:</span>
                        <span class="det-span">暂无,请选择规则</span>
                    </p>
                </div>
            </div>
        </van-popup>
        <!-- 匹配规则第一步 -->
        <van-popup v-model="isShowModal" class="modal-box" position="bottom">
            <h4 class="title">
                选择商户匹配规则
                <svg class="icon close" aria-hidden="true" style="width:24px;height:24px;fill:#999;"
                    @click="isShowModal =false;">
                    <use xlink:href="#iconcha"></use>
                </svg>
            </h4>
            <div class="my-cell" :class="activeVal-1 === index ? 'active':''" v-for="(item, index) in modoulList"
                :key="item.value" @click="nextStep(item,index)">
                <p>{{item.name}}</p>
                <van-icon v-if="activeVal-1 === index" name="passed" :color="$store.state.backColor" size="22" />
                <div class="circle" :style="{border:`1px solid ${$store.state.backColor}`}" v-else></div>
            </div>
        </van-popup>
        <!-- 选择模板第二步省份 -->
        <van-popup v-model="isShowModalPr" class="modal-box" position="bottom">
            <div class="title">
                <div style="position: absolute;top: 5px;">
                    <svg class="icon" aria-hidden="true" style="width:24px;height:24px;fill:#999;" @click="prToGo">
                        <use xlink:href="#iconzuojiantou"></use>
                    </svg>
                </div>
                
                <span>选择商户匹配规则</span>
                <svg class="icon close" aria-hidden="true" style="width:24px;height:24px;fill:#999;"
                    @click="isShowModalPr =false;">
                    <use xlink:href="#iconcha"></use>
                </svg>
            </div>
             <div class="my-cell" :class="allpr ? 'active':''" @click="getAllpr">
                <p>全选</p>
                <van-icon v-if="allpr" name="passed" :color="$store.state.backColor" size="22" />
                <div class="circle" :style="{border:`1px solid ${$store.state.backColor}`}" v-else></div>
            </div>
             <div class="my-cell" :class="item.selected === 1 ? 'active':''" v-for="(item, index) in areaArr"
                :key="index" @click="chosePr(index)">
                <p>{{item.name}}</p>
                <van-icon v-if="item.selected === 1" name="passed" :color="$store.state.backColor" size="22" />
                <div class="circle" :style="{border:`1px solid ${$store.state.backColor}`}" v-else></div>
            </div>
            <!-- <div class="my-cell" :class="areaClassIndex === index ? 'active':''" v-for="(item, index) in areaArr"
                :key="item.value" @click="areaClassIndex = index;">
                <p>{{item.name}}</p>
                <van-icon v-if="areaClassIndex===index" name="passed" color="#896EDB" size="22" />
                <div class="circle" v-else></div>
            </div> -->
        </van-popup>
        <!-- 选择模板第二步渠道 -->
        <van-popup v-model="isShowModalChan" class="modal-box" position="bottom">
            <div class="title">
                <div style="position: absolute;top: 5px;">
                    <svg class="icon" aria-hidden="true" style="width:24px;height:24px;fill:#999;" @click="chanToGo">
                        <use xlink:href="#iconzuojiantou"></use>
                    </svg>
                </div>
                选择商户匹配规则
                <svg class="icon close" aria-hidden="true" style="width:24px;height:24px;fill:#999;"
                    @click="isShowModalChan =false;">
                    <use xlink:href="#iconcha"></use>
                </svg>
            </div>
            <div class="my-cell" :class="allchan ? 'active':''" @click="getAllchan">
                <p>全选</p>
                <van-icon v-if="allchan" name="passed" :color="$store.state.backColor" size="22" />
                <div class="circle" :style="{border:`1px solid ${$store.state.backColor}`}" v-else></div>
            </div>
            <div class="my-cell" :class="item.selected === 1 ? 'active':''" v-for="(item, index) in chanArr"
                :key="item.value" @click="choseChan(index)">
                <p>{{item.name}}</p>
                <van-icon v-if="item.selected === 1" name="passed" :color="$store.state.backColor" size="22" />
                <div class="circle" :style="{border:`1px solid ${$store.state.backColor}`}" v-else></div>
            </div>
        </van-popup>
 
        <van-button v-show="isShowModal" :color="$store.state.backColor" class="btn-submit" style="z-index:3000;" @click="setInfoRules(1)">{{activeVal == 1 ? '确定':'下一步'}}</van-button>
        <van-button v-show="isShowModalPr" :color="$store.state.backColor" class="btn-submit" style="z-index:3000;" @click="setInfoRules(2)">确定</van-button>
        <van-button v-show="isShowModalChan" :color="$store.state.backColor" class="btn-submit" style="z-index:3000;" @click="setInfoRules(3)">确定</van-button>
 
        <!-- 模板列表 -->
        <van-popup v-model="isShowTempList" class="modal-box" position="bottom">
            <h4 class="title">
                更换模板
                <svg class="icon close" aria-hidden="true" style="width:24px;height:24px;fill:#999;"
                    @click="isShowTempList =false;">
                    <use xlink:href="#iconcha"></use>
                </svg>
            </h4>
            <div class="my-cell" :class="tempClassIndex===index ? 'active':''" v-for="(item, index) in tempList"
                :key="item.value" @click="tempClassIndex = index;">
                <p>{{item.tempName}}</p>
                <van-icon v-if="tempClassIndex===index" name="passed" :color="$store.state.backColor" size="22" />
                <div class="circle" :style="{border:`1px solid ${$store.state.backColor}`}" v-else></div>
            </div>
        </van-popup>
 
        <van-button :color="$store.state.backColor" v-show="!isShowModal && !isShowTempList" class="btn-submit save" @click="saveTemp">保存</van-button>
 
 
 
        <!-- 合约详情 -->
        <van-popup v-model="showDialogStyle" :close-on-click-overlay="false">
            <div class="dialog-box">
                <header class="head">
                    <svg class="icon" aria-hidden="true" style="width:97px;height:97px;">
                        <use xlink:href="#iconmobanxiangqingdanchuang"></use>
                    </svg>
                    <svg class="icon close" aria-hidden="true" style="width:26px;height:26px;fill:#fff;"
                        @click="showDialogStyle =false;">
                        <use xlink:href="#iconcha"></use>
                    </svg>
 
                </header>
                <div class="dialog-content">
                    <p class="title text-center-g">{{contractItem.name}}</p>
                    <ul class="message-box">
                        <li class="message-item">合约编号:{{contractItem.contNo}}</li>
                        <li class="message-item">还款期数:{{contractItem.nper}}期</li>
                        <li class="message-item">套餐资费:{{contractItem.packagePrices}}元</li>
                        <li class="message-item">商户结算:{{contractItem.loanAmt}}元</li>
                        <li class="message-item">月缴话费:{{contractItem.monthlyFees}}元</li>
                        <li class="message-item">月还款额:{{contractItem.monthlyPayments}}元</li>
                    </ul>
                </div>
            </div>
        </van-popup>
 
        <van-button :color="$store.state.backColor" v-show="isShowTempList" class="btn-submit" style="z-index:3001;" @click="setTempId">确定</van-button>
 
 
    </div>
</template>
 
<script>
    import {
        mapState
    } from 'vuex';
    import Vue from 'vue';
    import { Tab, Tabs } from 'vant';
    
    Vue.use(Tab);
    Vue.use(Tabs);
    export default {
        name: 'template_detail',
        data() {
            return {
                detArr:[],//规则详情数组
                showDetail:false,//详情弹出层
                allchan:false,//模板渠道全选
                allpr:false,//模板省份全选
                activeVal:1,//选择模板第一步,1-无规则,2-省份,3-渠道
                showDialogStyle: false,
                isShowModal: false,//模板选择第一步
                isShowModalChan:false,//模板选择第二步
                isShowModalPr:false,//模板选择第三步
                areaArr: [], //地区列表
                chanArr:[],//渠道列表
                modoulList:[
                    {
                        value:'999999',
                        name:'无匹配规则'
                    },
                    {
                        value:'1',
                        name:'省份'
                    },
                    {
                        value:'2',
                        name:'渠道'
                    }
                ],//无模板
                info: {
                    agencyId: '',
                    id: '',
                    prodInfList: [],
                    tempName: '' ,
                    tempRules: [],
                    tempType:''
                },
                contractItem: { //当前点击查看的合约
 
                },
                isShowTempList: false,
                tempIndex: 0,
                tempClassIndex: 0, //样式控制
                tempList: [], //模板列表
                areaIndex: 0,
                areaClassIndex: false, //样式控制
                modClassIndex:'',
                chanClassIndex:false
            }
        },
        watch:{
            'info.prodInfList':{
                handler: function() {
                   this.info.ruleChange = 1
                },
                deep: true
            },
            'info.tempRules':{
                handler: function() {
                  this.info.ruleChange = 1
                },
                deep: true
            },
            'info.tempType':{
                handler: function() {
                   this.info.ruleChange = 1
                },
                deep: true
            }
        },
        computed: {
            ...mapState(['areaList']),
            // 选中的地区
            currentRules() {
                return this.areaArr[this.areaIndex] 
            },
            // 选中的模板
            currentTemp() {
                return this.tempList[this.tempIndex]
            },
            tempId() {
                return this.$route.query.tempId
            },
            merId() {
                return this.$route.query.merId
            },
        },
        created() {
            this.init()
        },
        methods: {
            chanToGo(){
                this.isShowModalChan = false
                this.isShowModal = true
            },
            prToGo(){
                this.isShowModalPr = false
                this.isShowModal = true
            },
            // 选择省份
            chosePr(index){
                //按下标打钩,并且存储选中项,取消打钩的去掉存储项
                if(this.areaArr[index].selected == 0){
                    this.areaArr[index].selected = 1
                    console.log(this.info,this.areaArr[index])
                    this.info.tempRules.push(this.areaArr[index])
                }else{
                    this.areaArr[index].selected = 0
                    let num = this.info.tempRules.findIndex(item=>{
                        return item.code == this.areaArr[index].code
                    })
                    console.log('num:',num)
                    this.info.tempRules.splice(num,1)
                }
                // 有一个未打钩,取消全选,全部勾选则选中全选
                let i = this.areaArr.findIndex(item => {
                    return item.selected == 0
                })
                if(i > -1){
                    this.allpr = false
                }else{
                    this.allpr = true
                }
                console.log(this.info)
            },
            // 选择渠道
            choseChan(index){
                //按下标打钩,并且存储选中项,取消打钩的去掉存储项
                if(this.chanArr[index].selected == 0){
                    this.chanArr[index].selected = 1
                    this.info.tempRules.push(this.chanArr[index]) 
                }else{
                    this.chanArr[index].selected = 0
                    let num = this.info.tempRules.findIndex(item => {
                        return item.code == this.chanArr[index].code
                    })
                    console.log('num:',num)
                    this.info.tempRules.splice(num,1)
                }
                // 有一个未打钩,取消全选,全部勾选则选中全选
                let i = this.chanArr.findIndex(item => {
                    return item.selected == 0
                })
                if(i > -1){
                    this.allchan = false
                }else{
                    this.allchan = true
                }
                console.log(this.info)
                console.log('this.chanArr:',this.chanArr)
            },
            // 详情弹出层
            showDet(){
                this.showDetail = !this.showDetail
            },
            // 模板渠道全选
            getAllchan(){
                this.allchan = !this.allchan
                if(this.allchan){
                    this.chanArr.forEach(e=>{
                        e.selected = 1
                    })
                    this.info.tempRules = JSON.parse(JSON.stringify(this.chanArr)) 
                }else{
                    this.chanArr.forEach(e=>{
                        e.selected = 0
                    })
                    this.info.tempRules = []
                }
               console.log(this.info)
            },
            // 模板省份全选
            getAllpr(){
                this.allpr = !this.allpr
                if(this.allpr){
                    this.areaArr.forEach(e=>{
                        e.selected = 1
                    })
                    this.info.tempRules = JSON.parse(JSON.stringify(this.areaArr))
                }else{
                     this.areaArr.forEach(e=>{
                        e.selected = 0
                    })
                    this.info.tempRules = []
                }
                console.log(this.info)
            },
            // 控制模板选择弹出层
            nextStep(item,index){
                this.modClassIndex = index;
                this.info.tempRules = []
                if(item.value == '999999'){
                    this.activeVal = 1
                    this.info.tempType = 1
                }else if(item.value == '1'){
                    this.activeVal = 2
                    this.info.tempType = 2
                    this.areaArr.forEach(e=>{
                        if(e.selected == 1){
                            this.info.tempRules.push(e)
                        }
                    })
                }else{
                    this.activeVal = 3
                    this.info.tempType = 3
                    this.chanArr.forEach(e=>{
                        if(e.selected == 1){
                            this.info.tempRules.push(e)
                        }
                    })
                }
                console.log(this.info)
            },
            // 打开 模板弹窗
            openTempModal() {
                this.tempClassIndex = this.tempIndex;
                this.isShowTempList = true;
            },
            // 打开模板选择弹窗
            openAreaModal() {
                this.areaClassIndex = this.areaIndex;
                this.isShowModal = true;
            },
            init() {
                //获取地址
                //let list = this.areaList.province_list;
                // 增加第一个选项,可以选择无匹配规则
                // this.areaArr.push({
                //     value:'999999',
                //     name:'无匹配规则'
                // })
                // for (let key in list) {
                //     this.areaArr.push({
                //         value: key,
                //         name: list[key]
                //     })
 
                // }
                // 初始化模板
                // 有id的:查询详情,没有是新增
                if (this.tempId) {
                    this.getTempDetail()
                } else if (this.merId) {
                    this.initMerInfo()
                } else {
                    this.initTemp()
                }
            },
            // 初始化从商户管理页面进入的页面逻辑
            initMerInfo() {
                // 获取模板列表
                this.$api.getTempList().then((res) => {
                    let tempList = res.body || [];
                    tempList.unshift({
                        tempName: '无匹配规则',
                        value: '999999'
                    })
                    this.tempList = tempList;
                    // 获取商户产品信息
                    this.$api.tempGetMerRef({
                        merId: this.merId,
                        // tempId: 0
                    }).then((res) => {
                        this.parseTempInfo(res.body)
                        this.setTempIndex(res.body.id)
                    }).catch((err) => {
 
                    });
                }).catch((err) => {
 
                });
            },
            // 设置当前模板
            setTempIndex(id) {
                let index = this.tempList.findIndex(item => {
                    return item.id == id
                })
                if (index > -1) {
                    this.tempIndex = index;
                    this.tempClassIndex = index;
                }
            },
            //解析模板信息
            parseTempInfo(info) {
                let prodInfList = info.prodInfList || [];
                prodInfList = prodInfList.map(item => {
                    let contractList = item.contractList || [],
                        issueList = item.issueList || [];
                    contractList.forEach(el => {
                        el.status = !!el.status;
                    })
                    issueList.forEach(el => {
                        el.status = !!el.status;
                    })
                    item.status = !!item.status;
                    return {
                        ...item,
                        contractList,
                        issueList
                    }
                })
                
                this.chanArr = info.chanIds
                this.areaArr = info.provCodes
                this.info.prodInfList = prodInfList
                this.info.tempName = info.tempName
                this.activeVal = info.tempType || 1
                this.modClassIndex = info.tempType//规则选择第一步默认根据返回来确定
                this.info.id = info.id || ''
 
                // 访问详情接口时根据规则装载已选项
                if(info.tempType == 2){
                    info.provCodes.forEach(e=>{
                        if (e.selected == 1){
                            this.info.tempRules.push(e)
                            this.detArr.push(e)
                        }
                    })
                }
                if(info.tempType == 3){
                    info.chanIds.forEach(e=>{
                        if (e.selected == 1){
                            this.info.tempRules.push(e)
                            this.detArr.push(e)
                        }
                    })
                }
        
                
                // let tempRules = info.tempRules;
                // let index = this.areaArr.findIndex(item => {
                //     return item.value == tempRules
                // })
                // if (index > -1) {
                //     this.areaIndex = index;
                //     this.areaClassIndex = index;
                // }
 
                // this.info = {
                //     ...info,
                //     prodInfList
                // }
            },
            // 获取模板详情
            getTempDetail() {
                this.$api.getTempDetail(this.tempId).then((res) => {
                    this.parseTempInfo(res.body)
                }).catch((err) => {
 
                });
            },
            //父开关关闭时 同时关闭所有子开关
            changeChildStatus(item) {
                if (!item.status) {
                    item.contractList.forEach(el => {
                        el.status = false;
                    })
 
                    item.issueList.forEach(el => {
                        el.status = false;
                    })
                }
            },
            //设置子开关的状态
            setChildStatus(parentStatus, item, val) {
                // 商户进入页面 有模板时只能查看不能点击更改模板的状态
                if (this.merId && this.tempIndex !== 0) {
                    return
                }
                if (!parentStatus) {
                    return
                }
                item.status = val;
            },
            // 获取初始化数据并重组数据
            initTemp() {
                this.$api.getTempInit().then(res => {
                    this.parseTempInfo(res.body)
                    return
                });
            },
            //保存模版
            saveTemp() {
                if (!this.info.tempName) {
                    this.$notify(`请输入模板名称`)
                    return 
                }
                if(this.info.tempRules.length == 0 && this.activeVal != 1){
                    this.$notify(`请选择对应模板规则`)
                    return
                }
                // if(this.info.provName=='无匹配规则'){
                //     this.info.provName = '无匹配规则'
                //     this.info.tempRules = '999999'
                // }
                // 深拷贝改数据,避免重组数据时ui被更新
                let prodInfList = JSON.parse(JSON.stringify(this.info.prodInfList))
 
                //验证被打开的花呗费率是否输入并且在规定范围内
                for (let index = 0; index < prodInfList.length; index++) {
                    const el = prodInfList[index];
                    if (el.prodId == 30000003) {
                        let issueList = el.issueList;
                        for (let k = 0; k < issueList.length; k++) {
                            const issItem = issueList[k];
                            if ((issItem.fee == null || issItem.fee == '') && issItem.status) {
                                this.$notify(`请输入花呗${issItem.term}期费率!`)
                                return
                            }
                            if (issItem.fee && issItem.fee < issItem.feeMin || issItem.fee > issItem.feeMax) {
                                this.$notify(`请按要求范围输入花呗${issItem.term}期费率!`)
                                return
                            }
                        }
                    }
                    if (el.prodId == 30000010) {
                        let issueList = el.issueList;
                        for (let k = 0; k < issueList.length; k++) {
                            const issItem = issueList[k];
                            if ((issItem.fee == null || issItem.fee == '') && issItem.status) {
                                this.$notify(`请输入商户贴息${issItem.term}期费率!`)
                                return
                            }
                            if (issItem.fee && issItem.fee < issItem.feeMin || issItem.fee > issItem.feeMax) {
                                this.$notify(`请按要求范围输入商户贴息${issItem.term}期费率!`)
                                return
                            }
                        }
                    }
                }
                //验证被打开的花呗费率是否输入并且在规定范围内
                for (let index = 0; index < prodInfList.length; index++) {
                    const el = prodInfList[index];
                    if (el.prodId == 30000014) {
                        let issueList = el.issueList;
                        for (let k = 0; k < issueList.length; k++) {
                            const issItem = issueList[k];
                            if ((issItem.fee ===null || issItem.fee === '') && issItem.status) {
                                this.$notify(`请输入花呗间联${issItem.term}期费率!`)
                                return
                            }
                            if ((issItem.amt === null || issItem.amt === '') && issItem.status) {
                                console.log('000')
                                this.$notify(`请输入花呗间联${issItem.term}期商户固定收益!`)
                                return
                            }
                            if (issItem.fee && issItem.fee < issItem.feeMin || issItem.fee > issItem.feeMax) {
                                this.$notify(`请按要求范围输入花呗间联${issItem.term}期费率!`)
                                return
                            }
                            if (issItem.amt && issItem.amt < issItem.amtMin || issItem.amt  > issItem.amtMax) {
                                this.$notify(`请按要求范围输入花呗间联${issItem.term}期商户固定收益!`)
                                return
                            }
                        }
                    }
                }
                // return
 
                //重组状态 boolean转换成number
                prodInfList = prodInfList.map(item => {
                    let contractList = item.contractList || [],
                        issueList = item.issueList || [];
                    contractList = contractList.map(el => {
                        return {
                            ...el,
                            status: +el.status
                        }
                    })
                    issueList = issueList.map(el => {
                        return {
                            ...el,
                            status: +el.status
                        }
                    })
                    item.status = +item.status;
                    return {
                        ...item,
                        contractList,
                        issueList
                    }
                })
                let params = {
                    ...this.info,
                    prodInfList
                }
                if (this.merId) {
                    this.saveMerTemp(params)
                    return
                }
 
                if(this.tempId){
                    this.$api.tempManagerUpdate(params).then((res)=>{
                        this.$notify('保存成功!')
                        this.$router.back()
                    })
                }else{
                    this.$api.tempSave(params).then((res) => {
                        this.$notify('保存成功!')
                        this.$router.back()
                    }).catch((err) => {
                    
                    });
                }
               
            },
            // 保存商户模板信息
            saveMerTemp(params) {
                this.$api.tempSaveMerTemp({
                    ...params,
                    merId:this.merId
                    }).then((res) => {
                    this.$notify('保存成功!')
                    this.$router.back()
                }).catch((err) => {
 
                });
            },
            //查看合约详情
            lookDetails(item) {
                this.showDialogStyle = true;
                this.contractItem = item;
            },
            //设置商户匹配规则
            setInfoRules(i) {
                this.isShowModal = false;
                if(this.activeVal == 1){
                    this.isShowModalChan = false
                    this.isShowModalPr = false
                }
                if(this.activeVal == 2){
                    this.areaIndex = this.areaClassIndex;
                    if(this.areaArr.length > 0){
                        this.isShowModalChan = false
                        this.isShowModalPr = true
                    }else{
                        this.isShowModalPr = false
                        this.$notify('暂无此类型规则')
                        return
                    }
                    //this.info.tempRules = this.currentRules.value;
                    //this.info.provName = this.currentRules.name;
                    if(i==2){
                        this.isShowModalPr = false
                    }
                }
                if(this.activeVal == 3){
                    if(this.chanArr.length > 0){
                        this.isShowModalChan = true
                        this.isShowModalPr = false
                    }else{
                        this.isShowModalChan = false
                        this.$notify('暂无此类型规则')
                        return
                    }
                    if(i==3){ 
                        this.isShowModalChan = false
                    }
                }
                
                
            },
            //获取模板的数据,修改模板id
            setTempId() {
                this.tempIndex = this.tempClassIndex;
                if (this.tempIndex === 0) {
                    this.info.id = 999999;
                    this.isShowTempList = false;
                    return
                }
                let id = this.tempList[this.tempIndex].id;
                this.$api.getTempMerRef({
                    merId: this.merId,
                    tempId: id
                }).then((res) => {
                    this.info.id = id;
                    this.isShowTempList = false;
                    this.parseTempInfo(res.body)
                }).catch((err) => {
 
                });
 
            }
        }
    }
</script>
 
<style lang="less" scoped>
    .template-detail-box {
        position: relative;
        background-color: @c-bg-f5;
        padding-bottom: 100px;
 
        .bg-gray {
            background-color: #FAFAFA !important;
        }
 
        .bg-fff {
            background-color: #ffffff;
        }
    }
    
 
    
 
 
 
    .header {
        height: 44px;
        padding: 0 20px 30px 20px;
        line-height: 24px;
        font-weight: bold;
        color: @c-text-fff;
        background-color: @c-bg-black;
        background-image: url('../../../static/img/circle-top.png'), url('../../../static/img/circle-bottom.png');
        background-position: 0 0, 100% 100%;
        background-size: 78px 65px, 54px 41px;
        background-repeat: no-repeat;
        text-align: center;
        font-size: @font-16;
 
        .icon {
            z-index: @zIndex-20;
        }
 
        .title {
            font-size: @font-16;
            position: absolute;
            left: 60px;
            right: 60px;
        }
    }
 
    .temp-name {
        position: absolute;
        top: 54px;
        // width: 360px;
        left: 8px;
        right: 8px;
        height: 50px;
        box-shadow: 0px 4px 8px 0px rgba(66, 61, 93, 0.05);
        border-radius: 3px;
    }
 
    .product-box {
        margin-top: 48px;
        padding: 0 8px;
        position: relative;
        .det-btn{
            width: 80px;
            height: 20px;
            border: 1px solid #896EDB;
            outline: none;
            background-color: #fff;
            color: #896EDB;
            position: absolute;
            top: 15px;
            left: 120px;
            font-size: 12px;
        }
        .btn-d{
            padding: 2px 5px;
            width: 50px;
            height: 15px;
            line-height: 15px;
            text-align: center;
            background: rgba(247, 245, 255, 1);
            border: 1Px solid @c-text-default;
            border-radius: 3px;
            color: @c-text-default;
            font-size: @font-10;
            position: absolute;
            top: 15px;
            left: 120px;
            font-size: 12px;
        }
        .p-title {
            .lh(50px);
            padding: 0 12px;
            font-size: @font-16;
        }
    }
 
    .circle {
        border: 1px solid @c-bg-default;
        height: 16px;
        width: 16px;
        border-radius: 50%;
        margin-right: .2em;
    }
 
    .input-box {
        margin-left: 25px;
        .item-hbjl-box{
            .flex(space-between);
            height: 88px;
            padding-right: 13px;
            border-bottom:1px solid #DDDDDD;
        }
        .item-hbjl-box:last-child{
            border-bottom:0;
        }
        .item {
            .flex(space-between);
            height: 44px;
            padding-right: 13px;
            border-bottom:1px solid #DDDDDD;
 
            &:last-child {
                border-bottom: none;
            }
 
            input[type='number'] {
                width: 240px;
                border: none;
                outline: none;
                background-color: #fff;
                font-size: 12px;
            }
 
            .left {
                .flex;
                flex: 1;
            }
 
            .label {
                font-size: 14px;
                margin-right: 5px;
                min-width: 40px;
            }
 
        }
        .item-hbjl {
            .flex(space-between);
            height: 44px;
            padding-right: 13px;
            border-bottom:1px solid #DDDDDD;
 
            &:last-child {
                border-bottom: none;
            }
 
            input[type='number'] {
                width: 240px;
                border: none;
                outline: none;
                background-color: #fff;
                font-size: 12px;
            }
 
            .left {
                .flex;
                flex: 1;
            }
 
            .label {
                font-size: 14px;
                margin-right: 5px;
                min-width: 40px;
            }
 
        }
    }
 
    .hb-box {
        margin-left: 12px;
 
        .item {
            height: 75px;
            padding-right: 13px;
            border-bottom: 1px solid #DDDDDD;
            .flex(space-between);
 
 
            &:last-child {
                border-bottom: none;
            }
        }
 
        .left {
            .flex(flex-start, flex-start, '', column);
            flex: 1;
 
            .label {
                font-size: 14px;
            }
        }
 
        .info {
            .flex;
            margin-top: 5px;
            font-size: 12Px;
 
            p {
                margin-right: 15px;
                color: #999999;
            }
 
            .btn {
                padding: 2px 5px;
                width: 50px;
                height: 15px;
                line-height: 15px;
                text-align: center;
                background: rgba(247, 245, 255, 1);
                border: 1Px solid @c-text-default;
                border-radius: 3px;
                color: @c-text-default;
                font-size: @font-10;
            }
        }
    }
 
    .dialog-box {
        .head {
            .flex(center);
            height: 135px;
            background-color: @c-black;
            .gofront{
                display: inline-block;
                position: absolute;
                right: 355px;
                top: 10px;
            }
            .close {
                position: absolute;
                right: 5px;
                top: 5px;
            }
        }
        .det-box{
            //width: 200px;
            //min-height: 200px;
            box-sizing: border-box;
            padding: 10px;
            font-size: 16px;
            
            .det-span{
                margin-right: 10px;
            }
        }
        .dialog-content {
            background-color: #fff;
            width: 300px;
            height: 145px;
            margin: 0 auto;
            padding: 10px 15px;
            box-sizing: border-box;
 
            .title {
                .lh(50px);
            }
 
            .message-box {
                .flex(space-between);
                flex-wrap: wrap;
                color: @c-text-999;
                text-align: left;
            }
 
            .message-item {
                width: 50%;
                margin-bottom: 10px;
            }
        }
    }
 
    .modal-box {
        overflow-y: scroll;
        padding-bottom: 54px;
        font-size: 16px;
        height: 400px;
 
        .title {
            position: relative;
            .lh(50px);
            text-align: center;
            font-weight: normal;
            color: @c-text-999;
            border-bottom: 1px solid @c-bg-eee;
 
            .close {
                position: absolute;
                right: 3px;
                top: 3px;
            }
        }
    }
 
    .my-cell {
        .flex(space-between);
        height: 50px;
        padding: 0 20px;
 
        &.active {
            background-color: #FAFAFA;
        }
    }
 
    .btn-submit {
        position: fixed;
        bottom: 0;
        .lh(50px);
        width: 100%;
        border: none;
        background-color: @c-bg-default;
        color: @c-text-fff;
        font-size: @font-16;
 
        &.save {
            position: fixed;
            width: 320px;
            left: 28px;
            right: 28px;
            bottom: 25px;
            margin-top: 25px;
            z-index: 1000;
            border-radius: 50px;
        }
    }
</style>