/** * 跨城站点管理管理初始化 */ var TSite = { id: "TSiteTable", //表格id seItem: null, //选中的条目 table: null, layerIndex: -1, picture:"", fileUrl:"", img:"", plan:"", goodsPicArray:[], validateFields: { } }; var objectType =$("#objectType").val() /** * 初始化表格的列 */ TSite.initColumn = function () { return [ {field: 'selectItem', checkbox: true}, {title: '序号', field: 'id', visible: true, align: 'center', valign: 'middle'}, { title: '所属运营商', field: 'operator', visible: objectType==3?false:true, align: 'center', valign: 'middle', }, { title: '省', field: 'province', visible: objectType === 1 ? true : false, align: 'center', valign: 'middle', width: '20%', }, { title: '市', field: 'city', visible: objectType === 1 ? true : false, align: 'center', valign: 'middle', }, {title: '门店名称', field: 'storeName', visible: true, align: 'center', valign: 'middle'}, {title: '场地类型', field: 'siteTypeName', visible: true, align: 'center', valign: 'middle'}, {title: '场地名称', field: 'name', visible: true, align: 'center', valign: 'middle'}, {title: '场地责任险有效期', field: 'insuranceEndTime', visible: true, align: 'center', valign: 'middle'}, { title: '状态', field: 'state', visible: true, align: 'center', valign: 'middle', formatter: function(data) { return {1: '上架中', 2: '下架中'}[data]; } } ]; }; /** * 检查是否选中 */ TSite.check = function () { var selected = $('#' + this.id).bootstrapTable('getSelections'); if(selected.length == 0){ Feng.info("请先选中表格中的某一记录!"); return false; }else{ TSite.seItem = selected[0]; return true; } }; /** * 上架 */ TSite.onShelf = function () { if (this.check()){ var selected = $('#' + this.id).bootstrapTable('getSelections'); const data1 = { siteIds:[], type:null }; selected.forEach(function(obj) { var id = obj.id; data1.siteIds.push(id); }); data1.type = 1; $.ajax({ url: Feng.ctxPath + "/tSite/changeState", type: "POST", contentType: "application/json", // 设置请求头的 Content-Type data: JSON.stringify(data1), // 将数据转换为 JSON 字符串 success: function(response) { Feng.success("上架成功!"); TSite.search(); }, error: function(xhr, status, error) { var errorMessage = xhr.responseText ? xhr.responseText : "上架失败!"; Feng.error("您的网络异常!"); } }); } }; /** * 下架 */ TSite.offShelf = function () { if (this.check()){ var selected = $('#' + this.id).bootstrapTable('getSelections'); const data1 = { siteIds:[], type:null }; selected.forEach(function(obj) { var id = obj.id; data1.siteIds.push(id); }); data1.type = 2; $.ajax({ url: Feng.ctxPath + "/tSite/changeState", type: "POST", contentType: "application/json", // 设置请求头的 Content-Type data: JSON.stringify(data1), // 将数据转换为 JSON 字符串 success: function(response) { Feng.success("下架成功!"); TSite.search(); }, error: function(xhr, status, error) { var errorMessage = xhr.responseText ? xhr.responseText : "下架失败!"; Feng.error("您的网络异常!"); } }); } }; TSite.uploadFile = function(){ var elementById = document.getElementById("uploadFile"); var file = elementById.files[0]; var formData = new FormData(); formData.append('file',file); $.ajax({ url: Feng.ctxPath + "/tCouponManage/uploadPic" , type: "POST", data: formData, contentType: false, // 设置为false,让浏览器自动识别并设置请求头 processData: false, // 设置为false,不处理发送的数据(因为FormData对象已经包含了文件数据) success: function (response) { TSite.fileUrl = response; console.log(TSite.fileUrl); Feng.success("文件上传成功"); }, error: function (xhr, status, error) { Feng.error("文件上传失败!" + error); } }); }; TSite.getChange = function(e){ var oneId=$(e).val(); var selectedValue = e.value; var citySelect = document.getElementById("cCode"); var ajax = new $ax(Feng.ctxPath + "/tSite/getChange", function(data){ if(data!=null){ var content=''; $.each(data, function(k,v) { content += ""; }); $("#cCode").empty().append(content); } }); if (selectedValue === ""){ citySelect.innerHTML = ''; } ajax.set("province",oneId); ajax.start(); }; TSite.oneChangeYys = function(e){ var oneId = $(e).val(); var checkbox = document.querySelector('input[name="pt"]'); if (checkbox.checked) { oneId=0; console.log("选中是平台"); }else{ oneId = 1; console.log("运营商"); console.log(oneId) } if (oneId == "1"){ oneId = $("#yys").val() if (oneId==""){ oneId = 1 } console.log("看看选择之后") console.log(oneId) var button = document.getElementById("yys"); button.removeAttribute("disabled"); } var ajax = new $ax(Feng.ctxPath + "/tSite/getChangeOne", function(data){ if(data!=null){ // var content1 = ''; console.log("看看oneId") console.log(oneId) if (oneId == 0) { console.log("锁住") $("#yys").prop('disabled', true); }else{ console.log("放开") $("#yys").prop('disabled', false); } var content=''; $.each(data, function(k,v) { content += ""; }); $("#store").empty().append(content); } }); ajax.set("oneId",oneId); ajax.start(); }; // 场地管理首页 选择对应的省市 // 传1是场地管理首页 传2是场地管理添加页面 TSite.oneChange = function (e) { var selectElement = document.getElementById('store'); var startTime = document.getElementById('start-time'); var endTime = document.getElementById('end-time'); if (startTime!==null){ startTime.disabled = true; endTime.disabled = true; selectElement.addEventListener('change',function () { if (selectElement.value !== ''){ startTime.disabled = false; endTime.disabled = false; }else{ startTime.disabled = true; endTime.disabled = true; } }); } var province = $('#pCode option:selected').text(); var val = $('#pCode option:selected').val(); var citySelect = document.getElementById("cCode"); var accountSelect = document.getElementById("account"); var storeSelect = document.getElementById("store"); var ajax = new $ax(Feng.ctxPath + "/tSite/getCity", function(data){ if(data!=null){ var content=''; $.each(data, function(k,v) { content += ""; }); $("#cCode").empty().append(content); } }); // if (val === ""){ // citySelect.innerHTML = ''; // // } // if (e===2){ // accountSelect.innerHTML = ''; // storeSelect.innerHTML = ''; // } // if (val === ""){ // startTime.disabled = true; // endTime.disabled = true; // } ajax.set("province",province); ajax.start(); }; TSite.oneChange1 = function (e) { console.log(111) var oneId=$(e).val(); var ajax = new $ax(Feng.ctxPath + "/tCompetition/onChange", function(data){ if(data!=null){ var content=''; $.each(data, function(k,v) { content += ""; }); $("#cCode").empty().append(content); } }); ajax.set("oneId",oneId); ajax.start(); } TSite.oneChangeNext = function (e) { var startTime = document.getElementById('start-time'); var endTime = document.getElementById('end-time'); var oneId=$(e).val(); var citySelect = document.getElementById("account"); var storeSelect = document.getElementById("store"); var ajax = new $ax(Feng.ctxPath + "/tSite/accountChangeNext", function(data){ if(data!=null){ var content=''; $.each(data, function(k,v) { content += ""; }); $("#account").empty().append(content); } }); if (oneId === ""){ citySelect.innerHTML = ''; storeSelect.innerHTML = ''; startTime.disabled = true; endTime.disabled = true; } ajax.set("oneId",oneId); ajax.start(); var ajax1 = new $ax(Feng.ctxPath + "/tSite/storeChangeNext", function(data){ if(data!=null && data.length !== 0){ var content=''; $.each(data, function(k,v) { content += ""; }); $("#store").empty().append(content); }else { storeSelect.innerHTML = ''; } }); ajax1.set("oneId",oneId); ajax1.start(); }; /** * 跳转添加场地页面 */ TSite.openAddTSite = function () { var index = layer.open({ type: 2, title: "添加场地", area: ['100%', '100%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/tSite/add' }); this.layerIndex = index; }; /** * 跳转锁定场地页面 */ TSite.lock = function () { var selected = $('#' + this.id).bootstrapTable('getSelections'); if(selected.length >1 ){ Feng.info("只能选择一个场地进行锁定!"); }else { if (this.check()) { var index = layer.open({ type: 2, title: "锁定场地", area: ['100%', '100%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/tSite/lockSite/' + TSite.seItem.id }); this.layerIndex = index; } } }; /** * 打开场地管理查看详情 */ TSite.openInfo = function () { var selected = $('#' + this.id).bootstrapTable('getSelections'); if(selected.length >1 ){ Feng.info("只能选择一个问题进行编辑!"); }else { if (this.check()) { var index = layer.open({ type: 2, title: "查看详情", area: ['100%', '100%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/tSite/openInfoTSite/' + TSite.seItem.id }); this.layerIndex = index; } } }; /** * 打开场地管理编辑 */ TSite.openEditTSite = function () { var selected = $('#' + this.id).bootstrapTable('getSelections'); if(selected.length >1 ){ Feng.info("只能选择一个问题进行编辑!"); }else { if (this.check()) { var index = layer.open({ type: 2, title: "编辑场地", area: ['100%', '100%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/tSite/openEditTSite/' + TSite.seItem.id }); this.layerIndex = index; } } }; /** * 关闭此对话框 */ TSite.close = function() { parent.layer.close(window.parent.TSite.layerIndex); } var sh = ""; // 门店经营开始时间:小时 var sm = "";// 门店经营开始时间:分钟 var eh = "";// 门店经营结束时间:小时 var em = "";// 门店经营结束时间:分钟 TSite.addSubmit = function(){ var data = { province:"", city:"", cityManagerId:"", storeId:"", siteTypeId:null, appointmentStartTime:"", appointmentEndTime:"", cashPrice:null, playPaiCoin:null, insuranceEndTime:"", name:"", insuranceImg:"", managementPlan:"", operatorId:"", typeName:"", nextName:"", ishalf:"", cashPriceOne:"", playPaiCoinOne:"", halfName:"", introduce:"", imgs:"", reservation:"", isCanBeBooked:"", type:"", }; data.province = $("#pCode").val() data.city = $("#cCode").val() data.cityManagerId = $("#account").val() data.storeId = $("#store").val() data.siteTypeId = $("#siteTypeId").val() data.appointmentStartTime= $("#start-time").val() data.appointmentEndTime = $("#end-time").val() data.cashPrice = $("#cashPrice").val() data.playPaiCoin = $("#playPaiCoin").val() data.insuranceEndTime = $("#insuranceEndTime").val() data.name = $("#name").val() data.insuranceImg = $("input[type='hidden']#img").val() data.managementPlan = $('#courseVideo').val() data.typeName = $('#siteTypeOne').val() var sh =data.appointmentStartTime.split(':')[0]; var sm =data.appointmentStartTime.split(':')[1]; var eh =data.appointmentEndTime.split(':')[0]; var em =data.appointmentEndTime.split(':')[1]; console.log(data.typeName) var reservation= $("input[name='reservation']:checked").val(); data.reservation= reservation; data.isCanBeBooked= reservation; console.log("看看是否可预约值") console.log(reservation); var checkbox = document.querySelector('input[name="pt"]'); console.log(checkbox) if (checkbox!=null){ if (checkbox.checked) { data.type = 1 console.log("选中是平台"); data.operatorId = 0; } else { console.log("运营商"); data.type = 2; } } if (reservation == 1) { if (data.typeName === "智慧场地") { console.log("===========这是智慧球场") console.log("=====" + data.appointmentStartTime) var value = data.appointmentStartTime; var lastTwoDigits = value.slice(-2); if (lastTwoDigits === "00" || lastTwoDigits === "15" || lastTwoDigits === "30" || lastTwoDigits === "45") { console.log("Last two digits are 00, 15, 30, or 45"); } else { Feng.error("智慧场地的可预约时间段是15分钟的倍数") return; } var value1 = data.appointmentEndTime; var lastTwoDigits1 = value1.slice(-2); if (lastTwoDigits1 === "00" || lastTwoDigits1 === "15" || lastTwoDigits1 === "30" || lastTwoDigits1 === "45") { console.log("Last two digits are 00, 15, 30, or 45"); } else { Feng.error("智慧场地的可预约时间段是15分钟的倍数") return; } } else { console.log("===========这是普通球场") console.log("=====" + data.appointmentStartTime) var value = data.appointmentStartTime; var lastTwoDigits = value.slice(-2); if (lastTwoDigits === "00" || lastTwoDigits === "30") { console.log("Last two digits are 00, 15, 30, or 45"); } else { Feng.info("普通场地可预约时间段需是30分钟的倍数") return; } var value1 = data.appointmentEndTime; var lastTwoDigits1 = value1.slice(-2); if (lastTwoDigits1 === "00" || lastTwoDigits1 === "30") { console.log("Last two digits are 00, 15, 30, or 45"); } else { Feng.info("普通场地可预约时间段需是30分钟的倍数") return; } } } var SelectValue=""; var getSelectValueMenbers = $("input[name='pt']:checked").each(function(j) { if (j >= 0) { SelectValue += $(this).val() } }); if(SelectValue==''){ let yys = $("#yys").val() if(yys==""){ Feng.info("请选择运营商") return; } SelectValue= yys } data.operatorId= SelectValue; let num24 = $('input[name="name1"]'); var nextName=""; for (let i = 0; i < num24.length; i++) { if($(num24[i]).val()==''){ Feng.info("请填写场地名称") return; } if(i==num24.length-1){ nextName += $(num24[i]).val() }else { nextName += $(num24[i]).val()+"," } } data.nextName= nextName; var ishalf= $("input[name='ishalf']:checked").val(); data.ishalf= ishalf; var halfName=""; if (reservation==1) { if (ishalf == 1) { let cashPriceOne = $("#cashPriceOne").val() if (cashPriceOne == '') { Feng.info("请填写现金价格") return; } data.cashPriceOne = cashPriceOne; let playPaiCoinOne = $("#playPaiCoinOne").val() if (playPaiCoinOne == '') { Feng.info("请填写玩湃币价格") return; } data.playPaiCoinOne = playPaiCoinOne; let num2 = $('input[name="name2"]'); for (let i = 0; i < num2.length; i++) { if ($(num2[i]).val() == '') { Feng.info("请填写半场名称") return; } if (i == num2.length - 1) { halfName += $(num2[i]).val() } else { halfName += $(num2[i]).val() + "," } } } } data.halfName= halfName; let introduce ; if (objectType==1){ introduce = TSite.editor.getContent(); } console.log(introduce) if(introduce==""){ Feng.info("请输入公告内容") return; } data.introduce= introduce; var goodImgs = this.goodsPicArray; if(objectType==1){ if(goodImgs.length==0){ Feng.info("请上传实景图") return; } } var imgOne =""; for (let i = 0; i Number(startHour)) { Feng.error("预约的开始时间不应小于营业开始时间!") return false; } else if (Number(sh) === Number(startHour)) { if (Number(sm) > Number(startMinute)) { Feng.error("预约的开始时间不应大于营业开始时间!") return false; } } else if (Number(eh) < Number(startHour)) { Feng.error("预约的开始时间不应大于营业结束时间!") return false; } else if (Number(eh) === Number(startHour)) { Feng.error("预约的开始时间不应大于等于营业结束时间!") return false; } var end = eTime.value; var endHour = end.split(':')[0]; // 输入的可预约结束时间:小时 var endMinute = end.split(':')[1];// 输入的可预约结束时间:分钟 if (Number(eh) < Number(endHour)) { Feng.error("预约的结束时间不应大于营业结束时间!") return; } else if (Number(eh) === Number(endHour)) { if (Number(em) < Number(endMinute)) { Feng.error("预约的开始时间不应大于开始营业时间!") return; } } else if (Number(sh) > Number(endHour)) { Feng.error("预约的结束时间不应小于营业开始时间!") return; } if (Number(endHour) === Number(sh)) { if (Number(endMinute) < Number(sm)) { Feng.error("预约结束时间不应小于营业开始时间"); return; } } if (Number(startHour) === Number(endHour) && Number(startMinute) === Number(endMinute)) { Feng.error("至少预约半个小时"); return; } } $.ajax({ url: Feng.ctxPath + "/tSite/addSite" , type: "POST", data: JSON.stringify(data), contentType: "application/json", success: function (response) { window.parent.TSite.table.refresh(); TSite.close(); Feng.success("添加成功"); }, error: function (xhr, status, error) { Feng.error("添加失败!" + error); } }); }, error: function (xhr, status, error) { var errorMessage = xhr.responseText ? xhr.responseText : "上架失败!"; Feng.error("您的网络异常!"); return false; } }); }; TSite.search = function () { var queryData = {}; queryData['province'] = $("#pCode").val(); queryData['city'] = $("#cCode").val(); queryData['siteTypeId'] = $("#sCode").val(); // 场地名称 queryData['name'] = $("#name").val(); // 门店名称 queryData['storeName'] = $("#storeName").val(); queryData['opId'] = $("#opId").val(); queryData['storeName'] = $("#storeName").val(); TSite.table.refresh({query: queryData}); }; TSite.resetSearch = function () { $("#pCode").val(""); $("#cCode").val(""); $("#store").val(""); $("#sCode").val(""); $("#storeName").val(""); $("#siteTypeId").val(""); $("#name").val(""); $("#insuranceEndTime").val(""); $("#opId").val(""); $("#storeName").val(""); TSite.search(); }; function UploadFileFn(){ $('#upFile').click(); } $(function () { //初始化编辑器 // 检查editor元素是否存在再初始化UEditor if (document.getElementById('editor')) { TSite.editor = UE.getEditor('editor'); } else { console.log("editor元素未找到,跳过UEditor初始化"); // 创建一个空对象,防止后续代码出错 TSite.editor = { getContent: function() { return ""; }, setContent: function() {} }; } // 限制分钟选项为 0 和 30 // var timeInputs = document.querySelectorAll('input[type="time"]'); // timeInputs.forEach(function(input) { // input.addEventListener('change', function() { // var selectedTime = input.value; // var hour = selectedTime.split(':')[0]; // var minute = selectedTime.split(':')[1]; // if (minute < 30 &&minute>0) { // minute = '30'; // } else if (minute >30) { // hour++; // minute = '00'; // if (hour<10){ // hour = '0'+hour; // } // } // input.value = hour + ':' + minute; // }); // }); var defaultColunms = TSite.initColumn(); var type =$("#type").val(); if (type !== 1){ var table1 = new BSTable(TSite.id, "/tSite/listExipre", defaultColunms); table1.setPaginationType("client"); TSite.table = table1.init(); } var table = new BSTable(TSite.id, "/tSite/listAll", defaultColunms); table.setPaginationType("client"); TSite.table = table.init(); Feng.initValidator("carInfoForm", TSite.validateFields); var carPhoto = new $WebUpload("img"); carPhoto.setUploadBarId("progressBar"); carPhoto.init(); $('#upFile').on('change', function () { var formData = new FormData() //创建一个forData formData.append('file', $('#upFile')[0].files[0]) //把file添加进去 name命名为img layer.load(); //上传loading $.ajax({ url: Feng.ctxPath + '/mgr/uploadFile', data: formData, type: "POST", async: true, cache: false, contentType: false, processData: false, success: function(res) { layer.closeAll('loading'); //关闭loading $('#upFile').val(''); $('#courseVideo').val(res); } }) }); }); /** * 下一步:切换到价格配置 */ TSite.nextStep = function() { // 校验步骤一的必填字段 if (!TSite.validateBasicInfo()) { return; } var siteName = $("#name").val(); // 这些将在步骤二中配置 var isHalf = 2; // 默认不可预定半场 var nextNames = []; var halfNames = []; // 保存信息到全局变量 TSite.priceConfig = { siteName: siteName, isHalf: isHalf, nextNames: nextNames, halfNames: halfNames, timeSlots: [], priceData: {} }; // 显示场地信息 $("#display_site_name").text(siteName); $("#display_next_names").html(""); // 清空 $("#display_half_names").html(""); // 清空 // 切换步骤,仅依赖CSS的active class $("#step1_basic_info").removeClass('active'); $("#step2_price_config").addClass('active'); // 初始化价格配置 TSite.initPriceConfig(); // 滚动到顶部 $('html, body').animate({scrollTop: 0}, 300); } /** * 验证步骤一的必填字段 */ TSite.validateBasicInfo = function() { // 验证运营商 var SelectValue = ""; $("input[name='pt']:checked").each(function(j) { if (j >= 0) { SelectValue += $(this).val(); } }); if (SelectValue == '') { let yys = $("#yys").val(); if (yys == "") { Feng.error("请选择运营商"); return false; } } // 验证门店 if ($("#store").val() == '') { Feng.error("请选择门店"); return false; } // 验证场地分类 if ($("#siteTypeId").val() == '') { Feng.error("请选择场地分类"); return false; } // 验证场地名称 if ($("#name").val() == '') { Feng.error("请输入场地名称"); return false; } // 验证场地责任险有效期 if ($("#insuranceEndTime").val() == '') { Feng.error("请输入场地责任险有效期"); return false; } // 验证场地责任险图片(使用更精确的选择器获取hidden input) var imgValue = $("input[type='hidden']#img").val(); if (!imgValue || imgValue == '') { Feng.error("请上传场地责任有效期图片"); return false; } // 验证消防及应急管理方案 if ($('#courseVideo').val() == '') { Feng.error("请上传消防及应急管理方案"); return false; } // 验证对象类型相关字段 var objectType = $("#objectType").val(); if (objectType == 1) { // 验证公告内容 var introduce = TSite.editor.getContent(); if (introduce == "") { Feng.error("请输入公告内容"); return false; } // 验证实景图 var goodImgs = TSite.goodsPicArray; if (goodImgs.length == 0) { Feng.error("请上传实景图"); return false; } } return true; } /** * 上一步:返回基本信息 */ TSite.previousStep = function() { // 切换步骤,仅依赖CSS的active class $("#step2_price_config").removeClass('active'); $("#step1_basic_info").addClass('active'); // 滚动到顶部 $('html, body').animate({scrollTop: 0}, 300); } /** * 初始化价格配置 */ TSite.initPriceConfig = function() { // 初始化计数器 TSite.bookingRowIndex = 0; TSite.walkinRowIndex = 0; // 清空价格表 $("#booking_price_tbody").empty(); $("#walkin_price_tbody").empty(); // 隐藏价格表区域 $("#booking_section").hide(); $("#walkin_section").hide(); // 标记价格表未生成 TSite.priceTablesGenerated = false; // 初始化是否可预定半场状态 var isHalf = TSite.priceConfig ? TSite.priceConfig.isHalf : 2; if (isHalf == 1) { $("input[name='ishalf_step2'][value='1']").prop('checked', true); $("#halfCode_step2").show(); } else { $("input[name='ishalf_step2'][value='2']").prop('checked', true); $("#halfCode_step2").hide(); } // 监听人群选择变化 $("#audience_booking, #audience_walkin").off('change').on('change', function() { TSite.updateAudienceUI(); // 如果价格表已生成,提示需要重新生成 if (TSite.priceTablesGenerated) { TSite.clearPriceTables(); } }); // 更新界面(但不显示价格表) TSite.updateAudienceUI(); } /** * 生成价格表 * @param {boolean} autoAddRow - 是否自动添加空白时段,默认为 true */ TSite.generatePriceTables = function(autoAddRow) { // 默认自动添加空白时段 if (autoAddRow === undefined) { autoAddRow = true; } // 验证人群选择 var bookingChecked = $("#audience_booking").is(':checked'); var walkinChecked = $("#audience_walkin").is(':checked'); if (!bookingChecked && !walkinChecked) { Feng.error("请至少选择一种面向人群!"); return; } // 验证容纳散客数 if (walkinChecked) { var walkinCapacity = $("#walkin_capacity").val(); if (!walkinCapacity || parseInt(walkinCapacity) <= 0) { Feng.error("请输入有效的容纳散客数!"); return; } } // 清除现有价格表 TSite.clearPriceTables(); // 生成表头 TSite.buildTableHeaders(); // 显示对应的价格表区域 if (bookingChecked) { $("#booking_section").show(); // 根据参数决定是否自动添加一条订场时段 if (autoAddRow) { TSite.addBookingTimeSlot(); } } if (walkinChecked) { $("#walkin_section").show(); // 根据参数决定是否自动添加一条散客时段 if (autoAddRow) { TSite.addWalkinTimeSlot(); } } // 标记价格表已生成 TSite.priceTablesGenerated = true; if (autoAddRow) { Feng.success("价格表已生成,请填写价格!"); } } /** * 清除价格表 */ TSite.clearPriceTables = function() { // 清空价格表内容 $("#booking_price_tbody").empty(); $("#walkin_price_tbody").empty(); // 隐藏价格表区域 $("#booking_section").hide(); $("#walkin_section").hide(); // 重置计数器 TSite.bookingRowIndex = 0; TSite.walkinRowIndex = 0; // 标记价格表未生成 TSite.priceTablesGenerated = false; Feng.info("价格配置已清除,请重新生成价格表!"); } /** * 添加场地名 */ TSite.addFieldBox = function() { var html = '
' + '' + '' + '' + '
'; $("#field_container").append(html); } /** * 删除场地名 */ TSite.removeFieldBox = function(btn) { $(btn).closest('.field-item').remove(); } /** * 添加半场名称 */ TSite.addHalfFieldBox = function() { var html = '
' + '' + '' + '' + '
'; $("#half_field_container").append(html); } /** * 删除半场名称 */ TSite.removeHalfFieldBox = function(btn) { $(btn).closest('.field-item').remove(); } /** * 更新半场字段显示 */ TSite.updateHalfField = function(value) { if (value == 1) { $("#halfCode_step2").show(); // 更新isHalf TSite.priceConfig.isHalf = 1; } else { $("#halfCode_step2").hide(); TSite.priceConfig.isHalf = 2; } // 如果价格表已生成,清除价格表 if (TSite.priceTablesGenerated) { TSite.clearPriceTables(); } } /** * 更新人群相关UI */ TSite.updateAudienceUI = function() { var walkinChecked = $("#audience_walkin").is(':checked'); // 只控制容纳散客数字段的显示/隐藏 // 价格表的显示由生成按钮控制 if (walkinChecked) { $("#walkin_capacity_group").show(); } else { $("#walkin_capacity_group").hide(); } } /** * 构建表头 */ TSite.buildTableHeaders = function() { var isHalf = TSite.priceConfig ? TSite.priceConfig.isHalf : 2; var headerHtml = '' + '时段开始' + '时段结束'; // 周一到周日的表头 var weekDays = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']; if (isHalf == 1) { // 如果可预订半场,每天有4列(全场×2 + 半场×2) for (var i = 0; i < weekDays.length; i++) { headerHtml += '' + weekDays[i] + ''; } headerHtml += '操作' + '' + ''; // 第二行:全场/半场 for (var i = 0; i < weekDays.length; i++) { headerHtml += '全场' + '半场'; } headerHtml += '' + ''; // 第三行:现金/玩湃币 for (var i = 0; i < weekDays.length; i++) { headerHtml += '现金' + '玩湃币' + '现金' + '玩湃币'; } } else { // 如果不可预订半场,每天有2列(全场×2) for (var i = 0; i < weekDays.length; i++) { headerHtml += '' + weekDays[i] + ''; } headerHtml += '操作' + '' + ''; // 第二行:全场 for (var i = 0; i < weekDays.length; i++) { headerHtml += '全场'; } headerHtml += '' + ''; // 第三行:现金/玩湃币 for (var i = 0; i < weekDays.length; i++) { headerHtml += '现金' + '玩湃币'; } } headerHtml += ''; // 设置表头 $("#booking_thead").html(headerHtml); $("#walkin_thead").html(headerHtml); } /** * 添加订场时段 */ TSite.addBookingTimeSlot = function() { var isHalf = TSite.priceConfig ? TSite.priceConfig.isHalf : 2; var index = TSite.bookingRowIndex++; var html = '' + '' + ''; // 周一到周日,每天的价格输入框 for (var day = 1; day <= 7; day++) { if (isHalf == 1) { // 全场现金、全场玩湃币、半场现金、半场玩湃币 html += '' + '' + '' + ''; } else { // 全场现金、全场玩湃币 html += '' + ''; } } html += '' + ''; $("#booking_price_tbody").append(html); } /** * 添加散客时段 */ TSite.addWalkinTimeSlot = function() { var isHalf = TSite.priceConfig ? TSite.priceConfig.isHalf : 2; var index = TSite.walkinRowIndex++; var html = '' + '' + ''; // 周一到周日,每天的价格输入框 for (var day = 1; day <= 7; day++) { if (isHalf == 1) { // 全场现金、全场玩湃币、半场现金、半场玩湃币 html += '' + '' + '' + ''; } else { // 全场现金、全场玩湃币 html += '' + ''; } } html += '' + ''; $("#walkin_price_tbody").append(html); } /** * 删除时段 */ TSite.removeTimeSlot = function(btn) { $(btn).closest('tr').remove(); } /** * 检查时段是否重叠 */ TSite.checkTimeOverlap = function(start1, end1, start2, end2) { // 将时间字符串转换为分钟数便于比较 var toMinutes = function(time) { var parts = time.split(':'); return parseInt(parts[0]) * 60 + parseInt(parts[1]); }; var s1 = toMinutes(start1); var e1 = toMinutes(end1); var s2 = toMinutes(start2); var e2 = toMinutes(end2); // 检查重叠:时段1的结束时间 > 时段2的开始时间 且 时段1的开始时间 < 时段2的结束时间 return (e1 > s2 && s1 < e2); } /** * 验证订场和散客时段不重叠 */ TSite.validateNoTimeOverlap = function() { var bookingTimeSlots = []; var walkinTimeSlots = []; // 收集订场时段 $("#booking_price_tbody tr").each(function() { var index = $(this).data('index'); var startTime = $("#booking_start_" + index).val(); var endTime = $("#booking_end_" + index).val(); if (startTime && endTime) { bookingTimeSlots.push({start: startTime, end: endTime}); } }); // 收集散客时段 $("#walkin_price_tbody tr").each(function() { var index = $(this).data('index'); var startTime = $("#walkin_start_" + index).val(); var endTime = $("#walkin_end_" + index).val(); if (startTime && endTime) { walkinTimeSlots.push({start: startTime, end: endTime}); } }); // 检查订场时段之间是否重叠 for (var i = 0; i < bookingTimeSlots.length; i++) { for (var j = i + 1; j < bookingTimeSlots.length; j++) { if (TSite.checkTimeOverlap( bookingTimeSlots[i].start, bookingTimeSlots[i].end, bookingTimeSlots[j].start, bookingTimeSlots[j].end )) { Feng.error("订场价格表中存在重叠的时段:" + bookingTimeSlots[i].start + "-" + bookingTimeSlots[i].end + " 与 " + bookingTimeSlots[j].start + "-" + bookingTimeSlots[j].end); return false; } } } // 检查散客时段之间是否重叠 for (var i = 0; i < walkinTimeSlots.length; i++) { for (var j = i + 1; j < walkinTimeSlots.length; j++) { if (TSite.checkTimeOverlap( walkinTimeSlots[i].start, walkinTimeSlots[i].end, walkinTimeSlots[j].start, walkinTimeSlots[j].end )) { Feng.error("散客价格表中存在重叠的时段:" + walkinTimeSlots[i].start + "-" + walkinTimeSlots[i].end + " 与 " + walkinTimeSlots[j].start + "-" + walkinTimeSlots[j].end); return false; } } } return true; } /** * 保存所有数据(基本信息+价格配置) */ TSite.saveAllData = function() { // 验证价格表是否已生成 if (!TSite.priceTablesGenerated) { Feng.error("请先点击【生成价格表】按钮生成价格配置表!"); return; } // 验证时段不重叠 if (!TSite.validateNoTimeOverlap()) { return; } // 验证人群选择 var bookingChecked = $("#audience_booking").is(':checked'); var walkinChecked = $("#audience_walkin").is(':checked'); if (!bookingChecked && !walkinChecked) { Feng.error("请至少选择一种面向人群!"); return; } // 验证容纳散客数 if (walkinChecked) { var walkinCapacity = parseInt($("#walkin_capacity").val()); if (!walkinCapacity || walkinCapacity <= 0) { Feng.error("请输入有效的容纳散客数!"); return; } } // 验证时段不重叠 if (!TSite.validateNoTimeOverlap()) { return; } // 收集价格数据 var priceDTOS = TSite.collectPriceData(); // 如果返回 null,说明验证失败,已经显示了具体错误信息 if (priceDTOS === null) { return; } // 如果返回空数组,说明没有填写任何价格 if (priceDTOS.length === 0) { Feng.error("请至少添加一个时段并填写价格!"); return; } // 收集基本信息数据 var basicData = TSite.collectBasicData(); if (!basicData) { return; // 基本信息验证失败 } // 收集场地配置 var nextNames = []; $("input[name='name1_step2']").each(function() { var val = $(this).val(); if (val) { nextNames.push(val); } }); var halfNames = []; $("input[name='name2_step2']").each(function() { var val = $(this).val(); if (val) { halfNames.push(val); } }); var isHalf = $("input[name='ishalf_step2']:checked").val(); // 构建提交数据 var targetAudience = []; if (bookingChecked) targetAudience.push('1'); if (walkinChecked) targetAudience.push('2'); // 合并基本信息和价格配置 basicData.targetAudience = targetAudience.join(','); basicData.walkinCapacity = walkinChecked ? parseInt($("#walkin_capacity").val()) : 0; basicData.nextName = nextNames.join(','); basicData.halfName = halfNames.join(','); basicData.ishalf = parseInt(isHalf); basicData.priceDTOS = priceDTOS; // 确认提交 layer.confirm('确定要保存场地信息吗?', { btn: ['确定', '取消'] }, function(index) { layer.close(index); // 提交到后端 $.ajax({ url: Feng.ctxPath + "/tSite/addSite", type: "POST", data: JSON.stringify(basicData), contentType: "application/json", success: function(response) { Feng.success("场地信息保存成功!"); // 刷新列表 if (window.parent.TSite && window.parent.TSite.table) { window.parent.TSite.table.refresh(); } // 关闭页面 setTimeout(function() { TSite.close(); }, 1500); }, error: function(xhr, status, error) { var errorMsg = "保存失败"; if (xhr.responseJSON && xhr.responseJSON.message) { errorMsg = xhr.responseJSON.message; } Feng.error(errorMsg); } }); }); } /** * 收集基本信息数据 */ TSite.collectBasicData = function() { var data = { province:"", city:"", cityManagerId:"", storeId:"", siteTypeId:null, appointmentStartTime:"", appointmentEndTime:"", cashPrice:null, playPaiCoin:null, insuranceEndTime:"", name:"", insuranceImg:"", managementPlan:"", operatorId:"", typeName:"", nextName:"", ishalf:"", cashPriceOne:"", playPaiCoinOne:"", halfName:"", introduce:"", imgs:"", reservation:"", isCanBeBooked:"", type:"", }; data.province = $("#pCode").val() data.city = $("#cCode").val() data.cityManagerId = $("#account").val() data.storeId = $("#store").val() data.siteTypeId = $("#siteTypeId").val() data.appointmentStartTime= $("#start-time").val() data.appointmentEndTime = $("#end-time").val() data.cashPrice = $("#cashPrice").val() data.playPaiCoin = $("#playPaiCoin").val() data.insuranceEndTime = $("#insuranceEndTime").val() data.name = $("#name").val() data.insuranceImg = $("input[type='hidden']#img").val() data.managementPlan = $('#courseVideo').val() data.typeName = $('#siteTypeOne').val() var reservation= $("input[name='reservation']:checked").val(); data.reservation= reservation; data.isCanBeBooked= reservation; var checkbox = document.querySelector('input[name="pt"]'); if (checkbox!=null){ if (checkbox.checked) { data.type = 1 data.operatorId = 0; } else { data.type = 2; } } var SelectValue=""; var getSelectValueMenbers = $("input[name='pt']:checked").each(function(j) { if (j >= 0) { SelectValue += $(this).val() } }); if(SelectValue==''){ let yys = $("#yys").val() if(yys==""){ Feng.info("请选择运营商") return null; } SelectValue= yys } data.operatorId= SelectValue; let introduce = ""; var objectType = $("#objectType").val(); if (objectType==1){ introduce = TSite.editor.getContent(); if(introduce==""){ Feng.info("请输入公告内容") return null; } } data.introduce= introduce; var goodImgs = this.goodsPicArray; if(objectType==1){ if(goodImgs.length==0){ Feng.info("请上传实景图") return null; } } var imgOne =""; for (let i = 0; i = endTime) { Feng.error("订场价格配置中,结束时间必须大于开始时间!"); validationFailed = true; return false; } // 遍历周一到周日 var hasAnyPrice = false; // 标记该时段是否有任何价格 for (var day = 1; day <= 7; day++) { var fullCashVal = $("#booking_" + index + "_" + day + "_full_cash").val(); var fullCoinVal = $("#booking_" + index + "_" + day + "_full_coin").val(); var fullCash = parseFloat(fullCashVal || 0); var fullCoin = parseFloat(fullCoinVal || 0); // 全场价格验证 if (fullCashVal !== '' || fullCoinVal !== '') { hasAnyPrice = true; // 如果填写了一个,检查另一个是否为空 if (fullCashVal === '' || fullCoinVal === '') { var dayName = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'][day - 1]; Feng.error("订场价格 " + startTime + "-" + endTime + " " + dayName + " 全场的现金价格和玩湃币价格都必须填写!"); validationFailed = true; return false; } priceDTOS.push({ startTime: startTime, endTime: endTime, dayOfWeek: day, targetAudience: 1, // 1=订场 fieldType: 1, // 1=全场 cashPrice: fullCash, coinPrice: fullCoin }); } // 半场价格(如果可预订半场) if (isHalf == 1) { var halfCashVal = $("#booking_" + index + "_" + day + "_half_cash").val(); var halfCoinVal = $("#booking_" + index + "_" + day + "_half_coin").val(); var halfCash = parseFloat(halfCashVal || 0); var halfCoin = parseFloat(halfCoinVal || 0); // 半场价格验证 if (halfCashVal !== '' || halfCoinVal !== '') { hasAnyPrice = true; // 如果填写了一个,检查另一个是否为空 if (halfCashVal === '' || halfCoinVal === '') { var dayName = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'][day - 1]; Feng.error("订场价格 " + startTime + "-" + endTime + " " + dayName + " 半场的现金价格和玩湃币价格都必须填写!"); validationFailed = true; return false; } priceDTOS.push({ startTime: startTime, endTime: endTime, dayOfWeek: day, targetAudience: 1, // 1=订场 fieldType: 2, // 2=半场 cashPrice: halfCash, coinPrice: halfCoin }); } } } // 检查该时段是否至少有一个价格 if (!hasAnyPrice) { Feng.error("订场价格时段 " + startTime + "-" + endTime + " 价格未填写完整!"); validationFailed = true; return false; } }); // 如果订场价格验证失败,直接返回 null if (validationFailed) { return null; } } // 收集散客价格 if (walkinChecked) { $("#walkin_price_tbody tr").each(function() { if (validationFailed) return false; // 如果已经验证失败,终止循环 var index = $(this).data('index'); var startTime = $("#walkin_start_" + index).val(); var endTime = $("#walkin_end_" + index).val(); // 验证时段 if (!startTime || !endTime) { Feng.error("散客价格配置中存在空的时段!"); validationFailed = true; return false; } if (startTime >= endTime) { Feng.error("散客价格配置中,结束时间必须大于开始时间!"); validationFailed = true; return false; } // 遍历周一到周日 var hasAnyPrice = false; // 标记该时段是否有任何价格 for (var day = 1; day <= 7; day++) { var fullCashVal = $("#walkin_" + index + "_" + day + "_full_cash").val(); var fullCoinVal = $("#walkin_" + index + "_" + day + "_full_coin").val(); var fullCash = parseFloat(fullCashVal || 0); var fullCoin = parseFloat(fullCoinVal || 0); // 全场价格验证 if (fullCashVal !== '' || fullCoinVal !== '') { hasAnyPrice = true; // 如果填写了一个,检查另一个是否为空 if (fullCashVal === '' || fullCoinVal === '') { var dayName = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'][day - 1]; Feng.error("散客价格 " + startTime + "-" + endTime + " " + dayName + " 全场的现金价格和玩湃币价格都必须填写!"); validationFailed = true; return false; } priceDTOS.push({ startTime: startTime, endTime: endTime, dayOfWeek: day, targetAudience: 2, // 2=散客 fieldType: 1, // 1=全场 cashPrice: fullCash, coinPrice: fullCoin }); } // 半场价格(如果可预订半场) if (isHalf == 1) { var halfCashVal = $("#walkin_" + index + "_" + day + "_half_cash").val(); var halfCoinVal = $("#walkin_" + index + "_" + day + "_half_coin").val(); var halfCash = parseFloat(halfCashVal || 0); var halfCoin = parseFloat(halfCoinVal || 0); // 半场价格验证 if (halfCashVal !== '' || halfCoinVal !== '') { hasAnyPrice = true; // 如果填写了一个,检查另一个是否为空 if (halfCashVal === '' || halfCoinVal === '') { var dayName = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'][day - 1]; Feng.error("散客价格 " + startTime + "-" + endTime + " " + dayName + " 半场的现金价格和玩湃币价格都必须填写!"); validationFailed = true; return false; } priceDTOS.push({ startTime: startTime, endTime: endTime, dayOfWeek: day, targetAudience: 2, // 2=散客 fieldType: 2, // 2=半场 cashPrice: halfCash, coinPrice: halfCoin }); } } } // 检查该时段是否至少有一个价格 if (!hasAnyPrice) { Feng.error("散客价格时段 " + startTime + "-" + endTime + " 价格未填写完整!"); validationFailed = true; return false; } }); // 如果散客价格验证失败,直接返回 null if (validationFailed) { return null; } } return priceDTOS; };