李金换
2022-03-28 9b197b7fac92278fb591ea8f4942c7d5687cb5ce
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
<apex:page controller="SelectAssetEstimateVMController" tabStyle="Maintenance_Contract_Estimate__c" 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="/soap/ajax/29.0/connection.js"/>
    <apex:includeScript value="/soap/ajax/29.0/apex.js"/>
<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() });
 
function approvalJs() {
    approvalDate = new Date();
    var rowCnt = j$(escapeVfId('allPage:allForm:allBlock:assetSection:productCnt')).val();
    refreshAsset(rowCnt);
}
 
//add by gwy 2021-01-27 start 提交时的提示框
function KindsAndMonths() {
    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;  
        }
    }
        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();
    });
}
//<!-- 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(){
    var isDisabled = {!PageDisabled};
    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: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
    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');
            //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');
            //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') {
        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) {
    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;
    }
    val = localParseFloat(val);
    //val = Math.round(val * 100) / 100;
    val = Math.round(val);
    j$(escapeVfId('allPage:allForm:allBlock:contractInfo:quotation_Amount')).val(toNumComma(val));
   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 refreshAsset(cnt) {
    // alert(cnt);
    // 提交后就页面不计算了
    var isDisabled = {!PageDisabled};
    // 合同总理
    var newCount = 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());
 
 
    // 预定开始日
    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();
        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();
                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++;
                        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'){
                            //upPrice = (strMoney) * (1 + Adjustment_ratio_Upper/100);
                            //downPrice = (strMoney) * (1 + Adjustment_ratio_Lower/100);
                            upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                            downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                        }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();
            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++;
                    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'){
                        //upPrice = (strMoney) * (1 + Adjustment_ratio_Upper/100);
                        //downPrice = (strMoney) * (1 + Adjustment_ratio_Lower/100);
                        upPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Upper/100);
                        downPrice = (assetListmonth * Punish) * (1 + Adjustment_ratio_Lower/100);
                    }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);
            // 
            repairMoney = j$.trim(j$(escapeVfId('allPage:allForm:allBlock:assetSection:assetTable:' + i + ':repairPrice')).value());
        }
        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;
    }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();
}
 
 
 
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;
    // }
}
 
function changeEstiStartdate(val) {
    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 ;
    var w = window.open(encodeURI(urlNameJs),'过去两年修理实绩','menubar=no,height=720,width=986');
    w.focus();
}
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());
 
                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>
    <!-- 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>
                        <!-- 实绩联动价格计算 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>
                        <th style="width:70px" class="headerRow  booleanColumn">{!$ObjectType.Maintenance_Contract_Asset_Estimate__c.fields.Comment__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>
                                <td class="dataCell" width="70px">
                                    <apex:outputField value="{!ar.rec.Asset_situation__c}" rendered="{!Not(ar.IsManual)}" />
                                </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"/>
                                </td>
                                <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>
                                <td class="dataCell" width="70px">
                                    <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" />
                                </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"/>
                                    <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="70px" style="text-align:right" >
                                    <apex:inputField value="{!ar.mcae.Repair_Price__c}" id="repairPrice" style="ime-mode: disabled; width:95%; text-align:right;" onchange="refreshAsset({!productCount});"/>
                                </td>
                                <td class="dataCell" width="70px" style="text-align:right" >
                                    <apex:inputField value="{!ar.mcae.Comment__c}" id="comment" style="width:95%;"/>
                                </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">报价总额</th>
                    <th width="90px" style="text-align:right"><span id="allPage:allForm:allBlock:assetListSumNum" ></span></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: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__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__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__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>
                    </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>
                    </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>
            </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> -->
                        <td><apex:commandButton id="savebtn" action="{!save}" value="{!$Label.Save_Button}" disabled="{!SaveBtnDisabled}" rerender="allForm" onclick="if (!EGFlgconfim()) return false;" oncomplete="unblockUI();"/></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();"/>
                        <!-- 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 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"
                + "  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>