计算属性:

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" />
<text class="select_text">全选</text>
<text class="total_text">合计</text>
<text class="price">3999</text>
<view class="bottom_btn">去结算(12)</view>
<text class="price">{{totalPrice}}</text>
<view class="bottom_btn">去结算({{totalCount}})</view>
</view>
</view>
</template>
@ -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
}
}
}
</script>