// 贸理通V3.1合同逻辑 - 开始
// 审批结论发生改变
$('[name=approvalConclusion]').change(function () {
    if($('[name=approvalConclusion]:checked').val() == 'pass') {
        $('.validBox').show()
        $('.approvalConclusionTd').attr('colspan', 0)
        $('.approvalConclusionTd').attr('width', '35%')
        $('[name=purchContractApprovalUpload]').change()
        $('[name=signMode]').change()
        $('.approvalCommentTitle').removeClass('required_fileds_star')
    }else {
        $('.validBox').hide()
        $('.signModeChange').hide()
        $('.contractTable').hide()
        $('.approvalConclusionTd').attr('colspan', 3)
        $('.approvalConclusionTd').attr('width', '85%')
        $('.createProcurementContract').hide()
        $('.approvalCommentTitle').addClass('required_fileds_star')
    }
})

// 合同签署方式发生改变
$('[name=signMode]').change(function () {
    if($('[name=signMode]:checked').val() == '1') {
        $('.signModeChange').show()
        // $('.createProcurementContract').show()
        $('[name=purchContractApprovalUpload]').change()

        $('.createProcurementContract').click()
    }else {
        $('.signModeChange').hide()
        $('.contractTable').hide()
        $('.createProcurementContract').hide()
    }

})

// 上传合同文件发生改变
$('[name=purchContractApprovalUpload]').change(function () {
    if($('[name=purchContractApprovalUpload]:checked').val() == '1') {
        $('.contractTable').show()
    }else {
        $('.contractTable').hide()
    }
})



// 排序
function sortReceiptInfo(){
    $(".contractListTbody").each(function(i,ele){
          if($('.contractListTable').find('tr').eq(0).css('display') === 'table-row') {
              $(ele).find('td:first span').text(i+1);
          }else {
              $(ele).find('td:first span').text(i);
          }
    });
    if($('.contractListTable').find('tr').eq(0).css('display') === 'table-row') {
        if($(".contractListTbody").length <= 1){
            $('.contractTable .negativeInformationReduce').hide();
        }else{
            $('.contractTable .negativeInformationReduce').show();
        };
    }else {
        if($(".contractListTbody").not(':first').length <= 1){
            $('.contractTable .negativeInformationReduce').hide();
        }else{
            $('.contractTable .negativeInformationReduce').show();
        };
    }
};

// 添加行
$(".contractTable").on('click','.negativeInformationPlus',function(){
    var supplierTrClone = $(".contractListTbody:first").clone();
    supplierTrClone.find('.negativeInformationReduce').show();
    supplierTrClone.find('.contractName').val('')
    supplierTrClone.find('.error').hide();
    supplierTrClone.find('[name=contractType]').val('true')
    setTimeout(() => {
        supplierTrClone.find('.btn-delete-file').click()
        supplierTrClone.find('.btn-delete-originalfile').click()
        supplierTrClone.data('deletefileid',[])
    }, 100);
    supplierTrClone.show()
    $(this).parents('.contractListTbody').after(supplierTrClone);
    sortReceiptInfo()
    initDepositListData('.fileListBox', supplierTrClone)
  });


// 删除行
$(".contractTable").on('click','.negativeInformationReduce',function(){
	$(this).parents('.contractListTbody').remove();
	sortReceiptInfo();
});



let submitStatus = ''
function initSignType() {
    if(submitStatus === 'create') {
        $('[name=signMode]').get(1).checked = true
        $('[name=signMode]').change()
    }

}

