function chooseGoods(id) {
    var chooseData = $('#chooseGoodsList').jqGrid('getRowData', id);
    var trStr = `<tr class="choosedGoodsTbody">
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;"></td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseData.acceptanceDate + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;display: none">` + chooseData.enterpriseName + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseData.goodsName + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseData.goodsFactory + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseData.goodsType + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseData.goodsUnit + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseData.goodsNum + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + (chooseData.salesPrice ? chooseData.salesPrice : '') + `</td>
                        <td style="display: none">` + chooseData.supplierId + `</td>
                        <td style="display: none">` + chooseData.acceptanceBusinessGoodsId + `</td>
                        <td style="display: none">` + chooseData.salesRetentionPercent + `</td>
                        <td style="display: none">` + chooseData.purchRetentionPercent + `</td>
                        <td style="display: none">` + chooseData.purchasePrice + `</td>
                        <td style="display: none">` + chooseData.accountStart + `</td>
                        <td style="display: none">` + chooseData.accountPeriod + `</td>
                        <td style="display: none">` + chooseData.accountEnd + `</td>
                        <td style="display: none">` + chooseData.clear + `</td>
                        <td style="display: none" class="monthlyinterestRate">` + chooseData.monthlyinterestRate + `</td>
                        <td style="display: none" class="accrualMarginCalcMethod">` + chooseData.accrualMarginCalcMethod + `</td>
                        <td style="display: none" class="differAmount">` + chooseData.differAmount + `</td>
                        <td style="display: none" class="factoringFinanceDeadline">` + chooseData.factoringFinanceDeadline + `</td>
                        <td width="10%" style="background-color:#fff;border-bottom: 1px solid #E8F0F3;border-right: 1px solid #E8F0F3;"><span class="relaseGoods" style="color: #5AC4FC;cursor: pointer">释放</span></td>
                    </tr>`
    $(".choosedGoodsList").append(trStr);
    $("#myModal-chooseGoods").resize();
    sortChooseGoodsInfo();
}

//paixu
function sortChooseGoodsInfo() {
    $(".choosedGoodsTbody").each(function (i, ele) {
        $(ele).find('td:first').text(i + 1);
    });
}

function calcMoney(money) {
    return money == null ? '' : money
}

