$(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 calcMoney(money) {
        if(money === null || money === undefined) {
            return '/'
        }else {
            return commaDelimiter(money)
        }

    }

    // 加载查看历史信息dom元素
    $(".projectManagementTop .newTabAddUpdateBox").load('/saleInvoice/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:'/businessProcessingTask/doBusinessHistoryView',
            type:'get',
            data:{
                'businessKey':businessKey,
                'businessType':'invoiceManager'
            },
            async:async,
            success:function(data){
                if( data.success ){
                    var contractHistoryData = data.data;
                    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-enterpriseName').text(contractHistoryData[i].obj.customer.enterpriseName);
                            contractMakingViewBox.find('.contractMakingView-businessName').text(contractHistoryData[i].obj.businessBasicInfo.name);
                            contractMakingViewBox.find('.contractMakingView-businessNumber').text(contractHistoryData[i].obj.businessNumber);
                            contractMakingViewBox.find('.contractMakingView-platformName').text(contractHistoryData[i].obj.businessBasicInfo.platform.platformName);

                            // 开票信息
                            contractMakingViewBox.find('.contractMakingView-enterpriseName').text(contractHistoryData[i].obj.customer.enterpriseName);
                            contractMakingViewBox.find('.contractMakingView-taxIdentifyNumber').text(contractHistoryData[i].obj.taxIdentifyNumber);
                            contractMakingViewBox.find('.contractMakingView-address').text(contractHistoryData[i].obj.address);
                            contractMakingViewBox.find('.contractMakingView-phone').text(contractHistoryData[i].obj.phone);
                            contractMakingViewBox.find('.contractMakingView-accountBankName').text(contractHistoryData[i].obj.accountBankName);
                            contractMakingViewBox.find('.contractMakingView-accountNumber').text(contractHistoryData[i].obj.accountNumber);
                            contractMakingViewBox.find('.contractMakingView-invoiceTypeDic').text(contractHistoryData[i].obj.invoiceTypeDic.name);
                            contractMakingViewBox.find('.contractMakingView-amountKind').text((contractHistoryData[i].obj.amountKindDic.name));
                            contractMakingViewBox.find('.contractMakingView-remark').text((contractHistoryData[i].obj.remark));
                            contractMakingViewBox.find('.contractMakingView-openAmount').text((calcMoney(contractHistoryData[i].obj.openAmount)));

                            //销售合同附件
                            // if( contractHistoryData[i].obj.saleInvoiceInfo.salesContractFiles ){
                            //     var fileList=contractHistoryData[i].obj.saleInvoiceInfo.salesContractFiles;
                            //     var filesHtm='';
                            //     if( fileList.length>0 ){
                            //         //contractMakingViewBox.find(".uploadFile").removeClass("hide");
                            //         for(var ii=0;ii<fileList.length;ii++){
                            //             filesHtm+='<div class="uploaderFile oldFile">'+
                            //                 '<input type="hidden" class="fileid" value="'+fileList[ii].id+'">'+
                            //                 '<div class="fileContent"><div class="file-wrapper">';
                            //             var fileType=fileList[ii].fileType;
                            //             if(fileType=='.jpg' || fileType=='.jpeg' || fileType=='.png' || fileType=='.bmp'){
                            //                 filesHtm+='<div class="file-icon" style="color: rgb(119, 31, 173);"><div  class="file-icon-image"'+
                            //                     'style="background-image:url('+ fileList[ii].path +');"></div></div>';
                            //             }else {
                            //                 filesHtm+='<div class="file-icon" style="color:#5AC4FC;"><div class="file-icon-image"><i class="icon icon-file-pdf"></i></div></div>';
                            //             }
                            //             filesHtm+='<div class="content">'+
                            //                 '<div class="file-name">'+fileList[ii].originalName+'</div>'+
                            //                 '<div class="file-size small text-muted">'+(fileList[ii].size/1024/1024).toFixed(2)+'MB</div>'+
                            //                 '</div>'+
                            //                 '<div class="actions" style="width: 1.032rem;">'+
                            //                 '<a class="btn btn-link btn-preview-file" target="_blank" href="/fileStorage/preview?fileId='+fileList[ii].id+'">'+
                            //                 '<em style="display:none">预览</em>'+
                            //                 '<i class="operateIconfont operateIcon-yulan"></i>'+
                            //                 '</a>'+
                            //                 '<a class="btn btn-link btn-download-file" style="float:right" href="/fileStorage/downloadFile?fileId='+fileList[ii].id+'">'+
                            //                 '<em style="display:none">下载</em>'+
                            //                 '<i class="operateIconfont operateIcon-xiazai"></i>'+
                            //                 '</a></div></div>';
                            //         }
                            //         contractMakingViewBox.find(".contractMakingView-saleFile").append(filesHtm);
                            //     }
                            // }
                            //采购合同附件
                           /*  if( contractHistoryData[i].obj.files ){
                                var fileList=contractHistoryData[i].obj.files;
                                var filesHtm='';
                                if( fileList.length>0 ){
                                    //contractMakingViewBox.find(".uploadFile").removeClass("hide");
                                    for(var ii=0;ii<fileList.length;ii++){
                                        filesHtm+='<div class="uploaderFile oldFile">'+
                                            '<input type="hidden" class="fileid" value="'+fileList[ii].id+'">'+
                                            '<div class="fileContent"><div class="file-wrapper">';
                                        var fileType=fileList[ii].fileType;
                                        if(fileType=='.jpg' || fileType=='.jpeg' || fileType=='.png' || fileType=='.bmp'){
                                            filesHtm+='<div class="file-icon" style="color: rgb(119, 31, 173);"><div  class="file-icon-image"'+
                                                'style="background-image:url('+ fileList[ii].path +');"></div></div>';
                                        }else {
                                            filesHtm+='<div class="file-icon" style="color:#5AC4FC;"><div class="file-icon-image"><i class="icon icon-file-pdf"></i></div></div>';
                                        }
                                        filesHtm+='<div class="content">'+
                                            '<div class="file-name">'+fileList[ii].originalName+'</div>'+
                                            '<div class="file-size small text-muted">'+(fileList[ii].size/1024/1024).toFixed(2)+'MB</div>'+
                                            '</div>'+
                                            '<div class="actions" style="width: 1.032rem;">'+
                                            '<a class="btn btn-link btn-preview-file" target="_blank" href="/fileStorage/preview?fileId='+fileList[ii].id+'">'+
                                            '<em style="display:none">预览</em>'+
                                            '<i class="operateIconfont operateIcon-yulan"></i>'+
                                            '</a>'+
                                            '<a class="btn btn-link btn-download-file" style="float:right" href="/fileStorage/downloadFile?fileId='+fileList[ii].id+'">'+
                                            '<em style="display:none">下载</em>'+
                                            '<i class="operateIconfont operateIcon-xiazai"></i>'+
                                            '</a></div></div>';
                                    }
                                    contractMakingViewBox.find(".contractMakingView-purchFile").append(filesHtm);
                                }
                            } */
                            //发票
                            if( contractHistoryData[i].obj.files ){
                                var fileList=contractHistoryData[i].obj.files;
                                var filesHtm='';
                                if( fileList.length>0 ){
                                    //contractMakingViewBox.find(".uploadFile").removeClass("hide");
                                    for(var ii=0;ii<fileList.length;ii++){
                                        filesHtm+='<div class="uploaderFile oldFile">'+
                                            '<input type="hidden" class="fileid" value="'+fileList[ii].id+'">'+
                                            '<div class="fileContent"><div class="file-wrapper">';
                                        var fileType=fileList[ii].fileType;
                                        if(fileType=='.jpg' || fileType=='.jpeg' || fileType=='.png' || fileType=='.bmp'){
                                            filesHtm+='<div class="file-icon" style="color: rgb(119, 31, 173);"><div  class="file-icon-image"'+
                                                'style="background-image:url('+ fileList[ii].path +');"></div></div>';
                                        }else {
                                            filesHtm+='<div class="file-icon" style="color:#5AC4FC;"><div class="file-icon-image"><i class="icon icon-file-pdf"></i></div></div>';
                                        }
                                        filesHtm+='<div class="content">'+
                                            '<div class="file-name">'+fileList[ii].originalName+'</div>'+
                                            '<div class="file-size small text-muted">'+(fileList[ii].size/1024/1024).toFixed(2)+'MB</div>'+
                                            '</div>'+
                                            '<div class="actions" style="width: 1.032rem;">'+
                                            '<a class="btn btn-link btn-preview-file" target="_blank" href="/fileStorage/preview?fileId='+fileList[ii].id+'">'+
                                            '<em style="display:none">预览</em>'+
                                            '<i class="operateIconfont operateIcon-yulan"></i>'+
                                            '</a>'+
                                            // '<a class="btn btn-link btn-download-file" style="float:right" href="/fileStorage/downloadFile?fileId='+fileList[ii].id+'">'+
                                            // '<em style="display:none">下载</em>'+
                                            // '<i class="operateIconfont operateIcon-xiazai"></i>'+
                                            // '</a>'+
                                            '</div></div>';
                                    }
                                    contractMakingViewBox.find(".contractMakingView-invoiceFile").append(filesHtm);
                                }
                            }


                            //货物信息
                            var goodsInfoList=contractHistoryData[i].obj.invoiceHisGoodsInfos;
                            if(contractHistoryData[i].obj.amountKindDic.name=='货款') {
                                if( goodsInfoList ){
                                    let totalAmount = 0;
                                    let totalInvoicing = 0;
                                    var trs='';
                                    for(var ii=0;ii<goodsInfoList.length;ii++ ){
                                        var num=ii+1;
                                        trs+='<tr>'+
                                            '<td  class="enter">'+num+'</td>'+
                                            '<td  class="enter">'+goodsInfoList[ii].settlementNumber+'</td>'+
                                            '<td  class="enter">'+goodsInfoList[ii].goodsName+'</td>'+
                                            '<td  class="enter">'+goodsInfoList[ii].goodsType+'</td>'+
                                            '<td  class="enter">'+goodsInfoList[ii].goodsUnit+'</td>'+
                                            '<td  class="enter">'+(Number(goodsInfoList[ii].goodsQuantity)).toFixed(4)+'</td>'+
                                            '<td  class="enter">'+calcMoney((Number(goodsInfoList[ii].salesPrice)).toFixed(2))+'</td>'+
                                            '<td  class="enter">'+calcMoney((Number(goodsInfoList[ii].salesTotalPrice)).toFixed(2))+'</td>'+
                                            '<td  class="enter">'+calcMoney((Number(goodsInfoList[ii].usedNum ? goodsInfoList[ii].usedNum : '')).toFixed(4))+'</td>'+
                                            '<td  class="enter">'+calcMoney((Number(goodsInfoList[ii].openQuantity)).toFixed(4))+'</td>'+
                                            '<td  class="enter">'+calcMoney((Number(goodsInfoList[ii].openAmount)).toFixed(2))+'</td>'+
                                            '</tr>';

                                        let openAmount =  0;
                                        let openQuantity = 0;
                                        if(goodsInfoList[ii].openAmount == null || goodsInfoList[ii].openAmount == undefined) {
                                            openAmount =  0
                                        }else {
                                            openAmount = goodsInfoList[ii].openAmount
                                        }
                                        if(goodsInfoList[ii].openQuantity == null || goodsInfoList[ii].openQuantity == undefined) {
                                            openQuantity =  0
                                        }else {
                                            openQuantity = goodsInfoList[ii].openQuantity
                                        }
                                        totalAmount +=openAmount
                                        totalInvoicing +=openQuantity
                                    }
                                    ii=null;
                                    contractMakingViewBox.find(".totalAmount").text(commaDelimiter(totalAmount.toFixed(2)))
                                    contractMakingViewBox.find(".totalInvoicing").text(commaDelimiter(totalInvoicing.toFixed(4)))
                                    contractMakingViewBox.find(".goodsInfoList_header").after(trs);
                                }
                                if(contractHistoryData[i].obj.invoiceHisPossessionCostInfos.possessionCostType == 1) {
                                    contractMakingViewBox.find('.contractMakingView-possessionCostType').text(contractHistoryData[i].obj.invoiceHisPossessionCostInfos.possessionCostType == 1 ? '有，货物加价款' : '无');
                                    contractMakingViewBox.find('.contractMakingView-possessionCost').text((contractHistoryData[i].obj.invoiceHisPossessionCostInfos.possessionCost + '元'));
                                }else {
                                    setTimeout(() => {
                                        contractMakingViewBox.find('.contractMakingView-possessionCostType').text( '无');
                                        contractMakingViewBox.find('.contractMakingView-possessionCostType').css({width: '85%'})
                                        contractMakingViewBox.find('.possessionCostTypeStatus').remove()
                                    }, 300);
                                }


                            }else if(contractHistoryData[i].obj.amountKindDic.name=='贴现费用') {

                                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">'+goodsInfoList[ii].goodsName+'</td>'+
                                            '<td  class="enter">'+goodsInfoList[ii].goodsType+'</td>'+
                                            '<td  class="enter">'+goodsInfoList[ii].goodsUnit+'</td>'+
                                            '<td  class="enter">'+calcMoney((Number(goodsInfoList[ii].openAmount)).toFixed(2))+'</td>'+
                                            '</tr>';
                                    }
                                    ii=null;
                                    contractMakingViewBox.find(".tiexianList_header").after(trs);

                                }

                            }else if(contractHistoryData[i].obj.amountKindDic.name=='资金占用费') {
                                goodsInfoList=contractHistoryData[i].obj.invoiceHisSupplierInfos;
                                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">'+goodsInfoList[ii].supplierName+'</td>'+
                                            '<td  class="enter">'+calcMoney((Number(goodsInfoList[ii].openAmount)).toFixed(2))+'</td>'+
                                            '</tr>';
                                    }
                                    ii=null;
                                    contractMakingViewBox.find(".zijinList_header").after(trs);

                                }

                            }
                            $(".showarea").append(contractMakingViewBox.show());
                            if(contractHistoryData[i].obj.amountKindDic.name=='货款') {
                                contractMakingViewBox.find(".tiexianList").remove();
                                contractMakingViewBox.find(".supplierList").remove();
                            }else if(contractHistoryData[i].obj.amountKindDic.name=='贴现费用') {
                                contractMakingViewBox.find(".goodsList").remove();
                                contractMakingViewBox.find(".supplierList").remove();
                            }else if(contractHistoryData[i].obj.amountKindDic.name=='资金占用费') {
                                contractMakingViewBox.find(".goodsList").remove();
                                contractMakingViewBox.find(".tiexianList").remove();
                            }

                        };

                        //审核
                        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)

                             // 销售合同信息
                            if( contractHistoryData[i].obj.salesContract ){
                                var fileList=contractHistoryData[i].obj.salesContract;
                                var filesHtm='';
                                if( fileList.length>0 ){
                                    //contractMakingViewBox.find(".uploadFile").removeClass("hide");
                                    for(var ii=0;ii<fileList.length;ii++){
                                        filesHtm+='<div class="uploaderFile oldFile">'+
                                            '<input type="hidden" class="fileid" value="'+fileList[ii].id+'">'+
                                            '<div class="fileContent"><div class="file-wrapper">';
                                        var fileType=fileList[ii].fileType;
                                        if(fileType=='.jpg' || fileType=='.jpeg' || fileType=='.png' || fileType=='.bmp'){
                                            filesHtm+='<div class="file-icon" style="color: rgb(119, 31, 173);"><div  class="file-icon-image"'+
                                                'style="background-image:url('+ fileList[ii].path +');"></div></div>';
                                        }else {
                                            filesHtm+='<div class="file-icon" style="color:#5AC4FC;"><div class="file-icon-image"><i class="icon icon-file-pdf"></i></div></div>';
                                        }
                                        filesHtm+='<div class="content">'+
                                            '<div class="file-name">'+fileList[ii].originalName+'</div>'+
                                            '<div class="file-size small text-muted">'+(fileList[ii].size/1024/1024).toFixed(2)+'MB</div>'+
                                            '</div>'+
                                            '<div class="actions" style="width: 1.032rem;">'+
                                            '<a class="btn btn-link btn-preview-file" target="_blank" href="/fileStorage/preview?fileId='+fileList[ii].id+'">'+
                                            '<em style="display:none">预览</em>'+
                                            '<i class="operateIconfont operateIcon-yulan"></i>'+
                                            '</a>'+
                                            // '<a class="btn btn-link btn-download-file" style="float:right" href="/fileStorage/downloadFile?fileId='+fileList[ii].id+'">'+
                                            // '<em style="display:none">下载</em>'+
                                            // '<i class="operateIconfont operateIcon-xiazai"></i>'+
                                            // '</a>'+
                                            '</div></div>';
                                    }
                                    terminationContractApprovalViewBox.find(".terminationContractApprovalView-salesContract").append(filesHtm);
                                }
                            }

                            // 采购合同信息：
                            if( contractHistoryData[i].obj.purchContract ){
                                var fileList=contractHistoryData[i].obj.purchContract;
                                var filesHtm='';
                                if( fileList.length>0 ){
                                    //contractMakingViewBox.find(".uploadFile").removeClass("hide");
                                    for(var ii=0;ii<fileList.length;ii++){
                                        filesHtm+='<div class="uploaderFile oldFile">'+
                                            '<input type="hidden" class="fileid" value="'+fileList[ii].id+'">'+
                                            '<div class="fileContent"><div class="file-wrapper">';
                                        var fileType=fileList[ii].fileType;
                                        if(fileType=='.jpg' || fileType=='.jpeg' || fileType=='.png' || fileType=='.bmp'){
                                            filesHtm+='<div class="file-icon" style="color: rgb(119, 31, 173);"><div  class="file-icon-image"'+
                                                'style="background-image:url('+ fileList[ii].path +');"></div></div>';
                                        }else {
                                            filesHtm+='<div class="file-icon" style="color:#5AC4FC;"><div class="file-icon-image"><i class="icon icon-file-pdf"></i></div></div>';
                                        }
                                        filesHtm+='<div class="content">'+
                                            '<div class="file-name">'+fileList[ii].originalName+'</div>'+
                                            '<div class="file-size small text-muted">'+(fileList[ii].size/1024/1024).toFixed(2)+'MB</div>'+
                                            '</div>'+
                                            '<div class="actions" style="width: 1.032rem;">'+
                                            '<a class="btn btn-link btn-preview-file" target="_blank" href="/fileStorage/preview?fileId='+fileList[ii].id+'">'+
                                            '<em style="display:none">预览</em>'+
                                            '<i class="operateIconfont operateIcon-yulan"></i>'+
                                            '</a>'+
                                            // '<a class="btn btn-link btn-download-file" style="float:right" href="/fileStorage/downloadFile?fileId='+fileList[ii].id+'">'+
                                            // '<em style="display:none">下载</em>'+
                                            // '<i class="operateIconfont operateIcon-xiazai"></i>'+
                                            // '</a>'+
                                            '</div></div>';
                                    }
                                    terminationContractApprovalViewBox.find(".terminationContractApprovalView-purchContract").append(filesHtm);
                                }
                            }

                            // 下游结算单：
                            if( contractHistoryData[i].obj.settlementUpstreamSignedFile ){
                                var fileList=contractHistoryData[i].obj.settlementUpstreamSignedFile;
                                var filesHtm='';
                                if( fileList.length>0 ){
                                    //contractMakingViewBox.find(".uploadFile").removeClass("hide");
                                    for(var ii=0;ii<fileList.length;ii++){
                                        filesHtm+='<div class="uploaderFile oldFile">'+
                                            '<input type="hidden" class="fileid" value="'+fileList[ii].id+'">'+
                                            '<div class="fileContent"><div class="file-wrapper">';
                                        var fileType=fileList[ii].fileType;
                                        if(fileType=='.jpg' || fileType=='.jpeg' || fileType=='.png' || fileType=='.bmp'){
                                            filesHtm+='<div class="file-icon" style="color: rgb(119, 31, 173);"><div  class="file-icon-image"'+
                                                'style="background-image:url('+ fileList[ii].path +');"></div></div>';
                                        }else {
                                            filesHtm+='<div class="file-icon" style="color:#5AC4FC;"><div class="file-icon-image"><i class="icon icon-file-pdf"></i></div></div>';
                                        }
                                        filesHtm+='<div class="content">'+
                                            '<div class="file-name">'+fileList[ii].originalName+'</div>'+
                                            '<div class="file-size small text-muted">'+(fileList[ii].size/1024/1024).toFixed(2)+'MB</div>'+
                                            '</div>'+
                                            '<div class="actions" style="width: 1.032rem;">'+
                                            '<a class="btn btn-link btn-preview-file" target="_blank" href="/fileStorage/preview?fileId='+fileList[ii].id+'">'+
                                            '<em style="display:none">预览</em>'+
                                            '<i class="operateIconfont operateIcon-yulan"></i>'+
                                            '</a>'+
                                            // '<a class="btn btn-link btn-download-file" style="float:right" href="/fileStorage/downloadFile?fileId='+fileList[ii].id+'">'+
                                            // '<em style="display:none">下载</em>'+
                                            // '<i class="operateIconfont operateIcon-xiazai"></i>'+
                                            // '</a>'+
                                            '</div></div>';
                                    }
                                    terminationContractApprovalViewBox.find(".terminationContractApprovalView-settlementUpstreamSignedFile").append(filesHtm);
                                }
                            }

                            if( contractHistoryData[i].obj.amountKind ) {
                                setTimeout(() => {
                                    $('.settlementFile').remove()
                                }, 300);
                            }

                             // 上游结算单：
                             if( contractHistoryData[i].obj.settlementFile ){
                                var fileList=contractHistoryData[i].obj.settlementFile;
                                var filesHtm='';
                                if( fileList.length>0 ){
                                    //contractMakingViewBox.find(".uploadFile").removeClass("hide");
                                    for(var ii=0;ii<fileList.length;ii++){
                                        filesHtm+='<div class="uploaderFile oldFile">'+
                                            '<input type="hidden" class="fileid" value="'+fileList[ii].id+'">'+
                                            '<div class="fileContent"><div class="file-wrapper">';
                                        var fileType=fileList[ii].fileType;
                                        if(fileType=='.jpg' || fileType=='.jpeg' || fileType=='.png' || fileType=='.bmp'){
                                            filesHtm+='<div class="file-icon" style="color: rgb(119, 31, 173);"><div  class="file-icon-image"'+
                                                'style="background-image:url('+ fileList[ii].path +');"></div></div>';
                                        }else {
                                            filesHtm+='<div class="file-icon" style="color:#5AC4FC;"><div class="file-icon-image"><i class="icon icon-file-pdf"></i></div></div>';
                                        }
                                        filesHtm+='<div class="content">'+
                                            '<div class="file-name">'+fileList[ii].originalName+'</div>'+
                                            '<div class="file-size small text-muted">'+(fileList[ii].size/1024/1024).toFixed(2)+'MB</div>'+
                                            '</div>'+
                                            '<div class="actions" style="width: 1.032rem;">'+
                                            '<a class="btn btn-link btn-preview-file" target="_blank" href="/fileStorage/preview?fileId='+fileList[ii].id+'">'+
                                            '<em style="display:none">预览</em>'+
                                            '<i class="operateIconfont operateIcon-yulan"></i>'+
                                            '</a>'+
                                            // '<a class="btn btn-link btn-download-file" style="float:right" href="/fileStorage/downloadFile?fileId='+fileList[ii].id+'">'+
                                            // '<em style="display:none">下载</em>'+
                                            // '<i class="operateIconfont operateIcon-xiazai"></i>'+
                                            // '</a>'+
                                            '</div></div>';
                                    }
                                    terminationContractApprovalViewBox.find(".terminationContractApprovalView-settlementFile").append(filesHtm);
                                }
                            }

                             // 销售发票
                             if( contractHistoryData[i].obj.pendingInvoice ){
                                var fileList=contractHistoryData[i].obj.pendingInvoice;
                                var filesHtm='';
                                if( fileList.length>0 ){
                                    //contractMakingViewBox.find(".uploadFile").removeClass("hide");
                                    for(var ii=0;ii<fileList.length;ii++){
                                        filesHtm+='<div class="uploaderFile oldFile">'+
                                            '<input type="hidden" class="fileid" value="'+fileList[ii].id+'">'+
                                            '<div class="fileContent"><div class="file-wrapper">';
                                        var fileType=fileList[ii].fileType;
                                        if(fileType=='.jpg' || fileType=='.jpeg' || fileType=='.png' || fileType=='.bmp'){
                                            filesHtm+='<div class="file-icon" style="color: rgb(119, 31, 173);"><div  class="file-icon-image"'+
                                                'style="background-image:url('+ fileList[ii].path +');"></div></div>';
                                        }else {
                                            filesHtm+='<div class="file-icon" style="color:#5AC4FC;"><div class="file-icon-image"><i class="icon icon-file-pdf"></i></div></div>';
                                        }
                                        filesHtm+='<div class="content">'+
                                            '<div class="file-name">'+fileList[ii].originalName+'</div>'+
                                            '<div class="file-size small text-muted">'+(fileList[ii].size/1024/1024).toFixed(2)+'MB</div>'+
                                            '</div>'+
                                            '<div class="actions" style="width: 1.032rem;">'+

                                            '<a class="btn btn-link btn-download-file" style="float:right" href="/fileStorage/downloadFile?fileId='+fileList[ii].id+'">'+
                                            '<em style="display:none">下载</em>'+
                                            '<i class="operateIconfont operateIcon-xiazai"></i>'+
                                            '</a>'+
                                            '</div></div>';
                                    }
                                    terminationContractApprovalViewBox.find(".terminationContractApprovalView-pendingInvoice").append(filesHtm);
                                }
                            }

                            if(contractHistoryData[i].formBusinessName == '财务审核') {
                                terminationContractApprovalViewBox.find(".detailContentBox-title-small").text('财务审核')
                            }else if(contractHistoryData[i].formBusinessName == '财务审核变更'){
                                terminationContractApprovalViewBox.find(".detailContentBox-title-small").text('财务审核变更')
                            }

                            //审批结论
                            terminationContractApprovalViewBox.find(".terminationContractApprovalView-approvalConclusion").text(contractHistoryData[i].obj.approvalConclusion === 'back' ? '驳回' : '通过');

                            //审批意见
                            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();
            }
        });

    });


})
