LiJinHuan
2022-03-22 c0515c2f47cafe8da39089d2173e7b41f56e5f3e
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
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
import {
    LightningElement,
    track
} from 'lwc';
//引入后台方法
import GetPromotionDefalut from '@salesforce/apex/QuoteTrialController.GetPromotionDefalut';
import GetPromotionPromotionSearch from '@salesforce/apex/QuoteTrialController.GetPromotionPromotionSearch';
import GetNormalProductSearch from '@salesforce/apex/QuoteTrialController.GetNormalProductSearch';
import GetAuthorizerSearch from '@salesforce/apex/QuoteTrialController.GetAuthorizerSearch';
import GetSearchProductById from '@salesforce/apex/QuoteTrialController.GetSearchProductById';
import saveAllDataProduct from '@salesforce/apex/QuoteTrialController.saveAllDataProduct';
import GetParamToId from '@salesforce/apex/QuoteTrialController.GetParamToId';
import SelectAllDataProduct from '@salesforce/apex/QuoteTrialController.selectAllDataProduct';
import SelectAllDataDiscount from '@salesforce/apex/QuoteTrialController.selectAllDataDiscount';
import GetQuoteData from '@salesforce/apex/QuoteTrialController.GetQuoteData';
import GetAgencyRName from '@salesforce/apex/QuoteTrialController.GetAgencyRName';
import selectUpdateFiexedpriceData from '@salesforce/apex/QuoteTrialController.selectUpdateFiexedpriceData';
import selectUpdateQuoteLineItemData from '@salesforce/apex/QuoteTrialController.selectUpdateQuoteLineItemData';
import ClipboardJS from '@salesforce/resourceUrl/clipboardminjs';
import Please_Save_Quote from '@salesforce/label/c.Please_Save_Quote';
import Check_Your_Clipboard from '@salesforce/label/c.Check_Your_Clipboard';
import {
    arrTempsss,
    arrProductTempsss,
    initDataTableProduct2,
    initDataTable2,
    initSearchForm2,
    initDataTableFix2,
    initSearchFormFix2,
    getQueryVariable,
    ChangeFiexedData,
    GetUUID,
    initDataTableDefault2,
    initSearchFormDefalt2,
    initSearchFormFixedPrice2,
    initDataTableFixedPrice2,
    initSearchFormDiscount2,
    initDataTableDiscount2,
    initSearchFormSpecial2,
    initDataTableSpecial2,
    initSearchFormOtherData2,
    initDataTableOtherData2,
    initSearchFormCommonly2,
    initDataTableCommonly2,
    ConsolidationScheme,
    MergeProducts,
    ProductAssignmentSelect,
    ProductSelected,
    UnselectedScheme,
    SelectedScheme,
    commonlyDiscountLogic,
    PriceConsolidation,
    contributingDiscountLogic,
    ReplacementUnitPriceLogic,
    ConsolidatedDiscountDetailsLogic,
    ConsolidatedDiscountPolicyLogic,
    partPromotionSchemeLogical,
    partGeneralDiscountLogical,
    ComputationalLogic,
    addOfferLogic,
    ReverseCalculationModifyDiscountLogic,
    HeTongPriceComputeLogic,
    InverseCalculationTiShi,
    ContractPriceComputeLogic,
    SpecialPriceComputeReverse,
    GeneralDiscountContractSummaryLogic,
    SpecialSavesChangePartLogic,
    NewDefaultDatass,
    AddProductDatass,
    jzDataFixedPriceTemps,
    jzDataDiscountTemps,
    updatesNumsLogic,
    IfCopyProperties,
    PathJump,
    ContractPriceComputeReverse,
    copyLogic,
    updateCDLogic,
    DeftCopyQtyLists,
    countListAndNodLogic
} from "./quoteTrialUtil.js";
 
export default class Test02 extends LightningElement {
    //全局加载
    IsLoading = false; //加载的标识
    //加载提示框
    OnLoading(flag) {
        this.IsLoading = flag;
    }
    label = {
        Please_Save_Quote,
        Check_Your_Clipboard
    };
    //价格政策表单开关标识符
    jzDataTableFixedPriceIsShow = false;
    //折扣政策表单开关
    jzDataTableDiscountIsShow = false;
    //报价Decied后只读标识符,并控制按钮是否隐藏
    buttonIsShow = false;
    // ===============通用的方法 ====================
    //获取报价试算页面地址栏中的报价Id
    ParamIdStr = '';
    //页面初始化加载数据
    ScreenWidth = ''
    connectedCallback() {
        
        var paramId = getQueryVariable('Id');
        if (paramId == null || paramId == '') {
            return;
        }
        this.ParamIdStr = paramId;
        GetParamToId({
            Param: paramId
        }).then(result => {
            if (result) {
                console.warn("ID OK");
            }
        })
        this.ScreenWidth = "height:" + (window.screen.availHeight - 120) + "px;overflow:scroll;";
        //加载数据
        this.OnLoading(true);
        setTimeout(() => {
            this.ItmeOutFn();
        }, 1000);
        this.OnLoadSavesDatas();
        this.OnLoadQuoteData(this.ParamIdStr);
        var event = {
            page: 1,
            pageLimit: 10,
            search: "",
            sortOrder: "asc",
            sortPlus: undefined,
            fag: true
        };
        setTimeout(() => {
            this.getTableDataFix(event);
            this.getTableData(event);
        }, 1000);
 
 
 
    }
    //检查保存数据是否改变
    ItmeOutFn() {
        this.OnLoading(false);
        if (this.Complate) {
            this.Alert("保存数据发生改变,已加载最新数据!", false, true);
            setTimeout(() => {
                this.CloseAlert();
            }, 2000);
        }
    }
    
    //加载报价数据
    QuoteData = [];
    OnLoadQuoteData(idStr) { //idStr  报价id
        GetQuoteData({
            QuoteID: idStr
        }).then(result => {
            var responseObj = JSON.parse(result);
            this.QuoteData = responseObj;
            if(this.QuoteData[0].Dealer_Final_Price_F__c==undefined||this.QuoteData[0].Dealer_Final_Price_F__c==''){
                this.QuoteData[0].Dealer_Final_Price_F__c=0
            }
            if(this.QuoteData[0].Agent1_Agent2_Price__c==undefined||this.QuoteData[0].Agent1_Agent2_Price__c==''){
                this.QuoteData[0].Agent1_Agent2_Price__c=null;
            }
            debugger
            if (this.QuoteData[0].Quote_Decision__c != "√") {
                this.buttonIsShow = true;
                this.initDataTableFixedPrice.columns[7].editable = true;
                this.initDataTableFixedPrice.columns[10].editable = true;
                this.initDataTableDiscount.columns[2].editable = true;
                this.initDataTableDiscount.columns[3].editable = true;
                this.initDataTableDiscount.columns[4].editable = true;
                this.initDataTableDiscount.columns[5].editable = true;
                this.initDataTableOtherData.columns[3].editable = true;
                this.initDataTableCommonly.columns[3].editable = true;
            }
            this.jzDataTableFixedPriceIsShow = true;
            this.jzDataTableDiscountIsShow = true;
        })
    }
    OnLoadProduct = []; //未选择产品 
    OnLoadSaveProduct = []; //已选择产品
    OnLoadDiscount = []; //折扣政策
    OnLoadFixDiscount = []; //价格政策
    flagall = false;
    //加载保存的数据
 
