buli
2023-07-14 e6068da47c1bef5517c9e5fdc8c726766867ad4e
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
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
<apex:page controller="SelectAssetEstimateVMController" tabStyle="Maintenance_Contract_Estimate__c" lightningStylesheets="true" sidebar="false" showHeader="true" id="allPage" action="{!init}">
<head>
 <!-- <meta http-equiv="x-ua-compatible" content="ie=edge" /> -->
 <!-- <meta name="viewport" content="width=device-width, initial-scale=1" /> -->
 <!-- <apex:slds /> -->
</head>
    <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
    <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
    <apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
    <apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
<style type="text/css">
    table { border-collapse: collapse; }
    
    .container {
        overflow:auto;
        width:100%;
        height:304px;
    }
    .container2 {
        overflow:auto;
        width:100%;
        height:404px;
    }
    .btntable.dateFormat  {
        display: none;
    }
</style>
<script type="text/javascript">
//add by rentx 2020-11-17 start 失去焦点
function setFocusOnLoad() {}
function bodyOnLoad(){setFocusOnLoad();}
//add by rentx 2020-11-17 end 失去焦点
 
var oxygenPriceAdj = {!oxygenPriceAdj};
var approvalDate = '';
var Session_ID = '{!$Api.Session_ID}';
var Confirm_ChangedAfterPrint = '打印后行信息有变化,是否继续操作(报价编码会变新)?';
var isNewAddMonth = {!isNewAddMonth};
var Confirm_EstimateRefresh = '已超过创建日3个月,是否更新报价?';
window.sfdcPage.appendToOnloadQueue(function() { calonLoad() });
 
var RCbottonChanged = 0;
// 故障品
 
 
var hasSendEmail = {!hasSendEmail};
console.log('***hasSendEmail',hasSendEmail)// 故障品;
// if(hasSendEmail == true){
//     j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
//     j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
//     console.log('已提交RC 按钮不可见');
// }
 
function approvalJs() {
    approvalDate = new Date();
    var rowCnt = j$(escapeVfId('allPage:allForm:allBlock:assetSection:productCnt')).val();
    refreshAsset(rowCnt);
}
//故障品加费 RC 点击后不可见
function rcJs() {
    hasSendEmail = true;
    j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
    j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
    console.log('点击RC 按钮不可见hasSendEmail' +hasSendEmail);
}
//add by gwy 2021-01-27 start 提交时的提示框
function KindsAndMonths() {
   //   故障品加费 系统检查修理减价审批完成 Start
         ISReduced = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
        console.log('点击提交待审批时 是否审批通过='+ISReduced);
        if( ISReduced == '审批中' || ISReduced == '有八折以下待审批'){
            alert('请通过修理减价审批再提交');
            // approvalbtntop1.style.display = "none";
            return false;
        }
    
    //   故障品加费 系统检查修理减价审批完成 end
    var months      = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val());
    var contrNew    = document.getElementById("allPage:allForm:allBlock:contractInfo:Contract_TypeTXT").innerHTML;
    if(months>12 && months<60 && contrNew == '新品合同'){
        if(confirm("本次您提交的报价为多年期新品合同,请您在正式提交报价前先将经销商与医院签订的多年期合同邮件发送服务本部报价窗口。若已经提交请点击确定,继续保存提交。")){
            return true; 
        }else{
            return false;  
        }
    }
    // 先款后修-提交报价时如果是先款对象进行提示 thh 20220408 start
    var FirstParagraphEnd = j$(escapeVfId('allPage:allForm:allBlock:contract:FirstParagraphEnd'))[0].checked;
    if(FirstParagraphEnd){
        if (confirm('本次签约经销商是先款对象,请确认是否提交报价?')) {
            return true; 
        }else{
            return false;  
        }
    }
    // 先款后修-提交报价时如果是先款对象进行提示 thh 20220408 end
    return true;
}
//add by gwy 2021-01-27 end 提交时的提示框
 
 
 
 
 
function unblockUI(){
    // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk star
    // disable1();
    // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk end
    pageSetDisabled();
    var isChange = j$(escapeVfId('allPage:allForm:changedSubmitPrice')).value();
    if (isChange=='true') {
        j$(escapeVfId('allPage:allForm:changedSubmitPrice')).val('false');
        var rowCnt = j$(escapeVfId('allPage:allForm:allBlock:assetSection:productCnt')).val();
        refreshAsset(rowCnt);
    }
    j$("#sbArea").fadeOut(500, function(){
        j$("#sbArea").remove();
    });
  
    console.log('发送邮件成功');
   
}
//<!-- HWAG-B4R3SS  START 20181026-->
function clearAndSearch() {
    document.getElementById("allPage:allForm:allBlock:text1").value = "";
    document.getElementById("allPage:allForm:allBlock:cond1").value = "equals";
    document.getElementById("allPage:allForm:allBlock:val1").value = "";
    blockme();
    searchfunc();
}
function searchJs() {
    blockme();
    searchfunc();
}
//<!-- HWAG-B4R3SS  END 20181026-->
// 初始化设定画面项目不可用
function pageSetDisabled(){
    // if (RCbottonChanged == 0) {
    //     console.log('test初始化');
        // 故障品加费 提交RC按钮不可见 start
        // j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
        // j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
        // 故障品加费 提交RC按钮不可见 end
    // }
    // 故障品加费 start
    var hasSendEmail ={!hasSendEmail};
    console.log('page hasSendEmail',hasSendEmail);
    if(hasSendEmail == true){
        j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
        console.log('已提交RC 按钮不可见 page set');
    }
 
    //故障品加费 end
    var isDisabled = {!PageDisabled};
    // ResonCannotWarranty = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ResonCannotWarranty')).value();
    // if(!ResonCannotWarranty.contains("弃修")){
    //     j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto')).attr("display", none);
    // }
 
    if (isDisabled) {
 
        j$(escapeVfId('allPage:allForm:allBlock:contract:depart')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contract:estimateTarget')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contract:EndUserType')).attr("disabled", true);
        var rowCnt = {!productCount};
        for (var i = 0; i < rowCnt; i++) {
            // alert(11111111111111 +rowCnt);
            var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
            if (isManual == 'true') {
                var a = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Assert'));
                a.attr("disabled", true);
            }
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetCheck')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':comment')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Third_Party_Return__c')).attr("disabled", true);
        }
        j$(escapeVfId('allPage:allForm:allBlock:appendCondition:Examination_Count')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:disPercent')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:disMoney')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:discountReason')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:improveConsumptionRateIdea')).attr("disabled", true);
 
 
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:quotation_Amount')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:Appbackground:finalPriceDecideWay')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:Appbackground:Sales_incidental')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:Appbackground:mainTalksTime')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:Appbackground:talksStartDate')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:Appbackground:AgencyHos_Price')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:Appbackground:discountReason')).attr("disabled", true);
        j$(escapeVfId('allPage:allForm:allBlock:Appbackground:improveConsumptionRateIdea')).attr("disabled", true);
 
        j$(escapeVfId('allPage:allForm:contractstartdate')).attr("disabled", true);
        var target = j$(escapeVfId('allPage:allForm:allBlock:contract:estimateTarget')).val();
        if (target != '医院') {
            j$(escapeVfId('allPage:allForm:allBlock:contract:dealer')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:contract:FirstParagraphEnd')).attr("disabled", true);
        }
    }
    if ('{!DecideBtnDisabled}' == 'false') {
        j$(escapeVfId('allPage:allForm:contractstartdate')).attr("disabled", false);
    }
}
// 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk star
 
// function disable1(){
//     // alert(12312);
//     // addNewRows();
//     var isDisabled ;
//     var rowCnt = {!productCount}+{!productCount2};
//     if(isDisabled){
 
//         // alert(22222 + '444' +rowCnt);
//         for (var i = 0; i < rowCnt; i++) {
//             // 保有设备名
//             var assN = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:'+ i +':assetName')).text();
//             var assN1 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:'+ i +':Assert')).val();
//             // alert('1234567'+assN +'----'+assN1);
//             if(!assN1 && !assN){
//                 // alert('23456789'+assN);
//                 j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetCheck'   )).attr("disabled", true);
//             }else{
//                 j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetCheck'   )).attr("disabled", false);
//             }
//         }
//     }
// }
// 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk end
var winOpenObj;
function closeWin(flg) {
    winOpenObj.close();
    if (flg==2) {
        window.location.href="/{!URLENCODE(estimate.Id)}/e?completion=2"; 
    }
}
function controlDisabled() {
    winOpenObj = window.open("/apex/ChangeDealerApproval?eid=" + '{!URLENCODE(estimate.Id)}','ChangeDealerApproval','height=300,width=700,toolbar=no,menubar=no,left=20%,top=30%,scrollbars=yes,resizable=no,location=no,status=no');
}
// 見積もり作成後、3ヶ月以内であれば見積もりの内容を継続使用可能
function calonLoad() {
    // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk star
    // disable1();
    // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk end
    console.log('ApprovalBtnDisabled=='+{!ApprovalBtnDisabled});
    refreshAsset({!productCount});
    //上限合同 20230103 hql start
    // console.log('Limit_PriceHidden2=='+Limit_PriceHidden2);
    var RequestquotationAmount = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:quotation_Amount')).val();
    console.log('申请报价金额='+RequestquotationAmount);
    var AssetRepairSumPrice    = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPrice')).text();
    console.log('合同设备修理总额='+AssetRepairSumPrice);
    Limit_Price_Amount = (localParseFloat(AssetRepairSumPrice)+localParseFloat(RequestquotationAmount))*1.3;
    Limit_Price_Amount = Math.round(Limit_Price_Amount);
    // console.log('Limit_Price_Amount'+Limit_Price_Amount);
    Limit_Price_AmountOne =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).value();
    Limit_PriceHidden =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_PriceHidden')).value();
 
    if (Limit_PriceHidden*1==0) {
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).val(Limit_Price_Amount);
    }
    Limit_PriceHidden2 =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price2Hidden')).value();
    if (Limit_PriceHidden2 == 'false') {
        // lpa =  document.getElementById('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount');
        // lpa.style.display = "none";
        // console.log('隐藏完毕');
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).val('');
    }
    Price111 = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).val();
    // console.log('上限金额为'+Limit_Price_Amount);
    // console.log('原有上限金额为'+Limit_PriceHidden);
    // console.log('不是上限合同的金额为'+Price111);
    //上限合同 20230103 hql end
    pageSetDisabled();
    var createdDate = new Date('{!estimate.CreatedDate}');
    // 报价中设备的机身编码为空时的新品合同有效期延长 20200710 gzw
    var aLLManual = 'true';
    var cntWithKara = {!productCount};
 
    for (var i = 0; i < cntWithKara; i++) {
        var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
        if (isManual != 'true') {
            aLLManual = 'false';
            break;
        }
    }
    var nowDate = new Date();
    if (aLLManual == 'false') {
        createdDate = createdDate.setMonth(createdDate.getMonth() + 3);
        // FIX liang JSの時間って addMonthsないですか? そかも 1/1 なら、 4/1もだめですよ。
        if (createdDate < Date.parse(nowDate)) {
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:savebtntop')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:saveAndCancelBtn')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:approvalbtntop')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:savebtntop')).attr("class", 'btnDisabled');
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:saveAndCancelBtn')).attr("class", 'btnDisabled');
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:approvalbtntop')).attr("class", 'btnDisabled');
            j$(escapeVfId('allPage:allForm:savebtn')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:approvalbtn')).attr("disabled", true);
            // 最初は、Decideの同時に保存もあります、それを防ぐため、保存とDecideを同時に無効にする
            // 考えてみると、クラスにDecideの判断があり、Decideの時明細変更チェックもあります、3ヶ月のチェックもあります、ここで無効にする意味がありません
            //j$(escapeVfId('allPage:allForm:decidebtn')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:savebtn')).attr("class", 'btnDisabled');
            j$(escapeVfId('allPage:allForm:approvalbtn')).attr("class", 'btnDisabled');
 
            //故障品加费 RC按钮 
            j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
 
            //j$(escapeVfId('allPage:allForm:decidebtn')).attr("class", 'btnDisabled');
            
            if (confirm(Confirm_EstimateRefresh)) {
                window.location.href="/apex/SelectAssetEstimateVM?copyid={!URLENCODE(targetEstimateId)}"; 
                return true;
            } else {
                if ('{!DecideBtnDisabled}' == 'false') {
                    // decide可能の場合、別途decideのチェックが必要、
                    // チェック後再度画面refreshされるため、decide可能の場合、decideボタンが使えるようになります。
                    changeContractStartdate('{!estimate.Contract_Start_Date__c}');
                }
                return false;
            }
        }
    }else{
        createdDate = createdDate.setMonth(createdDate.getMonth() + 6);
        // FIX liang JSの時間って addMonthsないですか? そかも 1/1 なら、 4/1もだめですよ。
        if (createdDate < Date.parse(nowDate)) {
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:savebtntop')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:saveAndCancelBtn')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:approvalbtntop')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:savebtntop')).attr("class", 'btnDisabled');
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:saveAndCancelBtn')).attr("class", 'btnDisabled');
            j$(escapeVfId('allPage:allForm:allBlock:blocktop:approvalbtntop')).attr("class", 'btnDisabled');
            
            j$(escapeVfId('allPage:allForm:savebtn')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:approvalbtn')).attr("disabled", true);
            // 最初は、Decideの同時に保存もあります、それを防ぐため、保存とDecideを同時に無効にする
            // 考えてみると、クラスにDecideの判断があり、Decideの時明細変更チェックもあります、3ヶ月のチェックもあります、ここで無効にする意味がありません
            //j$(escapeVfId('allPage:allForm:decidebtn')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:savebtn')).attr("class", 'btnDisabled');
            j$(escapeVfId('allPage:allForm:approvalbtn')).attr("class", 'btnDisabled');
 
            //故障品加费RC按钮
            j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
            j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
            //j$(escapeVfId('allPage:allForm:decidebtn')).attr("class", 'btnDisabled');
            
            if (confirm('已超过创建日6个月,是否更新报价?')) {
                window.location.href="/apex/SelectAssetEstimateVM?copyid={!URLENCODE(targetEstimateId)}"; 
                return true;
            } else {
                if ('{!DecideBtnDisabled}' == 'false') {
                    // decide可能の場合、別途decideのチェックが必要、
                    // チェック後再度画面refreshされるため、decide可能の場合、decideボタンが使えるようになります。
                    changeContractStartdate('{!estimate.Contract_Start_Date__c}');
                }
                return false;
            }
        }
    }
    
    if ('{!DecideBtnDisabled}' == 'false') {
        console.log('oldMainteReal修改完成');
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:oldMainteReal')).val(j$(escapeVfId('allPage:allForm:allBlock:contractInfo:mainteReal')).text());
    }
}
 
function checkAll(checker) {
    var cnt = j$(escapeVfId('allPage:allForm:allBlock:assetSection:productCnt')).val();
    debugger;
    for (var i = 0; i < cnt; i++) {
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        if (j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetRowCheckbox')).size() == 0) {
            continue;
        }else{
            document.getElementById('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetRowCheckbox').checked = checker.checked;
        }
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
    }
}
 
function checkAll2(checker) {
    var cnt2 = j$(escapeVfId('allPage:allForm:allBlock:assetSection2:productCnt2')).val();
    var outer = 0;
    for (var i = 0; i < cnt2; i++) {
        outer = Math.floor(i / 1000);
        if (document.getElementById('allPage:allForm:allBlock:assetSection2:outassetTable2:' + outer +':assetTable2:' + (i-(1000*outer)) + ':assetRowCheckbox2').disabled == false) {
            document.getElementById('allPage:allForm:allBlock:assetSection2:outassetTable2:' + outer +':assetTable2:' + (i-(1000*outer)) + ':assetRowCheckbox2').checked = checker.checked;
        }
    }
}
 
function checkDiscount(val) {
    var alerts = 0;
    if (val == null || val == "") {
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:quotation_Amount')).val("");
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:discount_Rate')).text("");
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:discount_RateHidden')).val(0.00);
        return;
    }
    if (isNaN(parseInt(val))) {
        alert("请输入数值");
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:quotation_Amount')).val(0.00);
        return;
    }
    // 报价金额改善 20230314 start
    // var startime1 =  new Date(j$(escapeVfId('allPage:allForm:allBlock:contractInfo:PastContractendday')).value());
    // var startime2 = new Date(j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).value());
    // var result = (startime2-startime1)/(3600*24*1000);
    // Is_Blank_period1 =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Is_Blank_period')).value();
    // Cost_rate_ForecastF =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Cost_rate_ForecastF')).value();
    // downprice = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceDown')).value();
    // var renewTenOFF = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:renewTenOFF')).value();
    // if (Is_Blank_period1 == 'true' && ((parseFloat(Cost_rate_ForecastF)<100)||Cost_rate_ForecastF.length == 0) && result <=1 && downprice > val ) {
    //    alerts = 1;
    // }
    // if (alerts == 1 && renewTenOFF == 'false') {
    //     if (confirm("本单可以继续申请10%折扣,请确认是否申请,申请后合同开始日自动锁定为合同预定开始日,后续无法更改合同开始日")) {
    //         j$(escapeVfId('allPage:allForm:allBlock:contractInfo:renewTenOFF')).val(true);
    //         val = val*0.9;
    //         j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).attr("disabled", true);
    //     } else {
            
    //     }
    // }
    // 报价金额改善 20230314 end
    val = localParseFloat(val);
    //val = Math.round(val * 100) / 100;
    val = Math.round(val);
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:quotation_Amount')).val(toNumComma(val));
    //上限合同 20230117 HQL start
    var RequestquotationAmount = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:quotation_Amount')).val();
    console.log('申请报价金额='+RequestquotationAmount);
    var AssetRepairSumPrice    = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPrice')).text();
    console.log('合同设备修理总额='+AssetRepairSumPrice);
    Limit_Price_Amount = (localParseFloat(AssetRepairSumPrice)+localParseFloat(RequestquotationAmount))*1.3;
    Limit_Price_Amount = Math.round(Limit_Price_Amount);
    Limit_Price_AmountOne =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).value();
    Limit_PriceHidden =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_PriceHidden')).value();
    // if (Limit_PriceHidden*1==0) {
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).val(Limit_Price_Amount);
    // }
    Limit_PriceHidden2 =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price2Hidden')).value();
    if (Limit_PriceHidden2 == 'false') {
        // lpa =  document.getElementById('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount');
        // lpa.style.display = "none";
        // console.log('隐藏完毕');
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).val('');
    }
    amount = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).value();
    console.log('上限金额填入:'+amount);
    //上限合同 20230117 HQL end
   makeRealPrice(1);
}
 
