username@email.com
2025-04-27 15eb82df2d6ec539e9d4245bfe08d531e8eb6379
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
 
//获取href里面的参数
getQueryVariable = function (parameter) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] === parameter) { return pair[1]; }
    }
    return "";
}
 
//删除事件回调操作
deleteMethod = function (self) {
    CountAmount();
    $("#girdtable .body").each(function (i, v) {
        CountAmountDtl($(v).find('[name = "erp_settlement_dtl.count"]'));
    });
 
    BindEvent();
    if (window.taskid != '') {
        var id = $(self).find("input[name='id']").val();
        if (id != '') {
            deleteDtlData(id);
        }
    }
}
 
deleteDtlData = function (id) {
    $.ajax({
        url: "/ERP/Erp_Settlement/RemoveSettlementDtl?settlementDtlId=" + id
        , async: false
        , cache: false
        , dataType: "json",
        success: function (data) {
            if (data.Result) {
                layer.alert("删除成功");
            } else {
                layer.alert("删除失败");
            }
        }
    });
}
 
//添加事件回调操作
createMethod = function () {
    NumberBind();
    LoadConstructionCostDtlDropDownPage();
    CountAmount();
    $("#girdtable .body").each(function (i, v) {
        CountAmountDtl($(v).find('[name = "erp_settlement_dtl.count"]'));
    });
    BindEvent();
    ChangeDtlShowType();
    if (completeLoadPage == 1) {
        $("#girdtable .body").each(function () {
            if (($(this).attr("dtSource") != "contractpretrial") && ($(this).attr("dtSource") != "prove")) {
                $(this).find("[name='erp_settlement_dtl.type']").find("option[value='1']").remove();
            }
        });
    }
 
}
 
$(document).ready(function () {
    if (window.taskid != '') {
        $("#erp_settlement_settlement_date").val(JsonDateToDate($("#erp_settlement_settlement_date").val()).Format('yyyy-MM-dd'));
        $("#erp_settlement_start_date").val(JsonDateToDate($("#erp_settlement_start_date").val()).Format('yyyy-MM-dd'));
        $("#erp_settlement_end_date").val(JsonDateToDate($("#erp_settlement_end_date").val()).Format('yyyy-MM-dd'));
    } else {
        var date = new Date();
        var curDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
        $("#erp_settlement_settlement_date").val(curDate);
        $("#erp_settlement_start_date").val(curDate);
        $("#erp_settlement_end_date").val(curDate);
    }
 
    $('#girdtable .body').find(".subtrdel_js").hide();
});
 
///数据加载
initData = function () {
    NumberBind();
    //debugger;
    if (window.taskid == '') {
        if (LoadData() == false) {
            return;
        }
 
        LoadConstructionCostDtlDropDownData();
        LoadConstructionCostDtlDropDownPage();
        LoadPage();
    } else {
        LoadPJ();
        LoadDataUpdate();
        LoadConstructionCostDtlDropDownData();
        LoadConstructionCostDtlDropDownPage();
    }
 
    ChangeLabel();
 
 
    if (SettlementAllData.id > 0 && window.flowid != null && SettlementAllData.instance_status == 1) {
        var sprintbtn = '<div style="padding-top:20px;padding-right:10px;padding-left:70%;"> <a onclick="" href="/ERP/Erp_Settlement/costprint/?printType=4&id=' + SettlementAllData.id + '&flowid=' + window.flowid + '&orderType=' + orderType + '" target="_blank" style="font-size:12px;"><img src="../../img/ico/printer.png" />结算单打印</a>&nbsp;<a onclick="" href="/ERP/Erp_Settlement/costprint/?printType=3&id=' + SettlementAllData.id + '&flowid=' + window.flowid + '&orderType=' + orderType + '" target="_blank" style="font-size:12px;"><img src="../../img/ico/printer.png" />附件打印</a></div>';
        $('#txtTitle').append(sprintbtn);
    }
    
    //LoadConstructionCostDtlDropDown();
    ChangeDtlShowType();
    CountAmount();
    $("#girdtable .body").each(function (i, v) {
        CountAmountDtl($(v).find('[name = "erp_settlement_dtl.count"]'));
    });
    BindEvent();
    ChangeFormTitle();
    if (SettlementAllData.instance_status == 1 && (orderType == 4 || orderType == 5) && type == 3) {  
        var sprintbtn = '<div style="padding-top:20px;padding-right:10px;padding-left:70%;"> <a onclick="" href="/ERP/Erp_Settlement/costprintlw/?id=' + SettlementAllData.id + '" target="_blank" style="font-size:12px;"><img src="../../img/ico/printer.png" />单据打印</a></div>';
        $('#txtTitle').append(sprintbtn);
    }
 
    //统一给主表的金额设置可编辑
    $('[name="erp_settlement.amount"]').addClass('edit');
    $('[name="erp_settlement.amount_after_deduction"]').addClass('edit');
    $('[name="erp_settlement.payable_balance"]').addClass('edit');
}
 