    OnLoadSavesDatas() {
        //获取产品数据
        SelectAllDataDiscount({
            ParamIdStr: this.ParamIdStr
        }).then(result => {
            result.forEach(item => { //item已选产品查询的结果的一个对象
                if (item.ismatch__c == "0") {
                    //待选产品数据变化字段赋值
                    item = ProductAssignmentSelect(item);
                    this.OnLoadProduct.push(item);
                } else if (item.ismatch__c == "1") {
                    //已选产品数据变化字段赋值
                    item = ProductSelected(item);
                    this.OnLoadSaveProduct.push(item);
                }
            })
            var arrss = [...[], ...this.OnLoadSaveProduct];
            //合并上一次试算的报价行
            this.addOffer(arrss);
            //处理报价数据改动后试算界面的变化
            this.comparisonUniqueKey();
            if (this.OnLoadProduct != undefined && this.OnLoadProduct.length > 0) {
                this.flagall = true;
                this.jzDataDefault = this.OnLoadProduct;
                //更新数据 UpdateBy 2021 06 29
                if (this.jzDataDefault != undefined && this.jzDataDefault.length > 0) {
                    this.UpdateSaveDataQuoteLineItemSelectByID(0);
                }
            }
            if (this.OnLoadSaveProduct != undefined && this.OnLoadSaveProduct.length > 0) {
                this.flagall = true;
                this.jzDataProduct = this.OnLoadSaveProduct;
                //更新数据 UpdateBy 2021 06 29
                if (this.jzDataProduct != undefined && this.jzDataProduct.length > 0) {
                    this.UpdateSaveDataQuoteLineItemSelectByID(1);
                }
                //TODU 这里的逻辑需要重新计算 
                this.updateIdStr("1");
                //合同价格汇总
                this.ContractPriceCompute();
            }
        })
        //获取 折扣方案数据  UpdateBy 2021 06 29
        SelectAllDataProduct({
            ParamIdStr: this.ParamIdStr
        }).then(result => { //已选方案表中查询的数据
            result.forEach(items => {
                if (items.typess__c == "折扣政策") {
                    //折扣方案数据变化字段赋值
                    items = UnselectedScheme(items);
                    this.OnLoadDiscount.push(items);
                } else if (items.typess__c == "价格政策") {
                    //价格方案数据变化字段赋值
                    items = SelectedScheme(items)
                    this.OnLoadFixDiscount.push(items);
                }
            })
            //处理报价数据改动后试算界面的变化
            this.comparisonUniqueKey();
            if (this.OnLoadFixDiscount != undefined && this.OnLoadFixDiscount.length > 0) {
                this.jzDataFixedPrice = this.OnLoadFixDiscount;
                // this.updateIdStr("3");
                //更新数据 UpdateBy 2021 06 29
                if (this.jzDataFixedPrice != undefined && this.jzDataFixedPrice.length > 0) {
                    this.UpdateSaveDataFixedPriceSelectByID();
                }
            }
            if (this.OnLoadDiscount != undefined && this.OnLoadDiscount.length > 0) {
                this.jzDataDiscount = this.OnLoadDiscount;
                this.updateIdStr("2");
            }
        })
    }
    //合并上一次的报价行
    lastQuotation = [];
    addOffer(TrialLine) {
        this.lastQuotation = [...[], ...addOfferLogic(TrialLine)]; //合并上一次的报价行的逻辑
    }
    Complate = false;
    //从数据库更新已保存的数据 方案  UpdateBy 2021 06 29
    UpdateSaveDataFixedPriceSelectByID() {
        var idArr = [];
        this.jzDataFixedPrice.forEach(item => { //价格政策集合
            idArr.push(item.Id);
        })
        selectUpdateFiexedpriceData({
            ProId: idArr
        }).then(result => { //促销方案主数据
            var newArr = [];
            this.jzDataFixedPrice.forEach(dp => { //价格政策集合
                var temp = {
                    ...{},
                    ...dp
                };
                result.forEach(item => {
                    if (item.Id == temp.Id) {
                        var keys = Object.keys(temp);
                        keys.forEach(k => {
                            var flag = ChangeFiexedData(k);
                            if (flag && item[k] != undefined && item[k] != temp[k]) {
                                temp[k] = item[k];
                                this.Complate = true;
                            }
                        })
                    }
                })
                newArr.push(temp);
            })
            this.jzDataFixedPrice = newArr;
            this.updateIdStr("3");
        })
    }
    //产品需要更新的字段
    ChangeProductData(key) {
        var keyArr = [''];
        var flag = false;
        keyArr.forEach(item => {
            if (item == key) {
                flag = true;
            }
        })
        return flag;
    }
    //从数据库更新已保存的数据 产品  UpdateBy 2021 06 29
    UpdateSaveDataQuoteLineItemSelectByID(flag) { //flag 识别数字
        // flag 0 默认产品 flag 1 已选产品 
        if (flag == 0) {
            var idArr = [];
            this.jzDataDefault.forEach(item => { //待选产品
                idArr.push(item.QuiteLineitem__c);
            })
            selectUpdateQuoteLineItemData({
                ItemId: idArr
            }).then(result => { //报价行项目主数据
                var newArr = [];
                this.jzDataDefault.forEach(dp => { //待选产品
                    var temp = {
                        ...{},
                        ...dp
                    };
                    result.forEach(item => {
                        if (item.Id == temp.QuiteLineitem__c) {
                            var keys = Object.keys(temp);
                            keys.forEach(k => {
                                var flag = this.ChangeProductData(k);
                                if (flag && item[k] != undefined && item[k] != temp[k]) {
                                    this.Complate = true;
                                    temp[k] = item[k];
                                }
                            })
                        }
                    })
                    newArr.push(temp);
                })
                this.jzDataDefault = newArr;
            })
        }
        if (flag == 1) {
            var idArrPro = [];
            this.jzDataProduct.forEach(item => { //产品明细
                idArrPro.push(item.QuiteLineitem__c);
            })
            selectUpdateQuoteLineItemData({
                ItemId: idArrPro
            }).then(result => { //报价行项目主数据
                var newArr = [];
                this.jzDataProduct.forEach(dp => { //产品明细
                    var temp = {
                        ...{},
                        ...dp
                    };
                    result.forEach(item => {
                        if (item.Id == temp.QuiteLineitem__c) {
                            var keys = Object.keys(temp);
                            keys.forEach(k => {
                                var flag = this.ChangeProductData(k);
                                if (flag && item[k] != undefined && item[k] != temp[k]) {
                                    this.Complate = true;
                                    temp[k] = item[k];
                                }
                            })
                        }
                    })
                    newArr.push(temp);
                })
                this.jzDataProduct = newArr;
                //解决删除样式不更新问题
                this.updateIdStr("1");
                //合同价格汇总
                this.ContractPriceCompute();
            })
        }
    }
    // ==== 特约与一般折扣添加  价格= jzDataFixedPrice   折扣=jzDataDiscount  已选择的= jzDataProduct
    //折扣政策匹配规则
    SpecialSavesChange(SaveName, SelectedData, IdStr, CompareId) { //SelectedData 选中的数据  IdStr 选中的数据Id CompareId 方案中用到的uuid
        var DefalutQuantity = 0;
        var jzDataDefaultList = this.jzDataDefault//待选产品
        var jzDataDiscountList = this.jzDataDiscount//折扣政策
        var newDicountData = [];
        newDicountData=SpecialSavesChangePartLogic(jzDataDefaultList,SaveName, SelectedData, IdStr, CompareId,DefalutQuantity,newDicountData,jzDataDiscountList);
        this.jzDataDefault = NewDefaultDatass;
        this.jzDataProduct = [...this.jzDataProduct, ...AddProductDatass]; //产品明细
        //合同价格汇总
        this.ContractPriceCompute();
        this.jzDataDiscount = newDicountData;
    }
    //价格政策匹配
    //idStr 选中的数据ID jzDataProductParam  选中的数据对象 TypeName 方案类型  arrData 选中的数据集合
    GetSearchProductByIdFn(idStr, jzDataProductParam, TypeName, jzDataDefaultToTemps, arrData, isShow = true) {
        //dddd
        var SeachData = {
            SearchId: idStr
        };
        GetSearchProductById(SeachData).then(result => {
            var tempObject = {
                ...{},
                ...jzDataProductParam
            }
            jzDataProductParam = this.countListAndNod(tempObject, result);
            arrData = [...[], jzDataProductParam];
            //返回数据比较规则
            this.CompareData(result, idStr, jzDataProductParam, TypeName, jzDataDefaultToTemps, arrData, isShow);
        })
    }
    //计算listPrice的和以及nod和
    //item 选中的对象 result 查出的方案关联的产品
    countListAndNod(item, result) {
        var ifTrade = this.QuoteData[0].Opportunity.Trade__c; //内外贸信息
        var copydate=this.jzDataDefaultCopy;
        var DeftCopyQtyList = this.jzDataDefaultCopyQuantityList;
        //计算list和nod合计逻辑
        item=countListAndNodLogic(ifTrade,copydate,item,result,DeftCopyQtyList);
        this.jzDataDefaultCopyQuantityList=DeftCopyQtyLists;
        var arr = {
            ...{},
            ...item
        };
        return arr;
    }
    //匹配价格政策时数据比较规则
    //list 查出的方案关联的产品  idStr 选中的数据ID  jzDataProductParam  选中的数据对象 TypeName  方案类型  arrData  选中的数据集合  isShow  识别符
    CompareData(list, idStr, jzDataProductParam, TypeName, jzDataDefaultToTemps, arrData, isShow) {
        var isChange = false;
        var TempsJzData = []
        TempsJzData = [...[], ...this.jzDataDefault]; //待选产品
        var TempsJzDataToCompare = []
        TempsJzData.forEach(item => {
            list.forEach(element => { //促销方案主数据关联产品
                if (element.Asset_Model_No__c == item.Product2.MDM_Model_No__c) {
                    if (item.Quantity >= element.Quantity__c) {
                        isChange = true;
                        let CompareTemp = {
                            item: item,
                            element: element
                        }
                        TempsJzDataToCompare.push(CompareTemp);
                    }
                }
            });
        })
        //add 0602
        var CheckMinNum = 0;
        var newTempsJzDataToCompare = []
        TempsJzDataToCompare.forEach(item => { //符合规则的产品
            var intNum = parseInt(item.item.Quantity / item.element.Quantity__c);
            if (CheckMinNum == 0) {
                CheckMinNum = intNum;
            }
            if (intNum < CheckMinNum) {
                CheckMinNum = intNum;
            }
        })
        TempsJzDataToCompare.forEach(item => {
            var newItem = {
                ...{},
                ...item.item
            };
            var newElement = {
                ...{},
                ...item.element
            };
            newItem.Quantity = item.element.Quantity__c * CheckMinNum;
            var newObj = {};
            newObj.item = newItem;
            newObj.element = newElement;
            newTempsJzDataToCompare.push(newObj);
        })
        TempsJzDataToCompare = [...[], ...newTempsJzDataToCompare];
        //End
        if (TempsJzDataToCompare.length == list.length&&list.length!=0) {
            TempsJzDataToCompare.forEach(TempsItems => {
                this.ComparePushData(TempsItems.item.Quantity, TempsItems.element.Quantity__c, TempsItems.element.Asset_Model_No__c, idStr, jzDataProductParam, TypeName);
            });
            //判断是否显示 提示框
            if (isShow) {
                if (this.ifqianpi) {
                    this.Alert("促销方案选择完成", false, true);
                    setTimeout(() => {
                        this.CloseAlert();
                    }, 2000);
                }
            }
        } else {
            if (isShow) {
                if (this.ifqianpi) {
                    this.Alert("促销方案不满足,请重新选择", true, true);
                }
            }
            return;
        }
        if (isChange) {
            this.ChangeNumZeroTrueChanges();
        }
        var temps = this.CompareFullData;
        //添加
        this.UpdateJZData(arrData);
        //更新次数
        this.updatesNums();
        //合并重复价格政策方案
        var jzarr = [...[], ...this.jzDataFixedPrice];
        this.MergeDuplicateSchemes(jzarr);
        //保存最大次数
        this.savecount(idStr);
        //计算价格
        this.ComputeData(idStr, '价格政策');
    }
    //合并重复价格政策方案
    MergeDuplicateSchemes(SchemeSet) {
        var a = this.CompareFullData;
        var CompareFullDataedit = [];
        var Setmap = new Map();
        var arr = [];
        var arr2 = SchemeSet;
        arr2.forEach(arrs => {
            var object = {};
            if (Setmap.has(arrs.Id)) {
                object = {
                    ...{},
                    ...Setmap.get(arrs.Id)
                };
                object.Counts = object.Counts + arrs.Counts;
                object.determine = '';
                a.forEach(editnum => {
                    if (editnum.Id == object.Id) {
                        editnum.num = object.Counts;
                        CompareFullDataedit.push(editnum);
                    } else {
                        CompareFullDataedit.push(editnum);
                    }
                });
                this.CompareFullData = [...[], ...CompareFullDataedit];
                Setmap.set(arrs.Id, object);
            } else {
                object = {
                    ...{},
                    ...arrs
                };
                Setmap.set(arrs.Id, object);
            }
        });
        for (let [k, v] of Setmap) {
            arr.push(v);
        }
        this.jzDataFixedPrice = [...[], ...arr]
        this.ConsolidationProgramProducts(arr);
    }
    //归并相同价格政策方案的产品
    ConsolidationProgramProducts(arrSchemes) {
        var jzdataList = [...[], ...this.jzDataProduct];
        this.jzDataProduct = PriceConsolidation(arrSchemes, jzdataList);
    }
    //保存最大次数
    savecount(idStr) { //idStr 选中的数据ID
        var arr = []
        this.jzDataFixedPrice.forEach(item => { //价格政策
            if (idStr == item.Id) {
                item.maxCounts = item.Counts
                arr.push(item);
            } else {
                arr.push(item);
            }
        });
        this.jzDataFixedPrice = arr;
    }
    //替换listprice单价
    ReplacementUnitPrice() {
        var ifTrade = this.QuoteData[0].Opportunity.Trade__c; //内外贸
        var arr = [...[], ...this.jzDataProduct];
        this.jzDataProduct = [...[], ...ReplacementUnitPriceLogic(arr, ifTrade)]; //替换listprice单价逻辑
        //合同价格汇总
        this.ContractPriceCompute();
    }
    //计算价格政策价格
    ComputeData(id, category) { //id 选中的数据ID  category 方案类型
        //调用替换listprice单价
        this.ReplacementUnitPrice();
        //数据 
        this.updateIdStr("3");
        var arrTemp = this.jzDataFixedPrice; // id   价格政策
        this.updateIdStr("1");
        var arrProductTemp = this.jzDataProduct; // PromotionId   产品明细
        // this.updateIdStr("2");
        // var arrTemp1 = this.jzDataDiscount; //折扣政策
        var arrTemp2 = this.jzDataDefault; //待选产品
        if (category == '价格政策') {
            arrTemp.forEach(item => { // item价格政策
                if (id == item.Id) {
                    item.Total = item.Counts * item.Price_CNY__c;
                    item.sumNoDiscountTotal = item.sumNoDiscount * item.Counts;
                    //计算促销总价&& item.HeTongTotal == undefined
                    if (item.Price_CNY__c != undefined) {
                        if (item.determine != '改过') {
                            if (item.if_Contain_Nod__c) {
                                item.HeTongTotal = item.Total;
                            } else {
                                item.HeTongTotal = item.Total + item.sumNoDiscountTotal;
                            }
                        }
                    }
                    //计算选择促销政策的经销商单价和小计
                    var PromotionHeadRecordId = item.recordTypeName__c;
                    if (PromotionHeadRecordId == "Promotion") { //促销方案
                        this.newArrsTemp3 = []; //需要计算的产品明细的数据
                        this.newArrsTemp4 = []; //不需要计算的产品明细的数据
                        var newArrsTemp5 = [];
                        var newArrsTemp6 = [];
                        arrProductTemp.forEach(itemsss => { //itemsss产品明细
 
                            if (itemsss.PromotionId == item.Id) {
                                if (item.determine == '改过') {
                                    var flag = true;
                                    var b = this.jzDataDefaultCopyQuantityList; //获取方案中的产品数量
                                    arrTemp2.forEach(datedefault => { //datedefault待选产品
 
                                        var quantity = 0;
                                        if (datedefault.Id == itemsss.Id) {
                                            b.forEach(iem => { //iem方案中的产品数量
                                                if (iem.Asset_Model_No__c == datedefault.Product2.MDM_Model_No__c && iem.Id_H == item.PromotionNo__c) {
                                                    quantity = (itemsss.Quantity - iem.Quantity__c__c * item.Counts) + datedefault.Quantity;
                                                    datedefault.Quantity = quantity;
                                                    itemsss.Quantity = iem.Quantity__c__c * item.Counts;
                                                }
                                            });
                                            flag = false;
                                        }
                                    });
                                    if (flag) {
                                        this.jzDataDefaultCopy.forEach(add => { //add报价行项目主数据
                                            var quantity = 0;
                                            if (add.Id == itemsss.Id) {
                                                b.forEach(iems => { //iems方案关联产品数量
                                                    if (iems.Asset_Model_No__c == add.Product2.MDM_Model_No__c && iems.Id_H == item.PromotionNo__c) {
                                                        quantity = itemsss.Quantity - iems.Quantity__c__c * item.Counts;
                                                        add.Quantity = quantity;
                                                        itemsss.Quantity = iems.Quantity__c__c * item.Counts;
                                                        arrTemp2.push(add);
                                                    }
                                                });
                                                flag = true;
                                            }
                                        });
                                    }
                                }
                                itemsss = partPromotionSchemeLogical(itemsss, item,this.QuoteData[0].multiYearWarranty__c);
                                this.newArrsTemp3.push(itemsss);
                            } else if (itemsss.PromotionId != item.Id) {
                                this.newArrsTemp4.push(itemsss);
                            }
                        });
                        if (item.determine == '改过') {
                            arrTemp2.forEach(itsss => { //itsss待选产品
                                if (itsss.Quantity != 0) {
                                    newArrsTemp6.push(itsss);
                                }
                            });
                            newArrsTemp5 = [...[], ...newArrsTemp6];
                            this.jzDataDefault = newArrsTemp5;
                        }
                        this.jzDataProduct = arrProductTemp;
                        //合同价格汇总
                        this.ContractPriceCompute();
 
                    } else if (PromotionHeadRecordId == "NormalProduct") { //一般产品
                        //todu3
                        this.newArrsTemp3 = []; //需要计算的产品明细的数据
                        this.newArrsTemp4 = []; //不需要计算的产品明细的数据
                        var newArrsTemp5 = [];
                        var newArrsTemp6 = [];
                        arrProductTemp.forEach(itemsss => { //itemsss产品明细
                            var flag = true;
                            if (itemsss.PromotionId == item.Id) {
                                if (item.determine == '改过') {
                                    var b = this.jzDataDefaultCopyQuantityList; //获取方案中的产品数量
                                    var jzDataDefaultCopy = this.jzDataDefaultCopy;
                                    arrTemp2.forEach(datedefault => { //datedefault待选产品
                                        var quantity = 0;
                                        if (datedefault.Id == itemsss.Id) {
                                            b.forEach(iem => { //iem方案中的产品数量
                                                if (iem.Asset_Model_No__c == datedefault.Product2.MDM_Model_No__c && iem.Id_H == item.PromotionNo__c) {
                                                    quantity = (itemsss.Quantity - iem.Quantity__c__c * item.Counts) + datedefault.Quantity;
                                                    datedefault.Quantity = quantity;
                                                    itemsss.Quantity = iem.Quantity__c__c * item.Counts;
                                                }
                                            });
                                            flag = false;
                                        }
                                    });
                                    if (flag) {
                                        jzDataDefaultCopy.forEach(add => { //add报价行项目主数据
                                            var quantity = 0;
                                            if (add.Id == itemsss.Id) {
                                                b.forEach(iems => { //iems方案关联产品数量
                                                    if (iems.Asset_Model_No__c == add.Product2.MDM_Model_No__c && iems.Id_H == item.PromotionNo__c) {
                                                        quantity = itemsss.Quantity - iems.Quantity__c__c * item.Counts;
                                                        add.Quantity = quantity;
                                                        itemsss.Quantity = iems.Quantity__c__c * item.Counts;
                                                        arrTemp2.push(add);
                                                    }
                                                });
                                            }
                                        });
                                    }
                                }
                                if(this.QuoteData[0].multiYearWarranty__c){
                                    itemsss.AgencyUnitPrice__c = (item.HeTongTotal / item.Counts) * (itemsss.ListPrice / item.sumListPrice);
                                }else{
                                    itemsss.AgencyUnitPrice__c = ((item.HeTongTotal / item.Counts) - item.sumNoDiscount) * (itemsss.ListPrice / item.sumListPrice) + itemsss.ServicePrice__c;
                                }
                                if (item.HeTongTotal == undefined || item.HeTongTotal == "") {
                                    itemsss.AgencyUnitPrice__c = 0;
                                }
                                itemsss = partGeneralDiscountLogical(itemsss, item);
                                this.newArrsTemp3.push(itemsss);
                            } else if (itemsss.PromotionId != item.Id) {
                                this.newArrsTemp4.push(itemsss);
                            }
                        });
                        if (item.determine == '改过') {
                            arrTemp2.forEach(itsss => { //待选产品
                                if (itsss.Quantity != 0) {
                                    newArrsTemp6.push(itsss);
                                }
                            });
                            newArrsTemp5 = [...[], ...newArrsTemp6];
                            this.jzDataDefault = newArrsTemp5;
                        }
                        this.jzDataProduct = arrProductTemp;
                        //合同价格汇总
                        this.ContractPriceCompute();
                    }
                }
            });
            this.jzDataFixedPrice = [...[], ...arrTemp];
        }
 
    }
    //计算折扣政策
    ComputeDiscount(id, NormalDiscount__c_Input, GuaranteeDiscount__c_Input, Category__c, JxsType) {
        //todu2
        //数据 
        // this.updateIdStr("3");
        // var arrTemp = this.jzDataFixedPrice; // id   价格政策
        this.updateIdStr("1");
        var arrProductTemp = this.jzDataProduct; // PromotionId   产品明细
        this.updateIdStr("2");
        var arrTemp1 = this.jzDataDiscount; //折扣政策
        // var arrTemp2 = this.jzDataDefault; //待选产品
        arrTemp1.forEach(item => { //item折扣政策
            if (JxsType == '特约折扣') {
                if (item.JxsType == '特约折扣') {
                    if (id == item.Id) {
                        if (item.iftrue != "改过" &&
                            item.GuaranteeDiscount__c_Input == undefined &&
                            item.NormalDiscount__c_Input == undefined) {
                            item.GuaranteeDiscount__c_Input = item.GuaranteeDiscount__c;
                            item.NormalDiscount__c_Input = item.NormalDiscount__c;
                        }
                        if (NormalDiscount__c_Input == item.NormalDiscount__c_Input && //非对象品折扣录入
                            GuaranteeDiscount__c_Input == item.GuaranteeDiscount__c_Input) { //对象品折扣录入
                            this.newArrsTemp = [];
                            this.newArrsTemp2 = [];
                            arrProductTemp.forEach(itemss => { //itemss产品明细
                                var Discount__c_Input = 0;
                                if (itemss.warrantyType__c=="市场多年保修") {
                                    Discount__c_Input = item.GuaranteeDiscount__c_Input;
                                    Discount__c_Input = parseFloat(Discount__c_Input);
                                    debugger
                                    // item.GuaranteeDiscount__c_Input = (Discount__c_Input*100).toFixed(0)+"%";
                                } else {
                                    Discount__c_Input = item.NormalDiscount__c_Input;
                                    Discount__c_Input = parseFloat(Discount__c_Input);
                                    // item.NormalDiscount__c_Input = (Discount__c_Input*100).toFixed(0)+"%";
                                }
                                if (itemss.PromotionId == item.Id && //方案Id
                                    itemss.GuaranteeDiscount__c_Input == item.GuaranteeDiscount__c_Input && //对象品折扣录入
                                    itemss.NormalDiscount__c_Input == item.NormalDiscount__c_Input) { //非对象品折扣录入
                                    itemss = contributingDiscountLogic(itemss, Discount__c_Input, item); //特约折扣计算逻辑
                                    this.newArrsTemp.push(itemss);
                                } else if (itemss.PromotionId != item.Id ||
                                    itemss.GuaranteeDiscount__c_Input != item.GuaranteeDiscount__c_Input ||
                                    itemss.NormalDiscount__c_Input != item.NormalDiscount__c_Input) {
                                    this.newArrsTemp2.push(itemss);
                                }
                            });
                            this.jzDataProduct = arrProductTemp;
                            //合同价格汇总
                            this.ContractPriceCompute();
                        }
                    }
                }
            } else if (JxsType == '一般折扣') {
                if (item.JxsType == '一般折扣') {
                    if (NormalDiscount__c_Input == item.NormalDiscount__c_Input &&
                        Category__c == item.Category__c) {
                        this.newArrsTemp = [];
                        this.newArrsTemp2 = [];
                        arrProductTemp.forEach(itemss => { //itemss产品明细
                            if (itemss.NormalDiscount__c_Input == item.NormalDiscount__c_Input &&
                                itemss.Category__c == item.Category__c) {
                                itemss = commonlyDiscountLogic(itemss, item); //一般折扣计算逻辑
                                this.newArrsTemp.push(itemss);
                            } else if (itemss.Category__c != item.Category__c ||
                                itemss.NormalDiscount__c_Input != item.NormalDiscount__c_Input) {
                                this.newArrsTemp2.push(itemss);
                            }
                        });
                        this.jzDataProduct = arrProductTemp;
                        //合同价格汇总
                        this.ContractPriceCompute();
                    }
                }
            }
        });
        this.jzDataDiscount = [...[], ...arrTemp1];
    }
    //一般折扣更改过合同价格计算
    updateCommonlyDiscountLogic(Id,JxsType,GuaranteeDiscount__c_Input,NormalDiscount__c_Input,Category__c,jzDataDiscount) {
        //todu13
        this.updateIdStr("1");
        var arrProductTemp = this.jzDataProduct; // PromotionId   产品明细
        this.jzDataProduct=updateCDLogic(Id,JxsType,GuaranteeDiscount__c_Input,NormalDiscount__c_Input,Category__c,jzDataDiscount,arrProductTemp);
        this.GeneralDiscountContractSummary();
    } 
    //计算一般折扣非对象品折扣
    ComouteProductDiscount(Id,Category__c,GuaranteeDiscount__c_Input, NormalDiscount__c_Input,GuaranteeDiscount_H_Money__c, NormalDiscount_H_Money__c, item) {
        //todu12
        this.updateIdStr("2");
        var arrTemp1 = this.jzDataDiscount; //折扣政策
        this.updateIdStr("1");
        var arrProductTemp = this.jzDataProduct; // PromotionId   产品明细
    
        var reslut=ReverseCalculationModifyDiscountLogic(arrTemp1,arrProductTemp,Id,Category__c,GuaranteeDiscount__c_Input, NormalDiscount__c_Input,GuaranteeDiscount_H_Money__c, NormalDiscount_H_Money__c, item);
        this.jzDataDiscount=[...[], ...arrTempsss];
        this.jzDataProduct =[...[], ...arrProductTempsss];
        return reslut;
    }
    //todu
    //删除价格的listprice和
    ComputeListPrice(PromotionId) { //PromotionId 方案id
        var sum = 0;
        this.jzDataProduct.forEach(jzdp => { //jzdp产品明细
            if (jzdp.PromotionId == PromotionId) {
                sum = sum + jzdp.ListPrice * jzdp.Quantity;
            }
        });
        return sum;
    }
    //删除价格计算
    delectComputeData(item) { //item 产品明细的一条数据
        var sum = this.ComputeListPrice(item.PromotionId);
        var jzProductarry = [...[], ...this.jzDataProduct];
        jzProductarry.forEach(japdt => { //japdt产品明细
            if (item.PromotionId == japdt.PromotionId) {
                japdt.AgencySubtotal__c = japdt.AgencySubtotal__c + item.AgencySubtotal__c * (japdt.ListPrice * japdt.Quantity / sum);
                japdt.AgencyUnitPrice__c = japdt.AgencySubtotal__c / japdt.Quantity;
                japdt.AgencySubtotal__c = Math.round(japdt.AgencySubtotal__c * 100) / 100;
                japdt.AgencyUnitPrice__c = Math.round(japdt.AgencyUnitPrice__c * 100) / 100;
            }
        });
        this.jzDataProduct = [...[], ...jzProductarry];
        //合同价格汇总
        this.ContractPriceCompute();
    }
    //length 数量  Quantity 数量  Asset_Model_No__c 产品型号  Id 选中的数据ID  jzDataProductParam 选中的数据对象 TypeName 方案类型
    ComparePushData(length, Quantity, Asset_Model_No__c, Id, jzDataProductParam, TypeName) {
        //修改 产品明细
        let num = parseInt(length / Quantity);
        let addArr = [];
        var newss = [...[], ...this.jzDataDefault];
        var newDataDefault = newss.map(item => {
            if (item == undefined) {
                console.warn("undefined!!");
            }
            if (item.Product2.MDM_Model_No__c == Asset_Model_No__c) {
                let ItemTemp = {
                    ...{},
                    ...item
                };
                ItemTemp.Quantity = Quantity * num
                ItemTemp.PromotionNo__c = jzDataProductParam.PromotionNo__c;
                ItemTemp.Name = jzDataProductParam.Name;
                ItemTemp.TypeName = TypeName;
                ItemTemp.PromotionId = Id;
                addArr.push(ItemTemp);
                item.Quantity -= num * Quantity;
            }
            return item;
        })
        this.jzDataProduct = [...this.jzDataProduct, ...addArr];
        //合同价格汇总
        this.ContractPriceCompute();
        this.jzDataDefault = newDataDefault;
        //判断是否有 full的值
        this.ChangeNumZeroTrue();
        //追加次数
        this.AddNums(TypeName, Asset_Model_No__c, num, Id);
    }
    // ======================== 追加次数
    //用于填充次数 
    CompareFullData = []
    //ListName  方案类型  Asset_Model_No__c 产品型号   Id  选中的数据ID
    AddNums(ListName, Asset_Model_No__c, addNums, Id) {
        //TODO 用find
        var FilterList = this.CompareFullData.filter(item => {
            if (item.ListName == ListName && item.Id == Id) {
                return true;
            } else {
                return false;
            }
        })
        if (FilterList == undefined || FilterList.length <= 0) {
            var newTemp = {
                ListName: ListName,
                Asset_Model_No__c: Asset_Model_No__c,
                Id: Id,
                num: addNums
            }
            this.CompareFullData.push(newTemp);
        } else {
            FilterList[0].Asset_Model_No__c += Asset_Model_No__c + "||";
            FilterList[0].num = addNums;
        }
    }
    // =======更新促销方案次数数据
    updatesNums() {
        var jzDataFixedPriceTemp = [...[], ...this.jzDataFixedPrice];
        var jzDataDiscountTemp = [...[], ...this.jzDataDiscount];
        var CompareFullData = this.CompareFullData;
        updatesNumsLogic(jzDataFixedPriceTemp,jzDataDiscountTemp,CompareFullData);
        this.jzDataFixedPrice = jzDataFixedPriceTemps;
        this.jzDataDiscount = jzDataDiscountTemps;
    }
    // ====================== 判断是否为0 
    ChangeNumZeroTrueData = []
    ChangeNumZeroTrue() {
        this.ChangeNumZeroTrueData = [...[], ...this.jzDataDefault];
        var newJzDataDefault = this.ChangeNumZeroTrueData.filter(item => {
            if (item.Quantity > 0) {
                return true;
            } else {
                return false;
            }
        })
        this.ChangeNumZeroTrueData = newJzDataDefault;
    }
    ChangeNumZeroTrueChanges() {
        if (this.jzDataDefault.length != this.ChangeNumZeroTrueData) {
            this.jzDataDefault = this.ChangeNumZeroTrueData;
        }
    }
    // --- 删除匹配规则 jzDataProduct jzDataDefaultNotChange(初始产品列表) jzDataDefault(当前产品列表) CompareFullData(保存的次数) 
    DeleteChangesFn(ids, TypeName) { //  ids  选中的方案Id TypeName 方案类型
        var CompareFullDataTemp = [];
        ids.forEach(id => {
            //删除 规则数量
            this.CompareFullData.forEach(cItem => {
                if (cItem.Id == id && cItem.ListName == TypeName) {
                    console.warn("CompareFullData 删除");
                } else {
                    CompareFullDataTemp.push(cItem);
                }
            })
            //删除 已选产品
            var CurrentTemp = {};
            if (TypeName == "价格政策") {
                CurrentTemp = this.jzDataFixedPrice.filter(fItem => {
                    if (fItem.Id == id) {
                        return true;
                    }
                    return false;
                })[0];
            }
            if (TypeName == "折扣政策") {
                CurrentTemp = this.jzDataDiscount.filter(fItem => {
                    if (fItem.Id == id) {
                        return true;
                    }
                    return false;
                })[0];
            }
            //匹配需要删除产品
            var ProductNumsTemp = [];
            var NewjzDataProduct = [];;
            if (TypeName == "价格政策") {
                this.jzDataProduct.forEach(proItem => {
                    if (proItem.PromotionNo__c == CurrentTemp.PromotionNo__c) {
                        ProductNumsTemp.push({
                            Id: proItem.Id,
                            num: proItem.Quantity
                        })
                    } else {
                        NewjzDataProduct.push(proItem);
                    }
                });
            } else if (TypeName == "折扣政策") {
                this.jzDataProduct.forEach(proItem => {
                    if (proItem.CompareId == CurrentTemp.CompareId) {
                        ProductNumsTemp.push({
                            Id: proItem.Id,
                            num: proItem.Quantity
                        })
                    } else {
                        NewjzDataProduct.push(proItem);
                    }
                });
            }
            // 执行删除
            this.jzDataProduct = NewjzDataProduct;
            //合同价格汇总
            this.ContractPriceCompute();
            // 添加数量
            var newjzDataDefaults = [];
            var AddnumsTemp = [];
            this.jzDataDefault.forEach(defItem => {
                var defItemTemp = {
                    ...{},
                    ...defItem
                };
                ProductNumsTemp.forEach(pTempItem => {
                    if (pTempItem.Id == defItem.Id) {
                        defItemTemp.Quantity += pTempItem.num;
                        AddnumsTemp.push(pTempItem.Id);
                    }
                });
                newjzDataDefaults.push(defItemTemp);
            })
            this.jzDataDefault = newjzDataDefaults;
            //添加整条数据
            var PFTempArr = ProductNumsTemp.filter(pTempItem => {
                var flag = true;
                AddnumsTemp.filter(addItem => {
                    if (addItem == pTempItem.Id) {
                        flag = false;
                    }
                })
                return flag;
            })
            this.jzDataDefaultNotChange.forEach(noChangeItem => {
                PFTempArr.forEach(pftItem => {
                    if (pftItem.Id == noChangeItem.Id) {
                        let newChangeItem = {
                            ...{},
                            ...noChangeItem
                        };
                        newChangeItem.Quantity = pftItem.num;
                        this.jzDataDefault.push(newChangeItem);
                    }
                })
            })
        });
        this.CompareFullData = CompareFullDataTemp;
    }
    //todu6
    //================删除已选产品==========
    DeleteIsChangesFnSingle(list) { //list选中的产品明细
       let num = 0;
        list.forEach(item => {
            num++;
            var falg = true;
            if (item.TypeName == "价格政策") {
                this.DeleteIsChangelogic(item, item.TypeName, num, list);
                var arrTemp = [...[], ...this.jzDataFixedPrice]; //价格政策
                var TempItem = {};
                arrTemp.forEach(atItem => {
                    if (atItem.Id == item.PromotionId) {
                        TempItem = atItem;
                        return;
                    }
                })
                this.jzDataProduct.forEach(ite => { //ite产品明细
                    if (ite.PromotionId == TempItem.Id) {
                        falg = false;
                    }
                });
                if (TempItem != undefined && falg) {
                    this.SelectedFnDataFixedPrice.push(TempItem);
                    this.deleteFixedPriceTemp();
                }
            } else if (item.TypeName == "折扣政策") {
                this.DeleteIsChangelogic(item, item.TypeName, num, list);
                var arrTempTOName = [...[], ...this.jzDataDiscount]; //折扣政策
                var TempItemTOName = {};
                var PromotionHeadRecordId = item.recordTypeName__c;
                if (PromotionHeadRecordId == "Authorizer") {
                    arrTempTOName.forEach(atItem => {
 
                        if (atItem.Id == item.PromotionId && //方案Id
                            item.NormalDiscount__c_Input == atItem.NormalDiscount__c_Input && //非对象品折扣录入
                            item.GuaranteeDiscount__c_Input == atItem.GuaranteeDiscount__c_Input) { //对象品折扣录入
                            TempItemTOName = atItem;
                            return;
                        }
                    })
                    this.jzDataProduct.forEach(ite => {
                        if (ite.PromotionId == TempItemTOName.Id &&
                            ite.NormalDiscount__c_Input == TempItemTOName.NormalDiscount__c_Input &&
                            ite.GuaranteeDiscount__c_Input == TempItemTOName.GuaranteeDiscount__c_Input) {
                            falg = false;
                        }
                    });
                } else {
                    arrTempTOName.forEach(atItem => {
                        if (item.Category__c == atItem.Category__c &&
                            item.Discount__c_Input == atItem.NormalDiscount__c_Input) {
                            TempItemTOName = atItem;
                            return;
                        }
                    })
                    this.jzDataProduct.forEach(ite => {
                        if (ite.Category__c == TempItemTOName.Category__c &&
                            ite.Discount__c_Input == TempItemTOName.NormalDiscount__c_Input) {
                            falg = false;
                        }
                    });
                }
                if (TempItemTOName != undefined && falg) {
                    this.SelectedFnDataDiscount.push(TempItemTOName);
                    this.delectTableDiscountTemp();
                }
            }
            this.ContractPriceCompute();
        })
    }
    //删除产品明细和待选产品  item是选中的产品明细对象  TypeName是选中的产品明细对对应的方案类型
    DeleteIsChangelogic(item, TypeName, num, list) { //item  选中的数据对象 TypeName  方案类型
        var jzdatas = [];
        var flg = true;
        this.jzDataProduct.forEach(proItem => { //proItem产品明细
            if (TypeName == "价格政策") {
                var PromotionHeadRecordId = item.recordTypeName__c;
                if (PromotionHeadRecordId == "Promotion") {
                    if (!item.if_Fix__c) {
                        if (proItem.Id == item.Id && item.PromotionId == proItem.PromotionId) {} else {
                            jzdatas.push(proItem);
                        }
                    } else {
                        flg = false;
                        this.Alert("促销方案内产品型号,数量固定,不可删除明细", true, true);
                    }
                } else if (PromotionHeadRecordId == "NormalProduct") {
                    flg = false;
                    this.Alert("该产品为一般产品,不可删除明细", true, true);
                } else {
                    jzdatas.push(proItem);
                }
            } else if (TypeName == "折扣政策") {
                var PromotionHeadRecordId = item.recordTypeName__c;
                if (PromotionHeadRecordId == "Authorizer") {
                    if (proItem.Id == item.Id &&
                        item.PromotionId == proItem.PromotionId &&
                        item.NormalDiscount__c_Input == proItem.NormalDiscount__c_Input &&
                        item.GuaranteeDiscount__c_Input == proItem.GuaranteeDiscount__c_Input) {} else {
                        jzdatas.push(proItem);
                    }
                } else {
                    if (proItem.Id == item.Id &&
                        item.Category__c == proItem.Category__c &&
                        item.Discount__c_Input == proItem.Discount__c_Input) {} else {
                        jzdatas.push(proItem);
                    }
                }
 
            }
        });
        if (flg) {
            this.jzDataProduct = [...[], ...jzdatas];
            if (TypeName == "价格政策") {
                //删除价格计算
                this.delectComputeData(item);
            }
            //合同价格汇总
            this.ContractPriceCompute();
            var fg = true;
            var arr = this.jzDataDefault;
            arr.forEach(jddf => { //jddf待选产品
                if (jddf.Id == item.Id) {
                    jddf.Quantity = jddf.Quantity + item.Quantity
                    fg = false;
                }
            });
            if (fg) {
                this.jzDataDefaultCopy.forEach(itm => { //itm报价行项目主数据
                    if (itm.Id == item.Id) {
                        itm.Quantity = item.Quantity
                        arr.push(itm);
                        fg = false;
                    }
                });
            }
            this.jzDataDefault = [...[], ...arr];
        }
    }
    // ==================通知显示 ======================
    @track Tongzhishow = false;
    @track ErrorTongzhishow = false;
    ShowErrorContent = '折扣类只能选择一个';
    // 新提示
    Tongzhishow = false; //提示显示的标识
    SaveShowText = "操作成功"; //提示框的文本
    TongzhiIcon = 'standard:account' //提示框的图标
    IsLeftStyle = "" //提示框的样式
    BgColorStyle = ""
    //弹框提示 content 内容 error 是否是错误提示框  left 是否居左
    Alert(content, error = false, left = false) {
        this.SaveShowText = content;
        this.Tongzhishow = true;
        if (error) {
            this.TongzhiIcon = "standard:account";
            this.BgColorStyle = "background-color:#f88568";
        } else {
            this.TongzhiIcon = "standard:account";
            this.BgColorStyle = "background-color:#69e669";
        }
        if (left) {
            this.IsLeftStyle = "left: 40%"
        } else {
            this.IsLeftStyle = ""
        }
    }
    //关闭提示框
    CloseAlert() {
        if (this.Tongzhishow == true) {
            this.Tongzhishow = false;
        }
        if (this.SaveShowText != "") {
            this.SaveShowText = "";
        }
    }
    // END 
 