function checkContractRange(val, cnt) {
    if (isNaN(parseInt(val))) {
        alert("必须输入合同月数!");
        j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val("");
        return;
    }
    if (val <= 0) {
        alert("合同月数必须大于0");
        j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val("");
        return;
    }
    if (val > 60) {
        alert("合同期最长只能选择60个月!");
        j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val("");
        return;
    }
    // HWAG-BA73ZP
    //contractStartDateChange();
    refreshAsset(cnt);
}
function toChange1(){
    tochange();
    ISReducedpriceapproval = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
    console.log('方法1是否审批通过=='+ISReducedpriceapproval+'====================');
}
function toChange2(){
    tochange2();
    ISReducedpriceapproval = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
    console.log('方法2是否审批通过=='+ISReducedpriceapproval+'==============');
}
var number1 = 0;
// function seamlessRenew(cnt){
//     // 报价规则改善 20230309 start 
//     var isSeamlessRenew = 0;
//     var isSeamlessRenew1 = 0;
//     var isSeamlessRenew3 = 0;
//     var isSeamlessRenew4 = 0;
//     // 报价规则改善 20230309 end
//     // 报价规则改善 20230310 start
//     var downPriceSum = 0;
//     var upPriceSum = 0;
//     var downPriceSum1 = 0;
//     var upPriceSum1 = 0;
//     var downPriceSum3 = 0;
//     var upPriceSum3 = 0;
//     var downPriceSum4 = 0;
//     var upPriceSum4 = 0;
//     // 报价规则改善 20230310 end
//     // 报价规则改善 20230310 start
//     var renewTenOFF = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:renewTenOFF')).value();
//     if (renewTenOFF == 'true') {
//         j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).attr("disabled", true);
//     }
//         document.getElementById("startdateaddsix1").value = addMonths(j$(escapeVfId('allPage:allForm:allBlock:contractInfo:PastContractendday')).value(),6);
//         document.getElementById("startdateaddsix2").value = addMonths(j$(escapeVfId('allPage:allForm:allBlock:contractInfo:PastContractendday')).value(),6);
//         document.getElementById("startdateaddsix3").value = addMonths(j$(escapeVfId('allPage:allForm:allBlock:contractInfo:PastContractendday')).value(),12);
//     // 报价规则改善 20230310 end
//     for (var i = 0; i < cnt; i++) {
//         // 报价规则改善 20230310 start
//         var  downPrice1 = 0;
//         var  upPrice1 = 0;
//         var  downPrice3 = 0;
//         var  upPrice3 = 0;
//         var  downPrice4 = 0;
//         var  upPrice4 = 0;
//          var Price_YearTXT = 0;
//         var LastMContract_Price = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContract_Price')).val());
//         var isnew = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetNewHidden')).val();
//         // 合同月数乗算
//         var month = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val());
//         if (month == undefined || month == "") {
//             month = 1;
//         }
//         var month2 = 0;
//         if (month > 12) {
//             month2 = month - 12;
//             month = 12;
//         }
//         var b = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contract_No')).value();
//         var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
//         if(b != ''){
//                     // var lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value());
//                     var lastContRange = 0;
//                     if(LastMContractRecord == 'VM_Contract'){
//                         // lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
//                         lastContRange = 36;
//                     }else{
//                         lastContRange = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':lastContRange')).value();
//                     }
//         }           
//         var Punish = calculateNtoMRatio( lastContRange,(month + month2));
//          // 报价规则改善 20230310 end
//         if (!isDisabled) {
//             var Adjustment_ratio_Lower = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Lower')).val());
//             var Adjustment_ratio_Upper = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Upper')).val());
//              strMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
//                 Price_YearTXT = strMoney * 12;
//                 if (isnew == 'true') {
//                     strMoney = month * strMoney + month2 * strMoney / {!isNewPriceAdj};
//                 } else {
//                     strMoney = month * strMoney + month2 * strMoney;
//                 }
//             // 服务合同报价规则改善 20230227 start
//                     var LastMContractID = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractID')).value();
//                     // var ISStandardPricing = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ISStandardPricing')).value();
//                     // 缺少首签设备逻辑
//                     if (LastMContractID == '') {
//                         console.log('新签设备');
//                         j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(strMoney));
//                         j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_priceHidden')).val(strMoney);
//                         j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(strMoney));
//                         j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val(strMoney);
//                     }
//             // 服务合同报价规则改善 20230227 end
//             var startdate11 = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:PastContractendday')).value();
//             var startdate1 = j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).value();
//             var startdate = new Date(startdate1);
//             var startdatesix1 = new Date(addMonths(startdate11,6));
//             startdatesix1.setDate(startdatesix1.getDate()-1);
//             var startdatesix2 = new Date(addMonths(startdate11,6));
//             startdatesix2.setDate(startdatesix2.getDate()+1);
//             var startdatesix3 = new Date(addMonths(startdate11,12));
//             startdatesix3.setDate(startdatesix3.getDate()+1);
//             // 第一个日期
//             var result1 = Blankperiod(startdate,i,LastMContract_Price,Punish,Adjustment_ratio_Upper,Adjustment_ratio_Lower,strMoney,1);
//             var arr=result1.split( '/');
//             downPrice=parseInt(arr[0]);
//             upPrice=parseInt(arr[1]);
//             isSeamlessRenew=isSeamlessRenew+parseInt(arr[2]);
//             // console.log('result1='+result1);
//             // 第二个日期
//             var result2 = Blankperiod(startdatesix1,i,LastMContract_Price,Punish,Adjustment_ratio_Upper,Adjustment_ratio_Lower,strMoney,2);
//             var arr2=result2.split( '/');
//             downPrice1=parseInt(arr2[0]);
//             upPrice1=parseInt(arr2[1]);
//             isSeamlessRenew1=isSeamlessRenew1+parseInt(arr2[2]);
//             // console.log('result2='+result2);
//             // 第三个日期
//             var result3 = Blankperiod(startdatesix2,i,LastMContract_Price,Punish,Adjustment_ratio_Upper,Adjustment_ratio_Lower,strMoney,2);
//             var arr3=result3.split( '/');
//             downPrice3=parseInt(arr3[0]);
//             upPrice3=parseInt(arr3[1]);
//             isSeamlessRenew3=isSeamlessRenew3+parseInt(arr3[2]);
//             // console.log('result3='+result3);
//             // 第四个日期
//             var result4 = Blankperiod(startdatesix3,i,LastMContract_Price,Punish,Adjustment_ratio_Upper,Adjustment_ratio_Lower,strMoney,2);
//             var arr4=result4.split( '/');
//             downPrice4=parseInt(arr4[0]);
//             upPrice4=parseInt(arr4[1]);
//             isSeamlessRenew4=isSeamlessRenew4+parseInt(arr4[2]);
//             // console.log('result4='+result4);
//             // 报价规则改善 20230308 end
//             // 报价规则改善 20230310 start
//             downPriceSum = downPriceSum + localParseFloat(toNum(downPrice));
//             upPriceSum =  upPriceSum + localParseFloat(toNum(upPrice));
//             downPriceSum1 = downPriceSum1 + localParseFloat(toNum(downPrice1));
//             upPriceSum1 =  upPriceSum1 + localParseFloat(toNum(upPrice1));
//             downPriceSum3 = downPriceSum3 + localParseFloat(toNum(downPrice3));
//             upPriceSum3=  upPriceSum3 + localParseFloat(toNum(upPrice3));
//             downPriceSum4 = downPriceSum4 + localParseFloat(toNum(downPrice4));
//             upPriceSum4=  upPriceSum4 + localParseFloat(toNum(upPrice4));
//             // 报价规则改善 20230310 end
//         }
//     }
//     // 报价规则改善 20230309 start
//     // console.log('isSeamlessRenew='+isSeamlessRenew);
//         if (isSeamlessRenew==0) {
//             j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Is_Blank_period')).val(true);
//         }else{
//             j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Is_Blank_period')).val(false);
//         }
//         var startime1 =  new Date(j$(escapeVfId('allPage:allForm:allBlock:contractInfo:PastContractendday')).value());
//         var startime2 = new Date(j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).value());
//         var result = (startime2-startime1)/(3600*24*1000);
//         Is_Blank_period1 =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Is_Blank_period')).value();
//         Cost_rate_ForecastF =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Cost_rate_ForecastF')).value();
//         // 5.当预测成本率为空时实绩连动价格是否享受9折优惠
//         if (isSeamlessRenew==0 && ((parseFloat(Cost_rate_ForecastF)<100)||Cost_rate_ForecastF.length == 0)) {
//             downPriceSum = downPriceSum*0.9;
//             upPriceSum = upPriceSum*0.9;
//         }
//         if (isSeamlessRenew1==0) {
//             downPriceSum1 = downPriceSum1*0.9;
//             upPriceSum1 = upPriceSum1*0.9;
//         }
//         if (isSeamlessRenew3==0) {
//             downPriceSum3 = downPriceSum3*0.9;
//             upPriceSum3 = upPriceSum3*0.9;
//         }
//         if (isSeamlessRenew4==0) {
//             downPriceSum4 = downPriceSum4*0.9;
//             upPriceSum4 = upPriceSum4*0.9;
//         }
//         if (!isDisabled) {
//         j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceUp')).text(toNumComma(Math.round(upPriceSum)));
//         j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceUpHidden')).val(toNum(Math.round(upPriceSum)));
//         j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceDown')).text(toNumComma(Math.round(downPriceSum)));
//         j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceDownHidden')).val(toNum(Math.round(downPriceSum)));
//         }
//         document.getElementById("GuidePriceDown5").value = toNumComma(Math.round(downPriceSum));
//         document.getElementById("GuidePriceUp5").value = toNumComma(Math.round(upPriceSum));
//         document.getElementById("GuidePriceDown4").value = toNumComma(Math.round(downPriceSum1));
//         document.getElementById("GuidePriceUp4").value = toNumComma(Math.round(upPriceSum1));
//         document.getElementById("GuidePriceDown3").value = toNumComma(Math.round(downPriceSum3));
//         document.getElementById("GuidePriceUp3").value = toNumComma(Math.round(upPriceSum3));
//         document.getElementById("GuidePriceDown2").value = toNumComma(Math.round(downPriceSum4));
//         document.getElementById("GuidePriceUp2").value = toNumComma(Math.round(upPriceSum4));
//     // 报价规则改善 20230309 end
// } 
function refreshAsset(cnt) {
    console.log('执行refreshAsset');
    console.log('decide==='+{!DecideBtnDisabled});
    
     // alert(cnt);
    // 提交后就页面不计算了
    var isDisabled = {!PageDisabled};
    // 合同总理
    var newCount = 0;
    var isresduce = 0;
    var oyearCount = 0;
    var firstCCount = 0;
    var conCCount = 0;
    // row金額合計
    var repairSum = 0;
    var listSum = 0;
    // 新品合同 判断
    var newCon = true;
    var contractStartDate = new Date(j$(escapeVfId('allPage:allForm:contractstartdate')).value());
    //多年保续签合同数量 thh 20220316 start
    var GuranteeCount = 0;
    //多年保续签合同数量 thh 20220316 end
 
 
 
    //2022故障品加费 获取userInfo简档名称 是否为FSE start
    var isFSE = {!isFSE};
    // var isFSE = true;
    console.log('***isFSE',isFSE);
    //2022故障品加费 获取userInfo简档名称 end
    //20230208 上限合同开发 hql start
    if (isFSE) {
        // lpa =  document.getElementById('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount');
        // lpa.style.display = "none";
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).attr("disabled", true);
        console.log('上限金额隐藏');
    }
    //20230208 上限合同开发 hql end
    // 预定开始日
    var startdate = new Date(j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).value());
    // 报价规则改善
    // document.getElementById("startdateaddsix4").value = j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).value();
    // 报价规则改善
    
    // 预定开始日-6个月
    startdate.setMonth(startdate.getMonth() - 6);
    // 申请日 当前日期
    if(approvalDate != ''){
        //申请日
        approvalDate = new Date(approvalDate.toLocaleDateString());
        if (Date.parse(approvalDate) < Date.parse(startdate)) {
            newCon = false;
        }
 
    }
 
    // 最高、最低价格合计
    var downPriceSum = 0;
    var upPriceSum = 0;
    // 合同月数乗算
    var month = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val());
    if (month == undefined || month == "") {
        month = 1;
    }
    var month2 = 0;
    if (month > 12) {
        month2 = month - 12;
        month = 12;
    }
    for (var i = 0; i < cnt; i++) {
        // console.log('第'+i+'个设备');
        var strMoney = 0;
        var repairMoney = 0;
        // 行项目 最高、最低价格合计
        // 续签价格取联动价格页面计算,首签或产品取 实际价格
        // 下线价格
        var downPrice = 0;
        // 上线价格
        var upPrice = 0; 
        // 12个月合同金额
        var Price_YearTXT = 0;
 
        var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
        var isnew = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetNewHidden')).val();
        var assetListmonth = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
 
        //市场多年保修价格开发 DC 2023/02/09 start 
        var VMassetListmonth = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Maintenance_Price_Year__c')).val();
        // console.log('***合同定价:'+VMassetListmonth);
        //市场多年保修价格开发 DC 2023/02/09 end 
 
        // console.log('***isManual=:'+isManual);
        if (isManual == 'true') {
            var a = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Assert')).value();
            if (a != '') {
                // 所有设备按安装日、发货日(最早的),距离合同开始日6个月内都是新品合同
                //var isNewDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':isNewDate')).value());
                //isNewDate.setMonth(isNewDate.getMonth() + 6);
                //if (Date.parse(contractStartDate) > Date.parse(isNewDate)) {
                //    newCon = false;
                //}
 
                strMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
 
                // alert(strMoney);
                Price_YearTXT = strMoney * 12;
                if (isnew == 'true') {
                    newCount ++;
                    strMoney = month * strMoney + month2 * strMoney / {!isNewPriceAdj};
 
                } else {
                    newCon = false;
                    strMoney = month * strMoney + month2 * strMoney;
 
                }
                var b = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contract_No')).value();
                var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
                console.log('***维修合同记录类型1'+LastMContractRecord);
                if(b != ''){
                    conCCount ++;
                    // 1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。)
 
                    // 2.一年以上的合同,在结束前6个月开始可以开放续签报价。
 
                    var lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value());
                    var lastContRange = 0;
                    if(LastMContractRecord == 'VM_Contract'){
                        newCount++;
                        //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start
                        GuranteeCount++;
                        newCon = false;
                        //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end
                        lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                        lastContRange = 36;
                    }else{
                        lastContRange = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':lastContRange')).value();
                    }
                    //最后结束日+1年
                    lastendDate.setMonth(lastendDate.getMonth() + 12);
                    if (Date.parse(contractStartDate) > Date.parse(lastendDate) ) {
                        oyearCount ++;
                    }
                    // 取联动价格
                    // 上一期合同实际报价月额
                    // 
                    var LastMContract_Price = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContract_Price')).val());
                    var Adjustment_ratio_Lower = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Lower')).val());
                    var Adjustment_ratio_Upper = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Upper')).val());
                    //计算惩罚率
                    var Punish = calculateNtoMRatio( lastContRange,(month + month2));
                    if(Punish == 0){
                        return;
                    }
                    // 判断有无报价:没有按照标准价格实际联动
                    var Estimate_Num = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Estimate_NumHidden')).val();
                    if(Estimate_Num == 0){
                        if(LastMContractRecord == 'VM_Contract'){
                            // gzw 20220630  实际联动6个月价格区分
                            var nowdate = new Date();
                            lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                            nowdate = nowdate.setMonth(nowdate.getMonth() + 6);
                            if(nowdate < Date.parse(lastendDate)){
                                upPrice = strMoney;
                                downPrice = strMoney * 0.8;
                            }else{
                                upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                                downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
 
                            //市场多年保修价格开发 DC 2023/1/30 start 
 
                            var Maxcoefficient =0;
                            var Mincoefficient =0;
 
                            var ContractMonth = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val());
 
                            var AssetRate = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew')).val());
                            // console.log('***消费率:'+AssetRate);
 
                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contractrate')).text(AssetRate +'%');
 
                            if(AssetRate>0 &&AssetRate<=0.5){
                                Maxcoefficient = (1-0.3);
                                Mincoefficient = (1-0.4);
                            }else if(AssetRate>0.5 &&AssetRate<=0.6){
                                Maxcoefficient = (1-0.2);
                                Mincoefficient = (1-0.3);
                                
                            }else if(AssetRate>0.6 &&AssetRate<=0.7){
                                Maxcoefficient = (1-0.15);
                                Mincoefficient = (1-0.25);
                                
                            }else if(AssetRate>0.7 &&AssetRate<=0.8){
                                Maxcoefficient = (1-0.1);
                                Mincoefficient = (1-0.2);
                                
                            }else if(AssetRate>0.8 &&AssetRate<=0.9){
                                Maxcoefficient = (1-0.05);
                                Mincoefficient = (1-0.15);
                                
                            }else if(AssetRate>0.9 &&AssetRate<=1.0){
                                Maxcoefficient = 1;
                                Mincoefficient = (1-0.05);
                                
                            }else if(AssetRate>1.0 &&AssetRate<=1.1){
                                Maxcoefficient = (1+0.05);
                                Mincoefficient = 1;
                                
                            }else if(AssetRate>1.1 &&AssetRate<=1.2){
                                Maxcoefficient = (1+0.1);
                                Mincoefficient = 1;
                                
                            }else if(AssetRate>1.2 &&AssetRate<=1.3){
                                Maxcoefficient = (1+0.2);
                                Mincoefficient = (1+0.1);
                                
                            }else if(AssetRate>1.3 &&AssetRate<=1.4){
                                Maxcoefficient = (1+0.25);
                                Mincoefficient = (1+0.15);
                                
                            }else if(AssetRate>1.4){
                                Maxcoefficient = (1+0.3);
                                Mincoefficient = (1+0.2);
                                
                            }
                            //市场多年保修价格开发 DC 2023/1/30 end 
                            // console.log('***最高系数'+Maxcoefficient);
                            // console.log('***最低系数'+Mincoefficient);
 
                        if(nowdate < Date.parse(lastendDate)){
                            //设备小于两年半
                            // upPrice = strMoney;
                            // downPrice = strMoney * 0.8;
                        // console.log('***小于2年半')
                        // 市场多年保修价格开发 start DC 2023/01/19  
                            //市场多年保设备小于2年半
                            var AssetModelNo = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_Model_No__c')).value();
                            var Category4 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Category4__c')).value();
                            // console.log('***设备型号'+AssetModelNo);
                            // console.log('***产品类型'+Category4);
 
                            //设备设备消费率小于1.4
                            if(AssetRate<1.4){
                                upPrice = VMassetListmonth * ContractMonth /12;
                                // console.log('消费率小于1.4 upPrice = 定价 *经历月数 /12'+ upPrice);
 
                                if(AssetModelNo.includes('290')&&( Category4 =='BF'|| Category4=='BF扇扫'||Category4=='CF')){
                                    downPrice = upPrice;
                                    // console.log('消费率小于1.4 产品无最低价 downPrice '+ downPrice);
 
                                }else{
                                    downPrice = upPrice * 0.8;
                                    // console.log('消费率小于1.4 产品最低价 downPrice = upPrice* 0.8:'+ downPrice);
 
                                }
                            }else{
                                upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                                downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;   
                                // console.log('消费率大于1.4 upPrice'+ upPrice);
                                // console.log('消费率大于1.4 downPrice'+ downPrice);
                            }
                            // 市场多年保修价格开发 end DC 2023/01/19  
                            }else{
                                // upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                                // downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
 
 
                                //市场多年保修价格开发 DC 2023/1/30 start  设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数
                               
                                upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                                downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;
 
                                // console.log('设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数 upPrice'+ upPrice);
                                // console.log('设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数 downPrice'+ downPrice);
                                //市场多年保修价格开发 DC 2023/1/30 end 
                            
 
                            }
                            // gzw 20220630  实际联动6个月价格区分
                        }else{
                            upPrice = strMoney;
                            downPrice = strMoney * 0.8;
                            console.log('选择1');
                        }
                    }else{
                        upPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100);
                        downPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100);
                        console.log('选择2');
                    }
                }else{
                    //firstCCount ++;
                    upPrice = strMoney;
                    downPrice = strMoney * 0.8;
                    console.log('选择3');
                }
                // 上下限四舍五入
                upPrice = upPrice.toFixed(2);
                downPrice = downPrice.toFixed(2);
                // 12个月合同金额
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXT')).text(toNumComma(Price_YearTXT));
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXTHidden')).val(Price_YearTXT);
                if (!isDisabled) {
                    // 实际联动价格 start
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(downPrice));
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_priceHidden')).val(downPrice);
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice));
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val(upPrice);
                    // 实际联动价格 end
                }
                
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPrice')).text(toNumComma(strMoney));
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPricePageHidden')).val(strMoney);
                
                repairMoney = j$.trim(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value());
            } else {
                // TODO 一時的な対応、なんで別行の金額リフレッシュされた?
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPrice')).text("");
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPricePageHidden')).val();
 
                // 12个月合同金额
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXT')).text("");
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXTHidden')).val();
                if (!isDisabled) {
                    // 实际联动价格 start
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text("");
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_priceHidden')).val();
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text("");
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val();
                    // 实际联动价格 end
                 }
            }
        }
        else {
            // 所有设备按安装日、发货日(最早的),距离合同开始日6个月内都是新品合同
            var isNewDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':isNewDate')).value());
            isNewDate.setMonth(isNewDate.getMonth() + 6);
            if (Date.parse(contractStartDate) > Date.parse(isNewDate)) {
                newCon = false;
            }
            strMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
 
            Price_YearTXT = strMoney * 12;
            if (isnew == 'true') {
                strMoney = month * strMoney + month2 * strMoney / {!isNewPriceAdj};
 
            } else {
                strMoney = month * strMoney + month2 * strMoney;
            }
 
            var b = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contract_No')).value(); 
            var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
            // console.log('***维修合同记录类型2'+LastMContractRecord);
 
            if(b != ''){
                conCCount ++;
                // 1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。)
 
                // 2.一年以上的合同,在结束前6个月开始可以开放续签报价。
                var lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value());
                var lastContRange = 0;
                if(LastMContractRecord == 'VM_Contract'){
                    newCount++;
                    //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start
                    GuranteeCount++;
                    newCon = false;
                    //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end
                    lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                    lastContRange = 36;
                }else{
                    lastContRange = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':lastContRange')).value();
                }
                //最后结束日+1年
                lastendDate.setMonth(lastendDate.getMonth() + 12);
                // alert('+++++++++--------' + lastendDate);
                // alert('+++++++++--------' + Date.parse(contractStartDate) + '77777' + Date.parse(lastendDate));
                if (Date.parse(contractStartDate) > Date.parse(lastendDate)) {
                    oyearCount ++;
                }
                // 取联动价格
                // 上一期合同实际报价月额
                // 
                var LastMContract_Price = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContract_Price')).val());
                var Adjustment_ratio_Lower = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Lower')).val());
                var Adjustment_ratio_Upper = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Upper')).val());
                //计算惩罚率
                var Punish = calculateNtoMRatio( lastContRange,(month + month2));
                if(Punish == 0){
                    return;
                }
                // 判断有无报价:没有按照标准价格实际联动
                var Estimate_Num = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Estimate_NumHidden')).val();
                if(Estimate_Num == 0){
                    if(LastMContractRecord == 'VM_Contract'){
                        // alert('11111');
                        // gzw 20220630  实际联动6个月价格区分
                        var nowdate = new Date();
                        lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                        nowdate = nowdate.setMonth(nowdate.getMonth() + 6);
                        // console.log('**结束日',lastendDate);
                        //市场多年保修价格开发 DC 2023/1/30 start 
 
                            var Maxcoefficient =0;
                            var Mincoefficient =0;
 
                            var ContractMonth = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val());
                            // console.log('***经历月数'+ContractMonth);
                            var AssetRate = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew')).val());
                            // console.log('***消费率:'+AssetRate);
 
                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contractrate')).text(AssetRate +'%');
 
                            if(AssetRate>0 &&AssetRate<=0.5){
                                Maxcoefficient = (1-0.3);
                                Mincoefficient = (1-0.4);
                            }else if(AssetRate>0.5 &&AssetRate<=0.6){
                                Maxcoefficient = (1-0.2);
                                Mincoefficient = (1-0.3);
                                
                            }else if(AssetRate>0.6 &&AssetRate<=0.7){
                                Maxcoefficient = (1-0.15);
                                Mincoefficient = (1-0.25);
                                
                            }else if(AssetRate>0.7 &&AssetRate<=0.8){
                                Maxcoefficient = (1-0.1);
                                Mincoefficient = (1-0.2);
                                
                            }else if(AssetRate>0.8 &&AssetRate<=0.9){
                                Maxcoefficient = (1-0.05);
                                Mincoefficient = (1-0.15);
                                
                            }else if(AssetRate>0.9 &&AssetRate<=1.0){
                                Maxcoefficient = 1;
                                Mincoefficient = (1-0.05);
                                
                            }else if(AssetRate>1.0 &&AssetRate<=1.1){
                                Maxcoefficient = (1+0.05);
                                Mincoefficient = 1;
                                
                            }else if(AssetRate>1.1 &&AssetRate<=1.2){
                                Maxcoefficient = (1+0.1);
                                Mincoefficient = 1;
                                
                            }else if(AssetRate>1.2 &&AssetRate<=1.3){
                                Maxcoefficient = (1+0.2);
                                Mincoefficient = (1+0.1);
                                
                            }else if(AssetRate>1.3 &&AssetRate<=1.4){
                                Maxcoefficient = (1+0.25);
                                Mincoefficient = (1+0.15);
                                
                            }else if(AssetRate>1.4){
                                Maxcoefficient = (1+0.3);
                                Mincoefficient = (1+0.2);
                                
                            }
                            //市场多年保修价格开发 DC 2023/1/30 end 
                            // console.log('***最高系数'+Maxcoefficient);
                            // console.log('***最低系数'+Mincoefficient);
 
                        if(nowdate < Date.parse(lastendDate)){
                            upPrice = strMoney;
                            downPrice = strMoney * 0.8;
                        }else{
                            upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                            downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                        //     //设备小于两年半
                        //     // upPrice = strMoney;
                        //     // downPrice = strMoney * 0.8;
                            
                        // 市场多年保修价格开发 start DC 2023/01/19  
                            //市场多年保设备小于2年半
                            var AssetModelNo = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_Model_No__c')).value();
                            var Category4 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Category4__c')).value();
                            // console.log('***设备型号'+AssetModelNo);
                            // console.log('***产品类型'+Category4);
 
                            //设备设备消费率小于1.4
                            if(AssetRate<1.4){
                                upPrice = VMassetListmonth *ContractMonth / 12;
                                // console.log('消费率小于1.4 upPrice = VMassetListmonth *month /12'+ upPrice);
 
                                if(AssetModelNo.includes('290')&&( Category4 =='BF'|| Category4=='BF扇扫'||Category4=='CF')){
                                    downPrice = upPrice;
                                    // console.log('消费率小于1.4 产品无最低价 downPrice '+ downPrice);
 
                                }else{
                                    downPrice = upPrice * 0.8;
                                    // console.log('消费率小于1.4 产品最低价 downPrice = upPrice* 0.8:'+ downPrice);
 
                                }
                            }else{
                                upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                                downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;   
                                // console.log('消费率大于1.4 upPrice'+ upPrice);
                                // console.log('消费率大于1.4 downPrice'+ downPrice);
                            }
                        // 市场多年保修价格开发 end DC 2023/01/19      
 
                        }else{
                            //设备大于两年半
                            // upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                            // downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
 
                            //市场多年保修价格开发 DC 2023/1/30 start  设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数
                            upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                            downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;
 
                            // console.log('设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数 upPrice'+ upPrice);
                            // console.log('设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数 downPrice'+ downPrice);
                            //市场多年保修价格开发 DC 2023/1/30 end 
                        }
                        // gzw 20220630  实际联动6个月价格区分
                    }else{
                        upPrice = strMoney;
                        downPrice = strMoney * 0.8;
                        console.log('选择4');
                    }
                }else{
                    upPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100);
                    downPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100);
                    console.log('选择5');
                }
            }else{
                if (isnew == 'true') {
                    newCount ++;
                } else {
                    newCon = false;
                    firstCCount ++;
                }
                upPrice = strMoney;
                downPrice = strMoney * 0.8;
            }
            // 上下限四舍五入
            upPrice = upPrice.toFixed(2);
            downPrice = downPrice.toFixed(2);
            // 12个月合同金额
            //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXT')).text(toNumComma(Price_YearTXT));
            //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXTHidden')).val(Price_YearTXT);
            if (!isDisabled) {
                
                // else{
                // 实际联动价格 start
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(downPrice));
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_priceHidden')).val(downPrice);
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice));
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val(upPrice);
                // 实际联动价格 end
                // }
            }
            //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPrice')).text(toNumComma(strMoney));
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPricePageHidden')).val(strMoney);
            
 
            //<!-- (2022年12月上线)故障品加费 start -->  
            Repair_Price_AutoPrice = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto'));
            Repair_Price_Auto = Repair_Price_AutoPrice.value();
            repairMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value();
            Repair_Price_pass = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_pass')).val();
            // console.log((i+1)+'号repairMoney='+repairMoney);
            // console.log((i+1)+'号Repair_Price_Auto='+Repair_Price_Auto);
            if ((repairMoney+1)==1) {
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).val(Repair_Price_Auto);
                // console.log('repairMoney修改成功');
            }
            if ((Repair_Price_pass+1)==1) {
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_pass')).val(Repair_Price_Auto);
                // console.log('Repair_Price_pass修改成功');
            }
            repairMoney1 = localParseFloat(repairMoney);
            ISReducedpriceapproval = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
            // console.log('ISReducedpriceapproval=='+ISReducedpriceapproval);
            var isDisabled = {!PageDisabled};
            if (ISReducedpriceapproval =='有八折以下待审批' || ISReducedpriceapproval =='是'|| isDisabled) {
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).attr("disabled", true);
            }else{
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).attr("disabled", false);
            }
            ISReducedpriceapproval1 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ISReducedpriceapproval1')).val();
            ISReduced = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
            if (repairMoney1> 0 && (repairMoney1 <Repair_Price_Auto*0.80)) {
                
                isresduce = isresduce+1;
            }
          
            // console.log('初始化isresduce='+isresduce);
            rppa =  document.getElementById('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto');
            ResonCannotWarranty = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ResonCannotWarranty')).value();
            // console.log('不可参保原因为:'+ResonCannotWarranty);
            // console.log('repairMoney执行次数为'+repairMoney);
            if(!(ResonCannotWarranty.indexOf("弃修") != -1)&&(repairMoney+1)==1){
                // if (!(situation.indexOf("修理中")!=-1)&& !(Agreed_Date.indexOf("为空")!=-1)) { 
                    rppa.style.display = "none";
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).val('');
                    // console.log('###修改成功');
                // }
            }
            
            
            situation = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_situation')).value();
            // Agreed_Date =  j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Agreed_Date')).value();
 
            // console.log('situation='+situation);
            // console.log('Agreed_Date1='+Agreed_Date);
            
            // console.log('判断'+(Agreed_Date.indexOf("不为空")!=-1));
            // if ((situation.indexOf("修理中")!=-1)&& (Agreed_Date.indexOf("不为空")!=-1)) {
            //     console.log('开始操作2');
            //     j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto')).val(0);
            //     j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).val(0);
            // }
        //<!-- (2022年12月上线)故障品加费 end -->
        }
        
        repairSum = repairSum + localParseFloat(repairMoney);
        listSum = listSum + localParseFloat(toNum(strMoney));
        downPriceSum = downPriceSum + localParseFloat(toNum(downPrice));
        upPriceSum =  upPriceSum + localParseFloat(toNum(upPrice));
        
    }
    
   
    j$(escapeVfId('allPage:allForm:allBlock:assetRepairSumNum')).text(toNumComma(repairSum));
    //j$(escapeVfId('allPage:allForm:allBlock:assetListSumNum')).text(toNumComma(listSum));
    
    //j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetSumPrice')).text(toNumComma(listSum));
    //j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetSumPriceHidden')).val(toNum(listSum));
 
    if (!isDisabled) {
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceUp')).text(toNumComma(Math.round(upPriceSum)));
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceUpHidden')).val(toNum(Math.round(upPriceSum)));
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceDown')).text(toNumComma(Math.round(downPriceSum)));
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceDownHidden')).val(toNum(Math.round(downPriceSum)));
    }
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPrice')).text(toNumComma(repairSum));
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPriceHidden')).val(toNum(repairSum));
 
    var allcount = j$(escapeVfId('allPage:allForm:allBlock:productCount3')).value();
    var result = '';
    if (allcount == 0) {
        result = null;
    //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 start
    }else if(GuranteeCount > 0 && GuranteeCount == allcount){
        result = '市场多年保续签合同';
    //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 end
    }else if (newCount > 0 && newCount == allcount && newCon == true) {
        result = '新品合同';
    }else if (((newCount > 0 && newCount == allcount) ||(newCount + firstCCount == allcount)) && newCon == false) {
        result = '首签合同';
    }else if(firstCCount > 0 && firstCCount == allcount){
        result = '首签合同';
    // 20220328 ljh update  LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start
    // }else if(oyearCount > 0 && oyearCount == conCCount){
    }else if(oyearCount > 0 && oyearCount == conCCount && allcount == oyearCount ){
    // 20220328 ljh update  LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start
        result = '非续签合同(空白期一年以上)';
    }else{
        result = '续签合同';
    }
    // console.log(result);
    document.getElementById("allPage:allForm:allBlock:contractInfo:Contract_TypeTXT").innerHTML = result;
    document.getElementById("allPage:allForm:allBlock:contractInfo:Contract_TypeTXTHidden").value = result;
    // 取消酸化水
    //NotUseOxygenatedWaterAmount(1);
    examinationPriceCal(cnt);
    getLastContractRate();
    // 报价规则改善 20230315 start
    // seamlessRenew(cnt);
    // 报价规则改善 20230315 end
    number1++;
 
}
function changeAsset(cnt) {
    console.log('执行了changeAsset');
    // alert(cnt);
    // 提交后就页面不计算了
    var isDisabled = {!PageDisabled};
    // 合同总理
    var newCount = 0;
    var isresduce = 0;
    var oyearCount = 0;
    var firstCCount = 0;
    var conCCount = 0;
    // row金額合計
    var repairSum = 0;
    var listSum = 0;
    // 新品合同 判断
    var newCon = true;
    var contractStartDate = new Date(j$(escapeVfId('allPage:allForm:contractstartdate')).value());
 
    //多年保续签合同数量 thh 20220316 start
    var GuranteeCount = 0;
    //多年保续签合同数量 thh 20220316 end
 
    //2022故障品加费 获取userInfo简档名称 是否为FSE start
    var isFSE = {!isFSE};
    // var hasSendEmail = {!hasSendEmail};
 
    // var isFSE = true;
    console.log('***isFSE',isFSE);
    // console.log('***hasSendEmail',hasSendEmail);
    // if(hasSendEmail == true){
    //     j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", true);
    //     j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btnDisabled');
    //     console.log('8折以下提交RC可见 ');
    // }
                 
 
    //2022故障品加费 获取userInfo简档名称 end
 
    // 预定开始日
    var startdate = new Date(j$(escapeVfId('allPage:allForm:allBlock:contract:startdate')).value());
    // 预定开始日-6个月
    startdate.setMonth(startdate.getMonth() - 6);
    // 申请日 当前日期
    if(approvalDate != ''){
        //申请日
        approvalDate = new Date(approvalDate.toLocaleDateString());
        if (Date.parse(approvalDate) < Date.parse(startdate)) {
            newCon = false;
        }
 
    }
 
    // 最高、最低价格合计
    var downPriceSum = 0;
    var upPriceSum = 0;
    // 合同月数乗算
    var month = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val());
    if (month == undefined || month == "") {
        month = 1;
    }
    var month2 = 0;
    if (month > 12) {
        month2 = month - 12;
        month = 12;
    }
    for (var i = 0; i < cnt; i++) {
        var strMoney = 0;
        var repairMoney = 0;
        // 行项目 最高、最低价格合计
        // 续签价格取联动价格页面计算,首签或产品取 实际价格
        // 下线价格
        var downPrice = 0;
        // 上线价格
        var upPrice = 0;
        
        // 12个月合同金额
        var Price_YearTXT = 0;
        
        var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
        var isnew = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetNewHidden')).val();
        var assetListmonth = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
        //市场多年保修价格开发 DC 2023/02/09 start 
        var VMassetListmonth = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Maintenance_Price_Year__c')).val();
        //市场多年保修价格开发 DC 2023/02/09 end 
 
        if (isManual == 'true') {
            var a = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Assert')).value();
            if (a != '') {
                // 所有设备按安装日、发货日(最早的),距离合同开始日6个月内都是新品合同
                //var isNewDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':isNewDate')).value());
                //isNewDate.setMonth(isNewDate.getMonth() + 6);
                //if (Date.parse(contractStartDate) > Date.parse(isNewDate)) {
                //    newCon = false;
                //}
 
                strMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
 
                var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
                // alert(strMoney);
                console.log('***维修合同记录类型3'+LastMContractRecord);
 
                Price_YearTXT = strMoney * 12;
                if (isnew == 'true') {
                    newCount ++;
                    strMoney = month * strMoney + month2 * strMoney / {!isNewPriceAdj};
 
                } else {
                    newCon = false;
                    strMoney = month * strMoney + month2 * strMoney;
                }
                var b = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contract_No')).value();
                // var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
                if(b != ''){
                    conCCount ++;
                    // 1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。)
 
                    // 2.一年以上的合同,在结束前6个月开始可以开放续签报价。
 
                    var lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value());
                    var lastContRange = 0;
                    if(LastMContractRecord == 'VM_Contract'){
                        newCount++;
                        //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start
                        GuranteeCount++;
                        newCon = false;
                        //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end
                        lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                        lastContRange = 36;
                    }else{
                        lastContRange = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':lastContRange')).value();
                    }
                    //最后结束日+1年
                    lastendDate.setMonth(lastendDate.getMonth() + 12);
                    if (Date.parse(contractStartDate) > Date.parse(lastendDate) ) {
                        oyearCount ++;
                    }
                    // 取联动价格
                    // 上一期合同实际报价月额
                    // 
                    var LastMContract_Price = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContract_Price')).val());
                    var Adjustment_ratio_Lower = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Lower')).val());
                    var Adjustment_ratio_Upper = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Upper')).val());
                    //计算惩罚率
                    var Punish = calculateNtoMRatio( lastContRange,(month + month2));
                    if(Punish == 0){
                        return;
                    }
                    // 判断有无报价:没有按照标准价格实际联动
                    var Estimate_Num = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Estimate_NumHidden')).val();
                    if(Estimate_Num == 0){
                        if(LastMContractRecord == 'VM_Contract'){
                            // gzw 20220630  实际联动6个月价格区分
                            var nowdate = new Date();
                            lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                            nowdate = nowdate.setMonth(nowdate.getMonth() + 6);
 
                            //市场多年保修价格开发 DC 2023/1/30 start 
                            var Maxcoefficient =0;
                            var Mincoefficient =0;
 
                            var AssetRate = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew')).val());
                            console.log('***消费率:'+AssetRate);
 
                            var ContractMonth = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val());
 
                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contractrate')).text(AssetRate +'%');
 
                            if(AssetRate>0 &&AssetRate<=0.5){
                                Maxcoefficient = (1-0.3);
                                Mincoefficient = (1-0.4);
                            }else if(AssetRate>0.5 &&AssetRate<=0.6){
                                Maxcoefficient = (1-0.2);
                                Mincoefficient = (1-0.3);
                                
                            }else if(AssetRate>0.6 &&AssetRate<=0.7){
                                Maxcoefficient = (1-0.15);
                                Mincoefficient = (1-0.25);
                                
                            }else if(AssetRate>0.7 &&AssetRate<=0.8){
                                Maxcoefficient = (1-0.1);
                                Mincoefficient = (1-0.2);
                                
                            }else if(AssetRate>0.8 &&AssetRate<=0.9){
                                Maxcoefficient = (1-0.05);
                                Mincoefficient = (1-0.15);
                                
                            }else if(AssetRate>0.9 &&AssetRate<=1.0){
                                Maxcoefficient = 1;
                                Mincoefficient = (1-0.05);
                                
                            }else if(AssetRate>1.0 &&AssetRate<=1.1){
                                Maxcoefficient = (1+0.05);
                                Mincoefficient = 1;
                                
                            }else if(AssetRate>1.1 &&AssetRate<=1.2){
                                Maxcoefficient = (1+0.1);
                                Mincoefficient = 1;
                                
                            }else if(AssetRate>1.2 &&AssetRate<=1.3){
                                Maxcoefficient = (1+0.2);
                                Mincoefficient = (1+0.1);
                                
                            }else if(AssetRate>1.3 &&AssetRate<=1.4){
                                Maxcoefficient = (1+0.25);
                                Mincoefficient = (1+0.15);
                                
                            }else if(AssetRate>1.4){
                                Maxcoefficient = (1+0.3);
                                Mincoefficient = (1+0.2);
                                
                            }
                            //市场多年保修价格开发 DC 2023/1/30 end 
                            // console.log('***最高系数'+Maxcoefficient);
                            // console.log('***最低系数'+Mincoefficient);
 
                        if(nowdate < Date.parse(lastendDate)){
                            //设备小于两年半
                            // upPrice = strMoney;
                            // downPrice = strMoney * 0.8;
                        // console.log('***小于2年半')
                        // 市场多年保修价格开发 start DC 2023/01/19  
                            //市场多年保设备小于2年半
                            var AssetModelNo = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_Model_No__c')).value();
                            var Category4 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Category4__c')).value();
                            // console.log('***设备型号'+AssetModelNo);
                            // console.log('***产品类型'+Category4);
 
                            //设备设备消费率小于1.4
                            if(AssetRate<1.4){
                                upPrice = VMassetListmonth * ContractMonth / 12 ;
                                // console.log('消费率小于1.4 upPrice = VMassetListmonth *ContractMonth / 12'+ upPrice);
 
                                if(AssetModelNo.includes('290')&&( Category4 =='BF'|| Category4=='BF扇扫'||Category4=='CF')){
                                    downPrice = upPrice;
                                    // console.log('消费率小于1.4 产品无最低价 downPrice '+ downPrice);
 
                                }else{
                                    downPrice = upPrice * 0.8;
                                    // console.log('消费率小于1.4 产品最低价 downPrice = upPrice* 0.8:'+ downPrice);
 
                                }
                            }else{
                                upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                                downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;   
                                    // console.log('消费率大于1.4 upPrice'+ upPrice);
                                    // console.log('消费率大于1.4 downPrice'+ downPrice);
                            }
                            // 市场多年保修价格开发 end DC 2023/01/19  
 
                            }else{
                                upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                                downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                                // upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                                // downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
 
                                //市场多年保修价格开发 DC 2023/1/30 start  设备大于2年半 续签价格 =定价*消费率对应系数 / 12 *合同月数
                                upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                                downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;
                                //市场多年保修价格开发 DC 2023/1/30 end 
                            }
                            // gzw 20220630  实际联动6个月价格区分
                        }else{
                            upPrice = strMoney;
                            downPrice = strMoney * 0.8;
                        }
                    }else{
                        upPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100);
                        downPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100);
                    }
                }else{
                    //firstCCount ++;
                    upPrice = strMoney;
                    downPrice = strMoney * 0.8;
                }
                // 上下限四舍五入
                upPrice = upPrice.toFixed(2);
                downPrice = downPrice.toFixed(2);
                // 12个月合同金额
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXT')).text(toNumComma(Price_YearTXT));
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXTHidden')).val(Price_YearTXT);
                if (!isDisabled) {
                    // 实际联动价格 start
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(downPrice));
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_priceHidden')).val(downPrice);
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice));
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val(upPrice);
                    // 实际联动价格 end
                }
                
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPrice')).text(toNumComma(strMoney));
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPricePageHidden')).val(strMoney);
                
                repairMoney = j$.trim(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value());
            } else {
                // TODO 一時的な対応、なんで別行の金額リフレッシュされた?
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPrice')).text("");
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPricePageHidden')).val();
 
                // 12个月合同金额
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXT')).text("");
                //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXTHidden')).val();
                if (!isDisabled) {
                    // 实际联动价格 start
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text("");
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_priceHidden')).val();
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text("");
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val();
                    // 实际联动价格 end
                 }
            }
        }
        else {
            // 所有设备按安装日、发货日(最早的),距离合同开始日6个月内都是新品合同
            var isNewDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':isNewDate')).value());
            isNewDate.setMonth(isNewDate.getMonth() + 6);
            if (Date.parse(contractStartDate) > Date.parse(isNewDate)) {
                newCon = false;
            }
            strMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
 
            Price_YearTXT = strMoney * 12;
            if (isnew == 'true') {
                strMoney = month * strMoney + month2 * strMoney / {!isNewPriceAdj};
            } else {
                strMoney = month * strMoney + month2 * strMoney;
 
            }
            var b = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contract_No')).value(); 
            var LastMContractRecord = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractRecord')).value();
            console.log('***维修合同记录类型4'+LastMContractRecord);
            if(b != ''){
                conCCount ++;
                // 1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。)
 
                // 2.一年以上的合同,在结束前6个月开始可以开放续签报价。
                var lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value());
                var lastContRange = 0;
                if(LastMContractRecord == 'VM_Contract'){
                    newCount++;
                    //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start
                    GuranteeCount++;
                    newCon = false;
                    //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end
                    lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                    lastContRange = 36;
                }else{
                    lastContRange = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':lastContRange')).value();
                }
                //最后结束日+1年
                lastendDate.setMonth(lastendDate.getMonth() + 12);
                // alert('+++++++++--------' + lastendDate);
                // alert('+++++++++--------' + Date.parse(contractStartDate) + '77777' + Date.parse(lastendDate));
                if (Date.parse(contractStartDate) > Date.parse(lastendDate)) {
                    oyearCount ++;
                }
                // 取联动价格
                // 上一期合同实际报价月额
                // 
                var LastMContract_Price = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContract_Price')).val());
                var Adjustment_ratio_Lower = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Lower')).val());
                var Adjustment_ratio_Upper = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_ratio_Upper')).val());
                //计算惩罚率
                var Punish = calculateNtoMRatio( lastContRange,(month + month2));
                if(Punish == 0){
                    return;
                }
                // 判断有无报价:没有按照标准价格实际联动
                var Estimate_Num = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Estimate_NumHidden')).val();
                if(Estimate_Num == 0){
                    if(LastMContractRecord == 'VM_Contract'){
                        // alert('11111');
                        // gzw 20220630  实际联动6个月价格区分
                        var nowdate = new Date();
                        lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':endDateGurantee_Text')).value());
                        nowdate = nowdate.setMonth(nowdate.getMonth() + 6);
 
                         //市场多年保修价格开发 DC 2023/1/30 start 
                            var Maxcoefficient =0;
                            var Mincoefficient =0;
 
                            var AssetRate = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetConsumptionRateNew')).val());
                            console.log('***消费率:'+AssetRate);
 
                            var ContractMonth = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contract:monthRange')).val());
 
                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contractrate')).text(AssetRate +'%');
 
                            if(AssetRate>0 &&AssetRate<=0.5){
                                Maxcoefficient = (1-0.3);
                                Mincoefficient = (1-0.4);
                            }else if(AssetRate>0.5 &&AssetRate<=0.6){
                                Maxcoefficient = (1-0.2);
                                Mincoefficient = (1-0.3);
                                
                            }else if(AssetRate>0.6 &&AssetRate<=0.7){
                                Maxcoefficient = (1-0.15);
                                Mincoefficient = (1-0.25);
                                
                            }else if(AssetRate>0.7 &&AssetRate<=0.8){
                                Maxcoefficient = (1-0.1);
                                Mincoefficient = (1-0.2);
                                
                            }else if(AssetRate>0.8 &&AssetRate<=0.9){
                                Maxcoefficient = (1-0.05);
                                Mincoefficient = (1-0.15);
                                
                            }else if(AssetRate>0.9 &&AssetRate<=1.0){
                                Maxcoefficient = 1;
                                Mincoefficient = (1-0.05);
                                
                            }else if(AssetRate>1.0 &&AssetRate<=1.1){
                                Maxcoefficient = (1+0.05);
                                Mincoefficient = 1;
                                
                            }else if(AssetRate>1.1 &&AssetRate<=1.2){
                                Maxcoefficient = (1+0.1);
                                Mincoefficient = 1;
                                
                            }else if(AssetRate>1.2 &&AssetRate<=1.3){
                                Maxcoefficient = (1+0.2);
                                Mincoefficient = (1+0.1);
                                
                            }else if(AssetRate>1.3 &&AssetRate<=1.4){
                                Maxcoefficient = (1+0.25);
                                Mincoefficient = (1+0.15);
                                
                            }else if(AssetRate>1.4){
                                Maxcoefficient = (1+0.3);
                                Mincoefficient = (1+0.2);
                                
                            }
                            //市场多年保修价格开发 DC 2023/1/30 end 
                            // console.log('***最高系数'+Maxcoefficient);
                            // console.log('***最低系数'+Mincoefficient);
 
                        if(nowdate < Date.parse(lastendDate)){
                            upPrice = strMoney;
                            downPrice = strMoney * 0.8;
                            //设备小于两年半
                            // upPrice = strMoney;
                            // downPrice = strMoney * 0.8;
                        // console.log('***小于2年半')
                        // 市场多年保修价格开发 start DC 2023/01/19  
                            //市场多年保设备小于2年半
                            var AssetModelNo = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_Model_No__c')).value();
                            var Category4 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Category4__c')).value();
                            // console.log('***设备型号'+AssetModelNo);
                            // console.log('***产品类型'+Category4);
 
                            //设备设备消费率小于1.4
                            if(AssetRate<1.4){
                                upPrice = VMassetListmonth * ContractMonth /12;
                                // console.log('消费率小于1.4 upPrice = VMassetListmonth *ContractMonth /12'+ upPrice);
 
                                if(AssetModelNo.includes('290')&&( Category4 =='BF'|| Category4=='BF扇扫'||Category4=='CF')){
                                    downPrice = upPrice;
                                    // console.log('消费率小于1.4 产品无最低价 downPrice '+ downPrice);
 
                                }else{
                                    downPrice = upPrice * 0.8;
                                    // console.log('消费率小于1.4 产品最低价 downPrice = upPrice* 0.8:'+ downPrice);
 
                                }
                            }else{
                                upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                                downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;   
                                // console.log('消费率大于1.4 upPrice'+ upPrice);
                                // console.log('消费率大于1.4 downPrice'+ downPrice);
                            }
                            // 市场多年保修价格开发 end DC 2023/01/19  
                        }else{
                             upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                            downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                            // upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                            // downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
 
                            //市场多年保修价格开发 DC 2023/1/30 start  设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数
                            upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12;
                            downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12;
                            //市场多年保修价格开发 DC 2023/1/30 end 
 
                        }
                        // gzw 20220630  实际联动6个月价格区分
                    }else{
                        upPrice = strMoney;
                        downPrice = strMoney * 0.8;
                    }
                }else{
                    upPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100);
                    downPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100);
                }
            }else{
                if (isnew == 'true') {
                    newCount ++;
                } else {
                    newCon = false;
                    firstCCount ++;
                }
                upPrice = strMoney;
                downPrice = strMoney * 0.8;
            }
            // 上下限四舍五入
            upPrice = upPrice.toFixed(2);
            downPrice = downPrice.toFixed(2);
            // 12个月合同金额
            //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXT')).text(toNumComma(Price_YearTXT));
            //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceTXTHidden')).val(Price_YearTXT);
            if (!isDisabled) {
                // 实际联动价格 start
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(downPrice));
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_priceHidden')).val(downPrice);
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice));
                j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val(upPrice);
                // 实际联动价格 end
            }
            //j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPrice')).text(toNumComma(strMoney));
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPricePageHidden')).val(strMoney);
            //<!-- (2022年12月上线)故障品加费 start -->  
 
            Repair_Price_AutoPrice = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto'));
            Repair_Price_Auto = Repair_Price_AutoPrice.value();
            repairMoney = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value();
            // console.log('repairMoney='+repairMoney);
            repairMoney1 = localParseFloat(repairMoney);
            ISReducedpriceapproval1 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ISReducedpriceapproval1')).val();
            ISReduced = j$(escapeVfId('allPage:allForm:allBlock:ISReducedpriceapproval')).val();
            // console.log('ISReduced='+ISReduced);
            
            // console.log('Repair_Price_Auto='+Repair_Price_Auto);
            // console.log('第'+(i+1)+'个设备ISReducedpriceapproval1='+ISReducedpriceapproval1);
            // console.log('repairMoney1='+repairMoney1);
            
            Repair_Price_pass1 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_pass')).val();
            Repair_Price_pass2 = localParseFloat(Repair_Price_pass1);
            // console.log('结果='+(repairMoney1<Repair_Price_pass2));
            // console.log('Repair_Price_pass2='+Repair_Price_pass2);
            if (repairMoney1> 0 && repairMoney1<(Repair_Price_Auto*0.80) && Repair_Price_Auto != null && isFSE == true) {
                 if (Repair_Price_pass1!=null && repairMoney1<Repair_Price_pass2) {
                    alert('由于存在折扣率超过20%以上的修理加费减价申请,请先点击“提交RC评估”按钮,待RC评估后服务管理部会推进审批');
                        // j$(escapeVfId('allPage:allForm:emailSend')).attr("disabled", false);
                        // j$(escapeVfId('allPage:allForm:emailSend')).attr("class", 'btn');
 
                    // RCbottonChanged = 1;
 
                    // var change_cancel = document.getElementById("emailSend");
                    // change_cancel.style.display = "block";
                    repairMoney = Repair_Price_pass2;
                    j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).val(Repair_Price_pass2);
                 }
            }
             
             repairMoney2 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value();
            // console.log('repairMoney='+repairMoney);
            repairMoney3 = localParseFloat(repairMoney2);
             if (repairMoney3> 0 && (repairMoney3 <Repair_Price_Auto*0.80)) {
                if (Repair_Price_pass1!=null && repairMoney3<Repair_Price_pass2) {
                         isresduce = isresduce+1;
                }
            }
            ResonCannotWarranty = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ResonCannotWarranty')).value();
            rppa =  document.getElementById('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto');
            situation = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Asset_situation')).value();
            // Agreed_Date =  j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Agreed_Date')).value();
 
            // console.log('situation='+situation);
            // console.log('Agreed_Date1='+Agreed_Date);
            // if(!(ResonCannotWarranty.indexOf("弃修") != -1)){
            //         rppa.style.display = "none";
            //         // j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).val('');
            //         // console.log('###修改成功');
            // }
            // if ((situation.indexOf("修理中")!=-1)&& (Agreed_Date.indexOf("为空")!=-1)) {
            //     console.log('开始操作1');
            //     rppa.style.display = "none";
            // }
            // if ((situation.indexOf("修理中")!=-1)&& (Agreed_Date.indexOf("不为空")!=-1)) {
            //     console.log('开始操作2');
            //     j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Repair_Price_Auto')).val(0);
            //     j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).val(0);
            // }
        //<!-- (2022年12月上线)故障品加费 end -->
        }
        
        repairSum = repairSum + localParseFloat(repairMoney);
        listSum = listSum + localParseFloat(toNum(strMoney));
        downPriceSum = downPriceSum + localParseFloat(toNum(downPrice));
        upPriceSum =  upPriceSum + localParseFloat(toNum(upPrice));
    }
    // console.log('改变金额isresduce='+isresduce);
     if (isresduce!=0) {
                toChange1();
        }else{
            if(ISReduced !='' ){
                 toChange2();
            }
        }
    j$(escapeVfId('allPage:allForm:allBlock:assetRepairSumNum')).text(toNumComma(repairSum));
    if (!isDisabled) {
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceUp')).text(toNumComma(Math.round(upPriceSum)));
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceUpHidden')).val(toNum(Math.round(upPriceSum)));
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceDown')).text(toNumComma(Math.round(downPriceSum)));
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceDownHidden')).val(toNum(Math.round(downPriceSum)));
    }
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPrice')).text(toNumComma(repairSum));
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPriceHidden')).val(toNum(repairSum));
 
    var allcount = j$(escapeVfId('allPage:allForm:allBlock:productCount3')).value();
    var result = '';
    if (allcount == 0) {
        result = null;
    //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 start
    }else if(GuranteeCount > 0 && GuranteeCount == allcount){
        result = '市场多年保续签合同';
    //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 end
    }else if (newCount > 0 && newCount == allcount && newCon == true) {
        result = '新品合同';
    }else if (((newCount > 0 && newCount == allcount) ||(newCount + firstCCount == allcount)) && newCon == false) {
        result = '首签合同';
    }else if(firstCCount > 0 && firstCCount == allcount){
        result = '首签合同';
    // 20220328 ljh update  LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start
    // }else if(oyearCount > 0 && oyearCount == conCCount){
    }else if(oyearCount > 0 && oyearCount == conCCount && allcount == oyearCount ){
    // 20220328 ljh update  LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start
        result = '非续签合同(空白期一年以上)';
    }else{
        result = '续签合同';
    }
    document.getElementById("allPage:allForm:allBlock:contractInfo:Contract_TypeTXT").innerHTML = result;
    document.getElementById("allPage:allForm:allBlock:contractInfo:Contract_TypeTXTHidden").value = result;
     
    examinationPriceCal(cnt);
    getLastContractRate();
    //上限合同 20230214 hql start
    var RequestquotationAmount = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:quotation_Amount')).val();
    console.log('申请报价金额='+RequestquotationAmount);
    var AssetRepairSumPrice    = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPrice')).text();
    console.log('合同设备修理总额='+AssetRepairSumPrice);
    Limit_Price_Amount = (localParseFloat(AssetRepairSumPrice)+localParseFloat(RequestquotationAmount))*1.3;
    Limit_Price_Amount = Math.round(Limit_Price_Amount);
    // console.log('取整1='+Math.round(124.5));
    // console.log('取整2='+Math.round(124.4));
    // console.log('取整3='+Math.round(124.6));
    Limit_Price_AmountOne =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).value();
    Limit_PriceHidden =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_PriceHidden')).value();
    // if (Limit_PriceHidden*1==0) {
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).val(Limit_Price_Amount);
    // }
    Limit_PriceHidden2 =  j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price2Hidden')).value();
    if (Limit_PriceHidden2 == 'false') {
        // lpa =  document.getElementById('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount');
        // lpa.style.display = "none";
        // console.log('隐藏完毕');
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Limit_Price_Amount')).val('');
    }
    console.log('上限金额为'+Limit_Price_Amount);
    //上限合同 20230214 hql end
    // 报价规则改善 20230315 start
    // seamlessRenew(cnt);
    // 报价规则改善 20230315 end
}
 
 
function examinationPriceCal(cntWithKara) {
    var examinationCount = localParseInt(j$(escapeVfId('allPage:allForm:allBlock:appendCondition:Examination_Count')).val());
    var examinationCountStr = number_format_common(examinationCount, 0, ".", ",");
    j$(escapeVfId('allPage:allForm:allBlock:appendCondition:Examination_Count')).val(examinationCountStr);
    var cnt = 0;
    for (var i = 0; i < cntWithKara; i++) {
        var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
        if (isManual == 'true') {
            var a = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Assert')).value();
            if (a != '') {
                cnt++;
            }
        }
        else {
            cnt++;
        }
    }
    var examinationPrice = 0;
// 今後復活かも
//    var cntLot = Math.ceil(cnt / 20);
//    if (cntLot == 0) {
//        examinationPrice = 0;
//    }
//    else if (cntLot == 1) {
//        examinationPrice = 2000;
//    }
//    else if (cntLot == 2) {
//        examinationPrice = 3800;
//    }
//    else if (cntLot == 3) {
//        examinationPrice = 5400;
//    }
//    else if (cntLot == 4) {
//        examinationPrice = 6800;
//    }
//    else if (cntLot == 5) {
//        examinationPrice = 8000;
//    }
//    else if (cntLot >= 6) {
//        examinationPrice = 1600 * cntLot;
//    }
    j$(escapeVfId('allPage:allForm:allBlock:appendCondition:examinationReal')).text(toNumComma(examinationPrice * examinationCount));
    j$(escapeVfId('allPage:allForm:allBlock:appendCondition:examinationRealHidden')).val(toNum(examinationPrice * examinationCount));
    
    // 付加条件総額欄
    // 20200108 去除附加条件总额
    // var oxygenPrice = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:NotUseOxygenatedWaterAmount')).text());
    // j$(escapeVfId('allPage:allForm:allBlock:contractInfo:appendPrice')).text(toNumComma(oxygenPrice + examinationPrice * examinationCount));
    // j$(escapeVfId('allPage:allForm:allBlock:contractInfo:appendPriceHidden')).val(toNum(oxygenPrice + examinationPrice * examinationCount));
    
    makeRealPrice(1);
}
 