var SettlementAllData = {};
var ContractpretrialSettlementDtl = [];
var ProveSettlementDtl = [];
var ConstructionCostDtls = [];
var type = 0;
var orderType = 0;
var completeLoadPage = 0;
var addClick = 0
function LoadData() {
    var contractpretrialCode = getQueryVariable('contractpretrialCode');
    type = getQueryVariable('type');
    orderType = getQueryVariable('orderType');
    var subject = 2;
    $.ajax({
        url: "/ERP/Erp_Settlement/Get?ContractpretrialCode=" + contractpretrialCode + "&type=" + type + "&orderType=" + orderType + "&subject=" + subject
        , async: false
        , cache: false
        , dataType: "json",
        success: function (data) {
            SettlementAllData = data;
            SettlementAllData.cumulative_payment_t = SettlementAllData.cumulative_payment;
            SettlementAllData.cumulative_payable_t = SettlementAllData.cumulative_payable;
            var json = JSON.stringify(SettlementAllData);
            var sprintbtn = '<input type="hidden" id="erp_settlement_SettlementAllData" name="erp_settlement.SettlementAllData"  field="SettlementAllData" class="form-control edit" isvalid="yes" checkexpession="NotNull"">';
            $('#erp_settlement_code').after(sprintbtn);// 先弄个隐藏框把数据存起来
            $("#erp_settlement_SettlementAllData").val(json);
            //$("#txtTitle").text(data.title);
        }
    });
    $.ajax({
        url: "/ERP/Erp_Settlement/LoadSettlementDtlFromContractpretrial?contractpretrialCode=" + contractpretrialCode + "&orderType=" + orderType + "&type=" + type
        , async: false
        , cache: false
        , dataType: "json",
        success: function (data) {
            //debugger;
            if (data.Result) {
                ContractpretrialSettlementDtl = data.DataInfo;
            } else {
                layer.alert(data.Message);
                $(".btn-success").hide();
                return false;
            }
        }
    });
 
    if (orderType == "4") {
        $.ajax({
            url: "/ERP/Erp_Settlement/LoadSettlementDtlFromProve?contractpretrialCode=" + contractpretrialCode
            , async: false
            , cache: false
            , dataType: "json",
            success: function (data) {
                ProveSettlementDtl = data;
            }
        });
    }
 
 
    return true;
}
 
function LoadDataUpdate() {
    $.ajax({
        url: "/ERP/Erp_Settlement/Get?sysid=" + window.sysid
        , async: false
        , cache: false
        , dataType: "json",
        success: function (data) {
            SettlementAllData = data;
            SettlementAllData.cumulative_payment_t = SettlementAllData.cumulative_payment;
            SettlementAllData.cumulative_payable_t = SettlementAllData.cumulative_payable;
            type = SettlementAllData.type;
            orderType = SettlementAllData.order_type;
            var json = JSON.stringify(SettlementAllData);
            var sprintbtn = '<input type="hidden" id="erp_settlement_SettlementAllData" name="erp_settlement.SettlementAllData"  field="SettlementAllData" class="form-control" isvalid="yes" checkexpession="NotNull"">';
            $('#erp_settlement_code').after(sprintbtn);// 先弄个隐藏框把数据存起来
            $("#erp_settlement_SettlementAllData").val(json);
            $("#txtTitle").text(data.title);  
        }
    });
}
 
function LoadPage() {
    $("#erp_settlement_code").val(SettlementAllData.code);
    $("#erp_settlement_relation_order_num").val(SettlementAllData.relation_order_num);
    $("#erp_settlement_project_id").val(SettlementAllData.ProjectName);
    $("#erp_settlement_supplier_id").val(SettlementAllData.supplier_id);
    $("#erp_settlement_supplier_id").trigger("chosen:updated");
    $("#erp_settlement_contractpretrial_nature").val(SettlementAllData.contractpretrial_nature);
    $("#erp_settlement_supplier_name").val(SettlementAllData.supplier_name);
    $("#erp_settlement_supplier_user_name").val(SettlementAllData.supplier_user_name);
    $("#erp_settlement_cumulative_payment").val(SettlementAllData.cumulative_payment);
    $("#erp_settlement_cumulative_payable").val(SettlementAllData.cumulative_payable);
    var dtlIndex = 0;
    if (ContractpretrialSettlementDtl != null && ContractpretrialSettlementDtl.length > 0) {
        for (var i = 0; i < ContractpretrialSettlementDtl.length; i++) {
            $('#girdtable .body').eq(dtlIndex).attr("dtSource", "contractpretrial");
 
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.content']").val(ContractpretrialSettlementDtl[i].content);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.unit']").val(ContractpretrialSettlementDtl[i].unit);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.type']").trigger("chosen:updated");
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.count']").val(ContractpretrialSettlementDtl[i].count);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.price']").val(ContractpretrialSettlementDtl[i].price);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.amount']").val(ContractpretrialSettlementDtl[i].amount);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.construction_start_date']").val('');
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.construction_end_date']").val('');
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.no_taxrate_price']").val(ContractpretrialSettlementDtl[i].no_taxrate_price);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.no_taxrate_amount']").val(ContractpretrialSettlementDtl[i].no_taxrate_amount);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.jd_count_total']").val(ContractpretrialSettlementDtl[i].jd_count_total);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.jd_no_taxrate_amount_total']").val(ContractpretrialSettlementDtl[i].jd_no_taxrate_amount_total);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").val(ContractpretrialSettlementDtl[i].construction_cost_dtl_id);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").trigger("chosen:updated");
 
            dtlIndex++;
            if (dtlIndex != (ContractpretrialSettlementDtl.length + ProveSettlementDtl.length)) {
                $(".subtradd_js").click();
            }
        }
    }
 
    if (ProveSettlementDtl != null && ProveSettlementDtl.length > 0) {
        for (var i = 0; i < ProveSettlementDtl.length; i++) {
            $('#girdtable .body').eq(dtlIndex).attr("dtSource", "prove");
 
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.content']").val(ProveSettlementDtl[i].content);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.unit']").val(ProveSettlementDtl[i].unit);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.type']").trigger("chosen:updated");
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.count']").val(ProveSettlementDtl[i].count);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.price']").val(ProveSettlementDtl[i].price);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.amount']").val(ProveSettlementDtl[i].amount);
 
            //$('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.construction_start_date']").val(JsonDateToDate(ProveSettlementDtl[i].construction_start_date).Format('yyyy-MM-dd'));
            //$('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.construction_end_date']").val(JsonDateToDate(ProveSettlementDtl[i].construction_end_date).Format('yyyy-MM-dd'));
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.construction_start_date']").val('');
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.construction_end_date']").val('');
 
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.jd_count_total']").val(0);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.jd_no_taxrate_amount_total']").val(0);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").val(ProveSettlementDtl[i].construction_cost_dtl_id);
            $('#girdtable .body').eq(dtlIndex).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").trigger("chosen:updated");
 
            dtlIndex++;
            if (dtlIndex != (ContractpretrialSettlementDtl.length + ProveSettlementDtl.length)) {
                $(".subtradd_js").click();
            }
        }
    }
 
    completeLoadPage = 1;
}
 