    //  ===================== 弹出框组件 =====================================
    @track
    show = false
    showModal() {
        this.show = true
    }
    cancel() {
        this.show = false
    }
    @track
    pagingShow;
    constructor() {
        super();
        this.pagingShow = false;
    }
    @track
    initSearchForm = initSearchForm2
    @track
    initDataTable = initDataTable2;
    @track jzData = [];
    @track tableIsLoding = true;
    // 点击搜索触发
    searchData(event) {
        let searchParams = event.detail.searchParams || {};
        let temp = this.template;
        this.template.querySelector('[data-parent-id="parent-div-id"]').refreshDataTable({
            searchParams: searchParams
        });
    }
    //页面切换触发
    pagingClick(event) {
        let page = event.detail.page || {};
        this.template.querySelector('c-jz-data-table').refreshDataTable({
            page: page
        });
    }
    // 后台交互,获取列表数据
    getTableData(event) {
        let listQuery = event;
        if (event.fag == undefined) {
            listQuery = event.detail.listQuery;
        }
        GetPromotionPromotionSearch(listQuery).then(result => { //促销方案查询结果
            //CCCC
            var responseObj = JSON.parse(result);
            responseObj.records.forEach(item => {
                var SeachData = {
                    SearchId: item.Id
                };
                GetSearchProductById(SeachData).then(result => { //方案关联的产品
                    // var sumListPrice = 0;
                    // var sumNoDiscount = 0;
                    result.forEach(itemss => { //itemss方案关联的产品
                        var fl = true;
                        if (this.jzDataDefaultCopyQuantityList.length == 0) {
                            this.jzDataDefaultCopyQuantityList.push({
                                Asset_Model_No__c: itemss.Asset_Model_No__c,
                                Quantity__c__c: itemss.Quantity__c,
                                Id_H: item.PromotionNo__c
                            });
                        } else {
                            this.jzDataDefaultCopyQuantityList.forEach(jdcql => { //保存方案关联产品的数量
                                if (itemss.Asset_Model_No__c == jdcql.Asset_Model_No__c && jdcql.Id_H == item.PromotionNo__c) {
                                    fl = false;
                                }
                            });
                            if (fl) {
                                this.jzDataDefaultCopyQuantityList.push({
                                    Asset_Model_No__c: itemss.Asset_Model_No__c,
                                    Quantity__c__c: itemss.Quantity__c,
                                    Id_H: item.PromotionNo__c
                                });
                            }
                        }
                    });
                    var iflag = true;
                    var newarrjdf = [];
                    this.jzDataFixedPrice.forEach(jdf => { //jdf价格政策
                        if (jdf.Id == item.Id) {
                            iflag = false;
                            newarrjdf.push(jdf);
                        } else {
                            newarrjdf.push(jdf);
                        }
                    });
                    this.jzDataFixedPrice = [...[], ...newarrjdf];
                });
            });
            this.jzData = [...[], ...responseObj.records];
            // this.index=this.jzData.length;
            this.tableIsLoding = false;
        })
    }
    // 促销方案选中 
    SelectedFn(event) {
        let arr = event.detail.rows;
        if (arr.length > 1) {
            this.Alert("价格政策只可选择一个方案", true, true);
        } else {
            this.cancel();
            this.ifqianpi = true;
            this.GetSearchProductByIdFn(arr[0].Id, arr[0], "价格政策", [], arr);
        }
    }
    // ================== END 弹出框 ==============================
 