/*
 * @param t   1: 金額により割引
 */
function makeRealPrice(t) {
    // 実際金額合計
    // 申请报价金额
    var sum1 = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contractInfo:quotation_Amount')).val());
    // 修理总额
    var sum2 = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPrice')).text();
    var sum1 = localParseFloat(sum1);
    // 上限
    var upPrice = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceUp')).text();
    upPrice = localParseFloat(upPrice);
    // 下限
    var downPrice = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceDown')).text();
    downPrice = localParseFloat(downPrice);
 
    // 相对标准价格范围的折扣率 计算
    // 1)标准价格范围内时,结果为0;
    // 2)比标准价格低时,结果是1-希望价格/标准价的最低价格
    // 3)比标准价格高时,结果是1-希望价格/标准价的最高价格
    var disMP = 0.00;
    var disP = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:discount_RateHidden')).val();
    if(sum1 < downPrice){
        disMP = toNum((1 - sum1/downPrice) * 100);
    }else if(sum1 >= downPrice && sum1 <= upPrice){
        disMP = 0.00;
    }else if(sum1 > upPrice){
        disMP = toNum((1 - sum1/upPrice) * 100);
    }
    
 
    if (disMP != disP) {
        disMP = '' + disMP +  '%';
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:discount_Rate')).text(disMP);
        j$(escapeVfId('allPage:allForm:allBlock:contractInfo:discount_RateHidden')).val(parseFloat(disMP));
    }
    // 修理総額を計上
    sum = sum1 + localParseFloat(sum2);
    
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:mainteReal')).text(toNumComma(sum));
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:mainteRealHidden')).val(toNum(sum));
}
 