function LoadPJ() {
    var pjid = $("#erp_settlement_project_id").val();
    $.ajax({
        url: "/PM/PM_Project/Get?id=" + pjid
        , async: false
        , cache: false
        , dataType: "json",
        success: function (data) {
            $("#erp_settlement_project_id").val(data.pjname);
        }
    });
}
 
function LoadConstructionCostDtlDropDownData() {
    if (type == "3") {
        // 施工措施费的进度款关联 施工图目标成本的子表
        $.ajax({
            url: "/ERP/Erp_Settlement/GetConstructionCostDtlForSettlement?projectId=" + SettlementAllData.project_id + "&needDeduction=1"
            , async: false
            , cache: false
            , dataType: "json",
            success: function (data) {
                ConstructionCostDtls = data;
                //ConstructionCostDtlsBind();
            }
        });
    }
}
 
function LoadConstructionCostDtlDropDownPage() {
    if (ConstructionCostDtls != null && ConstructionCostDtls.length > 0) {
        var optionHtml = '<option value="">请选择</option>';
        for (var i = 0; i < ConstructionCostDtls.length; i++) {
            var parentName = '';
            if (ConstructionCostDtls[i].type == 1) {
                parentName = '材料费';
            } else if (ConstructionCostDtls[i].type == 2) {
                parentName = '施工费';
            } else if (ConstructionCostDtls[i].type == 3) {
                parentName = '措施费';
            } else if (ConstructionCostDtls[i].type == -999) {
                parentName = '扣款项';
            }
 
            var textStr = parentName + '/' + ConstructionCostDtls[i].relation_name + '/' + ConstructionCostDtls[i].specification + '/' + ConstructionCostDtls[i].unit + '/' + ConstructionCostDtls[i].purposename;
            optionHtml += '<option value="' + ConstructionCostDtls[i].id + '">' + textStr + '</option>';
        }
        $("[name='erp_settlement_dtl.construction_cost_dtl_id']").append(optionHtml);
 
        if (window.taskid != "") {
            $(SettlementAllData.Children).each(function (i, v) {
                $("#girdtable .body").each(function () {
                    if ($(this).find('input[name="id"]').val() == v.id + "") {
                        $(this).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").val(v.construction_cost_dtl_id);
                        $(this).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").trigger("chosen:updated");
                    }
                });
            });
        }
    }
}
 