    // ===================== 待选着产品  =============================
    @track jzDataDefault = []; //数据 待选择产品数据据
    jzDataDefaultNotChange = [];
    jzDataDefaultCopy = [];
    @track tableIsLodingDefault = true;
    @track
    initSearchFormDefalt = initSearchFormDefalt2
    @track
    initDataTableDefault = initDataTableDefault2;
    getRowActions(event) {
        let a = event;
    }
    //查询价格政策方案关联产品明细
    //算出的合计
    sumTotal = [];
    getschemedetails() {
        this.jzDataFixedPrice.forEach(jdfp => { //价格政策集合列表
            var SeachData = {
                SearchId: jdfp.Id
            };
            GetSearchProductById(SeachData).then(result => {
                var tempObject = {
                    ...{},
                    ...jdfp
                }
                jdfp = this.countListAndNod(tempObject, result);
                this.sumTotal.push(jdfp);
            });
        });
    }
 
    //比对报价行项目改变后试算界面的变化
    //‘试算合成待选数据’是为了与现在报价行项目进行比对,用试算产品表数据合并出的上一次进行试算的报价行项目
    //试算之前已将报价行项目相同的产品进行了合并
    //1.‘报价行项目’条数少于‘试算合成待选数据’条数时将之前的试算清空,使用新的报价行项目
    //2.当‘报价行项目’条数大于或等于‘试算合成待选数据’条数将两组数据进行比对
    // 2-1)当‘报价行项目’条数等于‘试算合成待选数据’条数时先对比两组数据(根据产品Id进行匹配)
    //  (2-1-1)当数据匹配成功后判断其数量字段,当‘报价行项目’数量小于‘试算合成待选数据’数量时将之前的试算清空,使用新的报价行项目
    //  (2-1-2)等于则删除‘试算合成待选数据’中匹配成功的数据
    //  (2-1-3)大于则用‘报价行项目’数量减去‘试算合成待选数据’数量并将这条数据存入待选报价行项目集合
    // 2-2)当比对结束后如果‘试算合成待选数据’中有数据没有被匹配则将之前的试算清空,使用新的报价行项目
    // 2-3)当‘报价行项目’条数大于‘试算合成待选数据’条数,且‘试算合成待选数据’都已匹配则将‘报价行项目’中未被匹配的数据全部存入待选报价行项目集合
    index = 3;
    comparisonUniqueKey() { //xxx
        this.index--;
        if (this.index == 0) {
            if (this.flagall) {
               if (this.jzDataDefaultCopy.length < this.lastQuotation.length) { //1、条数小于
                    this.jzDataDefault = [...[], ...this.jzDataDefaultCopy];
                    this.jzDataProduct = [];
                    this.jzDataFixedPrice = [];
                    this.jzDataDiscount = [];
                    return;
                } else { //2、
                    var lastQuotation = [...[], ...this.lastQuotation];
                    var DefaultCopy = [...[], ...this.jzDataDefaultCopy];
                    var Default = [];
                    for (var j = 0; j < DefaultCopy.length; j++) {
                        var arrList = [];
                        var fag = true
                        if (lastQuotation.length != 0) {
                            for (var i = 0; i < lastQuotation.length; i++) {
                                if (DefaultCopy[j].Id == lastQuotation[i].Id) {
                                    if (DefaultCopy[j].Quantity < lastQuotation[i].Quantity) { //2-1-1 数量小于 clear
                                        this.jzDataDefault = [...[], ...this.jzDataDefaultCopy];
                                        this.jzDataProduct = [];
                                        this.jzDataFixedPrice = [];
                                        this.jzDataDiscount = [];
                                        return;
                                    } else if (DefaultCopy[j].Quantity == lastQuotation[i].Quantity) { //2-1-2
                                        fag = false;
                                    } else { //2-1-3   数量大于 塞到待选产品
                                        DefaultCopy[j].Quantity = DefaultCopy[j].Quantity - lastQuotation[i].Quantity;
                                        Default.push(DefaultCopy[j]);
                                        fag = false;
                                    }
                                } else {
                                    arrList.push(lastQuotation[i]);
                                }
                            }
                            lastQuotation = arrList;
                            if (fag) {
                                Default.push(DefaultCopy[j]);
                            }
 
                        } else { //2-3  条数大于 将数据塞到待选产品
                            Default.push(DefaultCopy[j]);
                        }
                    }
                    if (lastQuotation.length != 0) { //2-2  合成数据有剩余
                        this.jzDataDefault = [...[], ...this.jzDataDefaultCopy];
                        this.jzDataProduct = [];
                        this.jzDataFixedPrice = [];
                        this.jzDataDiscount = [];
                        return;
                    }
                    this.jzDataDefault = [...[], ...Default];
                }
            }
        }
    }
    // 后台交互,获取待选择产品列表数据
    UniqueKey = new Map();
    getTableDataDefault(event) {
        let data = [];
        //todu10
        GetPromotionDefalut({
            IdParam: this.ParamIdStr
        }).then(result => {
            this.jzDataDefaultNotChange = [];
            this.jzDataDefaultCopy = [];
            var i = 1;
            result.forEach(rItem => {
                rItem.ListPrice = rItem.ListPrice__c;
                rItem.HangHao = i++;
                // if (!this.flagall) {
                rItem.Id = rItem.Product2Id; //报价行唯一key
                // }
                let tempS = {
                    ...{},
                    ...rItem
                };
                this.jzDataDefaultNotChange.push(tempS);
                this.jzDataDefaultCopy.push(tempS);
            });
            this.getschemedetails();
            if (this.flagall) {
                var newList = [];
                this.OnLoadProduct.forEach(items => { //items未选择产品 
                    var DataTemp = {};
                    result.forEach(reItgem => {
                        if (reItgem.Id == items.Id) {
                            DataTemp = reItgem;
                            return;
                        }
                        reItgem.ListPrice = reItgem.ListPrice__c;
                    })
                    if (DataTemp != undefined && DataTemp != {}) {
                        DataTemp = {
                            ...DataTemp,
                            ...items
                        };
                    }
                    newList.push(DataTemp);
                })
                this.jzDataDefault = newList;
                this.tableIsLodingDefault = false;
                this.comparisonUniqueKey();
                return;
            } else {
                result.forEach(rItems => {
                    rItems.ListPrice = rItems.ListPrice__c;
                });
                this.jzDataDefault = result;
                this.tableIsLodingDefault = false;
                var event = {
                    page: 1,
                    pageLimit: 10,
                    search: "",
                    sortOrder: "asc",
                    sortPlus: undefined,
                    fag: true
                };
                this.getTableDataFix(event);
            }
        })
    }
 