function resetDealer() {
    var target = j$(escapeVfId('allPage:allForm:allBlock:contract:estimateTarget')).val();
    var obj = document.getElementById('allPage:allForm:allBlock:contract:dealer');
    var obj2 = document.getElementById('allPage:allForm:allBlock:contract:FirstParagraphEnd');
    var obj_lkwgt = document.getElementById('allPage:allForm:allBlock:contract:dealer_lkwgt');
    if (target == '医院') {
        obj.style.display = "none";
        obj2.style.display = "none";
        obj_lkwgt.style.display = "none";
    } else {
        obj.style.display = "block";
        obj_lkwgt.style.display = "block";
        obj2.style.display = "block";
    }
}
 
function alertMsg() {
    // body...
    if('{!isPaymentSet}' == 'false'){
        alert('请填写付款计划');
        return false;
    }else if('{!isPaymentSet}' == 'Denied'){
        alert('付款计划金额与实际不符,请重新填写');
        return false;
    }else{
        return true;
    }
}
function EGFlgconfim() {
    getEstimateCost();   
    var cntWithKara = {!productCount};
    // 新合同备品确保提供 是否改变
    var alert1s = 0;
    for (var i = 0; i < cntWithKara; i++) {
        var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
        var EGFlgtxt = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':EquipmentGuaranteeFlg')).value();
        var EGFlgnow = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':EGFlgassHidden')).value();
        if (EGFlgtxt != EGFlgnow) {
            alert1s = 1;
        }
    }
    if (alert1s == 1) {
        if (confirm("选择的保有设备[新合同备品确保提供]发生变化,是否继续?")) {
            
        } else {
            return false;
        }
    }
    return onclickCheckchangedAfterPrint('true','true');
}
function onclickCheckchangedAfterPrint(saveBtnDisabled, saveOrApproval) {
    
    //if(saveBtnDisabled == 'Pttrue'){
    //    var rs = alertMsg();
    //    if(rs){
    //    }else {
    //        return false;
    //    } 
    //}
   
    var cntWithKara = {!productCount};
    var alerts = 0;
    // 新合同备品确保提供 是否改变
    var alert1s = 0;
    var today = new Date();
    today.setMonth(today.getMonth() - 3);
 
    for (var i = 0; i < cntWithKara; i++) {
        var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
        if (isManual == 'true') {
            var plkid = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Assert_lkid'));
            var pid = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ProductId'));
            if (plkid.size() > 0 && pid.size() > 0) {
                if (pid.value() != '' && plkid.value() != pid.value().substring(0, 15)) { 
                    alert('请使用产品放大镜按钮设定手动产品');
                    return false;
                }
            }
        }
        if (isManual == 'false') {
            var strDate = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':finalExaminationDate')).value();
            // var produ = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Assert')).value();
            //alert(EGFlgtxt + ':' + EGFlgnow);
            strDate = strDate.replace(/(^\s*)|(\s*$)/g, ""); 
            if (strDate == "" || Date.parse(strDate) < Date.parse(today)) {
                alerts = 1;
            }
        }
    }
    if (alerts == 1) {
        if (confirm("选择的保有设备[最后点检日]为空或已经超过三个月之前,是否继续?")) {
            
        } else {
            return false;
        }
    }
    blockme();
    if (saveOrApproval == "true") {
        if (saveBeforeCheckPriceChange()) {
            if (confirm("行信息有变化(服务合同价格),是否更新报价?")) {
                j$(escapeVfId('allPage:allForm:changedSubmitPrice')).val('true');
            } else {
                j$(escapeVfId('allPage:allForm:changedSubmitPrice')).val('fasle');
                unblockUI();
                return false;
            }
        }
        j$(escapeVfId('allPage:allForm:isSaveOrApproval')).val('true');
    }
 
    
   return true;
    // if ((saveBtnDisabled == "true"||saveBtnDisabled == "Pttrue" )&& checkchangedAfterPrint()) {
    //     if (confirm(Confirm_ChangedAfterPrint)) {
    //         if (saveOrApproval == "true") {
    //             j$(escapeVfId('allPage:allForm:isSaveOrApproval')).val('true');
    //         }
    //         return true;
    //     } else {
    //         unblockUI();
    //         return false;
    //     }
    // } else {
    //     if (saveOrApproval == "true") {
    //         j$(escapeVfId('allPage:allForm:isSaveOrApproval')).val('true');
    //     }
    //     return true;
    // }
}
// 报价规则改善 20230310 start
// function addMonths(yearMonthDay ,monthNum){
//     var arr=yearMonthDay.split( '/');
//     var year=parseInt(arr[0]);
//     var month=parseInt(arr[1]);
//     var day=parseInt(arr[2]);
//     month=month+monthNum;
//     if(month>12){//月份加
//         var yearNum=parseInt( (month-1)/12);
//         month=month%12==0?12 :month%12;
//         year+=yearNum;
//         }else if(month<=0){//月份减
//             month=Math.abs( month);
//             var yearNum=parseInt( (month+12)/12);
//             year-=yearNum;
//         }
//         month=month<10?"0"+month :month;
//         return year+"/"+month+"/"+day;
// }
// function Blankperiod(startdate,i,LastMContract_Price,Punish,Adjustment_ratio_Upper,Adjustment_ratio_Lower,strMoney,type){
//             var  downPrice = 0;
//             var  upPrice = 0;
//             var  isSeamlessRenew = 0;
//             Blank_period = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Blank_period')).value();
//             var lastendDate1= j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value()
//             var lastendDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value());
//             // console.log("lastendDate1="+lastendDate1); 
//             var today = new Date();
//             if (lastendDate1.length !=0) {
//                 if (startdate == null) {
//                     // console.log(1);
//                      Blank_period=(today-lastendDate)/(3600*24*1000);
//                 }else{
//                     // console.log(2);
//                     Blank_period=(startdate-lastendDate)/(3600*24*1000);
//                 }
//                 j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Blank_period')).val(Blank_period);
//             }
//             if (Number(Blank_period)<15&&Blank_period.length != 0) {
//                 // console.log(3);
//                 j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Blank_period')).val('无缝续签');
//             }
//             Blank_period1 = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Blank_period')).value();
//             // console.log('Blank_period1='+Blank_period1);
//             // 2.无空白期设备是否算无缝续签设备 是否包含在无缝续签的报价判断中(首签的设备)?
//             if (Blank_period1 != '无缝续签' && Blank_period.length != 0) {
//                 isSeamlessRenew++;
//             }
//             // 1.实绩连动价格和设备参保定价 逻辑查看
//             upPrice1 = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100);
//             downPrice1 = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100);
//             // 定价8折
//             downPrice2 = strMoney * 0.8;
 
//             upPrice1 = upPrice1.toFixed(2);
//             upPrice2 = strMoney.toFixed(2);
//             downPrice1 = downPrice1.toFixed(2);
//             downPrice2 = downPrice2.toFixed(2);
//             // console.log('LastMContract_Price='+LastMContract_Price);
//             // console.log('upPrice1='+upPrice1);
//             // console.log('downPrice1='+downPrice1);
//             // console.log('upPrice2='+upPrice2);
//             // console.log('downPrice2='+downPrice2);
//             if (!isDisabled) {
//                 if (Blank_period1.length==0) {
//                     downPrice = downPrice2;
//                     upPrice = upPrice2;
//                 }
//                 if (Blank_period1.length!=0 && Number(Blank_period1)<180 || Blank_period1 == '无缝续签' ) {
//                     if (type == 1) {
//                         console.log('续签设备小于6个月');
//                         j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(downPrice1));
//                         j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice1));
//                     }
//                      downPrice = downPrice1;
//                      upPrice = upPrice1;
//                 }
//                 if (Blank_period1 != '无缝续签' && Number(Blank_period1)>180 && Number(Blank_period1)<365) {
//                     if (downPrice1<downPrice2) {
//                         if (type == 1) {
//                             console.log('续签设备6-12个月1');
//                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(downPrice2));
//                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice2));
//                         }
                        
//                         downPrice = downPrice2;
//                         upPrice = upPrice2;
//                     }else{
//                          if (type == 1) {
//                             console.log('续签设备6-12个月2');
//                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(downPrice1));
//                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice1));
//                           }
//                         downPrice = downPrice1;
//                         upPrice = upPrice1;
//                     }
//                 }
//                 if (Blank_period1 != '无缝续签' && Number(Blank_period1)>365) {
 
