From f7411ecf55024614facaeda7d58a227dcc0e4ac7 Mon Sep 17 00:00:00 2001 From: "jqtmviyu@gmail.com" Date: Fri, 5 Mar 2021 00:34:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=B1=9E=E6=80=A7:=201.=20?= =?UTF-8?q?=E5=85=A8=E9=80=89=E7=8A=B6=E6=80=81=202.=20=E6=80=BB=E4=BB=B7?= =?UTF-8?q?=203.=20=E6=80=BB=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/cart/cart.vue | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/pages/cart/cart.vue b/src/pages/cart/cart.vue index 0610a49..8a88e8e 100644 --- a/src/pages/cart/cart.vue +++ b/src/pages/cart/cart.vue @@ -18,8 +18,8 @@ 全选 合计: - 3999 - 去结算(12) + {{totalPrice}} + 去结算({{totalCount}}) @@ -29,13 +29,13 @@ export default { data(){ return { cartList: [], - selectAll: false + // selectAll: false } }, onShow() { const cartList = uni.getStorageSync("cartList") || []; this.cartList = cartList - this.selectAll = this.cartList.every(item=>item.goods_select === true) + // this.selectAll = this.cartList.every(item=>item.goods_select === true) }, methods: { // 商品选择按钮切换 @@ -46,7 +46,7 @@ export default { this.cartList[index].goods_select = !this.cartList[index].goods_select // 判断全选 - this.selectAll = this.cartList.every(item=>item.goods_select === true) + // this.selectAll = this.cartList.every(item=>item.goods_select === true) }, // 商品数量的增减 @@ -74,6 +74,33 @@ export default { uni.setStorageSync("cartList", val) } } + }, + // 计算属性 + computed: { + // 全选状态 + selectAll(){ + return this.cartList.every(item=>item.goods_select === true) + }, + // 总价格 + totalPrice(){ + let totalPrice = 0 + this.cartList.forEach(item => { + if(item.goods_select){ + totalPrice += item.goods_price * item.goods_count + } + }) + return totalPrice + }, + // 总数量 + totalCount(){ + let totalCount = 0 + this.cartList.forEach(item => { + if(item.goods_select){ + totalCount += item.goods_count + } + }) + return totalCount + } } }