liuyn
2024-03-22 e8be4d964c6b336ed39dba5900b1b9a8f3181b96
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
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
import { LightningElement,wire,track,api} from 'lwc';
import LightningConfirm from 'lightning/confirm';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import { CurrentPageReference } from "lightning/navigation";
import estimateUtility from 'c/lexSelectEstimateUtility';
 
import init from "@salesforce/apex/lexSelectAssetEstimateVMController.init";
import save from "@salesforce/apex/lexSelectAssetEstimateVMController.save";
import refreshProductData from "@salesforce/apex/lexSelectAssetEstimateVMController.refreshProductData";
import saveAndCancel from "@salesforce/apex/lexSelectAssetEstimateVMController.saveAndCancel";
import addNewRows from "@salesforce/apex/lexSelectAssetEstimateVMController.addNewRows";
import searchBtn from "@salesforce/apex/lexSelectAssetEstimateVMController.searchBtn";
import exchangeAsset from "@salesforce/apex/lexSelectAssetEstimateVMController.exchangeAsset";
import approvalProcess from "@salesforce/apex/lexSelectAssetEstimateVMController.approvalProcess";
import ComputeLTYRepair from "@salesforce/apex/lexSelectAssetEstimateVMController.ComputeLTYRepair";
import ShowLTYRepair from "@salesforce/apex/lexSelectAssetEstimateVMController.ShowLTYRepair";
import toApprovalProcess from "@salesforce/apex/lexSelectAssetEstimateVMController.toApprovalProcess";
import decide from "@salesforce/apex/lexSelectAssetEstimateVMController.decide";
import decideCancle from "@salesforce/apex/lexSelectAssetEstimateVMController.decideCancle";
import undecide from "@salesforce/apex/lexSelectAssetEstimateVMController.undecide";
import print from "@salesforce/apex/lexSelectAssetEstimateVMController.print";
import sendEmail from "@salesforce/apex/lexSelectAssetEstimateVMController.sendEmail";
//import excelImport from "@salesforce/apex/lexSelectAssetEstimateVMController.excelImport";
//import readExcel from "@salesforce/apex/lexSelectAssetEstimateVMController.readExcel";
import accSendEmailFW from "@salesforce/apex/lexSelectAssetEstimateVMController.accSendEmailFW";// WYL 贸易合规2期 add
 
import getApprovalBtnNewDisabled from "@salesforce/apex/lexSelectAssetEstimateVMController.getApprovalBtnNewDisabled";
// import ToConsumptionRate from "@salesforce/apex/ConsumptionRateWebService2.ToConsumptionRate";
import interceptsend from "@salesforce/apex/lexSelectAssetEstimateVMController.interceptsend";
 
//前端需要补充方法
import getMCAEIsCreateable from "@salesforce/apex/lexSelectAssetEstimateVMController.getMCAEIsCreateable";
import saveBeforeCheckPriceChangeAsset from "@salesforce/apex/lexSelectAssetEstimateVMController.saveBeforeCheckPriceChangeAsset";
import saveBeforeCheckPriceChangeProduct2 from "@salesforce/apex/lexSelectAssetEstimateVMController.saveBeforeCheckPriceChangeProduct2";
import onChDealerUpdate from "@salesforce/apex/lexSelectAssetEstimateVMController.onChDealerUpdate";
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import lexSendNfm103 from '@salesforce/resourceUrl/lexSendNfm103';  
 
//completion=? page里跳转回原编辑页面  id=传回参数
export default class lexSelectAssetEstimateVM extends NavigationMixin(LightningElement){
    activeSections = ['A', 'B','C','D','E'];
    // @track activeSections = ['A'];
    IsLoading = true;
    objName = 'Maintenance_Contract_Estimate__c';
    recordId;
    params;
    goTo;
    IsParams;
    // openQuoteExcelImportWindow=null;
    //三方协议 勾选是否显示
    EnablePrintContract;
    //请提交待审批 文字提示
    IS_Clone_After_Decide;
    @track
    estimate = {};
    contract = {};
    
