index.sjs 808 B

123456789101112131415161718192021222324252627282930313233343536
  1. // 获得购物车商品总数
  2. const getCarTotalNum = carList => {
  3. let total = 0;
  4. carList.forEach(v => (total += +v.quantity));
  5. return total;
  6. };
  7. // 获取商品列表
  8. const getGoodsList = (anchor = '', list = []) => {
  9. const newList = list.find(anchorList => {
  10. if (anchorList.length) {
  11. return anchor === anchorList[0].anchor;
  12. }
  13. return false;
  14. });
  15. return newList;
  16. };
  17. // 得到分类标签下 name
  18. const getCategoryName = (list, index) => {
  19. const { title = '' } = list[index];
  20. return title;
  21. };
  22. const getCarItemNum = (car, item) => {
  23. const { carts = [] } = car;
  24. const findInCar = carts.find(v => v.skuId === item.skuId);
  25. if (findInCar) {
  26. return findInCar.quantity || 0;
  27. }
  28. };
  29. export default {
  30. getGoodsList,
  31. getCarTotalNum,
  32. getCarItemNum,
  33. getCategoryName,
  34. };