Files
code-bang/frontend/miniapp/services/good/fetchGoodsList.js
T
2026-09-17 16:25:31 +08:00

39 lines
1018 B
JavaScript

/* eslint-disable no-param-reassign */
import { config } from '../../config/index';
import { GoodsList } from '../../config/api';
/** 获取商品列表 */
function mockFetchGoodsList(params) {
const { delay } = require('../_utils/delay');
const { getSearchResult } = require('../../model/search');
const data = getSearchResult(params);
if (data.spuList.length) {
data.spuList.forEach((item) => {
item.spuId = item.spuId;
item.thumb = item.primaryImage;
item.title = item.title;
item.price = item.minSalePrice;
item.originPrice = item.maxLinePrice;
item.desc = '';
if (item.spuTagList) {
item.tags = item.spuTagList.map((tag) => tag.title);
} else {
item.tags = [];
}
});
}
return delay().then(() => {
return data;
});
}
/** 获取商品列表 */
export function fetchGoodsList(params) {
if (config.useMock) {
return mockFetchGoodsList(params);
}
return wx.$util.request(wx.$api.GoodsList, params, 'GET');
}