// 改下文本名  因为表单是按照结算的时候建的名字
function ChangeLabel() {
    //设置合同性质单选框的高度,不然要强行换行
    $('.z-radio').height($('.z-radio').parent('div').siblings().eq(0).find('div').eq(0).height());
 
    if (orderType == "4") {
        $("#erp_settlement_batch").parent('div').parent('div').hide();
    }
    if (orderType == "5") {
        var width_4_child_div = $('.col-sm-4').eq(0).find('div').width();
        $("#erp_settlement_supplier_id").parent('div').width(width_4_child_div);
        $("#erp_settlement_supplier_id").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_supplier_id").parent('div').parent('div').after($("#erp_settlement_supplier_user_name").parent('div').parent('div'));
        $("#erp_settlement_supplier_user_name").parent('div').width(width_4_child_div)
        $("#erp_settlement_supplier_user_name").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        //
        $("#erp_settlement_supplier_user_name").parent('div').parent('div').after($("#erp_settlement_code").parent('div').parent('div'));
        $("#erp_settlement_code").parent('div').width(width_4_child_div)
        $("#erp_settlement_code").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_code").parent('div').parent('div').after($("#erp_settlement_content").parent('div').parent('div'));
        $("#erp_settlement_content").parent('div').width(width_4_child_div)
        $("#erp_settlement_content").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_content").parent('div').parent('div').after($("[name='erp_settlement.contractpretrial_nature']").parent('label').parent('div').parent('div'));
        //$("[name='erp_settlement.contractpretrial_nature']").parent('label').parent('div').parent('div').width(width_4_child_div)
        $("[name='erp_settlement.contractpretrial_nature']").parent('label').parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("[name='erp_settlement.contractpretrial_nature']").parent('label').parent('div').parent('div').after($("#erp_settlement_relation_order_num").parent('div').parent('div'));
        $("#erp_settlement_relation_order_num").parent('div').width(width_4_child_div)
        $("#erp_settlement_relation_order_num").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_relation_order_num").parent('div').parent('div').after($("#erp_settlement_start_date").parent('div').parent('div'));
        $("#erp_settlement_start_date").parent('div').width(width_4_child_div)
        $("#erp_settlement_start_date").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_start_date").parent('div').parent('div').after($("#erp_settlement_end_date").parent('div').parent('div'));
        $("#erp_settlement_end_date").parent('div').width(width_4_child_div)
        $("#erp_settlement_end_date").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_end_date").parent('div').parent('div').after($("#erp_settlement_settlement_date").parent('div').parent('div'));
        $("#erp_settlement_settlement_date").parent('div').width(width_4_child_div)
        $("#erp_settlement_settlement_date").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_settlement_date").parent('div').parent('div').after($("#erp_settlement_amount").parent('div').parent('div'));
        $("#erp_settlement_amount").parent('div').width(width_4_child_div)
        $("#erp_settlement_amount").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_amount").parent('div').parent('div').after($("#erp_settlement_cumulative_payment").parent('div').parent('div'));
        $("#erp_settlement_cumulative_payment").parent('div').width(width_4_child_div)
        $("#erp_settlement_cumulative_payment").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_cumulative_payment").parent('div').parent('div').after($("#erp_settlement_payment_ratio").parent('div').parent('div'));
        $("#erp_settlement_payment_ratio").parent('div').width(width_4_child_div)
        $("#erp_settlement_payment_ratio").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_payment_ratio").parent('div').parent('div').after($("#erp_settlement_payable_balance").parent('div').parent('div'));
        $("#erp_settlement_payable_balance").parent('div').width(width_4_child_div)
        $("#erp_settlement_payable_balance").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_payable_balance").parent('div').parent('div').after($("#erp_settlement_cumulative_payable").parent('div').parent('div'));
        $("#erp_settlement_cumulative_payable").parent('div').width(width_4_child_div)
        $("#erp_settlement_cumulative_payable").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        $("#erp_settlement_cumulative_payable").parent('div').parent('div').after($("#erp_settlement_batch").parent('div').parent('div'));
        $("#erp_settlement_batch").parent('div').width(width_4_child_div)
        $("#erp_settlement_batch").parent('div').parent('div').attr("class", "col-xs-4 col-sm-4");
 
        // 累计已付-》累计完成
        $("#erp_settlement_cumulative_payment").parent('div').prev('label').text("累计完成");
 
        // 结算总金额-》本期完成
        $("#erp_settlement_amount").parent('div').prev('label').text("本期完成");
 
        // 应付款余额-》本期应付
        $("#erp_settlement_payable_balance").parent('div').prev('label').text("本期应付");
 
        // 合同单号-》关联单号
        $("#erp_settlement_relation_order_num").parent('div').prev('label').text("关联单号");
 
        // 合同单号-》关联单号
        $("#erp_settlement_condition").parent('div').prev('label').text("合同支付条款说明");
 
        // 施工起始日期-》计量起始日期
        $("#erp_settlement_start_date").parent('div').prev('label').text("计量起始日期");
 
        // 施工截止日期-》计量截止日期
        $("#erp_settlement_end_date").parent('div').prev('label').text("计量截止日期");
 
        // 结算日期-》计量日期
        $("#erp_settlement_settlement_date").parent('div').prev('label').text("计量日期");
 
 
        //// 承包内容隐藏
        //$("#erp_settlement_content").parent('div').parent('div').hide();
        if (orderType == "5" && type == "3") {
            $(".subtradd_js").show();
        } else {
            $(".subtradd_js").hide();
        }
    }
}
 