//                     if (downPrice1<upPrice2) {
//                         if (type == 1) {
//                             console.log('续签设备12个月1');
//                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(upPrice2));
//                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice2));
//                         }
//                         downPrice = upPrice2;
//                         upPrice = upPrice2;
//                     }else{
//                         if (type == 1) {
//                             console.log('续签设备12个月2');
//                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Lower_price')).text(toNumComma(downPrice1));
//                             j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_price')).text(toNumComma(upPrice1));
//                         }
//                         downPrice = downPrice1;
//                         upPrice = upPrice1;
//                     }
//                 }
//             }
//         return downPrice+"/"+upPrice+"/"+isSeamlessRenew;
// }
// 报价规则改善 20230310 end
function changeEstiStartdate(val) {
    // 报价规则改善 20230310 start
       // var startday = addMonths(val,6);
       // var startday1 = addMonths(val,12);
       //  document.getElementById("startdateaddsix1").value = startday;
       //  document.getElementById("startdateaddsix2").value = startday;
       //  document.getElementById("startdateaddsix3").value = startday1;
       //  document.getElementById("startdateaddsix4").value = val;
    // 报价规则改善 20230310 end
    if ('{!SaveBtnDisabled}' == 'false') {
        j$(escapeVfId('allPage:allForm:contractstartdate')).val(val);
        changeContractStartdate(val);
    }
}
 
function changeContractStartdate(val) {
 
    var oldDateStr = j$('#oldContractDate').value();
    var oldDate = new Date();
    if (oldDateStr != null && oldDateStr != '') {
        oldDate = new Date(oldDateStr);
    }
    if ('{!DecideBtnDisabled}' == 'false') {
        var monthStr = '00' + (oldDate.getMonth()+1);
        monthStr = monthStr.substring(monthStr.length-2, monthStr.length);
        var dayStr = '00' + oldDate.getDate();
        dayStr = dayStr.substring(dayStr.length-2, dayStr.length);
        var oldDateVal = oldDate.getFullYear() + '/' + monthStr + '/' + dayStr;
        j$(escapeVfId('allPage:allForm:oldDecideContractDate')).val(oldDateVal);
        if (saveBeforeCheckPriceChange()) {
            //blockme();
            //contractStartDateChange();
            //refreshAsset({!productCount});
        }
        refreshAsset({!productCount});
    } else {
        var cntWithKara = {!productCount};
        var haveLine = 'false';
        for (var i = 0; i < cntWithKara; i++) {
            var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
            if (isManual == 'true') {
                var a = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Assert_lkid'));
                if (a.size() > 0 && a.val() != "000000000000000") {
                    haveLine = 'true';
                }
            } else {
                haveLine = 'true';
            }
        }
 
        if (haveLine == 'false') {
            return false;
        }
        var contractStartDate = new Date(val);
        var strCreatedDate = '{!estimate.CreatedDate}';
        var createDate = new Date();
        if (strCreatedDate != '') {
            createDate = new Date(strCreatedDate);
        }
        createDate = new Date(createDate.toDateString());
        var threeMA = new Date(createDate.setMonth(createDate.getMonth() + 3));
        var isnewMA = new Date(createDate.setMonth(createDate.getMonth() - 3 - isNewAddMonth));
        
        /*if (oldDate >= isnewMA && contractStartDate >= isnewMA) {
            return false;
        }
        if (oldDate < threeMA && contractStartDate < threeMA) {
            return false;
        }
        
        if (contractStartDate >= isnewMA) {
            alert('合同开始预定日或合同开始日发生变化并且大于创建日6个月,所有合同对象设备不适用新品价格。\n请在画面刷新后确认服务合同价格,再继续其他操作。');
        } else if (contractStartDate >= threeMA) {
            alert('合同开始预定日或合同开始日发生变化并且大于创建日3个月,所有合同对象设备使用【合同开始日】重新计算服务合同价格。\n请在画面刷新后确认服务合同价格,再继续其他操作。');
        } else {
            alert('合同开始预定日或合同开始日发生变化并且在创建日3个月以内,所有合同对象设备使用【创建日】重新计算服务合同价格。\n请在画面刷新后确认服务合同价格,再继续其他操作。');
        }*/
        j$('oldContractDate').val(val);
        //blockme();
        //contractStartDateChange();
        refreshAsset({!productCount});
    }
}
function AlertPriceBtnJs(){
 
    var  VarAlert  = j$(escapeVfId('allPage:allForm:alertStringValue')).val();
    var  VarAlert2 = j$(escapeVfId('allPage:allForm:alertStringValue2')).val();
    var  VarAlert3 = j$(escapeVfId('allPage:allForm:alertStringValue3')).val();
    var  PStatus   = j$(escapeVfId('allPage:allForm:PriceStatus')).val();
    blockme();
 
    if(PStatus!='申请中'&& PStatus!='批准'){
        ComputeLTYRepair();
        //ShowLTYRepair();
    }else if(PStatus == '申请中'||PStatus == '批准'){
        ShowLTYRepair();
    }
   
}
function ComputeLTY() {
    var  urlNameJs = j$(escapeVfId('allPage:allForm:urlName')).val();
    urlNameJs = '{!$Label.ID_of_SelectAssetEstimate}'+urlNameJs ;
    //URF限次合同2期 LY 20220920 start
    // var w = window.open(encodeURI(urlNameJs),'过去两年修理实绩','menubar=no,height=720,width=986');
    // w.focus();
    //URF限次合同2期 LY 20220920 end
}
function recordNumChangeJs() {
    recordNumChangeAction();
}
 
function checkDecideDate() {
    // 报价有效期
    var strSubmitDate = '{!estimate.Submit_quotation_day__c}';
    // 上期合同结束日 取最晚的
    var conEndDate = getLastContractendDate();
    conEndDate = new Date(conEndDate);
    // 今天
    var submitDate = new Date();
    var nowDate = new Date();
    nowDate = new Date(nowDate.toLocaleDateString());
    /// 报价中设备的机身编码为空时的新品合同有效期延长 20200710 gzw
    // 默认为3月,全是产品为6月;
    var monthGap = 6;
    var cntWithKara = {!productCount};
        
    for (var i = 0; i < cntWithKara; i++) {
        var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
        if (isManual != 'true') {
            monthGap = 3;
            break;
        }
    }
        
 
    //nowDate = new Date(nowDate.getYear(),nowDate.getYear(),nowDate.getYear());
    if (strSubmitDate != '') {
        submitDate = new Date(strSubmitDate);
        submitDate = new Date(submitDate.setMonth(submitDate.getMonth() + monthGap));
        if(Date.parse(conEndDate)  > Date.parse(submitDate)){
            submitDate = new Date(conEndDate);
        }
    }
    //alert(nowDate + '=====' + submitDate);
    if (strSubmitDate != '' && nowDate > submitDate) {
        alert('已超出报价申请日'+ monthGap+'个月,不允许DECIDE。');
        return false;
    }
    return true;
}
 
function getLastContractendDate(){
    var rowCnt = {!productCount};
    var lastdate = null;
    for (var i = 0; i < rowCnt; i++) {
        var LastMContractID = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractID')).value();
        if(!!LastMContractID){
            var endDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value());
            if(lastdate == null){
                lastdate = new Date(endDate);
            }else if(Date.parse(endDate) > Date.parse(lastdate)){
                lastdate = new Date(endDate);
            }
        }
    }
    return lastdate;
}
 
 
function decideJs() {
    if (checkDecideDate() == true) {
        if (onclickCheckchangedAfterPrint('true','false') == true) {
            var oldDate = j$(escapeVfId('allPage:allForm:oldDecideContractDate')).value();
            var contractDate = new Date(j$(escapeVfId('allPage:allForm:contractstartdate')).value());
            //var olDt = oldDate.getFullYear() + oldDate.getMonth() + oldDate.getDate();
            var monthStr = '00' + (contractDate.getMonth()+1);
            monthStr = monthStr.substring(monthStr.length-2, monthStr.length);
            var dayStr = '00' + contractDate.getDate();
            dayStr = dayStr.substring(dayStr.length-2, dayStr.length);
            var contractDateStr = contractDate.getFullYear() + '/' + monthStr + '/' + dayStr;
 
            //var neDt = contractDate.getFullYear() + contractDate.getMonth() + contractDate.getDate();
            //monthStr = '00' + (oldDate.getMonth()+1);
            //monthStr = monthStr.substring(monthStr.length-2, monthStr.length);
            //dayStr = '00' + oldDate.getDate();
            //dayStr = dayStr.substring(dayStr.length-2, dayStr.length);
            //oldDateVal = oldDate.getFullYear() + '/' + monthStr + '/' + dayStr;
            if (oldDate == contractDateStr) {
                j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('false');
                decide();
            } else {
                var oldp = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contractInfo:oldMainteReal')).value());
                var newp = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contractInfo:mainteReal')).text());
                console.log('oldp='+oldp);
                 console.log('newp='+newp);
                if (oldp != newp) {
                    // 20201106 高章伟 提醒消息修改 start
                    j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('true');
                    if (confirm('合同金额发生变化,请您确认。')) {
                        decide();
                    } else {
                        alert('请确认全部内容后点击Decide。');
                        j$(escapeVfId('allPage:allForm:contractstartdate')).val(oldDate);
                        j$(escapeVfId('allPage:allForm:oldDecideContractDate')).val('');
                        j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('false');
                        decideCancle();
                    }
                } else {
                    j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('false');
                    decide();
                    // j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('false');
                    // if (confirm('本次合同开始日的修改不会导致合同金额发生变化,请您确认是否修改?')) {
                    //     decide();
                    // } else {
                    //     j$(escapeVfId('allPage:allForm:contractstartdate')).val(oldDate);
                    //     alert('合同开始日未进行变更,请确认全部内容后点击Decide。');
                    //     unblockUI();
                    // }
                }
                // 20201106 高章伟 提醒消息修改 end
            }
        }
    }
}
// 获取实际报价金额 按照上限比例算
function getEstimateCost() {
    // 行数   
    var rowcount = {!productCount};
    // 6.合同价格
    var mainteReal = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:mainteReal')).text();
    mainteReal = localParseFloat(mainteReal);
    // 5.修理总额
    var assetRepairSumPrice = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:assetRepairSumPrice')).text();
    assetRepairSumPrice = localParseFloat(assetRepairSumPrice);
    // 计算实际报价总金额
    var realprice = mainteReal - assetRepairSumPrice;
    // 标准价格的最高价总额
    var GuidePriceUp = localParseFloat(j$(escapeVfId('allPage:allForm:allBlock:contractInfo:GuidePriceUpHidden')).val());
    GuidePriceUp = localParseFloat(GuidePriceUp);
    for (var i = 0; i < rowcount; i++) {
        // 去上限价格
        var assetListPrice = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Adjustment_Upper_priceHidden')).val();
        assetListPrice = localParseFloat(assetListPrice);
        if(GuidePriceUp == 0){
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Estimate_Cost')).val(0);
        }else{
            var Estimate_Cost = (realprice * (assetListPrice / GuidePriceUp)).toFixed(2);
            j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Estimate_Cost')).val(Estimate_Cost);
        }
        
    
    }
}
 
function getLastContractRate(){
    var rowCnt = {!productCount};
    var Contractrate = 0.00;
    var count = 0;
    for (var i = 0; i < rowCnt; i++) {
        var LastMContractID = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':LastMContractID')).value();
        if(!!LastMContractID){
            var tempContractrate = parseFloat(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':Contractrate')).value().replace(/,/g,''));
            if(!!tempContractrate){
                Contractrate = Contractrate + tempContractrate;
            }
            count++;
        }
    }
    var allContractRate = '' + 0.00 + '%';
    if( count > 0){
        allContractRate = '' + (Contractrate/count).toFixed(2) + '%';
    }
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:Combinedrate')).text(allContractRate);
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:CombinedrateHidden')).val(parseFloat(allContractRate));
 
    return allContractRate;
}
function calculateNtoMRatio(lastContRange, month ){
    var lastContRangeYear = Math.ceil(localParseFloat(lastContRange)/12);
    var currentMonthYear = Math.ceil(localParseFloat(month)/12);
    //if(!lastendDate || currentMonthYear <= lastContRangeYear){
    if(currentMonthYear == lastContRangeYear || currentMonthYear == 1){
        return month;
    }else if(month <= 24) {
        return 12+ (month- 12) *1.1;
    }else if(month <= 36) {
        return 25.2 + (month- 24) *1.21;
    }else if(month <= 48) {
        return 39.72 + (month- 36) *1.331;
    }else if(month <= 60) {
        return 55.692 + (month- 48) *1.4641;
    }else {
        alert('合同期最长只能选择60个月!');
        return 0;
    }
 
}
 
    //获取经销商的先款标识
    function onChDealerUpdateJs(oBj){
        //获取 报价提交对象  是否为经销商
        var estimateTarget = j$(escapeVfId('allPage:allForm:allBlock:contract:estimateTarget'))[0].value;
        if(estimateTarget == '经销商'){
            //判断经销商名是否为空
            var dealerValue = j$(escapeVfId('allPage:allForm:allBlock:contract:dealer')).val();
            if(dealerValue != ''){
                //获取经销商名的id
                var dealerId = j$(escapeVfId('allPage:allForm:allBlock:contract:dealer_lkid')).val();
                //由于salesforce的查找字段是可以输入的,所以判断他如果为空或者为 000000000000000 的时候,传的参数就位经销商中文名,其他情况传id
                if(dealerId != '' && dealerId != '000000000000000'){
                    onChDealerUpdate(dealerId);
                }else{
                    onChDealerUpdate(dealerValue);
                }
            }else{
                onChDealerUpdate('');
                //j$(escapeVfId('allPage:allForm:allBlock:contract:FirstParagraphEnd'))[0].checked = false;
            }
        }
    }
    //如果选择的经销商为先款对象,那么做一下提示
    function hintAccount(){
        var xkChecked = j$(escapeVfId('allPage:allForm:allBlock:contract:FirstParagraphEnd'))[0].checked;
        if(xkChecked){
            alert('请注意,当前经销商为先款对象。');
        }
    }
 
//LJPH-C9SCX7 【委托】合同无空白期的提醒  lt  20211221  start
//合同开始日预定日默认为上期合同1结束日的第2天
// function DefaultStartDate(){
//     //上期合同1结束日
//     var LastContractEndDate;
//     var LastContractEndDate2;  //日期格式
//     var cnt = j$(escapeVfId('allPage:allForm:allBlock:assetSection:productCnt')).val();
//     for (var i = 0; i < cnt; i++){
//         LastContractEndDate = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':End_Date')).value();
//          //或者换隐藏标签Maintenance_Contract__r.Past_Contract_end_day__c
//         LastContractEndDate2 = LastContractEndDate;
//         if(LastContractEndDate != null && LastContractEndDate != ''){
//             break;
//         }
//     }
 
//     if(LastContractEndDate != null && LastContractEndDate != ''){
//         //上期合同1结束日的第2天
//         LastContractEndDate += " 00:00:00";//设置为当天凌晨12点
//         LastContractEndDate = Date.parse(new Date(LastContractEndDate))/1000;//转换为时间戳
//         LastContractEndDate += (86400) * 1;//修改后的时间戳
//         var newDate = new Date(parseInt(LastContractEndDate) * 1000);//转换为时间
//         var LastContractEndDate1 = newDate.getFullYear() + '/' + (newDate.getMonth() + 1) + '/' + newDate.getDate();;
 
//         //获取当前日期(currentdate)
//         var date1 = new Date();
//         var seperator = "/";
//         var year = date1.getFullYear();
//         var month = date1.getMonth() + 1;
//         var day = date1.getDate();
//         if (month >= 1 && month <= 9) {
//             month = "0" + month;
//         }
//         if (day >= 0 && day <= 9) {
//             day = "0" + day;
//         }
//         var currentdate = year + seperator + month + seperator + day;
 
//         //上期合同尚未结束 , 开始预定日
//         if(currentdate < LastContractEndDate2){
//             document.getElementById("allPage:allForm:allBlock:contract:startdate").value = LastContractEndDate1;
//         }
//     }
    
// }
//LJPH-C9SCX7 【委托】合同无空白期的提醒  lt  20211221  end
 
</script>
<apex:form id="allForm">
    <apex:inputHidden id="alertStringValue" value="{!alertString}" />
    <apex:inputHidden id="alertStringValue2" value="{!alertString2}" />
    <apex:inputHidden id="alertStringValue3" value="{!alertString3}" />
    <apex:inputHidden id="PriceStatus" value="{!estimate.Process_Status__c}"/>
    <apex:inputHidden id="urlName" value="{!estimate.Name}"/>
    <apex:inputHidden id="changedAfterPrint" value="{!changedAfterPrint}"/>
    <apex:inputHidden id="changedSubmitPrice" value="{!changedSubmitPrice}"/>
    <apex:inputHidden id="isSaveOrApproval" value="{!isSaveOrApproval}"/>
 
    <!-- HWAG-B4R3SS  START 20181026-->
    <apex:actionFunction name="searchfunc" action="{!searchBtn}" rerender="Form,Block,assetSection2,pageMessages,allBlock" onComplete="unblockUI();"></apex:actionFunction>
    <apex:actionfunction action="{!tochange}" name="tochange" rerender="ISReducedpriceapproval" oncomplete="unblockUI();">
        </apex:actionfunction>
        <apex:actionfunction action="{!tochange2}" name="tochange2" rerender="ISReducedpriceapproval" oncomplete="unblockUI();">
        </apex:actionfunction>
    <!-- HWAG-B4R3SS  END 20181026-->
    <apex:actionFunction name="ComputeLTYRepair" action="{!ComputeLTYRepair}" rerender="pageMessages" oncomplete="unblockUI();ComputeLTY();"/>
    <apex:actionFunction name="ShowLTYRepair" action="{!ShowLTYRepair}"  oncomplete="unblockUI();ComputeLTY();"/>
    <apex:actionFunction name="decide" action="{!decide}" rerender="allForm" oncomplete="unblockUI();"/>
    <apex:actionFunction name="decideCancle" action="{!decideCancle}" rerender="allForm" oncomplete="unblockUI();"/>
    <apex:inputHidden id="oldDecideContractDate" value="{!OldContractStartDate}" />
    <!-- 经销商发生变化的change时间 -->
    <apex:actionFunction name="onChDealerUpdate" action="{!onChDealerUpdate}" rerender="contract" onComplete="hintAccount();">
        <apex:param name="checkDealerId" assignTo="{!checkDealerId}" value="" />
    </apex:actionFunction>
    <input type="hidden" id="oldContractDate" value="{!estimate.Contract_Start_Date__c}" />
