记得上下班打卡 | git大法好,push需谨慎

Commit 576523ac authored by 姜秀龙's avatar 姜秀龙

收钱吧 admin假数据去掉

parent a7bad411
......@@ -75,20 +75,12 @@
// 内存中维护已关联商品列表
var linkedGoods = [];
// ——— mock 数据(接口无数据时用于测试)———
var MOCK_GOODS = [
{ skuId: 'SKU_MOCK_001', spuId: 'SPU_MOCK_001', spuName: '收钱吧周边T恤', skuName: '收钱吧周边T恤 M码', price: 9900, stock: 100, coverPic: '' },
{ skuId: 'SKU_MOCK_002', spuId: 'SPU_MOCK_002', spuName: '演出纪念手册', skuName: '演出纪念手册 精装版',price: 4900, stock: 200, coverPic: '' },
{ skuId: 'SKU_MOCK_003', spuId: 'SPU_MOCK_003', spuName: '限定徽章套装', skuName: '限定徽章套装 五件套', price: 3900, stock: 50, coverPic: '' },
{ skuId: 'SKU_MOCK_004', spuId: 'SPU_MOCK_004', spuName: '摇滚帽子', skuName: '摇滚帽子 黑色', price: 5900, stock: 80, coverPic: '' },
];
$(function () {
initSelect2();
loadLinkedGoods();
});
// 初始化 Select2(AJAX 搜索 + mock fallback
// 初始化 Select2(AJAX 搜索)
function initSelect2() {
$('#goodsSelect').select2({
allowClear: true,
......@@ -102,17 +94,9 @@
data: function (params) { return { keyword: params.term || '' }; },
processResults: function (resp) {
var list = (resp && resp.data) ? resp.data : [];
// 接口无数据时回退到 mock
if (list.length === 0) { list = filterMock($('#goodsSelect').data('select2').options.get('ajax').data({ term: '' }).keyword); }
return { results: list.map(function (item) {
return { id: item.skuId, text: (item.title || item.spuName || item.skuName), _raw: item };
})};
},
error: function () {
// 接口异常时使用 mock
return { results: MOCK_GOODS.map(function (item) {
return { id: item.skuId, text: item.spuName, _raw: item };
})};
}
}
});
......@@ -120,28 +104,10 @@
// 选中即添加
$('#goodsSelect').on('select2:select', function (e) {
var raw = e.params.data._raw;
if (!raw) {
// 兼容:从 mock 中找
raw = MOCK_GOODS.find(function(m){ return m.skuId === e.params.data.id; });
}
if (raw) { addLinked(raw); }
// 清空选择框
$(this).val(null).trigger('change');
});
// 若 ajax 报错或首次打开无关键词,预填 mock
$('#goodsSelect').on('select2:open', function () {
// 触发一次搜索以显示 mock 数据
setTimeout(function () {
var searchInput = document.querySelector('.select2-search__field');
if (searchInput) { $(searchInput).trigger('input'); }
}, 100);
});
}
function filterMock(keyword) {
if (!keyword) return MOCK_GOODS;
return MOCK_GOODS.filter(function (m) { return m.spuName.indexOf(keyword) >= 0; });
}
// 加载已关联商品
......@@ -234,7 +200,7 @@
}
// 未入库(本次新增、未保存)直接从页面移除
if (!item.persisted || (item.skuId && item.skuId.startsWith('SKU_MOCK_'))) {
if (!item.persisted) {
linkedGoods.splice(idx, 1);
renderLinkedGoods();
layer.msg('已从待保存列表移除');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment