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
+ }
}
}