    @track estimateTemp = {Request_quotation_Amount__c : 0,AgencyHos_Price__c : 0};
    @track estimateAgencyHosPrice = {AgencyHos_Price__c : 0};
    //存放初始化所有数据
    allData = {};
    checkedAssetRelatedMaintenanceContractAssetEstimate = 'Maintenance_Contract_Asset_Estimate__c';
    //页面数据显示  recId -- rec.Id(原通过后端的get方法取值)
    checkedAssetData = [];
    IsCheckAllcheckedAsset = false;
    //选中保有设备  数据统计 //allData.productCount3 可替换
    productCount3 = 0;
    checkedAssetDataSize = true;
    //修理总额--仅页面显示
    assetRepairSumNum;
    //未选中保有设备 弹框显示与否
    IsShowUnCheckedAsset;
    unCheckedAssetData = [];
    IsCheckAllUncheckedAsset = false;
    unCheckedAssetDataLength;
    //分页处理--是否可以直接在前端处理
    currentPage = 1;
    pageDataLimit = 20;
    pageCount;
    //未选中保有设备  下方文字
    unCheckedAssetDataShow1 ;
    unCheckedAssetDataShow2 ;
    //当前页数据
    unCheckedAssetNowData = [];
    //保有设备 搜索条件  -> allData里
    text1 = 'S:AssetMark__c';                      // 对象
    cond1 = 'equals';                   // 条件
    val1;
    //前端判断按钮是否可以点击
    SaveBtnDisabled;
    //consumptionbtnDisabled;
    ApprovalBtnDisabled;
    //后台返回结果
    ApprovalBtnNewDisabled;
    PageDisabled;
    hasSendEmail;
    //allData.productCount 可替换
    productCount;
    //报价提交对象 变更按钮 Disabled  DecideBtnDisabled
    DecideBtnDisabled =true;
    UnDecideBtnDisabled = true;
    //提交RC评估 btn
    SendEmailBtnDisabled;
    //补充初始化数据
    approvalDate = '';
    refreshAssetBtn;
    // lwc 刷新按钮禁用
    refreshAssetBtnLWC;
    IsTop;
    IsPre;
    IsNext;
    IsEnd;
    lineAddBtn;
    IsChangePageLimit;
    printFlag = true;
    //相关字段改动导致禁用或不显示
    IsContractstartdateDisabled;
    IsDealerDisabled;
    AgreeRenewTenDisabled;
    IsRequestQuotationAmountDisabled;
    isAgreeRenew;
    IsLimitPriceAmountDisabled;
    IsContractEstiStartDateDisabled;
    //页面数据刷新
    IsRefresh = true;
    EstimateTargetIsDealer;
    EstimatePricerange;
    ContractPriceType;
    //excel导入
    //showQuoteExcelImport=false;
    //svgRichText='富文本';
    // WYL 贸易合规 合同id
    mcid;
    //获取Id
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
            const urlValue = currentPageReference.state.fragment;
            if (urlValue) {
                this.otherParams = urlValue;
                let str = `${urlValue}`;
                this.params = str.split('=');
                
                this.recordId = str.split('=')[1];
                this.IsParams = this.params[0] == 'id';
                this.goTo = true;
            }else{
                estimateUtility.toast.showToast(this, 'error', '请从合同和报价页面进入');
                setTimeout(function() {
                         window.open('/lightning/page/home','_self');
                    }, 3000);
                this.goTo = false;
            }
        }
    }
    //页面初始化
    connectedCallback() {
         Promise.all([
            loadStyle(this, lwcCSS),
            loadStyle(this, lexSendNfm103)
           ]);
         if (this.goTo) {
            init({
                recordId: this.recordId,
                param: this.params[0],
            }).then(result => {
                result = JSON.parse(result);
                console.log('estimate===',JSON.stringify(result.estimate));
                this.mcid = result.estimate.Maintenance_Contract__c;    //贸易合规二期
                if (result != null) {
 
                    this.allData = result;
 
                    this.handleInitSimpleData(result);
                    this.allData.checkedAssets = this.refreshAsset(result.checkedAssets.length,result.checkedAssets);
                    this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
                    this.handleunCheckedAssetColumnsAndData(this.allData.unCheckedAssets);
                    this.calonLoad();
                    this.allDataInfo();
                }
            }).catch(error => {
                console.log('错误==='+error);
                estimateUtility.toast.showToast(this, 'error', '无法显示维修合同报价');
            }).finally(() => {
                const sections = this.template.querySelectorAll('lightning-accordion-section');
                    sections.forEach(section => {
                        if(section.id.includes('myAccordionSection')) {
                            section.active = true;
                        }
                    }); 
                this.IsLoading = false;             
            }); 
         }
        
    }
 
    handleCheckedAssetColumnsAndData(checkedAssets){
        console.log('handleCheckedAssetColumnsAndData');
        this.IsRefresh = false;
        let checkedAssetsData = [];
        let index = 0;
        let assetsCount = 0;
        let refreshAssetBtnLWCDisabled = true;
        checkedAssets.forEach(function(ar) {
            let objData = {};
 
            objData['lineNo'] = ar.lineNo;
            objData['rec_checkBox_c'] =  ar.rec_checkBox_c;
            objData['IsManual'] = ar.isManual;
            
            objData['CheckRows'] =ar.CheckRows;
 
            objData['Repair_Price_Auto'] =ar.Repair_Price_Auto;
            //共有字段
            if (ar.mcae != null) {
                objData['EquipmentGuaranteeFlgTxt__c'] = ar.mcae.EquipmentGuaranteeFlgTxt__c;
                objData['Check_Object__c'] = ar.mcae.Check_Object__c;
                objData['IsNew__c'] = ar.mcae.IsNew__c;
                var adl = '';
                var adu = '';
                if (ar.mcae.Adjustment_Lower_price__c !=''&& ar.mcae.Adjustment_Lower_price__c != null) {
                    if (typeof ar.mcae.Adjustment_Lower_price__c === 'number') {
                    adl = ar.mcae.Adjustment_Lower_price__c;
                    }else{
                        adl = parseFloat(ar.mcae.Adjustment_Lower_price__c);
                    }
                }
                if ( ar.mcae.Adjustment_Upper_price__c !='' && ar.mcae.Adjustment_Upper_price__c != null) {
                     if (typeof ar.mcae.Adjustment_Upper_price__c === 'number') {
                    adu = ar.mcae.Adjustment_Upper_price__c;
                    }else{
                        adu = parseFloat(ar.mcae.Adjustment_Upper_price__c);
                    }
                } 
                if (adu!='' ) {
                    objData['Adjustment_Upper_price__c'] = new Intl.NumberFormat('en-US', {
                                                            style: 'decimal',
                                                            // currency: 'USD',
                                                            minimumFractionDigits: 2
                                                        }).format(adu);
                }
                  if (adl!='' ) {
                    objData['Adjustment_Lower_price__c'] = new Intl.NumberFormat('en-US', {
                                                            style: 'decimal',
                                                            // currency: 'USD',
                                                            minimumFractionDigits: 2
                                                        }).format(adl);
                  }
        
                objData['Repair_Price__c'] = ar.mcae.Repair_Price__c;
                objData['Comment__c'] = ar.mcae.Comment__c;
                objData['commentTitle'] = ar.mcae.Comment__c ? ar.mcae.Comment__c : '';
                objData['Third_Party_Return__c'] = ar.mcae.Third_Party_Return__c;
            }
            if (ar.rec != null) {
                objData['IsCurrentContract'] = ar.rec.CurrentContract_F__c != null;
                objData['recId'] = ar.rec.Id;
 
                objData['CurrentContract_F__c'] = ar.rec.CurrentContract_F__c;
            }
            if (ar.isManual == true && ar.mcae != null) {
              objData['Name'] = ar.mcae.Product_Manual__c;
 
              if (ar.mcae.Product_Manual__c) {
                assetsCount += 1;
              }
            }else if ( ar.isManual == false) {
                assetsCount += 1;
                if (ar.rec != null) {
                  objData['Name'] = ar.rec.Name;
                  refreshAssetBtnLWCDisabled = false;
                  objData['CurrentContract_End_Date__c'] = ar.rec.CurrentContract_End_Date__c;
                  objData['Asset_situation__c'] = ar.rec.Asset_situation__c;
                  objData['SerialNumber'] = ar.rec.SerialNumber;
                  objData['InstallDate'] = ar.rec.InstallDate;
                  objData['Department_Name__c'] = ar.rec.Department_Name__c;
                  if (ar.rec.CurrentContract_F__r != null) {
                    if (ar.rec.CurrentContract_F_asset__r != null) {
                        objData['IS_VMContract_Asset__c'] =  ar.rec.CurrentContract_F_asset__r.IS_VMContract_Asset__c;
                    }
                    objData['Maintenance_Contract_No_F__c'] = ar.rec.CurrentContract_F__r.Maintenance_Contract_No_F__c;
                    objData['Contract_End_Date__c'] =  ar.rec.CurrentContract_F__r.Contract_End_Date__c;
                  }
              }
              if (ar.mcae != null) {
                objData['Asset_Consumption_rate__c'] =  ar.mcae.Asset_Consumption_rate__c;
              }
            }
            //补充字段可否编辑
            objData['IsAssertDisabled'] =  ar.IsAssertDisabled;
            objData['IsRepairPriceDisabled'] =  ar.IsRepairPriceDisabled;
            objData['ISCommentDisabled'] =  ar.ISCommentDisabled;
            objData['IsThirdPartyReturnDisabled'] =  ar.IsThirdPartyReturnDisabled;
            objData['ShowAssetSituation'] =  ar.ShowAssetSituation;
            checkedAssetsData.push(objData);
          
        });
        this.checkedAssetData = checkedAssetsData;
        console.log('this.checkedAssetData=='+this.checkedAssetData);
        //已选择保有设备
        //this.productCount3 统计
        this.productCount3 = assetsCount;
        this.allData.productCount3 = this.productCount3;
        this.refreshAssetBtnLWC = this.refreshAssetBtnLWC || refreshAssetBtnLWCDisabled;
        this.IsRefresh = true;
    }
 
 
    handleunCheckedAssetColumnsAndData(unCheckedAssets){
        console.log('handleunCheckedAssetColumnsAndData');
        this.IsRefresh = false;
 
        let uncheckedAssetsData = [];
        let refreshAssetBtnDisabled = true;
        unCheckedAssets.forEach(function(ar) {
             let objData = {};
            //共有字段
            objData['rec_checkBox_c'] = ar.rec_checkBox_c;
            if (ar.mcae != null) {
            }
            if (ar.rec != null) {
                objData['Id'] = ar.rec.Id;
                
                objData['uncheckedDisable'] = ar.rec.Maintenance_Price_Month__c == 0 || ar.rec.IF_Warranty_Service__c == '否';
                if (!objData['uncheckedDisable']) {
                    refreshAssetBtnDisabled = false; 
                }
                objData['EquipmentGuaranteeFlg__c'] = ar.rec.EquipmentGuaranteeFlg__c;
 
                objData['name'] = ar.rec.Name;
                objData['Asset_situation__c'] = ar.rec.Asset_situation__c;
                
                objData['SerialNumber'] = ar.rec.SerialNumber;
                objData['InstallDate'] = ar.rec.InstallDate;
                objData['Department_Name__c'] = ar.rec.Department_Name__c;
                objData['IF_Warranty_Service__c'] = ar.rec.IF_Warranty_Service__c;
                objData['AssetMark__c'] = ar.rec.AssetMark__c;
                objData['EquipmentGuaranteeFlg__c'] = ar.rec.EquipmentGuaranteeFlg__c;
                objData['Reson_Can_not_Warranty__c'] = ar.rec.Reson_Can_not_Warranty__c;
                objData['Accumulation_Repair_Amount__c'] = ar.rec.Accumulation_Repair_Amount__c;
                objData['CurrentContract_End_Date__c'] = ar.rec.CurrentContract_End_Date__c;
            }
            uncheckedAssetsData.push(objData);
        });
        this.unCheckedAssetData = uncheckedAssetsData;
        console.log('this.unCheckedAssetData',this.unCheckedAssetData);
        this.getUnCheckedAssetNowData();
        
        this.refreshAssetBtn = this.refreshAssetBtn || refreshAssetBtnDisabled;
 
        this.IsRefresh = true;
    }
 
    handleInitSimpleData(result) {
        console.log('handleInitSimpleData');
 
        this.IsRefresh = false;
        
 
        this.estimate = result.estimate;
        this.handleEstimateTargetIsHospitalTrue();
        
        if (this.estimate.Is_RecognitionModel__c  == null || !this.estimate.Is_RecognitionModel__c) {
            this.estimate.Is_RecognitionModel__c = false;
        }
        if (this.estimate.Print_RepairPrice__c == null || !this.estimate.Print_RepairPrice__c) {
            this.estimate.Print_RepairPrice__c = false;
        }
        if (this.estimate.Print_SumPrice__c == null || !this.estimate.Print_SumPrice__c) {
            this.estimate.Print_SumPrice__c = false;
        }
        if (this.estimate.Print_Contract__c == null || !this.estimate.Print_Contract__c) {
            this.estimate.Print_Contract__c = false;
        }
        if (this.estimate.Print_Tripartite__c == null || !this.estimate.Print_Tripartite__c) {
            this.estimate.Print_Tripartite__c = false;
        }
        if (this.estimate.Print_Agent__c == null || !this.estimate.Print_Agent__c) {
            this.estimate.Print_Agent__c = false;
        }
        this.contract = result.contract;
 
        this.pageDataLimit = result.selRecordOption;
        this.currentPage = result.currPage;
        this.pageCount = result.totalPage;
        this.IsChangePageLimit = result.totalRecords<10;
        this.hasSendEmail = result.hasSendEmail;
        this.productCount = result.checkedAssets.length;
        this.val1 = result.val1;
        this.productCount3 = result.productCount3;
        this.IS_Clone_After_Decide = result.IS_Clone_After_Decide;
 
        this.allData.text1 = this.text1 ;                  // 对象
        this.allData.cond1 = this.cond1 ; 
        // if (this.contract.Status__c =='引合中'  || this.estimate.Process_Status__c && this.estimate.Process_Status__c != '草案中') {
        //     this.consumptionbtnDisabled = true;
        // }else{
        //     this.consumptionbtnDisabled = false;
        // }
        if (this.contract.Decided_Estimation__c || this.estimate.Process_Status__c && this.estimate.Process_Status__c != '草案中') {
            this.SaveBtnDisabled = true;
            this.ApprovalBtnDisabled  = true;
            this.PageDisabled = true;
            this.SendEmailBtnDisabled = true;
        }else{
            this.SaveBtnDisabled = false;
            this.ApprovalBtnDisabled = false;
            this.SendEmailBtnDisabled = false;
            this.PageDisabled = false;
            if(this.hasSendEmail == true){
                this.SendEmailBtnDisabled = true;
            }
        }
        if(this.contract.Decided_Estimation__c || this.estimate.Process_Status__c != '批准' 
            || (this.estimate.Change_Dealer_Approval__c && this.estimate.Change_Dealer_Approval__c != '批准'
                && this.estimate.Change_Dealer_Approval__c != '未批准')){
 
            this.DecideBtnDisabled = true;
 
        }else{
            this.DecideBtnDisabled = false;
        }
        if (this.contract.Decided_Estimation__c) {
            this.EnablePrintContract = this.estimate.Estimation_Decision__c;
            if (this.estimate.Estimation_Decision__c) {
                this.UnDecideBtnDisabled = false;
            }
        }else{
            this.UnDecideBtnDisabled = true;
            this.EnablePrintContract = false;
        }
        getMCAEIsCreateable({
        }).then(result => {
            console.log('getMCAEIsCreateable result',result);
            this.lineAddBtn = this.PageDisabled || !result;
        }).catch(error => {
        }).finally(() => {
        }); 
        if (this.contract.Decided_Estimation__c || this.estimate.Process_Status__c && this.estimate.Process_Status__c != '草案中') {
            // TODO 特別資格があれば 申請可能にする
            this.ApprovalBtnNewDisabled = true;
        }else{
            getApprovalBtnNewDisabled({
            }).then(result => {
                this.ApprovalBtnNewDisabled = result;
                console.log('getApprovalBtnNewDisabled this.ApprovalBtnNewDisabled',this.ApprovalBtnNewDisabled);
            }).catch(error => {
            }).finally(() => {
            });  
        }
        // 报价规则改善 20230713 start
        if (result.isAgreeRenewTen == true) {
            this.AgreeRenewTenDisabled = false;
        }else{
            this.AgreeRenewTenDisabled = true;
        }
        this.refreshAssetBtn = this.SaveBtnDisabled;
        console.log('this.refreshAssetBtn ',this.refreshAssetBtn);
        this.refreshAssetBtnLWC = this.refreshAssetBtn;
        this.recordId = this.allData.targetEstimateId;
        this.IsRefresh = true;
    }
    pageBtnDiasbled(){
        console.log('pageBtnDiasbled');
        this.IsTop = this.pageCount == 0 || this.currentPage == 1;
        this.IsPre = this.pageCount == 0 || this.currentPage == 1;
        this.IsNext = this.pageCount == 0 || this.currentPage == this.pageCount;
        this.IsEnd = this.pageCount == 0 || this.currentPage == this.pageCount;
    }
    //页面按钮禁用初始化
    async calonLoad() {
        console.log('calonLoad');
 
        // refreshAsset 再次 空白期会被修改,实际显示值可能会与第一次计算不一致
        this.allData.checkedAssets = this.refreshAsset(this.allData.checkedAssets.length,this.allData.checkedAssets);
        this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
 
        var RequestquotationAmount = this.estimate.Request_quotation_Amount__c;
        var AssetRepairSumPrice    = this.estimate.Asset_Repair_Sum_Price__c;
        var Limit_Price_Amount = (this.localParseFloat(AssetRepairSumPrice)+this.localParseFloat(RequestquotationAmount))*1.3;
        Limit_Price_Amount = Math.round(Limit_Price_Amount);
        var Limit_Price_AmountOne =  this.estimate.Limit_Price_Amount__c;
        var Limit_PriceHidden =  this.allData.OldLimitPrice;
        if (Limit_PriceHidden*1==0) {
            this.estimate.Limit_Price_Amount__c = Limit_Price_Amount;
        }
        var Limit_PriceHidden2 =  this.allData.isLimitPrice;
        if (Limit_PriceHidden2 == false) {
            this.estimate.Limit_Price_Amount__c = '';
        }
        var Price111 = this.estimate.Limit_Price_Amount__c;
        await this.pageSetDisabled();
        var createdDate = new Date(this.estimate.CreatedDate);
        // 报价中设备的机身编码为空时的新品合同有效期延长 20200710 gzw
        var aLLManual = 'true';
        var cntWithKara = this.productCount; 
        for (var i = 0; i < cntWithKara; i++) {
            var isManual = this.allData.checkedAssets[i].isManual; 
            if (isManual != true) {
                aLLManual = 'false';
                break;
            }
        }
        var nowDate = new Date();
        if (aLLManual == 'false') {
            createdDate = createdDate.setMonth(createdDate.getMonth() + 3);
            // FIX liang JSの時間って addMonthsないですか? そかも 1/1 なら、 4/1もだめですよ。
            if (createdDate < Date.parse(nowDate)) {
                this.SaveBtnDisabled = true;
                this.ApprovalBtnDisabled = true;
                this.SendEmailBtnDisabled = true;
                if (await estimateUtility.toast.handleConfirmClick("已超过创建日3个月,是否更新报价?")) {
                    window.location.href=window.location.origin+"/lightning/n/lexSelectAssetEstimateVM#copyid="+this.allData.targetEstimateId; 
                    location.reload();
                    return true;
                } else {
                    if (!this.DecideBtnDisabled) {
                        // decide可能の場合、別途decideのチェックが必要、
                        // チェック後再度画面refreshされるため、decide可能の場合、decideボタンが使えるようになります。
                        this.changeContractStartdate(this.estimate.Contract_Start_Date__c);
                    }
                    return false;
                }
            }
        }else{
            createdDate = createdDate.setMonth(createdDate.getMonth() + 6);
            // FIX liang JSの時間って addMonthsないですか? そかも 1/1 なら、 4/1もだめですよ。
            if (createdDate < Date.parse(nowDate)) {
                this.SaveBtnDisabled = true;
                this.ApprovalBtnDisabled = true;
                this.SendEmailBtnDisabled = true;
                if (await estimateUtility.toast.handleConfirmClick("已超过创建日6个月,是否更新报价?")) {
                    window.location.href=window.location.origin+"/lightning/n/lexSelectAssetEstimateVM#copyid="+this.allData.targetEstimateId; 
                    location.reload();
                    return true;
                } else {
                    if (!this.DecideBtnDisabled) {
                        // decide可能の場合、別途decideのチェックが必要、
                        // チェック後再度画面refreshされるため、decide可能の場合、decideボタンが使えるようになります。
                        this.changeContractStartdate(this.estimate.Contract_Start_Date__c);
                    }
                    return false;
                }
            }
        }
        if (!this.DecideBtnDisabled) {
            this.allData.OldMaintenancePrice = this.estimate.Maintenance_Price__c;
        }
    }
 
    pageSetDisabled(){
        console.log('pageSetDisabled');
 
        var hasSendEmail = this.allData.hasSendEmail; 
        if(hasSendEmail == true){
            this.SendEmailBtnDisabled = true;
        }
 
        var isDisabled = this.PageDisabled;
        if (isDisabled) {
 
 
            this.IsContractEstiStartDateDisabled = true;
 
            var rowCnt = this.productCount;
            for (var i = 0; i < rowCnt; i++) {
 
                var isManual = this.allData.checkedAssets[i].isManual;
                if (isManual == true) {
                    this.allData.checkedAssets[i].IsAssertDisabled = true;
                }
                this.allData.checkedAssets[i].CheckRows = true;
                this.allData.checkedAssets[i].IsRepairPriceDisabled = true;
                this.allData.checkedAssets[i].ISCommentDisabled = true;
                this.allData.checkedAssets[i].IsThirdPartyReturnDisabled = true;
            }
            this.IsRequestQuotationAmountDisabled = true;
            this.IsContractstartdateDisabled = true;
            var target = this.estimate.Estimate_Target__c;
            if (target != '医院') {
                this.IsDealerDisabled = true;
            }
        }
        if (!this.DecideBtnDisabled) {
            this.IsContractstartdateDisabled = false;
            // 2023/09/06 报价规则改善空白期 start +-   
            var renewTenOFF = this.estimate.renewTen_OFF__c;     
            var startime1 =  new Date(this.allData.Past_Contract_end_day);       
            var startime2 = new Date(this.estimate.Contract_Esti_Start_Date__c);         
            var result = (startime2-startime1)/(3600*24*1000);       
            var VMProductCountAll = this.allData.VMProductCountAll;        
            var ProductCountAll = this.allData.ProductCountAll; 
            console.log('VMProductCountAll',VMProductCountAll);
            console.log('ProductCountAll',ProductCountAll);
            // 不能 添加有值判定
            if (VMProductCountAll ==ProductCountAll) {       
                result = 0;      
            }
            console.log('result',result);
                    
            if (renewTenOFF) {       
                if (result==0) {         
                }else{       
                    this.IsContractstartdateDisabled = true;   
                }        
            }        
             // 报价规则改善空白期 end
        }
        //补充页面数据处理
        this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
    }
    //
    async changeContractStartdate(val) {
        var oldDateStr = this.estimate.Contract_Start_Date__c;
        console.log('changeContractStartdate oldDateStr',oldDateStr);
        console.log('changeContractStartdate Date',new Date(this.estimate.Contract_Start_Date__c));
        var oldDate = new Date();
        if (oldDateStr != null && oldDateStr != '') {
            oldDate = new Date(oldDateStr);
        }
        if (!this.DecideBtnDisabled) {
            var monthStr = '00' + (oldDate.getMonth()+1);
            monthStr = monthStr.substring(monthStr.length-2, monthStr.length);
            var dayStr = '00' + oldDate.getDate();
            dayStr = dayStr.substring(dayStr.length-2, dayStr.length);
            var oldDateVal = oldDate.getFullYear() + '/' + monthStr + '/' + dayStr;
            this.allData.OldContractStartDate = oldDateVal;
            if (await this.saveBeforeCheckPriceChange()) {
            }
            this.allData.checkedAssets = this.refreshAsset(this.allData.checkedAssets.length,this.allData.checkedAssets);
            this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
        } else {
            var cntWithKara = this.productCount;
            var haveLine = 'false';
            for (var i = 0; i < cntWithKara; i++) {
                var isManual = this.allData.checkedAssets[i].isManual;
                if (isManual) {
                    //Assert_lkid id未找到
                } else {
                    haveLine = 'true';
                }
            }
            if (haveLine == 'false') {
                return false;
            }
            var contractStartDate = new Date(val);
            var strCreatedDate = this.estimate.CreatedDate;
            var createDate = new Date();
            if (strCreatedDate != '') {
                createDate = new Date(strCreatedDate);
            }
            createDate = new Date(createDate.toDateString());
            var threeMA = new Date(createDate.setMonth(createDate.getMonth() + 3));
            var isnewMA = new Date(createDate.setMonth(createDate.getMonth() - 3 - this.allData.isNewAddMonth));
            this.estimate.Contract_Start_Date__c = val;
            this.allData.checkedAssets = this.refreshAsset(this.allData.checkedAssets.length,this.allData.checkedAssets);
            this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
        }
    }
    //分页Limit
    get pageDataLimitOptions() {
        return [
            { label: '10', value: '10' },
            { label: '20', value: '20' },
            { label: '50', value: '50' },
            { label: '100', value: '100' },
            { label: '200', value: '200' },
        ];
    }
    handlePageLimitChange(event) {
        this.IsLoading = true;
        // this.allDataInfo();
        this.pageDataLimit = event.detail.value;
        this.allData.selRecordOption = event.detail.value;
        this.allData.selctRecordNum = this.allData.selRecordOption *1;
 
        this.currentPage = 1;
        this.allData.currPage = 1;
        // this.getUnCheckedAssetNowData();
        this.handleunCheckedAssetColumnsAndData(this.allData.unCheckedAssets);
 
        this.IsLoading = false;
    }
    //首页
    toTop(event) {
        this.IsLoading = true;
 
        // 前端 处理
        this.currentPage = 1;
        this.allData.currPage = 1;
        // this.getUnCheckedAssetNowData();
        this.handleunCheckedAssetColumnsAndData(this.allData.unCheckedAssets);
        this.IsLoading = false;
    }
    //上一页
    toPre(event) {
        this.IsLoading = true;
        // currentPage 后台未对currentPage值判断,补充--页面禁用
        if (this.currentPage <= 1) {
            this.IsLoading = false;
            return;
        } else {
            this.currentPage--;
        }
 
        this.allData.currPage = this.currentPage;
        // this.getUnCheckedAssetNowData();
        this.handleunCheckedAssetColumnsAndData(this.allData.unCheckedAssets);
        this.IsLoading = false;
    }
    //下一页
    toNext(event) {
        this.IsLoading = true;
        if (this.currentPage >= this.pageCount) {
            this.IsLoading = false;
            return;
        } else {
            this.currentPage++;
        }
 
        this.allData.currPage = this.currentPage;
        this.handleunCheckedAssetColumnsAndData(this.allData.unCheckedAssets);
        this.IsLoading = false;
    }
    //尾页
    toEnd(event) {
        this.IsLoading = true;
 
        this.currentPage = this.pageCount;
        this.allData.currPage = this.currentPage;
        // this.getUnCheckedAssetNowData();
        this.handleunCheckedAssetColumnsAndData(this.allData.unCheckedAssets);
        this.IsLoading = false;
    }
    //分页后台数据返回后处理
    handlePageBtnReturn(result){
        result = JSON.parse(result);
        this.allData = result;
        //页面相关数据初始化
        this.handleInitSimpleData(result);
        //unCheckedAssets 处理
        this.handleunCheckedAssetColumnsAndData(result.unCheckedAssets);
        this.IsLoading = false;
    }
 
    //保有设备 搜索条件
    get textOpts() {
        return [
            { label: '主机/耗材', value: 'S:AssetMark__c' },
            { label: '保有设备名', value: 'S:Name' },
            { label: '机身编码', value: 'S:SerialNumber' },
            { label: '最近一期维修合同', value: 'S:CurrentContract__r.Management_Code__c' },
            { label: '装机地点', value: 'S:Installation_Site__c' },
            { label: '科室', value: 'S:Department_Name__c' },
        ];
    }
    get equalOpts() {
        return [
            { label: '等于', value: 'equals' },
            { label: '包含', value: 'contains' },
            { label: '不等于', value: 'notequals' },
        ];
    }
    //获取当前未选择的保有设备--util
    getUnCheckedAssetNowData(){
        if(this.unCheckedAssetData && this.unCheckedAssetData.length > 0){
            this.unCheckedAssetNowData = this.unCheckedAssetData.slice((this.currentPage-1)*this.allData.selRecordOption,this.currentPage*this.allData.selRecordOption);
            // this.unCheckedAssetNowData = this.unCheckedAssetData;
        }else{
            this.unCheckedAssetNowData = [];
        }
 
        this.unCheckedAssetDataLength = this.unCheckedAssetData.length;
        this.pageCount = Math.ceil(this.unCheckedAssetData.length / this.allData.selRecordOption);
        this.allData.currPage = this.currentPage;
        //  下方文字 所在位置
        this.unCheckedAssetDataShow1 = (this.currentPage-1)*this.pageDataLimit;
        // 数据下标 -1(最后一条数据位置)
        this.unCheckedAssetDataShow2 = this.currentPage*this.pageDataLimit >= this.allData.totalRecords ? this.allData.totalRecords : this.currentPage*this.pageDataLimit - 1;
        this.pageBtnDiasbled();
    }
    handleTableUncheckedRecCheckBox(event) {
        let index = event.currentTarget.dataset.id;
        console.log('handleTableUncheckedRecCheckBox index',index);
        this.allData.unCheckedAssets.forEach(function(ar) {
            if (ar.rec.Id == index) {
                ar.rec_checkBox_c = event.detail.checked;
                console.log('ar.rec_checkBox_c',ar.rec_checkBox_c);
            }
        });
    }
    
    //报价提交对象 变更 --util
    controlDisabled(event) {
        window.open("/apex/ChangeDealerApproval?eid=" + this.recordId,'ChangeDealerApproval','height=300,width=700,toolbar=no,menubar=no,left=20%,top=30%,scrollbars=yes,resizable=no,location=no,status=no');
    }
    //服务合同 内容修改   todo 通过传入参数,制定字段值
    changeDepartment(event) {
        this.estimate.Department__c = event.detail.value;        
    }
    //合同开始预订日
    changeEstiStartdate(event) {
        this.IsRefresh = false;
        let val = event.detail.value;
        this.estimate.Contract_Esti_Start_Date__c = event.detail.value;
        // 2023/09/01 合同结束预订日 显示同步
        // 报价规则改善 20230310 start val 2022-12-12
        var startday = estimateUtility.handleInfo.addMonths(val,6);
        var startday1 = estimateUtility.handleInfo.addMonths(val,12);
        // del startdateaddsix1-3 seamlessRenew 会重新赋值,这里给值无意义 - page好像有改动逻辑?简单看了下逻辑,依旧会重新赋值
        this.allData.startdateaddsix1 = startday;
        this.allData.startdateaddsix2 = startday;
        this.allData.startdateaddsix3 = startday1;
        this.allData.startdateaddsix4 = val;
        console.log('this.allData.startdateaddsix1 ',this.allData.startdateaddsix1 );
        console.log('this.allData.startdateaddsix2 ',this.allData.startdateaddsix2 );
        console.log('this.allData.startdateaddsix3 ',this.allData.startdateaddsix3 );
        console.log('this.allData.startdateaddsix4 ',this.allData.startdateaddsix4 );
        var rowCnt = this.productCount;
        this.allDataInfo();
        let returnData = estimateUtility.handleInfo.seamlessRenew(this,rowCnt,this.allData,this.allData.checkedAssets,this.PageDisabled,this.IsContractEstiStartDateDisabled);
        this.allData = returnData.allData;
        this.allData.checkedAssets = returnData.checkedAssets;
        this.handleInitSimpleData(this.allData);
        this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
        // 2023/09/18 seamlessRenew 可能修改 IsContractEstiStartDateDisabled 值,handleInitSimpleData中未处理该禁用
        this.IsContractEstiStartDateDisabled = returnData.IsContractEstiStartDateDisabled;
        // 报价规则改善 20230310 end
        if (!this.SaveBtnDisabled) {
            this.estimate.Contract_Start_Date__c =val;
            this.changeContractStartdate(val);
        }
        this.makeRealPrice(1);
        this.IsRefresh = true;
    }
    // == checkContractRange
    handleChangeContractRange(event) {
        let errorMsg = '';
        //页面 required
        if (isNaN(parseInt(event.target.value))) {
            errorMsg = '必须输入合同月数!';
        }else if (event.target.value <= 0) {
            errorMsg = '合同月数必须大于0';
        }else if (event.target.value > 60) {
            errorMsg = '合同期最长只能选择60个月!';
        }
        if (errorMsg != '') {
            estimateUtility.toast.showToast(this, 'error', errorMsg);
            //页面值同步刷新
            event.target.value = null;
        }
        this.estimate.Contract_Range__c = event.target.value; 
        // 2023/09/01 合同结束预订日 显示同步
        // this.handleChangeContractEstiEndDate(this.estimate.Contract_Esti_Start_Date__c);
        console.log('this.estimate.Contract_Range__c',this.estimate.Contract_Range__c);
        //页面数据刷新 --checkAssetData reresh
        this.allData.checkedAssets = this.refreshAsset(this.allData.checkedAssets.length,this.allData.checkedAssets);
        this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
    }
    //合同结束预订日 - 有计算逻辑,填写无意义 -> 同步 初步计算
    handleChangeContractEstiEndDate(val) {
        console.log('handleChangeContractEstiEndDate');
        if (this.estimate.Contract_Esti_Start_Date__c && this.estimate.Contract_Range__c) {
            let datearr = val.split("-");//基础日期
            let months = this.estimate.Contract_Range__c *1;//增加月数 *1 转Number
            let year = parseInt(datearr[0]);
            let month = parseInt(datearr[1][0] == 0 ? datearr[1][1] : datearr[1]) - 1;
            let day = parseInt(datearr[2][0] == 0 ? datearr[2][1] : datearr[2]);
            year += Math.floor((month + months) / 12); //计算年
            month = Math.floor((month + months) % 12) + 1; //计算月
            let d_max = new Date(year + "/" + (month + 1) + "/0").getDate();  //获取计算后的月的最大天数
            if (day > d_max) {
                day = d_max;
            }
 
            let date = year + "-" + (month < 10 ? ("0" + month) : month) + "-" + (day < 10 ? ("0" + day) : day);
            this.estimate.Contract_Esti_End_Date__c = date;
 
        }
        console.log('this.estimate.Contract_Esti_End_Date__c',this.estimate.Contract_Esti_End_Date__c);
    }
    //报价提交对象
    handleChangeEstimateTarget(event) {
        this.estimate.Estimate_Target__c = event.detail.value;
        //resetDealer 处理页面隐藏
        this.handleEstimateTargetIsHospitalTrue();
    }
    handleEstimateTargetIsHospitalTrue(){
        this.EstimateTargetIsDealer = this.estimate.Estimate_Target__c == '经销商';
    }
    //==onChDealerUpdateJs 报价提交对象 为经销商 才能触发该事件
    handleChangeDealer(event) {
        this.estimate.Dealer__c = event.detail.value[0] ? event.detail.value[0] : '';
        onChDealerUpdate({
            estimateStr: JSON.stringify(this.estimate),
            checkDealerId : this.estimate.Dealer__c
        }).then(result => {
            if (result != null) {
                this.estimate = JSON.parse(result);
            }
        }).catch(error => {
        }).finally(() => {
            if (this.estimate.Is_RecognitionModel__c) {
                estimateUtility.toast.showToast(this, 'warning', '请注意,当前经销商为先款对象。');
            }
        }); 
 
    }
    //申请报价金额
    checkDiscount(event) {
        console.log('checkDiscount');
        console.log('event.detail.value;',event.currentTarget.value);
        // this.IsRefresh = false;
        let val = event.currentTarget.value;
        this.estimateTemp = {Request_quotation_Amount__c : Math.round(val)};
        if (!val) {
            val = '';
            this.estimate.Request_quotation_Amount__c = "";
            this.estimate.Service_discount_Rate__c = 0.00;
            this.IsRefresh = true;
            return;
        }
        // 非数字,并不会触发,页面会有提示
        if (isNaN(parseInt(val))) {
            estimateUtility.toast.showToast(this, 'error', '请输入数值');
            val = 0.00;
            this.estimate.Request_quotation_Amount__c = 0.00;
            this.IsRefresh = true;
            return;
        }
        this.allDataInfo();
        let returnData = estimateUtility.handleInfo.checkDiscount(this,val,this.allData,this.IsContractEstiStartDateDisabled,this.IsContractstartdateDisabled,this.IsRequestQuotationAmountDisabled,this.refreshAssetBtn,this.AgreeRenewTenDisabled);
 
        this.allData = returnData.allData;
        this.handleInitSimpleData(this.allData);
        this.IsContractEstiStartDateDisabled = returnData.IsContractEstiStartDateDisabled;
        this.IsContractstartdateDisabled = returnData.IsContractstartdateDisabled;
        this.IsRequestQuotationAmountDisabled = returnData.IsRequestQuotationAmountDisabled;
        this.refreshAssetBtn = returnData.refreshAssetBtn;
        this.isAgreeRenew = returnData.isAgreeRenew;
        this.refreshAssetBtnLWC = this.refreshAssetBtn;
        console.log('Until checkDiscount after',returnData.AgreeRenewTenDisabled);
        this.AgreeRenewTenDisabled = returnData.AgreeRenewTenDisabled;
        this.makeRealPrice(1);
 
        //上限金额清空
        this.estimate.Limit_Price_Amount__c = '';
        // this.estimate.Request_quotation_Amount__c = Math.round(val);
        // event.detail.value = this.estimate.Request_quotation_Amount__c;
        console.log('this.estimate.Request_quotation_Amount__c final',this.estimate.Request_quotation_Amount__c);
        this.estimate.Request_quotation_Amount__c = 0;
        console.log('this.estimate.Request_quotation_Amount__c 0',this.estimate.Request_quotation_Amount__c);
 
        this.event1 = setTimeout(() => {
            if (this.isAgreeRenew) {
                this.estimate.Request_quotation_Amount__c = Math.round(val*0.9);
            }else{
                this.estimate.Request_quotation_Amount__c = Math.round(val);
            }
            this.estimate.Limit_Price_Amount__c = (this.localParseFloat(this.estimate.Asset_Repair_Sum_Price__c)+this.localParseFloat(this.estimate.Request_quotation_Amount__c))*1.3; //zzm 20240117 上限金额bug
          console.log('setTimeout',this.estimate.Request_quotation_Amount__c);
        }, 1);
        console.log('this.estimate.Request_quotation_Amount__c 01',this.estimate.Request_quotation_Amount__c);
 
        this.estimate = JSON.parse(JSON.stringify(this.estimate));
        console.log('this.estimate.Request_quotation_Amount__c 02',this.estimate.Request_quotation_Amount__c);
 
        // this.IsRefresh = true;
    }
 
    get quotationAmount(){
        return this.estimateTemp.Request_quotation_Amount__c;
    }
    // 上限金额
    handleLimitPriceAmount(event) {
        console.log('handleLimitPriceAmount',event.currentTarget.value);
        // this.estimate.Limit_Price_Amount__c = event.detail.value;
        let num = event.currentTarget.value;
        this.estimate.Limit_Price_Amount__c = 0;
        this.event1 = setTimeout(() => {
          // this.estimate.AgencyHos_Price__c = num.toFixed(2);
            this.estimate.Limit_Price_Amount__c = Math.round(num);
 
            console.log('this.estimate.Limit_Price_Amount__c event1',this.estimate.Limit_Price_Amount__c);
        }, 1);
 
        this.estimate = JSON.parse(JSON.stringify(this.estimate));
        console.log('this.estimate.AgencyHos_Price__c',this.estimate.Limit_Price_Amount__c);
 
    }
    /*
     * @param t   1: 金額により割引
     */
    makeRealPrice(t) {
 
        // 実際金額合計
        // 申请报价金额
        var sum1 = this.localParseFloat(this.estimate.Request_quotation_Amount__c);
        // 修理总额
        var sum2 = this.estimate.Asset_Repair_Sum_Price__c ? this.estimate.Asset_Repair_Sum_Price__c : null ;
        //*1 避免NaN
        var sum1 = this.localParseFloat(sum1*1);
        // 上限
        var upPrice = this.estimate.GuidePrice_Up__c;
        upPrice = this.localParseFloat(upPrice*1);
        // 下限
        var downPrice = this.estimate.GuidePrice_Down__c;
        downPrice = this.localParseFloat(downPrice*1);
 
        // 相对标准价格范围的折扣率 计算
        // 1)标准价格范围内时,结果为0;
        // 2)比标准价格低时,结果是1-希望价格/标准价的最低价格
        // 3)比标准价格高时,结果是1-希望价格/标准价的最高价格
        var disMP = 0.00;
        var disP = this.estimate.Service_discount_Rate__c;
 
        if(sum1 < downPrice){
            disMP = ((1 - sum1/downPrice) * 100)*1;
        }else if(sum1 >= downPrice && sum1 <= upPrice){
            disMP = 0.00;
        }else if(sum1 > upPrice){
            disMP = 1*((1 - sum1/upPrice) * 100);
        }
        //出现精度浮动
 
        if (disMP != disP) {
            disMP = '' + disMP.toFixed(2) +  '%';
            // 20% -parseFloat = 20
            this.estimate.Service_discount_Rate__c = parseFloat(disMP);
        }
        // 修理総額を計上
        let sum = sum1 + this.localParseFloat(sum2*1);
        this.estimate.Maintenance_Price__c = sum*1;
    }
    //最终价格决定形式
    handleFinalPriceDecideWay(event) {
        this.estimate.finalPriceDecideWay__c = event.detail.value;
    }
    //是否销售附带
    handleSalesIncidental(event) {
        this.estimate.Sales_incidental__c = event.detail.checked;
    }
    //主要谈判次数
    handleMainTalksTime(event) {
        this.estimate.mainTalksTime__c = event.detail.value;
    }
    //谈判的开始时间
    handleTalksStartDate(event) {
        this.estimate.talksStartDate__c = event.detail.value;
    }
    //经销商和医院的价格 classic 保存两位小数,四舍五入  页面显示依旧是多位,但实际值已经变化(classic效果)
    handleAgencyHosPrice(event) {
        let num = event.currentTarget.value * 1;
        // event
        this.estimate.AgencyHos_Price__c = num.toFixed(2);
        console.log('this.handleAgencyHosPrice.AgencyHos_Price__c',this.estimate.AgencyHos_Price__c);
    }
    //价格申请理由
    handleDiscountReason(event) {
        this.estimate.Discount_reason__c = event.detail.value;
    }
    //消费率改善方案
    handleImproveConsumptionRateIdea(event) {
        this.estimate.Improve_ConsumptionRate_Idea__c = event.detail.value;
    }
    //打印报价 复选框选择  单选
    handleSimply(event){
        let param = event.currentTarget.dataset.param;
        this.estimate[param] = event.detail.checked;
        this.printFlag = false;
        let paramsList = ["Print_ListPrice__c","Print_Simplify__c","Print_RepairPrice__c","Print_SumPrice__c"];
        for (var i = 0; i < paramsList.length; i++) {
            if (param != paramsList[i]) {
                this.estimate[paramsList[i]] = false;
            }
        }
        this.printFlag = true;
    }
    //三方协议
    handlePrintContract(event) {
        let param = event.currentTarget.dataset.param;
        this.estimate[param] = event.detail.checked;
    }
    //合同开始日
    handleContractStartDate(event) {
        this.estimate.Contract_Start_Date__c = event.detail.value;
        //changeContractStartdate
        this.changeContractStartdate(this.estimate.Contract_Start_Date__c);
    }
    //无缝续签折扣 
    handleRenewTenOFF(event) {
        this.estimate.renewTen_OFF__c = event.detail.checked;
        console.log('this.estimate.renewTen_OFF__c',this.estimate.renewTen_OFF__c);
    }
    handleAgreeRenewTenOFF(event) {
        this.estimate.AgreeRenewTen_OFF__c = event.detail.checked;
    }
    //保存
    async handleSave(event){
        //onclick
        this.IsLoading = true;
        let resEGFlgconfim = await this.EGFlgconfim('【贸易合规】--服务报价保存涉及警示产品');
        if (resEGFlgconfim) {
            this.allDataInfo();
            // 2023/09/18 unCheckedAssets 后台方法未涉及该属性,直接置空,避免数据量过大,如果后台返回异常信息,则将原数据重新赋值
            let oldUnCheckedAssets = JSON.stringify(this.allData.unCheckedAssets);
            this.allData.unCheckedAssets = [];
 
            let saveDataStr = JSON.stringify(this.allData);
            console.log('handleSave');
            await save({
                saveData: saveDataStr,
            }).then(result => {
                console.log('handleSave result',result);
                if (result != null && result.indexOf('completion=5') != -1) {
                    //重新跳转该页面 携带参数
                    estimateUtility.toast.showToast(this, 'success', '保存好了');
                    window.location.href=window.location.origin+"/lightning/n/lexSelectAssetEstimateVM#id="+result.split('/')[1]; 
                    location.reload();
                }else{
                    estimateUtility.toast.showToast(this, 'error', result);
                    // 2023/09/18 返回异常,旧数据返回赋值 - 页面数据并没有更改(未调用 handleunCheckedAssetColumnsAndData),页面数据不会异常
                    this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
                }
            }).catch(error => {
                // 2023/09/18 返回异常,旧数据返回赋值
                this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
            }).finally(() => {
                this.IsLoading = false;
            }); 
            //oncomplete
            this.unblockUI();
        }
        this.IsLoading = false;
    }
    //
    async EGFlgconfim(title) {
        await this.getEstimateCost();   
        var cntWithKara = this.productCount;
        // 新合同备品确保提供 是否改变
        var alert1s = 0;
        //20231222
        var tradeTwoFlag = false;
        var AccDealerBlacklist2 = this.contract.AccDealerBlacklist2__c; //WYL 贸易合规2期 黑名单,警示名单
        var TradeComplianceStatusFlagFW = this.allData.TradeComplianceStatusFlagFW; //贸易合规开关
        var violationName =''   //违规产品型号
        for (var i = 0; i < cntWithKara; i++) {
            var isManual =this.allData.checkedAssets[i].isManual;
            var EGFlgtxt =this.allData.checkedAssets[i].mcae.EquipmentGuaranteeFlgTxt__c;
            var EGFlgnow =this.allData.checkedAssets[i].etGFlg;
            //20231214 sx 贸易合规add
            var checked = this.allData.checkedAssets[i].rec_checkBox_c;
            //补充 undefined的判定
            if (EGFlgtxt != undefined && EGFlgnow != undefined && EGFlgtxt != EGFlgnow) {
                alert1s = 1;
            }
            //选中的设备 只要有一个不合规就弹出提醒
            console.log('checked===='+checked);
            if(checked){
                console.log(this.allData.checkedAssets[i].rec.Product2);
                var ProTradeComplianceStatus = this.allData.checkedAssets[i].rec.Product2.ProTradeComplianceStatus__c;
                if(ProTradeComplianceStatus == '0' && checked){
                    tradeTwoFlag = true;
                    violationName += this.allData.checkedAssets[i].rec.Product2.Name + '、';
                }
            }
        }
        if (alert1s == 1) {
            let confirmResult = await estimateUtility.toast.handleConfirmClick("选择的保有设备[新合同备品确保提供]发生变化,是否继续?");
            if (!confirmResult) {
                return false;
            }
        }
        //20231214 sx 贸易合规add start
        if(TradeComplianceStatusFlagFW){
            if(AccDealerBlacklist2 =='3' || AccDealerBlacklist2 =='4' || AccDealerBlacklist2 =='24'){
                estimateUtility.toast.showToast(this, 'error', '黑名单:存在贸易合规风险,无法新建,有问题请联系法务部贸易合规窗口恽李娜。');
                this.EmailSending(1,null,null);
                return null;
            }else if(AccDealerBlacklist2 =='1' || AccDealerBlacklist2 =='2' || AccDealerBlacklist2 =='12'){
                estimateUtility.toast.showToast(this, 'error', '冻结清单:可能存在贸易合规风险,目前正在评估中(一般需5-10个工作日),暂时无法新建,有问题请联系法务部贸易合规窗口恽李娜。');
                return null;
            }else if(AccDealerBlacklist2 =='5' || AccDealerBlacklist2 =='6' || AccDealerBlacklist2 =='56'){
                if(tradeTwoFlag){
                    this.EmailSending(2,title,violationName.slice(0, -1));
                    if (!(await estimateUtility.toast.handleConfirmClick('您此次申请的业务可能存在贸易合规风险,是否继续申请,如有问题请联系法务本部贸易合规窗口恽李娜进一步评估(一般需5-10个工作日)'))) {
                        this.unblockUI();
                        return null;
                    }
                }
            }
        }
        //20231214 sx 贸易合规add end
        return this.onclickCheckchangedAfterPrint('true','true');
    }
 
    //2024-1-3 WYL 贸易合规2期 邮件 add start
    async EmailSending(type,title,violation){
        accSendEmailFW({
            mcid : this.mcid,
            titles :title,
            type :type,
            violationName:violation
        })
        .then(result=>{
            return;
        }).catch(err=>{
            console.log('邮件错误'+err);
        })
    }
     //2024-1-3 WYL 贸易合规2期 邮件 add end
    //ok 获取实际报价金额 按照上限比例算
    getEstimateCost() {
        // 行数   
        var rowcount = this.productCount;
        // 6.合同价格
        var mainteReal = parseFloat(this.estimate.Maintenance_Price__c);
        // 5.修理总额
        var assetRepairSumPrice = parseFloat(this.estimate.Asset_Repair_Sum_Price__c);
        // 计算实际报价总金额
        var realprice = mainteReal - assetRepairSumPrice;
        // 标准价格的最高价总额
        var GuidePriceUp = parseFloat(this.estimate.GuidePrice_Up__c);
        for (var i = 0; i < rowcount; i++) {
            // 去上限价格
            var assetListPrice = parseFloat(this.allData.checkedAssets[i].mcae.Adjustment_Upper_price__c);
            if(GuidePriceUp == 0){
                this.allData.checkedAssets[i].mcae.Estimate_Cost__c = 0;
            }else{
                var Estimate_Cost = (realprice * (assetListPrice / GuidePriceUp)).toFixed(2);
                //parseFloat 可能会为NAN
                this.allData.checkedAssets[i].mcae.Estimate_Cost__c = isNaN(Estimate_Cost) ? 0 : Estimate_Cost;
            }
        }
    }
   //
    async onclickCheckchangedAfterPrint(saveBtnDisabled, saveOrApproval) {
        console.log('onclickCheckchangedAfterPrint');
        var cntWithKara = this.productCount;
        var alerts = 0;
        // 新合同备品确保提供 是否改变
        var alert1s = 0;
        var today = new Date();
        today.setMonth(today.getMonth() - 3);
 
        for (var i = 0; i < cntWithKara; i++) {
            var isManual = this.allData.checkedAssets[i].isManual;//value boolean
 
            if (isManual) {
                //原页面未找到对应id  Assert_lkid
            }
            if (!isManual) {
                var strDate = this.allData.checkedAssets[i].rec.Final_Examination_Date__c ? this.allData.checkedAssets[i].rec.Final_Examination_Date__c : '';
 
                strDate = strDate.replace(/(^\s*)|(\s*$)/g, ""); 
                if (strDate == "" || Date.parse(strDate) < Date.parse(today)) {
                    alerts = 1;
                }
            }
        }
 
        if (alerts == 1) {
            let confirmResult = await estimateUtility.toast.handleConfirmClick("选择的保有设备[最后点检日]为空或已经超过三个月之前,是否继续?");
        
            if (!confirmResult) {
                return false;
            }
        }
        if (saveOrApproval == "true") {
            if (await this.saveBeforeCheckPriceChange()) {
                let confirmResult = await estimateUtility.toast.handleConfirmClick("行信息有变化(服务合同价格),是否更新报价?");
            
                if (confirmResult) {
                    this.allData.changedSubmitPrice = true;
                }else{
                    this.allData.changedSubmitPrice = false;
                    this.unblockUI();
                    return false;
                }
            }
            this.allData.isSaveOrApproval = true;
 
        }
       return true;
    }
    //
    unblockUI(){
        // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk star
        // disable1();
        // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk end
        this.pageSetDisabled();
        var isChange = this.allData.changedSubmitPrice;
        if (isChange) {
            this.allData.changedSubmitPrice = false;
            //页面数据刷新 --checkAssetData reresh 后handleCheckedAssetColumnsAndData
            this.allData.checkedAssets = this.refreshAsset(this.allData.checkedAssets.length,this.allData.checkedAssets);
            this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
        }
        //未找到该id
        
    }
    //
    async saveBeforeCheckPriceChange() {
        console.log('saveBeforeCheckPriceChange');
        var needClearId = false;
        //this.productCount =>  this.allData.productCount
        var rowCnt = this.productCount;
        var assIds = "";
        var proIds = "";
        var priceMap = new Map();
        var newProductMap = new Map();
        var newProductCheck = false;
        var nowDate = new Date();
        var createdDate = null;
        var createdDateShow = this.estimate.CreatedDate;
        var contractDate = new Date(this.estimate.Contract_Start_Date__c);
        if (createdDateShow && createdDateShow.trim() != '') {
            createdDate = new Date(createdDateShow);
            newProductCheck = true;
        } else {
            createdDate = new Date();
        }
        var threeMonthAfter = new Date(createdDate.setMonth(createdDate.getMonth() + 3));
        createdDate = new Date(createdDate.setMonth(createdDate.getMonth() - 3));
        for (var i = 0; i < rowCnt; i++) {
            var isManual = this.allData.checkedAssets[i].isManual;
            //mcae 不会为null
            var isnew = this.allData.checkedAssets[i].mcae.IsNew__c;
            var price = this.allData.checkedAssets[i].mcae.Estimate_List_Price__c ; 
            if (isManual) {
                var a = this.allData.checkedAssets[i].mcae.Product_Manual__c; 
                //补充 a 有值的判定
                if ( a != "000000000000000000" && a != "" && a) {
                    if (proIds == "") {
                        proIds = "'" + a + "'";
                    } else {
                        proIds = proIds + ",'" + a + "'";
                    }
                    if (isnew) {
                        priceMap.set(a, price/this.allData.isNewPriceAdj);
                    } else {
                        priceMap.set(a, price);
                    }
                    newProductMap.set(a, isnew);
                    
                } else {
                    continue;
                }
            }else {
                var aId = this.allData.checkedAssets[i].rec.Id;
                if (assIds == "") {
                    assIds = "'" + aId + "'";
                } else if (aId) {////补充 aId 有值的判定
                    assIds = assIds + ",'" + aId + "'";
                }
                if (isnew) {
                    priceMap.set(aId, price/this.allData.isNewPriceAdj);
                } else {
                    priceMap.set(aId, price);
                }
                newProductMap.set(aId, isnew);
            }
        }
 
        // 选择设备后价格变更check
        if (assIds.length > 0) {
            //后台查询1
            await saveBeforeCheckPriceChangeAsset({
                assIds : assIds
            }).then(asList => {
             
                if (asList != null) {
                    for(var i=0;i<asList.length;i++) {
                        var asvar = asList[i];
                        var asId = asvar["Id"];
                        var mprice = asvar["Maintenance_Price_Month__c"];
                        var ptDt = asvar["Posting_Date__c"];
                        var postingDate = null;
                        if (ptDt != null && ptDt != '') {
                            postingDate = new Date(ptDt);
                        }
                        var inDt = asvar["InstallDate"];
                        var installDate = null;
                        if (inDt != null && inDt != '') {
                            installDate = new Date(inDt);
                        }
                        var priceShow = priceMap.get(asId);
                        var isNew = newProductMap.get(asId);
                        if (this.DecideBtnDisabled) {
                            if (Number(mprice).toFixed(2) != Number(priceShow).toFixed(2)) {
                                needClearId = true;
                                return needClearId;
                            }
                        }
                    }
                }
            }).catch(error => {
            }).finally(() => {
            });
        }
        console.log('proIds',proIds);
        if (proIds.length > 0) {
            if (!this.DecideBtnDisabled) {
                var oldDateStr = this.estimate.Contract_Start_Date__c;
                console.log('proIds oldDateStr',oldDateStr);
                var oldDate = new Date();
                if (oldDateStr != null && oldDateStr != '') {
                    oldDate = new Date(oldDateStr);
                }
                var crdt = new Date(this.estimate.CreatedDate);
                var newContractDate = new Date(this.estimate.Contract_Start_Date__c);
                var sixMonthAfter = new Date(crdt.setMonth(crdt.getMonth() + 6));
                if ((newContractDate > sixMonthAfter && oldDate <= sixMonthAfter) || (newContractDate <= sixMonthAfter && oldDate > sixMonthAfter)) {
                    this.allData.changedAfterPrint = true;
                    return true;
                }
            } else {
                //后台查询2
                await saveBeforeCheckPriceChangeProduct2({
                    proIds : proIds
                }).then(pdList => {
                    if (pdList != null) {
                        for(var i=0;i<pdList.length;i++) {
                            var pdvar = pdList[i];
                            var pdId = pdvar["Id"];
                            var mprice = pdvar["Maintenance_Price_Month__c"];
                            var priceShow = priceMap.get(pdId);
                            if (Number(mprice).toFixed(2) != Number(priceShow).toFixed(2)) {
                                needClearId = true;
                                return needClearId;
                            }
                        }
                    }
                }).catch(error => {
                }).finally(() => {
                });
            }
        }
        return needClearId;
    }
 
    // 不保存返回
    cancel(event) {
        if (this.allData.targetMaintenanceContractId) {
            //返回原报价页面
            this.navigateToOtherObj(this.allData.targetMaintenanceContractId);
        }else{
            location.reload();
        }
    }
    // 保存返回
    async handleSaveAndCancel(event){
        this.IsLoading = true;
        let resEGFlgconfim = await this.EGFlgconfim('【贸易合规】--服务报价保存涉及警示产品');
        if (resEGFlgconfim) {
             //onclick
        let checkResult = await this.onclickCheckchangedAfterPrint('true','true');
        if (checkResult) {
            //修改值传回
            this.allDataInfo();
            // 2023/09/16 unCheckedAssets 后台方法未涉及该属性,直接置空
            let oldUnCheckedAssets = JSON.stringify(this.allData.unCheckedAssets);
            this.allData.unCheckedAssets = [];
            //checkedAssets unCheckedAssetData 在更改的时候同步改动
            let saveDataStr = JSON.stringify(this.allData);
            console.log('saveDataStr',JSON.stringify(this.allData.estimate));
            await saveAndCancel({
                saveData: saveDataStr,
            }).then(result => {
                console.log('handleSaveAndCancel result',result);
                if (result != null && result.indexOf('navigateTo') == -1) {
                    estimateUtility.toast.showToast(this, 'error', result);
                    // 2023/09/18 返回异常,旧数据返回赋值
                    this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
                }else if (result != null) {
                    this.navigateToOtherObj(result.split('=')[1]);
                }
            }).catch(error => {
                // 2023/09/18 返回异常,旧数据返回赋值
                this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
            }).finally(() => {
            });  
        }
        }
        this.IsLoading = false;  
        
    }
    //行追加
    handleAddNewRows(event){
        this.IsLoading = true;
        addNewRows({
            checkedAssetsStr: JSON.stringify(this.allData.checkedAssets),
        }).then(result => {
            result = JSON.parse(result);
            this.allData.checkedAssets = this.refreshAsset(result.length,result);
        }).catch(error => {
        }).finally(() => {
            this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
            this.unblockUI();
            this.IsLoading = false;
        });  
    }
    //合同对象设备 数据修改处理
    handleTableProductManualChange(event) {
        let index = event.currentTarget.dataset.index;
        this.allData.checkedAssets[index].mcae.Product_Manual__c = event.detail.value[0] ? event.detail.value[0] : null;
        refreshProductData({
            checkedAssetsStr : JSON.stringify(this.allData.checkedAssets),
            topProductModelStr : JSON.stringify(this.allData.TopProductModel),
            productIdx : index,
            isNewPriceAdj : this.allData.isNewPriceAdj,
        }).then(result => {
            result = JSON.parse(result);
            console.log('handleTableProductManualChange result',result);
            //对后台返回数据 进行处理
            this.allData.checkedAssets = this.refreshAsset(result.length,result);
        }).catch(error => {
        }).finally(() => {
            this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
            this.unblockUI();
        }); 
    }
    //合同对象设备 机身编码跳转保有设备
    handlePageNagivateTo(event) {
        let param = event.currentTarget.dataset.param;
        // console.log('index',param);
        this.navigateToOtherObj(param);
    }
    //合同对象设备 全选
    checkAllcheckedAsset(event){
        this.IsCheckAllcheckedAsset = event.detail.checked;
        for (var i = 0; i < this.allData.checkedAssets.length; i++) {
            this.allData.checkedAssets[i].rec_checkBox_c = event.detail.checked;
        }
        this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
    }
    handleTableRecCheckBox(event) {
        let index = event.currentTarget.dataset.index;
        this.allData.checkedAssets[index].rec_checkBox_c = event.detail.checked;
    }
    handleTableCheckObjectChange(event) {
        let index = event.currentTarget.dataset.index;
        this.allData.checkedAssets[index].mcae.Check_Object__c = event.detail.checked;
    }
 
    // ==changeAsset 
    async handleTableRepairPriceChange(event) {
        // classic 参保修理金额 在实际保存时依旧只留两位小数
        let num = event.currentTarget.value*1;
        num = num.toFixed(2);
        let index = event.currentTarget.dataset.index;
        // event.detail.value = num;
        this.allData.checkedAssets[index].mcae.Repair_Price__c = num;
        //changeAsset  页面数据同步刷新--工具类中 
        this.allDataInfo();
        console.log('this.allData.checkedAssets[index].mcae.Repair_Price__c before changeAsset',this.allData.checkedAssets[index].mcae.Repair_Price__c);
 
        let changeAssetReturnData = await estimateUtility.handleInfo.changeAsset(this,this.allData.checkedAssets.length,this.allData.checkedAssets,this.PageDisabled,this.approvalDate,this.allData);
        //changeAsset alert Info  --工具类中alert
        // estimateUtility.toast.showToast(this, 'error', '合同期最长只能选择60个月!');
        this.allData = changeAssetReturnData.allData;
        this.approvalDate = changeAssetReturnData.approvalDate;
        // 仅保留两位小数
        this.assetRepairSumNum = changeAssetReturnData.assetRepairSumNum.toFixed(2);
        
        
        //页面相关数据初始化
        this.handleInitSimpleData(this.allData);
        this.allData.checkedAssets = this.refreshAsset(this.allData.checkedAssets.length,this.allData.checkedAssets);
        this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
        // examinationPriceCal(cnt);
        this.getLastContractRate();
        this.makeRealPrice(1);
        //上限合同 20230214 hql start
        var RequestquotationAmount = this.estimate.Request_quotation_Amount__c;
        var AssetRepairSumPrice    = this.estimate.Asset_Repair_Sum_Price__c;
        var Limit_Price_Amount = (this.localParseFloat(AssetRepairSumPrice)+this.localParseFloat(RequestquotationAmount))*1.3;
        Limit_Price_Amount = Math.round(Limit_Price_Amount);
        var Limit_Price_AmountOne =  this.estimate.Limit_Price_Amount__c;
        var Limit_PriceHidden =  this.allData.OldLimitPrice;
        this.estimate.Limit_Price_Amount__c = Limit_Price_Amount;
        var Limit_PriceHidden2 =  this.allData.isLimitPrice;
        if (Limit_PriceHidden2 == false) {
            this.estimate.Limit_Price_Amount__c = '';
        }
        //上限合同 20230214 hql end
        // 报价规则改善 20230315 start
        this.allDataInfo();
        let returnData = estimateUtility.handleInfo.seamlessRenew(this,this.allData.checkedAssets.length,this.allData,this.allData.checkedAssets,this.PageDisabled,this.IsContractEstiStartDateDisabled);
        this.allData = returnData.allData;
        this.handleInitSimpleData(this.allData);
        this.allData.checkedAssets = returnData.checkedAssets;
        // 2023/09/18 seamlessRenew 可能修改 IsContractEstiStartDateDisabled 值,handleInitSimpleData中未处理该禁用
        this.IsContractEstiStartDateDisabled = returnData.IsContractEstiStartDateDisabled;
 
        // 报价规则改善 20230315 end
        this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
        this.makeRealPrice(1);
        console.log('this.allData.checkedAssets[index].mcae.Adjustment_Lower_price__c before refresh',this.allData.checkedAssets[index].mcae.Adjustment_Lower_price__c);
        // 刷新赋值
        // num = this.allData.checkedAssets[index].mcae.Repair_Price__c;
        // this.allData.checkedAssets[index].mcae.Repair_Price__c = 0;
        // this.event1 = setTimeout(() => {
        //   this.allData.checkedAssets[index].mcae.Repair_Price__c = num.toFixed(2);
        // }, 1);
        // this.allData.checkedAssets[index].mcae = JSON.parse(JSON.stringify(this.allData.checkedAssets[index].mcae));
        // console.log('this.allData.checkedAssets[index].mcae.Repair_Price__c',this.allData.checkedAssets[index].mcae.Repair_Price__c);
 
    }
    //page
    getLastContractRate(){
        var rowCnt = this.productCount;
        var Contractrate = 0.00;
        var count = 0;
        for (var i = 0; i < rowCnt; i++) {
            var LastMContractID = this.allData.checkedAssets[i].rec ? this.allData.checkedAssets[i].rec.CurrentContract_F__c : null;
            if(LastMContractID){
                var tempContractrate = parseFloat((this.allData.checkedAssets[i].mcae.Asset_Consumption_rate__c ? this.allData.checkedAssets[i].mcae.Asset_Consumption_rate__c : null)*1);
                if(tempContractrate){
                    Contractrate = Contractrate + tempContractrate;
                }
                count++;
            }
        }
        var allContractRate = '' + 0.00 + '%';
        if( count > 0){
            allContractRate = '' + (Contractrate/count).toFixed(2) + '%';
        }
        this.estimate.Combined_rate__c = parseFloat(allContractRate);
        return allContractRate;
    }
    //合同对象设备 备注
    handleTableCommentChange(event) {
        let index = event.currentTarget.dataset.index;
        this.allData.checkedAssets[index].mcae.Comment__c = event.detail.value;
    }
    //合同对象设备 第三方回归
    handleTableThirdPartyReturnChange(event) {
        let index = event.currentTarget.dataset.index;
        this.allData.checkedAssets[index].mcae.Third_Party_Return__c = event.detail.checked;
    }
    // 合同对象设备 数据计算处理 todo 核对涉及变量
    refreshAsset(cnt,checkedAssets) {
        console.log('cnt',cnt);
        // 提交后就页面不计算了
        var isDisabled = this.PageDisabled;
        //  报价页面【合同定价总额】字段添加 20230608 start
        var TotalMaintenancePriceYear = 0.0;
        //  报价页面【合同定价总额】字段添加 20230608 end
        // 合同总理
        var newCount = 0;
        var isresduce = 0;
        var oyearCount = 0;
        var firstCCount = 0;
        var conCCount = 0;
        // row金額合計
        var repairSum = 0;
        var listSum = 0;
        // 新品合同 判断
        var newCon = true;
        var contractStartDate = new Date(this.estimate.Contract_Start_Date__c);
        
        //多年保续签合同数量 thh 20220316 start
        var GuranteeCount = 0;
        // 报价规则改善 20230310 start
        // 2023/09/06 报价规则改善新增 - 显示页面部分整体处理
        this.IsRenewTenOFFDisabled = true;
        var renewTenOFF = this.estimate.renewTen_OFF__c;
 
        // 2023/09/06  result 变量无意义,后面js 有同名变量重新赋值
        var startime1 =  new Date(this.allData.Past_Contract_end_day);
        var startime2 = new Date(this.estimate.Contract_Esti_Start_Date__c);
        var result = (startime2-startime1)/(3600*24*1000);       
        var VMProductCountAll = this.allData.VMProductCountAll;
        var ProductCountAll = this.allData.VMProductCountAll;   
        if (VMProductCountAll ==ProductCountAll) {       
            result = 0;      
        }
 
        if (renewTenOFF == true) {
            this.IsContractEstiStartDateDisabled = true;
            this.IsRequestQuotationAmountDisabled = true;
            this.IsContractstartdateDisabled = true;
            this.refreshAssetBtn = true;
            this.refreshAssetBtnLWC = this.refreshAssetBtn;
            //2023/09/06 同意无缝续签 禁用
            this.AgreeRenewTenDisabled = true;
        }
        // 报价规则改善 20230310 end
        //2022故障品加费 获取userInfo简档名称 是否为FSE start
        var isFSE = this.allData.isFSE;
        //2022故障品加费 获取userInfo简档名称 end
        //20230208 上限合同开发 hql start
        if (isFSE) {
            this.IsLimitPriceAmountDisabled = true;
        }
        //20230208 上限合同开发 hql end
        // 预定开始日
        var startdate = new Date(this.estimate.Contract_Esti_Start_Date__c);
        // 预定开始日-6个月
        startdate.setMonth(startdate.getMonth() - 6);
        // 申请日 当前日期
        if(this.approvalDate != ''){
            //申请日
            this.approvalDate = new Date(this.approvalDate.toLocaleDateString());
            if (Date.parse(this.approvalDate) < Date.parse(startdate)) {
                newCon = false;
            }
        }
        // 最高、最低价格合计
        var downPriceSum = 0;
        var upPriceSum = 0;
        // 合同月数乗算  parseFloat(null.'',undefined) 为NAN  补充判断
        var month = parseFloat(this.estimate.Contract_Range__c);
        
        if (month == undefined || month == "" || isNaN(month)) {
            month = 1;
        }
        var month2 = 0;
        if (month > 12) {
            month2 = month - 12;
            month = 12;
        }
        for (var i = 0; i < cnt; i++) {
            console.log('refreshAsset i'+i);
            //字段按钮 默认可用
            checkedAssets[i].ShowAssetSituation = true;
            var strMoney = 0;
            var repairMoney = 0;
            // 行项目 最高、最低价格合计
            // 续签价格取联动价格页面计算,首签或产品取 实际价格
            // 下线价格
            var downPrice = 0;
            // 上线价格
            var upPrice = 0;
            // 12个月合同金额
            var Price_YearTXT = 0;
            var isManual = checkedAssets[i].isManual; //return boolean
            var isnew = checkedAssets[i].mcae.IsNew__c; //return boolean
            var assetListmonth = checkedAssets[i].mcae.Estimate_List_Price__c; 
            //市场多年保修价格开发 DC 2023/02/09 start 
            var VMassetListmonth = checkedAssets[i].rec ? (checkedAssets[i].rec.CurrentContract_F_asset__r ? checkedAssets[i].rec.CurrentContract_F_asset__r.Maintenance_Price_Year__c : '') : '';
            //市场多年保修价格开发 DC 2023/02/09 end 
            //  报价页面【合同定价总额】字段添加 20230608 start
            var Product2MaintenancePriceYear = checkedAssets[i].rec ? (checkedAssets[i].rec.Product2 ? checkedAssets[i].rec.Product2.Maintenance_Price_Year__c : '') : ''; 
            //page outputField 原本就是 隐藏
            Product2MaintenancePriceYear = this.localParseFloat(Product2MaintenancePriceYear);
            TotalMaintenancePriceYear += Product2MaintenancePriceYear;
            //  报价页面【合同定价总额】字段添加 20230608 end
            if (isManual) {
                var a = checkedAssets[i].mcae.Product_Manual__c ? checkedAssets[i].mcae.Product_Manual__c : ''; 
                console.log('isManual true a',a);
                if (a != '') {
                    strMoney = assetListmonth; 
                    // alert(strMoney);
                    Price_YearTXT = strMoney * 12;
                    if (isnew) {
                        newCount ++;
                        strMoney = month * strMoney + month2 * strMoney / this.allData.isNewPriceAdj;
                    } else {
                        newCon = false;
                        strMoney = month * strMoney + month2 * strMoney;
                    }
                    //补充空指针
                    var b = checkedAssets[i].rec ? (checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.Maintenance_Contract_No_F__c : '') : '';
                    var LastMContractRecord = checkedAssets[i].rec ? (checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.RecordType_DeveloperName__c : '') : ''; 
                    console.log('b product',b);
                    if(b != ''){
                        conCCount ++;
                        var lastendDate = new Date(checkedAssets[i].rec.CurrentContract_End_Date__c);
                        var lastContRange = 0;
                        if(LastMContractRecord == 'VM_Contract'){
                            newCount++;
                            //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start
                            GuranteeCount++;
                            newCon = false;
                            //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end
                            lastendDate = new Date(checkedAssets[i].rec.CurrentContract_F_asset__r.endDateGurantee_Text__c);
                            lastContRange = 36;
                        }else{
                            lastContRange = checkedAssets[i].rec.CurrentContract_F__r.Contract_Range__c; 
                        }
                        //最后结束日+1年
                        lastendDate.setMonth(lastendDate.getMonth() + 12);
                        if (Date.parse(contractStartDate) > Date.parse(lastendDate) ) {
                            oyearCount ++;
                        }
                        // 取联动价格
                        // 上一期合同实际报价月额
                        // * 1 避免 parseFloat(null) ->NAN
                        var LastMContract_Price = parseFloat(checkedAssets[i].mcae.LastMContract_Price__c  * 1);
                        var Adjustment_ratio_Lower = parseFloat(checkedAssets[i].mcae.Adjustment_ratio_Lower__c   * 1);
                        var Adjustment_ratio_Upper = parseFloat(checkedAssets[i].mcae.Adjustment_ratio_Upper__c   * 1);
                        //计算惩罚率
                        var Punish = this.calculateNtoMRatio( lastContRange,(month + month2));
                        if(Punish == 0){
                            return;
                        }
                        // 判断有无报价:没有按照标准价格实际联动
                        var Estimate_Num = checkedAssets[i].rec.CurrentContract_F__r.Estimate_Num__c ;
                        if(Estimate_Num == 0){
                            if(LastMContractRecord == 'VM_Contract'){
                                // gzw 20220630  实际联动6个月价格区分
                                var nowdate = new Date();
                                lastendDate = new Date(checkedAssets[i].rec.CurrentContract_F_asset__r.endDateGurantee_Text__c);
                                nowdate = nowdate.setMonth(nowdate.getMonth() + 6);
                                //市场多年保修价格开发 DC 2023/1/30 start 
                                var Maxcoefficient =0;
                                var Mincoefficient =0;
                                var ContractMonth = this.localParseFloat(this.estimate.Contract_Range__c);
                                var AssetRate = this.localParseFloat(checkedAssets[i].rec.CurrentContract_F_asset__r.Asset_Consumption_Rate__c);
                                checkedAssets[i].mcae.Asset_Consumption_rate__c = AssetRate;
                                if(AssetRate<= 50){
                                    Maxcoefficient = (1-0.3);
                                    Mincoefficient = (1-0.4);
                                }else if(AssetRate>50 &&AssetRate<=60){
                                    Maxcoefficient = (1-0.2);
                                    Mincoefficient = (1-0.3);
                                }else if(AssetRate>60 &&AssetRate<=70){
                                    Maxcoefficient = (1-0.15);
                                    Mincoefficient = (1-0.25);
                                }else if(AssetRate>70 &&AssetRate<=80){
                                    Maxcoefficient = (1-0.1);
                                    Mincoefficient = (1-0.2);
                                    
                                }else if(AssetRate>80 &&AssetRate<=90){
                                    Maxcoefficient = (1-0.05);
                                    Mincoefficient = (1-0.15);
                                }else if(AssetRate>90 &&AssetRate<=100){
                                    Maxcoefficient = 1;
                                    Mincoefficient = (1-0.05);
                                }else if(AssetRate>100 &&AssetRate<=110){
                                    Maxcoefficient = (1+0.05);
                                    Mincoefficient = 1;
                                }else if(AssetRate>110 &&AssetRate<=120){
                                    Maxcoefficient = (1+0.1);
                                    Mincoefficient = 1;
                                }else if(AssetRate>120 &&AssetRate<=130){
                                    Maxcoefficient = (1+0.2);
                                    Mincoefficient = (1+0.1);
                                }else if(AssetRate>130 &&AssetRate<=140){
                                    Maxcoefficient = (1+0.25);
                                    Mincoefficient = (1+0.15);
                                }else if(AssetRate>140){
                                    Maxcoefficient = (1+0.3);
                                    Mincoefficient = (1+0.2);
                                }
                                //市场多年保修价格开发 DC 2023/1/30 end 
                                if(nowdate < Date.parse(lastendDate)){
                                    // 市场多年保修价格开发 start DC 2023/01/19  
                                    //市场多年保设备小于2年半
                                    var AssetModelNo = checkedAssets[i].rec.Product2 ? checkedAssets[i].rec.Product2.Asset_Model_No__c : 0;
                                    var Category4 = checkedAssets[i].rec.Product2 ? checkedAssets[i].rec.Product2.Category4__c : ''; 
                                    //设备设备消费率小于1.4
                                    if(AssetRate<140){
                                        upPrice = VMassetListmonth * ContractMonth /12;
                                        if((AssetModelNo.includes('290')&&( Category4 =='BF'|| Category4=='BF扇扫'||Category4=='CF'))|| Category4 =='URF'){
                                            downPrice = upPrice;
                                        }else{
                                            downPrice = upPrice * 0.8;
                                        }
                                    }else{
                                        upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                                        downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;   
                                    }
                                    // 市场多年保修价格开发 end DC 2023/01/19  
                                }else{
                                    //市场多年保修价格开发 DC 2023/1/30 start  设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数
                                    upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                                    downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;
                                    //市场多年保修价格开发 DC 2023/1/30 end 
                                }
                                // gzw 20220630  实际联动6个月价格区分
                            }else{
                                upPrice = strMoney;
                                downPrice = strMoney * 0.8;
                            }
                        }else{
                            upPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100);
                            downPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100);
                        }
                    }else{
                        upPrice = strMoney;
                        downPrice = strMoney * 0.8;
                    }
                    // 上下限四舍五入
                    upPrice = upPrice.toFixed(2);
                    downPrice = downPrice.toFixed(2);
                    console.log('downPrice Product',downPrice);
                    // 12个月合同金额                    
                    if (!isDisabled) {
                        // 实际联动价格 start
                        //*1 转化为Number类型 结果保留两位小数
                        checkedAssets[i].mcae.Adjustment_Lower_price__c = (downPrice*1).toFixed(2);
                        checkedAssets[i].mcae.Adjustment_Upper_price__c = (upPrice*1).toFixed(2);
                        // 实际联动价格 end
                    }
                    checkedAssets[i].mcae.Estimate_List_Price_Page__c = strMoney * 1;
                    //Repair_Price__c null Number类型  .trim()
                    repairMoney = (checkedAssets[i].mcae.Repair_Price__c == undefined ? null : checkedAssets[i].mcae.Repair_Price__c ) *1;
                } else {
                    // TODO 一時的な対応、なんで別行の金額リフレッシュされた?
                    checkedAssets[i].mcae.Estimate_List_Price_Page__c = '';
                    // 12个月合同金额
                    if (!isDisabled) {
                        // 实际联动价格 start
                        checkedAssets[i].mcae.Adjustment_Lower_price__c = '';
                        checkedAssets[i].mcae.Adjustment_Upper_price__c = '';
                        // 实际联动价格 end
                     }
                }
            }
            else {
                // 所有设备按安装日、发货日(最早的),距离合同开始日6个月内都是新品合同
                var isNewDate = new Date( checkedAssets[i].rec.isNewDate_use__c);
                isNewDate.setMonth(isNewDate.getMonth() + 6);
                if (Date.parse(contractStartDate) > Date.parse(isNewDate)) {
                    newCon = false;
                }
                strMoney = assetListmonth ; 
                Price_YearTXT = strMoney * 12;
                if (isnew) {
                    strMoney = month * strMoney + month2 * strMoney / this.allData.isNewPriceAdj;
                } else {
                    strMoney = month * strMoney + month2 * strMoney;
                }
                var b = checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.Maintenance_Contract_No_F__c : ''; 
                var LastMContractRecord = checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.RecordType_DeveloperName__c : '';
                if(b != ''){
                    conCCount ++;
                    var lastendDate = new Date(checkedAssets[i].rec.CurrentContract_End_Date__c);
                    var lastendDate = new Date(checkedAssets[i].rec.CurrentContract_F__r.Contract_End_Date__c);
                    var lastContRange = 0;
                    if(LastMContractRecord == 'VM_Contract'){
                        newCount++;
                        //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start
                        GuranteeCount++;
                        newCon = false;
                        //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end
                        lastendDate = new Date(checkedAssets[i].rec.CurrentContract_F_asset__r.endDateGurantee_Text__c) ;
                        lastContRange = 36;
                    }else{
                        lastContRange = checkedAssets[i].rec.CurrentContract_F__r.Contract_Range__c; 
                    }
                    //最后结束日+1年
                    lastendDate.setMonth(lastendDate.getMonth() + 12);
                    if (Date.parse(contractStartDate) > Date.parse(lastendDate)) {
                        oyearCount ++;
                    }
                    // 取联动价格
                    // 上一期合同实际报价月额
                    var LastMContract_Price = parseFloat(checkedAssets[i].mcae.LastMContract_Price__c * 1);
                    var Adjustment_ratio_Lower = parseFloat(checkedAssets[i].mcae.Adjustment_ratio_Lower__c * 1);
                    var Adjustment_ratio_Upper = parseFloat(checkedAssets[i].mcae.Adjustment_ratio_Upper__c * 1);
                    //计算惩罚率   return month 不可能为0
                    var Punish = this.calculateNtoMRatio( lastContRange,(month + month2));
                    if(Punish == 0){
                        return;
                    }
                    // 判断有无报价:没有按照标准价格实际联动
                    var Estimate_Num = checkedAssets[i].rec.CurrentContract_F__r.Estimate_Num__c ;
                    if(Estimate_Num == 0){
                        if(LastMContractRecord == 'VM_Contract'){
                            // gzw 20220630  实际联动6个月价格区分
                            var nowdate = new Date();
                            lastendDate = new Date(checkedAssets[i].rec.CurrentContract_F_asset__r.endDateGurantee_Text__c);
                            nowdate = nowdate.setMonth(nowdate.getMonth() + 6);
                            //市场多年保修价格开发 DC 2023/1/30 start 
                            var Maxcoefficient =0;
                            var Mincoefficient =0;
                            var ContractMonth = this.localParseFloat(this.estimate.Contract_Range__c);
                            var AssetRate = this.localParseFloat(checkedAssets[i].rec.CurrentContract_F_asset__r.Asset_Consumption_Rate__c);
                            checkedAssets[i].mcae.Asset_Consumption_rate__c = AssetRate;
                            if(AssetRate<= 50){
                                Maxcoefficient = (1-0.3);
                                Mincoefficient = (1-0.4);
                            }else if(AssetRate>50 &&AssetRate<=60){
                                Maxcoefficient = (1-0.2);
                                Mincoefficient = (1-0.3);
                            }else if(AssetRate>60 &&AssetRate<=70){
                                Maxcoefficient = (1-0.15);
                                Mincoefficient = (1-0.25);
                            }else if(AssetRate>70 &&AssetRate<=80){
                                Maxcoefficient = (1-0.1);
                                Mincoefficient = (1-0.2);
                            }else if(AssetRate>80 &&AssetRate<=90){
                                Maxcoefficient = (1-0.05);
                                Mincoefficient = (1-0.15);
                            }else if(AssetRate>90 &&AssetRate<=100){
                                Maxcoefficient = 1;
                                Mincoefficient = (1-0.05);
                            }else if(AssetRate>100 &&AssetRate<=110){
                                Maxcoefficient = (1+0.05);
                                Mincoefficient = 1;
                            }else if(AssetRate>110 &&AssetRate<=120){
                                Maxcoefficient = (1+0.1);
                                Mincoefficient = 1;
                            }else if(AssetRate>120 &&AssetRate<=130){
                                Maxcoefficient = (1+0.2);
                                Mincoefficient = (1+0.1);
                            }else if(AssetRate>130 &&AssetRate<=140){
                                Maxcoefficient = (1+0.25);
                                Mincoefficient = (1+0.15);
                            }else if(AssetRate>140){
                                Maxcoefficient = (1+0.3);
                                Mincoefficient = (1+0.2);
                            }
                            //市场多年保修价格开发 DC 2023/1/30 end 
                            if(nowdate < Date.parse(lastendDate)){
                                // 市场多年保修价格开发 start DC 2023/01/19  
                                //市场多年保设备小于2年半
                                var AssetModelNo = checkedAssets[i].rec.Product2 ? checkedAssets[i].rec.Product2.Asset_Model_No__c : 0;
                                var Category4 = checkedAssets[i].rec.Product2 ? checkedAssets[i].rec.Product2.Category4__c : '';
                                //设备设备消费率小于1.4
                                if(AssetRate<140){
                                    upPrice = VMassetListmonth *ContractMonth / 12;
                                    if((AssetModelNo.includes('290')&&( Category4 =='BF'|| Category4=='BF扇扫'||Category4=='CF'))|| Category4 =='URF'){
                                        downPrice = upPrice;
                                    }else{
                                        downPrice = upPrice * 0.8;
                                    }
                                }else{
                                    upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                                    downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;   
                                }
                                // 市场多年保修价格开发 end DC 2023/01/19    
                            }else{
                                //市场多年保修价格开发 DC 2023/1/30 start  设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数
                                upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                                downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;
                                //市场多年保修价格开发 DC 2023/1/30 end 
                            }
                            // gzw 20220630  实际联动6个月价格区分
                        }else{
                            upPrice = strMoney;
                            downPrice = strMoney * 0.8;
                        }
                    }else{
                        upPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100);
                        downPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100);
                    }
                }else{
                    if (isnew) {
                        newCount ++;
                    } else {
                        newCon = false;
                        firstCCount ++;
                    }
                    upPrice = strMoney;
                    downPrice = strMoney * 0.8;
                }
                // 上下限四舍五入
                upPrice = upPrice.toFixed(2);
                downPrice = downPrice.toFixed(2);
                console.log('upPrice Asset',upPrice);
                console.log('strMoney Asset',strMoney);
                console.log('VMassetListmonth Asset',VMassetListmonth);
                console.log('LastMContract_Price Asset',LastMContract_Price);
                console.log('ContractMonth Asset',ContractMonth);
                console.log('Maxcoefficient Asset',Maxcoefficient);
                if (!isDisabled) {
                    // 实际联动价格 start
                    checkedAssets[i].mcae.Adjustment_Lower_price__c = (downPrice*1).toFixed(2);
                    checkedAssets[i].mcae.Adjustment_Upper_price__c = (upPrice*1).toFixed(2);
                    // 实际联动价格 end
                }
                console.log('checkedAssets[i].mcae.Adjustment_Upper_price__c Asset',checkedAssets[i].mcae.Adjustment_Upper_price__c );
                checkedAssets[i].mcae.Estimate_List_Price_Page__c = strMoney * 1;
                //<!-- (2022年12月上线)故障品加费 start -->  
                let Repair_Price_Auto = checkedAssets[i].Repair_Price_Auto;
                repairMoney = checkedAssets[i].mcae.Repair_Price__c == undefined  ? null : checkedAssets[i].mcae.Repair_Price__c;
                // Repair_Price_pass__c 没有值为null 避免下面条件误判   == null ? undefined : checkedAssets[i].mcae.Repair_Price_pass__c 
                let Repair_Price_pass = checkedAssets[i].mcae.Repair_Price_pass__c; 
                if ((repairMoney+1)==1) {
                    checkedAssets[i].mcae.Repair_Price__c = Repair_Price_Auto;
                    repairMoney = Repair_Price_Auto;
                }
                if ((Repair_Price_pass+1)==1) {
                    checkedAssets[i].mcae.Repair_Price_pass__c = Repair_Price_Auto;
                }
                let repairMoney1 = parseFloat(repairMoney * 1);
                let ISReducedpriceapproval = this.estimate.IS_Reduced_price_approval__c; 
                if (ISReducedpriceapproval =='有八折以下待审批' || ISReducedpriceapproval =='是' || isDisabled) {
                    checkedAssets[i].IsRepairPriceDisabled = true;
                }else{
                    checkedAssets[i].IsRepairPriceDisabled = false;
                }
                if (repairMoney1> 0 && (repairMoney1 <Repair_Price_Auto*0.80)) {
                    isresduce = isresduce+1;
                }
                //+ '' 避免获取值是undefined 或者 null 导致引用异常
                let ResonCannotWarranty = checkedAssets[i].rec.Reson_Can_not_Warranty__c + ''; 
                if(!(ResonCannotWarranty.indexOf("弃修") != -1)&&(repairMoney+1)==1){
                    checkedAssets[i].ShowAssetSituation = false;
                    checkedAssets[i].mcae.Repair_Price__c = '';
                }
                //在该部分js代码 未使用变量
                // let situation = checkedAssets[i].rec.Asset_situation__c + ''; 
            }
            repairSum = repairSum + parseFloat(repairMoney* 1);
            listSum = listSum + parseFloat(strMoney* 1);
            downPriceSum = downPriceSum + parseFloat(downPrice* 1);
            upPriceSum =  upPriceSum + parseFloat(upPrice* 1);
        }
        // 仅保留两位小数
        this.assetRepairSumNum = (repairSum * 1).toFixed(2);
        if (!isDisabled) {
            this.estimate.GuidePrice_Up__c = Math.round(upPriceSum) * 1;
            this.estimate.GuidePrice_Down__c = Math.round(downPriceSum) * 1;
        }
        this.estimate.Asset_Repair_Sum_Price__c = repairSum * 1;
        var allcount = this.productCount3 ;
        var result = '';
        if (allcount == 0) {
            result = null;
        //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 start
        }else if(GuranteeCount > 0 && GuranteeCount == allcount){
            result = '市场多年保续签合同';
        //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 end
        }else if (newCount > 0 && newCount == allcount && newCon == true) {
            result = '新品合同';
        }else if (((newCount > 0 && newCount == allcount) ||(newCount + firstCCount == allcount)) && newCon == false) {
            result = '首签合同';
        }else if(firstCCount > 0 && firstCCount == allcount){
            result = '首签合同';
        }else if(oyearCount > 0 && oyearCount == conCCount && allcount == oyearCount ){
            // 20220328 ljh update  LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start
            result = '非续签合同(空白期一年以上)';
        }else{
            result = '续签合同';
        }
        console.log('result',result);
        this.estimate.New_Contract_Type_TxT__c = result;
        this.allData.typeresult = result;
        // 取消酸化水
        //NotUseOxygenatedWaterAmount(1);
        //next  makeRealPrice 暂时补充 examinationPriceCal--方法 目前可走逻辑:makeRealPrice(1)
        // examinationPriceCal(cnt);
        this.makeRealPrice(1);
        this.getLastContractRate();
        // 报价规则改善 20230315 start todo
        this.allDataInfo();
        let returnData = estimateUtility.handleInfo.seamlessRenew(this,checkedAssets.length,this.allData,checkedAssets,this.PageDisabled,this.IsContractEstiStartDateDisabled);
        this.allData = returnData.allData;
        this.handleInitSimpleData(this.allData);
        // 2023/09/18 seamlessRenew 可能修改 IsContractEstiStartDateDisabled 值,handleInitSimpleData中未处理该禁用
        this.IsContractEstiStartDateDisabled = returnData.IsContractEstiStartDateDisabled;
        checkedAssets = returnData.checkedAssets;
        // 报价规则改善 20230315 end
        if (TotalMaintenancePriceYear!=0) {
            TotalMaintenancePriceYear = this.localParseFloat(TotalMaintenancePriceYear).toFixed(2);
            var ContractMonth1 = this.localParseFloat(this.estimate.Contract_Range__c).toFixed(2);
            var result = ((TotalMaintenancePriceYear/12)*ContractMonth1).toFixed(2);
            this.estimate.Total_Contract_Price__c = result;
        }
        //  报价页面【合同定价总额】字段添加 20230608 end
        //返回处理后的结果给allData的checkAsset
        this.makeRealPrice(1);
        return checkedAssets;
    }
    //
    calculateNtoMRatio(lastContRange, month ){
        var lastContRangeYear = Math.ceil(parseFloat(lastContRange* 1)/12);
        var currentMonthYear = Math.ceil(parseFloat(month* 1)/12);  
        if(currentMonthYear == lastContRangeYear || currentMonthYear == 1){
            return month;
        }else if(month <= 24) {
            return 12+ (month- 12) *1.1;
        }else if(month <= 36) {
            return 25.2 + (month- 24) *1.21;
        }else if(month <= 48) {
            return 39.72 + (month- 36) *1.331;
        }else if(month <= 60) {
            return 55.692 + (month- 48) *1.4641;
        }else {
            estimateUtility.toast.showToast(this, 'error', '合同期最长只能选择60个月!');
            return 0;
        }
    }
    //未选择的保有设备 当前页 全选
    checkAllUncheckedAsset(event){
        this.IsCheckAllUncheckedAsset = event.detail.checked;
        for (var i = 0; i < this.unCheckedAssetNowData.length; i++) {
            let index = this.unCheckedAssetNowData[i].Id;
            this.allData.unCheckedAssets.forEach(function(ar) {
                if (ar.rec.Id == index && !(ar.rec.Maintenance_Price_Month__c == 0 || ar.rec.IF_Warranty_Service__c == '否')) {
                    ar.rec_checkBox_c = event.detail.checked;
                }
            });
        }
        this.handleunCheckedAssetColumnsAndData(this.allData.unCheckedAssets);
    }
    //显示未选择保有设备
    showUnCheckedAsset(event){
        this.IsShowUnCheckedAsset = true;
    }
    //隐藏未选择保有设备
    hiddenUnCheckedAsset(event){
        this.IsShowUnCheckedAsset = false;
    }
    //未选择保有设备 搜索处理
    handleChangeText1(event){
        this.text1 = event.detail.value;
    }
    handleChangeCond1(event){
        this.cond1 = event.detail.value;
    }
    handleChangeVal1(event){
        this.val1 = event.detail.value;
    }
    //检索
    searchJs(event){
        this.IsLoading = true;
        this.allData.text1 = this.text1;
        this.allData.cond1 = this.cond1;
        this.allData.val1 = this.val1;
        this.allDataInfo();
        // 2023/09/16 unCheckedAssets 后台方法重新赋值,直接置空
        let oldUnCheckedAssets = JSON.stringify(this.allData.unCheckedAssets);
        this.allData.unCheckedAssets = [];
        searchBtn({
            initDataStr: JSON.stringify(this.allData),
        }).then(result => {
            result = JSON.parse(result);
            console.log('searchJs result',result);
            this.allData = result;
            this.handleInitSimpleData(result);
            //unCheckedAssets 处理
            this.currentPage = 1;
            this.handleunCheckedAssetColumnsAndData(result.unCheckedAssets);
        }).catch(error => {
            // 2023/09/18 返回异常,旧数据返回赋值
            this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
        }).finally(() => {
            // classic 一致,优化:改用flag,页面显示和后台处理条件不一致(清除条件时,页面显示为 S:AssetMark__c,实际为 '')
            this.allData.text1 = this.allData.text1 == '' ? 'S:AssetMark__c' : this.allData.text1;
            this.text1 = this.allData.text1;
            this.cond1 = this.allData.cond1;
            this.val1 = this.allData.val1;
            this.IsLoading = false;
        });  
    }
    //清除条件 
    clearAndSearch() {
        this.text1 = '';
        this.cond1 = 'equals';
        this.val1 = ''; 
        this.searchJs();
    }
    //确认添加 -- 刷新行选中
    handleExchangeAsset(template,event) {
        this.IsLoading = true;
        this.IsRefresh = false;
        this.allDataInfo();
        //2023/09/16 unCheckedAssets 仅保留勾选数据 后台unCheckedAssets 会重新查询赋值
        let oldUnCheckedAssets = JSON.stringify(this.allData.unCheckedAssets);
        let checkedNewUnCheckedAssets = [];
        this.allData.unCheckedAssets.forEach(function(ar) {
            if (ar.rec_checkBox_c) {
                checkedNewUnCheckedAssets.push(ar);
            }
        });
        this.allData.unCheckedAssets = checkedNewUnCheckedAssets;
        exchangeAsset({
            initDataStr:JSON.stringify(this.allData)
        }).then(result => {
            result = JSON.parse(result);
            console.log('handleExchangeAsset result',result);
            if (result != null) {
                this.allData = result;
                //页面相关数据初始化
                this.handleInitSimpleData(result);
                this.allData.checkedAssets = this.refreshAsset(result.checkedAssets.length,result.checkedAssets);
                
                this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
                //param : unCheckedAssetsView
                this.currentPage = 1;
                this.handleunCheckedAssetColumnsAndData(this.allData.unCheckedAssets);
 
            }else{
                // 2023/09/18 返回异常,旧数据返回赋值
                this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
            }
        }).catch(error => {
            console.log(error);
            // 2023/09/18 返回异常,旧数据返回赋值
            this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
        }).finally(() => {
            this.IsLoading = false;
            this.IsShowUnCheckedAsset = false;
            // 两个表格的 全选 勾选 清除
            this.IsCheckAllUncheckedAsset = false;
            this.IsCheckAllcheckedAsset = false;
            this.IsRefresh = true;
        }); 
    }
    //提交待审批
    async handleApprove(event){
        //onclick
        this.IsLoading = true;
        // WYL 贸易合规2期 update start
        let resEGFlgconfim = await this.EGFlgconfim('【贸易合规】--服务报价提交待审批涉及警示产品');
        if (resEGFlgconfim) {
            let resKindsAndMonths = await this.KindsAndMonths();
            await this.approvalJs();
            if(resKindsAndMonths){
                this.allDataInfo();
                console.log('approvalProcess result');
                // 2023/09/18 unCheckedAssets 后台方法未涉及该属性,直接置空
                let oldUnCheckedAssets = JSON.stringify(this.allData.unCheckedAssets);
                this.allData.unCheckedAssets = [];
                await approvalProcess({
                    initDataStr: JSON.stringify(this.allData),
                }).then(result => {
                    console.log('approvalProcess result',result);
                    if (result.indexOf('navigateTo') != -1) {
                        this.navigateToOtherObj(result.split('=')[1]);
                    }else{
                        estimateUtility.toast.showToast(this, 'error', result);
                        // 2023/09/18 返回异常,旧数据返回赋值
                        this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
                    }
                }).catch(error => {
                    // 2023/09/18 返回异常,旧数据返回赋值
                    this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
                }).finally(() => {
                }); 
                //oncomplete
                this.unblockUI();
            }   
        }
         // WYL 贸易合规2期 update end
        this.IsLoading = false;
    }
    async KindsAndMonths() {
       //   故障品加费 系统检查修理减价审批完成 Start
        let ISReduced = this.estimate.IS_Reduced_price_approval__c;
        if( ISReduced == '审批中' || ISReduced == '有八折以下待审批'){
            estimateUtility.toast.showToast(this, 'error', '请通过修理减价审批再提交');
            return false;
        }
        //   故障品加费 系统检查修理减价审批完成 end
        var months      = parseFloat(this.estimate.Contract_Range__c == undefined ? null : this.estimate.Contract_Range__c);
        var contrNew    = this.estimate.New_Contract_Type_TxT__c; 
        if(months>12 && months<60 && contrNew == '新品合同'){
            let confirmResult = await estimateUtility.toast.handleConfirmClick("本次您提交的报价为多年期新品合同,请您在正式提交报价前先将经销商与医院签订的多年期合同邮件发送服务本部报价窗口。若已经提交请点击确定,继续保存提交。");
            return confirmResult;
        }
        // 先款后修-提交报价时如果是先款对象进行提示 thh 20220408 start
        var FirstParagraphEnd = this.estimate.Is_RecognitionModel__c;
        if(FirstParagraphEnd){
            let confirmResult = await estimateUtility.toast.handleConfirmClick("本次签约经销商是先款对象,请确认是否提交报价?");
            return confirmResult;
        }
        // 先款后修-提交报价时如果是先款对象进行提示 thh 20220408 end
        return true;
    }
    approvalJs() {
        this.approvalDate = new Date();
        var rowCnt = this.productCount;
        this.allData.checkedAssets = this.refreshAsset(rowCnt,this.allData.checkedAssets);
        this.handleCheckedAssetColumnsAndData(this.allData.checkedAssets);
    }
    // 过去三年维修实绩计算
    async AlertPriceBtnJs(){
        this.IsLoading = true;
        var  PStatus   = this.estimate.Process_Status__c;
        if(PStatus!='申请中'&& PStatus!='批准'){
            await ComputeLTYRepair({
                targetEstimateId: this.allData.targetEstimateId,
            }).then(result => {
                if (result != null) {
                    estimateUtility.toast.showToast(this, 'error', result);
                }
            }).catch(error => {
            }).finally(() => {
                
            }); 
        }else if(PStatus == '申请中'||PStatus == '批准'){
            await ShowLTYRepair({
                targetEstimateId: this.allData.targetEstimateId,
            }).then(result => {
                result = JSON.parse(result);
                if (result != null) {
                    //allData 赋值
                    this.allData.lastFriYearsPriceSum = result.lastFriYearsPriceSum;
                    this.allData.lastSecYearsPriceSum = result.lastSecYearsPriceSum;
                    this.allData.alertString = result.alertString;
                    this.allData.alertString2 = result.alertString2;
                    this.allData.alertString3 = result.alertString3;
                }
            }).catch(error => {
            }); 
        }
        this.IsLoading = false;
    }
    // 提交修理减价审批
    handleToApprovalProcess(){
        this.IsLoading = true;
        this.allDataInfo();
        // 2023/09/18 unCheckedAssets 后台方法未涉及该属性,直接置空
        let oldUnCheckedAssets = JSON.stringify(this.allData.unCheckedAssets);
        this.allData.unCheckedAssets = [];
        toApprovalProcess({
            initDataStr: JSON.stringify(this.allData),
        }).then(result => {
            if (result != null && result.indexOf('completion=5') != -1) {
                //重新跳转该页面 携带参数
                estimateUtility.toast.showToast(this, 'success', '提交修理减价审批成功');
                window.location.href=window.location.origin+"/lightning/n/lexSelectAssetEstimateVM#id="+result.split('/')[1]; 
                location.reload();
            }else{
                estimateUtility.toast.showToast(this, 'error', result);
                // 2023/09/18 返回异常,旧数据返回赋值
                this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
            }
        }).catch(error => {
            // 2023/09/18 返回异常,旧数据返回赋值
            this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
        }).finally(() => {
            this.IsLoading = false;
        });
    }
    // Decide
    async decideJs() {
        console.log('decideJs');
        if(this.allData.MaintanceContractPackId && this.estimate.McpDecide__c == false) {
            estimateUtility.toast.showToast(this, 'error', '只能对决定报价组合里的报价进行decide!');
            return;
        }
        this.IsLoading = true;
        if (await this.checkDecideDate()) {
            if (await this.onclickCheckchangedAfterPrint('true','false')) {
                var oldDate = this.allData.OldContractStartDate;
                var contractDate = new Date(this.estimate.Contract_Start_Date__c);
                var monthStr = '00' + (contractDate.getMonth()+1);
                monthStr = monthStr.substring(monthStr.length-2, monthStr.length);
                var dayStr = '00' + contractDate.getDate();
                dayStr = dayStr.substring(dayStr.length-2, dayStr.length);
                var contractDateStr = contractDate.getFullYear() + '/' + monthStr + '/' + dayStr;
                //贸易合规 you 20230414 start
                var AccDealerBlacklist = this.contract.AccDealerBlacklist__c;//黑名单,警示名单
                var TradeComplianceStatusFlagFW = this.allData.TradeComplianceStatusFlagFW;//贸易合规开关
                var IFTradeComplianceAlert = this.allData.IFTradeComplianceAlert;//贸易合规提醒
                if(TradeComplianceStatusFlagFW=='true'){
                   if(AccDealerBlacklist =='1'){
                       estimateUtility.toast.showToast(this, 'warning', '您所选择的医院存在贸易合规风险,无法签订服务合同,建议您向客户做好不签约说明,'+IFTradeComplianceAlert);
                       var reflag = this.handleInterceptsend();//后台
                       this.unblockUI();
                       return null;
                    }else if(AccDealerBlacklist =='2'){
                       estimateUtility.toast.showToast(this, 'warning', '您所选择的经销商存在贸易合规风险,无法签订服务合同,建议您向客户做好不签约说明,'+IFTradeComplianceAlert);
                       var reflag = this.handleInterceptsend();
                       this.unblockUI();
                       return null;
                    }else if(AccDealerBlacklist =='12'){
                       estimateUtility.toast.showToast(this, 'warning', '您所选择的医院和经销商存在贸易合规风险,无法签订服务合同,建议您向客户做好不签约说明,'+IFTradeComplianceAlert);
                       var reflag = this.handleInterceptsend();
                       this.unblockUI();
                       return null;
                    }else if(AccDealerBlacklist =='5' || AccDealerBlacklist =='6' || AccDealerBlacklist =='56'){
                        //20231208 sx 贸易合规二期 修改 start 
                        let tradeFlagTwo = false;
                        console.info('Decide=' + JSON.stringify(this.allData.checkedAssets));
                        var violationName='';
                        this.allData.checkedAssets.forEach(function(ass) {
                            if (ass.rec != null && ass.rec.Product2.ProTradeComplianceStatus__c === '0') {
                                tradeFlagTwo = true;
                                violationName+=ass.rec.Product2.Asset_Model_No__c+',';
                            }
                        });
                        if(tradeFlagTwo){
                            this.EmailSending(2,'【贸易合规】--服务报价Decide涉及警示产品',violationName.slice(0, -1));
                            if (!(await estimateUtility.toast.handleConfirmClick('您此次申请的业务可能存在贸易合规风险,请联系法务本部贸易合规窗口恽李娜进一步评估(一般需5-10个工作日)'))) {
                                this.unblockUI();
                                this.IsLoading = false;
                                return null;
                            }
                        }
                        //20231208 sx 贸易合规二期 修改 end
                    }
                }
                //贸易合规 you 20230414 end
                if (oldDate == contractDateStr) {
                    this.allData.changedAfterPrint = false;
                    this.handleDecide();
                } else {
                    var oldp = parseFloat(this.allData.OldMaintenancePrice*1);
                    var newp = parseFloat(this.estimate.Maintenance_Price__c);
                    console.log('oldp',oldp);
                    console.log('newp',newp);
                    if (oldp != newp) {
                        // 20201106 高章伟 提醒消息修改 start
                        this.allData.changedAfterPrint = true;
                        if (await estimateUtility.toast.handleConfirmClick("合同金额发生变化,请您确认。")) {
                            this.handleDecide();
                        } else {
                            estimateUtility.toast.showToast(this, 'warning', '请确认全部内容后点击Decide。');
                            this.estimate.Contract_Start_Date__c = oldDate;
                            this.allData.OldContractStartDate = '';
                            this.allData.changedAfterPrint = false;
                            this.handleDecideCancle();
                        }
                    } else {
                        this.allData.changedAfterPrint = false;
                        this.handleDecide();  
                    }
                    // 20201106 高章伟 提醒消息修改 end
                }
            }else{
                this.IsLoading = false;
 
            }
        }else{
            this.IsLoading = false;
        }
    }
    handleInterceptsend(){
        this.allDataInfo();
        interceptsend({
            estimateStr: JSON.stringify(this.allData.estimate),
            targetEstimateId: this.allData.targetEstimateId,
        }).then(result => {
            return result;
        }).catch(error => {
        }).finally(() => {
            this.IsLoading = false;
        });
    }
    //
    async checkDecideDate() {
        console.log('checkDecideDate');
        // 报价有效期
        var strSubmitDate = this.estimate.Submit_quotation_day__c;
        // 上期合同结束日 取最晚的
        var conEndDate = await this.getLastContractendDate();
        console.log(11);
        conEndDate = new Date(conEndDate);
        // 今天
        var submitDate = new Date();
        var nowDate = new Date();
        nowDate = new Date(nowDate.toLocaleDateString());
        /// 报价中设备的机身编码为空时的新品合同有效期延长 20200710 gzw
        var monthGap = 6;
        var cntWithKara = this.productCount;
        for (var i = 0; i < cntWithKara; i++) {
            var isManual = this.allData.checkedAssets[i].isManual;
            if (isManual != true) {
                monthGap = 3;
                break;
            }
        }
        if (strSubmitDate != '') {
            submitDate = new Date(strSubmitDate);
            submitDate = new Date(submitDate.setMonth(submitDate.getMonth() + monthGap));
            if(Date.parse(conEndDate)  > Date.parse(submitDate)){
                submitDate = new Date(conEndDate);
            }
        }
        if (strSubmitDate != '' && nowDate > submitDate) {
            estimateUtility.toast.showToast(this, 'error','已超出报价申请日'+ monthGap+'个月,不允许DECIDE。');
            return false;
        }
        return true;
    }
    //
    getLastContractendDate(){
        console.log('getLastContractendDate');
        var rowCnt = this.productCount;
        var lastdate = null;
 
        for (var i = 0; i < rowCnt; i++) {
            var LastMContractID = this.allData.checkedAssets[i].rec ? this.allData.checkedAssets[i].rec.CurrentContract_F__c : null;
            if(LastMContractID){
                var endDate = new Date(this.allData.checkedAssets[i].rec.CurrentContract_End_Date__c);
                if(lastdate == null){
                    lastdate = new Date(endDate);
                }else if(Date.parse(endDate) > Date.parse(lastdate)){
                    lastdate = new Date(endDate);
                }
            }
        }
        return lastdate;
    }
    //decide
    handleDecide(){
        this.IsLoading = true;
        this.allDataInfo();
        // 2023/09/16 unCheckedAssets 后台方法重新赋值,直接置空
        let oldUnCheckedAssets = JSON.stringify(this.allData.unCheckedAssets);
        this.allData.unCheckedAssets = [];
        decide({
            initDataStr: JSON.stringify(this.allData),
        }).then(result => {
            if (result != null && result.indexOf('completion=') != -1) {
                //重新跳转该页面 携带参数
                window.location.href=window.location.origin+"/lightning/n/lexSelectAssetEstimateVM#id="+result.split('/')[1]; 
                location.reload();
            }else{
                estimateUtility.toast.showToast(this, 'error', result);
                // 2023/09/18 返回异常,旧数据返回赋值
                this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
            }
        }).catch(error => {
            // 2023/09/18 返回异常,旧数据返回赋值
            this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
        }).finally(() => {
            this.IsLoading = false;
        });
    }
    //decideCancle
    handleDecideCancle(){
        //后台页面跳转原页面  替换成location.reload();
        this.IsLoading = true;
        this.allDataInfo();
        // 2023/09/16 unCheckedAssets 后台方法重新赋值,直接置空,后台处理后,页面重载,不考虑旧值 重新赋值
        this.allData.unCheckedAssets = [];
        decideCancle({
            initDataStr: JSON.stringify(this.allData),
        }).then(result => {
        }).catch(error => {
        }).finally(() => {
            location.reload();
            this.IsLoading = false;
        });
    }
    //取消Decide
    handleUndecide(){
        this.IsLoading = true;
        this.allData.estimate = this.estimate;
        undecide({
            targetEstimateId: this.allData.targetEstimateId,
            estimateStr: JSON.stringify(this.allData.estimate),
        }).then(result => {
            if (result != null && result.indexOf('completion=1') != -1) {
                window.location.href=window.location.origin+"/lightning/n/lexSelectAssetEstimateVM#id="+result.split('/')[1]; 
                location.reload();
            }else{
               estimateUtility.toast.showToast(this, 'error', result);
            }
        }).catch(error => {
        }).finally(() => {
            location.reload();
            this.IsLoading = false;
        });
    }
    //PDF打印按钮
    async handlePrint(){
        this.IsLoading = true;
        // 20231120 hql 添加逻辑:页面锁定后无法点击且提示
        var isdecide = this.estimate.Estimation_Decision__c;;
        if (isdecide == true) {
            estimateUtility.toast.showToast(this, 'error', '请前往文本信息录入页面进行打印');
            this.IsLoading = false;
            return;
        }
        // 20231120 hql 添加逻辑:页面锁定后无法点击且提示
        if (await this.onclickCheckchangedAfterPrint(this.SaveBtnDisabled,'false')) {
            this.allDataInfo();   
            // 2023/09/16 unCheckedAssets 后台方法重新赋值,直接置空
            let oldUnCheckedAssets = JSON.stringify(this.allData.unCheckedAssets);
            this.allData.unCheckedAssets = [];
            print({
                initDataStr: JSON.stringify(this.allData),
            }).then(result => {
                if (result != null && result.indexOf('printAsset') == -1) {
                    estimateUtility.toast.showToast(this, 'error', result);
                    // 2023/09/18 返回异常,旧数据返回赋值
                    this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
                }else if (result != null) {
                    result = JSON.parse(result);
                    this.allData = result;
                    //页面相关数据初始化
                    this.handleInitSimpleData(result);
                }
            }).catch(error => {
                // 2023/09/18 返回异常,旧数据返回赋值
                this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
            }).finally(() => {
                //complete
                this.PDFDataChang();
                this.unblockUI();
                ComputeLTYRepair({
                    targetEstimateId: this.allData.targetEstimateId,
                }).then(result => {
                    if (result != null) {
                        estimateUtility.toast.showToast(this, 'error', result);
                    }
                    this.IsLoading = false;
                }).catch(error => {
                }).finally(() => {
                });  
            }); 
        }else{
            this.IsLoading = false;
        }
    }
    //page 后台js 方法 检测printAsset是否满足
    PDFDataChang(){
        if (this.allData.printAsset) {
            var con = 0;
            if (this.estimate.Print_ListPrice__c) {
                con ++;
            }
            if (this.estimate.Print_Simplify__c) {
                con ++;
            }
            if (this.estimate.Print_RepairPrice__c) {
                con ++;
            }
            if (this.estimate.Print_SumPrice__c) {
                con ++;
            }
            if(con != 1){
                estimateUtility.toast.showToast(this, 'error', '请您勾选打印报价版本,只能勾选一个。');
            }else{
                 window.open('/apex/MaintenanceContractEstimateVMPDF?id='+this.allData.targetEstimateId, 'MaintenanceContractEstimateVMPDF');
            }
        } else if (this.allData.printContract) {
            window.open('/apex/MceConfigPDF?id='+this.allData.targetEstimateId+'&flag=printContract', 'MceConfigPDF');
        } else if (this.allData.printTripartite) {
            window.open('/apex/MceConfigPDF?id='+this.allData.targetEstimateId+'&flag=printTripartite', 'MceConfigPDF');
        } else if (this.allData.printAgent) {
            window.open('/apex/MceConfigPDF?id='+this.allData.targetEstimateId+'&flag=printAgent', 'MceConfigPDF');
        }else {}
    }
    async handleSendEmail(){
        this.IsLoading = true;
        if (await this.EGFlgconfim()) {
            this.allDataInfo();
            // 2023/09/16 unCheckedAssets 后台方法重新赋值,直接置空
            let oldUnCheckedAssets = JSON.stringify(this.allData.unCheckedAssets);
            this.allData.unCheckedAssets = [];
            sendEmail({
                initDataStr: JSON.stringify(this.allData),
            }).then(result => {
                //判断是否返回initData  targetEstimateId
                if (result != null && result.indexOf('currPage') != -1) {
                    result = JSON.parse(result);
                    console.log('handleSendEmail result',result);
                    this.allData = result;
                    //页面相关数据初始化
                    this.handleInitSimpleData(result);
                    if (this.allData.sendEmailSuccess) {
                        estimateUtility.toast.showToast(this, 'success', '邮件发送成功!');
                    }else{
                        estimateUtility.toast.showToast(this, 'error', '邮件发送失败,请联系管理员!');
                        // 2023/09/18 返回异常,旧数据返回赋值
                        this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
                    }
                }else{
                    estimateUtility.toast.showToast(this, 'error', result);
                    // 2023/09/18 返回异常,旧数据返回赋值
                    this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
                }
            }).catch(error => {
                // 2023/09/18 返回异常,旧数据返回赋值
                this.allData.unCheckedAssets = JSON.parse(oldUnCheckedAssets);
            }).finally(() => {
                this.unblockUI();
                this.IsLoading = false; 
            }); 
        }else{
           this.IsLoading = false;  
        }
    }
    /*//计算预测消费率
    consumptionbtnJs(){
        this.IsLoading = true;
        var mceId = this.allData.targetEstimateId;
        console.log('报价=='+mceId);
        // sforce.connection.sessionId = '{!$Api.Session_ID}';
        ToConsumptionRate({
            mceId: mceId,
        }).then(flg => {
            console.log('计算结果=='+flg);
            if (flg == '计算完成') {
                estimateUtility.toast.showToast(this, 'success', flg);
            }else{
                estimateUtility.toast.showToast(this, 'error', flg);
            }
        }).catch(error => {
        }).finally(() => {
            this.IsLoading = false;
        }); 
    }*/
    //estimate contract 同步
    allDataInfo(){
        this.allData.estimate = this.estimate;
        this.allData.contract = this.contract;
    }
    //parseFloat 避免NAN
    localParseFloat(val){
        val = val == undefined ? null : val;
        return parseFloat(val*1);
    }    
    //页面对象跳转
    navigateToOtherObj(recordId){
        // this.IsLoading = true;
        this[NavigationMixin.Navigate]({
            type:'standard__recordPage',
            attributes:{
                recordId:recordId,
                objectApiName:'Account',
                actionName:'view'
            }
        });
    }
   /* openQuoteExcelImport() {
        this.showQuoteExcelImport = true;
    }
 
        // Excel导入态框关闭
    cancelQuoteExcelImport(){
        this.showQuoteExcelImport = false;
        this.exceltextvalue = '';
    }
    //Excel导入保存
    async SavesSQuoteExcelImport(){
 
        
    }
    get acceptedFormats() {
        return ['.csv'];
    }
    handleUploadFinished(event) {
        const file = event.detail.files[0];
        let reader = new FileReader();
        let that=this;
        console.log("ddd");
        console.log(this.allData.uncheckedAssets);
        let addAssetsList=[];
        reader.onload = function (e) {
            var data = e.target.result;
            var allTextLines = data.split(/\r\n|\n/);
 
            readExcel({fileStr:allTextLines}).then(res=>{
                console.log('解析结果');
                console.log(res);
                console.log(that.allData);
                console.log(that.unCheckedAssetData);
                for(let i=0;i<res.length;i++){
                    if(res[i][0]=='SerialNumber'){
                        console.log(that.allData);
                        console.log(that.unCheckedAssetData);
                        console.log(that.allData.uncheckedAssets);
                        for (var j = that.unCheckedAssetData.length - 1; j >= 0; j--) {
                            if(res[i].indexOf(that.unCheckedAssetData[j].SerialNumber)!=-1){
                                // that.unCheckedAssetData[i].rec_checkBox_c=true;
                                if(that.unCheckedAssetData[j].uncheckedDisable==false){
                                    addAssetsList.push(that.unCheckedAssetData[j]);
                                }
                                
                            }
                        }
                        console.log('匹对结果');
                        console.log(addAssetsList);
                        return;
                    }
                }
            })
        }
        reader.readAsText(file, 'gb2312');
    }
 
                
    @track
    exceltextvalue;
    //textArea事件
    exceltextChange(event){
        let value = event.detail.value;
        this.exceltextvalue = value;
    }*/
}