$(function () {
    // resize时设置操作部分的样式(定位的top值)
    $('body').resize(function () {
        $(".projectManagementBottom").css('top', $(".projectManagementTop").height() + $(".businessNavigation").height() + $('.projectManagementBottom .detailContentBox-title').height() + 'px');
    });
    $('body').resize();

    // 拖动中间线
    $(".projectManagementBottom .detailContentBox-title").mousedown(function () {
        var isDrag = true;
        $(document).mousemove(function (e) {
            if (isDrag) {
                if (e.clientY >= ($(".breadcrumb").height() + $(".yk_head").height()) && $('.detailContentBox').height() - e.clientY + $(".breadcrumb").height() + $(".yk_head").height() > 200) {
                    $(".projectManagementTop").css('height', (e.clientY - $(".businessNavigation").height() - $(".breadcrumb").height() - $(".yk_head").height()) + 'px');
                    $(".projectManagementBottom").css('top', (e.clientY - $(".breadcrumb").height() - $(".yk_head").height()) + 'px');
                }
                ;
            }
            ;
        });
        $(document).unbind('mouseup').bind('mouseup', function () {
            $(document).unbind('mousemove');
            isDrag = false;
        });
        return false;
    });

    // 点击历史信息标题展开对应内容
    $(".projectManagementTop").on('click', '.detailContentBox-title', function () {
        if ($(this).hasClass('up')) {
            $(this).removeClass('up');
            $(this).nextAll().each(function (i, ele) {
                if (!$(ele).hasClass('hide')) {
                    $(ele).show();
                }
            });
        } else {
            $(this).addClass('up');
            $(this).nextAll().hide();
        }
    });

    // 点击导航展开对应部分的内容
    $('.businessNavigation').on("click", "li", function () {
        var scrollTopNo = $('.businessNavigation li').index($(this));
        if ($('.projectManagementTop .detailContentBox-title').eq(scrollTopNo).hasClass('up')) {
            $('.projectManagementTop .detailContentBox-title').eq(scrollTopNo).removeClass('up');
            $('.projectManagementTop .detailContentBox-title').eq(scrollTopNo).nextAll().each(function (i, ele) {
                if (!$(ele).hasClass('hide')) {
                    $(ele).show();
                }
            });
        }
        ;
        var scrollTopHeight = 0;
        if (scrollTopNo == 0) {
            scrollTopHeight = 0;
        } else {
            for (var i = 0; i < scrollTopNo; i++) {
                scrollTopHeight += $('.projectManagementTop .nodeShow').eq(i).height();
            }
            ;
            i = null;
        }
        ;
        $('.projectManagementTop .newTabAddUpdateBox').animate({'scrollTop': scrollTopHeight})
    });


    function formatMoney(moeny) {
        if(moeny || moeny == 0) {
            return commaDelimiter(moeny)
        }else {
            return '/'
        }
    }
    function formatNull(str) {
        if(str) {
            return str
        }else {
            return ''
        }
     }
    // 加载查看历史信息dom元素
    $(".projectManagementTop .newTabAddUpdateBox").load('/ledger/history', function () {
        var businessKey, async = true;
        if (GetRequest() && GetRequest()['historyId']) {
            businessKey = GetRequest()['historyId'];
            async = false;
            //window.location.href = window.location.href.split('?')[0]
        } else {
            businessKey = $('[name=businessKey]').val();
        }
        ;

        // 获取历史信息
        $.ajax({
            url: '/ledger/doView',
            type: 'get',
            data: {
                'id': businessKey,
                // 'businessType': 'LedgerInfoManage'
            },
            async: async,
            success: function (data) {
                if (data.success) {
                    var contractHistoryData = data.data;
                    // 回款信息
                    var contractMakingViewBox = $(".historyHideArea .contractMakingViewBox").clone();
                    contractMakingViewBox.find('.contractMakingView-customerName').text(contractHistoryData.ledgerAccountBasicInfo.customerName);
                    contractMakingViewBox.find('.contractMakingView-businessName').text(contractHistoryData.ledgerAccountBasicInfo.businessName);
                    contractMakingViewBox.find('.contractMakingView-businessNumber').text(contractHistoryData.ledgerAccountBasicInfo.businessNumber);
                    contractMakingViewBox.find('.contractMakingView-ledgerNumber').text(contractHistoryData.ledgerAccountBasicInfo.ledgerNumber);
                    contractMakingViewBox.find('.contractMakingView-ledgerTypeDictName').text(contractHistoryData.ledgerAccountBasicInfo.ledgerTypeDict.name);
                    contractMakingViewBox.find('.contractMakingView-currencyDictName').text(contractHistoryData.ledgerAccountBasicInfo.currencyDict.name);
                    contractMakingViewBox.find('.contractMakingView-ledgerAmount').text(contractHistoryData.ledgerAccountBasicInfo.ledgerAmount);
                    contractMakingViewBox.find('.contractMakingView-ledgerDate').text(contractHistoryData.ledgerAccountBasicInfo.ledgerDate);
                    // 贴现费用
                    contractMakingViewBox.find('.contractMakingView-discountCharge').text(contractHistoryData.ledgerAccountBasicInfo.discountCharge);
                    contractMakingViewBox.find('.contractMakingView-discountCharge2').text(contractHistoryData.ledgerAccountBasicInfo.discountCharge || 0);
                    contractMakingViewBox.find('.contractMakingView-remark').text(contractHistoryData.ledgerAccountBasicInfo.remark);

                    if(contractHistoryData.ledgerAccountBasicInfo.ledgerTypeDict.name == '现金') {
                        setInterval(() => {
                            $('.tiexianMoney').hide()
                        }, 300);
                    }

                    // 货款分配
                    contractMakingViewBox.find('.contractMakingView-goodsAssign').text(contractHistoryData.ledgerAccountBasicInfo.goodsAssign == 1 ? '是' : '否');
                    contractMakingViewBox.find('.contractMakingView-goodsAmount').text(contractHistoryData.ledgerAccountBasicInfo.goodsAmount);
                    contractMakingViewBox.find('.contractMakingView-goodsAmount2').text(contractHistoryData.ledgerAccountBasicInfo.goodsAmount || 0);

                    if(contractHistoryData.ledgerAccountBasicInfo.goodsAssign != 1) {
                        contractMakingViewBox.find('.contractMakingView-goodsAssign').css({'width': '85%'})
                        setTimeout(() => {
                            $('.goodsAssignStatus').hide()
                        }, 500);
                    }

                    if (contractHistoryData.goodsAssignList) {
                        var goodsInfoList = contractHistoryData.goodsAssignList
                        let totalFinancingOverdueInterest = 0;
                        let totalFinancingInterest = 0;
                        let totalFinancingManagementFee = 0;
                        let totalFinancingPrincipal = 0;
                        let totalAccrualAmount = 0;
                        let totalPlatformProfit = 0;
                        let totalDiscountAmount = 0;
                        let totalRefundManagementFee = 0;
                        let totalRefundInterest = 0;
                        let str = '';
                        for (var ii = 0; ii < goodsInfoList.length; ii++) {
                            var num = ii + 1;
                            if(goodsInfoList[ii].settlementNumber) {
                                $('.numberType').text('结算单单号')
                                // $('.settmentDate').text('结算日期')
                            }
                            str += `<tr class="goodsInfoListContent">
                                <td  class="enter">${num}</td>
                                <td  class="enter" sopAccountsReceivableId=${goodsInfoList[ii].sopAccountsReceivableId} billingFactoringBusinessLoanRecordId=${goodsInfoList[ii].billingFactoringBusinessLoanRecordId}>${goodsInfoList[ii].settlementNumber ? goodsInfoList[ii].settlementNumber : goodsInfoList[ii].receivablesNumber}</td>
                                <td  class="enter">${formatNull(goodsInfoList[ii].underlyingAssetsNo)}</td>
                                <td  class="enter">${formatNull(goodsInfoList[ii].contractNo)}</td>
                                <td  class="enter">${formatNull(goodsInfoList[ii].quotaDisburseBatch)}</td>
                                <td  class="enter">${formatNull(goodsInfoList[ii].supplierName)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].salesTotalPrice)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].purchaseTotalPrice)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].toAssignedAmount)}</td>
                                <td  class="enter">${goodsInfoList[ii].loanDate}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].loanAmount)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].returnedAmount)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].currentAssignAmount)}</td>
                                <td  class="enter">${goodsInfoList[ii].accrual ? '是' : '否'}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].financingOverdueInterest)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].financingInterest)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].financingManagementFee)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].financingPrincipal)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].accrualAmount)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].platformProfit)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].discountAmount)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].refundManagementFee)}</td>
                                <td  class="enter">${formatMoney(goodsInfoList[ii].refundInterest)}</td>
                                <td  class="enter"><i class="operateIconfont operateIcon-chakan" style="color: #5AC4FC;cursor: pointer"></i></td>
                                </tr>`
                                let financingOverdueInterest = 0;
                                let financingInterest = 0;
                                let financingManagementFee = 0;
                                let financingPrincipal = 0;
                                let accrualAmount = 0;
                                let platformProfit = 0;
                                let discountAmount = 0;
                                let refundManagementFee = 0;
                                let refundInterest = 0;
                                if(goodsInfoList[ii].financingOverdueInterest == null || goodsInfoList[ii].financingOverdueInterest == undefined) {
                                    financingOverdueInterest =  0
                                }else {
                                    financingOverdueInterest = goodsInfoList[ii].financingOverdueInterest
                                }
                                if(goodsInfoList[ii].financingInterest == null || goodsInfoList[ii].financingInterest == undefined) {
                                    financingInterest =  0
                                }else {
                                    financingInterest = goodsInfoList[ii].financingInterest
                                }
                                if(goodsInfoList[ii].financingManagementFee == null || goodsInfoList[ii].financingManagementFee == undefined) {
                                    financingManagementFee =  0
                                }else {
                                    financingManagementFee = goodsInfoList[ii].financingManagementFee
                                }
                                if(goodsInfoList[ii].financingPrincipal == null || goodsInfoList[ii].financingPrincipal == undefined) {
                                    financingPrincipal =  0
                                }else {
                                    financingPrincipal = goodsInfoList[ii].financingPrincipal
                                }
                                if(goodsInfoList[ii].accrualAmount == null || goodsInfoList[ii].accrualAmount == undefined) {
                                    accrualAmount =  0
                                }else {
                                    accrualAmount = goodsInfoList[ii].accrualAmount
                                }
                                if(goodsInfoList[ii].platformProfit == null || goodsInfoList[ii].platformProfit == undefined) {
                                    platformProfit =  0
                                }else {
                                    platformProfit = goodsInfoList[ii].platformProfit
                                }
                                if(goodsInfoList[ii].discountAmount == null || goodsInfoList[ii].discountAmount == undefined) {
                                    discountAmount =  0
                                }else {
                                    discountAmount = goodsInfoList[ii].discountAmount
                                }
                                if(goodsInfoList[ii].refundManagementFee == null || goodsInfoList[ii].refundManagementFee == undefined) {
                                    refundManagementFee =  0
                                }else {
                                    refundManagementFee = goodsInfoList[ii].refundManagementFee
                                }
                                if(goodsInfoList[ii].refundInterest == null || goodsInfoList[ii].refundInterest == undefined) {
                                    refundInterest =  0
                                }else {
                                    refundInterest = goodsInfoList[ii].refundInterest
                                }
                                totalFinancingOverdueInterest +=financingOverdueInterest
                                totalFinancingInterest +=financingInterest
                                totalFinancingManagementFee +=financingManagementFee
                                totalFinancingPrincipal +=financingPrincipal
                                totalAccrualAmount +=accrualAmount
                                totalPlatformProfit +=platformProfit
                                totalDiscountAmount +=discountAmount
                                totalRefundManagementFee +=refundManagementFee
                                totalRefundInterest +=refundInterest

                        }
                        ii = null;
                        contractMakingViewBox.find(".goodsInfoListHeader").after(str);
                        if(totalFinancingOverdueInterest == 0) {
                            contractMakingViewBox.find(".financingOverdueInterest").hide()
                        }else {
                            contractMakingViewBox.find(".financingOverdueInterest").show()
                            contractMakingViewBox.find(".totalFinancingOverdueInterest").text(commaDelimiter(totalFinancingOverdueInterest.toFixed(2)))
                        }

                        if(totalFinancingInterest == 0) {
                            contractMakingViewBox.find(".financingInterest").hide()
                        }else {
                            contractMakingViewBox.find(".financingInterest").show()
                            contractMakingViewBox.find(".totalFinancingInterest").text(commaDelimiter(totalFinancingInterest.toFixed(2)))
                        }

                        if(totalFinancingManagementFee == 0) {
                            contractMakingViewBox.find(".financingManagementFee").hide()
                        }else {
                            contractMakingViewBox.find(".financingManagementFee").show()
                            contractMakingViewBox.find(".totalFinancingManagementFee").text(commaDelimiter(totalFinancingManagementFee.toFixed(2)))
                        }

                        if(totalFinancingPrincipal == 0) {
                            contractMakingViewBox.find(".financingPrincipal").hide()
                        }else {
                            contractMakingViewBox.find(".financingPrincipal").show()
                            contractMakingViewBox.find(".totalFinancingPrincipal").text(commaDelimiter(totalFinancingPrincipal.toFixed(2)))
                        }

                        if(totalAccrualAmount == 0) {
                            contractMakingViewBox.find(".accrualAmount").hide()
                        }else {
                            contractMakingViewBox.find(".accrualAmount").show()
                            contractMakingViewBox.find(".totalAccrualAmount").text(commaDelimiter(totalAccrualAmount.toFixed(2)))
                        }

                        if(totalPlatformProfit == 0) {
                            contractMakingViewBox.find(".platformProfit").hide()
                        }else {
                            contractMakingViewBox.find(".platformProfit").show()
                            contractMakingViewBox.find(".totalPlatformProfit").text(commaDelimiter(totalPlatformProfit.toFixed(2)))
                        }

                        if(totalDiscountAmount == 0) {
                            contractMakingViewBox.find(".discountAmount").hide()
                        }else {
                            contractMakingViewBox.find(".discountAmount").show()
                            contractMakingViewBox.find(".totalDiscountAmount").text(commaDelimiter(totalDiscountAmount.toFixed(2)))
                        }

                        if(totalRefundManagementFee == 0) {
                            contractMakingViewBox.find(".refundManagementFee").hide()
                        }else {
                            contractMakingViewBox.find(".refundManagementFee").show()
                            contractMakingViewBox.find(".totalRefundManagementFee").text(commaDelimiter(totalRefundManagementFee.toFixed(2)))
                        }

                        if(totalRefundInterest == 0) {
                            contractMakingViewBox.find(".refundInterest").hide()
                        }else {
                            contractMakingViewBox.find(".refundInterest").show()
                            contractMakingViewBox.find(".totalRefundInterest").text(commaDelimiter(totalRefundInterest.toFixed(2)))
                        }
                    }

                    // 资金占用费
                    contractMakingViewBox.find('.contractMakingView-possessionCost').text(contractHistoryData.ledgerAccountBasicInfo.possessionCost == 1 ? '是' : '否');
                    if(contractHistoryData.ledgerAccountBasicInfo.possessionCost != 1) {
                        setTimeout(() => {
                            $('.tiexianListHeader').hide()
                        }, 500);
                    }
                    if(contractHistoryData.ledgerFundPossessionCostList) {
                        let trs = ''
                        const underList = contractHistoryData.ledgerFundPossessionCostList
                        let zijinMoney = null
                        for (var ii = 0; ii < underList.length; ii++) {
                            var num = ii + 1;
                            trs += '<tr>' +
                                '<td  class="enter">' + underList[ii].supplierName + '</td>' +
                                '<td  class="enter">' + commaDelimiter(underList[ii].fundPossessionCost) + '</td>' +
                                '<td  class="enter">' + underList[ii].assignReason + '</td>' +
                                '</tr>';
                            zijinMoney += Number(underList[ii].fundPossessionCost)
                        }

                        contractMakingViewBox.find('.contractMakingView-zijinMoney').text(zijinMoney || 0);
                        ii = null;
                        contractMakingViewBox.find(".tiexianListHeader").after(trs);
                    }else {
                        contractMakingViewBox.find('.contractMakingView-zijinMoney').text(0)
                    }

                    // 关联收款账号
                    if(contractHistoryData.ledgerSupplierBankRefList) {
                        let trs = ''
                        const ledgerSupplierBankRefList = contractHistoryData.ledgerSupplierBankRefList
                        for (var ii = 0; ii < ledgerSupplierBankRefList.length; ii++) {
                            var num = ii + 1;
                            trs += '<tr>' +
                                '<td  class="enter">' + ledgerSupplierBankRefList[ii].supplierBankCardInfo.supplierName + '</td>' +
                                '<td  class="enter">' + ledgerSupplierBankRefList[ii].supplierBankCardInfo.bankName + '</td>' +
                                '<td  class="enter">' + ledgerSupplierBankRefList[ii].supplierBankCardInfo.accountName + '</td>' +
                                '<td  class="enter">' + ledgerSupplierBankRefList[ii].supplierBankCardInfo.accountNumber + '</td>' +
                                '</tr>';
                        }
                        ii = null;
                        contractMakingViewBox.find(".bankListHeader").after(trs);
                    }

                    $(".showarea").append(contractMakingViewBox.show());



                    for (var i = 0; i < contractHistoryData.length; i++) {
                        // 添加导航dom
                        $(".businessNavigation ul").append('<li><div class="businessCircle">' + (i + 1) + '</div><div class="businessWord"><span>' + contractHistoryData[i].formBusinessName + '</span></div></li>');

                        //
                        if (contractHistoryData[i].formBusinessName == '录入分账') {
                            //标题log
                            var logText = '';
                            if (contractHistoryData[i].businessProcessingLogVo) {
                                if (contractHistoryData[i].businessProcessingLogVo.assigneeTypeName) {
                                    logText += '<span style="color: #333;font-size: 0.13rem;font-weight: normal">' + contractHistoryData[i].businessProcessingLogVo.assigneeTypeName + '：' + contractHistoryData[i].businessProcessingLogVo.assigneeName + ' </span>';
                                }

                                if (contractHistoryData[i].businessProcessingLogVo.status) {
                                    logText += '<span style="color: #333;font-size: 0.13rem;font-weight: normal">状态：' + contractHistoryData[i].businessProcessingLogVo.status + ' </span>';
                                }

                                if (contractHistoryData[i].businessProcessingLogVo.startTime) {
                                    logText += '<span style="color: #333;font-size: 0.13rem;font-weight: normal">开始时间：' + contractHistoryData[i].businessProcessingLogVo.startTime + ' </span>';
                                }

                                if (contractHistoryData[i].businessProcessingLogVo.endTime) {
                                    logText += '<span style="color: #333;font-size: 0.13rem;font-weight: normal">完成时间：' + contractHistoryData[i].businessProcessingLogVo.endTime + ' </span>';
                                }
                            }

                            var contractMakingViewBox = $(".historyHideArea .contractMakingViewBox").clone();
                            contractMakingViewBox.find('.contractMakingViewBox-log').append(logText)

                            contractMakingViewBox.find('.contractMakingView-supplierName').text(contractHistoryData[i].obj.ledgerAccountManagement?.purchaser);
                            contractMakingViewBox.find('.contractMakingView-purchaserCustomer').text(contractHistoryData[i].obj.ledgerAccountManagement?.businessName);
                            contractMakingViewBox.find('.contractMakingView-mortgageNumber').text(contractHistoryData[i].obj.ledgerAccountManagement?.businessNumber);
                            contractMakingViewBox.find('.contractMakingView-contractName').text(contractHistoryData[i].obj.ledgerAccountManagement?.gmtCreate);
                            contractMakingViewBox.find('.contractMakingView-contractNumber').text(contractHistoryData[i].obj.ledgerAccountManagement?.ledgerNumber);
                            contractMakingViewBox.find('.contractMakingView-contractAmount').text(commaDelimiter(contractHistoryData[i].obj.ledgerAccountManagement?.ledgerAmount) + ' ' + contractHistoryData[i].obj.ledgerAccountManagement?.currencyDict?.code);

                            if (contractHistoryData[i].obj.fundGoodsAssignTotal) {
                                //货款分配
                                contractMakingViewBox.find('.contractMakingView-goodsAssignAmount').text(commaDelimiter(contractHistoryData[i].obj.fundGoodsAssignTotal?.goodsAssignAmount));
                                contractMakingViewBox.find('.contractMakingView-discountChargeAmount').text(commaDelimiter(contractHistoryData[i].obj.fundGoodsAssignTotal?.discountChargeAmount));

                                contractMakingViewBox.find('.contractMakingView-saleTotal').text(commaDelimiter(contractHistoryData[i].obj.fundGoodsAssignTotal?.goodsAssignAmount));
                                contractMakingViewBox.find('.contractMakingView-tiexianTotal').text(commaDelimiter(contractHistoryData[i].obj.fundGoodsAssignTotal?.discountChargeAmount));

                                var goodsInfoList = contractHistoryData[i].obj.fundGoodsAssignTotal.fundGoodsAssignVoList;
                                if (goodsInfoList) {
                                    var trs = '';
                                    for (var ii = 0; ii < goodsInfoList.length; ii++) {
                                        var num = ii + 1;
                                        trs += '<tr>' +
                                            '<td  class="enter">' + num + '</td>' +
                                            '<td  class="enter">' + commaDelimiter(goodsInfoList[ii].assignableAmount) + '</td>' +
                                            '<td  class="enter">' + commaDelimiter(goodsInfoList[ii].assignAmount) + '</td>' +
                                            '<td  class="enter">' + goodsInfoList[ii].supplierName + '</td>' +
                                            '<td  class="enter">' + goodsInfoList[ii].billGoodsInformation.goodsName + '</td>' +
                                            '<td  class="enter">' + goodsInfoList[ii].billGoodsInformation.goodsFactory + '</td>' +
                                            '<td  class="enter">' + goodsInfoList[ii].billGoodsInformation.goodsType + '</td>' +
                                            '<td  class="enter">' + goodsInfoList[ii].billGoodsInformation.goodsUnit + '</td>' +
                                            '<td  class="enter">' + commaDelimiter(goodsInfoList[ii].billGoodsInformation.goodsNum) + '</td>' +
                                            '<td  class="enter">' + commaDelimiter(goodsInfoList[ii].invoicedQuantity) + '</td>' +
                                            '<td  class="enter">' + commaDelimiter(goodsInfoList[ii].financingInterest) + '</td>' +
                                            '<td  class="enter">' + commaDelimiter(goodsInfoList[ii].financingPrincipal) + '</td>' +
                                            '<td  class="enter">' + commaDelimiter(goodsInfoList[ii].platformProfit) + '</td>' +
                                            '<td  class="enter">' + commaDelimiter(goodsInfoList[ii].discountAmount) + '</td>' +
                                            '</tr>';
                                    }
                                    ii = null;
                                    contractMakingViewBox.find(".goodsInfoList_header").after(trs);
                                }
                            } else {
                                contractMakingViewBox.find(".goodsBox").remove();
                            }


                            //资金占用费
                            if (contractHistoryData[i].obj.ledgerFundPossessionCostList) {
                                var underList = contractHistoryData[i].obj.ledgerFundPossessionCostList;
                                if (underList) {
                                    var trs = '';
                                    var sumFundPossessionCost = 0;
                                    for (var ii = 0; ii < underList.length; ii++) {
                                        var num = ii + 1;
                                        trs += '<tr>' +
                                            '<td  class="enter">' + underList[ii].supplierName + '</td>' +
                                            '<td  class="enter">' + commaDelimiter(underList[ii].fundPossessionCost) + '</td>' +
                                            '<td  class="enter">' + underList[ii].assignReason + '</td>' +
                                            '</tr>';
                                        sumFundPossessionCost += underList[ii].fundPossessionCost
                                    }
                                    ii = null;
                                    contractMakingViewBox.find(".contractMakingView-zijinTotal").text(commaDelimiter(Math.round(sumFundPossessionCost*100)/100))
                                    contractMakingViewBox.find(".tiexianList_header").after(trs);
                                }
                            } else {
                                contractMakingViewBox.find('.tiexianList').remove()
                            }


                            if (contractHistoryData[i].obj.fundRetentionMoneyTotal.fundRetentionMoneyVoList.length) {
                                //质保金
                                contractMakingViewBox.find('.contractMakingView-surplusSalesRetentionAmount').text(commaDelimiter(contractHistoryData[i].obj.fundRetentionMoneyTotal?.surplusSalesRetentionAmount));
                                contractMakingViewBox.find('.contractMakingView-assignRetentionAmountTotal').text(commaDelimiter(contractHistoryData[i].obj.fundRetentionMoneyTotal?.assignRetentionAmountTotal));

                                contractMakingViewBox.find('.contractMakingView-retenTotal').text(commaDelimiter(contractHistoryData[i].obj.fundRetentionMoneyTotal?.assignRetentionAmountTotal));

                                var retenList = contractHistoryData[i].obj.fundRetentionMoneyTotal.fundRetentionMoneyVoList;
                                if (retenList) {
                                    var retenBox = '';
                                    for (var n = 0; n < retenList.length; n++) {
                                        retenBox += `<table>
                                                    <tr>
                                                        <td width="22%">
                                                            <span>供应商名称</span>
                                                        </td>
                                                        <td width="20%">
                                                            <span>剩余采购质保金</span>
                                                        </td>
                                                        <td width="20%">
                                                            <span>分配质保金</span>
                                                        </td>
                                                        <td width="19%">
                                                            <span>现金分配</span>
                                                        </td>
                                                        <td width="19%">
                                                            <span>抵货款</span>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td class="enter">` + retenList[n].supplierName + `</td>
                                                        <td class="enter">` + commaDelimiter(retenList[n].surplusPurchRetentionAmount) + `</td>
                                                        <td class="enter">` + commaDelimiter(retenList[n].assignRetentionAmount) + `</td>
                                                        <td class="enter">` + commaDelimiter(retenList[n].cashDistribution) + `</td>
                                                        <td class="enter">` + commaDelimiter(retenList[n].offsetMoney) + `</td>
                                                    </tr>
                                                </table>
                                                <table>
                                                        <tr>
                                                            <td colspan="14">
                                                                <span>抵扣货款</span>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td width="4%">
                                                                <span>编号</span>
                                                            </td>
                                                            <td width="8%">
                                                                <span>可分配金额</span>
                                                            </td>
                                                            <td width="9%">
                                                                <span>分配金额</span>
                                                            </td>
                                                            <td width="9%">
                                                                <span>供应商</span>
                                                            </td>
                                                            <td width="8%">
                                                                <span>名称</span>
                                                            </td>
                                                            <td width="6%">
                                                                <span>厂家</span>
                                                            </td>
                                                            <td width="6%">
                                                                <span>型号</span>
                                                            </td>
                                                            <td width="5%">
                                                                <span>单位</span>
                                                            </td>
                                                            <td width="6%">
                                                                <span>已结清数量</span>
                                                            </td>
                                                            <td width="6%">
                                                                <span>已开票数量</span>
                                                            </td>
                                                            <td width="7%">
                                                                <span>融资利息</span>
                                                            </td>
                                                            <td width="7%">
                                                                <span>融资本金</span>
                                                            </td>
                                                            <td width="7%">
                                                                <span>平台利润</span>
                                                            </td>
                                                            <td width="7%">
                                                                <span>实退折扣金额</span>
                                                            </td>
                                                        </tr>`
                                        var retenGoodsList = retenList[n].fundGoodsAssignVoList
                                        if (retenGoodsList) {
                                            for (var m = 0; m < retenGoodsList.length; m++) {
                                                retenBox += `<tr>
                                                            <td  class="enter">` + (m + 1) + `</td>
                                                            <td  class="enter">` + commaDelimiter(retenGoodsList[m].assignableAmount) + `</td>
                                                            <td  class="enter">` + commaDelimiter(retenGoodsList[m].assignAmount) + `</td>
                                                            <td  class="enter">` + retenGoodsList[m].supplierName + `</td>
                                                            <td  class="enter">` + retenGoodsList[m].billGoodsInformation.goodsName + `</td>
                                                            <td  class="enter">` + retenGoodsList[m].billGoodsInformation.goodsFactory + `</td>
                                                            <td  class="enter">` + retenGoodsList[m].billGoodsInformation.goodsType + `</td>
                                                            <td  class="enter">` + retenGoodsList[m].billGoodsInformation.goodsUnit + `</td>
                                                            <td  class="enter">` + commaDelimiter(retenGoodsList[m].billGoodsInformation.goodsNum) + `</td>
                                                            <td  class="enter">` + commaDelimiter(retenGoodsList[m].invoicedQuantity) + `</td>
                                                            <td  class="enter">` + commaDelimiter(retenGoodsList[m].financingInterest) + `</td>
                                                            <td  class="enter">` + commaDelimiter(retenGoodsList[m].financingPrincipal) + `</td>
                                                            <td  class="enter">` + commaDelimiter(retenGoodsList[m].platformProfit) + `</td>
                                                            <td  class="enter">` + commaDelimiter(retenGoodsList[m].discountAmount) + `</td>
                                                         </tr>`
                                            }
                                            m = null;
                                        }

                                        retenBox += `</table>`


                                    }
                                    n = null;
                                    contractMakingViewBox.find(".retentionBox").append(retenBox);
                                }
                            } else {
                                contractMakingViewBox.find(".supplierList").remove();
                            }


                            $(".showarea").append(contractMakingViewBox.show());

                        }
                        ;

                        //审核
                        if (contractHistoryData[i].formBusinessName == '财务审核') {
                            //标题log
                            var logText = '';
                            if (contractHistoryData[i].businessProcessingLogVo) {
                                if (contractHistoryData[i].businessProcessingLogVo.assigneeTypeName) {
                                    logText += '<span style="color: #333;font-size: 0.13rem;font-weight: normal">' + contractHistoryData[i].businessProcessingLogVo.assigneeTypeName + '：' + contractHistoryData[i].businessProcessingLogVo.assigneeName + ' </span>';
                                }

                                if (contractHistoryData[i].businessProcessingLogVo.status) {
                                    logText += '<span style="color: #333;font-size: 0.13rem;font-weight: normal">状态：' + contractHistoryData[i].businessProcessingLogVo.status + ' </span>';
                                }

                                if (contractHistoryData[i].businessProcessingLogVo.startTime) {
                                    logText += '<span style="color: #333;font-size: 0.13rem;font-weight: normal">开始时间：' + contractHistoryData[i].businessProcessingLogVo.startTime + ' </span>';
                                }

                                if (contractHistoryData[i].businessProcessingLogVo.endTime) {
                                    logText += '<span style="color: #333;font-size: 0.13rem;font-weight: normal">完成时间：' + contractHistoryData[i].businessProcessingLogVo.endTime + ' </span>';
                                }
                                // $('.terminationContractApprovalViewBox-log').append(logText)
                            }

                            var terminationContractApprovalViewBox = $(".historyHideArea .terminationContractApprovalViewBox").clone();
                            terminationContractApprovalViewBox.find('.terminationContractApprovalViewBox-log').append(logText)

                            //审批结论
                            terminationContractApprovalViewBox.find(".terminationContractApprovalView-approvalConclusion").text(contractHistoryData[i].obj.approvalConclusion);

                            //审批意见
                            if (contractHistoryData[i].obj.approvalComment) {
                                terminationContractApprovalViewBox.find(".terminationContractApprovalView-approvalOpinion").text(contractHistoryData[i].obj.approvalComment);
                            }

                            $(".showarea").append(terminationContractApprovalViewBox.show());
                        }

                    }
                    ;
                    i = null;
                } else {
                    if (data.msg != '返回结果为空') {
                        new $.zui.Messager('获取历史信息失败:' + data.msg, {
                            type: 'danger'
                        }).show();
                    }
                    ;
                }
                ;

                // 导航排序
                $('.businessNavigation .businessCircle').each(function (i, ele) {
                    $(ele).text(i + 1)
                })

                // 历史信息排序
                $(".projectManagementTop .detailContentBox-title").each(function (i, ele) {
                    $(ele).text((i + 1) + '、' + $(ele).text());
                    $(ele).addClass('up');
                    $(ele).nextAll().hide();
                });

                if ($('.projectManagementTop .showarea .nodeShow').length <= 0) {
                    $('.projectManagementBottom').css('top', '0')
                }
                ;

                // 新窗口查看时需要计算高度
                $(".projectManagementTop.historyTop").css('height', $("body").height() - $(".breadcrumb").height() - $(".businessNavigation").height() - 15)
                $(window).bind('resize', function () {
                    $(".projectManagementTop.historyTop").css('height', $("body").height() - $(".breadcrumb").height() - $(".businessNavigation").height() - 15)
                })
            },
            error: function (status) {
                new $.zui.Messager('获取历史信息时发生错误:' + status, {
                    type: 'danger'
                }).show();
            }
        });

        // 查看收支计划
        $('.contractMakingViewBox').on( 'click', '.goodsBox .operateIconfont', function () {
            var sopAccountsReceivableId = $(this).parent().parent().find('td').eq(1).attr('sopAccountsReceivableId');
            var billingFactoringBusinessLoanRecordId = $(this).parent().parent().find('td').eq(1).attr('billingFactoringBusinessLoanRecordId');
            $('#planList').setGridParam({
                mtype: 'GET',
                url: '/ledger/doFindPayCollPlanFactoringList',
                datatype: 'json',
                postData: {
                    'sopAccountsReceivableId': sopAccountsReceivableId,
                    'billingFactoringBusinessLoanRecordId': billingFactoringBusinessLoanRecordId
                },
                page: 1
            });
            $('#planList').trigger('reloadGrid');
            $("#myModal-planBox").modal("show");
            $("#myModal-planBox").on('shown.zui.modal', function () {
                $(".modal-dialog").css({'margin-top': '58px'})
                $(window).resize();

            })
            return false;
        })

        function showAmountStard(cellValue, options, rowObject) {
            return '<span class="tableRowMultipleSpan" style="text-align:left;">' + handleListAmountFn(rowObject.amount, (rowObject.currencyType ? rowObject.currencyType.code : '')) + '</span>';
        };

        // 收放款执行(保理融资款)--显示实收付日期
        function showSumDateAllocation(cellValue, options, rowObject) {
            var planDateStr = '';
            if( rowObject.paymentCollectionType == '放款' ){
                if (rowObject.loanRecordList && rowObject.loanRecordList.length > 0) {
                    for (var i = 0; i < rowObject.loanRecordList.length; i++) {
                        planDateStr += '<span class="tableRowMultipleSpan" style="text-align:left;">' + getStandardDate(new Date(rowObject.loanRecordList[i].thisLoanDate)) + '</span>'
                    }
                    ;
                    i = null;
                } else {
                    planDateStr += '<span class="tableRowMultipleSpan" style="text-align:left;">' + '' + '</span>'
                }
            }
            if( rowObject.paymentCollectionType == '收款' ){
                if (rowObject.amountAllocationList && rowObject.amountAllocationList.length > 0) {
                    for (var i = 0; i < rowObject.amountAllocationList.length; i++) {
                        planDateStr += '<span class="tableRowMultipleSpan" style="text-align:left;">' + getStandardDate(new Date(rowObject.amountAllocationList[i].actualDate)) + '</span>'
                    }
                    ;
                    i = null;
                } else {
                    planDateStr += '<span class="tableRowMultipleSpan" style="text-align:left;">' + '' + '</span>'
                }
            }
            return planDateStr;
        }

        // 收放款执行(保理融资款)--显示实收/付总金额
        function showSumAmountAllocation(cellValue, options, rowObject) {
            var sumAmount = '';
            if (rowObject.paymentCollectionType == '放款') {
                if (rowObject.loanRecordList && rowObject.loanRecordList.length > 0) {
                    for (var i = 0; i < rowObject.loanRecordList.length; i++) {
                        sumAmount += '<span class="tableRowMultipleSpan" style="text-align:left;">' + handleListAmountFn(rowObject.loanRecordList[i].thisLoanAmount, (rowObject.currencyType ? rowObject.currencyType.code : '')) + '</span>'
                    }
                    ;
                    i = null;
                } else {
                    sumAmount += '<span class="tableRowMultipleSpan" style="text-align:left;">' + '' + '</span>'
                }
            }
            if (rowObject.paymentCollectionType == '收款') {
                if (rowObject.amountAllocationList && rowObject.amountAllocationList.length > 0) {
                    for (var i = 0; i < rowObject.amountAllocationList.length; i++) {
                        sumAmount += '<span class="tableRowMultipleSpan" style="text-align:left;">' + handleListAmountFn(rowObject.amountAllocationList[i].actualAmount, (rowObject.currencyType ? rowObject.currencyType.code : '')) + '</span>'
                    }
                    ;
                    i = null;
                } else {
                    sumAmount += '<span class="tableRowMultipleSpan" style="text-align:left;">' + '' + '</span>'
                }
            }

            return sumAmount;
            //return '<span class="tableRowMultipleSpan" style="text-align:right;">'+handleListAmountFn(rowObject.sumAmountAllocation,(rowObject.currencyType?rowObject.currencyType.code:''))+'</span>';
        };
        // 查看收支计划
        function tablefunction2(tableid) {
            var tipword = '', pageid = '', pageNo = 1, postData = {};
            url = '', colNamesArray = [], colModelArray = [];
            switch (tableid) {
                case '#planList':
                    tipword = '收放款计划';
                    pageid = '#planListPage';
                    pageNo = 1;
                    postData = {'sopAccountsReceivableId': '', billingFactoringBusinessLoanRecordId: ''};
                    url = '/ledger/doFindPayCollPlanFactoringList';

                    colNamesArray = ['ID', '序号', '金额类型', '收放款类型', '收款主体', '约定日期', '<p style="text-align:left;margin:0;">应收/付金额</p>', '<p style="text-align:left;margin:0;">实收/付日期</p>', '<p style="text-align:left;margin:0;">实收/付总金额</p>','本次分配金额', '状态',];
                    colModelArray = [
                        {name: 'id', label: 'ID', hidedlg: true, hidden: true, sortable: false, title: false},
                        {name: 'orderNumber', label: '序号', hidedlg: true, width: 60, sortable: false, title: false},
                        {name: 'amountType.name', label: '金额类型', sortable: false, align: 'left', width: 100, title: false},
                        {
                            name: 'paymentCollectionType',
                            label: '收放款类型',
                            sortable: false,
                            align: 'left',
                            width: 100,
                            title: false
                        },
                        {name: 'receivingSubject', label: '收款主体', sortable: false, align: 'left', width: 100, title: false},
                        {
                            name: 'planDate',
                            label: '约定日期',
                            sortable: false,
                            align: 'left',
                            width: 120,
                            title: false,

                        },
                        {
                            name: 'amount',
                            label: '应收/付金额',
                            sortable: false,
                            align: 'left',
                            width: 120,
                            title: false,
                            formatter: showAmountStard
                        },
                        {
                            name: 'sumDateAllocation',
                            label: '实收/付日期',
                            sortable: false,
                            align: 'left',
                            width: 120,
                            title: false,
                            classes: 'tableRowMultiple',
                            formatter: showSumDateAllocation
                        },
                        {
                            name: 'sumAmountAllocation',
                            label: '实收/付金额',
                            sortable: false,
                            align: 'left',
                            width: 120,
                            title: false,
                            classes: 'tableRowMultiple',
                            formatter: showSumAmountAllocation
                        },
                        {
                            name: 'sumDateAllocation',
                            label: '本次分配金额',
                            sortable: false,
                            align: 'left',
                            width: 120,
                            title: false,
                            formatter: showAmountStard
                        },
                        {name: 'status.name', label: '状态', sortable: false, align: 'left', width: 100, title: false},
                    ];
                    break;
            }
            ;
            sxUtil.jqGrid(tableid, {
                colNames: colNamesArray,
                colModel: colModelArray,
                height: 'auto',
                mtype: 'GET',
                url: url,
                pager: pageid,
                multiselect: false,
                rownumbers: false,
                postData: postData,
                page: pageNo,
                loadError: function () {
                    // new $.zui.Messager(tipword + '列表加载失败', {
                    //     type: 'warning'
                    // }).show();
                }
            }, true);
            $(tableid).trigger('reloadGrid');
        };
        tablefunction2('#planList')
    });
})