$(function () {
    //初始化日期
    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=accountsReceivableStartDate]','1970-01-01','2116-12-31');
    $('[name=accountsReceivableStartDate]').datetimepicker(
        {
            weekStart: 1,
            autoclose: 1,
            todayHighlight: 0,
            startView: 2,
            minView: 2,
            forceParse: 0,
            showMeridian: 1,
        }
    ).on('change', function () {
        let num = Number($('[name=accountReceivablePeriod]').val()) + 1
        $('[name=accountsReceivableEndDate]').val(caculateDeadlineDate($('[name=accountsReceivableStartDate]').val(), num ))
    });

    $('[name=accountReceivablePeriod]').on('blur', function (params) {
        let num = Number($('[name=accountReceivablePeriod]').val()) + 1
        $('[name=accountsReceivableEndDate]').val(caculateDeadlineDate($('[name=accountsReceivableStartDate]').val(), num ))
    })

    $(".amountInput").each(function (i, ele) {
        $(ele).val(commaDelimiter($(this).val()))
    })
    $('#entryForm').on("keyup", ".amountInput", function () {
        $(this).val(commaDelimiter($(this).val()))
    })

    // 附件相关dom
    var fileWrapperbasic = '<div class="file-wrapper"><div class="file-icon" style="color: #5AC4FC;"><div class="file-icon-image"></div></div>' +
        '<div class="content"><div class="file-name"></div><div class="file-size small text-muted"></div></div>' +
        '<div class="actions" style="width:0.5rem"><a class="btn btn-link btn-delete-file">' +
        '<em>删除</em><i class="operateIconfont operateIcon-shanchu"></i></a></div></div>';

    // 在附件元素的data上存放选择的附件数据,初始为空
    $('.addFileList').each(function (i, ele) {
        $(ele).data('filearray', []);
        $(ele).data('deletefileid', []);
    });

    // 展示原先有的附件
    function showOriginalFile(source, insert) {
        for (var j = 0; j < $(source).length; j++) {
            var originalFileWrapper = $(fileWrapperbasic).clone();
            originalFileWrapper.find('.file-name').text($(source).eq(j).find('.originalName').val());
            originalFileWrapper.find('.file-name').attr('originalid', $(source).eq(j).find('.originalId').val());
            if (parseFloat($(source).eq(j).find('.originalSize').val()) < 1048576) {
                originalFileWrapper.find('.file-size').text(($(source).eq(j).find('.originalSize').val() / 1024).toFixed(2) + "KB");
            } else {
                originalFileWrapper.find('.file-size').text(($(source).eq(j).find('.originalSize').val() / 1024 / 1024).toFixed(2) + "MB");
            }
            ;
            var originaltype = $(source).eq(j).find('.originalType').val().toUpperCase();
            if (originaltype == '.JPG' || originaltype == '.JPEG' || originaltype == '.PNG' || originaltype == '.BMP') {
                originalFileWrapper.find('.file-icon-image').css('background-image', 'url(' + $(source).eq(j).find('.originalUrl').val() + ')');
            } else {
                originalFileWrapper.find('.file-icon-image').append('<i class="icon icon-file-pdf"></i>');
            }
            ;
            originalFileWrapper.find('.btn-delete-file').addClass('btn-delete-originalfile').removeClass("btn-delete-file");

            originalFileWrapper.find('.btn-yulan-file').attr('href', '/fileStorage/preview?fileId=' + $(source).eq(j).find('.originalId').val());
            originalFileWrapper.find('.btn-xiazai-file').attr('href', '/fileStorage/downloadFile?fileId=' + $(source).eq(j).find('.originalId').val());
            $(insert).find('.fileContent').append(originalFileWrapper)
        }
        ;
        j = null;
        if ($(insert).find('.file-wrapper').length > 0) {
            $(insert).find('.spanHolder').remove();
        }
        ;
    };

    if ($('#updatePage').length) {
        // 展示原附件
        showOriginalFile('.fileInfoListOriginal', '.addFileList');
    }

    // 触发选择附件
    $('#entryForm').on("click", ".fileInfoListBox .choiceFile", function () {
        if (!window.FileReader) {
            new $.zui.Messager('您的浏览器版本过低，请升级您的浏览器', {
                type: 'danger'
            }).show();
            return;
        }
        ;
        $(this).parent().find('.fileinput').click();
    });

    // 触发选择附件
    $('#entryForm').on("click", ".fileInfoListBox .fileContent", function () {
        if (!window.FileReader) {
            new $.zui.Messager('您的浏览器版本过低，请升级您的浏览器', {
                type: 'danger'
            }).show();
            return;
        }
        ;
        if ($(this).find(".spanHolder").length > 0) {
            $(this).parent().prev().click();
        }
        ;
    });

    // 选择附件
    $("#entryForm").on("change", ".fileInfoListBox .fileinput", function (e) {
        var that = $(this);
        if (that.val() == '') {
            $(".addFileList .error").addClass('shows').show();
        } else {
            $(".addFileList .error").removeClass('shows').hide();
        }
        var choosefiles = e.target.files || e.dataTransfer.files;
        for (var i = 0; i < choosefiles.length; i++) {
            var file = e.target.files[i] || e.dataTransfer.files[i];//用于提交
            $(this).parent().data('filearray').push(file);
            fileWrapper = $(fileWrapperbasic).clone();
            var type = file.type;
            var indexof = type.indexOf("/"), fileType = '';
            if (indexof != -1) {
                var index = parseInt(indexof) + 1;
                fileType = type.substring(index, type.length).toUpperCase();
            }
            ;
            fileWrapper.find('.file-name').text(file.name);
            if (parseFloat(file.size) < 1048576) {
                fileWrapper.find('.file-size').text((file.size / 1024).toFixed(2) + 'KB');
            } else {
                fileWrapper.find('.file-size').text((file.size / 1024 / 1024).toFixed(2) + 'MB');
            }
            ;
            that.next().find(".fileContent").append(fileWrapper);
            // 有附件时去掉框框里的'上传附件'字样
            if (that.next().find('.file-wrapper').length > 0) {
                that.next().find('.spanHolder').remove();
            }
            ;
            detailpreview(fileType, fileWrapper, file);
        }
        ;
        i = null;

        function detailpreview(fileType, fileWrapper, file) {
            var reader = new FileReader();
            reader.readAsDataURL(file);//转为base64(预览)
            reader.onload = function (e) {
                e = e || window.event;
                if (fileType == 'JPG' || fileType == 'JPEG' || fileType == 'PNG' || fileType == 'BMP' || fileType == 'JPG') {
                    fileWrapper.find(".file-icon-image").css("backgroundImage", 'url(' + e.target.result + ')')
                } else {
                    fileWrapper.find(".file-icon-image").append('<i class="icon icon-file-pdf"></i>')
                }
                ;
            };
        };
    });

    // 删除附件
    $("#entryForm").on("click", ".btn-delete-file", function () {
        var deleteindex = $(this).parents('td').find('.btn-delete-file').index($(this));
        $(this).parents('td').data('filearray').splice(deleteindex, 1);
        $(this).parents(".uploaderFile").prev().val(null);
        if ($(this).parents('td').find('.file-wrapper').length == 1) {
            $(this).parents(".file-wrapper").before('<span class="spanHolder">上传附件</span>');
        }
        ;
        $(this).parents(".file-wrapper").remove();
        return false;
    });


    // 排序-货物
    function sortIGoodsnfo() {
        var totalPrice = 0;
        var totalNum = 0;
        var totalPurchase = 0;
        $(".goodsListTbody").each(function (i, ele) {
            $(ele).find('td:first span').text(i);
            totalPrice += Number($(ele).find('td').eq(9).find('input').val().split(',').join(''))
            totalPurchase += Number($(ele).find('td').eq(12).find('input').val().split(',').join(''))
            totalNum += Number($(ele).find('td').eq(7).text().split(',').join(''))
        });
        if ($(".goodsListTbody").length <= 1) {
            $('.goodsTable .negativeInformationReduce').hide();
        } else {
            $('.goodsTable .negativeInformationReduce').show();
        }
        if(totalPrice!== 'null') {
            $('.totalPrice').text(commaDelimiter((Math.round(totalPrice*10000)/10000).toFixed(2)))
        }else {
            $('.totalPrice').text('0.00')
        }
        if(totalPurchase!== 'null') {
            $('.totalPurchase').text(commaDelimiter((Math.round(totalPurchase*10000)/10000).toFixed(2)))
        }else {
            $('.totalPurchase').text('0.00')
        }
        if(totalNum!== 'null') {
            $('.totalNum').text(commaDelimiter((Math.round(totalNum*10000)/10000).toFixed(4)))
        }else {
            $('.totalNum').text('0.0000')
        }
    };
    sortIGoodsnfo();
    var goodsChooseType = ''
    // 删除行-货物
    $("#entryForm").on('click', '.goodsTable .negativeInformationReduce', function () {
        //diceng
        var id = $(this).parent().parent().attr('id')
        var acceptanceBasicInfoId = $(this).parent().parent().attr('acceptanceBasicInfoId')
        $('.goodsListTbody').each(function ( i, ele) {
            if(id == $(ele).attr('id')) {
                $(ele).remove()
                sortIGoodsnfo();
            }

        })
        $(".underlyingList").each(function ( i, ele) {
            if(acceptanceBasicInfoId == $(ele).attr('id')) {
                $(ele).remove()
                sortReceiptInfo();
            }
        })
        if($('.goodsListTbody').length === 1) {
            goodsChooseType = ''
        }
    });

    $(".cancelBtn").on('click', function (params) {
        $("#myModal-chooseGoods").modal("hide");
        $(".choosedGoodsList").empty();
        if($('.goodsListTbody').length <= 1) {
            goodsChooseType = ''
        }
    })

    $(".cancelBtn2").on('click', function (params) {
        $("#myModal-chooseGoods2").modal("hide");
        $(".choosedGoodsList2").empty();
        if($('.goodsListTbody').length <= 1) {
            goodsChooseType = ''
        }
    })

    // 排序-底层信息
    function sortReceiptInfo() {
        let underlyingTotalNum = 0;
        let netAccountsReceivableAmountAll = 0
        let totalAmountAccountsReceivable = 0
        $(".underlyingList").each(function (i, ele) {
            $(ele).find('td:first span').text(i + 1);
            underlyingTotalNum += Number($(ele).find('td').eq(5).text().split(',').join(''))
            netAccountsReceivableAmountAll += Number($(ele).find('td').eq(7).text().split(',').join(''))
            totalAmountAccountsReceivable += Number($(ele).find('td').eq(6).text().split(',').join(''))
        });
        if(underlyingTotalNum!== 'null') {
            $('.underlyingTotalNum').text(commaDelimiter((Math.round(underlyingTotalNum*10000)/10000).toFixed(4)))
        }else {
            $('.underlyingTotalNum').text('0.0000')
        }
        if(netAccountsReceivableAmountAll!== 'null') {
            $('.netAccountsReceivableAmountAll').text(commaDelimiter((Math.round(netAccountsReceivableAmountAll*10000)/10000).toFixed(2)))
        }else {
            $('.netAccountsReceivableAmountAll').text('0.00')
        }
        if(totalAmountAccountsReceivable!== 'null') {
            $('.totalAmountAccountsReceivable').text(commaDelimiter((Math.round(totalAmountAccountsReceivable*10000)/10000).toFixed(2)))
        }else {
            $('.totalAmountAccountsReceivable').text('0.00')
        }
    };
    sortReceiptInfo();

    //保存
    function submitFunction(type) {
        var postdata = new FormData();
        // 底层基本信息
        postdata.append('underlyingBasicInfo.supplierId',$("[name=supplierName]").val());
        postdata.append('underlyingBasicInfo.businessNumber',$("[name=businessNo]").val());
        postdata.append('underlyingBasicInfo.businessName',$("[name=businessName]").val());
        postdata.append('underlyingBasicInfo.enterpriseCustomerInfoId',$("[name=enterpriseName]").val());
        postdata.append('underlyingBasicInfo.tradingPlatformId',$("[name=tradingPlatformId]").val());
        postdata.append('underlyingBasicInfo.contractName',$("[name=contractName]").val());
        postdata.append('underlyingBasicInfo.contractNumber',$("[name=contractNumber]").val());
        postdata.append('underlyingBasicInfo.contractAmount',$("[name=contractAmount]").val().split(',').join(''));
        postdata.append('underlyingBasicInfo.remark',$("[name=remark]").val());
        // 应收账款信息
        postdata.append('underlyingBasicInfo.accountsReceivableStartDate',$("[name=accountsReceivableStartDate]").val());
        postdata.append('underlyingBasicInfo.accountsReceivableEndDate',$("[name=accountsReceivableEndDate]").val());
        postdata.append('underlyingBasicInfo.accountReceivablePeriod',$("[name=accountReceivablePeriod]").val());

        //货物信息
        for (var i = 1; i < $(".goodsListTbody").length; i++) {
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].acceptanceDate', $(".goodsListTbody").eq(i).find('td').eq(1).text());
            if(goodsChooseType === 'check') {
                postdata.append('underlyingGoodsInfoList['+(i-1)+'].acceptanceGoodsInfoId',$(".goodsListTbody").eq(i).find('td').eq(1).attr('id'));
                postdata.append('underlyingGoodsInfoList['+(i-1)+'].acceptanceBasicInfoId',$(".goodsListTbody").eq(i).find('td').eq(1).attr('acceptanceBasicInfoId'));
            }else {
                postdata.append('underlyingGoodsInfoList['+(i-1)+'].settlementGoodsInfoId',$(".goodsListTbody").eq(i).find('td').eq(1).attr('id'));
                postdata.append('underlyingGoodsInfoList['+(i-1)+'].acceptanceBasicInfoId',$(".goodsListTbody").eq(i).find('td').eq(1).attr('acceptanceBasicInfoId'));
                postdata.append('underlyingGoodsInfoList['+(i-1)+'].acceptanceGoodsInfoId',$(".goodsListTbody").eq(i).find('td').eq(1).attr('acceptanceGoodsInfoId'));
                postdata.append('underlyingGoodsInfoList['+(i-1)+'].settlementBasicInfoId',$(".goodsListTbody").eq(i).find('td').eq(1).attr('settlementBasicInfoId'));
            }
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].goodsName', $(".goodsListTbody").eq(i).find('td').eq(3).text());
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].goodsFactory', $(".goodsListTbody").eq(i).find('td').eq(4).text());
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].goodsType', $(".goodsListTbody").eq(i).find('td').eq(5).text());
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].goodsUnit', $(".goodsListTbody").eq(i).find('td').eq(6).text());
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].goodsQuantity', $(".goodsListTbody").eq(i).find('td').eq(7).text());
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].salesPrice', $(".goodsListTbody").eq(i).find('td').eq(8).find('input').val().split(',').join(''));
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].salesTotalPrice', $(".goodsListTbody").eq(i).find('td').eq(9).find('input').val().split(',').join(''));
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].salesGuaranteeMoney', $(".goodsListTbody").eq(i).find('td').eq(10).find('input').val().split(',').join(''));
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].purchasePrice', $(".goodsListTbody").eq(i).find('td').eq(11).find('input').val().split(',').join(''));
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].purchaseTotalPrice', $(".goodsListTbody").eq(i).find('td').eq(12).find('input').val().split(',').join(''));
            postdata.append('underlyingGoodsInfoList[' + (i - 1) + '].purchaseGuaranteeMoney', $(".goodsListTbody").eq(i).find('td').eq(13).find('input').val().split(',').join(''));
        }
        i = null;

        //底层信息
        for (var i = 0; i < $(".underlyingList").length; i++) {
            postdata.append('accountsReceivableInfoList[' + (i) + '].acceptanceBasicInfoId', $(".underlyingList").eq(i).attr('id'));
            postdata.append('accountsReceivableInfoList[' + (i) + '].acceptanceGoodsInfoId', $(".underlyingList").eq(i).attr('acceptanceGoodsInfoId'));
            postdata.append('accountsReceivableInfoList[' + (i) + '].goodsName', $(".underlyingList").eq(i).find('td').eq(1).text());
            postdata.append('accountsReceivableInfoList[' + (i) + '].goodsFactory', $(".underlyingList").eq(i).find('td').eq(2).text());
            postdata.append('accountsReceivableInfoList[' + (i) + '].goodsType', $(".underlyingList").eq(i).find('td').eq(3).text());
            postdata.append('accountsReceivableInfoList[' + (i) + '].goodsUnit', $(".underlyingList").eq(i).find('td').eq(4).text());
            postdata.append('accountsReceivableInfoList[' + (i) + '].goodsQuantity', $(".underlyingList").eq(i).find('td').eq(5).text());
            postdata.append('accountsReceivableInfoList[' + (i) + '].accountsReceivableAmount', $(".underlyingList").eq(i).find('td').eq(6).text().split(',').join(''));
            postdata.append('accountsReceivableInfoList[' + (i) + '].netAccountsReceivableAmount', $(".underlyingList").eq(i).find('td').eq(7).text().split(',').join(''));
        }
        i = null;

        // 附件信息
        for (var m = 0; m < $('.netPrice .addFileList').data('filearray').length; m++) {
            postdata.append('file[' + m + ']', $('.netPrice .addFileList').data('filearray')[m]);
        }
        ;
        m = null;

        // var url = '/underlying/doAdd', tip = '添加';
        if(type == 'temp'){
            tipword = '暂存';
            postdata.append('submit',false);
        }else{
            tipword = '添加';
            postdata.append('submit',true);
        }

        $.ajax({
            url: '/underlying/doAdd',
            type: 'post',
            data: postdata,
            processData: false,
            contentType: false,
            success: function (data) {
                if (data.success) {
                    new $.zui.Messager(tipword + '底层成功', {
                        type: 'success'
                    }).show();
                    $.get('/underlying/pendingList?businessBasicId=' + underlyingQuery.detailId2, function (data) {
                        $(".yk_rightcontent").empty().append(data);
                    });
                } else {
                    new $.zui.Messager(tipword + '底层失败:' + data.msg, {
                        type: 'danger'
                    }).show();
                }
            },
            error: function (status) {
                new $.zui.Messager(tipword + '底层时发生错误:' + status, {
                    type: 'danger'
                }).show();
            }
        });
        return false;
    };

    var formRules = {
        'supplierName':{
            required:true
        },
        'enterpriseName':{
            required:true
        },
        'businessNo':{
            required:true
        },
        'tradingPlatformId':{
            required:true
        },

    };

    var formMessages = {
        'supplierName':{
            required:'请选择供应商名称'
        },
        'enterpriseName':{
          required:'请选择核心企业名称'
        },
        'businessNo':{
            required:'请选择业务编号'
        },
        'tradingPlatformId':{
            required:'请输入贸易平台'
        },
    };

    //表单验证
    function addNewCustomer(e) {

        if ($(".addFileList .fileinput").val() == '' && !$(".addFileList .content").length) {
            $(".addFileList .error").addClass('shows').show();
        } else {
            $(".addFileList .error").removeClass('shows').hide();
        }

        $("#entryForm").validate({
            promptPosition: "bottomLeft",
            submitHandler: function (form) {
                //货物必填验证
                if ($(".goodsListTable .goodsListTbody").length) {
                    $('.goodsListTable .validInput').keyup();
                } else {
                    new $.zui.Messager('请添加货物信息。', {
                        type: 'danger'
                    }).show();
                    return false;
                }

                if($(".addFileList .file-name").length==0){
                    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().css('display') !== 'none') {
            if ($(this).val() == '') {
                $(this).next().addClass('shows').show();
            } else {
                $(this).next().removeClass('shows').hide();
            }
        }

    })


    //提交按钮
    $(".yk_addNewMsg .submitBusiness").click(addNewCustomer);

    // 暂存-按钮 
    $(".yk_addNewMsg .submitTemSave").click(function(){
        if($("[name=businessNo]").val() !== ''){
            submitFunction('temp')
            return false            
        }else {
            new $.zui.Messager('请锁定业务编号后暂存', {
                type: 'danger'
            }).show();
            return false            
        }
    })

    //关闭按钮
    $(".yk_addNewMsg .btn-cancel, .newBackBtn").click(function () {
        $.get('/underlying/pendingList?businessBasicId=' + $('[name=basicId]').val(), function (data) {
            $(".yk_rightcontent").empty().append(data);
        });
        return false;
    });


    //释放
    $("#myModal-chooseGoods").on('click', '.chooseGoodsTable .relaseGoods', function () {
        $(this).parents('.choosedGoodsTbody').remove();
        sortChooseGoodsInfo();
        //return false;
    });

    function operate(cellValue, options, rowObject) {
        var btnstr = '';
        btnstr += '<p><span>选择</span><i class="icon-check" onclick="chooseGoods(' + rowObject.id + ')"></i></p>';
        return '<div class="operateIcon noHover">' + btnstr + '</div>';
    };

    function supplier(cellValue, options, rowObject) {
        return rowObject.customer.enterpriseName
    }

    function showAmount(cellValue, options, rowObject) {
        if (cellValue !== null) {
            return commaDelimiter(cellValue)
        } else {
            return ''
        }
    }

    function monthlyinterestRate(cellValue, options, rowObject) {
        if (rowObject.priceRule.monthlyinterestRate !== undefined && rowObject.priceRule.monthlyinterestRate !== null) {
            return rowObject.priceRule.monthlyinterestRate
        } else {
            return ''
        }

    }

    function accrualMarginCalcMethod(cellValue, options, rowObject) {
        if (rowObject.priceRule.accrualMarginCalcMethodDict !== undefined && rowObject.priceRule.accrualMarginCalcMethodDict !== null) {
            return rowObject.priceRule.accrualMarginCalcMethodDict.name
        } else {
            return ''
        }

    }

    function differAmount(cellValue, options, rowObject) {
        if (rowObject.priceRule.differAmount !== undefined && rowObject.priceRule.differAmount !== null) {
            return rowObject.priceRule.differAmount
        } else {
            return ''
        }

    }

    function factoringFinanceDeadline(cellValue, options, rowObject) {
        if (rowObject.priceRule.factoringFinanceDeadline !== undefined && rowObject.priceRule.factoringFinanceDeadline !== null) {
            return rowObject.priceRule.factoringFinanceDeadline
        } else {
            return ''
        }
    }

    function acceptanceGoodInfos(cellValue, options, rowObject) {
        return JSON.stringify(rowObject)
    }

    // 复选框禁用
    function checkBoxDisabled() {
        $('.goodsListTbody').each(function ( i, ele) {
            if($(ele).attr('id')){
                var nameVal = `jqg_chooseGoodsList_${$(ele).attr('id')}`
                    $(`[name=${nameVal}]`).attr('checked', true)
                    $(`[name=${nameVal}]`).attr('disabled',true)
                // setTimeout(() => {
                //     var nameVal = `jqg_chooseGoodsList_${$(ele).attr('id')}`
                //     $(`[name=${nameVal}]`).attr('checked', true)
                //     $(`[name=${nameVal}]`).attr('disabled',true)
                // }, 300);
            }
        })
    }

    function checkBoxDisabled2() {
        $('.goodsListTbody').each(function ( i, ele) {
            if($(ele).attr('id')){
                var nameVal = `jqg_chooseGoodsList2_${$(ele).attr('id')}`
                    $(`[name=${nameVal}]`).attr('checked', true)
                    $(`[name=${nameVal}]`).attr('disabled',true)
                // setTimeout(() => {
                //     var nameVal = `jqg_chooseGoodsList2_${$(ele).attr('id')}`
                //     $(`[name=${nameVal}]`).attr('checked', true)
                //     $(`[name=${nameVal}]`).attr('disabled',true)
                // }, 300);
            }
        })
    }

    function tablefunction(tableid) {
        var tipword = '', pageid = '', pageNo = 1, postData = {};
        url = '', colNamesArray = [], colModelArray = [];
        switch (tableid) {
            case '#chooseGoodsList':
                tipword = '货物';
                pageid = '#chooseGoodsListPage';
                postData = {
                    'supplierId': $("[name=supplierName]").val(),
                    'businessNumber': $('[name=businessNo]').val()
                };
                url = '/underlying/findGoodsByAcceptance'
                rl = '/bill/getAcceptanceGoods';
                colNamesArray = ['ID', '编号', '验收单号', '供应商', '预估结算日期',  '货物信息'];
                colModelArray = [
                    {name: 'id', label: 'ID', hidedlg:true, hidden:true,sortable:false,title:false},
                    {name: 'orderNumber', label: '编号', hidedlg:true, width:55,sortable:false,title:false},
                    {name: 'acceptanceNumber', label: '验收单号', sortable:false, align:'left', title:false},
                    {name: 'supplier.enterpriseName', label: '供应商', sortable:false, align:'left', title:false},
                    {name: 'expectedSettlementDate', label: '预估结算日期',sortable:false, align:'left', title:false},
                    {name: 'acceptanceGoodInfos', label: '货物信息', hidedlg: true, hidden: true, sortable:false, align:'left', title:false, formatter: acceptanceGoodInfos},
                    // {name: 'operate', label: '操作', sortable: false, align: 'left', title: false, formatter: operate},
                ];
                break;
        }
        ;
        sxUtil.jqGrid(tableid, {
            colNames: colNamesArray,
            colModel: colModelArray,
            height: 'auto',
            mtype: 'GET',
            url: url,
            pager: pageid,
            multiselect: true,
            multiboxonly: true,
            beforeSelectRow: function (rowid, e) {
                var $myGrid = $(this),
                    i = $.jgrid.getCellIndex($(e.target).closest('td')[0]),
                    cm = $myGrid.jqGrid('getGridParam', 'colModel');
                return (cm[i].name == 'cb')
            },
            onSelectAll: function(aRowids,status) {
                checkBoxDisabled()
            },
            onPaging:function(pgButton){
                checkBoxDisabled()
            },
            rownumbers: false,
            postData: postData,
            page: pageNo,
            gridComplete: function() {
                checkBoxDisabled();
            },
            loadError: function () {
                // new $.zui.Messager(tipword+'列表加载失败', {
                //     type: 'warning'
                // }).show();
            }
        }, true);
        // checkBoxDisabled()
        // $(tableid).trigger('reloadGrid');
    };

    function tablefunction2(tableid) {
        var tipword = '', pageid = '', pageNo = 1, postData = {};
        url = '', colNamesArray = [], colModelArray = [];
        switch (tableid) {
            case '#chooseGoodsList2':
                tipword = '货物';
                pageid = '#chooseGoodsListPage2';
                postData = {
                    'supplierId': $("[name=supplierName]").val(),
                    'businessNumber': $('[name=businessNo]').val()
                };
                url = ' /underlying/findGoodsBySettlement'
                rl = '/bill/getAcceptanceGoods';
                colNamesArray = ['ID', '编号', '结算单号', '供应商', '结算日期',  '货物信息'];
                colModelArray = [
                    {name: 'id', label: 'ID', hidedlg:true, hidden:true,sortable:false,title:false},
                    {name: 'orderNumber', label: '编号', hidedlg:true, width:55,sortable:false,title:false},
                    {name: 'settlementNumber', label: '结算单号', sortable:false, align:'left', title:false},
                    {name: 'supplier.enterpriseName', label: '供应商', sortable:false, align:'left', title:false},
                    {name: 'settlementDate', label: '结算日期',sortable:false, align:'left', title:false},
                    {name: 'settlementGoodsInfos', label: '货物信息', hidedlg: true, hidden: true, sortable:false, align:'left', title:false, formatter: acceptanceGoodInfos},
                    // {name: 'operate', label: '操作', sortable: false, align: 'left', title: false, formatter: operate},
                ];
                break;
        }
        ;
        sxUtil.jqGrid(tableid, {
            colNames: colNamesArray,
            colModel: colModelArray,
            height: 'auto',
            mtype: 'GET',
            url: url,
            pager: pageid,
            multiselect: true,
            multiboxonly: true,
            beforeSelectRow: function (rowid, e) {
                var $myGrid = $(this),
                    i = $.jgrid.getCellIndex($(e.target).closest('td')[0]),
                    cm = $myGrid.jqGrid('getGridParam', 'colModel');
                return (cm[i].name == 'cb')
            },
            onSelectAll: function(aRowids,status) {
                checkBoxDisabled2()
            },
            onPaging:function(pgButton){
                checkBoxDisabled2()
            },
            rownumbers: false,
            postData: postData,
            page: pageNo,
            gridComplete: function() {
                checkBoxDisabled2();
            },
            loadError: function () {
                // new $.zui.Messager(tipword+'列表加载失败', {
                //     type: 'warning'
                // }).show();
            }
        }, true);
        // checkBoxDisabled2()
        // $(tableid).trigger('reloadGrid');
    };

    tablefunction('#chooseGoodsList');
    tablefunction2('#chooseGoodsList2');

    var goodsFlag = '';
    // 选择已验收货物
    $("#chooseCheckButton").click(function () {
        if(!$("[name=supplierName]").val()) {
            new $.zui.Messager('请选择供应商名称', {
                type: 'danger'
            }).show();
            return
        }
        if(!$('[name=businessNo]').val()) {
            new $.zui.Messager('请选择业务编号', {
                type: 'danger'
            }).show();
            return
        }
        goodsChooseType = ''
        console.log(goodsChooseType, '1111')
        console.log($('.goodsListTbody').eq(1).attr('goodschoosetype') !== 'check', '2222')
        if( goodsChooseType && $('.goodsListTbody').eq(1).attr('goodschoosetype') !== 'check') {
            new $.zui.Messager('请选择结算货物', {
                type: 'danger'
            }).show();
            return
        }
        goodsChooseType = 'check'
        goodsFlag = 'goods';
        $('#chooseGoodsList').setGridParam({
            mtype: 'GET',
            url: ' /underlying/findGoodsByAcceptance',
            datatype: 'json',
            postData: {
                'supplierId': $("[name=supplierName]").val(),
                'businessNumber': $('[name=businessNo]').val()
            },
            page: 1,
            onPaging:function(pgButton){
                checkBoxDisabled()
            },
        });
        $('#chooseGoodsList').trigger('reloadGrid');
        $("#myModal-chooseGoods").modal("show");
        $("#myModal-chooseGoods").on('shown.zui.modal', function () {
            $(".modal-dialog").css({'margin-top': '58px'})
            $(window).resize();
            $("#chooseGoodsList_cb").css({'width': '45', 'padding': '0 0.12rem'})
            $('#chooseGoodsList .jqgfirstrow td:first').css('width', '45')

            $(".choosedGoodsList").empty();
        })
        // checkBoxDisabled()
        return false;
    });
    $('#myModal-chooseGoods').click(function () {
        checkBoxDisabled()
    })
    // 选择结算货物
    $("#chooseSettlementButton").click(function () {
        if(!$("[name=supplierName]").val()) {
            new $.zui.Messager('请选择供应商名称', {
                type: 'danger'
            }).show();
            return
        }
        if(!$('[name=businessNo]').val()) {
            new $.zui.Messager('请选择业务编号', {
                type: 'danger'
            }).show();
            return
        }
        if( goodsChooseType && $('.goodsListTbody').eq(1).attr('goodschoosetype') !== 'settlement') {
            new $.zui.Messager('请选择验收货物', {
                type: 'danger'
            }).show();
            return
        }
        goodsChooseType = 'settlement'
        goodsFlag = 'goods';
        $('#chooseGoodsList2').setGridParam({
            mtype: 'GET',
            url: '/underlying/findGoodsBySettlement',
            datatype: 'json',
            postData: {
                'supplierId': $("[name=supplierName]").val(),
                'businessNumber': $('[name=businessNo]').val()
            },
            page: 1,
            onPaging:function(pgButton){
                checkBoxDisabled2()
            },
        });
        $('#chooseGoodsList2').trigger('reloadGrid');
        $("#myModal-chooseGoods2").modal("show");
        $("#myModal-chooseGoods2").on('shown.zui.modal', function () {
            $(".modal-dialog").css({'margin-top': '58px'})
            $(window).resize();
            $("#chooseGoodsList2_cb").css({'width': '45', 'padding': '0 0.12rem'})
            $('#chooseGoodsList2 .jqgfirstrow td:first').css('width', '45')

            $(".choosedGoodsList2").empty();
        })
        // checkBoxDisabled2()
        return false;
    });
    $('#myModal-chooseGoods2').click(function () {
        checkBoxDisabled2()
    })

    $(".chooseSure").click(function () {
        var ids = $('#chooseGoodsList').jqGrid('getGridParam', 'selarrrow');
        $('.goodsListTbody').each(function ( i, ele) {
            if($(ele).attr('id')){
                ids =  ids.filter(item => item !== $(ele).attr('id'))
            }
        })
        if (ids.length > 0) {
            for (var i = 0; i < ids.length; i++) {
                var chooseData = $('#chooseGoodsList').jqGrid('getRowData', ids[i]);
                var dataInfo = JSON.parse(chooseData.acceptanceGoodInfos)
                var  chooseDataGoodsInfo = dataInfo.acceptanceGoodInfos
                for (let j = 0; j < chooseDataGoodsInfo.length; j++) {
                    var trStr = `<tr class="choosedGoodsTbody">
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;" trValue=${i} id=${ids[i]}></td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;" rowspanValue=${j == 0 ? chooseDataGoodsInfo.length : '' } >` + chooseDataGoodsInfo[j].acceptanceDate + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;display: none" >` + chooseDataGoodsInfo[j].enterpriseName + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseDataGoodsInfo[j].goodsName + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseDataGoodsInfo[j].goodsFactory + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseDataGoodsInfo[j].goodsType + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseDataGoodsInfo[j].goodsUnit + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + (Number(chooseDataGoodsInfo[j].goodsQuantity)).toFixed(4) + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + (chooseDataGoodsInfo[j].salesPrice != null ? (Number(chooseDataGoodsInfo[j].salesPrice)).toFixed(2) : '') + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;" class="amountInput">` + calcMoney((Number(chooseDataGoodsInfo[j].salesTotalPrice)).toFixed(2)) + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;" class="amountInput">` + calcMoney((Number(chooseDataGoodsInfo[j].salesGuaranteeMoney)).toFixed(2)) + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;" class="amountInput">` + calcMoney((Number(chooseDataGoodsInfo[j].purchasePrice)).toFixed(2)) + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;" class="amountInput">` + calcMoney((Number(chooseDataGoodsInfo[j].purchaseTotalPrice)).toFixed(2)) + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;" class="amountInput">` + calcMoney((Number(chooseDataGoodsInfo[j].purchaseGuaranteeMoney ? chooseDataGoodsInfo[j].purchaseGuaranteeMoney : '')).toFixed(2)) + `</td>
                        <td style="display: none">`+chooseDataGoodsInfo[j].id+`</td>
                        <td style="display: none">`+chooseDataGoodsInfo[j].acceptanceBasicInfoId+`</td>
                        <td style="display: none">`+chooseDataGoodsInfo[j].acceptanceGoodsInfoId+`</td>
                        <td style="display: none">`+chooseDataGoodsInfo[j].settlementBasicInfoId+`</td>

                    </tr>`
                    $(".choosedGoodsList").append(trStr);
                }

            }
        }

        $(".choosedGoodsTbody").each(function (i, ele) { 
            if (goodsFlag == 'goods') {
                var supplierTrClone = $(".goodsListTbody:first").clone();
                supplierTrClone.find('.negativeInformationReduce').show();
                supplierTrClone.find('.error').hide();
                supplierTrClone.find('input').val('');
                supplierTrClone.find('select').val('');
                supplierTrClone.find('td').eq(1).text($(ele).find('td').eq(1).text())
                supplierTrClone.find('td').eq(1).attr('id',$(ele).find('td').eq(14).text())
                supplierTrClone.find('td').eq(1).attr('acceptanceBasicInfoId', $(ele).find('td').eq(15).text())
                supplierTrClone.find('td').eq(1).attr('acceptanceGoodsInfoId', $(ele).find('td').eq(16).text())
                supplierTrClone.find('td').eq(1).attr('settlementBasicInfoId', $(ele).find('td').eq(17).text())
                supplierTrClone.find('td').eq(2).text($(ele).find('td').eq(2).text())
                supplierTrClone.find('td').eq(2).attr('monthlyinterestRate', $(ele).find('td').eq(18).text())
                supplierTrClone.find('td').eq(2).attr('accrualMarginCalcMethod', $(ele).find('td').eq(19).text())
                supplierTrClone.find('td').eq(2).attr('differAmount', $(ele).find('td').eq(20).text())
                supplierTrClone.find('td').eq(2).attr('factoringFinanceDeadline', $(ele).find('td').eq(21).text())
                supplierTrClone.find('td').eq(2).attr('salesRetentionPercent', $(ele).find('td').eq(11).text())
                supplierTrClone.find('td').eq(2).attr('purchRetentionPercent', $(ele).find('td').eq(12).text())
                supplierTrClone.find('td').eq(3).text($(ele).find('td').eq(3).text())
                supplierTrClone.find('td').eq(4).text($(ele).find('td').eq(4).text())
                supplierTrClone.find('td').eq(5).text($(ele).find('td').eq(5).text())
                supplierTrClone.find('td').eq(6).text($(ele).find('td').eq(6).text())
                supplierTrClone.find('td').eq(7).text($(ele).find('td').eq(7).text())
                supplierTrClone.find('td').eq(8).find('input').val($(ele).find('td').eq(8).text())//销售单价
                supplierTrClone.find('td').eq(9).find('input').val($(ele).find('td').eq(9).text())
                supplierTrClone.find('td').eq(10).find('input').val($(ele).find('td').eq(10).text())
                supplierTrClone.find('td').eq(11).find('input').val($(ele).find('td').eq(11).text())
                supplierTrClone.find('td').eq(12).find('input').val($(ele).find('td').eq(12).text())
                supplierTrClone.find('td').eq(13).find('input').val($(ele).find('td').eq(13).text())
                // 合并删除
                if( $(ele).find('td').eq(1).attr('rowspanValue')) {
                    supplierTrClone.find('td').eq(14).attr('rowspan', $(ele).find('td').eq(1).attr('rowspanValue'))
                }else {
                    supplierTrClone.find('td').eq(14).remove()
                }
                supplierTrClone.attr('trValue', $(ele).find('td').eq(0).attr('trValue'))
                supplierTrClone.attr('id', $(ele).find('td').eq(0).attr('id'))
                supplierTrClone.attr('acceptanceBasicInfoId', $(ele).find('td').eq(15).text())
                supplierTrClone.attr('goodsChooseType', goodsChooseType)
              /*   var oneSale = 0, num = 0, saleRetPct = 0, saleRet = 0, totalSale = 0;
                var onePurch = 0, num2 = 0, purchRetPct = 0, purchRet = 0, totalPurch = 0;
                //如果有销售单价
                if ($(ele).find('td').eq(8).text() !== '') {
                    oneSale = Number($(ele).find('td').eq(8).text().split(',').join(''))
                    num = Number($(ele).find('td').eq(7).text());
                    totalSale = Math.round((oneSale * num) * 100) / 100;
                    supplierTrClone.find('td').eq(9).find('input').val(commaDelimiter(totalSale))

                    //如果有销售质保金比例
                    if ($(ele).find('td').eq(11).text() !== '') {
                        saleRetPct = Number($(ele).find('td').eq(11).text())
                        saleRet = Math.round((oneSale * num * saleRetPct / 100) * 100) / 100;
                        supplierTrClone.find('td').eq(10).find('input').val(commaDelimiter(saleRet))
                    } else {
                        supplierTrClone.find('td').eq(10).find('input').val(0.00)
                    }
                } else {
                    supplierTrClone.find('td').eq(8).find('input').val(0.00)
                    supplierTrClone.find('td').eq(9).find('input').val(0.00)
                    supplierTrClone.find('td').eq(10).find('input').val(0.00)
                }
                //如果有采购单价
                if ($(ele).find('td').eq(13).text() !== '') {
                    supplierTrClone.find('td').eq(11).find('input').attr('readOnly', true)
                    onePurch = Number($(ele).find('td').eq(13).text().split(',').join(''))
                    num2 = Number($(ele).find('td').eq(7).text());
                    totalPurch = Math.round((onePurch * num2) * 100) / 100;
                    supplierTrClone.find('td').eq(12).find('input').val(commaDelimiter(totalPurch))

                    //如果有质保金比例
                    if ($(ele).find('td').eq(12).text() !== '') {
                        purchRetPct = Number($(ele).find('td').eq(12).text())
                        purchRet = Math.round((onePurch * num2 * purchRetPct / 100) * 100) / 100;
                        supplierTrClone.find('td').eq(13).find('input').val(commaDelimiter(purchRet))
                    } else {
                        supplierTrClone.find('td').eq(13).find('input').val(0.00)
                    }
                } else {
                    supplierTrClone.find('td').eq(11).find('input').val(0.00)
                    supplierTrClone.find('td').eq(12).find('input').val(0.00)
                    supplierTrClone.find('td').eq(13).find('input').val(0.00)
                }

                if ($(ele).find('td').eq(17).text() == 'true') { //做过结算
                    supplierTrClone.find('td').eq(8).find('input').attr('readOnly', true)
                } */

                supplierTrClone.show();

                $('.goodsListTable').append(supplierTrClone);

                sortIGoodsnfo();

                //底层信息
               /*  var account = 0;
                if (purchRetPct) {
                    account = Math.round((totalPurch - purchRet) * 100) / 100;
                }
                var underTr = `<tr class="underlyingList">
                                   <td style="background-color: #fff"><span></span></td>
                                   <td style="background-color: #fff">` + $(ele).find('td').eq(3).text() + `</td>
                                   <td style="background-color: #fff">` + $(ele).find('td').eq(4).text() + `</td>
                                   <td style="background-color: #fff">` + $(ele).find('td').eq(5).text() + `</td>
                                   <td style="background-color: #fff">` + $(ele).find('td').eq(6).text() + `</td>
                                   <td style="background-color: #fff">` + $(ele).find('td').eq(7).text() + `</td>

                                   <td style="background-color: #fff">` + (commaDelimiter(totalPurch)) + `</td>
                                   <td style="background-color: #fff">` + (commaDelimiter(account)) + `</td>

                                   <td class="enter"><input type="text" class="form-control accountStart" readonly value="`+$(ele).find('td').eq(14).text()+`"></td>
                                   <td style="background-color: #fff">` + $(ele).find('td').eq(15).text() + `</td>
                                   <td style="background-color: #fff">` + $(ele).find('td').eq(16).text() + `</td>
                                   <td style="display: none">` + $(ele).find('td').eq(10).text() + `</td>
                               </tr>`

                $(".underlyingTbody").append(underTr)
                sortReceiptInfo(); */
            }

        })
        $("#myModal-chooseGoods").modal("hide");

        //底层日期初始化
        $('.underlyingList').each(function (i, ele) {
            setDate($(ele).find('td').eq(8).find('input'),'1970-01-01','2116-12-31');
        })
    })

    $(".chooseSure2").click(function () {
        var ids = $('#chooseGoodsList2').jqGrid('getGridParam', 'selarrrow');
        $('.goodsListTbody').each(function ( i, ele) {
            if($(ele).attr('id')){
                ids =  ids.filter(item => item !== $(ele).attr('id'))
            }
        })

        if (ids.length > 0) {
            for (var i = 0; i < ids.length; i++) {
                var chooseData = $('#chooseGoodsList2').jqGrid('getRowData', ids[i]);
                var dataInfo = JSON.parse(chooseData.settlementGoodsInfos)
                var  chooseDataGoodsInfo = dataInfo.settlementGoodsInfos
                for (let j = 0; j < chooseDataGoodsInfo.length; j++) {
                    var trStr = `<tr class="choosedGoodsTbody2">
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;" trValue=${i} id=${ids[i]}></td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;" rowspanValue=${j == 0 ? chooseDataGoodsInfo.length : '' } >` + chooseDataGoodsInfo[j].acceptanceDate + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;display: none" >` + chooseDataGoodsInfo[j].enterpriseName + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseDataGoodsInfo[j].goodsName + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseDataGoodsInfo[j].goodsFactory + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseDataGoodsInfo[j].goodsType + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + chooseDataGoodsInfo[j].goodsUnit + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + (Number(chooseDataGoodsInfo[j].goodsQuantity)).toFixed(4) + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + (chooseDataGoodsInfo[j].salesPrice ? (Number(chooseDataGoodsInfo[j].salesPrice)).toFixed(2) : '') + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + calcMoney((Number(chooseDataGoodsInfo[j].salesTotalPrice)).toFixed(2)) + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + calcMoney((Number(chooseDataGoodsInfo[j].salesGuaranteeMoney)).toFixed(2)) + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + calcMoney((Number(chooseDataGoodsInfo[j].purchasePrice)).toFixed(2)) + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + calcMoney((Number(chooseDataGoodsInfo[j].purchaseTotalPrice)).toFixed(2)) + `</td>
                        <td  style="background-color:#fff;border-bottom: 1px solid #E8F0F3;">` + calcMoney((Number(chooseDataGoodsInfo[j].purchaseGuaranteeMoney)).toFixed(2)) + `</td>
                        <td style="display: none">`+chooseDataGoodsInfo[j].id+`</td>
                        <td style="display: none">`+chooseDataGoodsInfo[j].acceptanceBasicInfoId+`</td>
                        <td style="display: none">`+chooseDataGoodsInfo[j].acceptanceGoodsInfoId+`</td>
                        <td style="display: none">`+chooseDataGoodsInfo[j].settlementBasicInfoId+`</td>
                    </tr>`
                    $(".choosedGoodsList2").append(trStr);
                }
            }
        }

        $(".choosedGoodsTbody2").each(function (i, ele) {
            if (goodsFlag == 'goods') {
                var supplierTrClone = $(".goodsListTbody:first").clone();
                supplierTrClone.find('.negativeInformationReduce').show();
                supplierTrClone.find('.error').hide();
                supplierTrClone.find('input').val('');
                supplierTrClone.find('select').val('');
                supplierTrClone.find('td').eq(1).text($(ele).find('td').eq(1).text())
                supplierTrClone.find('td').eq(1).attr('id',$(ele).find('td').eq(14).text())
                supplierTrClone.find('td').eq(1).attr('acceptanceBasicInfoId', $(ele).find('td').eq(15).text())
                supplierTrClone.find('td').eq(1).attr('acceptanceGoodsInfoId', $(ele).find('td').eq(16).text())
                supplierTrClone.find('td').eq(1).attr('settlementBasicInfoId', $(ele).find('td').eq(17).text())
                supplierTrClone.find('td').eq(2).text($(ele).find('td').eq(2).text())
                supplierTrClone.find('td').eq(2).attr('monthlyinterestRate', $(ele).find('td').eq(18).text())
                supplierTrClone.find('td').eq(2).attr('accrualMarginCalcMethod', $(ele).find('td').eq(19).text())
                supplierTrClone.find('td').eq(2).attr('differAmount', $(ele).find('td').eq(20).text())
                supplierTrClone.find('td').eq(2).attr('factoringFinanceDeadline', $(ele).find('td').eq(21).text())
                supplierTrClone.find('td').eq(2).attr('salesRetentionPercent', $(ele).find('td').eq(11).text())
                supplierTrClone.find('td').eq(2).attr('purchRetentionPercent', $(ele).find('td').eq(12).text())
                supplierTrClone.find('td').eq(3).text($(ele).find('td').eq(3).text())
                supplierTrClone.find('td').eq(4).text($(ele).find('td').eq(4).text())
                supplierTrClone.find('td').eq(5).text($(ele).find('td').eq(5).text())
                supplierTrClone.find('td').eq(6).text($(ele).find('td').eq(6).text())
                supplierTrClone.find('td').eq(7).text($(ele).find('td').eq(7).text())
                supplierTrClone.find('td').eq(8).find('input').attr('readonly', true)
                supplierTrClone.find('td').eq(8).find('input').val($(ele).find('td').eq(8).text())//销售单价
                supplierTrClone.find('td').eq(9).find('input').val( $(ele).find('td').eq(9).text())//销售单价
                supplierTrClone.find('td').eq(10).find('input').val($(ele).find('td').eq(10).text())
                supplierTrClone.find('td').eq(11).find('input').val($(ele).find('td').eq(11).text())
                supplierTrClone.find('td').eq(12).find('input').val($(ele).find('td').eq(12).text())
                supplierTrClone.find('td').eq(13).find('input').val($(ele).find('td').eq(13).text())
                // 合并删除
                if( $(ele).find('td').eq(1).attr('rowspanValue')) {
                    supplierTrClone.find('td').eq(14).attr('rowspan', $(ele).find('td').eq(1).attr('rowspanValue'))
                }else {
                    supplierTrClone.find('td').eq(14).remove()
                }
                supplierTrClone.attr('trValue', $(ele).find('td').eq(0).attr('trValue'))
                supplierTrClone.attr('id', $(ele).find('td').eq(0).attr('id'))
                supplierTrClone.attr('acceptanceBasicInfoId',  $(ele).find('td').eq(15).text())
                supplierTrClone.attr('goodsChooseType', goodsChooseType)
                supplierTrClone.show();
                $('.goodsListTable').append(supplierTrClone);
                sortIGoodsnfo();
            }

        })
        $("#myModal-chooseGoods2").modal("hide");

        //底层日期初始化
        $('.underlyingList').each(function (i, ele) {
            setDate($(ele).find('td').eq(8).find('input'),'1970-01-01','2116-12-31');
        })
    })

    //底层日期初始化
    $('.underlyingList').each(function (i, ele) {
        setDate($(ele).find('td').eq(8).find('input'),'1970-01-01','2116-12-31');
    })

    //底层日期变化
    $('.underlyingTbody').on('change', '.accountStart', function () {
        var accountPeriod = Number($(this).parent().next().text());
        var startTime = new Date($(this).val()).getTime();
        var endTime = getStandardDate(new Date(startTime + accountPeriod*24*60*60*1000));
        $(this).parent().parent().find('td').eq(10).text(endTime)

    })

    //销售单价输入
    /* $('.goodsTable').on('keyup', '.salesPrice', function () {
        var oneSale = Number($(this).val().split(',').join(''))
        var num = Number($(this).parent().parent().find('td').eq(7).text());
        var totalSale = Math.round((oneSale * num) * 100) / 100;
        $(this).parent().siblings().find('.totalsalesPrice').val(commaDelimiter(totalSale));

        //如果有质保金比例
        if ($(this).parent().siblings().eq(2).attr('salesRetentionPercent')) {
            var saleRetPct = Number($(this).parent().siblings().eq(2).attr('salesRetentionPercent'))
            var saleRet = Math.round((oneSale * num * saleRetPct / 100) * 100) / 100;
            $(this).parent().siblings().find('.salesGuaranteeMoney').val(commaDelimiter(saleRet));


        }

        //计算采购单价--根据利差计算规则
        var purchSale=0;
        if($(this).parent().siblings().eq(2).attr('accrualMarginCalcMethod') !== '' && $(this).parent().siblings().eq(2).attr('accrualMarginCalcMethod') !== undefined) {
            var accrualMarginCalcMethod = $(this).parent().siblings().eq(2).attr('accrualMarginCalcMethod');
            if(accrualMarginCalcMethod == '固定利率') {   //采购单价=销售单价-销售单价*(月利率)*（预估保理融资期限/30
                if($(this).parent().siblings().eq(2).attr('monthlyinterestRate') !== '' && $(this).parent().siblings().eq(2).attr('monthlyinterestRate') !== undefined) {
                    var monthlyinterestRate = Number($(this).parent().siblings().eq(2).attr('monthlyinterestRate'));
                    var factoringFinanceDeadline = Number($(this).parent().siblings().eq(2).attr('factoringFinanceDeadline'));
                    purchSale = Math.round((oneSale - oneSale *  monthlyinterestRate/100 * factoringFinanceDeadline/30)*100)/100
                }
            }else if(accrualMarginCalcMethod == '固定差额') {    //采购单价=销售单价-差额
                if($(this).parent().siblings().eq(2).attr('differAmount') !== '' && $(this).parent().siblings().eq(2).attr('differAmount') !== undefined) {
                    var differAmount = Number($(this).parent().siblings().eq(2).attr('differAmount'));
                    purchSale = Math.round((oneSale - differAmount)*100)/100
                }
            }

        }
        $(this).parent().siblings().find('.purchasePrice').val(commaDelimiter(purchSale));
        var totalPurch = Math.round((purchSale * num) * 100) / 100;
        $(this).parent().siblings().find('.totalPurchasePrice').val(commaDelimiter(totalPurch));
        //如果有质保金比例
        if ($(this).parent().siblings().eq(2).attr('purchRetentionPercent')) {
            var purchRetPct = Number($(this).parent().siblings().eq(2).attr('purchRetentionPercent'))
            var purchRet = Math.round((purchSale * num * purchRetPct / 100) * 100) / 100;
            $(this).parent().siblings().find('.purchaseGuaranteeMoney').val(commaDelimiter(purchRet));
        }

        //底层
        var index = $('.goodsListTbody').index($(this).parent().parent())
        $('.underlyingList').eq(index - 1).find('td').eq(6).text(commaDelimiter(totalPurch))
        var accountAmount=0;
        if(purchRetPct) {
            accountAmount = Math.round((purchSale * num * (1 - (purchRetPct / 100))) * 100) / 100;
        }else {
            accountAmount = totalPurch;
        }

        $('.underlyingList').eq(index - 1).find('td').eq(7).text(commaDelimiter(accountAmount))

        sortIGoodsnfo();
    }) */
    //采购单价输入
    // $('.goodsTable').on('keyup', '.purchasePrice', function () {
    //     var oneSale = Number($(this).val().split(',').join(''))
    //     var num = Number($(this).parent().parent().find('td').eq(7).text());
    //     var totalSale = Math.round((oneSale * num) * 100) / 100;
    //     $(this).parent().siblings().find('.totalPurchasePrice').val(commaDelimiter(totalSale));
    //
    //     //如果有质保金比例
    //     if ($(this).parent().siblings().eq(2).attr('purchRetentionPercent')) {
    //         var saleRetPct = Number($(this).parent().siblings().eq(2).attr('purchRetentionPercent'))
    //         var saleRet = Math.round((oneSale * num * saleRetPct / 100) * 100) / 100;
    //         $(this).parent().siblings().find('.purchaseGuaranteeMoney').val(commaDelimiter(saleRet));
    //     }
    // })
    function getBottomInfo(params) {
        var postdata = new FormData();
          //货物信息
        for(var i=1;i<$(".goodsListTbody").length;i++) {
            if(goodsChooseType === 'check') {
                postdata.append('underlyingGoodsInfoList['+(i-1)+'].acceptanceGoodsInfoId',$(".goodsListTbody").eq(i).find('td').eq(1).attr('id'));
            }else {
                postdata.append('underlyingGoodsInfoList['+(i-1)+'].acceptanceGoodsInfoId',$(".goodsListTbody").eq(i).find('td').eq(1).attr('acceptanceGoodsInfoId'));
            }
            let purchaseTotalPrice = $(".goodsListTbody").eq(i).find('td').eq(12).find('input').val()

            let purchaseGuaranteeMoney = $(".goodsListTbody").eq(i).find('td').eq(13).find('input').val()
            postdata.append('underlyingGoodsInfoList['+(i-1)+'].purchaseTotalPrice',purchaseTotalPrice.split(',').join(''));
            postdata.append('underlyingGoodsInfoList['+(i-1)+'].purchaseGuaranteeMoney',purchaseGuaranteeMoney.split(',').join(''));
        }
        i=null;
        $.ajax({
            url: '/underlying/doGenerateAccountsReceivable',
            type:'post',
            data:postdata,
            processData:false,
            contentType:false,
            success:function(data){
                if( data.success ){
                    const goodsInfo = data.data
                    $(".underlyingTbody").empty()
                    for (let i = 0; i < goodsInfo.length; i++) {
                        var underTr = `<tr class="underlyingList" id=${goodsInfo[i].acceptanceBasicInfoId} acceptanceGoodsInfoId=${goodsInfo[i].acceptanceGoodsInfoId}>
                            <td style="background-color: #fff"><span></span></td>
                            <td style="background-color: #fff">` + goodsInfo[i].goodsName + `</td>
                            <td style="background-color: #fff">` + goodsInfo[i].goodsFactory + `</td>
                            <td style="background-color: #fff">` + goodsInfo[i].goodsType + `</td>
                            <td style="background-color: #fff">` + goodsInfo[i].goodsUnit + `</td>
                            <td style="background-color: #fff">` + (Number(goodsInfo[i].goodsQuantity)).toFixed(4) + `</td>
                            <td style="background-color: #fff">` + ( goodsInfo[i].accountsReceivableAmount == null ? '/' : commaDelimiter((Number(goodsInfo[i].accountsReceivableAmount)).toFixed(2))) + `</td>
                            <td style="background-color: #fff">` + ( goodsInfo[i].netAccountsReceivableAmount == null ? '/' : commaDelimiter((Number(goodsInfo[i].netAccountsReceivableAmount)).toFixed(2))) + `</td>
                        </tr>`
                        $(".underlyingTbody").append(underTr)
                    }
                    sortReceiptInfo();
                }else{
                    new $.zui.Messager('生成底层信息失败:'+data.msg, {
                        type: 'danger'
                    }).show();
                }
            },
            error:function(status){
                new $.zui.Messager('生成底层信息发生错误:'+status, {
                    type: 'danger'
                }).show();
            }
        });
    }

    //  一键计算质保金
    $('.calcMoney').on('click', function() {
        var postdata = new FormData();
        postdata.append('supplierId', $('[name=supplierName]').val())
        postdata.append('businessNumber', $('[name=businessNo]').val())

        if(!$(".goodsListTbody").length) {
            new $.zui.Messager('请选择货物', {
                type: 'danger'
            }).show();
            return
        }

        //货物信息
        for(var i=1;i<$(".goodsListTbody").length;i++) {
            if(!$(".goodsListTbody").eq(i).find('td').eq(8).find('input').val().split(',').join('')) {
                new $.zui.Messager('请输入销售单价', {
                    type: 'danger'
                }).show();
                return
            }
            postdata.append('goodsInfoList['+(i-1)+'].id',$(".goodsListTbody").eq(i).find('td').eq(1).attr('id'));
            postdata.append('goodsInfoList['+(i-1)+'].acceptanceBasicInfoId',$(".goodsListTbody").eq(i).find('td').eq(1).attr('acceptanceBasicInfoId'));
            if( goodsChooseType == 'settlement') {
                postdata.append('goodsInfoList['+(i-1)+'].settlementBasicInfoId',$(".goodsListTbody").eq(i).find('td').eq(1).attr('settlementBasicInfoId'));
            }else {
                postdata.append('goodsInfoList['+(i-1)+'].settlementBasicInfoId', '');
            }
            postdata.append('goodsInfoList['+(i-1)+'].acceptanceDate',$(".goodsListTbody").eq(i).find('td').eq(1).text());
            postdata.append('goodsInfoList['+(i-1)+'].goodsName',$(".goodsListTbody").eq(i).find('td').eq(3).text());
            postdata.append('goodsInfoList['+(i-1)+'].goodsFactory',$(".goodsListTbody").eq(i).find('td').eq(4).text());
            postdata.append('goodsInfoList['+(i-1)+'].goodsType',$(".goodsListTbody").eq(i).find('td').eq(5).text());
            postdata.append('goodsInfoList['+(i-1)+'].goodsUnit',$(".goodsListTbody").eq(i).find('td').eq(6).text());
            postdata.append('goodsInfoList['+(i-1)+'].goodsQuantity',$(".goodsListTbody").eq(i).find('td').eq(7).text());
            postdata.append('goodsInfoList['+(i-1)+'].salesPrice',$(".goodsListTbody").eq(i).find('td').eq(8).find('input').val().split(',').join(''));
            postdata.append('goodsInfoList[' + (i - 1) + '].salesTotalPrice', $(".goodsListTbody").eq(i).find('td').eq(9).find('input').val().split(',').join(''));
            postdata.append('goodsInfoList[' + (i - 1) + '].salesGuaranteeMoney', $(".goodsListTbody").eq(i).find('td').eq(10).find('input').val().split(',').join(''));
            postdata.append('goodsInfoList[' + (i - 1) + '].purchasePrice', $(".goodsListTbody").eq(i).find('td').eq(11).find('input').val().split(',').join(''));
            postdata.append('goodsInfoList[' + (i - 1) + '].purchaseTotalPrice', $(".goodsListTbody").eq(i).find('td').eq(12).find('input').val().split(',').join(''));
            postdata.append('goodsInfoList[' + (i - 1) + '].purchGuaranteeMoney', $(".goodsListTbody").eq(i).find('td').eq(13).find('input').val().split(',').join(''));
        }
        i=null;
        $.ajax({
            url: '/underlying/doCalculate',
            type:'post',
            data:postdata,
            processData:false,
            contentType:false,
            success:function(data){
                if( data.success ){
                    const goodsInfo = data.data
                    for (let i = 0; i < goodsInfo.length; i++) {
                        $(".goodsListTbody").eq(i + 1).find('td').eq(9).find('input').val(goodsInfo[i].salesTotalPrice != null ? commaDelimiter((Number(goodsInfo[i].salesTotalPrice)).toFixed(2)): '')
                        $(".goodsListTbody").eq(i + 1).find('td').eq(10).find('input').val(goodsInfo[i].salesGuaranteeMoney != null ? commaDelimiter((Number(goodsInfo[i].salesGuaranteeMoney)).toFixed(2)) : '')
                        $(".goodsListTbody").eq(i + 1).find('td').eq(11).find('input').val(goodsInfo[i].purchasePrice != null ? commaDelimiter((Number(goodsInfo[i].purchasePrice)).toFixed(2)) : '')
                        $(".goodsListTbody").eq(i + 1).find('td').eq(12).find('input').val(goodsInfo[i].purchaseTotalPrice != null ? commaDelimiter((Number(goodsInfo[i].purchaseTotalPrice)).toFixed(2)): '')
                        $(".goodsListTbody").eq(i + 1).find('td').eq(13).find('input').val( goodsInfo[i].purchaseGuaranteeMoney != null ? commaDelimiter((Number(goodsInfo[i].purchaseGuaranteeMoney)).toFixed(2)) : '')
                    }
                    sortIGoodsnfo()
                    getBottomInfo()
                }else{
                    new $.zui.Messager('计算质保金失败:'+data.msg, {
                        type: 'danger'
                    }).show();
                }
            },
            error:function(status){
                new $.zui.Messager('计算质保金发生错误:'+status, {
                    type: 'danger'
                }).show();
            }
        });
    })

    $('.goodsTable').on('blur', '.salePrice', function () {
        $('.calcMoney').click()
    })
})

function getContractInfo() {
    if($("[name=supplierName]").val() && $("[name=businessNo]").val()) {
        $.ajax({
            url:'/underlying/findByBusinessNumberAndSupplierId',
            type:'get',
            async:false,
            data: {
                'supplierId':  $("[name=supplierName]").val(),
                'businessNumber': $("[name=businessNo]").val()
            },
            success:function(data){
               console.log(data)
               $('[name=contractName]').val(data.contractName)
               $('[name=contractNumber]').val(data.contractNumber)
               $('[name=contractAmount]').val(data.contractPlanAmount)
            },
            error:function(status){
                console.log(status, '获取核心企业名称失败')
            }
        });
    }
}

function getAccountInfo(params) {
    if( $("[name=businessNo]").val()) {
        $.ajax({
            url:'/underlying/findAccountsReceivableByBusinessNumber',
            type:'get',
            async:false,
            data: {
                'businessNumber': $("[name=businessNo]").val()
            },
            success:function(data){
               console.log(data.accountsReceivableEndDate)
               $('[name=accountsReceivableStartDate]').val(data.accountsReceivableStartDate)
               $('[name=accountReceivablePeriod]').val(data.accountReceivablePeriod)
               $('[name=accountsReceivableEndDate]').val(data.accountsReceivableEndDate)
            },
            error:function(status){
                console.log(status, '获取核心企业名称失败')
            }
        });
    }
}


$("[name=supplierName]").on('change', function(e) {
    getContractInfo()
    var postdata = new FormData();
    $("[name=enterpriseName]").val('')
    $("[name=enterpriseName]").children().remove()
    $("[name=businessName]").val('')
    $('.entCustomerListBox .companyli').empty()
    $("[name=businessName]").children().remove()
    $("[name=businessNo]").val('')
    $("[name=platformName]").val('')
    $("[name=tradingPlatformId]").val('')
    $("[name=contractName]").val('')
    $("[name=contractNumber]").val('')
    $("[name=contractAmount]").val('')
    postdata.append('supplierId', $("[name=supplierName]").val())
    $.ajax({
        url:'/customer/getLocalUserCustomers',
        type:'post',
        data:postdata,
        processData:false,
        contentType:false,
        success:function(data){
            var str = ''
            var list = data.data
            for (var i = 0; i < list.length; i++) {
                str += `<option value ="${list[i].id}">${list[i].enterpriseName}</option>`
            }
            $("[name=enterpriseName]").append(str)
            $("[name=businessNo]").val('')
        },
        error:function(status){
            console.log(status, '获取核心企业名称失败')
        }
    });
})

let businessNameDataList = []
//获取业务名称
$("[name=enterpriseName]").on('change', function(e) {
    if(!$("[name=enterpriseName]").val()) {
        return
    }
    $("[name=businessName]").val('')
    $("[name=businessName]").children().remove()
    $("[name=businessNo]").val('')
    $("[name=tradingPlatformId]").val('')
    $("[name=platformName]").val('')
    $("[name=contractName]").val('')
    $("[name=contractNumber]").val('')
    $("[name=contractAmount]").val('')
    var postdata = new FormData();
    postdata.append('supplierId', $("[name=supplierName]").val())
    postdata.append('customerId', $("[name=enterpriseName]").val())
    $.ajax({
        url: '/business/management/getLocalUserBusinessListByAcceptance',
        type: 'post',
        data: postdata,
        processData: false,
        contentType: false,
        success: function(data){
            var businessNameStr = ''
            var list = data.data
            businessNameDataList = data.data
            $('.allBusinessName').empty()
            for (var i = 0; i < list.length; i++) {                $('.allBusinessName').append('<li class="companyli" value="' + list[i].businessNumber + '" businessNameId="' + list[i].businessNumber + '">' + list[i].businessName + '</li>')
            }
            withSearchDropDownBox({
                allOptionSelector: '.allBusinessName li',//所有的选项的选择器
                triggerSelector: '#businessName',//触发选择(显示下拉框)的表单的选择器(存放选择的name)
                resultIdSelector: '#businessNameId',//表单元素选择器(存放选择的id)
                dropdownSelector: '.busListBox',//下拉框的选择器
                searchBtn:'.searchBus',
                isCallback: true,
                callback: function () {
                    setTimeout(() => {
                        $('[name=businessName]').change()
                    },100)
                }
            });
        },       
        error: function(status){
            console.log(status, '获取业务名称失败')
        }
    });
})

// 获取业务编号/合同名称(采购)/合同编号(采购)/合同金额
$("[name=businessName]").on('change', function(e) {
    if($('#businessNameId').val()){
        const businessNameSelectData =  businessNameDataList.find(item => item.businessNumber == $('#businessNameId').val() ) 
        $("[name=businessNo]").val(businessNameSelectData.businessNumber)
        $("[name=contractName]").val(businessNameSelectData.purchContractBasicInfo.contractName)
        $("[name=contractNumber]").val(businessNameSelectData.purchContractBasicInfo.contractNumber)
        $("[name=contractAmount]").val(businessNameSelectData.purchContractBasicInfo.contractPlanAmount)
    }else {
        $("[name=businessNo]").val('')
        $("[name=platformName]").val('')
        $("[name=tradingPlatformId]").val('')
        $("[name=contractName]").val('')
        $("[name=contractNumber]").val('')
        $("[name=contractAmount]").val('')
    }
})

// 获取业务编号
// $("[name=enterpriseName]").on('change', function(e) {
//     if(!$("[name=enterpriseName]").val()) {
//         return
//     }
//     $("[name=businessNo]").val('')
//     $("[name=businessNo]").children().remove()
//     $("[name=platform]").val('')
//     var postdata = new FormData();
//     postdata.append('supplierId', $("[name=supplierName]").val())
//     postdata.append('customerId', $("[name=enterpriseName]").val())
//     $.ajax({
//         url: '/business/management/getLocalUserBusinessListByAcceptance',
//         type: 'post',
//         data: postdata,
//         processData: false,
//         contentType: false,
//         success: function(data){
//             var str = ''
//             var list = data.data
//             for (var i = 0; i < list.length; i++) {
//                 str += `<option value ="${list[i].businessNumber}">${list[i].businessNumber}</option>`
//             }
//             $("[name=businessNo]").append(str)
//         },
//         error: function(status){
//             console.log(status, '获取核心企业名称失败')
//         }
//     });
// })

// 获取贸易平台
$("[name=businessName]").on('change', function(e) {
    getContractInfo()
    getAccountInfo()
    if(!$("[name=businessName]").val()) {
        return
    }
    $("[name=platformName]").val('')
    $("[name=tradingPlatformId]").val('')
    var postdata = new FormData();
    postdata.append('businessNumber', $("[name=businessNo]").val())
    $.ajax({
        url: '/platform/getPlateformByBusiness',
        type: 'post',
        data: postdata,
        processData: false,
        contentType: false,
        success: function(data){
            $("[name=platformName]").val(data.data.platformName)
            $("[name=tradingPlatformId]").val(data.data.id)
        },
        error: function(status){
            console.log(status, '获取核心企业名称失败')
        }
    });
})

$('.yk_addNewMsg .getBottomInfo').click(function (event) {
    event.preventDefault();
})
