计算属性:
1. 全选状态 2. 总价 3. 总数量
This commit is contained in:
parent
96651e2d32
commit
f7411ecf55
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user