good.js 627 B

12345678910111213141516171819202122232425
  1. import { cdnBase } from '../config/index';
  2. const imgPrefix = cdnBase;
  3. const defaultDesc = [`${imgPrefix}/goods/details-1.png`];
  4. const allGoods = [];
  5. /**
  6. * @param {string} id
  7. * @param {number} [available] 库存, 默认1
  8. */
  9. export function genGood(id, available = 1) {
  10. const specID = ['135681624', '135681628'];
  11. if (specID.indexOf(id) > -1) {
  12. return allGoods.filter((good) => good.spuId === id)[0];
  13. }
  14. const item = allGoods[id % allGoods.length];
  15. return {
  16. ...item,
  17. spuId: `${id}`,
  18. available: available,
  19. desc: item?.desc || defaultDesc,
  20. images: item?.images || [item?.primaryImage],
  21. };
  22. }