// 处理子表启用禁用状态
function ChangeDtlShowType() {
    $("#girdtable .body").each(function () {
        if ($(this).find("input[name='id']").val() == '') {// 新增的时候
            if ($(this).attr("dtSource") == "contractpretrial") {
                $(this).find("[name='erp_settlement_dtl.type']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.type']").trigger("chosen:updated");
                $(this).find("[name='erp_settlement_dtl.content']").attr("disabled", "disabled");
                //$(this).find("[name='erp_settlement_dtl.unit']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.unit']").trigger("chosen:updated");
                $(this).find("[name='erp_settlement_dtl.type']").trigger("chosen:updated");
                //$(this).find("[name='erp_settlement_dtl.price']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.amount']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.no_taxrate_price']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.no_taxrate_amount']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.jd_count_total']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.jd_no_taxrate_amount_total']").attr("disabled", "disabled");
                if (orderType == "4") {
                    $(this).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").attr("disabled", "disabled");
                } else {
                    $(this).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").removeAttr("disabled");
                }
                $(this).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").trigger("chosen:updated");
 
            } else if ($(this).attr("dtSource") == "prove") {
                $(this).find("[name='erp_settlement_dtl.type']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.type']").trigger("chosen:updated");
                $(this).find("[name='erp_settlement_dtl.content']").attr("disabled", "disabled");
                //$(this).find("[name='erp_settlement_dtl.unit']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.unit']").trigger("chosen:updated");
                $(this).find("[name='erp_settlement_dtl.type']").trigger("chosen:updated");
                //$(this).find("[name='erp_settlement_dtl.price']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.amount']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.construction_start_date']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.construction_end_date']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.no_taxrate_price']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.no_taxrate_amount']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.jd_count_total']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.jd_no_taxrate_amount_total']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.construction_cost_dtl_id']").trigger("chosen:updated");
            } else {
                // 扣款项
                $(this).find("[name='erp_settlement_dtl.no_taxrate_price']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.no_taxrate_amount']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.jd_count_total']").val("0");
                $(this).find("[name='erp_settlement_dtl.jd_count_total']").attr("disabled", "disabled");
                $(this).find("[name='erp_settlement_dtl.jd_no_taxrate_amount_total']").val("0");
                $(this).find("[name='erp_settlement_dtl.jd_no_taxrate_amount_total']").attr("disabled", "disabled");
                //$(this).find("[name='erp_settlement_dtl.type']").find("option[value='1']").remove();
            }
        } else {// 保存后更新的时候
            $(this).find("[name='erp_settlement_dtl.type']").attr("disabled", "disabled");
            $(this).find("[name='erp_settlement_dtl.type']").trigger("chosen:updated");
            $(this).find("[name='erp_settlement_dtl.content']").attr("disabled", "disabled");
            //$(this).find("[name='erp_settlement_dtl.unit']").attr("disabled", "disabled");
            $(this).find("[name='erp_settlement_dtl.unit']").trigger("chosen:updated");
            $(this).find("[name='erp_settlement_dtl.type']").trigger("chosen:updated");
            //$(this).find("[name='erp_settlement_dtl.price']").attr("disabled", "disabled");
            $(this).find("[name='erp_settlement_dtl.amount']").attr("disabled", "disabled");
            $(this).find("[name='erp_settlement_dtl.construction_start_date']").attr("disabled", "disabled");
            $(this).find("[name='erp_settlement_dtl.construction_end_date']").attr("disabled", "disabled");
            $(this).find("[name='erp_settlement_dtl.no_taxrate_price']").attr("disabled", "disabled");
            $(this).find("[name='erp_settlement_dtl.no_taxrate_amount']").attr("disabled", "disabled");
            $(this).find("[name='erp_settlement_dtl.jd_count_total']").attr("disabled", "disabled");
            $(this).find("[name='erp_settlement_dtl.jd_no_taxrate_amount_total']").attr("disabled", "disabled");
        }
    });
 
    if (orderType == "4") {
        $('#erp_settlement_deductions').attr("checkexpession", "NotNull");
    } else if (orderType == "5") {
        $('#erp_settlement_payment_ratio').attr("checkexpession", "NotNull");
    }
 
    // 施工措施费的进度款关联 施工图目标成本的子表
    var tdIndex = $('#girdtable .body').eq(0).find('[name="erp_settlement_dtl.construction_cost_dtl_id"]').parent('td').index();
    if (tdIndex > -1) {
        if (type == "3") {
            $('#girdtable tr').each(function () {
                $(this).children("td").eq(tdIndex).show();
            });
            $('[name="erp_settlement_dtl.construction_cost_dtl_id"]').attr("checkexpession", "NotNull");
        } else {
            $('#girdtable tr').each(function () {
                $(this).children("td").eq(tdIndex).hide();
            });
        }
    }
    var tdIndex2 = $('#girdtable .body').eq(0).find('[name="erp_settlement_dtl.jd_count_total"]').parent('td').index();
    var tdIndex3 = $('#girdtable .body').eq(0).find('[name="erp_settlement_dtl.jd_no_taxrate_amount_total"]').parent('td').index();
    if (orderType == "5") {
        $('#girdtable tr').each(function () {
            if (window.taskid == "") {
                $("[name='erp_settlement_dtl.price']").removeAttr("disabled");
            }
            if (tdIndex2 > -1) {
                $(this).children("td").eq(tdIndex2).hide();
            }
            if (tdIndex3 > -1) {
                $(this).children("td").eq(tdIndex3).hide();
            }
        });
    }
}
 
