计算属性:

1. 全选状态
2. 总价
3. 总数量
This commit is contained in:
jqtmviyu@gmail.com 2021-03-05 00:34:35 +08:00
parent 96651e2d32
commit f7411ecf55

View File

@ -18,8 +18,8 @@
<radio :checked="selectAll" color="#E03440" class="select_btn" /> <radio :checked="selectAll" color="#E03440" class="select_btn" />
<text class="select_text">全选</text> <text class="select_text">全选</text>
<text class="total_text">合计</text> <text class="total_text">合计</text>
<text class="price">3999</text> <text class="price">{{totalPrice}}</text>
<view class="bottom_btn">去结算(12)</view> <view class="bottom_btn">去结算({{totalCount}})</view>
</view> </view>
</view> </view>
</template> </template>
@ -29,13 +29,13 @@ export default {
data(){ data(){
return { return {
cartList: [], cartList: [],
selectAll: false // selectAll: false
} }
}, },
onShow() { onShow() {
const cartList = uni.getStorageSync("cartList") || []; const cartList = uni.getStorageSync("cartList") || [];
this.cartList = 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: { methods: {
// //
@ -46,7 +46,7 @@ export default {
this.cartList[index].goods_select = !this.cartList[index].goods_select 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) 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
}
} }
} }
</script> </script>