fetchGoodsList.js 978 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* eslint-disable no-param-reassign */
  2. import { config } from '../../config/index';
  3. /** 获取商品列表 */
  4. function mockFetchGoodsList(params) {
  5. const { delay } = require('../_utils/delay');
  6. const { getSearchResult } = require('../../model/search');
  7. const data = getSearchResult(params);
  8. if (data.spuList.length) {
  9. data.spuList.forEach((item) => {
  10. item.spuId = item.spuId;
  11. item.thumb = item.primaryImage;
  12. item.title = item.title;
  13. item.price = item.minSalePrice;
  14. item.originPrice = item.maxLinePrice;
  15. item.desc = '';
  16. if (item.spuTagList) {
  17. item.tags = item.spuTagList.map((tag) => tag.title);
  18. } else {
  19. item.tags = [];
  20. }
  21. });
  22. }
  23. return delay().then(() => {
  24. return data;
  25. });
  26. }
  27. /** 获取商品列表 */
  28. export function fetchGoodsList(params) {
  29. if (config.useMock) {
  30. return mockFetchGoodsList(params);
  31. }
  32. return new Promise((resolve) => {
  33. resolve('real api');
  34. });
  35. }