// 改变页面表单标题
function ChangeFormTitle() {
    //debugger;
    var titleStr = SettlementAllData.title.replace('进度计量', '<span style="color: #4ee61d;">进度计量</span >').replace('结算计量', '<span style="color: #e75464;">结算计量</span >');
 
    $("#txtTitle").html(titleStr);
    $('#girdtable').prev("h3").html(titleStr + "明细"); 
}
 
function RemoveDtlType() {
 
}
 
function BindEvent() {
    // 所以的输入框改变的时候都同步SettlementAllData对象
    $('input,textarea,select').change(function () {
        var fildName = $(this).attr("name").replace("erp_settlement.", "");
        SettlementAllData[fildName] = $(this).val();
        $("#erp_settlement_SettlementAllData").val(JSON.stringify(SettlementAllData));
    });
 
    // 结算项改变时重新算总价
    $('[name="erp_settlement_dtl.type"]').change(function () {
        CountAmount();
    });
 
    $('[name="erp_settlement_dtl.count"],[name="erp_settlement_dtl.price"],[name="erp_settlement_dtl.tax_rate"]').change(function () {
        if (/^[0-9]+(([.]{1}([0-9]+))|)$/.test($(this).val()) == false) {
            $(this).val('');
            return false;
        }
        CountAmountDtl($(this));
    });
 
    // 供应商负责人同步
    $('#erp_settlement_supplier_id').change(function () {
        var supplier_id = $(this).val();
        var supplier_name = $(this).next("div").find("a").find("span").text();
        $.ajax({
            url: "/SC/Sc_supplier/GetSupplierInfoByID?id=" + supplier_id
            , async: false
            , cache: false
            , dataType: "json",
            success: function (data) {
                $("#erp_settlement_supplier_user_name").val(data.UserName);
                SetJsonData("supplier_user_id", data.user_id);
                SetJsonData("supplier_user_name", data.UserName);
                SetJsonData("supplier_id", data.supplier_id);
                SetJsonData("supplier_name", data.supplier_name);
            }
        });
    });
 
    // 合同详情跳转
    $('#erp_settlement_relation_order_num').css({ "color": "cornflowerblue", "cursor": "pointer" });
    $('#erp_settlement_relation_order_num').parent('div').click(function () {
        var code = $(this).find("#erp_settlement_relation_order_num").val();
        if (code == "无关联单号") {
            return false;
        }
 
        $.ajax({
            url: '/ERP/Erp_Settlement/GetContractpretrialByCode',
            data: { code: code },
            type: 'Post',
            success: function (resp) {
                if (resp.Data != null && resp.Data != undefined) {
                    var data = resp.Data;
                    var tableName = 'oa_contractpretrial';
                    $.ajax({
                        url: '/OA/OA_SysErpMGMT/GetFlowTaskByIdAndTable',
                        data: { id: data.PKID, table: tableName },
                        type: 'Post',
                        success: function (resp) {
                            var url = "/WorkFlowRun/Index?flowid=" + resp.FlowId + '&taskid=' + resp.TaskId;
                            appendTabByUrl(url, "查看单据详情");
                        }
                    });
                } else {
                    layer.alert("合同未找到");
                }
            }
        });
    });
 
    if (orderType == "4") {// 结算
        $('#erp_settlement_deductions').bind('change', function () {
            if (/^[-]{0,1}[0-9]+(([.]{1}([0-9]+))|)$/.test($(this).val()) == false) {
                $(this).val('');
                return false;
            }
            MoneyChangeEvent();
        });
    } else if (orderType == "5") {// 进度款
        $('#erp_settlement_payment_ratio').bind('change', function () {
            if (/^[0-9]+(([.]{1}([0-9]+))|)$/.test($(this).val()) == false) {
                $(this).val('');
                return false;
            }
            MoneyChangeEvent();
        });
    }
 
 
    $('[name="erp_settlement_dtl.construction_cost_dtl_id"]').parent("td").unbind();
    $('[name="erp_settlement_dtl.construction_cost_dtl_id"]').parent("td").click(function () {
        ShowCostPage($(this).find('[name="erp_settlement_dtl.construction_cost_dtl_id"]'));
    });
 
    $('.subtradd_js').parent("span").unbind();
    $('.subtradd_js').parent("span").click(function () {
        if (completeLoadPage == 1 && orderType == "5") {
            ShowContractpretrialList();
        }
    });
}
 
function CountAmount() {
    // 算总金额
    var amount = 0;
    var deductions = 0;
    $('[name="erp_settlement_dtl.amount"]').each(function (i, v) {
        var type = $(this).parents('tr').find('[name="erp_settlement_dtl.type"]').val();
        if (type == "1") {
            var curAmountStr = $(v).val();
            var curAmount = curAmountStr == "" ? 0 : Number(curAmountStr);
            amount += curAmount;
        } else if (type == "2") {
            var curDeductionsStr = $(v).val();
            var curDeductions = curDeductionsStr == "" ? 0 : Number(curDeductionsStr);
            deductions += curDeductions;
        }
    });
 
    $('#erp_settlement_amount').val(amount);
    $('#erp_settlement_deductions').val(deductions);
    SetJsonData("amount", amount);
    SetJsonData("deductions", deductions);
    MoneyChangeEvent();
}
 
