|
@@ -125,17 +125,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
// 初始化规则数据管理器
|
|
|
Controller.api.rulesDataManager.init();
|
|
|
|
|
|
- // 同步DOM中现有的奖品数据到数据管理器
|
|
|
- Controller.api.syncExistingPrizesToDataManager();
|
|
|
-
|
|
|
// 初始化奖品管理
|
|
|
Controller.api.initPrizeManagement();
|
|
|
|
|
|
// 初始化任务规则管理
|
|
|
Controller.api.initTaskRuleManagement();
|
|
|
|
|
|
- // 确保系统默认项有正确的概率值
|
|
|
- Controller.api.initDefaultPrizeRate();
|
|
|
+ // 清空奖品列表DOM,确保没有任何默认奖品
|
|
|
+ $('.prize-list').empty();
|
|
|
+
|
|
|
+ // 添加页面:用户手动添加所有奖品,不创建任何默认项
|
|
|
+ console.log('添加页面初始化完成,奖品列表已清空,等待用户手动添加奖品');
|
|
|
|
|
|
// 确保DOM渲染完成后再计算奖品数量
|
|
|
setTimeout(function() {
|
|
@@ -143,12 +143,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
Controller.api.updatePrizeCount();
|
|
|
}, 50);
|
|
|
|
|
|
- // 再次延迟调用,确保所有DOM都已渲染
|
|
|
- setTimeout(function() {
|
|
|
- console.log('页面初始化 - 二次更新奖品计数');
|
|
|
- Controller.api.updatePrizeCount();
|
|
|
- }, 500);
|
|
|
-
|
|
|
// 初始化表单验证
|
|
|
Controller.api.initFormValidation();
|
|
|
},
|
|
@@ -288,23 +282,50 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ var totalRate = 0;
|
|
|
+
|
|
|
// 验证每个奖品的基本字段
|
|
|
for (var i = 0; i < prizes.length; i++) {
|
|
|
var prize = prizes[i];
|
|
|
- if (!prize.name || !prize.type || !prize.image) {
|
|
|
+
|
|
|
+ // 验证必填字段
|
|
|
+ if (!prize.name || prize.name.trim() === '') {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!prize.type) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证奖品类型是否有效
|
|
|
+ if (!prize.type || prize.type < 1 || prize.type > 8) {
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
// 验证概率值
|
|
|
if (typeof prize.rate !== 'number' || prize.rate < 0 || prize.rate > 100) {
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ // 验证数量(未中奖项除外)
|
|
|
+ if (prize.type !== 1 && (!prize.quantity || prize.quantity <= 0)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统计总概率
|
|
|
+ totalRate += parseFloat(prize.rate || 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证总概率必须等于100%
|
|
|
+ if (Math.abs(totalRate - 100) > 0.01) {
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
} catch (e) {
|
|
|
return false;
|
|
|
}
|
|
|
- }, '奖品数据不完整或格式错误');
|
|
|
+ }, '奖品数据不完整或格式错误,请检查:1.总概率必须等于100% 2.实物奖品数量必须大于0');
|
|
|
|
|
|
// 添加自定义验证规则 - 验证规则JSON数据
|
|
|
Nice.Validator.addRule('rulesJson', function(val, el) {
|
|
@@ -345,6 +366,50 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
return false;
|
|
|
}
|
|
|
}, '规则设置不完整或格式错误');
|
|
|
+
|
|
|
+ // 添加自定义验证规则 - 验证条件JSON数据
|
|
|
+ Nice.Validator.addRule('conditionsJson', function(val, el) {
|
|
|
+ try {
|
|
|
+ var conditions = JSON.parse(val || '{}');
|
|
|
+
|
|
|
+ // 验证是否有条件
|
|
|
+ if (!conditions || Object.keys(conditions).length === 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证每个条件的基本字段
|
|
|
+ for (var type in conditions) {
|
|
|
+ var condition = conditions[type];
|
|
|
+ if (!condition.type || condition.type != type) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据类型验证特定字段
|
|
|
+ switch(parseInt(type)) {
|
|
|
+ case 1: // 购买指定商品
|
|
|
+ var goodsIds = JSON.parse(condition.goods_ids || '[]');
|
|
|
+ if (!goodsIds || goodsIds.length === 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!condition.goods_rule || (condition.goods_rule != 1 && condition.goods_rule != 2)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2: // 单笔订单消费满额
|
|
|
+ case 3: // 单次充值满额
|
|
|
+ case 4: // 活动期间累计消费满额
|
|
|
+ if (!condition.condition_value || parseFloat(condition.condition_value) <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ } catch (e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }, '参与条件设置不完整或格式错误,请检查:1.购买指定商品需要选择商品 2.消费/充值条件需要输入有效金额');
|
|
|
}
|
|
|
|
|
|
// 监听表单提交事件
|
|
@@ -357,8 +422,25 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 收集规则数据并保存到隐藏域
|
|
|
- Controller.api.collectAndSaveRulesData();
|
|
|
+ // 收集并验证条件数据
|
|
|
+ try {
|
|
|
+ Controller.api.collectAndSaveRulesData();
|
|
|
+
|
|
|
+ // 验证条件数据是否满足要求
|
|
|
+ var conditionsData = Controller.api.rulesDataManager.getAllRules();
|
|
|
+ if (!conditionsData || Object.keys(conditionsData).length === 0) {
|
|
|
+ Toastr.error('请设置至少一种参与条件');
|
|
|
+ e.preventDefault();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('条件数据验证通过:', conditionsData);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('条件数据验证失败:', error);
|
|
|
+ Toastr.error('参与条件设置有误:' + error.message);
|
|
|
+ e.preventDefault();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
|
});
|
|
@@ -508,12 +590,58 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
|
|
|
// 初始化已有的奖品数据(重构版 - 使用数据管理器)
|
|
|
initExistingPrizes: function() {
|
|
|
+ // 直接从Config中获取奖品数据
|
|
|
+ var existingPrizes = Controller.api.parseConfigJson('existingPrizes', []);
|
|
|
+
|
|
|
// 检查是否有后台传递的奖品数据
|
|
|
- if (typeof window.existingPrizes !== 'undefined' && window.existingPrizes.length > 0) {
|
|
|
- console.log('正在初始化已有奖品数据:', window.existingPrizes);
|
|
|
+ if (existingPrizes && existingPrizes.length > 0) {
|
|
|
+ console.log('正在初始化已有奖品数据,共', existingPrizes.length, '个奖品');
|
|
|
+
|
|
|
+ // 处理奖品数据,确保格式正确
|
|
|
+ var processedPrizes = [];
|
|
|
+ for (var i = 0; i < existingPrizes.length; i++) {
|
|
|
+ var prize = existingPrizes[i];
|
|
|
+ var processedPrize = {
|
|
|
+ id: prize.id || ('prize_' + Date.now() + '_' + i),
|
|
|
+ name: prize.name || '',
|
|
|
+ type: parseInt(prize.type) || 1,
|
|
|
+ image: prize.image || '',
|
|
|
+ description: prize.description || '',
|
|
|
+ quantity: parseInt(prize.quantity) || 0,
|
|
|
+ rate: parseFloat(prize.rate) || 0,
|
|
|
+ sort_order: parseInt(prize.sort_order) || i
|
|
|
+ };
|
|
|
+
|
|
|
+ // 根据奖品类型设置特定字段
|
|
|
+ switch (processedPrize.type) {
|
|
|
+ case 3: // 积分
|
|
|
+ processedPrize.points = parseInt(prize.points) || 0;
|
|
|
+ break;
|
|
|
+ case 4: // 余额
|
|
|
+ processedPrize.balance = parseFloat(prize.balance) || 0;
|
|
|
+ break;
|
|
|
+ case 5: // 优惠券
|
|
|
+ processedPrize.coupon_id = prize.coupon_id || '';
|
|
|
+ processedPrize.coupon_name = prize.coupon_name || '';
|
|
|
+ break;
|
|
|
+ case 6: // 红包
|
|
|
+ processedPrize.redpack_amount = parseFloat(prize.redpack_amount) || 0;
|
|
|
+ break;
|
|
|
+ case 7: // 兑换码
|
|
|
+ processedPrize.code_type = prize.code_type || 'auto';
|
|
|
+ processedPrize.manual_codes = prize.manual_codes || '';
|
|
|
+ break;
|
|
|
+ case 8: // 商城奖品
|
|
|
+ processedPrize.goods_id = prize.goods_id || '';
|
|
|
+ processedPrize.goods_name = prize.goods_name || '';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ processedPrizes.push(processedPrize);
|
|
|
+ }
|
|
|
|
|
|
- // 将已有奖品数据加载到数据管理器
|
|
|
- Controller.api.prizesDataManager.prizesData = window.existingPrizes;
|
|
|
+ // 将处理后的奖品数据加载到数据管理器
|
|
|
+ Controller.api.prizesDataManager.prizesData = processedPrizes;
|
|
|
Controller.api.prizesDataManager.saveToHiddenField();
|
|
|
|
|
|
// 重新构建奖品列表
|
|
@@ -523,77 +651,114 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
Controller.api.updatePrizeCount();
|
|
|
Controller.api.updateTotalRate();
|
|
|
|
|
|
- console.log('奖品数据初始化完成,数据管理器已同步');
|
|
|
+ console.log('奖品数据初始化完成,数据管理器已同步,共', processedPrizes.length, '个奖品');
|
|
|
} else {
|
|
|
- console.log('没有找到已有的奖品数据,尝试从DOM同步');
|
|
|
- // 如果没有后台数据,尝试从DOM同步现有数据
|
|
|
- Controller.api.syncExistingPrizesToDataManager();
|
|
|
+ console.log('编辑页面没有找到已有的奖品数据');
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 初始化已有的规则数据
|
|
|
initExistingRules: function() {
|
|
|
+ // 直接从Config中获取规则数据
|
|
|
+ var existingRulesData = Controller.api.parseConfigJson('existingRulesData', {});
|
|
|
+
|
|
|
// 检查是否有后台传递的规则数据
|
|
|
- if (typeof window.existingRulesData !== 'undefined' && window.existingRulesData) {
|
|
|
- console.log('正在初始化已有规则数据:', window.existingRulesData);
|
|
|
+ if (existingRulesData && Object.keys(existingRulesData).length > 0) {
|
|
|
+ console.log('正在初始化已有规则数据:', existingRulesData);
|
|
|
|
|
|
// 将已有规则数据加载到数据管理器
|
|
|
- Controller.api.rulesDataManager.rulesData = window.existingRulesData;
|
|
|
+ Controller.api.rulesDataManager.rulesData = existingRulesData;
|
|
|
Controller.api.rulesDataManager.saveToHiddenField();
|
|
|
|
|
|
+ // 根据规则数据设置任务类型选择状态
|
|
|
+ Controller.api.renderTaskTypesFromRules(existingRulesData);
|
|
|
+
|
|
|
console.log('规则数据初始化完成');
|
|
|
} else {
|
|
|
console.log('没有找到已有的规则数据');
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- // 初始化已有的条件数据
|
|
|
- initExistingConditions: function() {
|
|
|
- // 检查是否有后台传递的条件数据
|
|
|
- if (typeof window.existingConditions !== 'undefined' && window.existingConditions.length > 0) {
|
|
|
- console.log('正在初始化已有条件数据:', window.existingConditions);
|
|
|
+ // 根据规则数据渲染任务类型选择
|
|
|
+ renderTaskTypesFromRules: function(rulesData) {
|
|
|
+ console.log('根据规则数据渲染任务类型选择:', rulesData);
|
|
|
+
|
|
|
+ // 取消所有任务类型的选中状态
|
|
|
+ $('input[name="row[task_type][]"]').prop('checked', false);
|
|
|
+
|
|
|
+ // 隐藏所有任务设置项
|
|
|
+ $('.task-setting-item').hide();
|
|
|
+
|
|
|
+ // 遍历规则数据,设置对应的任务类型
|
|
|
+ for (var type in rulesData) {
|
|
|
+ var rule = rulesData[type];
|
|
|
+ var taskType = parseInt(type);
|
|
|
|
|
|
- // 根据条件数据勾选任务类型
|
|
|
- window.existingConditions.forEach(function(condition) {
|
|
|
- var checkbox = $('input[name="row[task_type][]"][value="' + condition.type + '"]');
|
|
|
- if (checkbox.length > 0) {
|
|
|
- checkbox.prop('checked', true);
|
|
|
- // 显示对应的任务设置
|
|
|
- $('#task-setting-' + condition.type).show();
|
|
|
-
|
|
|
- // 根据条件类型设置具体的数据
|
|
|
- switch (parseInt(condition.type)) {
|
|
|
- case 1: // 购买指定商品
|
|
|
- if (condition.goods_ids_array && condition.goods_ids_array.length > 0) {
|
|
|
- // 需要调用商品选择API来获取商品详情
|
|
|
- Controller.api.loadConditionGoods(condition.type, condition.goods_ids_array);
|
|
|
- }
|
|
|
- break;
|
|
|
- case 2: // 单笔订单消费满额
|
|
|
- case 3: // 单次充值满额
|
|
|
- case 4: // 活动期间累计消费满额
|
|
|
- var amountInput = $('input[name="condition[' + condition.type + '][condition_value]"]');
|
|
|
- if (amountInput.length > 0) {
|
|
|
- amountInput.val(condition.condition_value);
|
|
|
- }
|
|
|
- break;
|
|
|
+ // 勾选对应的任务类型
|
|
|
+ var checkbox = $('input[name="row[task_type][]"][value="' + taskType + '"]');
|
|
|
+ if (checkbox.length > 0) {
|
|
|
+ checkbox.prop('checked', true);
|
|
|
+
|
|
|
+ // 显示对应的任务设置
|
|
|
+ $('#task-setting-' + taskType).show();
|
|
|
+
|
|
|
+ // 根据任务类型设置具体的数据
|
|
|
+ Controller.api.renderTaskSettingData(taskType, rule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新复选框样式
|
|
|
+ Controller.api.handleTaskTypeChange();
|
|
|
+ },
|
|
|
+
|
|
|
+ // 渲染任务设置数据
|
|
|
+ renderTaskSettingData: function(taskType, ruleData) {
|
|
|
+ console.log('渲染任务设置数据:', taskType, ruleData);
|
|
|
+
|
|
|
+ switch (parseInt(taskType)) {
|
|
|
+ case 1: // 购买指定商品
|
|
|
+ // 设置商品规则
|
|
|
+ if (ruleData.goods_rule) {
|
|
|
+ $('input[name="condition[' + taskType + '][goods_rule]"][value="' + ruleData.goods_rule + '"]').prop('checked', true);
|
|
|
+ Controller.api.updateGoodsRuleDisplay($('input[name="condition[' + taskType + '][goods_rule]"]:checked'));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置商品选择
|
|
|
+ if (ruleData.goods_ids) {
|
|
|
+ var goodsIds = JSON.parse(ruleData.goods_ids || '[]');
|
|
|
+ if (goodsIds.length > 0) {
|
|
|
+ // 更新隐藏字段
|
|
|
+ $('#task-goods-ids-' + taskType).val(ruleData.goods_ids);
|
|
|
+
|
|
|
+ // 调用商品信息API来渲染商品列表
|
|
|
+ Controller.api.loadAndRenderTaskGoods(taskType, goodsIds);
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
- console.log('条件数据初始化完成');
|
|
|
- } else {
|
|
|
- console.log('没有找到已有的条件数据');
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 2: // 单笔订单消费满额
|
|
|
+ case 3: // 单次充值满额
|
|
|
+ case 4: // 活动期间累计消费满额
|
|
|
+ // 设置条件值
|
|
|
+ if (ruleData.condition_value) {
|
|
|
+ var amountInput = $('input[name="condition[' + taskType + '][condition_value]"]');
|
|
|
+ if (amountInput.length > 0) {
|
|
|
+ amountInput.val(ruleData.condition_value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- // 加载条件中的商品数据
|
|
|
- loadConditionGoods: function(taskType, goodsIds) {
|
|
|
+ // 加载并渲染任务商品
|
|
|
+ loadAndRenderTaskGoods: function(taskType, goodsIds) {
|
|
|
if (!goodsIds || goodsIds.length === 0) return;
|
|
|
|
|
|
+ console.log('加载任务商品数据:', taskType, goodsIds);
|
|
|
+
|
|
|
// 调用商品信息API
|
|
|
$.ajax({
|
|
|
- url: 'shop/goods/info',
|
|
|
+ url: Fast.api.fixurl('shop/goods/info'),
|
|
|
type: 'POST',
|
|
|
data: {
|
|
|
ids: goodsIds.join(',')
|
|
@@ -603,21 +768,41 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
if (ret.code === 1 && ret.data && ret.data.length > 0) {
|
|
|
// 更新商品显示
|
|
|
Controller.api.updateSelectedGoods(ret.data, {
|
|
|
- container: '#task-setting-' + taskType + ' #selected-goods',
|
|
|
+ container: '#selected-goods',
|
|
|
template: 'goods-list-template'
|
|
|
});
|
|
|
|
|
|
- // 更新隐藏字段
|
|
|
- $('#task-goods-ids-' + taskType).val(JSON.stringify(goodsIds));
|
|
|
+ // 绑定删除事件
|
|
|
+ Controller.api.bindTaskGoodsEvents();
|
|
|
|
|
|
- console.log('任务商品数据加载完成:', ret.data);
|
|
|
+ console.log('任务商品数据渲染完成:', ret.data);
|
|
|
+ } else {
|
|
|
+ console.warn('加载任务商品数据失败:', ret);
|
|
|
+ // 显示友好的错误提示
|
|
|
+ $('#selected-goods').html(
|
|
|
+ '<div class="alert alert-warning" style="margin-top: 10px;">' +
|
|
|
+ '<i class="fa fa-warning"></i> 部分商品数据加载失败,请重新选择商品' +
|
|
|
+ '</div>'
|
|
|
+ );
|
|
|
}
|
|
|
},
|
|
|
error: function(xhr, status, error) {
|
|
|
console.error('加载任务商品数据失败:', error);
|
|
|
+ $('#selected-goods').html(
|
|
|
+ '<div class="alert alert-danger" style="margin-top: 10px;">' +
|
|
|
+ '<i class="fa fa-exclamation-circle"></i> 商品数据加载失败,请检查网络连接' +
|
|
|
+ '</div>'
|
|
|
+ );
|
|
|
}
|
|
|
});
|
|
|
- },
|
|
|
+ },
|
|
|
+
|
|
|
+ // 初始化已有的条件数据(已合并到initExistingRules中)
|
|
|
+ initExistingConditions: function() {
|
|
|
+ console.log('条件数据初始化已合并到规则数据管理器中');
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
// 验证任务规则设置
|
|
@@ -686,12 +871,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
|
|
|
// 添加奖品
|
|
|
addPrize: function() {
|
|
|
- var totalCount = $('.prize-item').length; // 总奖品数(包含未中奖项)
|
|
|
- var userCount = totalCount - 1; // 用户添加的奖品数(减去未中奖项)
|
|
|
- var maxUserCount = 7; // 用户最多只能添加7个奖品(总共8个,包括系统默认的未中奖项)
|
|
|
+ var totalCount = $('.prize-item').length; // 总奖品数
|
|
|
+ var maxCount = 10; // 最多10个奖品
|
|
|
|
|
|
- if (userCount >= maxUserCount) {
|
|
|
- Toastr.error('最多只能添加' + maxUserCount + '个奖品(不包括系统默认的未中奖项)');
|
|
|
+ if (totalCount >= maxCount) {
|
|
|
+ Toastr.error('最多只能添加' + maxCount + '个奖品');
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -717,7 +901,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
mode: 'add', // 'add' 或 'edit'
|
|
|
title: '奖品表单',
|
|
|
prizeItem: null,
|
|
|
- isSystemNoPrize: false,
|
|
|
data: {
|
|
|
name: '',
|
|
|
image: '',
|
|
@@ -730,13 +913,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
var config = $.extend({}, defaults, options);
|
|
|
var isEditMode = config.mode === 'edit';
|
|
|
|
|
|
- // 获取奖品类型数据
|
|
|
+ // 获取奖品类型数据 - 显示所有可用类型
|
|
|
var prizeTypeMap = Controller.api.parseConfigJson('prizeTypeList', {});
|
|
|
var prizeTypes = [];
|
|
|
|
|
|
for (var key in prizeTypeMap) {
|
|
|
if (prizeTypeMap.hasOwnProperty(key)) {
|
|
|
- // 添加模式和编辑模式都包含所有类型
|
|
|
prizeTypes.push({
|
|
|
value: parseInt(key),
|
|
|
text: prizeTypeMap[key]
|
|
@@ -756,7 +938,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
selectedType: selectedType
|
|
|
});
|
|
|
|
|
|
- // 弹出表单 - 学习提供的样式代码
|
|
|
+ // 弹出表单
|
|
|
Layer.open({
|
|
|
type: 1,
|
|
|
title: config.title,
|
|
@@ -772,15 +954,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
// 编辑模式需要设置表单数据
|
|
|
if (isEditMode) {
|
|
|
Controller.api.setFormData($form, config);
|
|
|
-
|
|
|
- // 系统默认未中奖项的特殊处理
|
|
|
- if (config.isSystemNoPrize) {
|
|
|
- // 隐藏奖品数量字段(未中奖不需要数量)
|
|
|
- $form.find('.prize-quantity-group').hide();
|
|
|
- $form.find('[data-favisible="prize_type!=1"]').hide();
|
|
|
- // 禁用奖品类型选择(固定为未中奖)
|
|
|
- $form.find('input[name="row[prize_type]"]').prop('disabled', true);
|
|
|
- }
|
|
|
} else {
|
|
|
// 添加模式:设置默认奖品类型并触发相应逻辑
|
|
|
var defaultType = selectedType || 2; // 默认实物奖品
|
|
@@ -1386,6 +1559,51 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
return prizeData;
|
|
|
},
|
|
|
|
|
|
+ // 统一的奖品数据处理方法
|
|
|
+ processPrizeData: function(formData) {
|
|
|
+ var prizeData = {
|
|
|
+ name: formData.name || '',
|
|
|
+ type: parseInt(formData.type) || 1,
|
|
|
+ image: formData.image || '',
|
|
|
+ description: formData.description || '',
|
|
|
+ quantity: parseInt(formData.quantity) || 0,
|
|
|
+ rate: parseFloat(formData.rate) || 0
|
|
|
+ };
|
|
|
+
|
|
|
+ // 未中奖项的特殊处理
|
|
|
+ if (prizeData.type === 1) {
|
|
|
+ prizeData.quantity = 0;
|
|
|
+ prizeData.rate = prizeData.rate || 50; // 默认50%概率
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据奖品类型设置特定字段
|
|
|
+ switch (prizeData.type) {
|
|
|
+ case 3: // 积分
|
|
|
+ prizeData.points = parseInt(formData.points) || 0;
|
|
|
+ break;
|
|
|
+ case 4: // 余额
|
|
|
+ prizeData.balance = parseFloat(formData.balance) || 0;
|
|
|
+ break;
|
|
|
+ case 5: // 优惠券
|
|
|
+ prizeData.coupon_id = formData.coupon_id || '';
|
|
|
+ prizeData.coupon_name = formData.coupon_name || '';
|
|
|
+ break;
|
|
|
+ case 6: // 红包
|
|
|
+ prizeData.redpack_amount = parseFloat(formData.redpack_amount) || 0;
|
|
|
+ break;
|
|
|
+ case 7: // 兑换码
|
|
|
+ prizeData.code_type = formData.code_type || 'auto';
|
|
|
+ prizeData.manual_codes = formData.manual_codes || '';
|
|
|
+ break;
|
|
|
+ case 8: // 商城奖品
|
|
|
+ prizeData.goods_id = formData.goods_id || '';
|
|
|
+ prizeData.goods_name = formData.goods_name || '';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return prizeData;
|
|
|
+ },
|
|
|
+
|
|
|
// 添加奖品到列表(编辑模式用)
|
|
|
addPrizeToList: function(prize, index) {
|
|
|
// 获取奖品类型信息
|
|
@@ -1400,9 +1618,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
var imageRelative = prize.image; // 相对路径,用于表单提交
|
|
|
var imageDisplay = prize.image ? (typeof Fast !== 'undefined' && Fast.api ? Fast.api.cdnurl(prize.image) : prize.image) : ''; // CDN URL,用于显示
|
|
|
|
|
|
- // 判断是否为系统奖品(未中奖类型)
|
|
|
- var isSystemPrize = Controller.api.isNoPrizeType(prize.type);
|
|
|
-
|
|
|
// 生成唯一的奖品ID
|
|
|
var prizeId = prize.id || ('prize_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9));
|
|
|
|
|
@@ -1410,7 +1625,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
var prizeHtml = Template('prize-item-template', {
|
|
|
index: prizeIndex,
|
|
|
prizeId: prizeId,
|
|
|
- prizeType: isSystemPrize ? 'no-prize' : prize.type, // 系统默认项使用特殊标识
|
|
|
+ prizeType: prize.type, // 直接使用奖品类型
|
|
|
name: prize.name, // 奖品名称
|
|
|
description: prize.description || '', // 奖品描述
|
|
|
type: prize.type, // 奖品类型
|
|
@@ -1421,12 +1636,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
quantity: prize.quantity || 0, // 奖品数量
|
|
|
showQuantity: !Controller.api.isNoPrizeType(prize.type), // 是否显示数量
|
|
|
rate: parseFloat(prize.rate || 0).toFixed(2), // 确保概率值格式化为两位小数
|
|
|
- isSystemPrize: isSystemPrize // 是否为系统奖品
|
|
|
+ isSystemPrize: false // 移除系统奖品概念
|
|
|
});
|
|
|
|
|
|
$('.prize-list').append(prizeHtml);
|
|
|
|
|
|
- console.log('已添加奖品到列表:', prize.name, '索引:', prizeIndex, '系统奖品:', isSystemPrize, '数据:', prize);
|
|
|
+ console.log('已添加奖品到列表:', prize.name, '类型:', typeName);
|
|
|
},
|
|
|
|
|
|
// 添加奖品到列表(新增模式用)- 重构版
|
|
@@ -1460,7 +1675,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
quantity: prize.quantity || 0, // 奖品数量
|
|
|
showQuantity: !Controller.api.isNoPrizeType(prize.type), // 是否显示数量
|
|
|
rate: parseFloat(prize.rate || 0).toFixed(2), // 确保概率值格式化为两位小数
|
|
|
- isSystemPrize: false // 用户添加的奖品非系统奖品
|
|
|
+ isSystemPrize: false // 移除系统奖品概念
|
|
|
});
|
|
|
|
|
|
$('.prize-list').append(prizeHtml);
|
|
@@ -1477,101 +1692,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
initDefaultPrizeRate: function() {
|
|
|
console.log('=== 开始初始化奖品概率值 ===');
|
|
|
|
|
|
- // 检查整个表格结构
|
|
|
- var prizeTable = $('.prize-list');
|
|
|
- console.log('奖品表格查找结果:', prizeTable.length > 0);
|
|
|
- if (prizeTable.length > 0) {
|
|
|
- console.log('奖品表格HTML:', prizeTable.html().substring(0, 500) + '...');
|
|
|
- }
|
|
|
-
|
|
|
- // 检查所有概率输入框
|
|
|
- var allRateInputs = $('.prize-rate');
|
|
|
- console.log('找到的所有概率输入框数量:', allRateInputs.length);
|
|
|
-
|
|
|
- // 使用更精确的选择器
|
|
|
- var noPrizeInput = $('#no-prize-rate-input');
|
|
|
- console.log('通过ID查找默认未中奖项输入框:', {
|
|
|
- found: noPrizeInput.length > 0,
|
|
|
- value: noPrizeInput.val(),
|
|
|
- visible: noPrizeInput.is(':visible'),
|
|
|
- display: noPrizeInput.css('display'),
|
|
|
- visibility: noPrizeInput.css('visibility')
|
|
|
- });
|
|
|
-
|
|
|
- // 通过class查找
|
|
|
- var noPrizeInputByClass = $('.prize-item[data-type="no-prize"] .prize-rate');
|
|
|
- console.log('通过class查找默认未中奖项输入框:', {
|
|
|
- found: noPrizeInputByClass.length > 0,
|
|
|
- value: noPrizeInputByClass.val(),
|
|
|
- visible: noPrizeInputByClass.is(':visible')
|
|
|
- });
|
|
|
-
|
|
|
- // 检查所有奖品行
|
|
|
- var prizeRows = $('.prize-item');
|
|
|
- console.log('找到的奖品行数量:', prizeRows.length);
|
|
|
- prizeRows.each(function(index) {
|
|
|
- var $row = $(this);
|
|
|
- var dataType = $row.attr('data-type');
|
|
|
- var rateInput = $row.find('.prize-rate');
|
|
|
- console.log('奖品行 ' + index + ':', {
|
|
|
- dataType: dataType,
|
|
|
- hasRateInput: rateInput.length > 0,
|
|
|
- rateInputValue: rateInput.val(),
|
|
|
- rateInputVisible: rateInput.is(':visible'),
|
|
|
- rowHTML: $row.html().substring(0, 200) + '...'
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- // 确保系统默认未中奖项有正确的概率值
|
|
|
- var defaultPrizeRateInput = noPrizeInput.length > 0 ? noPrizeInput : noPrizeInputByClass;
|
|
|
- if (defaultPrizeRateInput.length > 0) {
|
|
|
- var currentValue = defaultPrizeRateInput.val();
|
|
|
- console.log('当前默认概率值:', currentValue);
|
|
|
- if (!currentValue || currentValue === '' || parseFloat(currentValue) === 0) {
|
|
|
- defaultPrizeRateInput.val('50.00');
|
|
|
- console.log('设置系统默认未中奖项概率为50.00%');
|
|
|
- }
|
|
|
-
|
|
|
- // 强制确保可见性
|
|
|
- defaultPrizeRateInput.show().css({
|
|
|
- 'display': 'inline-block',
|
|
|
- 'visibility': 'visible',
|
|
|
- 'opacity': '1'
|
|
|
- });
|
|
|
- } else {
|
|
|
- console.log('⚠️ 警告: 未找到系统默认未中奖项的概率输入框!');
|
|
|
-
|
|
|
- // 尝试创建缺失的输入框
|
|
|
- var noPrizeRow = $('tr[data-type="no-prize"]');
|
|
|
- if (noPrizeRow.length > 0) {
|
|
|
- console.log('找到未中奖行,检查其结构...');
|
|
|
- var rateTd = noPrizeRow.find('td').eq(5); // 概率列
|
|
|
- console.log('概率列内容:', rateTd.html());
|
|
|
-
|
|
|
- // 如果概率列只有%符号,重新构建
|
|
|
- if (rateTd.text().trim() === '%') {
|
|
|
- console.log('发现概率列只有%符号,重新构建input...');
|
|
|
- rateTd.html(
|
|
|
- '<div class="input-group" style="width: 100px; margin: 0 auto;">' +
|
|
|
- '<input type="number" class="form-control input-sm prize-rate text-center" name="prizes[0][rate]" id="no-prize-rate-input" value="50.00" min="0" max="100" step="0.01">' +
|
|
|
- '<span class="input-group-addon" style="padding: 4px 6px;">%</span>' +
|
|
|
- '</div>'
|
|
|
- );
|
|
|
- console.log('重新构建完成');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// 确保所有奖品概率输入框都有默认值
|
|
|
$('.prize-rate').each(function() {
|
|
|
var $this = $(this);
|
|
|
var currentValue = $this.val();
|
|
|
if (!currentValue || currentValue === '') {
|
|
|
- if ($this.attr('id') === 'no-prize-rate-input') {
|
|
|
- $this.val('50.00');
|
|
|
- } else {
|
|
|
- $this.val('0.00');
|
|
|
- }
|
|
|
+ $this.val('0.00'); // 所有奖品默认概率为0
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -1621,12 +1747,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
var $item = $(this).closest('.prize-item');
|
|
|
var index = parseInt($item.attr('data-index'));
|
|
|
|
|
|
- // 检查是否是系统默认项
|
|
|
- if ($item.attr('data-type') === 'no-prize') {
|
|
|
- Toastr.error('系统默认的未中奖项不能删除');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+ // 直接删除奖品,不再有系统默认项的限制
|
|
|
Controller.api.deletePrizeByIndex(index);
|
|
|
});
|
|
|
|
|
@@ -1661,16 +1782,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 判断是否为系统默认未中奖项
|
|
|
- var isSystemNoPrize = Controller.api.isNoPrizeType(prizeData.type);
|
|
|
- var title = isSystemNoPrize ? '编辑未中奖项' : '编辑奖品';
|
|
|
-
|
|
|
// 使用通用表单,编辑模式
|
|
|
Controller.api.openPrizeForm({
|
|
|
mode: 'edit',
|
|
|
- title: title,
|
|
|
+ title: '编辑奖品',
|
|
|
prizeIndex: index,
|
|
|
- isSystemNoPrize: isSystemNoPrize,
|
|
|
data: prizeData
|
|
|
});
|
|
|
},
|
|
@@ -1691,7 +1807,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
// 重新初始化拖拽排序
|
|
|
Controller.api.initPrizeSort();
|
|
|
|
|
|
- console.log('奖品列表已重新构建');
|
|
|
+ console.log('奖品列表已重新构建,共', allPrizes.length, '个奖品');
|
|
|
},
|
|
|
|
|
|
// 奖品数据管理 - 使用单一JSON隐藏域
|
|
@@ -1718,6 +1834,27 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
this.loadFromHiddenField();
|
|
|
},
|
|
|
|
|
|
+ // 验证奖品数据
|
|
|
+ validatePrizeData: function(prizeData) {
|
|
|
+ if (!prizeData.name || prizeData.name.trim() === '') {
|
|
|
+ throw new Error('奖品名称不能为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!prizeData.type || !Controller.api.getAvailablePrizeTypes()[prizeData.type]) {
|
|
|
+ throw new Error('请选择正确的奖品类型');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (prizeData.type != 1 && (!prizeData.quantity || prizeData.quantity <= 0)) {
|
|
|
+ throw new Error('奖品数量必须大于0');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (prizeData.rate < 0 || prizeData.rate > 100) {
|
|
|
+ throw new Error('中奖概率必须在0-100之间');
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+
|
|
|
// 从隐藏域加载数据
|
|
|
loadFromHiddenField: function() {
|
|
|
var jsonData = $('#prizes-data-json').val();
|
|
@@ -1738,8 +1875,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
|
|
|
// 添加奖品
|
|
|
addPrize: function(prizeData) {
|
|
|
+ // 验证奖品数据
|
|
|
+ this.validatePrizeData(prizeData);
|
|
|
+
|
|
|
// 生成唯一ID
|
|
|
prizeData.id = 'prize_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
|
|
|
+
|
|
|
+ // 设置默认值
|
|
|
+ prizeData.description = prizeData.description || '';
|
|
|
+ prizeData.sort_order = this.prizesData.length;
|
|
|
+
|
|
|
this.prizesData.push(prizeData);
|
|
|
this.saveToHiddenField();
|
|
|
return prizeData.id;
|
|
@@ -1748,8 +1893,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
// 更新奖品
|
|
|
updatePrize: function(index, prizeData) {
|
|
|
if (index >= 0 && index < this.prizesData.length) {
|
|
|
- // 保持原有ID
|
|
|
+ // 验证奖品数据
|
|
|
+ this.validatePrizeData(prizeData);
|
|
|
+
|
|
|
+ // 保持原有ID和排序
|
|
|
prizeData.id = this.prizesData[index].id;
|
|
|
+ prizeData.sort_order = this.prizesData[index].sort_order;
|
|
|
+
|
|
|
+ // 设置默认值
|
|
|
+ prizeData.description = prizeData.description || '';
|
|
|
+
|
|
|
this.prizesData[index] = prizeData;
|
|
|
this.saveToHiddenField();
|
|
|
return true;
|
|
@@ -1868,6 +2021,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
return prizeTypeMap[type] || '未知';
|
|
|
},
|
|
|
|
|
|
+ // 获取可用的奖品类型(显示所有奖品类型)
|
|
|
+ getAvailablePrizeTypes: function() {
|
|
|
+ // 返回所有奖品类型,不再限制
|
|
|
+ return Controller.api.parseConfigJson('prizeTypeList', {});
|
|
|
+ },
|
|
|
+
|
|
|
// 获取奖品标签样式类
|
|
|
getPrizeLabelClass: function(type) {
|
|
|
var classMap = {
|
|
@@ -1969,46 +2128,43 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
|
|
|
// 更新奖品数量统计
|
|
|
updatePrizeCount: function() {
|
|
|
- var totalCount = $('.prize-item').length; // 总奖品数(包含未中奖项)
|
|
|
- var userCount = totalCount - 1; // 用户添加的奖品数(减去未中奖项)
|
|
|
+ // 从数据管理器获取准确的奖品数量
|
|
|
+ var totalCount = Controller.api.prizesDataManager.prizesData.length;
|
|
|
|
|
|
- console.log('updatePrizeCount - 总奖品数:', totalCount, '用户添加数:', userCount);
|
|
|
+ console.log('updatePrizeCount - 总奖品数:', totalCount);
|
|
|
|
|
|
- // 显示总奖品数(包含系统默认的未中奖项)
|
|
|
+ // 显示总奖品数
|
|
|
$('#prize-count').text(totalCount);
|
|
|
|
|
|
- // 更新添加奖品按钮状态(基于用户可添加的奖品数)
|
|
|
- Controller.api.updateAddPrizeButtonState(userCount);
|
|
|
+ // 更新添加奖品按钮状态
|
|
|
+ Controller.api.updateAddPrizeButtonState(totalCount);
|
|
|
},
|
|
|
|
|
|
// 更新添加奖品按钮状态
|
|
|
- updateAddPrizeButtonState: function(userCount) {
|
|
|
- var maxUserCount = 7; // 用户最大可添加奖品数量(总共8个,包括系统默认的未中奖项)
|
|
|
+ updateAddPrizeButtonState: function(totalCount) {
|
|
|
+ var maxCount = 10; // 最大奖品数量
|
|
|
var addButton = $('#add-prize-btn');
|
|
|
- var remainingCount = maxUserCount - userCount;
|
|
|
+ var remainingCount = maxCount - totalCount;
|
|
|
|
|
|
- console.log('updateAddPrizeButtonState - 用户奖品数:', userCount, '最大允许:', maxUserCount, '剩余:', remainingCount);
|
|
|
+ console.log('updateAddPrizeButtonState - 奖品数:', totalCount, '最大允许:', maxCount, '剩余:', remainingCount);
|
|
|
|
|
|
- if (userCount >= maxUserCount) {
|
|
|
+ if (totalCount >= maxCount) {
|
|
|
// 达到最大数量,禁用按钮
|
|
|
addButton.prop('disabled', true).addClass('disabled');
|
|
|
addButton.find('.btn-text').text('已达最大数量');
|
|
|
- $('#prize-count-tip').text('已添加最大数量的奖品').removeClass('text-muted').addClass('text-danger');
|
|
|
+ // 更新按钮计数显示
|
|
|
+ addButton.html('<i class="fa fa-plus"></i> 添加奖品 (10/10)');
|
|
|
+ $('#prize-count-tip').text('已添加最大数量的奖品(' + maxCount + '个)').removeClass('text-muted').addClass('text-danger');
|
|
|
console.log('按钮已禁用 - 达到最大数量');
|
|
|
} else {
|
|
|
// 未达到最大数量,启用按钮
|
|
|
addButton.prop('disabled', false).removeClass('disabled');
|
|
|
- addButton.find('.btn-text').text('添加奖品');
|
|
|
+ // 更新按钮计数显示
|
|
|
+ addButton.html('<i class="fa fa-plus"></i> 添加奖品 (' + totalCount + '/10)');
|
|
|
if (remainingCount <= 2) {
|
|
|
$('#prize-count-tip').text('还可添加 ' + remainingCount + ' 个奖品').removeClass('text-muted text-danger').addClass('text-warning');
|
|
|
} else {
|
|
|
- // 当用户还没添加奖品时,显示还需添加多少个才能满足最低要求
|
|
|
- var minRequired = Math.max(0, maxUserCount - userCount); // 需要添加的奖品数量
|
|
|
- if (minRequired > 0) {
|
|
|
- $('#prize-count-tip').text('还需添加 ' + minRequired + ' 个奖品').removeClass('text-warning text-danger').addClass('text-muted');
|
|
|
- } else {
|
|
|
- $('#prize-count-tip').text('还可添加 ' + remainingCount + ' 个奖品').removeClass('text-warning text-danger').addClass('text-muted');
|
|
|
- }
|
|
|
+ $('#prize-count-tip').text('还可添加 ' + remainingCount + ' 个奖品').removeClass('text-warning text-danger').addClass('text-muted');
|
|
|
}
|
|
|
console.log('按钮已启用 - 剩余数量:', remainingCount);
|
|
|
}
|
|
@@ -2206,14 +2362,15 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
Controller.api.selectGoods({
|
|
|
mode: 'multiple',
|
|
|
title: '选择参与商品',
|
|
|
- container: container || '#task-goods-container',
|
|
|
- template: 'task-goods-template',
|
|
|
+ container: container || '#selected-goods',
|
|
|
+ template: 'goods-list-template',
|
|
|
callback: function(data) {
|
|
|
- // 如果是购买指定商品任务,更新隐藏字段
|
|
|
+ // 如果是购买指定商品任务,更新隐藏字段和规则数据管理器
|
|
|
if (container === '#selected-goods' && data && data.length > 0) {
|
|
|
var goodsIds = data.map(function(item) {
|
|
|
return item.id;
|
|
|
});
|
|
|
+
|
|
|
// 更新隐藏字段,存储JSON格式的商品IDs
|
|
|
$('#task-goods-ids-1').val(JSON.stringify(goodsIds));
|
|
|
console.log('购买指定商品任务 - 商品IDs已更新:', goodsIds);
|
|
@@ -2383,11 +2540,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
$('<input>').attr({
|
|
|
type: 'hidden',
|
|
|
id: 'rules-data-json',
|
|
|
- name: 'rules_json',
|
|
|
+ name: 'conditions_json',
|
|
|
value: '{}',
|
|
|
- 'data-rule': 'required;rulesJson',
|
|
|
+ 'data-rule': 'required;conditionsJson',
|
|
|
'data-msg-required': '请设置至少一种参与条件',
|
|
|
- 'data-msg-rulesJson': '规则设置数据格式不正确'
|
|
|
+ 'data-msg-conditionsJson': '参与条件设置数据格式不正确'
|
|
|
}).appendTo('form[role="form"]');
|
|
|
}
|
|
|
|
|
@@ -2395,6 +2552,36 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
this.loadFromHiddenField();
|
|
|
},
|
|
|
|
|
|
+ // 验证规则数据
|
|
|
+ validateRuleData: function(type, ruleData) {
|
|
|
+ if (!ruleData.type || ruleData.type !== type) {
|
|
|
+ throw new Error('规则类型不匹配');
|
|
|
+ }
|
|
|
+
|
|
|
+ switch(parseInt(type)) {
|
|
|
+ case 1: // 购买指定商品
|
|
|
+ var goodsIds = JSON.parse(ruleData.goods_ids || '[]');
|
|
|
+ if (!goodsIds || goodsIds.length === 0) {
|
|
|
+ throw new Error('请选择参与商品');
|
|
|
+ }
|
|
|
+ if (!ruleData.goods_rule || (ruleData.goods_rule != 1 && ruleData.goods_rule != 2)) {
|
|
|
+ throw new Error('请选择商品规则');
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2: // 单笔订单消费满额
|
|
|
+ case 3: // 单次充值满额
|
|
|
+ case 4: // 活动期间累计消费满额
|
|
|
+ if (!ruleData.condition_value || parseFloat(ruleData.condition_value) <= 0) {
|
|
|
+ throw new Error('请输入有效的条件金额');
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new Error('无效的规则类型');
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+
|
|
|
// 从隐藏域加载数据
|
|
|
loadFromHiddenField: function() {
|
|
|
var jsonData = $('#rules-data-json').val();
|
|
@@ -2413,8 +2600,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
console.log('规则数据已保存到隐藏域:', this.rulesData);
|
|
|
},
|
|
|
|
|
|
- // 更新规则数据
|
|
|
+ // 添加或更新规则数据
|
|
|
updateRule: function(type, ruleData) {
|
|
|
+ // 验证规则数据
|
|
|
+ this.validateRuleData(type, ruleData);
|
|
|
+
|
|
|
this.rulesData[type] = ruleData;
|
|
|
this.saveToHiddenField();
|
|
|
},
|
|
@@ -2433,6 +2623,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|
|
// 获取所有规则数据
|
|
|
getAllRules: function() {
|
|
|
return this.rulesData;
|
|
|
+ },
|
|
|
+
|
|
|
+ // 检查是否有规则数据
|
|
|
+ hasRules: function() {
|
|
|
+ return Object.keys(this.rulesData).length > 0;
|
|
|
+ },
|
|
|
+
|
|
|
+ // 清空所有规则
|
|
|
+ clearAllRules: function() {
|
|
|
+ this.rulesData = {};
|
|
|
+ this.saveToHiddenField();
|
|
|
}
|
|
|
},
|
|
|
|