// 获得购物车中对应skuId商品总数 const getQuantity = (carList = [], skuId = 0) => { const carIndex = carList.findIndex(v => v.skuId === skuId); return carIndex !== -1 ? carList[carIndex].quantity : 0; }; // 是否可买 // 参数 在售状态,库存状态,库存数量 限购 // params { status, stockStatus, stock } const isActive = (goodsItem) => { const { status, // 是否停售 stockStatus = 'N', // 是否有库存 stock = 0, buyLimitCount = 1, quantity = 0, buyLimitType = '', // 是否限购 } = goodsItem; // 不在售 if (status === 'N') { return false; } // 库存为 0 不能买 if (stockStatus === 'Y' && !stock) { return false; } // 限购了 if (buyLimitType === 'GENERAL' && quantity >= buyLimitCount) { return false; } return true; }; export default { isActive, getQuantity, };