//  贸理通V3.1合同逻辑 - 结束
$(function () {

    // 贸理通3.1需求 - 开始
    if(!$('[name=approvalConclusion]:checked').val()) {
        $('[name=approvalConclusion]').get(0).checked = true
    }
    if(!$('[name=purchContractApprovalUpload]:checked').val()) {
        $('[name=purchContractApprovalUpload]').get(1).checked = true
    }
    $('[name=approvalConclusion]').change()
    if($('.procurementContractFileStorage')) {
        showOriginalFile($('.procurementContractFileStorage'),  $('.procurementContract').find('.fileListBox'), 'onlyView')
    }

    $('.contractListTbody').each(function (i, ele) {
        $(ele).find('.fileStorage').each(function (j, item) {
			$(ele).find('.choiceFile').hide()
			showOriginalFile(item, $(ele).find('.fileListBox'), 'onlyDelete')
		})
    })
    if( $(".contractListTbody").length > 1 ){
        $('.contractListTable').find('tr').eq(0).addClass('hide')
    }
    sortReceiptInfo()
    uploadFileMethod({
        mainDom: '#contractReview-form',
        delegateDom: '.choiceFile',
        insideDelegateDom: '.fileContent',
        delegateDomInput: '.contractTable .contractListTbody .fileinput',
        depositDataDom: '.fileListBox',
        delegateLabel: '.fileListBox',
        displayListDom: '.uploaderFile',
        isCustomUploadBtn: false,
    })

    if( $('[name=useContract]').attr('useContractStatus') == '1') {
        $('[name=useContract]').prop('checked', true)
    } else {
        $('[name=useContract]').prop('checked', false)
    }


    // 贸理通3.1需求 - 结束
    function setDate(select,startDate,endDate){
        $(select).datetimepicker(
            {
                weekStart: 1,
                autoclose: 1,
                todayHighlight: 0,
                startView: 2,
                minView: 2,
                forceParse: 0,
                showMeridian: 1,
                startDate:startDate,
                endDate:endDate,
                format: "yyyy-mm-dd"
            }
        );
        $(select).datetimepicker('setStartDate',startDate);
        $(select).datetimepicker('setEndDate',endDate);
    };
    // setDate('[name=deliverDate]','1970-01-01','2116-12-31');

    // 排序-xufang
    function sortXfInfo() {
        $(".xufangListTbody").each(function (i, ele) {
            $(ele).find('td:first span').text(i);
        });
        if ($(".xufangListTbody").length <= 1) {
            $('.xufangTable .negativeInformationReduce').hide();
        } else {
            $('.xufangTable .negativeInformationReduce').show();
        }
        ;
    };
    sortXfInfo();
    $("#contractReview-form").on('click', '.xufangTable #addXufang', function () {
        var supplierTrClone = $(".xufangListTbody:first").clone();
        supplierTrClone.find('.negativeInformationReduce').show();
        supplierTrClone.find('.error').hide();
        supplierTrClone.find('input').val('');
        supplierTrClone.find('select').val('');
        supplierTrClone.show();
        $('.xufangListTable').append(supplierTrClone);
        sortXfInfo();
    });
    // 删除行
    $("#contractReview-form").on('click', '.xufangTable .negativeInformationReduce', function () {
        $(this).parents('.xufangListTbody').remove();
        sortXfInfo();
    });


    // 排序-供应商
    function sortGyInfo() {
        $(".supplierListTbody").each(function (i, ele) {
            $(ele).find('td:first span').text(i);
        });
        if ($(".supplierListTbody").length <= 1) {
            $('.supplierTable .negativeInformationReduce').hide();
        } else {
            $('.supplierTable .negativeInformationReduce').show();
        }
        ;
    };
    sortGyInfo();
    $("#contractReview-form").on('click', '.supplierTable #addSupplier', function () {
        var supplierTrClone2 = $(".supplierListTbody:first").clone();
        supplierTrClone2.find('.negativeInformationReduce').show();
        supplierTrClone2.find('.error').hide();
        supplierTrClone2.find('input').val('');
        supplierTrClone2.find('select').val('');
        supplierTrClone2.show();
        $('.supplierListTable').append(supplierTrClone2);
        sortGyInfo();
    });
    // 删除行
    $("#contractReview-form").on('click', '.supplierTable .negativeInformationReduce', function () {
        $(this).parents('.supplierListTbody').remove();
        sortGyInfo();
    });

    // 排序-其他
    function sortOtInfo() {
        $(".otherListTbody").each(function (i, ele) {
            $(ele).find('td:first span').text(i);
        });
        if ($(".otherListTbody").length <= 1) {
            $('.otherTable .negativeInformationReduce').hide();
        } else {
            $('.otherTable .negativeInformationReduce').show();
        }
        ;
    };
    sortOtInfo();
    $("#contractReview-form").on('click', '.otherTable #addOther', function () {
        var supplierTrClone3 = $(".otherListTbody:first").clone();
        supplierTrClone3.find('.negativeInformationReduce').show();
        supplierTrClone3.find('.error').hide();
        supplierTrClone3.find('input').val('');
        supplierTrClone3.find('select').val('');
        supplierTrClone3.show();
        $('.otherListTable').append(supplierTrClone3);
        sortOtInfo();
    });
    // 删除行
    $("#contractReview-form").on('click', '.otherTable .negativeInformationReduce', function () {
        $(this).parents('.otherListTbody').remove();
        sortOtInfo();
    });

    //提交
    function submitFunction(e) {
        if(submitStatus === 'create') {
            // $(".createProcurementContract").addClass("loadingCircle");
        }else if(submitStatus === 'temp') {
            // $(".newTabAddUpdateBtnBox .temp").addClass("loadingCircle");
        }else {
            // $(".newTabAddUpdateBtnBox .save, .newTabAddUpdateBtnBox .btn-cancel").addClass("loadingCircle");
        }
        var postdata = new FormData();
        let tipword = "提交"
        postdata.append('taskId', $('[name=taskId]').val())
        postdata.append('businessKey', $('[name=businessKey]').val())

        if ($('[name=approvalConclusion]:checked').val() == 'pass') {

            postdata.append('purchContractReplenishInfo.projectAmountCategory', $("[name=projectAmountCategory]").val());
            postdata.append('purchContractReplenishInfo.goodsPriceSettleMethod', $("[name=goodsPriceSettleMethod]").val());

            // postdata.append('purchContractVatInfo.priceComment', $("[name=priceComment]").val());
            // postdata.append('purchContractVatInfo.taxRate', $("[name=taxRate]").val());
            // postdata.append('purchContractVatInfo.receiptType', $("[name=receiptType]").val());
            // postdata.append('purchContractVatInfo.openCycle', $("[name=openCycle]").val());
            // postdata.append('purchContractVatInfo.openBank', $("[name=openBank]").val());
            // postdata.append('purchContractVatInfo.receiptAccount', $("[name=receiptAccount]").val());
            // postdata.append('purchContractVatInfo.receiptRemark', $("[name=receiptRemark]").val());

            postdata.append('purchContractQualityAccept.acceptCriteria', $("[name=acceptCriteria]").val());
            postdata.append('purchContractQualityAccept.qualityCriteria', $("[name=qualityCriteria]").val());

            // postdata.append('purchContractSettlePayment.settleMethod', $("[name=settleMethod]").val());
            // postdata.append('purchContractSettlePayment.paymentMethod', $("[name=paymentMethod]").val());

            postdata.append('purchContractDeliverClause.deliverSite', $("[name=deliverSite]").val());
            postdata.append('purchContractDeliverClause.deliverMethod', $("[name=deliverMethod]").val());
            postdata.append('purchContractDeliverClause.deliverDate', $("[name=deliverDate]").val());
            postdata.append('purchContractDeliverClause.transportPremium', $("[name=transportPremium]").val());

            // postdata.append('purchContractSellerBlame.penaltyRate', $("[name=penaltyRate]").val());

            // postdata.append('purchContractPunishClause.contractCompensateRate', $("[name=contractCompensateRate]").val());
            // postdata.append('purchContractPunishClause.contractPenaltyRate', $("[name=contractPenaltyRate]").val());

            //需方
          /*   for (var i = 1; i < $(".xufangListTbody").length; i++) {
                postdata.append('purchContractBuyerReceiver[' + (i - 1) + '].name', $(".xufangListTbody").eq(i).find('td').eq(1).find('input').val());
                postdata.append('purchContractBuyerReceiver[' + (i - 1) + '].certno', $(".xufangListTbody").eq(i).find('td').eq(2).find('input').val());
                postdata.append('purchContractBuyerReceiver[' + (i - 1) + '].contact', $(".xufangListTbody").eq(i).find('td').eq(3).find('input').val());
            }
            i = null; */

            //供应商
            /* for (var i = 1; i < $(".supplierListTbody").length; i++) {
                postdata.append('purchContractSellerSender[' + (i - 1) + '].name', $(".supplierListTbody").eq(i).find('td').eq(1).find('input').val());
                postdata.append('purchContractSellerSender[' + (i - 1) + '].certno', $(".supplierListTbody").eq(i).find('td').eq(2).find('input').val());
                postdata.append('purchContractSellerSender[' + (i - 1) + '].contact', $(".supplierListTbody").eq(i).find('td').eq(3).find('input').val());
            }
            i = null; */

            //其他条件
            for (var i = 1; i < $(".otherListTbody").length; i++) {
                postdata.append('purchContractOtherClause[' + (i - 1) + '].serialNumber', $(".otherListTbody").eq(i).find('td').eq(0).find('span').text());
                postdata.append('purchContractOtherClause[' + (i - 1) + '].paymentCondition', $(".otherListTbody").eq(i).find('td').eq(1).find('input').val());
            }
            i = null;

            postdata.append('purchContractApproval.signMode', $('[name=signMode]:checked').val() ? submitStatus === 'create' ? '1' : $('[name=signMode]:checked').val() : '')
            if($('[name=signMode]:checked').val() == '1') {
                if(submitStatus === 'save') {
                    if(!$('[name=purchContractApprovalUpload]:checked').val()) {
                        new $.zui.Messager('请选择上传合同文件', {
                            type: 'danger'
                        }).show();
                        return
                    }
                }
                postdata.append('purchContractApproval.useContract', $('[name=useContract]').prop('checked') ? 1 : 0)
                postdata.append('purchContractApproval.upload', $('[name=purchContractApprovalUpload]:checked').val() ? $('[name=purchContractApprovalUpload]:checked').val() : '')
            }
        }else {
            if(submitStatus === 'save') {
                if(!$('[name=approvalComment]').val()) {
                    new $.zui.Messager('请输入审批意见', {
                        type: 'danger'
                    }).show();
                    return
                }
            }
        }

        postdata.append('purchContractApproval.approvalConclusion', $('[name=approvalConclusion]:checked').val())
        postdata.append('purchContractApproval.approvalComment', $('[name=approvalComment]').val())



        // 签署合同文件
        if($('[name=approvalConclusion]:checked').val() == 'pass' && $('[name=purchContractApprovalUpload]:checked').val() == '1' && submitStatus !== 'create') {
            let contractListTbodyData = $('.contractListTable').find('tr').eq(0).css('display') === 'table-row' ? $('.contractListTbody') : $('.contractListTbody').not(':first')
            for(let j = 0; j < contractListTbodyData.length; j++ ){
                let el = contractListTbodyData[j]
                if(!$(el).find('.contractName').val() && submitStatus === 'save') {
                    new $.zui.Messager('请输入合同名称', {
                        type: 'danger'
                    }).show();
                    return
                }
                postdata.append('purchContractApproval.uploadPurchContracts['+j+'].contractName', $(el).find('.contractName').val())
                let file = $(el).find('td').eq(3).find('.fileListBox').data('filearray')
                let fileId = $(el).find('.fileListBox .file-name').attr('originalId')
                if(!file.length && !fileId && submitStatus === 'save') {
                    new $.zui.Messager('请上传附件', {
                        type: 'danger'
                    }).show();
                    return
                }
                if(fileId) {
                    postdata.append('purchContractApproval.uploadPurchContracts['+j+'].fileId', fileId)
                }else {
                    if(file[0]) {
                        postdata.append('purchContractApproval.uploadPurchContracts['+j+'].file', file[0])
                    }

                }
            }
        }
        let ajaxUrl = '/purchContract/approval/doAudit'
        if(submitStatus === 'temp') {
            tipword = '暂存'
            postdata.append('purchContractApproval.visible', '0')
        }else if (submitStatus === 'save') {
            tipword = '提交'
            postdata.append('purchContractApproval.visible', '1')
        }else if (submitStatus === 'create') {
            postdata.append('purchContractApproval.visible', '0')
            postdata.append('makeContract', true)
            tipword = '生成采购合同文件'
            ajaxUrl = '/purchContract/approval/makeContractPdf'
        }

        $.ajax({
            url: ajaxUrl,
            type: 'post',
            data: postdata,
            processData: false,
            contentType: false,
            success: function (data) {
                if (data.success) {

                    new $.zui.Messager(tipword + '成功', {
                        type: 'success'
                    }).show();

                    if(submitStatus === 'save' || submitStatus === 'temp') {

                        $(".yk_rightcontent").load('/purchContract/list');
                    }
                    if(submitStatus === 'create') {
                        $('[name=signMode]').get(0).checked = true
                        $('.signModeChange').show()
                        $('[name=purchContractApprovalUpload]').change()
                        $('[name=useContract]').prop('checked', true)
                        const fileStorage  = data.data
                        $('.procurementContract').find('.fileListBox .fileContent').empty()
                        const procurementContractStr = `
                            <div class="fileStorage" style="display:none">
                                    <input type="text" class="originalId"   value="${fileStorage.id}">
                                    <input type="text" class="originalUrl"  value="${fileStorage.path}">
                                    <input type="text" class="originalType" value="${fileStorage.fileType}">
                                    <input type="text" class="originalName" value="${fileStorage.originalName}">
                                    <input type="text" class="originalSize" value="${fileStorage.size}">
                            </div>
                        `
                        showOriginalFile(procurementContractStr, $('.procurementContract').find('.fileListBox'), 'onlyView')
                    }
                    // $(".newTabAddUpdateBtnBox .save, .newTabAddUpdateBtnBox .btn-cancel, .newTabAddUpdateBtnBox .temp").removeClass("loadingCircle");
                    return false;

                } else {
                    new $.zui.Messager(tipword + '失败:' + data.msg, {
                        type: 'danger'
                    }).show();
                    initSignType()
                    // $(".newTabAddUpdateBtnBox .save, .newTabAddUpdateBtnBox .btn-cancel, .newTabAddUpdateBtnBox .temp").removeClass("loadingCircle");
                }
            },
            error: function () {
                new $.zui.Messager(tipword + '时发生错误:' + status, {
                    type: 'danger'
                }).show();
                initSignType()
                // $(".newTabAddUpdateBtnBox .save, .newTabAddUpdateBtnBox .btn-cancel, .newTabAddUpdateBtnBox .temp").removeClass("loadingCircle");
            }
        });
        return false;
    };

    var formRules = {
        'projectAmountCategory': {
            required: true
        },
        'goodsPriceSettleMethod': {
            required: true
        },
        'priceComment': {
            required: true
        },
        'taxRate': {
            required: true,
        },
        'receiptType': {
            required: true
        },
        'openCycle': {
            required: true
        },
        'openBank': {
            required: true
        },
        'receiptAccount': {
            required: true
        },
        'receiptRemark': {
            required: true,
        },
        'acceptCriteria': {
            required: true
        },
        'qualityCriteria': {
            required: true
        },
        'settleMethod': {
            required: true
        },
        'paymentMethod': {
            required: true,
        },
        'deliverSite': {
            required: true
        },
        'deliverDate':{
            required:true,
        },
        'transportPremium':{
            required:true,
        },
        'deliverMethod': {
            required: true
        },
        'penaltyRate': {
            required: true,
            checkPenaltyRate:true,
        },
        'contractCompensateRate': {
            required: true,
            checkContractCompensateRate:true,
        },
        'contractPenaltyRate': {
            required: true,
            checkContractPenaltyRate:true,
        },
        'approvalConclusion': {
            required: true
        },
        'signMode': {
            required: true
        },
        // 'purchContractApprovalUpload': {
        //     required: true
        // }

    };

    var formMessages = {
        'projectAmountCategory': {
            required: '请选择工程量类别'
        },
        'goodsPriceSettleMethod': {
            required: '请输入货物单价结算方式'
        },
        'priceComment': {
            required: '请输入价款说明'
        },
        'taxRate': {
            required: '请输入税率',
        },
        'receiptType': {
            required: '请输入发票类型'
        },
        'openCycle': {
            required: '请输入开票周期'
        },
        'openBank': {
            required: '请输入发票开户行'
        },
        'receiptAccount': {
            required: '请输入发票账号'
        },
        'receiptRemark': {
            required: '请输入发票备注',
        },
        'acceptCriteria': {
            required: '请输入验收标准'
        },
        'qualityCriteria': {
            required: '请输入质量标准'
        },
        'settleMethod': {
            required: '请选择结算方式'
        },
        'paymentMethod': {
            required: '请选择付款方式',
        },
        'deliverSite': {
            required: '请输入交货地点'
        },
        'deliverMethod': {
            required: '请输入交货方式'
        },
        'deliverDate':{
            required:'请输入交货日期',
        },
        'transportPremium':{
            required:'请输入运费及保险费',
        },
        'penaltyRate': {
            required: '请输入供应商违约金比例'
        },
        'contractCompensateRate': {
            required: '请输入合同补偿金比例',
        },
        'contractPenaltyRate': {
            required: '请输入合同违约金比例'
        },
        'approvalConclusion': {
            required: '请选择审批结论'
        },
        'signMode': {
            required: '请选择合同签署方式'
        },
        // 'purchContractApprovalUpload': {
        //     required: '请选择上传合同'
        // }

    };

    //供应商违约金比例限制
    $.validator.addMethod("checkPenaltyRate",function(value,element){
        value = value.replace(/,/gi,'')
        var score = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/;
        return this.optional(element) || (score.test(value));
    },"供应商违约金比例格式不正确");

    //合同补偿金比例限制
    $.validator.addMethod("checkContractCompensateRate",function(value,element){
        value = value.replace(/,/gi,'')
        var score = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/;
        return this.optional(element) || (score.test(value));
    },"合同补偿金比例格式不正确");

    //合同违约金比例限制
    $.validator.addMethod("checkContractPenaltyRate",function(value,element){
        value = value.replace(/,/gi,'')
        var score = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/;
        return this.optional(element) || (score.test(value));
    },"合同违约金比例格式不正确");

    //表单验证
    function addNewCustomer(e) {
        $("#contractReview-form").validate({
            promptPosition: "bottomLeft",
            showErrors : function(errorMap, errorList) {
                if(errorList.length) {
                    initSignType()
                }

                this.defaultShowErrors();
            },
            submitHandler: function (form) {
                if($('[name=approvalConclusion]:checked').val() == 'pass') {
                    //需方必填验证
                    // if ($(".xufangListTable .xufangListTbody").length) {
                    //     $('.xufangListTable .validInput').keyup();
                    // } else {
                    //     new $.zui.Messager('请添加需方收货人。', {
                    //         type: 'danger'
                    //     }).show();
                    //     return false;
                    // }
                    // //收货必填验证
                    // if ($(".supplierListTable .supplierListTbody").length) {
                    //     $('.supplierListTable .validInput').keyup();
                    // } else {
                    //     new $.zui.Messager('请添加供应商发货人。', {
                    //         type: 'danger'
                    //     }).show();
                    //     return false;
                    // }
                    if($(".otherListTable .otherListTbody").length) {
                        $('.otherListTbody .validInput').change();
                    }else {
                        initSignType()
                        new $.zui.Messager('请添加其他条款。' , {
                            type: 'danger'
                        }).show();
                        return false;
                    }
                    //其他必填验证
                    if ($(".otherListTable .otherListTbody").length) {
                        $('.otherListTable .validInput').keyup();
                    } else {
                        initSignType()
                        new $.zui.Messager('请添加其他条款。', {
                            type: 'danger'
                        }).show();
                        return false;
                    }
                }

                if ($('.error.shows').length > 0) {
                    $('.error.shows:first').prev().focus();
                    return;
                }
                ;
                submitFunction(e);
            },
            rules: formRules,
            messages: formMessages
        });
    };


    //需方必填验证
    $(".goodsListTable").on("keyup", ".validInput", function (e) {
        if ($(this).parent().parent().attr('display') !== 'none') {
            if ($(this).val() == '') {
                $(this).next().addClass('shows').show();
            } else {
                $(this).next().removeClass('shows').hide();
            }
        }
    })

    //供应商必填验证
    $(".supplierListTable").on("keyup", ".validInput", function (e) {
        if ($(this).parent().parent().attr('display') !== 'none') {
            if ($(this).val() == '') {
                $(this).next().addClass('shows').show();
            } else {
                $(this).next().removeClass('shows').hide();
            }
        }
    })

    //其他必填验证
    $(".otherListTable").on("keyup", ".validInput", function (e) {
        if ($(this).parent().parent().attr('display') !== 'none') {
            if ($(this).val() == '') {
                $(this).next().addClass('shows').show();
            } else {
                $(this).next().removeClass('shows').hide();
            }
        }
    })

    // 生成采购合同文件
    $('.createProcurementContract').click(function (e) {
        submitStatus = 'create'
        $(".yk_addNewMsg .createContract").click()
    })

    // 暂存按钮
    $(".yk_addNewMsg .temp").click(function (e) {
        if (!$(this).hasClass('loadingCircle')) {
            submitStatus = 'temp'
            submitFunction()
            return false
        }

    })
    // 提交按钮
    $(".yk_addNewMsg .save").click(function (e) {
        if (!$(this).hasClass('loadingCircle')) {
            if($('[name=approvalConclusion]:checked').val() == 'pass' && $('[name=signMode]:checked').val() == '1') {
                bootbox.confirm({
                    title: '确认提交合同',
                    message: '<div style="text-align:left;font-size:0.12rem">确定已核对所有合同模板？</div>',
                    size: 'small',
                    buttons: {
                            cancel:  {
                                label: '取消',
                                className: 'btn-white btn-info'
                            },
                            confirm: {
                                label: '确定',
                                className:'btn-white btn-info colorbtn downloadContract'
                            }
                    },
                    callback:function(result){
                        if (result) {
                            $(".yk_addNewMsg .saveHide").click()
                        };
                    }
                })
                return false
            }else {
                $(".yk_addNewMsg .saveHide").click()
                return false
            }

        }
    });

    $(".yk_addNewMsg .saveHide").click(function (e) {
        submitStatus = 'save'
        addNewCustomer();
    })

    $(".yk_addNewMsg .createContract").click(function (e) {
        submitStatus = 'create'
        addNewCustomer();
    });

    // 关闭按钮
    $(".yk_addNewMsg .btn-cancel,.newBackBtn").click(function () {
        if (!$(this).hasClass('loadingCircle')) {
            $(".yk_rightcontent").load('/purchContract/list');
        }
        ;
        return false;
    });


})
