$(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})
    });

    // 加载查看历史信息dom元素
    $(".projectManagementTop .newTabAddUpdateBox").load('/salesContract/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':'SalesContract'
            },
            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 == '销售合同录入' || 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)

                            if(contractHistoryData[i].formBusinessName == '销售合同录入') {
                                contractMakingViewBox.find(".detailContentBox-title-small").text('销售合同录入')
                            }else {
                                contractMakingViewBox.find(".detailContentBox-title-small").text('业务变更合同')
                            }

                            contractMakingViewBox.find('.contractMakingView-businessName').text(contractHistoryData[i].obj.businessBasicInfo.name);
                            contractMakingViewBox.find('.contractMakingView-enterpriseName').text(contractHistoryData[i].obj.businessBasicInfo.customer.enterpriseName);
                            contractMakingViewBox.find('.contractMakingView-businessNo').text(contractHistoryData[i].obj.businessBasicInfo.businessNumber);
                            contractMakingViewBox.find('.contractMakingView-creatTime').text(contractHistoryData[i].obj.businessBasicInfo.gmtCreate);

                            if( contractHistoryData[i].obj.salesContractFileList ){
                                var fileList=contractHistoryData[i].obj.salesContractFileList;
                                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-uploadFile").append(filesHtm);
                                }
                            }

                            //合同信息
                            contractMakingViewBox.find('.contractMakingView-contractNumber').text(contractHistoryData[i].obj.salesContractBasicInfo.contractNumber);
                            contractMakingViewBox.find('.contractMakingView-contractName').text(contractHistoryData[i].obj.salesContractBasicInfo.contractName);
                            contractMakingViewBox.find('.contractMakingView-platform').text(contractHistoryData[i].obj.businessBasicInfo.platform.platformName);
                            contractMakingViewBox.find('.contractMakingView-customer').text(contractHistoryData[i].obj.businessBasicInfo.customer.enterpriseName);
                            contractMakingViewBox.find('.contractMakingView-contractPeriod').text(contractHistoryData[i].obj.salesContractBasicInfo.contractPeriod);
                            contractMakingViewBox.find('.contractMakingView-contractPlanAmountType').text(contractHistoryData[i].obj.salesContractBasicInfo.contractPlanAmountTypeDict.name);
                            contractMakingViewBox.find('.contractMakingView-contractPlanAmount').text(commaDelimiter(contractHistoryData[i].obj.salesContractBasicInfo.contractPlanAmount + '元'));
                            contractMakingViewBox.find('.contractMakingView-checkOperator').text(contractHistoryData[i].obj.salesContractBasicInfo.checkOperator);
                            contractMakingViewBox.find('.contractMakingView-settlementOperator').text(contractHistoryData[i].obj.salesContractBasicInfo.settlementOperator);

                            //人员信息
                            var personalConditionList = contractHistoryData[i].obj.salesContractPersonInfoHistories;
                            if( personalConditionList ){
                                var trs='';
                                for(var ii=0;ii<personalConditionList.length;ii++ ){
                                    let socialCreditCode = '';
                                    let mobile = '';
                                    if(personalConditionList[ii].socialCreditCode == null) {
                                        socialCreditCode = ''
                                    }else {
                                        socialCreditCode = personalConditionList[ii].socialCreditCode
                                    }
                                    if(personalConditionList[ii].mobile == null) {
                                        mobile = ''
                                    }else {
                                        mobile = personalConditionList[ii].mobile
                                    }
                                    
                                    trs+= 
                                        '<tr>'+
                                            '<td width="20%" class="enter">'+personalConditionList[ii].type+'</td>'+
                                            '<td width="20%" class="enter">'+personalConditionList[ii].name+'</td>'+
                                            // '<td width="20%" class="enter">'+personalConditionList[ii].cardType+'</td>'+
                                            // '<td width="20%" class="enter">'+socialCreditCode+'</td>'+
                                            '<td width="20%" class="enter">'+mobile+'</td>'+
                                        '</tr>';
                                    
                                }
                                contractMakingViewBox.find(".personalConditionList_header").after(trs);
                            }
                            //付款条件
                            var paymentConditionList=contractHistoryData[i].obj.paymentConditionList;
                            if( paymentConditionList ){
                                var trs='';
                                for(var ii=0;ii<paymentConditionList.length;ii++ ){
                                    var num=ii+1;
                                    trs+='<tr>'+
                                        '<td width="15%" class="enter">'+num+'</td>'+
                                        '<td width="85%" class="enter">'+paymentConditionList[ii].paymentCondition+'</td>'+
                                        '</tr>';
                                }
                                contractMakingViewBox.find(".paymentConditionList_header").after(trs);
                            }

                            //结算
                            contractMakingViewBox.find('.contractMakingView-deliveryDate').text(contractHistoryData[i].obj.salesContractSettleInfo.deliveryDate);
                            contractMakingViewBox.find('.contractMakingView-signDate').text(contractHistoryData[i].obj.salesContractSettleInfo.signDate);
                            contractMakingViewBox.find('.contractMakingView-firstSettleDate').text(contractHistoryData[i].obj.salesContractSettleInfo.firstSettleDate);
                            contractMakingViewBox.find('.contractMakingView-settleCycleMethodDict').text(contractHistoryData[i].obj.salesContractSettleInfo.settleCycleMethodDict.name);
                            if(contractHistoryData[i].obj.salesContractSettleInfo.settleCycleMethodDict.name == '自然月') {
                                contractMakingViewBox.find('.contractMakingView-settleCycle').text('上一次结算后' + contractHistoryData[i].obj.salesContractSettleInfo.settleCycle + '个自然月');
                            }else {
                                contractMakingViewBox.find('.contractMakingView-settleCycle').text('上一次结算后' + contractHistoryData[i].obj.salesContractSettleInfo.settleCycle + '天');
                            }

                            contractMakingViewBox.find('.contractMakingView-receivableTypeDic').text(contractHistoryData[i].obj.salesContractSettleInfo.receivableTypeDic.name);
                            if(contractHistoryData[i].obj.salesContractSettleInfo.receivableTypeDic.code === 'goodsCharge') {
                                contractMakingViewBox.find('.contractMakingView-planPaybackDays').text('结算后'+ contractHistoryData[i].obj.salesContractSettleInfo.planPaybackDays + '天');
                                contractMakingViewBox.find('.contractMakingView-estimatePayBackDays').text('结算后'+ contractHistoryData[i].obj.salesContractSettleInfo.estimatePaybackDays + '天');
                            }else {
                                contractMakingViewBox.find('.receivableTypeDicChange').hide()
                            }


                            //质保金
                            contractMakingViewBox.find('.contractMakingView-retention').text((contractHistoryData[i].obj.salesContractRetentionInfo.retention?'是':'否'));
                            if(contractHistoryData[i].obj.salesContractRetentionInfo.retention) {
                                contractMakingViewBox.find('.contractMakingView-retentionPercent').text((contractHistoryData[i].obj.salesContractRetentionInfo.retentionPercent?contractHistoryData[i].obj.salesContractRetentionInfo.retentionPercent+'%':''));
                                contractMakingViewBox.find('.contractMakingView-limit').text((contractHistoryData[i].obj.salesContractRetentionInfo.limit?'是':'否'));

                                if(!contractHistoryData[i].obj.salesContractRetentionInfo.limit) {
                                    setTimeout(() => {
                                        contractMakingViewBox.find('.contractMakingView-limit').attr('colspan', '3')
                                        contractMakingViewBox.find('.contractMakingView-limit').attr('width', '0')
                                        contractMakingViewBox.find('.hideRetentionLimit').remove()
                                    }, 300);

                                }
                                contractMakingViewBox.find('.contractMakingView-retentionLimit').text((contractHistoryData[i].obj.salesContractRetentionInfo.retentionLimit?(commaDelimiter(contractHistoryData[i].obj.salesContractRetentionInfo.retentionLimit)+'元'):''));
                                contractMakingViewBox.find('.contractMakingView-releaseMethodDict').text(contractHistoryData[i].obj.salesContractRetentionInfo.releaseMethodDict.name);
                                if(contractHistoryData[i].obj.salesContractRetentionInfo.releaseMethodDict.name == '固定日期') {
                                    contractMakingViewBox.find('.contractMakingView-releaseMethodDict').removeAttr('colspan').css('width','35%')
                                    contractMakingViewBox.find('.contractMakingView-releaseDays').hide();
                                    contractMakingViewBox.find('.releaseDays').hide();
                                    contractMakingViewBox.find('.contractMakingView-releaseDate').show();
                                    contractMakingViewBox.find('.releaseDate').show();
                                    contractMakingViewBox.find('.contractMakingView-releaseDate').text(contractHistoryData[i].obj.salesContractRetentionInfo.releaseDate);
                                }else if(contractHistoryData[i].obj.salesContractRetentionInfo.releaseMethodDict.name == '回款后固定天数'){
                                    contractMakingViewBox.find('.contractMakingView-releaseMethodDict').removeAttr('colspan').css('width','35%')
                                    contractMakingViewBox.find('.contractMakingView-releaseDays').show();
                                    contractMakingViewBox.find('.releaseDays').show();
                                    contractMakingViewBox.find('.contractMakingView-releaseDate').hide();
                                    contractMakingViewBox.find('.releaseDate').hide();
                                    contractMakingViewBox.find('.contractMakingView-releaseDays').text(contractHistoryData[i].obj.salesContractRetentionInfo.releaseDays + '天');
                                }else {
                                    contractMakingViewBox.find('.contractMakingView-releaseMethodDict').css('width','0').attr('colspan','3')
                                    contractMakingViewBox.find('.contractMakingView-releaseDays').hide();
                                    contractMakingViewBox.find('.releaseDays').hide();
                                    contractMakingViewBox.find('.contractMakingView-releaseDate').hide();
                                    contractMakingViewBox.find('.releaseDate').hide();
                                }
                            }else {
                                contractMakingViewBox.find(".retentionTr").hide();
                                contractMakingViewBox.find(".contractMakingView-retention").css('width',0).attr('colspan',3)
                            }



                            //货物信息
                            var goodsInfoList=contractHistoryData[i].obj.goodsInfoList;
                            if( goodsInfoList ){
                                var trs='';
                                for(var ii=0;ii<goodsInfoList.length;ii++ ){
                                    var num=ii+1;
                                    trs+='<tr>'+
                                        '<td width="8%" class="enter">'+num+'</td>'+
                                        '<td width="12%" class="enter">'+goodsInfoList[ii].goodsName+'</td>'+
                                        '<td width="12%" class="enter">'+goodsInfoList[ii].goodsFactory+'</td>'+
                                        '<td width="11%" class="enter">'+goodsInfoList[ii].modelNumber+'</td>'+
                                        '<td width="11%" class="enter">'+goodsInfoList[ii].units+'</td>'+
                                        '<td width="10%" class="enter">'+goodsInfoList[ii].quantity+'</td>'+
                                        '<td width="12%" class="enter">'+(goodsInfoList[ii].clearPrice?'是':'否')+'</td>'+
                                        '<td width="10%" class="enter">'+(goodsInfoList[ii].salesPrice?goodsInfoList[ii].salesPrice:'')+'</td>'+
                                        '<td width="14%" class="enter">'+goodsInfoList[ii].remark+'</td>'+
                                        '</tr>';
                                }
                                ii=null;
                                contractMakingViewBox.find(".goodsInfoList_header").after(trs);
                            }

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

                        };

                        //法务审核条款
                        if( contractHistoryData[i].formBusinessName == '销售合同审核' || contractHistoryData[i].formBusinessName == '法务审核条款' || 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].formBusinessName == '销售合同审核') {
                                terminationContractApprovalViewBox.find(".detailContentBox-title-small").text('销售合同审核')
                            }else if(contractHistoryData[i].formBusinessName == '变更合同审核') {
                                terminationContractApprovalViewBox.find(".detailContentBox-title-small").text('变更合同审核')
                            }else {
                                terminationContractApprovalViewBox.find(".detailContentBox-title-small").text('法务审核条款')
                            }

                            if( contractHistoryData[i].obj.fileList ){
                                var fileList=contractHistoryData[i].obj.fileList;
                                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(".terminationContractApprovalViewBox-uploadFile").append(filesHtm);
                                }
                            }
                            if(contractHistoryData[i].formBusinessName == '变更合同审核') {
                                //审批结论
                                terminationContractApprovalViewBox.find(".terminationContractApprovalView-approvalConclusion").text(contractHistoryData[i].obj.approvalConclusion);
                                //审批意见
                                if( contractHistoryData[i].obj.approvalComment ){
                                    terminationContractApprovalViewBox.find(".terminationContractApprovalView-approvalOpinion").text(contractHistoryData[i].obj.approvalComment);
                                }
                                //签署确认
                                if(contractHistoryData[i].obj.approvalConclusion == '通过') {
                                    terminationContractApprovalViewBox.find(".signConfirmationHistory").show()
                                    terminationContractApprovalViewBox.find(".terminationContractApprovalView-signConfirmation").text(contractHistoryData[i].obj.signConfirm == 1 ? '是' : '否');
                                }
                                if(contractHistoryData[i].obj.signConfirm == 1) {
                                    terminationContractApprovalViewBox.find(".signingInformationHistory").show()
                                    //签署文件
                                    let fileStorages = ''
                                    contractHistoryData[i].obj.files.forEach(item => {
                                        fileStorages += `<div class="fileStorage" style="display:none">
                                            <input type="text" class="originalId"   value="${item.id}">
                                            <input type="text" class="originalUrl"  value="${item.path}">
                                            <input type="text" class="originalType" value="${item.fileType}">
                                            <input type="text" class="originalName" value="${item.originalName}">
                                            <input type="text" class="originalSize" value="${item.size}">
                                        </div>`
                                    })
                                    showOriginalFile(fileStorages, terminationContractApprovalViewBox.find('.originalFileListHistory').find('.fileListBox'), 'onlyView')
                                    //签署人信息
                                    var signPersonalConditionList = [contractHistoryData[i].obj.salesContractSupplementApprovalPersonInfoHistoryRef];
                                    if( signPersonalConditionList ){
                                        var str='';
                                        for(var ii=0;ii<signPersonalConditionList.length;ii++ ){
                                            str += 
                                                '<tr>'+
                                                    '<td width="20%" class="enter">'+signPersonalConditionList[ii].type+'</td>'+
                                                    '<td width="20%" class="enter">'+signPersonalConditionList[ii].name+'</td>'+
                                                    // '<td width="20%" class="enter">'+signPersonalConditionList[ii].cardType+'</td>'+
                                                    // '<td width="20%" class="enter">'+signPersonalConditionList[ii].socialCreditCode+'</td>'+
                                                    '<td width="20%" class="enter">'+signPersonalConditionList[ii].mobile+'</td>'+
                                                '</tr>';
                                            
                                        }
                                        terminationContractApprovalViewBox.find(".signTable").find(".signerContent").append(str);
                                    }

                                }
                            }else {
                                //审批结论
                                terminationContractApprovalViewBox.find(".terminationContractApprovalView-approvalConclusion").text(contractHistoryData[i].obj.salesContractApproval.approvalConclusion);
                                //审批意见
                                if( contractHistoryData[i].obj.salesContractApproval.approvalComment ){
                                    terminationContractApprovalViewBox.find(".terminationContractApprovalView-approvalOpinion").text(contractHistoryData[i].obj.salesContractApproval.approvalComment);
                                }
                                //签署确认
                                if(contractHistoryData[i].obj.salesContractApproval.approvalConclusion == '通过') {
                                    terminationContractApprovalViewBox.find(".signConfirmationHistory").show()
                                    terminationContractApprovalViewBox.find(".terminationContractApprovalView-signConfirmation").text(contractHistoryData[i].obj.salesContractApproval.signConfirm == 1 ? '是' : '否');
                                }
                                if(contractHistoryData[i].obj.salesContractApproval.signConfirm == 1) {
                                    terminationContractApprovalViewBox.find(".signingInformationHistory").show()
                                    //签署文件
                                    let fileStorages = ''
                                    contractHistoryData[i].obj.fileList.forEach(item => {
                                        fileStorages += `<div class="fileStorage" style="display:none">
                                            <input type="text" class="originalId"   value="${item.id}">
                                            <input type="text" class="originalUrl"  value="${item.path}">
                                            <input type="text" class="originalType" value="${item.fileType}">
                                            <input type="text" class="originalName" value="${item.originalName}">
                                            <input type="text" class="originalSize" value="${item.size}">
                                        </div>`
                                    })
                                    showOriginalFile(fileStorages, terminationContractApprovalViewBox.find('.originalFileListHistory').find('.fileListBox'), 'onlyView')
                                    //签署人信息
                                    var signPersonalConditionList = [contractHistoryData[i].obj.salesContractApprovalPersonInfoHistoryRef];
                                    if( signPersonalConditionList ){
                                        var str='';
                                        for(var ii=0;ii<signPersonalConditionList.length;ii++ ){
                                            str += 
                                                '<tr>'+
                                                    '<td width="20%" class="enter">'+signPersonalConditionList[ii].type+'</td>'+
                                                    '<td width="20%" class="enter">'+signPersonalConditionList[ii].name+'</td>'+
                                                    // '<td width="20%" class="enter">'+signPersonalConditionList[ii].cardType+'</td>'+
                                                    // '<td width="20%" class="enter">'+signPersonalConditionList[ii].socialCreditCode+'</td>'+
                                                    '<td width="20%" class="enter">'+signPersonalConditionList[ii].mobile+'</td>'+
                                                '</tr>';
                                            
                                        }
                                        terminationContractApprovalViewBox.find(".signTable").find(".signerContent").append(str);
                                    }

                                }
                            }


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

                        //签署确认
                        if( contractHistoryData[i].formBusinessName == '销售合同签署' || 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>';
                                }
                                //$('.signConfirmationViewBox-log').append(logText)
                            }

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

                            if(contractHistoryData[i].formBusinessName == '销售合同签署') {
                                signConfirmationViewBox.find(".detailContentBox-title-small").text('销售合同签署')
                            }else {
                                signConfirmationViewBox.find(".detailContentBox-title-small").text('销售合同变更签署')
                            }

                            //签署结论
                            signConfirmationViewBox.find('.signConfirmationView-businessNo').text(contractHistoryData[i].obj.salesContractSignConfirm.conclusion);

                            //附件页面初始化
                            if( contractHistoryData[i].obj.fileList ){
                                var fileList=contractHistoryData[i].obj.fileList;
                                var filesHtm='';
                                if( fileList.length>0 ){
                                    signConfirmationViewBox.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>';
                                    }
                                    signConfirmationViewBox.find(".signConfirmationView-uploadFile").append(filesHtm);
                                }
                            }
                            //否决原因  /  图片/视频
                            if( signConfirmationViewBox.find('.signConfirmationView-businessNo').text()=="否决" ){
                                signConfirmationViewBox.find('.signConfirmationView-vetoReason').removeClass("hide").text(contractHistoryData[i].obj.salesContractSignConfirm.vetoReason);
                                signConfirmationViewBox.find(".conclusionCause").removeClass("hide");
                            }else{

                            }

                            //备注
                            if( contractHistoryData[i].obj.salesContractSignConfirm.remark ){
                                signConfirmationViewBox.find('.signConfirmationView-remark').text(contractHistoryData[i].obj.salesContractSignConfirm.remark);
                            }

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

                            $('body').on('mouseenter',".operateIconfont",function(e){
                                $(this).prev().removeClass("hide");
                            });
                            $('body').on('mouseleave',".operateIconfont",function(e){
                                $(this).prev().addClass("hide");
                            });
                        }

                        //法务终审
                        if( contractHistoryData[i].formBusinessName == '销售合同终审' || 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>';
                                }
                                //$('.legalFinalAdjudicationViewBox-log').append(logText)
                            }

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

                            if(contractHistoryData[i].formBusinessName == '销售合同终审') {
                                legalFinalAdjudicationViewBox.find(".detailContentBox-title-small").text('销售合同终审')
                            }else {
                                legalFinalAdjudicationViewBox.find(".detailContentBox-title-small").text('销售合同变更终审')
                            }

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

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

                            $(".showarea").append(legalFinalAdjudicationViewBox.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>';
                                 }
                                 //$('.legalFinalAdjudicationViewBox-log').append(logText)
                            }
                            var terminationContractApprovalViewBox = $(".historyHideArea .contrractChangeViewBox").clone();
                            terminationContractApprovalViewBox.find('.contrractChangeViewBox-log').append(logText)

                            // 补充合同编号
                            terminationContractApprovalViewBox.find(".contrractChangeViewBox-supplementContractNumber").text(contractHistoryData[i].obj.salesContractSupplementInfo.supplementContractNumber);

                            terminationContractApprovalViewBox.find(".contrractChangeViewBox-approval").text(contractHistoryData[i].obj.salesContractSupplementInfo.approval == 1 ? '是': '否');

                            terminationContractApprovalViewBox.find(".contrractChangeViewBox-addGoods").text(contractHistoryData[i].obj.salesContractSupplementInfo.addGoods == 1 ? '是': '否');
                            if(contractHistoryData[i].obj.salesContractSupplementInfo.approval != 1) {
                                terminationContractApprovalViewBox.find(".contrractChangeViewBox-approvalChange").hide()
                            }

                            terminationContractApprovalViewBox.find(".contrractChangeViewBox-remark").text(contractHistoryData[i].obj.salesContractSupplementInfo.remark);

                            // 补充合同文件
                            if( contractHistoryData[i].obj.fileList ){
                                var fileList=contractHistoryData[i].obj.fileList;
                                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(".contrractChangeViewBox-uploadFile").append(filesHtm);
                                }
                            }

                            //货物信息
                            var goodsInfoList=contractHistoryData[i].obj.goodsInfoList;
                            if( goodsInfoList ){
                                var trs='';
                                for(var ii=0;ii<goodsInfoList.length;ii++ ){
                                    var num=ii+1;
                                    trs+='<tr>'+
                                        '<td width="8%" class="enter">'+num+'</td>'+
                                        '<td width="12%" class="enter">'+goodsInfoList[ii].goodsName+'</td>'+
                                        '<td width="12%" class="enter">'+goodsInfoList[ii].goodsFactory+'</td>'+
                                        '<td width="11%" class="enter">'+goodsInfoList[ii].modelNumber+'</td>'+
                                        '<td width="11%" class="enter">'+goodsInfoList[ii].units+'</td>'+
                                        '<td width="10%" class="enter">'+goodsInfoList[ii].quantity+'</td>'+
                                        '<td width="12%" class="enter">'+(goodsInfoList[ii].clearPrice?'是':'否')+'</td>'+
                                        '<td width="10%" class="enter">'+(goodsInfoList[ii].salesPrice?goodsInfoList[ii].salesPrice:'')+'</td>'+
                                        '<td width="14%" class="enter">'+goodsInfoList[ii].remark+'</td>'+
                                        '</tr>';
                                }
                                ii=null;
                                terminationContractApprovalViewBox.find(".goodsInfoList_header").after(trs);
                            }
                            if(contractHistoryData[i].obj.salesContractSupplementInfo.addGoods == 1) {
                                terminationContractApprovalViewBox.find(".contrractChangeViewBox-addGoodsChange").show()
                            }

                            $(".showarea").append(terminationContractApprovalViewBox.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>';
                                }
                                //$('.legalFinalAdjudicationViewBox-log').append(logText)
                           }
                           var refundBondViewBox = $(".historyHideArea .refundBondViewBox").clone();
                           refundBondViewBox.find('.refundBondViewBox-log').append(logText)

                           // 补充合同编号
                           refundBondViewBox.find(".refundBondViewBox-returnType").text(contractHistoryData[i].obj.returnType == 1 ? '退还' : '其他');


                           refundBondViewBox.find(".refundBondViewBox-remark").text(contractHistoryData[i].obj.remark);

                           // 补充合同文件
                           if( contractHistoryData[i].obj.voucherFiles ){
                               var fileList=contractHistoryData[i].obj.voucherFiles;
                               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>';
                                   }
                                   refundBondViewBox.find(".refundBondViewBox-voucherFiles").append(filesHtm);
                               }
                           }

                            if(contractHistoryData[i].obj.returnType == 1) {
                                refundBondViewBox.find(".refundBondViewBox-voucherFilesChange").show()
                            }

                           $(".showarea").append(refundBondViewBox.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();
            }
        });

    });


})