    SelectedFnDefault(rows) {
        let arr = rows;
    }
    // ===================== END待选着产品  =============================
 
 
    // ===================== 使用价格政策  =============================
 
 
    @track jzDataFixedPrice = []; //价格政策数据存储1   集合
    @track tableIsLodingFixedPrice = true;
    Lianxi = true;
    @track
    initSearchFormFixedPrice = initSearchFormFixedPrice2
    @track
    initDataTableFixedPrice = initDataTableFixedPrice2
    // 后台交互,获取列表数据
    getTableDataFixedPrice(event) {
        this.tableIsLodingFixedPrice = false;
        var indexTemp = [];
    }
    //对比价格政策赋值
    comparativeAssignment() {
        this.jzDataFixedPrice.forEach(jdfp => { //价格政策集合
            this.sumTotal.forEach(stl => { //初始化时价格政策集合
                if (jdfp.Id == stl.Id) {
                    if (stl.sumListPrice != undefined && stl.sumNoDiscount != undefined) {
                        jdfp.sumListPrice = stl.sumListPrice;
                        jdfp.sumNoDiscount = stl.sumNoDiscount;
                    }
                }
            });
        });
    }
    //计算价格政策的最大次数
    ComputeMaximumTimes(priceArr) {
        // var num=0;
        var Pricepolicy = {
            ...{},
            ...priceArr
        };
        var b = this.jzDataDefaultCopyQuantityList; //查出的每个方案的明细的数量
        var selectproducts = this.jzDataDefault; //待选产品
        Pricepolicy.maxCounts = ComputationalLogic(Pricepolicy, b, selectproducts);
        return Pricepolicy;
    }
    //保存价格政策编辑列
    handleSaveFixedPrice(event) {
        this.comparativeAssignment();
        // 更改次数 把对应的id 的 num值也需要改变,这个集合是记录所有匹配上的 政策的 关系的,改变了对应关系 也需要维护一下这个集合
        var a = this.CompareFullData;
        var CompareFullDataedit = [];
        var HeTongTotal = 0;
        var data = event.detail.rows;
        let newData = [];
        let editnewDate = [];
        var boolean = 1;
        for (var i = 0; i < this.jzDataFixedPrice.length; i++) {
            var editData = {};
            var flag = false;
            for (var j = 0; j < data.length; j++) {
                var id = data[j].DelectId.replace("row-", "");
                if (this.jzDataFixedPrice[i].DelectId == id) {
                    // editData=data[j];
                    editData = {
                        Counts: '',
                        HeTongTotal: ''
                    };
                    //对象折扣
                    editData.Counts = data[j].Counts;
                    //赋值 非对象折扣
                    editData.HeTongTotal = data[j].HeTongTotal;
                    // editData.id=id;
                    flag = true;
                }
            }
            if (flag) {
                var newItem = {
                    ...this.jzDataFixedPrice[i],
                    ...{}
                }; //价格政策数据
                //计算最大次数
                newItem = this.ComputeMaximumTimes(newItem);
                if (editData.Counts != undefined) {
                    var ifNec = true;
                    if (newItem.recordTypeName__c == "NormalProduct") {
                        if (newItem.ifNecessary__c) {
                            ifNec = false;
                        }
                    }
                    newItem.maxCounts = Number(newItem.maxCounts);
                    if (newItem.maxCounts >= editData.Counts && ifNec) {
                        if (editData.Counts == 0) {
                            boolean = 4;
                        } else {
                            if (newItem.if_Contain_Nod__c) {
                                HeTongTotal = newItem.Price_CNY__c * editData.Counts;
                            } else {
                                HeTongTotal = newItem.Price_CNY__c * editData.Counts + newItem.sumNoDiscount * editData.Counts;
                            }
                            newItem.Counts = editData.Counts;
                            // newItem.HeTongTotal = HeTongTotal;
                            if (newItem.recordTypeName__c == "Promotion") {
                                newItem.HeTongTotal = HeTongTotal;
                            }
                            newItem.determine = '改过';
                            a.forEach(editnum => {
                                if (editnum.Id == newItem.Id) {
                                    editnum.num = newItem.Counts;
                                    CompareFullDataedit.push(editnum);
                                } else {
                                    CompareFullDataedit.push(editnum);
                                }
                            });
                            this.CompareFullData = [...[], ...CompareFullDataedit];
                            // }
                        }
                    } else {
                        if (ifNec) {
                            boolean = 3;
                        } else {
                            boolean = 5;
                        }
                    }
                }
                if (editData.HeTongTotal != undefined) {
                    if (newItem.if_Contain_Nod__c) {
                        HeTongTotal = newItem.Price_CNY__c * newItem.Counts;
                    } else {
                        HeTongTotal = newItem.Price_CNY__c * newItem.Counts + newItem.sumNoDiscount * newItem.Counts;
                    }
                    if (editData.HeTongTotal < HeTongTotal) {
                        boolean = 6;
                    } else {
                        newItem.HeTongTotal = editData.HeTongTotal;
                        newItem.determine = '改过';
                    }
                }
                newData.push(newItem);
                editnewDate.push(newItem);
            } else {
                newData.push({
                    ...{},
                    ...this.jzDataFixedPrice[i]
                });
            }
        }
        //haha
        var newArrs = [...[], ...editnewDate];
        if (boolean == 1) {
            this.jzDataFixedPrice = newData;
            newArrs.forEach(item => {
                this.ComputeData(item.Id, '价格政策');
                this.Alert("数据修改成功", false, true);
                setTimeout(() => {
                    this.CloseAlert();
                }, 2000);
            });
            this.jzDataProduct = [...this.newArrsTemp3, ...this.newArrsTemp4];
            //合同价格汇总
            this.ContractPriceCompute();
        } else if (boolean == 3) {
            this.Alert("修改错误,次数已经超过最大值,不可增加", true, true);
        } else if (boolean == 4) {
            this.Alert("修改错误,次数不可以为0", true, true);
        } else if (boolean == 5) {
            this.Alert("该方案为强制匹配,次数不可修改!", true, true);
        } else if (boolean == 6) {
            var str1 = String(HeTongTotal);
            var str = "修改错误,合同价格不得小于";
            var str3 = str + str1;
            this.Alert(str3, true, true);
        }
        //刷新
        this.jzshows3 = false;
        this.IsLoading3 = true;
        setTimeout(() => {
            this.IsLoading3 = false;
            this.jzshows3 = true;
        }, 800);
    }
    newArrsTemp3 = [];
    newArrsTemp4 = [];
 
    UpdateJZData(arrs) { //arrs  选中的数据集合
        if (this.jzDataFixedPrice == null || this.jzDataFixedPrice.length <= 0) {
            this.jzDataFixedPrice = arrs;
        } else {
            this.jzDataFixedPrice = [...this.jzDataFixedPrice, ...arrs];
        };
    }
    //价格政策选中
    @track SelectedFnDataFixedPrice = [];
    SelectedFnFixedPrice(event) {
        let arr = event.detail.rows;
        this.SelectedFnDataFixedPrice = arr;
    }
    //删除价格政策
    //todu8
    deleteFixedPrice() {
        let ids = [];
        var fag = true;
        var select = [];
        for (var j = 0; j < this.SelectedFnDataFixedPrice.length; j++) {
            fag = true;
            var PromotionHeadRecordId = this.SelectedFnDataFixedPrice[j].recordTypeName__c;
            if (PromotionHeadRecordId == "NormalProduct") {
                if (this.SelectedFnDataFixedPrice[j].ifNecessary__c) {
                    fag = false;
                    this.Alert("一般产品为强制匹配,不可删除", true, true);
                } else {
                    select.push(this.SelectedFnDataFixedPrice[j]);
                }
            } else {
                select.push(this.SelectedFnDataFixedPrice[j]);
            }
            if (fag) {
                var a = this.CompareFullData;
                var compareFu = [];
                ids.push(this.SelectedFnDataFixedPrice[j].Id);
                a.forEach(deletId => {
                    if (this.SelectedFnDataFixedPrice[j].Id != deletId.Id) {
                        compareFu.push(deletId);
                    }
                });
                this.CompareFullData = [...[], ...compareFu];
            }
        }
        this.SelectedFnDataFixedPrice = [...[], ...select];
        if (fag) {
            //删除所选方案匹配的产品
            this.DeleteChangesFn(ids, "价格政策");
            //调用删除价格政策
            this.deleteFixedPriceTemp();
            //合同价格汇总
            this.ContractPriceCompute();
        }
    }
    jzshows3 = true;
    //加载
    //删除价格政策
    deleteFixedPriceTemp() {
        let newarr = [];
        for (var j = 0; j < this.SelectedFnDataFixedPrice.length; j++) {
            for (var i = 0; i < this.jzDataFixedPrice.length; i++) {
                var a = this.CompareFullData;
                var compareFu = [];
                a.forEach(deletId => {
                    if (this.SelectedFnDataFixedPrice[j].Id != deletId.Id) {
                        compareFu.push(deletId);
                    }
                });
                this.CompareFullData = [...[], ...compareFu];
                if (this.SelectedFnDataFixedPrice[j].Id == this.jzDataFixedPrice[i].Id) {
                    this.jzDataFixedPrice.splice(i, 1); // 将使后面的元素依次前移,数组长度减1
                    i--;
                }
            }
        }
        for (var i = 0; i < this.jzDataFixedPrice.length; i++) {
            newarr.push(this.jzDataFixedPrice[i]);
        }
        this.jzDataFixedPrice = newarr;
        this.SelectedFnDataFixedPrice = [];
    }
    // ===================== END使用价格政策  =============================
 
 
    // =========================固定价格 弹出框 ========================= 
    @track ShowFix;
    showModalFix() {
        this.ShowFix = true
    }
    cancelFix() {
        this.ShowFix = false
    }
    @track
    initSearchFormFix = initSearchFormFix2;
    @track
    initDataTableFix = initDataTableFix2;
 
    @track jzDataFix = [];
    @track tableIsLodingFix = true;
 
    // 点击搜索触发
    searchDataFix(event) {
        let searchParams = event.detail.searchParams || {};
        this.template.querySelector('[data-parent-id="parent-div-idFix"]').refreshDataTable({
            searchParams: searchParams
        });
    }
    //页面切换触发
    pagingClickFix(event) {
        let page = event.detail.page || {};
        this.template.querySelector('[data-parent-id="parent-div-idFix"]').refreshDataTable({
            page: page
        });
    }
 
    jzDataDefaultCopyQuantityList = [];
    // 后台交互,获取一般产品列表数据
    ifqianpi = true;
    getTableDataFix(event) {
        let listQuery = event;
        if (event.fag) {
            this.ifqianpi = false;
        } else {
            listQuery = event.detail.listQuery;
        }
        listQuery.pageLimit = 200;
        GetNormalProductSearch(listQuery).then(result => {
            //BBBB 
            var tempArr = result.split("--");
            var responseObj = JSON.parse(tempArr[0]);
            var responseObjAll = JSON.parse(tempArr[1]);
            //排序
            var newArrs = new Array;
            responseObjAll.forEach(item => {
                newArrs.push(item);
            })
            newArrs.sort((a, b) => {
                return a.OrderNo__c - b.OrderNo__c;
            })
            newArrs.forEach(item => { //排序后的一般产品主数据
                var SeachData = {
                    SearchId: item.Id
                };
                GetSearchProductById(SeachData).then(results => {
                    results.forEach(itemss => { //方案关联的产品
                        var fl = true;
                        if (this.jzDataDefaultCopyQuantityList.length == 0) {
                            this.jzDataDefaultCopyQuantityList.push({
                                Asset_Model_No__c: itemss.Asset_Model_No__c,
                                Quantity__c__c: itemss.Quantity__c,
                                Id_H: item.PromotionNo__c
                            });
                        } else {
                            this.jzDataDefaultCopyQuantityList.forEach(jdcql => {
                                if (itemss.Asset_Model_No__c == jdcql.Asset_Model_No__c && jdcql.Id_H == item.PromotionNo__c) {
                                    fl = false;
                                }
                            });
                            if (fl) {
                                this.jzDataDefaultCopyQuantityList.push({
                                    Asset_Model_No__c: itemss.Asset_Model_No__c,
                                    Quantity__c__c: itemss.Quantity__c,
                                    Id_H: item.PromotionNo__c
                                });
                            }
                        }
                        // }
                        // });
                    });
                    var iflag = true;
                    var newarrjdf = [];
                    this.jzDataFixedPrice.forEach(jdf => { //价格政策
                        if (jdf.Id == item.Id) {
                            iflag = false;
                            // jdf.sumListPrice = sumListPrice;
                            // jdf.sumNoDiscount = sumNoDiscount;
                            newarrjdf.push(jdf);
                        } else {
                            newarrjdf.push(jdf);
                        }
                    });
                    this.jzDataFixedPrice = [...[], ...newarrjdf];
                    if (event.fag && iflag) {
                        var newArr = [];
                        newArr.push(item);
                        this.ifqianpi = false;
                        this.GetSearchProductByIdFn(item.Id, item, "价格政策", [], newArr, false);
                    }
                });
            });
            var respons = [];
            responseObj.records.forEach(rrds => { //查出的前十条
                responseObjAll.forEach(rsja => { //查出的所有一般产品数据
                    if (rrds.Id == rsja.Id) {
                        respons.push(rsja);
                    }
                })
            })
            this.jzDataFix = [...[], ...respons];
            this.tableIsLodingFix = false;
        })
    }
    // 价格政策选中 
    SelectedFnFix(event) {
        let arr = event.detail.rows;
        this.ifqianpi = true;
        if (arr.length > 1) {
            this.TZshow(false);
            this.TZErrorshow(true);
        } else {
            //获取数据
            this.GetSearchProductByIdFn(arr[0].Id, arr[0], "价格政策", [], arr);
            this.cancelFix();
        }
    }
 
