// 获得购物车商品总数 const getCarTotalNum = carList => { let total = 0; carList.forEach(v => (total += +v.quantity)); return total; }; // 获取商品列表 const getGoodsList = (anchor = '', list = []) => { const newList = list.find(anchorList => { if (anchorList.length) { return anchor === anchorList[0].anchor; } return false; }); return newList; }; // 得到分类标签下 name const getCategoryName = (list, index) => { const { title = '' } = list[index]; return title; }; const getCarItemNum = (car, item) => { const { carts = [] } = car; const findInCar = carts.find(v => v.skuId === item.skuId); if (findInCar) { return findInCar.quantity || 0; } }; export default { getGoodsList, getCarTotalNum, getCarItemNum, getCategoryName, };