function CountAmountDtl(self) {
    //debugger;
    //子表算总金额
    var countStr = $(self).parents('tr').find('[name="erp_settlement_dtl.count"]').val();
    var count = countStr == "" ? 0 : Number(countStr);
    if (count == 0) {// 数量是0的时候 合计这些就不用算了
        $(self).parents('tr').find('[name="erp_settlement_dtl.amount"]').val(0);
        $(self).parents('tr').find('[name="erp_settlement_dtl.no_taxrate_amount"]').val(0);
        $(self).parents('tr').find('[name="erp_settlement_dtl.no_taxrate_price"]').val(0);
    } else {
        var priceStr = $(self).parents('tr').find('[name="erp_settlement_dtl.price"]').val();
        var price = priceStr == "" ? 0 : Number(priceStr);
        var amount = accMul(count, price);
        var taxrate = accDiv(Number($(self).parents('tr').find('select[name="erp_settlement_dtl.tax_rate"]').val()), 100);
        //不含税合计 =含税合计- (含税合计 / (1 + 税率) * 税率)
        var no_taxrate_amount = accSub(amount, (accMul(accDiv(amount, accAdd(1, taxrate)), taxrate)));
        var no_taxrate_price = accDiv(no_taxrate_amount.toFixed(2), count);
        $(self).parents('tr').find('[name="erp_settlement_dtl.amount"]').val(amount.toFixed(2));
        $(self).parents('tr').find('[name="erp_settlement_dtl.no_taxrate_amount"]').val(no_taxrate_amount.toFixed(2));
        $(self).parents('tr').find('[name="erp_settlement_dtl.no_taxrate_price"]').val(no_taxrate_price.toFixed(8));
    }
 
    // 全部总金额
    CountAmount();
}
 
function MoneyChangeEvent() {
    if (orderType == "4") {// 结算
        // 扣款后结算金额=结算金额-各项 扣款
        var erp_settlement_amount = $("#erp_settlement_amount").val() == "" ? 0 : Number($("#erp_settlement_amount").val());
        var erp_settlement_deductions = $("#erp_settlement_deductions").val() == "" ? 0 : Number($("#erp_settlement_deductions").val());
        var erp_settlement_amount_after_deduction = accSub(erp_settlement_amount, erp_settlement_deductions);
        $("#erp_settlement_amount_after_deduction").val(erp_settlement_amount_after_deduction);
        SetJsonData("amount_after_deduction", erp_settlement_amount_after_deduction);
        // 应付款余额=扣款后结算金额-累计已付款
        var erp_settlement_cumulative_payment = $("#erp_settlement_cumulative_payment").val() == "" ? 0 : Number($("#erp_settlement_cumulative_payment").val());
        $("#erp_settlement_payable_balance").val(accSub(erp_settlement_amount_after_deduction, erp_settlement_cumulative_payment));
        SetJsonData("payable_balance", erp_settlement_amount_after_deduction - erp_settlement_cumulative_payment);
    } else if (orderType == "5") {// 进度款
        // 本期应付=本期完成*支付比例
        var erp_settlement_amount = $("#erp_settlement_amount").val() == "" ? 0 : Number($("#erp_settlement_amount").val());
        var erp_settlement_payment_ratio = $("#erp_settlement_payment_ratio").val() == "" ? 0 : Number($("#erp_settlement_payment_ratio").val());
        $("#erp_settlement_payable_balance").val(accMul(erp_settlement_amount, (accDiv(erp_settlement_payment_ratio, 100))).toFixed(2));
        SetJsonData("payable_balance", accMul(erp_settlement_amount, (accDiv(erp_settlement_payment_ratio, 100))).toFixed(2));
        //// 累计已付和累计应付要加本期本期应付和本期完成
        $("#erp_settlement_cumulative_payment").val(SettlementAllData.cumulative_payment_t);
        $("#erp_settlement_cumulative_payment").val(accAdd($("#erp_settlement_amount").val(), $("#erp_settlement_cumulative_payment").val()));
        $("#erp_settlement_cumulative_payable").val(SettlementAllData.cumulative_payable_t); 
        //$("#erp_settlement_cumulative_payable").val(accAdd($("#erp_settlement_payable_balance").val(), $("#erp_settlement_cumulative_payable").val()));
        $("#erp_settlement_cumulative_payable").val(accMul($("#erp_settlement_cumulative_payment").val(), accDiv($("#erp_settlement_payment_ratio").val(), 100)).toFixed(2));
    }
}
 
function SetJsonData(key, value) {
    SettlementAllData[key] = value;
    var json = JSON.stringify(SettlementAllData);
    $("#erp_settlement_SettlementAllData").val(json);
}
 