    // ============================END =======================
 
    // ===================== 使用折扣政策  =============================
 
    @track jzDataDiscount = []; //折扣政策数据2 集合
    @track tableIsLodingDiscount = true;
    @track
    initSearchFormDiscount = initSearchFormDiscount2;
    @track
    initDataTableDiscount = initDataTableDiscount2;
    // 后台交互,获取列表数据
    getTableDataDiscount(event) {
        this.tableIsLodingDiscount = false;
    }
    //将产品与方案匹配
    UpdateDiscountData(arrs) { //选中的数据
        if (this.jzDataDiscount == null || this.jzDataDiscount.length <= 0) {
            this.jzDataDiscount = arrs;
        } else {
            this.jzDataDiscount = [...this.jzDataDiscount, ...arrs];
        }
    }
    //折扣政策选中
    @track SelectedFnDataDiscount = []
    SelectedFnDiscount(event) {
        let arr = event.detail.rows;
        this.SelectedFnDataDiscount = arr;
    }
    //删除折扣政策
    //todu9
    delectTableDiscount() {
        let ids = [];
        for (var j = 0; j < this.SelectedFnDataDiscount.length; j++) {
            ids.push(this.SelectedFnDataDiscount[j].Id);
        }
        //删除方案对应的产品明细
        // this.DeleteChangesFn(ids, "折扣政策");
        this.DeleteSchemeMatching(this.SelectedFnDataDiscount, "折扣政策");
        //删除折扣政策
        this.delectTableDiscountTemp();
        //合同价格汇总
        this.ContractPriceCompute();
    }
    //折扣政策删除方案对应产品规则
    DeleteSchemeMatching(ids, TypeName) {
        var CompareFullDataTemp = [];
        ids.forEach(id => {
            //删除 规则数量
            this.CompareFullData.forEach(cItem => {
                if (cItem.Id == id.Id && cItem.ListName == TypeName) {
                    console.warn("CompareFullData 删除");
                } else {
                    CompareFullDataTemp.push(cItem);
                }
            })
            //删除 已选产品
            var CurrentTemp = {};
            if (TypeName == "价格政策") {
                CurrentTemp = this.jzDataFixedPrice.filter(fItem => {
                    if (fItem.Id == id.Id) {
                        return true;
                    }
                    return false;
                })[0];
            }
            if (TypeName == "折扣政策") {
                CurrentTemp = this.jzDataDiscount.filter(fItem => {
                    var PromotionHeadRecordId = id.recordTypeName__c;
                    if (PromotionHeadRecordId == "Authorizer") {
                        if (fItem.Id == id.Id && //方案Id
                            fItem.NormalDiscount__c_Input == id.NormalDiscount__c_Input && //非对象品折扣录入
                            fItem.GuaranteeDiscount__c_Input == id.GuaranteeDiscount__c_Input) { //对象品折扣录入
                            return true;
                        }
                    } else {
                        if (fItem.NormalDiscount__c_Input == id.NormalDiscount__c_Input &&
                            fItem.Category__c == id.Category__c) { //折扣政策分类
                            return true;
                        }
                    }
                    return false;
                })[0];
            }
            //匹配需要删除产品
            var ProductNumsTemp = [];
            var NewjzDataProduct = [];;
            if (TypeName == "价格政策") {
                this.jzDataProduct.forEach(proItem => {
                    if (proItem.PromotionNo__c == CurrentTemp.PromotionNo__c) {
                        ProductNumsTemp.push({
                            Id: proItem.Id,
                            num: proItem.Quantity
                        })
                    } else {
                        NewjzDataProduct.push(proItem);
                    }
                });
            } else if (TypeName == "折扣政策") {
                this.jzDataProduct.forEach(proItem => {
                    var PromotionHeadRecordId = id.recordTypeName__c;
                    if (PromotionHeadRecordId == "Authorizer") {
                        if (CurrentTemp.Id == proItem.PromotionId && //方案Id
                            CurrentTemp.NormalDiscount__c_Input == proItem.NormalDiscount__c_Input && //非对象品折扣录入
                            CurrentTemp.GuaranteeDiscount__c_Input == proItem.GuaranteeDiscount__c_Input) { //对象品折扣录入
                            ProductNumsTemp.push({
                                Id: proItem.Id,
                                num: proItem.Quantity
                            })
                        } else {
                            NewjzDataProduct.push(proItem);
                        }
                    } else {
                        if (CurrentTemp.NormalDiscount__c_Input == proItem.NormalDiscount__c_Input &&
                            CurrentTemp.Category__c == proItem.Category__c) { //折扣政策分类
                            ProductNumsTemp.push({
                                Id: proItem.Id,
                                num: proItem.Quantity
                            })
                        } else {
                            NewjzDataProduct.push(proItem);
                        }
                    }
                });
            }
            // 执行删除
            this.jzDataProduct = NewjzDataProduct;
            //合同价格汇总
            this.ContractPriceCompute();
            // 添加数量
            var newjzDataDefaults = [];
            var AddnumsTemp = [];
            this.jzDataDefault.forEach(defItem => {
                var defItemTemp = {
                    ...{},
                    ...defItem
                };
                ProductNumsTemp.forEach(pTempItem => {
                    if (pTempItem.Id == defItem.Id) {
                        defItemTemp.Quantity += pTempItem.num;
                        AddnumsTemp.push(pTempItem.Id);
                    }
                });
                newjzDataDefaults.push(defItemTemp);
            })
            this.jzDataDefault = newjzDataDefaults;
            //添加整条数据
            var PFTempArr = ProductNumsTemp.filter(pTempItem => {
                var flag = true;
                AddnumsTemp.filter(addItem => {
                    if (addItem == pTempItem.Id) {
                        flag = false;
                    }
                })
                return flag;
            })
            this.jzDataDefaultNotChange.forEach(noChangeItem => {
                PFTempArr.forEach(pftItem => {
                    if (pftItem.Id == noChangeItem.Id) {
                        let newChangeItem = {
                            ...{},
                            ...noChangeItem
                        };
                        newChangeItem.Quantity = pftItem.num;
                        this.jzDataDefault.push(newChangeItem);
                    }
                })
            })
        });
        this.CompareFullData = CompareFullDataTemp;
    }
    //ttt
    jzshows2 = true;
    jzshows3 = true;
 
    //加载
    //删除折扣政策
    delectTableDiscountTemp() {
        let newarr = [];
        for (var j = 0; j < this.SelectedFnDataDiscount.length; j++) {
            for (var i = 0; i < this.jzDataDiscount.length; i++) {
                var PromotionHeadRecordId = this.SelectedFnDataDiscount[j].recordTypeName__c;
                if (PromotionHeadRecordId == "Authorizer") {
                    if (this.SelectedFnDataDiscount[j].Id == this.jzDataDiscount[i].Id &&
                        this.SelectedFnDataDiscount[j].NormalDiscount__c_Input == this.jzDataDiscount[i].NormalDiscount__c_Input &&
                        this.SelectedFnDataDiscount[j].GuaranteeDiscount__c_Input == this.jzDataDiscount[i].GuaranteeDiscount__c_Input) {
                        this.jzDataDiscount.splice(i, 1); // 将使后面的元素依次前移,数组长度减1
                        i--;
                    }
                } else {
                    if (this.SelectedFnDataDiscount[j].Category__c == this.jzDataDiscount[i].Category__c &&
                        this.SelectedFnDataDiscount[j].NormalDiscount__c_Input == this.jzDataDiscount[i].NormalDiscount__c_Input) {
                        this.jzDataDiscount.splice(i, 1); // 将使后面的元素依次前移,数组长度减1
                        i--;
                    }
                }
            }
        }
        for (var i = 0; i < this.jzDataDiscount.length; i++) {
            newarr.push(this.jzDataDiscount[i]);
        }
        this.jzDataDiscount = newarr;
        this.SelectedFnDataDiscount = [];
    }
    //save 方法,保存折扣政策编辑列
    handleSaveDiscount(event) {
        var boolean = 0;
        var boolean2 = false;
        var boolean3 = false;
        var data = event.detail.rows;
        let newData = [];
        let newData2 = [];
        var newMap3 = new Map();
        let newData3 = [];
        var key=0;
        let editnewDate = [];
        var GuaranteeDiscount__cZuiXiao =0;
        var NormalDiscount__cZuiXiao =0;
        for (var i = 0; i < this.jzDataDiscount.length; i++) {
            var editData = {};
            var flag = false;
            for (var j = 0; j < data.length; j++) {
                var id = data[j].DelectId.replace("row-", "");
                if (this.jzDataDiscount[i].DelectId == id) {
                    // editData=data[j];
                    editData = {
                        GuaranteeDiscount__c_Input: '',
                        NormalDiscount__c_Input: '',
                        HeTongPrice: '',
                        GuaranteeDiscount_H_Money__c: '',
                        NormalDiscount_H_Money__c: ''
                    };
                    //对象折扣
                    editData.GuaranteeDiscount__c_Input = data[j].GuaranteeDiscount__c_Input;
                    //赋值 非对象折扣
                    editData.NormalDiscount__c_Input = data[j].NormalDiscount__c_Input;
                    //一般折扣合同价格
                    editData.HeTongPrice = data[j].HeTongPrice;
                    //对象品合同金额
                    editData.GuaranteeDiscount_H_Money__c = data[j].GuaranteeDiscount_H_Money__c;
                    //非对象品合同金额
                    editData.NormalDiscount_H_Money__c = data[j].NormalDiscount_H_Money__c;
                    // editData.id=id;
                    flag = true;
                }
            }
            if (flag) {
                var newItem = {
                    ...this.jzDataDiscount[i],
                    ...{}
                };
                if (editData.GuaranteeDiscount__c_Input != undefined) {
                    if(newItem.JxsType == "特约折扣"){
                        var GuaranteeDiscount__c_Input = parseFloat(editData.GuaranteeDiscount__c_Input);
                        editData.GuaranteeDiscount__c_Input=GuaranteeDiscount__c_Input+'%';
                        var GuaranteeDiscount__c = parseFloat(newItem.GuaranteeDiscount__c);
                        if (GuaranteeDiscount__c_Input < GuaranteeDiscount__c) {
                            GuaranteeDiscount__cZuiXiao=GuaranteeDiscount__c;
                            boolean = 1;
                            break;
                        } else {
                            this.jzDataProduct.forEach(jdpt => {
                                if (newItem.Id == jdpt.PromotionId &&
                                    newItem.GuaranteeDiscount__c_Input == jdpt.GuaranteeDiscount__c_Input &&
                                    newItem.NormalDiscount__c_Input == jdpt.NormalDiscount__c_Input) {
                                    jdpt.GuaranteeDiscount__c_Input = editData.GuaranteeDiscount__c_Input;
                                }
                            });
                            newItem.GuaranteeDiscount__c_Input = editData.GuaranteeDiscount__c_Input;
                            newItem.iftrue = "改过";
                        }
                    }else{
                        boolean = 3;
                        break;
                    }
                }
                if (editData.NormalDiscount__c_Input != undefined) {
                    if(editData.NormalDiscount__c_Input!=''&&editData.NormalDiscount__c_Input>=0){
                        var NormalDiscount__c_Input = parseFloat(editData.NormalDiscount__c_Input);
                        editData.NormalDiscount__c_Input = NormalDiscount__c_Input+'%';
                        var NormalDiscount__c = parseFloat(newItem.NormalDiscount__c);
                        if (NormalDiscount__c_Input < NormalDiscount__c) {
                            NormalDiscount__cZuiXiao=NormalDiscount__c;
                            boolean = 2;
                            break;
                        } else {
                            this.jzDataProduct.forEach(jdpt => {
                                if (newItem.Id == jdpt.PromotionId &&
                                    newItem.GuaranteeDiscount__c_Input == jdpt.GuaranteeDiscount__c_Input &&
                                    newItem.NormalDiscount__c_Input == jdpt.NormalDiscount__c_Input) {
                                    jdpt.NormalDiscount__c_Input = editData.NormalDiscount__c_Input;
                                }
                            });
                            newItem.NormalDiscount__c_Input = editData.NormalDiscount__c_Input;
                            newItem.iftrue = "改过";
                        }
                    }else{
                        boolean = 5
                        break;
                    }
                }
                newItem.GuaranteeDiscount_H_Money_yuan=newItem.GuaranteeDiscount_H_Money__c;
                if (editData.GuaranteeDiscount_H_Money__c != undefined) {
                    if(newItem.JxsType == "特约折扣"){
                        if(editData.GuaranteeDiscount_H_Money__c==""){
                            editData.GuaranteeDiscount_H_Money__c=0;
                        }
                        newItem.GuaranteeDiscount_H_Money__c = editData.GuaranteeDiscount_H_Money__c;
                        newMap3.set(key,newItem);
                        boolean = 4;
                        boolean2 = true ;
                    }else{
                        boolean = 3;
                        break;
                    }
                        
                }
                newItem.NormalDiscount_H_Money_yuan=newItem.NormalDiscount_H_Money__c;
                if (editData.NormalDiscount_H_Money__c != undefined) {
                        if(editData.NormalDiscount_H_Money__c==""){
                            editData.NormalDiscount_H_Money__c=0;
                        }
                        newItem.NormalDiscount_H_Money__c = editData.NormalDiscount_H_Money__c;
                        if(newItem.JxsType == "一般折扣"){
                            newData2.push(newItem);
                            boolean = 4;
                            boolean3 = true;
                        }else{
                            newMap3.set(key,newItem);
                            boolean = 4;
                            boolean2 = true;
                        }
                }
                if (editData.NormalDiscount_H_Money__c != undefined||editData.GuaranteeDiscount_H_Money__c != undefined) {
                    if(newItem.JxsType == "一般折扣"){
                        newItem.HeTongPrice = parseFloat(newItem.NormalDiscount_H_Money__c)
                    }else{
                        newItem.HeTongPrice = parseFloat(newItem.NormalDiscount_H_Money__c)+parseFloat(newItem.GuaranteeDiscount_H_Money__c);
                    }
                }
                key++;
                newData.push(newItem);
                editnewDate.push(newItem);
            } else {
                newData.push({
                    ...{},
                    ...this.jzDataDiscount[i]
                });
            }
        }
        for (let [k, v] of newMap3) {
            newData3.push(v);
        }
        //haha2
        debugger
        if (boolean == 0) {
            this.jzDataDiscount = newData;
            var newArrs = [...[], ...editnewDate];
            newArrs.forEach(item => {
                // this.ComputeData(item.Id, '折扣政策');
                //合并折扣政策重复方案
                this.ConsolidatedDiscountPolicy(this.jzDataDiscount);
                this.ComputeDiscount(item.Id, item.NormalDiscount__c_Input, item.GuaranteeDiscount__c_Input, item.Category__c, item.JxsType);
            });
            this.jzDataProduct = [...this.newArrsTemp2, ...this.newArrsTemp];
            //合同价格汇总
            this.ContractPriceCompute();
            this.Alert("数据修改成功", false, true);
            setTimeout(() => {
                this.CloseAlert();
            }, 2000);
        } else if (boolean == 1) {
            this.Alert("修改错误,对象品折扣不得小于对象品最低折扣:"+GuaranteeDiscount__cZuiXiao+"%", true, true);
        } else if (boolean == 2) {
            this.Alert("修改错误,非对象品折扣不得小于非对象品最低折扣:"+NormalDiscount__cZuiXiao+"%", true, true);
        } else if (boolean == 3) {
            this.Alert("修改错误,一般折扣没有对象品折扣", true, true);
        } else if (boolean == 5) {
            this.Alert("非对象品折扣不可以为空或小于0", true, true);
        } else if (boolean == 4) {
            this.jzDataDiscount = newData;
            var ffgg=0;
            if(boolean3){
                newData2.forEach(HeTo => {
                    //根据合同价格计算一般折扣
                    HeTo = this.ComouteProductDiscount(HeTo.Id,HeTo.Category__c,HeTo.GuaranteeDiscount__c_Input, HeTo.NormalDiscount__c_Input, HeTo.GuaranteeDiscount_H_Money__c,HeTo.NormalDiscount_H_Money__c, HeTo);
                    if(HeTo==1||HeTo==2||HeTo==12||HeTo==3){
                        ffgg=HeTo;
                        return ;
                    }
                    //合并折扣政策重复方案
                    this.ConsolidatedDiscountPolicy(this.jzDataDiscount);
                    //一般折扣更改过合同价格计算
                    this.updateCommonlyDiscountLogic(HeTo.Id,HeTo.JxsType,HeTo.GuaranteeDiscount__c_Input,HeTo.NormalDiscount__c_Input,HeTo.Category__c,this.jzDataDiscount);
                });
            }
            if(boolean2&&ffgg==0){
                newData3.forEach(TeYue=>{
                    //根据合同价格计算特约折扣
                    GuaranteeDiscount__cZuiXiao=parseFloat(TeYue.GuaranteeDiscount__c);
                    NormalDiscount__cZuiXiao=parseFloat(TeYue.NormalDiscount__c);
                    TeYue=this.ComouteProductDiscount(TeYue.Id,TeYue.Category__c,TeYue.GuaranteeDiscount__c_Input, TeYue.NormalDiscount__c_Input, TeYue.GuaranteeDiscount_H_Money__c,TeYue.NormalDiscount_H_Money__c, TeYue);
                    if(TeYue==1||TeYue==2||TeYue==12||TeYue==3){
                        ffgg=TeYue;
                        return ;
                    }else{
                        //合并折扣政策重复方案
                        this.ConsolidatedDiscountPolicy(this.jzDataDiscount);
                        //一般折扣更改过合同价格计算
                        this.updateCommonlyDiscountLogic(TeYue.Id,TeYue.JxsType,TeYue.GuaranteeDiscount__c_Input,TeYue.NormalDiscount__c_Input,TeYue.Category__c,this.jzDataDiscount);
                    }
                });
            }
            if(ffgg==1||ffgg==2||ffgg==12||ffgg==3){
                this.Alert(InverseCalculationTiShi(ffgg,GuaranteeDiscount__cZuiXiao,NormalDiscount__cZuiXiao), true, true);
            }else{
                this.Alert("数据修改成功", false, true);
                setTimeout(() => {
                    this.CloseAlert();
                }, 2000);
            }
        }
        //刷新
        this.jzshows2 = false;
        this.IsLoading2 = true;
        setTimeout(() => {
            this.jzshows2 = true;
            this.IsLoading2 = false;
        }, 800)
    }
    newArrsTemp = [];
    newArrsTemp2 = [];
    // ===================== END使用价格政策  =============================
 
