var release = {
    saveOrUpdate: function (callback) {
        if (tenderComm.submitFlag == 1) {
            return;
        }
        if (!$('#tender').form("validate")) {
            $("#tbb").tabs("select", '基础信息');
            return;
        }
        const postData = tenderComm.getFormData();
        if (postData['round'].startDay != undefined && postData['round'].endDay != undefined) {
            // 将字符串解析为moment对象
            let moment1 = moment(postData['round'].startDay, "YYYY-MM-DD HH:mm");
            let moment2 = moment(postData['round'].endDay, "YYYY-MM-DD HH:mm");

            if (moment1.isAfter(moment2)) {
                topWin.layer.msg("投标开始时间不能在投标截止时间之后!")
                return;
            }
        }

        if (postData.tenderAttachmentList.length <= 0) {
            layer.alert("请添加附件!", {icon: 2});
            $('#tbb').tabs('select', '招标文件');
            return;
        }
        if (postData.tenderDetails.length <= 0) {
            layer.alert("请添加招标项目!", {icon: 2});
            $('#tbb').tabs('select', '招标项目');
            return;
        } else {
            var msg = [];
            for (var i = 0; i < postData.tenderDetails.length; i++) {
                var row = postData.tenderDetails[i];
                for (var prop in row) {
                    if (tenderComm.detailRequired[prop] != undefined) {
                        if (row[prop] == undefined || row[prop] === '') {
                            $('#tbb').tabs('select', '招标项目');
                            layer.alert("招标行项目:" + (i + 1) + "行，<span style='color: red;'>" + tenderComm.detailRequired[prop] + "</span>不能为空!", {icon: 2});
                            return;
                        }
                    }
                }
            }
            if (msg.length > 0) {
                layer.alert(msg.join("</br>"), {icon: 2});
                return;
            }
        }
        var supplier = postData.bidSupplierDtos;
        if (supplier.length <= 0) {
            layer.alert("请添加供应商", {icon: 2});
            $('#tbb').tabs('select', '供应商清单');
            return;
        }
        const requiredColumns = ['purchaseCategoryCode'];
        const missingColumns = requiredColumns.filter(col =>
            !postData.bidSupplierDtos.some(row => row.hasOwnProperty(col))
        );

        if (missingColumns.length > 0) {
            $('#tbb').tabs('select', '供应商清单');
            topWin.layer.msg("供应商信息：<span style='color: red;'>" + "采购品类编码必须选择" + "</span>", {icon: 2});
            return;
        }



        for (var i = 0; i < postData.bidSupplierDtos.length; i++) {
            var row = postData.bidSupplierDtos[i];
            for (var prop in row) {
                debugger;
                console.log(prop);
                if(prop == "purchaseCategoryCode"){
                    if (row[prop] == undefined || row[prop] === '') {
                        $('#tbb').tabs('select', '供应商清单');
                        topWin.layer.msg("供应商信息:" + (i + 1) + "行，<span style='color: red;'>" + "采购品类编码" + "</span>不能为空!", {icon: 2});
                        return;
                    }
                }

            }
        }





        var openUsers = postData.userRelations;
        if (openUsers.length <= 0) {
            layer.alert("请添加开标小组", {icon: 2});
            $('#tbb').tabs('select', '开标小组');
            return;
        }
        tenderComm.submitFlag = 1;
        var index = layer.load(0, {
            shade: [0.6, '#eee'] //0.1透明度的白色背景
        });
        debugger;
        $.ajax({
            url: g.ctx + 'pc/tender/rest/saveOrUpdate',
            type: "POST",
            contentType: 'application/json',
            data: JSON.stringify(postData),
            complete: function () {
                tenderComm.submitFlag = 0;
                layer.close(index);
            },
            success: function (d) {
                callback();
            },
            error: function (data) {
                topWin.layer.alert(data.responseJSON.message, {icon: 2});
            }
        });
    }
}
$(function () {
    if (id != 0) {
        if (type !== 0) {
            tenderComm.editFristTime = true
        }
        tenderComm.eventBind();
        tenderComm.loadData(id);
    } else {
        tenderComm.eventBind();
        tenderComm.initItemDataGrid();
        tenderComm.typeIdChange();
        tenderComm.initSupplierDataGrid([], 0);
        tenderComm.initOpenBidUserDatagird([]);
        tenderComm.initAttanchmentDatagrid([]);
        $("input[name='securityDeposit.securityDepositFlag'][value='0']").click();
    }
});