var _costInput;
//施工图明细选择选择
function ShowCostPage(costInput) {
    //debugger;
    var deduction = $(costInput).parents('tr').find("[name='erp_settlement_dtl.type']").val() == "2" ? 1 : 0;
    if (orderType == "4" && deduction == 0 || $(costInput).attr("disabled") == "disabled") {
        return false;
    }
 
    _costInput = costInput;
    var id = $(_costInput).val();
    //if ($(costInput).attr("disabled") == "disabled") {
    //    id = $(_costInput).val();
    //}
    layer.open({
        type: 2,
        title: '资源库',
        shadeClose: true,
        shade: 0.4,
        area: ['90%', '90%'],
        content: "/Article/Cost_Index?projectid=" + SettlementAllData.project_id + "&id=" + id + "&iskoukuan=" + deduction
    });
}
 
function setCostInfo(id, relation_key, relation_name, specification, unit, count, price, amount, type, ratio, ratio_count, purposename, cost_subject_id) {
    $(_costInput).val(id);
    $(_costInput).trigger("chosen:updated");
    //$(_costInput).parents('tr').find('[name="erp_settlement_dtl.unit"]').val(unit);
    //$(_costInput).parents('tr').find('[name="erp_settlement_dtl.unit"]').trigger("chosen:updated");
 
    $("#erp_settlement_remark").click();
 
    layer.closeAll();
}
 
function setCostInfoOfKouKuan(id, parentid, name, typeName, specifications, unitid, unitName, range, debit_subject, credit_subject, before_subject, after_subject) {
    $(_costInput).val(id);
    $(_costInput).trigger("chosen:updated");
    $("#erp_settlement_remark").click();
 
    layer.closeAll();
}
 
function ShowContractpretrialList() {
    //debugger;
    var contractpretrialCode = $("#erp_settlement_relation_order_num").val();
    layer.open({
        type: 2,
        title: '合同明细列表',
        shadeClose: true,
        shade: 0.4,
        closeBtn: 0,
        area: ['90%', '90%'],
        content: "/Erp_Settlement/ContractpretrialList?contractpretrialCode=" + contractpretrialCode
    });
}
 
function SelectContractpretrialDtl(name, unit, count, price, amount) {
    $('#girdtable .body').last().find("[name='erp_settlement_dtl.content']").val(name);
    $('#girdtable .body').last().find("[name='erp_settlement_dtl.unit']").val(unit);
    $('#girdtable .body').last().find("[name='erp_settlement_dtl.unit']").trigger("chosen:updated");
    $('#girdtable .body').last().find("[name='erp_settlement_dtl.count']").val(count);
    $('#girdtable .body').last().find("[name='erp_settlement_dtl.price']").val(price);
    $('#girdtable .body').last().find("[name='erp_settlement_dtl.amount']").val(amount);
    //debugger;
    $('#girdtable .body').last().find("[name='erp_settlement_dtl.type']").append("<option value='1'>结算项</option>");
    $('#girdtable .body').last().find("[name='erp_settlement_dtl.type']").val("1");
    $('#girdtable .body').last().find("[name='erp_settlement_dtl.type']").trigger("chosen:updated");
 
    $('#girdtable .body').last().attr("dtSource", "contractpretrial");
    //debugger;
    createMethod();
    layer.closeAll();
}
 
var NoContractpretrialDtlSelect = function () {
    $('#girdtable .body').last().find(".subtrdel_js").click();
    $('#girdtable .body').last().remove();
}
 
NumberBind = function () {
    $("[name='erp_settlement_dtl.count']").addClass("countTxtBox");
    $("[name='erp_settlement_dtl.price']").addClass("priceTxtBox");
    $("[name='erp_settlement_dtl.amount']").addClass("amountTxtBox");
    NumberBoxBind();
}
 
/**
* 乘法
*/
function accMul(arg1, arg2) {
    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
    try { m += s1.split(".")[1].length } catch (e) { }
    try { m += s2.split(".")[1].length } catch (e) { }
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
/**
 * 除法
 */
function accDiv(arg1, arg2) {
    var t1 = 0, t2 = 0, r1, r2;
    try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
    try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
    with (Math) {
        r1 = Number(arg1.toString().replace(".", ""))
        r2 = Number(arg2.toString().replace(".", ""))
        return (r1 / r2) * pow(10, t2 - t1);
    }
}
/**
 * 加法
 */
function accAdd(arg1, arg2) {
    var r1, r2, m, c;
    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
    c = Math.abs(r1 - r2);
    m = Math.pow(10, Math.max(r1, r2))
    if (c > 0) {
        var cm = Math.pow(10, c);
        if (r1 > r2) {
            arg1 = Number(arg1.toString().replace(".", ""));
            arg2 = Number(arg2.toString().replace(".", "")) * cm;
        }
        else {
            arg1 = Number(arg1.toString().replace(".", "")) * cm;
            arg2 = Number(arg2.toString().replace(".", ""));
        }
    }
    else {
        arg1 = Number(arg1.toString().replace(".", ""));
        arg2 = Number(arg2.toString().replace(".", ""));
    }
    return (arg1 + arg2) / m
}
/**
 * 减法
 */
function accSub(arg1, arg2) {
    var r1, r2, m, n;
    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
    m = Math.pow(10, Math.max(r1, r2));
    //last modify by deeka
    //动态控制精度长度
    n = (r1 >= r2) ? r1 : r2;
    return ((arg1 * m - arg2 * m) / m).toFixed(n);
}