<script type="text/javascript">
//j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('false');
</script>
    <apex:pageBlock title="服务合同报价" id="allBlock">
        <apex:pageBlockButtons id="blocktop" location="top">
            <apex:commandButton id="savebtntop" action="{!save}" value="{!$Label.Save_Button}" disabled="{!SaveBtnDisabled}" rerender="allForm" onclick="if (!EGFlgconfim()) return false;" oncomplete="unblockUI();"/>
           <!--  <apex:commandButton id="LastTwoYearRepairShow" value="过去两年维修实绩Repaort"  action="{!ShowLTYRepair}" rerender="alertStringValue,alertStringValue2,alertStringValue3" oncomplete="AlertPrice();"/> -->
            <apex:commandButton id="LastTwoYearRepairComp" value="过去三年维修实绩计算" rerender="PriceStatus" onclick="AlertPriceBtnJs()"/>
            <apex:commandButton id="approvalbtntop" action="{!approvalProcess}" value="提交待审批" disabled="{!ApprovalBtnDisabled}" rerender="allForm" onclick="if (!KindsAndMonths()) return false;if (!EGFlgconfim()) return false;approvalJs();" oncomplete="unblockUI();"/>
            <!-- HWAG-B399Q8 2018/08/20 新增请提交待审批 提示字段 start-->
            &nbsp; <apex:outputText style="color:red;font-size:20px" value="请提交待审批" rendered="{!IS_Clone_After_Decide}"/>
            <!-- HWAG-B399Q8 2018/08/20 新增请提交待审批 提示字段 end-->
            <apex:commandButton action="{!cancel}" value="不保存(返回)" style="float:right;" rerender="allForm" onclick="blockme();" oncomplete="unblockUI();"/>
            <apex:commandButton id="saveAndCancelBtn" action="{!saveAndCancel}" value="保存(返回)" style="float:right;" rerender="allForm" oncomplete="unblockUI();" onclick="if (!onclickCheckchangedAfterPrint('true','true')) return false;" disabled="{!SaveBtnDisabled}"/>
        </apex:pageBlockButtons>
       
        <apex:pageMessages id="pageMessages"></apex:pageMessages>
        <!-- update 合同报价页面的优化 添加‘assetSection’ fxk 2021/9/10 Star-->
        <apex:actionFunction name="refreshProductData" action="{!refreshProductData}" rerender="pageMessages,EquipmentGuaranteeFlg,EGFlgassHidden,EquipmentGuaranteeFlgtxt, assetListPriceHidden, productCount3,assetSection" oncomplete="refreshAsset({!productCount});unblockUI();">
            <apex:param assignTo="{!productIdx}" name="productIdx" value=""/>
        </apex:actionFunction>
        <!-- update 合同报价页面的优化 添加‘assetSection’ fxk 2021/9/10 End-->
        <!--<apex:actionFunction name="contractStartDateChange" action="{!contractStartDateChange}" rerender="allForm" oncomplete="unblockUI();">
        </apex:actionFunction>-->
 
        <apex:actionFunction name="recordNumChangeAction" action="{!recordNumChange}" rerender="allForm" oncomplete="unblockUI();">
        </apex:actionFunction>
 
        <!-- update by rentx 2020-11-17  -->
            <!-- <apex:pageblocksection title="服务合同" id="contract"> -->
            <!-- <apex:outputField value="{!estimate.Name}"/> -->
            <!-- <apex:outputField value="{!contract.Management_Code__c}" /> -->
            <!-- <apex:outputField value="{!estimate.Process_Status__c}"/> -->
            <!-- <apex:outputField value="{!contract.Status__c}"/> -->
            <!-- <apex:outputField value="{!contract.Hospital__c}" /> -->
            <!-- <apex:inputField value="{!estimate.Department__c}" id="depart"/> -->
            <!-- <apex:inputField value="{!estimate.Contract_Esti_Start_Date__c}" required="true" id="startdate" onchange="changeEstiStartdate(this.value);"/>onchange="checkContractEstiStartDate(this.value, {!productCount})" --> 
            <!-- <apex:inputField value="{!estimate.Contract_Range__c}" required="true" id="monthRange" onchange="checkContractRange(this.value, {!productCount})"/> -->
            <!-- <apex:inputField style="width:3px;height:15px;background-color:#cc0000; position:absolute;margin-right:5px;"> -->
            <!-- <div><div style="width:2px;height:20px;background-color:red; position:absolute;margin-right:5px;"></div></div> -->
            <!-- <apex:inputField value="{!estimate.Contract_Range__c}" required="false" id="monthRange" onchange="checkContractRange(this.value, {!productCount})"/> -->
            <!-- </apex:inputField> -->
            
            <!-- <apex:outputField value="{!estimate.Contract_Esti_End_Date__c}"/> -->
            <!-- <apex:outputField label="制定日" value="{!estimate.CreatedDate}" id="createDateShow"/> -->
 
            <!-- <apex:outputPanel > -->
                <!-- <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">报价提交对象</label> -->
                <!-- <apex:inputField value="{!estimate.Estimate_Target__c}" id="estimateTarget" onchange="resetDealer()" style="margin-left:5px"/> -->
 
                <!-- <apex:outputPanel rendered="{!DecideBtnDisabled==false}"> -->
                    <!-- <input type="button" class="btn" value="变更" onclick="controlDisabled()" style="margin-left:20px;width:40px;padding:0 0;"/> -->
                <!-- </apex:outputPanel> -->
                <!-- <apex:outputPanel rendered="{!DecideBtnDisabled==true}"> -->
                    <!-- <input type="button" class="btnDisabled" value="变更" disabled="true" onclick="controlDisabled()" style="margin-left:20px;width:40px;padding:0 0;"/> -->
                <!-- </apex:outputPanel> -->
            <!-- </apex:outputPanel> -->
 
            <!-- <apex:inputField value="{!estimate.Dealer__c}" id="dealer" /> -->
            <!-- <apex:inputField value="{!estimate.EndUserType__c}" id="EndUserType" /> -->
            <!-- <script type="text/javascript"> -->
                <!-- j$(escapeVfId('allPage:allForm:allBlock:contract:estimateTarget')).children('option[value=]').remove(); -->
                <!-- resetDealer(); -->
            <!-- </script> -->
        <!-- </apex:pageblocksection> -->
        <apex:pageBlockSection title="服务合同" id="contract">
        <!-- <apex:outputPanel/> -->
            <apex:outputPanel >
            <table align="center" width="100%"  style="border-collapse:separate; border-spacing:0px 10px" >
                <tr>    
                    <td width="50%" align="right"> <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">报价编码</label> </td>
                    <td width="50%" align="left"> <apex:outputField value="{!estimate.Name}"/> </td>
                </tr>
                <tr>
                    <td width="50%" align="right"> <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">报价状态</label> </td>
                    <td width="50%" align="left"> <apex:outputField value="{!estimate.Process_Status__c}"/> </td>
                </tr>
                <tr>
                    <td width="50%" align="right"> <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">医院</label> </td>
                    <td width="50%" align="left"> <apex:outputField value="{!contract.Hospital__c}" /> </td>
                </tr>
                <tr>
                    <td width="50%" align="right"> <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">合同开始预订日</label> </td>
                    <td width="50%" align="left"> <apex:inputField value="{!estimate.Contract_Esti_Start_Date__c}" required="true" id="startdate" onchange="changeEstiStartdate(this.value);"/> 
                    </td>
                </tr>
                <tr>
                    <td width="50%" align="right"><label class="labelCol vfLabelColTextWrap " style="margin-left:22%">合同结束预订日</label> </td>
                    <td width="50%" align="left"> <apex:outputField value="{!estimate.Contract_Esti_End_Date__c}"/> </td>
                </tr>
                <tr>
                    <td align="right"> 
                        <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">报价提交对象</label>
                    <td>
                        <apex:outputPanel >
                            <apex:inputField value="{!estimate.Estimate_Target__c}" id="estimateTarget" onchange="resetDealer()" style="margin-left:5px"/>
                            <apex:outputPanel rendered="{!DecideBtnDisabled==false}">
                                <input type="button" class="btn" value="变更" onclick="controlDisabled()" style="margin-left:20px;width:40px;padding:0 0;"/>
                            </apex:outputPanel>
                            <apex:outputPanel rendered="{!DecideBtnDisabled==true}">
                                <input type="button" class="btnDisabled" value="变更" disabled="true" onclick="controlDisabled()" style="margin-left:20px;width:40px;padding:0 0;"/>
                            </apex:outputPanel>
                        </apex:outputPanel>
                    </td>
                    </td> 
                </tr>
                <tr>
                    <td align="right"> <label class="labelCol vfLabelColTextWrap " style="margin-left:22%"> 用户类型</label></td>
                    <td align="left">
                        <apex:outputField value="{!estimate.EndUserType__c}" id="EndUserType" />
                    </td>
                    <td> </td>
                </tr>
            </table>
            </apex:outputPanel>
        <apex:outputPanel >
            
        <table align="center" width="100%"  style="border-collapse:separate; border-spacing:0px 10px" >
            <tr>    
                <td width="50%" align="right"> <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">合同询价编码</label> </td>
                <td width="50%" align="left"> <apex:outputField value="{!contract.Management_Code__c}" /> </td>
            </tr>
            <tr>
                <td width="50%" align="right"> <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">状态</label> </td>
                <td width="50%" align="left"> <apex:outputField value="{!contract.Status__c}"/> </td>
            </tr>
            <tr>
 
                <td width="50%" align="right"> <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">科室</label> </td>
                <td width="50%" align="left"> <apex:inputField value="{!estimate.Department__c}" id="depart"/> </td>
            </tr>
            <tr>
 
 
                <td width="50%" align="right"> 
                    <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">合同月数</label> </td>
                <td width="50%" align="left">
                    <div style="width:3px;height:20px;background-color:#cc0000; position:absolute;margin-right:5px" />&nbsp;
                    <apex:inputField value="{!estimate.Contract_Range__c}" required="false" id="monthRange" 
                    onchange="checkContractRange(this.value, {!productCount})"
                    />
                </td>
            </tr>
            <tr>
 
                <td width="50%" align="right"> <label class="labelCol vfLabelColTextWrap " style="margin-left:22%">制定日</label></td>
                <td width="50%" align="left"> <apex:outputField label="制定日" value="{!estimate.CreatedDate}" id="createDateShow"/> </td>
            </tr>
            <tr>
  
                <td  width="50%" align="right">  
                    <label class="labelCol vfLabelColTextWrap " style="margin-left:30%"> 经销商名</label></td>
            <!-- update     wangweipeng             2021/12/04         start -->
                <td width="50%" align="left"> <apex:inputField value="{!estimate.Dealer__c}" id="dealer" onchange="onChDealerUpdateJs(this);return false;" style="float: left;"/> </td>
            </tr>
            <tr>
                <td  width="50%" align="right">  
                    <label class="labelCol vfLabelColTextWrap " style="margin-left:30%"> 先款标识(经销商)</label></td>
                <td width="50%" align="left" > <apex:inputCheckbox value="{!estimate.Is_RecognitionModel__c}" id="FirstParagraphEnd" onClick="return false;" /> </td>
            </tr>
            <!-- update     wangweipeng             2021/12/04         end -->
        </table>
        <script type="text/javascript">
            j$(escapeVfId('allPage:allForm:allBlock:contract:estimateTarget')).children('option[value=]').remove();
            resetDealer();
        </script>
        </apex:outputPanel>
        </apex:pageBlockSection>
 
        <!-- update by rentx 2020-11-17 end -->
 
        <apex:pageblocksection columns="1" title="合同对象设备" id="assetSection" >
            <apex:outputLabel />
            <apex:outputPanel >
                <input type="hidden" id="allPage:allForm:allBlock:assetSection:productCnt" value="{!productCount}" />
                <!-- <table width="100%">
                    <tr>
                        <td>&nbsp;</td>
                        <td width="100px"><span>全</span>
                            <select style="vertical-align:text-bottom" id="allCheckResult" size="1" onchange="changeAllCheckResult(this.value)">
                                <option value=" ">--无--</option>
                                <option value="OK">OK</option>
                                <option value="NG">NG</option>
                            </select>
                        </td>
                        <td width="150px">&nbsp;</td>
                    </tr>
                </table> -->
                <!-- <div id = 'aaaa' class="slds-scrollable_x" style="width:450px">
                <div class="slds-table--header-fixed_container" style="height:450px;width:850px">
                    <div class="slds-scrollable_y" style="height:100%;width:850px"> -->
                <div style="width: 100%">
                <table class="list" style="border-bottom-width: 0px; font-size:13px;" border="0" cellspacing="0" cellpadding="0">
                    <tr class="headerRow" height="30px">
                        <th style="width:25px" class="headerRow  booleanColumn"><input type='checkbox' onClick='checkAll(this)'/></th>
                        <th class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Name.label}</th>
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Asset_situation__c.label}</th>
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.SerialNumber.label}</th>
                        <th class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.EGFlg_fromContract_asset__c.label}</th>
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.InstallDate.label}</th>
                        <!--add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star-->
                        <th style="width:70px" class="headerRow  booleanColumn">
                        {!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Check_Object__c.label}</th>
                        <!--add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk end-->
                        <th style="width:40px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.IsNew__c.label}</th>
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Department_Name__c.label}</th>
                        
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Management_Code__c.label}</th>
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Asset_Consumption_rate__c.label}</th>
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.CurrentContract_End_Date__c.label}</th>
                        <!-- 市场多年保修价格开发 DC 2023/02/20  start-->
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset__c.fields.IS_VMContract_Asset__c.label}</th>
 
                        <!-- 市场多年保修价格开发 DC 2023/02/20  end-->
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Asset_Consumption_rate__c.label}</th>
 
                        <!-- 市场多年保修价格开发 DC 2023/1/30 start -->
                        <!-- <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Asset_Consumption_rate__c.label}</th>
 -->
                        <!-- 市场多年保修价格开发 DC 2023/1/30 end -->
                        <th style="width:70px" class="headerRow  booleanColumn">
                            <!-- 最近一期维修合同结束 -->
                            {!$ObjectType.Asset.fields.CurrentContract_End_Date__c.label}
                        </th>
                        <!-- 实绩联动价格计算 start -->
                        <th style="width:35px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Adjustment_Upper_price__c.label}</th>
                        <th style="width:35px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Adjustment_Lower_price__c.label}</th>
                        <!-- 实绩联动价格计算 end -->
                        <!-- 隐藏合同月数
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract__c.fields.Contract_Range__c.label}</th>-->
 
 
 
 
 
 
 
                        
                        <!-- <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Asset_Owner__c.label}</th>
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Accumulation_Repair_Amount__c.label}</th>
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Estimate_List_Price_All__c.label}</th>
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Maintenance_Price_YearTXT__c.label}</th>-->
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Repair_Price__c.label}</th>
                        <!-- (2022年12月上线)故障品加费 start -->
 
                        <th style="width:70px" class="headerRow ">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Repair_Price_Auto__c.label}</th>
 
                       <!-- (2022年12月上线)故障品加费 end -->
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Comment__c.label}</th>
 
                        <!-- (2022年12月上线)故障品加费 第三方回归 -->
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Third_Party_Return__c.label}</th>
                    </tr>
                    
                    <apex:variable value="{!1}" var="cnt" />
                        <apex:repeat value="{!checkedAssets}" var="ar" id="assetTable">
                            <tr class="dataRow {!IF(MOD(cnt, 2)==0, 'odd', 'even')} {!IF(cnt==1, 'first', '')}" onmouseover="if (window.hiOn){hiOn(this);} " onmouseout="if (window.hiOff){hiOff(this);} " onblur="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}">
                                <td class="dataCell" width="25px">
                                    <apex:inputCheckbox value="{!ar.rec_checkBox_c}" id="assetRowCheckbox" rendered="{!Not(ar.IsManual)}" disabled="{!PageDisabled}"/>
                                    <apex:outputText value="{!ar.IsManual}" id="IsManual" style="display:none;" />
                                    <!-- 判断是否可报价 -->
                                    <!-- <input type="hidden" value="{!ar.estimateass}" id="allPage:allForm:allBlock:assetSection:assetTable:{!Text(cnt-1)}:estimateass"/> -->
                                    <!-- <apex:inputCheckbox value="{!ar.estimateass}" id="estimateass" style="display:none;" /> -->
                                </td>
                                <td class="dataCell">
                                    <apex:outputField value="{!ar.rec.Name}" id="assetName" rendered="{!Not(ar.IsManual)}" />
                                    <apex:inputField value="{!ar.mcae.Product_Manual__c}" id="Assert" style="width:90%;" rendered="{!ar.IsManual}" onchange="blockme();refreshProductData({!ar.lineNo});"/>
                                    <apex:inputText id="ProductId" value="{!ar.mcae.Product_Manual__c}" style="display:none;" disabled="true"/>
                                </td>
                                <!-- URF限次合同2期 LY 20220811 start -->
                            
                                    <apex:inputHidden value="{!ar.rec.URF_Maintenance_Contract__r.Management_Code__c}" rendered="{!Not(ar.IsManual)}" id="URF_Contract_No"/>
                                
                                <!-- URF限次合同2期 LY 20220811 end -->
                                <td class="dataCell" width="70px">
                                    <apex:outputField value="{!ar.rec.Asset_situation__c}" rendered="{!Not(ar.IsManual)}" id="Asset_situation"/>
                                </td>
                                <td class="dataCell" width="70px">
                                    <apex:outputLink value="/{!ar.recId}" rendered="{!Not(ar.IsManual)}" >{!ar.rec.SerialNumber}</apex:outputLink>
                                    <apex:inputHidden id="AssetId" value="{!ar.recId}"/>
                                    <apex:inputField value="{!ar.rec.isNewDate_use__c}" id="isNewDate" style="display: none" showDatePicker="false"/>
                                </td>
                                <td class="dataCell" >
                                    <apex:outputField value="{!ar.mcae.EquipmentGuaranteeFlgTxt__c}" id="EquipmentGuaranteeFlgtxt"/>
                                    <apex:outputText value="{!ar.mcae.EquipmentGuaranteeFlgTxt__c}" id="EquipmentGuaranteeFlg" style="display:none;"/>
                                    <apex:inputHidden id="EGFlgassHidden" value="{!ar.etGFlg}"/>
                                </td>
                                <td class="dataCell" width="70px" style="text-align:center" >
                                    <apex:outputField value="{!ar.rec.InstallDate}" id="InstallDate" rendered="{!Not(ar.IsManual)}" />
                                </td>
                                <!--add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star-->
                                <td class="dataCell" width="70px" style="text-align:center" >
                                    <apex:inputCheckbox value="{!ar.mcae.Check_Object__c}" id="assetCheck" disabled="{!ar.CheckRows}"/>
                                </td>
                                <!--add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk end-->
                                <td class="dataCell" width="40px" style="text-align:center" >
                                    <apex:inputCheckbox value="{!ar.mcae.IsNew__c}" id="assetNew" disabled="true"/>
                                    <apex:outputPanel layout="none" rendered="{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.createable}" >
                                        <apex:inputHidden value="{!ar.mcae.IsNew__c}" id="assetNewHidden" />
                                    </apex:outputPanel>
                                    <apex:outputPanel layout="none" rendered="{!Not($ObjectType.Maintenance_Contract_Asset_Estimate__c.createable)}" >
                                        <input type="hidden" value="{!ar.mcae.IsNew__c}" id="allPage:allForm:allBlock:assetSection:assetTable:{!Text(cnt-1)}:assetNewHidden" />
                                    </apex:outputPanel>
                                    <apex:outputText value="{!ar.rec.Final_Examination_Date__c}" id="finalExaminationDate" rendered="{!Not(ar.IsManual)}" style="display:none"/>
                                </td>
                                <td class="dataCell" width="70px" >
                                    <apex:outputField value="{!ar.rec.Department_Name__c}" rendered="{!Not(ar.IsManual)}" />
                                </td>
                               
                                <td class="dataCell" width="70px">
                                    <apex:outputField value="{!ar.rec.CurrentContract_F__r.Maintenance_Contract_No_F__c}" rendered="{!Not(ar.IsManual)}" id="Contract_No"/>
 
                                    <apex:inputHidden value="{!ar.rec.CurrentContract_F__r.RecordType_DeveloperName__c}" id="LastMContractRecord"/>
                                    <apex:inputField value="{!ar.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c}" id="endDateGurantee_Text" style="display: none" showDatePicker="false"/>
                                    <apex:inputHidden value="{!ar.rec.CurrentContract_F__c}" id="LastMContractID"/>
                                    <!-- 市场多年保价格开发 start 20223/01/17 维修合同/保有设备 设备消费率 -->
 
 
                                    <!-- <apex:outputField value="{!ar.rec.CurrentContract_F_asset__r.IS_VMContract_Asset__c}" rendered="{!Not(ar.IsManual)}" id="IS_VMContract_Asset"/> -->
 
                                    <apex:inputHidden value="{!ar.rec.CurrentContract_F_asset__r.Asset_Consumption_Rate__c}" id="AssetConsumptionRateNew"/>
 
                                    <apex:inputHidden value="{!ar.rec.CurrentContract_F_asset__r.Maintenance_Price_Year__c}" id="Maintenance_Price_Year__c"/>
 
                                 <!--    <apex:inputField value="{!ar.rec.CurrentContract_F_asset__r.Asset_Consumption_Rate__c}" id="AssetConsumptionRateNew2" style="display: none" showDatePicker="false" />
 
                                    <apex:outputText value="{!ar.rec.CurrentContract_F_asset__r.Asset_Consumption_Rate__c}" id="AssetConsumptionRateNew3" rendered="{!Not(ar.IsManual)}" style="display: none"/> -->
 
                                    <apex:inputField value="{!ar.rec.Product2.Asset_Model_No__c}" id="Asset_Model_No__c" style="display: none" showDatePicker="false"/>
 
                                    <apex:inputField value="{!ar.rec.Product2.Category4__c}" id="Category4__c" style="display: none" showDatePicker="false"/>
                                    <!-- 市场多年保价格开发 end 20223/01/17 设备消费率 -->
 
                                </td>
                                 <!-- 市场多年保价格开发 end 20223/02/20 是否多年保设备 start -->
                                <td class="dataCell" width="90px" style="text-align:center">
                                    <apex:outputField value="{!ar.rec.CurrentContract_F_asset__r.IS_VMContract_Asset__c}" rendered="{!Not(ar.IsManual)}" id="IS_VMContract_Asset"/>
                                </td>
                                 <!-- 市场多年保价格开发 end 20223/02/20 是否多年保设备 end -->
 
                                <td class="dataCell" width="90px" style="text-align:right" >
                                    <apex:outputField value="{!ar.mcae.Asset_Consumption_rate__c}" rendered="{!Not(ar.IsManual)}" id="Contractrate"/>
                                    <apex:inputHidden value="{!ar.rec.CurrentContract_F__r.Contract_Range__c}" id="lastContRange"/>
                                </td>
                                <!-- 2023/03/21  !ar.rec.CurrentContract_F_asset__r.IS_VMContract_Asset__c 为true  保有设备结束时间:true:多年保:保修期至;false.最近一期维修合同结束日 -->
                                <td class="dataCell" width="70px">
                                    <!-- old: 直接拿保有设备的最近一期维修合同 -->
                                    <!-- <apex:outputField value="{!ar.rec.CurrentContract_F__r.Contract_End_Date__c}" rendered="{!(Not(ar.IsManual)&& ar.rec.CurrentContract_F__c != null)}" id="End_Date" /> -->
                                    <!-- new: 在获取保有设备信息时直接判断保有设备的字段时间(保修期至/最近一期维修合同结束日) -->
                                    <apex:outputField value="{!ar.rec.CurrentContract_End_Date__c}" rendered="{!(Not(ar.IsManual) && ar.rec.CurrentContract_F__c != null )}" id="End_Date" />
                                </td>
 
                                 <!-- 实绩联动价格计算 start -->
                                <td class="dataCell" width="35px">
                                    <apex:outputText value="{!ar.mcae.Adjustment_Upper_price__c}" id="Adjustment_Upper_price"/>
                                    <apex:inputHidden value="{!ar.mcae.Adjustment_Upper_price__c}" id="Adjustment_Upper_priceHidden"/>
                                    <apex:inputHidden value="{!ar.mcae.Adjustment_ratio_Upper__c}" id="Adjustment_ratio_Upper"/>
                                </td>
                                <td class="dataCell" width="35px" >
                                    <apex:outputText value="{!ar.mcae.Adjustment_Lower_price__c}" id="Adjustment_Lower_price"/>
                                  <!--   // 服务合同报价规则改善 20230227 start -->
                                      <!-- <apex:inputHidden value="{!ar.ISStandardPricing}" id="ISStandardPricing" /> -->
 
                                  <!-- // 服务合同报价规则改善 20230227 end -->
                                    <apex:inputHidden value="{!ar.mcae.LastMContract_Price__c}" id="LastMContract_Price"/>
                                    <apex:inputHidden value="{!ar.mcae.Adjustment_ratio_Lower__c}" id="Adjustment_ratio_Lower"/>
                                    <apex:inputHidden value="{!ar.mcae.Adjustment_Lower_price__c}" id="Adjustment_Lower_priceHidden"/>
                                    <apex:outputPanel layout="none" rendered="{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.createable}" >
                                        <apex:inputHidden value="{!ar.mcae.Estimate_List_Price__c}" id="assetListPriceHidden"/>
                                        <apex:inputHidden value="{!ar.mcae.Estimate_List_Price_Page__c}" id="assetListPricePageHidden" />
                                        <apex:inputHidden value="{!ar.rec.CurrentContract_F__r.Estimate_Num__c}" id="Estimate_NumHidden" />
 
                                    </apex:outputPanel>
                                    
                                    <apex:outputPanel layout="none" rendered="{!Not($ObjectType.Maintenance_Contract_Asset_Estimate__c.createable)}" >
                                        <input type="hidden" value="{!ar.mcae.Estimate_List_Price__c}" id="allPage:allForm:allBlock:assetSection:assetTable:{!Text(cnt-1)}:assetListPriceHidden"/>
                                        <input type="hidden" value="{!ar.rec.CurrentContract_F__r.Estimate_Num__c}" id="allPage:allForm:allBlock:assetSection:assetTable:{!Text(cnt-1)}:Estimate_NumHidden"/>
                                    </apex:outputPanel>
                                    <!-- 20200103 Gzw 计算实际报价金额 start -->
                                        <apex:inputHidden value="{!ar.mcae.Estimate_Cost__c}" id="Estimate_Cost"/>
                                    <!-- 20200103 Gzw 计算实际报价金额 end -->
 
                                </td>
                                <td class="dataCell" width="35px" style="text-align:right" >
                                    <apex:inputField value="{!ar.mcae.Repair_Price__c}" id="repairPrice" style="ime-mode: disabled; width:95%; text-align:right;" onchange="changeAsset({!productCount})"/>
                                </td>
                               <!-- (2022年12月上线)故障品加费 start -->
                                <td class="dataCell" width="35px" style="text-align:right" >
                                     <!-- // 报价规则改善 20230308 start -->
                                  <!--   <apex:inputField value="{!ar.mcae.Blank_period__c}" id="Blank_period" style="display:none"/> -->
                                     <!-- // 报价规则改善 20230308 start -->
                                    <apex:outputText value="{!ar.Repair_Price_Auto}" id="Repair_Price_Auto" style="width:95%; "/>
                                    <!-- <apex:inputHiddenalue="{!ar.rec.Reson_Can_not_Warranty__c}" id="ResonCannotWarranty"/> -->
                                    <!-- <apex:outputText value="{!ar.Agreed_Date}" id="Agreed_Date" style="width:95%;display: none;"/> -->
                                    <apex:inputField value="{!ar.mcae.Repair_Price_pass__c}" id="Repair_Price_pass" style="width:95%;display: none;"/>
                                    <apex:inputHidden value="{!ar.mcae.IS_Reduced_price_approval__c}" id="ISReducedpriceapproval1"/>
                                     <apex:outputText value="{!ar.rec.Reson_Can_not_Warranty__c}" id="ResonCannotWarranty" style="display:none;" rendered="{!Not(ar.IsManual)}" /> 
                                </td>
                                
                                <!-- (2022年12月上线)故障品加费 end -->
                                <td class="dataCell" width="70px" style="text-align:right" >
                                    <apex:inputField value="{!ar.mcae.Comment__c}" id="comment" style="width:95%;"/>
                                </td>
                                <!--(2022年12月上线)故障品加费 第三方回归  -->
                                <td class="dataCell" width="40px" style="text-align:center;" >
                                    <apex:inputCheckbox value="{!ar.mcae.Third_Party_Return__c}" id="Third_Party_Return__c"/>
                                </td>
                            </tr>
 
                            <!-- LJPH-C9SCX7 【委托】合同无空白期的提醒  lt  20211221  start  -->
                            <!-- <script>
                                DefaultStartDate();
                            </script> -->
                            <!-- LJPH-C9SCX7 【委托】合同无空白期的提醒  lt  20211221  end  -->
 
                            <apex:variable value="{!cnt + 1}" var="cnt" />
                        </apex:repeat>
 
                </table>
                    </div>