    // =========================特约折扣 弹出框 ========================= 
    @track ShowSpecial;
    //打开特约折扣弹出框
    showModalSpecial() {
        this.QuoteData.forEach(qtd => {
            if (!qtd.Opportunity.IsAuthorized__c) {
                this.Alert("该询价不是特约经销商授权", true, true);
            } else {
                this.ShowSpecial = true;
            }
        });
    }
    cancelSpecial() {
        this.ShowSpecial = false
        this.ShowSpecialIsError = false;
        this.SelectedFnDataSpecial = [];
        this.SelectedOtherDataArr = [];
    }
    //特约错误提示
    errorTiShi(str){
        this.ShowSpecialIsError = true;
        this.ShowSpecial = true;
        this.ShowSpecialError = str;
    }
    @track TyName = []
    ShowSpecialError = "只能选择一条折扣数据!";
    //特约折扣点击确定后执行
    SavesSpecial() {
        this.ShowSpecialIsError = false;
        this.ShowSpecial = false;
        var ItempTempData = {
            ...{},
            ...this.SelectedFnDataSpecial[0]
        };
        if (this.SelectedOtherDataArr.length == 0 && this.SelectedFnDataSpecial.length != 0) {
            this.errorTiShi("请选择特约折扣产品!");
        } else if (this.SelectedFnDataSpecial.length == 0 && this.SelectedOtherDataArr.length != 0) {
            this.errorTiShi("请选择特约折扣方案!");
        } else if (this.SelectedFnDataSpecial.length == 0 && this.SelectedOtherDataArr.length == 0) {
            this.errorTiShi("请选择特约折扣方案和产品!");
        } else {
            ItempTempData.itemss = this.SelectedOtherDataArr;
            ItempTempData.IsTempItems = true;
            //tt
            // ItempTempData.NormalDiscount__c = parseFloat(ItempTempData.NormalDiscount__c);
            // ItempTempData.GuaranteeDiscount__c = parseFloat(ItempTempData.GuaranteeDiscount__c);
            ItempTempData.NormalDiscount__c_Input = ItempTempData.NormalDiscount__c;
            ItempTempData.GuaranteeDiscount__c_Input = ItempTempData.GuaranteeDiscount__c;
            //tt
            this.SelectedFnDataSpecial[0] = ItempTempData;
            //将产品与方案匹配
            this.UpdateDiscountData(this.SelectedFnDataSpecial);
            //特约折扣匹配规则
            this.SpecialSavesChange("特约折扣", ItempTempData, this.SelectedFnDataSpecial[0].Id, this.SelectedFnDataSpecial[0].CompareId);
            this.Alert("特约折扣选择完成", false, true);
            setTimeout(() => {
                this.CloseAlert();
            }, 2000);
            //合并折扣政策重复方案
            this.ConsolidatedDiscountPolicy(this.jzDataDiscount);
            //折扣政策价格计算
            // this.ComputeData(ItempTempData.Id, '折扣政策');
            this.ComputeDiscount(ItempTempData.Id, ItempTempData.NormalDiscount__c, ItempTempData.GuaranteeDiscount__c, ItempTempData.Category__c, ItempTempData.JxsType);
            this.SelectedFnDataSpecial = [];
            this.SelectedOtherDataArr = [];
        }
    }
    //合并折扣政策重复方案
    ConsolidatedDiscountPolicy(SchemeSet) {
        var arr = [];
        arr = ConsolidatedDiscountPolicyLogic(SchemeSet, arr); //合并折扣政策重复方案逻辑
        this.jzDataDiscount = [...[], ...arr];
        // this.ConsolidationProgramProducts(arr);
        this.ConsolidatedDiscountDetails(arr); //合并折扣政策产品明细
    }
    //合并折扣政策产品明细
    ConsolidatedDiscountDetails(arrSchemes) {
        var jzdataList = [...[], ...this.jzDataProduct];
        this.jzDataProduct = ConsolidatedDiscountDetailsLogic(arrSchemes, jzdataList); //合并折扣政策产品明细逻辑
    }
    @track
    initSearchFormSpecial = initSearchFormSpecial2;
    @track
    initDataTableSpecial = initDataTableSpecial2;
    @track jzDataSpecial = [];
    @track tableIsLodingSpecial = true;
    // 后台交互,获取特约折扣方案列表数据
    getTableDataSpecial(event) {
        let listQuery = event.detail.listQuery;
        var Agency1__c = this.QuoteData[0].Agency1__c;
        listQuery.pageLimit = 40;
        listQuery.Agency1c = Agency1__c;
        GetAuthorizerSearch(listQuery).then(result => {
            var responseObj = JSON.parse(result);
            this.jzDataSpecial = responseObj.records;
            this.jzDataSpecial.forEach(element => {
                element.JxsType = "特约折扣";
                //tt
                element.NormalDiscount__c = element.NormalDiscount__c+"%";
                // element.NormalDiscount__c=Number(element.NormalDiscount__c.toFixed(2));
                element.GuaranteeDiscount__c = element.GuaranteeDiscount__c+'%';
                // element.GuaranteeDiscount__c=Number(element.GuaranteeDiscount__c.toFixed(2));
                //tt
            });
            GetAgencyRName().then(gar => { //获取经销商姓名
                var a = JSON.parse(gar);
                a.forEach(ga => {
                    if (ga.Agency__r != undefined) {
                        var arr = [];
                        this.jzDataSpecial.forEach(jzdsc => { //特约折扣方案数据
                            if (ga.Agency__c == jzdsc.Agency__c) {
                                jzdsc.Agency__Name = ga.Agency__r.Name;
                                arr.push(jzdsc);
                            } else {
                                arr.push(jzdsc);
                            }
                        });
                        this.jzDataSpecial = [...[], ...arr];
                    }
                });
            })
            this.tableIsLodingSpecial = false;
        })
    }
    // 选中特约折扣方案数据
    @track SelectedFnDataSpecial = [];
    ShowSpecialIsError = false;
    SelectedFnSpecial(event) {
        let arr = event.detail.rows;
        if (event.detail.rows.length > 1) {
            this.ShowSpecialIsError = true;
        } else {
            this.ShowSpecialIsError = false;
        }
        var TempArr = [];
        TempArr.push(arr[0])
        var tempObject = {
            ...{},
            ...TempArr[0]
        }
        tempObject.CompareId = GetUUID();
        this.SelectedFnDataSpecial = [tempObject];
    }
    //特约折扣数量拆分
    IsLoading5 = false;
    jzshows5 = true;
    IsLoadingFlag1 = true;
    SaveSpecialDiscount(event) {
        var data = event.detail.rows;
        let newData = [];
        let editnewDate = [];
        var boolean = 1;
        for (var i = 0; i < this.jzDataOtherData.length; i++) {
            var editData = {};
            var flag = false;
            for (var j = 0; j < data.length; j++) {
                var id = data[j].Id;
                if (this.jzDataOtherData[i].Id == id) {
                    // editData=data[j];
                    editData = {
                        SplitQuantity: ''
                    };
                    //拆分次数
                    editData.SplitQuantity = data[j].SplitQuantity;
                    // editData.id=id;
                    flag = true;
                }
            }
            if (flag) {
                var newItem = {
                    ...this.jzDataOtherData[i],
                    ...{}
                };
                if (editData.SplitQuantity != undefined) {
                    newItem.SplitQuantity = Number(editData.SplitQuantity);
                }
                newData.push(newItem);
                editnewDate.push(newItem);
            } else {
                newData.push({
                    ...{},
                    ...this.jzDataOtherData[i]
                });
            }
        }
        //haha4
        var newArrs = [...[], ...editnewDate];
        newArrs.forEach(item => {
            if (item.Quantity < item.SplitQuantity) {
                boolean = 2;
            } else if (item.SplitQuantity == 0 || item.SplitQuantity == '') {
                boolean = 3;
            }
        });
        if (boolean == 1) {
            this.jzDataOtherData = newData;
            this.ShowSpecialIsError = false;
        } else if (boolean == 2) {
            this.errorTiShi("修改错误,使用数量不得大于数量");
        } else if (boolean == 3) {
            this.errorTiShi("修改错误,使用数量不得为0或为空");
        }
 
        //刷新
        this.jzshows5 = false;
        this.IsLoading5 = true;
        this.IsLoadingFlag1 = false;
        setTimeout(() => {
            this.SelectedOtherDataArr = [];
            this.IsLoading5 = false;
            this.jzshows5 = true;
        }, 1000);
        setTimeout(() => {
            this.IsLoadingFlag1 = true;
        }, 2000);
    }
    //  OtherData
    @track
    initSearchFormOtherData = initSearchFormOtherData2;
    @track
    initDataTableOtherData = initDataTableOtherData2;
    @track jzDataOtherData = [];
    @track tableIsLodingOtherData = true;
    // 后台交互,获取特约折扣产品列表数据
    getTableDataOtherData(event) {
        if (!this.IsLoadingFlag1) {
            return
        };
        this.jzDataOtherData = this.jzDataDefault;
        var jzDataOtherDataTemp = [];
        this.jzDataOtherData.forEach(jzdod => {
            var ItemsTemp = {
                ...{},
                ...jzdod
            };
            ItemsTemp.SplitQuantity = ItemsTemp.Quantity;
            jzDataOtherDataTemp.push(ItemsTemp);
        })
        this.jzDataOtherData = jzDataOtherDataTemp;
        this.tableIsLodingOtherData = false;
    }
    // 特约折扣产品选中 
    @track SelectedOtherDataArr = [];
    SelectedFnOtherData(event) {
        let arr = event.detail.rows;
        this.SelectedOtherDataArr = arr;
    }
    // ============================END =======================
 
 
    // =========================一般价格 弹出框 ========================= 
    @track ShowCommonly;
    showModalCommonly() {
        this.ShowCommonly = true
    }
    //保存使用数量
    IsLoading4 = false;
    jzshows4 = true;
    IsLoadingFlag = true;
    //一般折扣匹配规则
    SaveGeneralDiscount(event) {
        var data = event.detail.rows;
        let newData = [];
        let editnewDate = [];
        var boolean = 1;
        for (var i = 0; i < this.jzDataCommonly.length; i++) {
            var editData = {};
            var flag = false;
            for (var j = 0; j < data.length; j++) {
                var id = data[j].Id;
                if (this.jzDataCommonly[i].Id == id) {
                    // editData=data[j];
                    editData = {
                        SplitQuantity: ''
                    };
                    //拆分次数
                    editData.SplitQuantity = data[j].SplitQuantity;
                    // editData.id=id;
                    flag = true;
                }
            }
            if (flag) {
                var newItem = {
                    ...this.jzDataCommonly[i],
                    ...{}
                };
                if (editData.SplitQuantity != undefined) {
                    newItem.SplitQuantity = Number(editData.SplitQuantity);
                }
                newData.push(newItem);
                editnewDate.push(newItem);
            } else {
                newData.push({
                    ...{},
                    ...this.jzDataCommonly[i]
                });
            }
        }
        //haha3
        var newArrs = [...[], ...editnewDate];
        newArrs.forEach(item => {
            if (item.Quantity < item.SplitQuantity) {
                boolean = 2;
            } else if (item.SplitQuantity == 0 || item.SplitQuantity == '') {
                boolean = 3;
            }
        });
        if (boolean == 1) {
            this.jzDataCommonly = newData;
            this.ShowCommonlyIsError = false;
        } else if (boolean == 2) {
            this.ShowCommonlyIsError = true;
            this.ShowCommonlyError = "修改错误,使用数量不得大于数量";
        } else if (boolean == 3) {
            this.ShowCommonlyIsError = true;
            this.ShowCommonlyError = "修改错误,使用数量不得为0或为空";
        }
        //刷新
        this.jzshows4 = false;
        this.IsLoading4 = true;
        this.IsLoadingFlag = false;
        setTimeout(() => {
            this.SelectedFnCommonlyData = [];
            this.IsLoading4 = false;
            this.jzshows4 = true;
        }, 1000);
        setTimeout(() => {
            this.IsLoadingFlag = true;
        }, 2000);
    }
    //关闭一般折扣弹出框触发
    cancelCommonly() {
        this.ShowCommonly = false;
        this.ShowCommonlyIsError = false;
        this.SelectedFnCommonlyData = [];
        this.SaveLb = '';
        this.SaveZk = '';
    }
    @track
    initSearchFormCommonly = initSearchFormCommonly2;
    @track
    initDataTableCommonly = initDataTableCommonly2;
    @track jzDataCommonly = [];
    @track tableIsLodingCommonly = true;
    // 后台交互,获取一般折扣列表数据
    getTableDataCommonly(event) {
        if (!this.IsLoadingFlag) {
            return
        };
        this.jzDataCommonly = this.jzDataDefault;
        var jzDataCommonlyTemp = [];
        this.jzDataCommonly.forEach(items => {
            var ItemsTemp = {
                ...{},
                ...items
            };
            ItemsTemp.JxsType = "一般折扣";
            ItemsTemp.SplitQuantity = ItemsTemp.Quantity;
            jzDataCommonlyTemp.push(ItemsTemp);
        })
        this.jzDataCommonly = jzDataCommonlyTemp;
 
        this.tableIsLodingCommonly = false;
    }
    SelectedFnCommonlyData = [];
    // 选中一般折扣产品
    SelectedFnCommonly(event) {
        let arr = event.detail.rows;
        var newArr = [];
        arr.forEach(item => {
            var TempObject = {
                ...{},
                ...item
            };
            TempObject.JxsType = "一般折扣";
            newArr.push(TempObject);
        })
        this.SelectedFnCommonlyData = newArr;
    }
    SaveLb = '';
    SaveZk = '';
    //获取一般折扣弹出框产品类别
    handleChangeLb(event) {
        this.SaveLb = event.target.value;
    }
    //获取一般折扣弹出框使用折扣
    handleChangeZk(event) {
        if (event.target.value != '') {
            event.target.value = parseFloat(event.target.value) + "%";
        }
        this.SaveZk = event.target.value;
 
    }
    //一般错误提示
    errorTiShiYi(str){
        this.ShowCommonlyIsError = true;
        this.ShowCommonlyError = str;
    }
    //点击一般折扣弹出框确定按钮触发
    PromotionNoTemp = 1001;
    ShowCommonlyError = "请选择一般产品!";
    ShowCommonlyIsError = false;
    cancelSaveCommonly() {
        //处理数据
        var arr = this.SelectedFnCommonlyData;
        this.ShowCommonlyIsError = false;
        if (this.SelectedFnCommonlyData.length != 0) {
            var ItempTempData = {};
            ItempTempData.Id = GetUUID();
            ItempTempData.CompareId = GetUUID();
            ItempTempData.Name = '一般折扣';
            ItempTempData.JxsType = "一般折扣";
            ItempTempData.itemss = arr;
            if (this.SaveLb == '' || this.SaveZk == '') {
                if (this.SaveLb == '' && this.SaveZk != '') {
                    this.errorTiShiYi("请选择产品类别!");
                } else if (this.SaveZk == '' && this.SaveLb != '') {
                    this.errorTiShiYi("请输入使用折扣!");
                } else if (this.SaveZk == '' && this.SaveLb == '') {
                    this.errorTiShiYi("请输入使用折扣和产品类别!");
                }
            } else {
                ItempTempData.Category__c = this.SaveLb;
                ItempTempData.NormalDiscount__c_Input = this.SaveZk;
                ItempTempData.if_Contain_Nod__c = false;
                var TempList = [];
                TempList.push(ItempTempData);
                //将产品与方案匹配
                this.UpdateDiscountData(TempList);
                //折扣政策匹配规则
                this.SpecialSavesChange("一般折扣", ItempTempData, ItempTempData.Id, ItempTempData.CompareId);
                //关闭一般折扣弹出框触发
                this.cancelCommonly();
                this.Alert("一般折扣选择完成", false, true);
                setTimeout(() => {
                    this.CloseAlert();
                }, 2000);
                this.ConsolidatedDiscountPolicy(this.jzDataDiscount);
                //计算折扣政策价格
                // this.ComputeData(ItempTempData.Id, '折扣政策');
                this.ComputeDiscount(ItempTempData.Id, ItempTempData.NormalDiscount__c_Input, ItempTempData.GuaranteeDiscount__c, ItempTempData.Category__c, ItempTempData.JxsType);
            }
        } else {
            this.errorTiShiYi("请选择一般产品!");
        }
    }
    // ============================END =======================
 
