2022-04-06 16:08:26 +08:00
|
|
|
<template>
|
2022-04-19 17:58:39 +08:00
|
|
|
<view class="container">
|
2023-05-23 17:37:49 +08:00
|
|
|
<view class="navbar">
|
|
|
|
<u-navbar title="个人中心">
|
|
|
|
</u-navbar>
|
|
|
|
</view>
|
2022-04-19 17:58:39 +08:00
|
|
|
</view>
|
2022-04-06 16:08:26 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-16 22:04:02 +08:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2022-12-05 21:51:39 +08:00
|
|
|
title: '',
|
|
|
|
cartList: [],
|
|
|
|
checkedNumber: 0,
|
|
|
|
totalAmount: 0
|
2022-04-16 22:04:02 +08:00
|
|
|
}
|
|
|
|
},
|
2022-04-20 03:08:59 +08:00
|
|
|
computed: {
|
2022-12-05 21:51:39 +08:00
|
|
|
checkedProduct() {
|
|
|
|
return this.cartList.filter(item => {
|
|
|
|
return item.checked
|
|
|
|
})
|
|
|
|
},
|
|
|
|
isCheckAll() {
|
|
|
|
if (this.cartList.length < 1) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return this.cartList.every(item => {
|
|
|
|
return item.checked
|
|
|
|
})
|
|
|
|
},
|
2022-04-20 03:08:59 +08:00
|
|
|
hasLogin() {
|
|
|
|
return this.$store.getters.hasLogin
|
|
|
|
}
|
2022-12-05 21:51:39 +08:00
|
|
|
},
|
|
|
|
onShow() {
|
|
|
|
if (this.hasLogin) {
|
|
|
|
this.loadCartDetailData()
|
|
|
|
} else {
|
|
|
|
this.cartList =[]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
loadCartDetailData() {
|
|
|
|
this.$store.dispatch('CartProductDetail').then(res => {
|
|
|
|
this.cartList = res.data || []
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/** 商品全选/取消全选 */
|
|
|
|
handleCheckAllProduct() {
|
|
|
|
if (this.cartList.length < 1) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const productIds = this.cartList.map(item => {
|
|
|
|
return item.productId
|
|
|
|
})
|
|
|
|
this.$store.dispatch('CartProductCheckChange', { productIds, checked: !this.isCheckAll }).then(res => {
|
|
|
|
this.cartList = res.data || []
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/** 商品单选/取消单选 */
|
|
|
|
handleProductCheckedChange(productId, checked) {
|
|
|
|
this.$store.dispatch('CartProductCheckChange', { productIds: [productId], checked: checked }).then(res => {
|
|
|
|
this.cartList = res.data || []
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/** 修改购物车商品数量 */
|
|
|
|
handleProductCountChange(productId, number) {
|
|
|
|
this.$store.dispatch('CartProductCountChange', { productIds: [productId], productCount: number }).then(res => {
|
|
|
|
this.cartList = res.data || []
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/** 移除购物车商品 */
|
|
|
|
handleRemoveProduct() {
|
|
|
|
if (this.checkedProduct < 1) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const productIds = this.checkedProduct.map(item => {
|
|
|
|
return item.productId
|
|
|
|
})
|
|
|
|
|
|
|
|
uni.showModal({
|
|
|
|
title: '确定要移除选中的商品?',
|
|
|
|
cancelText: '取消',
|
|
|
|
confirmText: '移除',
|
|
|
|
success: res => {
|
|
|
|
if (res.confirm) {
|
|
|
|
this.$store.dispatch('CartProductCountChange', { productIds: productIds, productCount: 0 }).then(res => {
|
|
|
|
this.cartList = res.data || []
|
|
|
|
})
|
|
|
|
} else if (res.cancel) {
|
|
|
|
//console.log('用户点击取消')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/** 购物车提交结算 */
|
|
|
|
handleCheckoutProduct() {
|
|
|
|
if (this.checkedProduct < 1) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const checkedProduct = this.checkedProduct.map(item => {
|
|
|
|
return { productId: item.productId, productCount: item.productCount, sellPrice: item.sellPrice }
|
|
|
|
})
|
|
|
|
uni.$u.route('/pages/checkout/checkout', {
|
|
|
|
checkedProduct: JSON.stringify(checkedProduct)
|
|
|
|
})
|
|
|
|
}
|
2022-04-20 03:08:59 +08:00
|
|
|
}
|
2022-04-16 22:04:02 +08:00
|
|
|
}
|
2022-04-06 16:08:26 +08:00
|
|
|
</script>
|
|
|
|
|
2022-04-19 17:58:39 +08:00
|
|
|
<style lang="scss" scoped>
|
2022-12-05 21:51:39 +08:00
|
|
|
|
2022-04-19 17:58:39 +08:00
|
|
|
</style>
|