<!-- </div>
         </div> -->
            </apex:outputPanel>
        </apex:pageblocksection>
        <!-- HWAG-B4R3SS  START 20181026-->
        <apex:outputPanel id="sumPanel"  onkeydown="if(event.keyCode==13){searchJs(); return false;}">
        <!-- HWAG-B4R3SS  END 20181026-->
            <table style="width:100%;">
                <tr>
 
                    <td>
                        <apex:commandButton value="行追加" action="{!addNewRows}" disabled="{!Not($ObjectType.Maintenance_Contract_Asset_Estimate__c.createable) || PageDisabled}"
                            style="margin-left:10px;float:left;" onclick="blockme();" oncomplete="unblockUI();" rerender="allForm" />
                        <apex:commandButton value="刷新选中的保有设备" disabled="{!SaveBtnDisabled || productCount2==0}" action="{!exchangeAsset}" onclick="blockme();" oncomplete="unblockUI();refreshAsset({!productCount});" rerender="allForm" />
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <!-- HWAG-B4R3SS  START 20181026-->
                        <apex:outputText value="选择条件"/>
                        &nbsp;&nbsp;
                        <apex:selectList value="{!text1}" id="text1" size="1" style="width:80px"><apex:selectOptions value="{!textOpts}"/>
                        </apex:selectList>
                        &nbsp;&nbsp;
                        <apex:selectList value="{!cond1}" id="cond1" size="1" style="width:80px">
                        <apex:selectOptions value="{!equalOpts}"/>
                        </apex:selectList>
                        &nbsp;&nbsp;
                        <!-- LJPH-BSS6E2  ---20200911 ---update by rentongxiao start -->
 
                        <apex:inputText value="{!val1}" 
                        id="val1" style="width:100px; background-color:{!IF(contr == '1','#e3f3ff','white')}"/>
                        <!-- LJPH-BSS6E2  ---20200911 ---update by rentongxiao end -->
                        &nbsp;
                        <apex:commandButton value="检索" onclick="searchJs();" style="width:100px" rerender="dummy"/>
                        &nbsp;
                        <apex:commandButton value="清除条件" onclick="clearAndSearch();" style="width:100px" rerender="dummy"/>
                        <!-- HWAG-B4R3SS END 20181026-->
                    </td>
                    <th width="90px" style="text-align:right"></th>
                    <th width="90px" style="text-align:right"></th>
 
                    <th width="90px" style="text-align:right">设备数量</th>
                    <td width="90px" style="text-align:right"><apex:outputtext value="{!productCount3}" id="productCount3"/></td>
                    <td width="25px">&nbsp;</td>
                    <th width="90px" style="text-align:right">
                        <apex:inputField value="{!estimate.IS_Reduced_price_approval__c}" id="ISReducedpriceapproval" style="display:none"/></th>
                         <!-- <apex:inputField value="{!estimate.IS_Reduced_price_approval__c}" id="ISReducedpriceapproval"/></th> -->
                    <td width="25px">&nbsp;</td>
                    <!--<th width="90px" style="text-align:right">报价总额</th>
                    <th width="90px" style="text-align:right"><span id="allPage:allForm:allBlock:assetListSumNum" ></span></th>-->
                    <th width="90px" style="text-align:right">修理总额</th>
                    <th width="90px" style="text-align:right"><span id="allPage:allForm:allBlock:assetRepairSumNum" ></span></th>
                    <td width="95px">&nbsp;</td>
                </tr>
 
            </table>
        </apex:outputPanel>
        
        <apex:pageblocksection columns="1" title="未选择的保有设备" id="assetSection2" >
            <apex:outputLabel />
            <apex:outputPanel >
                <input type="hidden" id="allPage:allForm:allBlock:assetSection2:productCnt2" value="{!productCount2}" />
                <table class="list" style="border-bottom-width: 0px; font-size:13px;" border="0" cellspacing="0" cellpadding="0">
                    <tr class="headerRow" height="30px">
                        <th style="width:25px" class="headerRow  booleanColumn"><input type='checkbox' onClick='checkAll2(this)'/></th>
                        <th style="width:25%" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Name.label}</th>
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Asset_situation__c.label}</th>
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.SerialNumber.label}</th>
                        <th class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Department_Name__c.label}</th>
                        <!-- <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Installation_Site__c.label}</th> -->
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.IF_Warranty_Service__c.label}</th>
                         <!-- //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start -->
                        <th style="width:90px" class="headerRow  booleanColumn">主机/耗材</th>
                         <!-- //JZHG-BSDUT4 ---20200825---update By rentongxiao---End -->
 
                        <th class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.EGFlg_fromContract_asset__c.label}</th>
                        <th style="width:150px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Reson_Can_not_Warranty__c.label}</th>
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.InstallDate.label}</th>
                        <!-- <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Asset_Owner__c.label}</th> -->
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Asset.fields.Accumulation_Repair_Amount__c.label}</th>
                        <th style="width:90px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Estimate_List_Price__c.label}</th>
                    </tr>
 
                    <apex:variable value="{!1}" var="cnt" />
                    <apex:repeat value="{!unCheckedAssetsView}" var="assetsView" id="outassetTable2">
                        <apex:repeat value="{!assetsView}" var="ar" id="assetTable2">
                            <tr class="dataRow {!IF(MOD(cnt, 2)==0, 'odd', 'even')} {!IF(cnt==1, 'first', '')}" onmouseover="if (window.hiOn){hiOn(this);} " onmouseout="if (window.hiOff){hiOff(this);} " onblur="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}">
                                <td class="dataCell" width="25px">
                                    <apex:inputCheckbox value="{!ar.rec_checkBox_c}" id="assetRowCheckbox2" disabled="{!IF(ar.rec.Maintenance_Price_Month__c == 0 || ar.rec.IF_Warranty_Service__c = '否', 'true', 'false')}"/>
                                </td>
                                <td class="dataCell" width="25%">
                                    <apex:outputField value="{!ar.rec.name}" id="assetName"/>
                                </td>
                                <td class="dataCell" width="70px">
                                    <apex:outputField value="{!ar.rec.Asset_situation__c}"/>
                                </td>
                                <td class="dataCell" width="70px">
                                    <apex:outputField value="{!ar.rec.SerialNumber}"/>
                                </td>
                                <td class="dataCell">
                                    <apex:outputField value="{!ar.rec.Department_Name__c}"/>
                                </td>
                                <!-- <td class="dataCell" width="70px">
                                    <apex:outputField value="{!ar.rec.Installation_Site__c}"/>
                                </td> -->
                                <td class="dataCell" width="90px" style="text-align:center">
                                    <apex:outputField value="{!ar.rec.IF_Warranty_Service__c}"/>
                                </td>
                                 <!-- //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start -->
                                <td class="dataCell" width="90px" style="text-align:center">
                                    <apex:outputField value="{!ar.rec.AssetMark__c}"/>
                                </td>
                                 <!-- //JZHG-BSDUT4 ---20200825---update By rentongxiao---End -->
                                <td class="dataCell" style="text-align:center" >
                                    <apex:outputField value="{!ar.rec.EquipmentGuaranteeFlg__c}"/>
                                </td>
                                <td class="dataCell" width="150px" style="text-align:center">
                                    <apex:outputField value="{!ar.rec.Reson_Can_not_Warranty__c}"/>
                                </td>
                                <td class="dataCell" width="90px" style="text-align:center" >
                                    <apex:outputField value="{!ar.rec.InstallDate}"/>
                                </td>
                                <!-- <td class="dataCell" width="90px">
                                    <apex:outputField value="{!ar.rec.Asset_Owner__c}"/>
                                </td> -->
                                <td class="dataCell" width="90px" style="text-align:right" >
                                    <apex:outputField value="{!ar.rec.Accumulation_Repair_Amount__c}"/>
                                </td>
                                <td class="dataCell" width="90px" style="text-align:right" >
                                    <apex:outputField value="{!ar.rec.Maintenance_Price_Month__c}" />
                                </td>
                            </tr>
                            <apex:variable value="{!cnt + 1}" var="cnt" />
                        </apex:repeat>
                    </apex:repeat>
                </table>                
                <apex:outputPanel >
                    <dir align="right">
                        <table>
                            <tr>
                                <td>{!(currPage-1)*selctRecordNum}&nbsp;-&nbsp;{!IF(currPage*selctRecordNum > totalRecords, totalRecords, currPage*selctRecordNum)}</td>
                                <td>&nbsp;&nbsp;共{!totalRecords}个</td>
                                <td align="right" width="115px">显示
                                    <apex:selectList value="{!selRecordOption}" id="selRecordOption" size="1" onchange="blockme();recordNumChangeJs();" disabled="{!IF(totalRecords<10,true,false)}"><apex:selectOptions value="{!recordNum}"/></apex:selectList>条记录
                                </td>
                                <td align="right" width="50px">第{!currPage}页</td>
                                <td align="right" width="45px">
                                    <apex:commandLink action="{!firstPage}" value="首页" id="firstPg" onclick="blockme();" oncomplete="unblockUI();" reRender="allForm" style="{!IF(currPage==1,'display: none;','')}color: blue;"/>
                                    <apex:outputText value="首页" style="{!IF(currPage!=1,'display: none;','')}color: gray;"></apex:outputText>
                                </td>
                                <td align="right" width="40px">
                                    <apex:commandLink action="{!previousPage}" value="上一页" id="previous" onclick="blockme();" oncomplete="unblockUI();" reRender="allForm" style="{!IF(currPage==1,'display: none;','')}color: blue;"/>
                                    <apex:outputText value="上一页" style="{!IF(currPage!=1,'display: none;','')}color: gray;"></apex:outputText>
                                </td>
                                <td width="3px"></td>
                                <td align="left" width="40px">
                                    <!-- HWAG-B4R3SS  START 20181026-->
                                    <apex:commandLink action="{!nextPage}" value="下一页" id="next" onclick="blockme();" oncomplete="unblockUI();" reRender="allForm" style="{!IF(totalPage==currPage ||totalPage == 0,'display: none;','')}color: blue;"/>
                                    <apex:outputText value="下一页" style="{!IF(totalPage!=currPage && totalPage != 0,'display: none;','')}color: gray;"></apex:outputText>
                                </td>
                                <td align="left" width="45px">
                                    <apex:commandLink action="{!endPage}" value="尾页" id="endPg" onclick="blockme();" oncomplete="unblockUI();" reRender="allForm" style="{!IF(totalPage==currPage||totalPage == 0,'display: none;','')}color: blue;"/>
                                    <apex:outputText value="尾页" style="{!IF(totalPage!=currPage
                                        && totalPage != 0,'display: none;','')}color: gray;"></apex:outputText>
                                </td>
                                <!-- HWAG-B4R3SS  END 20181026-->
                                <td align="left">共{!totalPage}页</td>
                            </tr>
                        </table>
                    </dir>
                </apex:outputPanel>
            </apex:outputPanel>
        </apex:pageblocksection>
        <apex:pageblocksection title="合同信息" columns="1" id="contractInfo">
            <apex:outputLabel />
            <apex:outputPanel >
                <table style="width:100%">
                    <tr>
                        <td width="22%"></td>
                        <!-- <td width="14%"></td> -->
                        <td width="22%"></td>
                        <td width="28%"></td>
                        <td width="14%"></td>
                        <td width="14%"></td>
                    </tr>
                    <tr>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.GuidePrice_Down__c.label}</th>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.GuidePrice_Up__c.label}</th>
                        <th style="text-align: center">申请报价金额</th>
                        <th style="text-align: center">合同设备修理总额</th>
                        <th style="text-align: center">合同总金额</th>
                        <!-- 上限合同 20230103 hql start -->
                        <th style="text-align: center">上限金额</th>
                        <!-- 上限合同 20230103 hql end -->
                    </tr>
                    <tr>
                        <td style="text-align: center">
                            <apex:outputField value="{!estimate.GuidePrice_Down__c}" id="GuidePriceDown" />
                            <apex:inputHidden value="{!estimate.GuidePrice_Down__c}" id="GuidePriceDownHidden" />
                        </td>
                        <td style="text-align: center">
                            <apex:outputField value="{!estimate.GuidePrice_Up__c}" id="GuidePriceUp" />
                            <apex:inputHidden value="{!estimate.GuidePrice_Up__c}" id="GuidePriceUpHidden" />
                        </td>
                        
                        <td style="text-align: center">
                            <!--<apex:inputField value="{!estimate.Request_quotation_Amount__c}" id="quotation_Amount" />-->
                            <apex:inputField value="{!estimate.Request_quotation_Amount__c}" style="ime-mode: disabled; text-align: right; width:100px" id="quotation_Amount" onchange="checkDiscount(this.value);"/>
                        </td>
                        <td style="text-align: center">
                            <apex:outputField value="{!estimate.Asset_Repair_Sum_Price__c}" id="assetRepairSumPrice" />
                            <apex:inputHidden value="{!estimate.Asset_Repair_Sum_Price__c}" id="assetRepairSumPriceHidden" />
                        </td>
                        <td style="text-align: center">
                            <apex:outputField value="{!estimate.Maintenance_Price__c}" id="mainteReal"/>
                            <apex:inputHidden value="{!estimate.Maintenance_Price__c}" id="mainteRealHidden"/>
                            <apex:inputHidden value="{!OldMaintenancePrice}" id="oldMainteReal"/>
                        </td>
                        <!-- 上限合同 20230103 hql start -->
                        <td style="text-align: center">
                            <apex:inputField value="{!estimate.Limit_Price_Amount__c}" style="ime-mode: disabled; text-align: right; width:100px" id="Limit_Price_Amount" />
                            <apex:inputHidden value="{!isLimitPrice}" id="Limit_Price2Hidden" />
                            <apex:inputHidden value="{!OldLimitPrice}" id="Limit_PriceHidden" />
                            <!-- // 报价规则改善 20230309 start  -->
                            <!-- <apex:inputHidden value="{!Is_Blank_period}" id="Is_Blank_period" />
                            <apex:inputField value="{!estimate.Maintenance_Contract__r.Past_Contract_end_day__c}" style="display:none"  id="PastContractendday" />
                            <apex:inputHidden value="{!estimate.renewTen_OFF__c}" id="renewTenOFF" />
                            <apex:inputHidden value="{!Cost_rate_ForecastF}" id="Cost_rate_ForecastF" /> -->
                            <!-- // 报价规则改善 20230309 end  -->
                        </td>
                        <!-- 上限合同 20230103 hql end -->
                    </tr>
                    <tr>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.Service_discount_Rate__c.label}</th>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.New_Contract_Type_TxT__c.label}</th>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.Combined_rate__c.label}</th>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.Consumption_rate_Forecast__c.label}</th>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.Estimate_Price_range__c.label}</th>
                    </tr>
                    <tr>
                        <td style="text-align: center">
                            <apex:outputField value="{!estimate.Service_discount_Rate__c}" id="discount_Rate"/>
                            <apex:inputHidden value="{!estimate.Service_discount_Rate__c}" id="discount_RateHidden" />
                        </td>
                        <td style="text-align: center">
                            <apex:outputText value="{!estimate.New_Contract_Type_TxT__c}" id="Contract_TypeTXT" />
                            <apex:inputHidden value="{!typeresult}" id="Contract_TypeTXTHidden" />
                        </td>
                        <td style="text-align: center">
                            <apex:outputField value="{!estimate.Combined_rate__c}" id="Combinedrate" />
                            <apex:inputHidden value="{!estimate.Combined_rate__c}" id="CombinedrateHidden" />
                        </td>
                        <td style="text-align: center">
                            <apex:outputField value="{!estimate.Consumption_rate_Forecast__c}"  />
                        </td>
                        <td style="text-align: center">
                            <apex:outputField value="{!estimate.Estimate_Price_range__c}"  />
                        </td>
                    </tr>
                    <tr>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.ContractPriceType__c.label}</th>
                        <th style="text-align: center"></th>
                        <th style="text-align: center"></th>
                        <th style="text-align: center"></th>
                        <th style="text-align: center"></th>
                    </tr>
                    <tr>
                        <td style="text-align: center">
                            <apex:outputField value="{!estimate.ContractPriceType__c}"/>
                        </td>
                        <td style="text-align: center"></td>
                        <td style="text-align: center"></td>
                        <td style="text-align: center"></td>
                        <td style="text-align: center"></td>
                    </tr>
                </table>
                <!-- // 报价规则改善 20230309 start  -->
               <!--  <table style="width:100%">
                    <tr>
                        <th style="text-align: center" colspan="3">请结合实际可以签约的日期,选择恰当的申请金额,以免后续空白期变化导致标准金额变化,再次申请价格延误时间</th>
                        <th style="text-align: center"></th>
                        <th style="text-align: center"></th>
                    </tr>
                    <tr>
                        <th style="text-align: center">本次计划【合同预定开始日】:<input type="text" id="startdateaddsix4" readonly="readonly" style="border: none;width:70px"></input> </th>
                        <th style="text-align: center">标准价格的最低价总额</th>
                        <th style="text-align: center">标准价格的最高价总额</th>
                    </tr>
                    <tr>
                        <td style="text-align: center"></td>
                        <td style="text-align: center">
                            CNY<input type="text" id="GuidePriceDown5" readonly="readonly" style="border: none;width:70px"></input> 
                        </td>
                        <td style="text-align: center">
                            CNY<input type="text" id="GuidePriceUp5" readonly="readonly" style="border: none;width:70px"></input> 
                        </td>
                    </tr>
                    <tr>
                        <th style="text-align: center">当【合同预定开始日】在<input type="text" id="startdateaddsix1" readonly="readonly" style="border: none;width:70px"></input> 之前</th>
                        <th style="text-align: center">标准价格的最低价总额</th>
                        <th style="text-align: center">标准价格的最高价总额</th>
                    </tr>
                    <tr>
                        <td style="text-align: center"></td>
                        <td style="text-align: center">
                            CNY<input type="text" id="GuidePriceDown4" readonly="readonly" style="border: none;width:70px"></input> 
                        </td>
                        <td style="text-align: center">
                            CNY<input type="text" id="GuidePriceUp4" readonly="readonly" style="border: none;width:70px"></input> 
                        </td>
                    </tr>
                    <tr>
                        <th style="text-align: center">当【合同预定开始日】在<input type="text" id="startdateaddsix2" readonly="readonly" style="border: none;width:70px"></input> 之后</th>
                        <th style="text-align: center">标准价格的最低价总额</th>
                        <th style="text-align: center">标准价格的最高价总额</th>
                    </tr>
                    <tr>
                        <td style="text-align: center"></td>
                        <td style="text-align: center">
                            CNY<input type="text" id="GuidePriceDown3" readonly="readonly" style="border: none;width:70px"></input> 
                        </td>
                        <td style="text-align: center">
                            CNY<input type="text" id="GuidePriceUp3" readonly="readonly" style="border: none;width:70px"></input> 
                        </td>
                    </tr>
                    <tr>
                        <th style="text-align: center">当【合同预定开始日】在<input type="text" id="startdateaddsix3" readonly="readonly" style="border: none;width:70px"></input> 之后</th>
                        <th style="text-align: center">标准价格的最低价总额</th>
                        <th style="text-align: center">标准价格的最高价总额</th>
                    </tr>
                    <tr>
                        <td style="text-align: center"></td>
                        <td style="text-align: center">
                            CNY<input type="text" id="GuidePriceDown2" readonly="readonly" style="border: none;width:70px"></input> 
                        </td>
                        <td style="text-align: center">
                            CNY<input type="text" id="GuidePriceUp2" readonly="readonly" style="border: none;width:70px"></input> 
                        </td>
                    </tr>
                </table> -->
                <!-- // 报价规则改善 20230309 end  -->    
            </apex:outputPanel>
        </apex:pageblocksection>
 
        <apex:pageblocksection title="申请背景" columns="1" id="Appbackground">
            <apex:outputLabel />
            <apex:outputPanel >
                <table style="width:100%">
                    <tr>
                        <td width="10%"></td>
                        <td width="30%"></td>
                        <td width="10%"></td>
                        <td width="50%"></td>
                    </tr>
                    <tr>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.finalPriceDecideWay__c.label}</th>
                        <td><apex:inputField value="{!estimate.finalPriceDecideWay__c}" id="finalPriceDecideWay" style="width:50%;" /></td>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.Sales_incidental__c.label}</th>
                        <td><apex:inputField value="{!estimate.Sales_incidental__c}" id="Sales_incidental" style="width:50%;" /></td>
                    </tr>
                    <tr>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.mainTalksTime__c.label}</th>
                        <td ><apex:inputField value="{!estimate.mainTalksTime__c}"  style="width:50%;" id="mainTalksTime"/></td>
                        <th>{!$ObjectType.Maintenance_Contract_Estimate__c.fields.talksStartDate__c.label}</th>
                        <td><apex:inputField value="{!estimate.talksStartDate__c}" id="talksStartDate" style="width:50%;"  /></td>
                    </tr>
                    <tr>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.AgencyHos_Price__c.label}</th>
                        <td ><apex:inputField value="{!estimate.AgencyHos_Price__c}"  style="width:50%;" id="AgencyHos_Price"/></td>
                        <th style="text-align: center"></th>
                        <td ></td>
                    </tr>
                    <tr>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.Discount_reason__c.label}</th>
                        <td colspan="3"><apex:inputField value="{!estimate.Discount_reason__c}" id="discountReason" style="width:95%;height:50px;" /></td>
                    </tr>
                    <tr>
                        <th style="text-align: center">{!$ObjectType.Maintenance_Contract_Estimate__c.fields.Improve_ConsumptionRate_Idea__c.label}</th>
                        <td colspan="3"><apex:inputField value="{!estimate.Improve_ConsumptionRate_Idea__c}" id="improveConsumptionRateIdea" style="width:95%;height:50px;" /></td>
                    </tr>
                </table>
            </apex:outputPanel>
            <script type="text/javascript">
                //var applyType = j$(escapeVfId('allPage:allForm:allBlock:Appbackground:applyType')).val();
                //var obj = document.getElementById('allPage:allForm:allBlock:Appbackground:TypeOther');
                //if (applyType == '其他') {
                //    obj.style.display = "block";
                //} else {
                //    obj.style.display = "none";
                //} 
                //resetapplyType();
            </script>
        </apex:pageblocksection>
        
        <script type="text/javascript">
            var isDisabled = {!PageDisabled};
            if(!isDisabled){
                refreshAsset({!productCount});
            }
        </script>
    </apex:pageBlock>
 
    
    
    <table width="100%" border="0">
        <tr>
            <!-- <td width="40%" style="text-align: right;"> -->
            <td width="50%">
                <table border="0" style="background-color:#ffd6c1;" width="100%">
                    <tr>
                        <th width="50px">打印报价</th>
                        <td width="90px"><apex:inputCheckbox id="check0" onchange="hideSimplify(0);" value="{!estimate.Print_ListPrice__c}" />完整版+折扣前</td>
                        <td width="90px"><apex:inputCheckbox id="check1" onchange="hideSimplify(1);" value="{!estimate.Print_Simplify__c}" />完整版+折扣后</td>
 
                        <td width="80px"><apex:inputCheckbox id="check2" onchange="hideSimplify(2);" value="{!estimate.Print_RepairPrice__c}"/>简化版+折扣前</td>
                        <td width="80px"><apex:inputCheckbox id="check3" onchange="hideSimplify(3);" value="{!estimate.Print_SumPrice__c}"/>简化版+折扣后</td>
                    </tr>
                    <tr>
                        <th width="70px">打印合同配置</th>
                        <td width="60px">
 
                        <!-- 2018/10/26HWAG-B5C88S 医院和经销商合同任何时候都不能选择 start -->
 
                            <apex:outputPanel rendered="false">
                                <apex:inputCheckbox value="{!estimate.Print_Contract__c}" />
                            </apex:outputPanel>
                            <apex:outputPanel rendered="{!Not(EnablePrintContract)}">
                                &nbsp;&nbsp;&nbsp;
                            </apex:outputPanel>
                            医院合同
                        </td>
                        <!-- 2018/09/26 HWAG-B4SCR3 三方和代理商合同在未decide前也不能选择 start -->
                        <td width="60px">
                            <apex:outputPanel rendered="{!EnablePrintContract}">
                                <apex:inputCheckbox id="tripartite" value="{!estimate.Print_Tripartite__c}"/>
                            </apex:outputPanel>
                            <apex:outputPanel rendered="{!Not(EnablePrintContract)}">
                                &nbsp;&nbsp;&nbsp;
                            </apex:outputPanel>
                        三方协议</td>
                        <td width="85px">
                            <apex:outputPanel rendered="false">
                                <apex:inputCheckbox id="agent" value="{!estimate.Print_Agent__c}"/>
                            </apex:outputPanel>
                            <apex:outputPanel rendered="{!Not(EnablePrintContract)}">
                                &nbsp;&nbsp;&nbsp;
                            </apex:outputPanel>
                        代理商合同</td>
                        <!-- 2018/09/26  HWAG-B4SCR3 三方和代理商合同在未decide前也不能选择 end -->
                        <!-- 2018/10/26 HWAG-B5C88S 医院和经销商合同任何时候都不能选择 end --> 
                                      
                        <td colspan="3" style="text-align: right"><apex:commandButton action="{!print}" value="PDF印刷" rerender="allBlock,pdfPrint"  onclick="if (!onclickCheckchangedAfterPrint('Pt{!SaveBtnDisabled}','false')) return false;" oncomplete="unblockUI();ComputeLTYRepair()"/></td>
                    </tr>
                </table>
            </td>
            <td>
                <table class="btntable" border="0">
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td width="20px">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td width="30px">&nbsp;</td>
                        <!-- <td><apex:commandButton id="savebtn" action="{!save}" value="{!$Label.Save_Button}" disabled="{!SaveBtnDisabled}" rerender="allForm" onclick="if (!onclickCheckchangedAfterPrint('true','true')) return false;" oncomplete="unblockUI();"/></td> -->
                        <!-- 故障修理费  添加提交修理减价按钮  disabled="true" -->
                        <td><apex:commandButton id="emailSend" action="{!sendEmail}" value="提交RC评估" rerender="allForm" disabled="{!SendEmailBtnDisabled}" onclick="if (!EGFlgconfim()) return false;" oncomplete="unblockUI();"/></td>
                        <td>
                            <apex:commandButton id="approvalbtn1" action="{!toApprovalProcess}" value="提交修理减价审批" disabled="{!ApprovalBtnNewDisabled}" />
                        </td>
                        <td width="200px"><apex:commandButton id="approvalbtn" action="{!approvalProcess}" value="提交待审批" disabled="{!ApprovalBtnDisabled}" rerender="allForm" onclick="if (!KindsAndMonths()) return false;if (!EGFlgconfim()) return false;approvalJs();" oncomplete="unblockUI();toApprovalProcess();"/>
                        <!-- HWAG-B399Q8 2018/08/20 新增请提交待审批 提示字段 start-->
                        &nbsp; <apex:outputText style="color:red;font-size:20px;" value="请提交待审批" rendered="{!IS_Clone_After_Decide}"/>
                        <!-- HWAG-B399Q8 2018/08/20 新增请提交待审批 提示字段 end-->
                        </td>
                    </tr>
                    <tr>
                        <th>{!$ObjectType.Maintenance_Contract_Estimate__c.fields.Contract_Start_Date__c.label}</th>
                        <td><apex:inputField value="{!estimate.Contract_Start_Date__c}" id="contractstartdate" onchange="changeContractStartdate(this.value);"/></td>
                        <td>&nbsp;</td>
                        <th>&nbsp;&nbsp;{!$ObjectType.Maintenance_Contract_Estimate__c.fields.Contract_End_Date__c.label}</th>
                        <td><apex:outputField value="{!estimate.Contract_End_Date__c}" id="contractenddate"/></td>
                        <td>&nbsp;</td>
                        <td><apex:commandButton id="decidebtn" value="{!$Label.QuoteDecision_Button}" disabled="{!DecideBtnDisabled}" onclick="decideJs(); return false;"/></td>
                           <td>  <apex:commandButton id="savebtn" action="{!save}" value="{!$Label.Save_Button}" disabled="{!SaveBtnDisabled}" rerender="allForm" onclick="if (!EGFlgconfim()) return false;" oncomplete="unblockUI();"/>
                        </td>
                        <!-- <td><apex:commandButton id="decidebtn1" value="{!$Label.QuoteDecision_Button}" action="{!dosomething}"/></td> -->
                        <td style="text-align:right"><apex:commandButton id="undecidebtn" action="{!undecide}" value="取消{!$Label.QuoteDecision_Button}" disabled="{!UnDecideBtnDisabled}" rerender="allForm" onclick="blockme();" oncomplete="unblockUI();"/></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</apex:form>
