购物车方法

157 阅读1分钟
  addCart() {
        //操作购物车得Array 将productDetailObj数据添加进去
        const { styles, total, totals, currentPrice, getCurrentProductPrice, totalPrice, preferential, productDetailObj, moboShoppingList, updateMoboShoppingList, productList, updateProductList } = this.props;
        let newShoppingData = [...moboShoppingList];
        newShoppingData.push(productDetailObj);
        const { mealItemId, menuId } = productDetailObj;
        let newProductList = [...productList];
        for (const item of newProductList) {
            if (item.mealItemId === mealItemId && item.menuId === menuId) {
                item.count += 1;
            }
        };
        updateProductList(newProductList);
        updateMoboShoppingList(newShoppingData);
        
        let totalPriceAdd = totals + currentPrice;
        totalPriceAdd = Math.floor(totalPriceAdd * 100) / 100;
        totalPrice(totalPriceAdd);
        console.log(totals, "totaltotaltotaltotaltotal");
        // console.log("newShoppingData", newShoppingData);
        console.log("支付得productDetailObj", productDetailObj);
        getCurrentProductPrice(0)
        this.props.history.push('/');
    }