    // ===================== 产品明细  =============================
    @track jzDataProduct = [];
    @track tableIsLodingProduct = true;
 
    @track
    initDataTableProduct = initDataTableProduct2;
    // 后台交互,获取列表数据
    getTableDataProduct(event) {
        this.tableIsLodingProduct = false;
    }
    @track SelectedFnProductData = [];
    //选中产品明细
    SelectedFnProduct(event) {
        let arr = event.detail.rows;
        this.SelectedFnProductData = arr;
    }
    //todu5
    jzshows = true;
    //加载
    IsLoading = false;
    OnLoading(flag) {
        this.IsLoading = flag;
    }
    //删除产品明细
    delectTableProduct() {
        this.DeleteIsChangesFnSingle(this.SelectedFnProductData);
    }
    ifTips=true;
    ifFTip=true;
    //保存所有报价试算界面数据
    saveAllDataProductFn() {
        var newTemp = [];
        this.jzDataFixedPrice.forEach(item => { //价格政策
            var itemTemp = {
                ...{},
                ...item
            };
            // itemTemp.分类名称(根据 两个折扣数据分类  1) 价格政策 2)折扣政策)
            itemTemp.typess = "价格政策 ";
            newTemp.push(itemTemp);
        });
        var newTemp2 = [];
        this.jzDataDiscount.forEach(item => { //折扣政策
            var itemTemp = {
                ...{},
                ...item
            };
            // itemTemp.分类名称(根据 两个折扣数据分类  1) 价格政策 2)折扣政策)
            itemTemp.typess = "折扣政策";
            newTemp2.push(itemTemp);
        });
        var data = [...newTemp, ...newTemp2];
        var ParamIdStr = this.ParamIdStr;
        var Trade__c = this.QuoteData[0].Opportunity.Trade__c;
        var NewData = ConsolidationScheme(data, ParamIdStr, Trade__c);
        var NewData1 = MergeProducts(this.jzDataProduct, this.jzDataDefault, data, ParamIdStr);
        var jsondatasss = JSON.stringify(NewData);
        var jsondatassss = JSON.stringify(NewData1);
        var Sales_Root__c = this.QuoteData[0].Opportunity.Sales_Root__c;
        var QuoteId = this.QuoteData[0].Id;
        var OpportunityId = this.QuoteData[0].OpportunityId;
        if (this.jzDataDefault.length == 0) {
            var ifnull = true;
            var ifnunum=1;
            newTemp.forEach(ntp => { //价格政策
                if (ntp.HeTongTotal == undefined || ntp.HeTongTotal == 0) {
                    ifnull = false;
                }
            });
            this.jzDataProduct.forEach(jzdp=>{
                if(jzdp.AgencyUnitPrice__c<0){
                    ifnunum=2;
                    return;
                }
            });
            debugger;
            if (ifnull&&ifnunum==1) {
                this.IsLoading=true;
                saveAllDataProduct({
                    JsonStr: jsondatasss,
                    ParamIdStr: this.ParamIdStr,
                    JsonStr2: jsondatassss,
                    QuoteId: QuoteId,
                    SalesRootc: Sales_Root__c,
                    ContractPrice: this.ContractPrice,
                    OpportunityId: OpportunityId,
                    DealerFinalPriceFc: this.QuoteData[0].Dealer_Final_Price_F__c,
                    Agent1Agent2Pricec: this.QuoteData[0].Agent1_Agent2_Price__c
                    
                }).then(result => {
                    if(this.ifTips){
                        this.IsLoading=false;
                        this.Alert("数据已保存", false, true);
                        setTimeout(() => {
                            this.CloseAlert();
                        }, 2000);
                    }
                    // SWAG-C9X7S3 20211224 ssm start
                    else {
                        this.jumpNewQuoteEntry();
                    }
                    // SWAG-C9X7S3 20211224 ssm end
                });
            } else {
                if(ifnunum==2){
                    this.ifFTip=false;
                    this.Alert("产品明细中金额有负数,不可保存", true, true);
                }else{
                    this.ifFTip=false;
                    this.Alert("一般产品的合同价格为空,不可保存", true, true);
                }
            }
        } else {
            this.ifFTip=false;
            this.Alert("产品未选完,不可保存", true, true);
        }
 
    }
 
    // ===================== 产品明细  =============================
    //成功提示
    SaveShowText = '促销方案选择完成';
    //折扣政策合同价格汇总
    HeTongPriceCompute() {
        var HeTongPriceList = [];
        var jzdateList=this.jzDataDiscount;//折扣政策
        var jzDataProductList=this.jzDataProduct;//产品明细
        HeTongPriceList=HeTongPriceComputeLogic(jzdateList,jzDataProductList);
        if (HeTongPriceList.length > 0) {
            this.jzDataDiscount = HeTongPriceList;
        }
    }
    //合同价格汇总
    ContractPrice = 0;
    ContractPriceCompute() {
        this.HeTongPriceCompute();
        this.ContractPrice = 0;
        var sum = this.ContractPrice;
        var jzDataProductList = this.jzDataProduct//产品明细
        var jzDataDiscountList = this.jzDataDiscount//折扣政策
        var jzDataFixedPriceList = this.jzDataFixedPrice//价格政策
        sum = parseFloat(sum);
        sum=ContractPriceComputeLogic(sum,jzDataProductList,jzDataDiscountList,jzDataFixedPriceList);
        this.ContractPrice = sum;
    }
    //更改一般折扣合同价格计算合同总价
    GeneralDiscountContractSummary(){
        this.ContractPrice = 0;
        var sum = this.ContractPrice;
        sum = parseFloat(sum);
        var jzDataDiscountList = this.jzDataDiscount;//折扣政策
        var jzDataFixedPriceList = this.jzDataFixedPrice;//价格政策
        sum=GeneralDiscountContractSummaryLogic(sum,jzDataDiscountList,jzDataFixedPriceList);
        this.ContractPrice = sum;
    }
    //删除时需要用的唯一id的添加
    updateIdStr(str) { //方案的识别字符串
        // TODU
        var newArr = [];
        var indexNum = 0;
        var jzdpdc = [];
        if (str == "1") {
            jzdpdc = [...[], ...this.jzDataProduct]; //促销产品
        } else if (str == "2") {
            jzdpdc = [...[], ...this.jzDataDiscount]; //折扣政策
        } else if (str == "3") {
            jzdpdc = [...[], ...this.jzDataFixedPrice]; //价格政策
        }
        jzdpdc.forEach(item => {
            indexNum++;
            var temp = {
                ...item
            };
            temp.DelectId = indexNum;
            newArr.push(temp);
        })
        if (str == "1") {
            this.jzDataProduct = [...[], ...newArr]; //促销产品
        } else if (str == "2") {
            this.jzDataDiscount = [...[], ...newArr]; //折扣政策
        } else if (str == "3") {
            this.jzDataFixedPrice = [...[], ...newArr]; //价格政策
        }
        //TODU
    }
    //返回不保存
    jumpNewQuoteEntry() {
        var DeveloperName = this.QuoteData[0].Opportunity.RecordType.DeveloperName;
        //路径跳转
        PathJump(DeveloperName,this.ParamIdStr);
    }
    //返回并保存
    jumpNewQuoteEntryAndSave(){
        this.ifTips=false;
        this.saveAllDataProductFn();
        // SWAG-C9X7S3 20211224 ssm start
        // if(this.ifFTip){
        //     this.jumpNewQuoteEntry();
        // }
        // SWAG-C9X7S3 20211224 ssm end
    }
    //复制
    copyJzDataTableProduct(){
        var QuoteId = this.QuoteData[0].Id;
        if (QuoteId == null || QuoteId == '') {
            alert(this.label.Please_Save_Quote);
            return null;
        }
        var records;
        var x;
        var targetString = '产品型号\t产品名称\t数量\t保修类型\t方案代码\t促销方案名称/产品系列\t主报价\t多年保价格小计\t折扣\t合同单价\t合同总价';
        try {
            SelectAllDataDiscount({
                ParamIdStr: this.ParamIdStr
            }).then(reslut=>{
                copyLogic(this.label.Check_Your_Clipboard,records,x,targetString,reslut);
            });
        } catch (e) {
            alert(e.faultcode + ',' + e.faultstring);
        }
    }
}