<apex:outputPanel id="pdfPrint">
<script type="text/javascript">
//j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('false');
function saveBeforeCheckPriceChange() {
    sforce.connection.sessionId = Session_ID;
    var needClearId = false;
    var rowCnt = j$(escapeVfId('allPage:allForm:allBlock:assetSection:productCnt')).val();
    var assIds = "";
    var proIds = "";
    var priceMap = new Map();
    var newProductMap = new Map();
    var newProductCheck = false;
    var nowDate = new Date();
    var createdDate = null;
    var createdDateShow = j$(escapeVfId('allPage:allForm:allBlock:contract:createDateShow')).text();
    var contractDate = new Date(j$(escapeVfId('allPage:allForm:contractstartdate')).value());
    if (createdDateShow.trim() != '') {
        createdDate = new Date(createdDateShow);
        newProductCheck = true;
    } else {
        createdDate = new Date();
    }
    var threeMonthAfter = new Date(createdDate.setMonth(createdDate.getMonth() + 3));
    createdDate = new Date(createdDate.setMonth(createdDate.getMonth() - 3));
    for (var i = 0; i < rowCnt; i++) {
        var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
        var isnew = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetNewHidden')).val();
        var price = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':assetListPriceHidden')).val();
        if (isManual == 'true') {
            var a = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ProductId'));
            if (a.size() > 0 && a.value() != "000000000000000000" && a.value() != "") {
                if (proIds == "") {
                    proIds = "'" + a.value() + "'";
                } else {
                    proIds = proIds + ",'" + a.value() + "'";
                }
                if (isnew == "true") {
                    priceMap.set(a.value(), price/{!isNewPriceAdj});
                } else {
                    priceMap.set(a.value(), price);
                }
                newProductMap.set(a.value(), isnew);
                
            } else {
                continue;
            }
        }
        else {
            var aId = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetId')).value();
            if (assIds == "") {
                assIds = "'" + aId + "'";
            } else {
                assIds = assIds + ",'" + aId + "'";
            }
            if (isnew == "true") {
                priceMap.set(aId, price/{!isNewPriceAdj});
            } else {
                priceMap.set(aId, price);
            }
            newProductMap.set(aId, isnew);
        }
    }
    // 选择设备后价格变更check
    if (assIds.length > 0) {
        var sql = "SELECT Id, Maintenance_Price_Month__c, Posting_Date__c, InstallDate from Asset where Id In(" + assIds + ")";
        var rt = sforce.connection.query(sql);
        var asList = rt.getArray("records"); 
        if (asList != null) {
            for(var i=0;i<asList.length;i++) {
                var asvar = asList[i];
                var asId = asvar["Id"];
                var mprice = asvar["Maintenance_Price_Month__c"];
                var ptDt = asvar["Posting_Date__c"];
                var postingDate = null;
                if (ptDt != null && ptDt != '') {
                    postingDate = new Date(ptDt);
                }
                var inDt = asvar["InstallDate"];
                var installDate = null;
                if (inDt != null && inDt != '') {
                    installDate = new Date(inDt);
                }
                var priceShow = priceMap.get(asId);
                var isNew = newProductMap.get(asId);
                if ('{!DecideBtnDisabled}' == 'true') {
                    if (Number(mprice).toFixed(2) != Number(priceShow).toFixed(2)) {
                        needClearId = true;
                        // j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('true');
                        return needClearId;
                    }
                }
            }
        }
    }
    if (proIds.length > 0) {
        if ('{!DecideBtnDisabled}' == 'false') {
            var oldDateStr = j$('#oldContractDate').value();
            var oldDate = new Date();
            if (oldDateStr != null && oldDateStr != '') {
                oldDate = new Date(oldDateStr);
            }
            var crdt = new Date(j$(escapeVfId('allPage:allForm:allBlock:contract:createDateShow')).text());
            var newContractDate = new Date(j$(escapeVfId('allPage:allForm:contractstartdate')).value());
            var sixMonthAfter = new Date(crdt.setMonth(crdt.getMonth() + 6));
            if ((newContractDate > sixMonthAfter && oldDate <= sixMonthAfter) || (newContractDate <= sixMonthAfter && oldDate > sixMonthAfter)) {
                j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('true');
                return true;
            }
        } else {
            var sql = "SELECT Id, Maintenance_Price_Month__c from Product2 where Id In(" + proIds + ")";
            var rt = sforce.connection.query(sql);
            var pdList = rt.getArray("records");
            if (pdList != null) {
                for(var i=0;i<pdList.length;i++) {
                    var pdvar = pdList[i];
                    var pdId = pdvar["Id"];
                    var mprice = pdvar["Maintenance_Price_Month__c"];
                    var priceShow = priceMap.get(pdId);
                    if (Number(mprice).toFixed(2) != Number(priceShow).toFixed(2)) {
                        needClearId = true;
                        // j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('true');
                        return needClearId;
                    }
                }
            }
        }
    }
    // var changedPrice = j$(escapeVfId('allPage:allForm:changedSubmitPrice')).value();
    // if (changedPrice=='true') {
    //     needClearId = true;
    // }
    return needClearId;
}
 
// SelectAssetEstimateController#checkchangedAfterPrint と同じロジックにする必要があります。
// true 変更あり、false 変更なし
function checkchangedAfterPrint() {
    sforce.connection.sessionId = Session_ID;
    var needClearId = false;
    //j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('false');
    var changedPrice = j$(escapeVfId('allPage:allForm:changedSubmitPrice')).value();
    // 新規の場合、targetEstimateIdがない、判断いらない
    if ('{!targetEstimateId}' == '') return needClearId;
    if ('{!estimate.Quote_Date__c}' != '' || '{!estimate.Process_Status__c}' != '草案中') {
        // xud 20140529 ここは明細変更判断
        // xudan 20150729 ソート項目にIdを追加
        var sql = "SELECT Id, Asset__c, Asset__r.SerialNumber, Check_Result__c, Product_Manual__c,"
                + " Repair_Price__c, Comment__c, Maintenance_Contract_Estimate__r.Maintenance_Price__c,Third_Party_Return__c"
                + "  FROM Maintenance_Contract_Asset_Estimate__c"
                + " WHERE Maintenance_Contract_Estimate__c = '{!targetEstimateId}'"
                + " ORDER BY id,Asset__c,Product_Manual__c, Asset__r.SerialNumber, Asset__r.Name, Asset__r.Department_Name__c, Asset__r.InstallDate";
        var result = sforce.connection.query(sql);
        var mcaeList = result.getArray("records");
        var inputingList = [];
        var finalPrice = 0;
        // 画面入力値を整理(いらないものを対象外にする)
        var cntWithKara = {!productCount};
        for (var i = 0; i < cntWithKara; i++) {
            var isManual = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':IsManual')).text();
            if (isManual == 'true') {
                var a = j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':ProductId'));
                if (a.size() > 0 && a.value() != "000000000000000000" && a.value() != "") {
                    inputingList.push(
                        {'id' : '',
                         'Product_Manual__c' : a.value(),
                         'Check_Result__c' : j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':checkResult')).value(),
                         'Repair_Price__c' : localParseFloat(j$.trim(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value())),
                         'Comment__c': j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':comment')).value()
                        }
                    );
                } else {
                    continue;
                }
            }
            else {
                inputingList.push(
                    {'id' : j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':AssetId')).value(),
                     'Check_Result__c' : j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':checkResult')).value(),
                     'Repair_Price__c' : localParseFloat(j$.trim(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value())),
                     'Comment__c': j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':comment')).value()
                    }
                );
            }
        }
        //针对inputingList的重新排序
        var arrayMap = [];
        var ArrayOrderPMCnt = [];
        for(var i=0;i<mcaeList.length;i++){
            var mcaeVar = mcaeList[i];
            var AssetIDOrPMC = mcaeVar["Asset__c"]!=null?mcaeVar["Asset__c"]:mcaeVar["Product_Manual__c"];
            if(arrayMap[AssetIDOrPMC]!=null){
                arrayMap[AssetIDOrPMC] = i;
                ArrayOrderPMCnt[AssetIDOrPMC] = i;
            }else{
                // Product_Manual__c相同的话怎么办
                if(ArrayOrderPMCnt[AssetIDOrPMC]==null){
                    ArrayOrderPMCnt[AssetIDOrPMC] = i;
                }else{
                    var cacheArray = new Array();
                    cacheArray = ArrayOrderPMCnt[AssetIDOrPMC];
                    ArrayOrderPMCnt[AssetIDOrPMC] = cacheArray+','+i;
                }
                
            }
            
        }
        var inputingListCache = inputingList;
        var cntLength = mcaeList.length>inputingListCache.length?mcaeList.length:inputingListCache.length;
        if(mcaeList.length!=inputingListCache.length){
            needClearId = true;
            //j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('true');
            return needClearId;
        }
        inputingList = new Array(cntLength);
        var inputingListOut = new Array();
        for(var i=0;i<inputingListCache.length;i++){
            var InputIdOrPMc = inputingListCache[i].id!=""?inputingListCache[i].id:inputingListCache[i].Product_Manual__c;
            var thisArray = ArrayOrderPMCnt[InputIdOrPMc];
            if(thisArray.length!=null){
                thisArray = thisArray.split(',');
                var ORDERCnt = thisArray[0];
                thisArray.shift(); 
                thisArray = thisArray.join(','); 
                ArrayOrderPMCnt[InputIdOrPMc] = thisArray;
            }else{
                var ORDERCnt = thisArray;
            }
            if( ORDERCnt !=null){
                inputingList[ORDERCnt] = inputingListCache[i];
            }else{
                inputingList[ORDERCnt] = inputingListCache[i];
                inputingListOut.push(inputingListCache[i]);
            }
        }
        if( inputingListOut.length>0){
            for(var i = 0; i<inputingListOut.length;i++){
                inputingList.push(inputingListOut[i]);
            }
        }
        //20161122,测试发现Check_Result__c已停用,故而修改对应的Js判断部分
        /*
                            && (((mcae["Check_Result__c"] == null || mcae["Check_Result__c"] == "")
                                  && (inputing["Check_Result__c"] == null || inputing["Check_Result__c"] == "")
                                )
                                || mcae["Check_Result__c"] == inputing["Check_Result__c"]
                               )
        //==================================================================================
                            && (((mcae["Check_Result__c"] == null || mcae["Check_Result__c"] == "")
                                  && (inputing["Check_Result__c"] == null || inputing["Check_Result__c"] == "")
                                )
                                || mcae["Check_Result__c"] == inputing["Check_Result__c"]
                               )
        */
        //原是代码保留
        if (inputingList.length == mcaeList.length && needClearId == false ) {
            for (var i = 0; i < mcaeList.length; i++) {
                var mcae = mcaeList[i];
                finalPrice = mcae["Maintenance_Contract_Estimate__r"]["Maintenance_Price__c"];
                var inputing = inputingList[i];
                if (mcae["Asset__c"] != null && mcae["Asset__c"] != "") {
                    if (inputing["id"] != "" && mcae["Asset__c"] == inputing["id"]
                            && localParseFloat(mcae["Repair_Price__c"]) == inputing["Repair_Price__c"]
                            
                            && (((mcae["Comment__c"] == null || mcae["Comment__c"] == "")
                                  && (inputing["Comment__c"] == null || inputing["Comment__c"] == "")
                                )
                                || mcae["Comment__c"] == inputing["Comment__c"]
                               )
                    ) {
                        // 同じ
                    } else {
                        needClearId = true;
                        break;
                    }
                } else {
                    if (inputing["id"] == "" && mcae["Product_Manual__c"] != null && mcae["Product_Manual__c"] != ""
                            && mcae["Product_Manual__c"] == inputing["Product_Manual__c"]
                            
                            && localParseFloat(mcae["Repair_Price__c"]) == inputing["Repair_Price__c"]
                            && (((mcae["Comment__c"] == null || mcae["Comment__c"] == "")
                                  && (inputing["Comment__c"] == null || inputing["Comment__c"] == "")
                                )
                                || mcae["Comment__c"] == inputing["Comment__c"]
                               )
                    ) {
                        // 同じ
                    } else {
                        needClearId = true;
                        break;
                    }
                }
            }
        } else {
            needClearId = true;
        }
        
        // xud 20140529 ここは総金額変更判断(割引を変更したらまずい)
        var inputFinalPrice = j$(escapeVfId('allPage:allForm:allBlock:contractInfo:mainteRealHidden')).value();
        if (toNum(inputFinalPrice) != toNum(finalPrice)) {
            needClearId = true;
        }
        if (changedPrice=='true') {
            needClearId = true;
        }
    }
    if (needClearId) {
        //j$(escapeVfId('allPage:allForm:changedAfterPrint')).val('true');
    }
    return needClearId;
}
 
if ('{!printAsset}' == 'true') {
    //打印保有設備
    // //必须选择打印报价(详细还是简化)
    var con = 0;
    for (j = 0; j < 4; j++) {
        if (j$(escapeVfId('allPage:allForm:check' + j)).attr('checked')) {
            con ++;
        }
    }
    if(con != 1){
        alert('请您勾选打印报价版本,只能勾选一个。');
    }else{
         window.open('/apex/MaintenanceContractEstimateVMPDF?id={!targetEstimateId}', 'MaintenanceContractEstimateVMPDF');
    }
    
} else if ('{!printContract}' == 'true') {
    // 打印医院合同配置
    window.open('/apex/MceConfigPDF?id={!targetEstimateId}&flag=printContract', 'MceConfigPDF');
} else if ('{!printTripartite}' == 'true') {
    //打印三方合同
    window.open('/apex/MceConfigPDF?id={!targetEstimateId}&flag=printTripartite', 'MceConfigPDF');
} else if ('{!printAgent}' == 'true') {
    //打印经销商合同
    window.open('/apex/MceConfigPDF?id={!targetEstimateId}&flag=printAgent', 'MceConfigPDF');
}else {}
//当选择报价单(详细版)的时候隐藏报价单(简化版)
// 4个选项只可以选一个
function hideSimplify(cb){
    for (j = 0; j < 4; j++) {
        if (j$(escapeVfId('allPage:allForm:check' + j)).attr('checked')) {
            j$(escapeVfId('allPage:allForm:check' + j)).attr('checked',false);
            if (j == cb) {
                j$(escapeVfId('allPage:allForm:check' + j)).attr('checked',true);
            }
        }
    }
 
}
var isDisabled = {!PageDisabled};
if(!isDisabled){
    refreshAsset({!productCount});
}
</script>
</apex:outputPanel>
</apex:page>