商品选择功能现在支持通过最后一列的"选择"按钮来控制单选和多选模式,提供了更直观的用户体验。
Fast.api.open('shop/goods/select?selectMode=single', '选择商品', {
callback: function(data) {
if (data.length > 0) {
var goods = data[0];
console.log('选中的商品:', goods);
// 处理选中的商品
}
}
});
Fast.api.open('shop/goods/select?selectMode=multiple', '选择商品', {
callback: function(data) {
if (data.length > 0) {
console.log('选中的商品列表:', data);
// 处理选中的商品列表
}
}
});
Fast.api.open('shop/goods/select?selectMode=multiple&maxSelect=5', '选择商品(最多5个)', {
callback: function(data) {
if (data.length > 0) {
console.log('选中的商品列表:', data);
// 处理选中的商品列表
}
}
});
// 单选商品(奖品场景)
Controller.api.selectPrizeGoods('#prize-goods-container');
// 多选商品(任务场景)
Controller.api.selectTaskGoods('#task-goods-container');
// 通用商品选择
Controller.api.selectGoods({
mode: 'single', // 'single' 或 'multiple'
title: '选择商品',
container: '#selected-goods',
maxSelect: 0, // 最大选择数量,0表示无限制
callback: function(data) {
// 处理选中的商品
}
});
参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
selectMode | string | multiple | 选择模式:single(单选) 或 multiple(多选) |
maxSelect | number | 0 | 最大选择数量,仅在多选模式下有效,0表示无限制 |
相比之前的版本,新版本有以下重要变更:
注意:单选和多选模式现在使用相同的显示样式模板
┌─────────────────────────────────────────────────┐
│ [图片] [标签]商品名称 删除 │
│ ¥价格 [单规格/多规格] │
│ 编码: xxx | 分类: xxx | 类型: xxx │
└─────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────┐
│ [图片] [标签]商品名称1 删除 │
│ ¥价格1 [单规格/多规格] │
│ 编码: xxx | 分类: xxx | 类型: xxx │
├─────────────────────────────────────────────────┤
│ [图片] [标签]商品名称2 删除 │
│ ¥价格2 [单规格/多规格] │
│ 编码: xxx | 分类: xxx | 类型: xxx │
├─────────────────────────────────────────────────┤
│ [图片] [标签]商品名称3 删除 │
│ ¥价格3 [单规格/多规格] │
│ 编码: xxx | 分类: xxx | 类型: xxx │
└─────────────────────────────────────────────────┘
系统会根据商品属性自动显示相应的彩色标签:
注意:模板会根据选择的商品数量自动判断字段名
选中的商品会生成以下隐藏字段:
<input type="hidden" name="goods_id" value="商品ID" />
选中的商品会生成以下隐藏字段:
<input type="hidden" name="task_goods_ids[]" value="商品ID1" />
<input type="hidden" name="task_goods_ids[]" value="商品ID2" />
<input type="hidden" name="task_goods_ids[]" value="商品ID3" />
Controller.api.selectGoods({
mode: 'single', // 选择模式:single/multiple
title: '自定义标题', // 弹窗标题
container: '#my-container', // 显示容器
template: 'my-template', // 使用的模板
maxSelect: 5, // 最大选择数量(仅多选模式有效),0表示无限制
callback: function(data) { // 选择完成后的回调
console.log('选中的商品:', data);
}
});
系统通过URL参数控制商品选择器的行为:
selectMode=single
- 单选模式,显示单选按钮selectMode=multiple
- 多选模式,显示复选框(默认)maxSelect=N
- 最大选择数量限制(仅多选模式有效)// 单选商品(奖品选择)
Controller.api.selectGoods({
mode: 'single',
title: '选择奖品商品',
container: '#prize-goods',
template: 'goods-list-template'
});
// 多选商品(任务商品,最多3个)
Controller.api.selectGoods({
mode: 'multiple',
title: '选择参与商品',
container: '#task-goods',
template: 'goods-list-template',
maxSelect: 3
});
// 无限制多选
Controller.api.selectGoods({
mode: 'multiple',
title: '选择商品',
container: '#goods-list',
template: 'goods-list-template'
});
// 获取单选商品ID
var goodsId = $('input[name="goods_id"]').val();
// 获取多选商品ID数组
var taskGoodsIds = [];
$('input[name="task_goods_ids[]"]').each(function() {
taskGoodsIds.push($(this).val());
});
系统现在统一使用一个商品显示模板:
统一使用: goods-list-template
模板,它支持单选和多选两种模式,会根据商品数量自动生成正确的表单字段。
模板中每个商品对象包含以下字段:
{
id: '商品ID',
name: '商品名称',
title: '商品标题',
image: '商品图片URL(已处理CDN)',
price: '商品价格',
goods_sn: '商品编码',
spec_type: '规格类型(0=单规格,1=多规格)',
category: {name: '分类名称'},
type_name: '商品类型名称',
type_text: '商品标签文本(热、新、荐、密等)'
}
如需自定义显示样式,可以修改对应的模板文件:
application/admin/view/lottery/activity/scripttpl.html
选择器通过以下URL参数控制行为:
shop/goods/select?selectMode=single // 单选
shop/goods/select?selectMode=multiple // 多选
shop/goods/select?selectMode=multiple&maxSelect=5 // 多选,最多5个
// 单选模式
{
field: 'state',
radio: true
}
// 多选模式
{
checkbox: true
}
// 多选数量限制控制
table.on('check.bs.table check-all.bs.table', function (e, row) {
// 检查选择数量并控制
});