2022-04-06 16:08:26 +08:00
|
|
|
|
<template>
|
2022-04-19 17:58:39 +08:00
|
|
|
|
<view class="container">
|
2022-12-05 21:51:39 +08:00
|
|
|
|
<!-- 购物车为空 -->
|
|
|
|
|
<view v-if="!hasLogin || cartList.length === 0">
|
|
|
|
|
<view class="cart-empty">
|
|
|
|
|
<u-empty text="去逛逛添点什么吧" width="500rpx" height="500rpx" icon="/static/images/empty/cart.png"></u-empty>
|
|
|
|
|
</view>
|
2022-04-19 17:58:39 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
2022-12-05 21:51:39 +08:00
|
|
|
|
<!-- 购物车列表 -->
|
|
|
|
|
<scroll-view v-if="hasLogin && cartList.length > 0" class="cart-product" scroll-y="true">
|
|
|
|
|
<yd-cart-product :product-list="cartList" @productCheckedChange="handleProductCheckedChange" @productCountChange="handleProductCountChange"></yd-cart-product>
|
|
|
|
|
</scroll-view>
|
|
|
|
|
|
|
|
|
|
<!-- 未登录 -->
|
2022-04-20 03:08:59 +08:00
|
|
|
|
<view v-if="!hasLogin" class="login-tips-box">
|
2022-04-19 17:58:39 +08:00
|
|
|
|
<view class="login-tips">
|
2022-05-05 19:09:04 +08:00
|
|
|
|
<navigator url="/pages/login/social" open-type="navigate" hover-class="none">
|
2022-12-05 21:51:39 +08:00
|
|
|
|
<view class="login-link">登录查看</view>
|
2022-04-19 17:58:39 +08:00
|
|
|
|
</navigator>
|
2022-12-05 21:51:39 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<!-- 底部菜单 -->
|
|
|
|
|
<view class="cart-btn-container">
|
|
|
|
|
<view class="btn-box">
|
|
|
|
|
<view class="product-check-info">
|
|
|
|
|
<view class="check-all-btn" @click.stop="handleCheckAllProduct">
|
|
|
|
|
<u-icon v-if="isCheckAll" name="checkmark-circle-fill" color="#3c9cff" size="22"></u-icon>
|
|
|
|
|
<view v-else class="un-check-box"></view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="info-text">合计:</view>
|
|
|
|
|
<view>
|
|
|
|
|
<yd-text-price color="red" size="15" intSize="20" :price="totalAmount"></yd-text-price>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<view v-if="checkedProduct.length > 0" class="cart-btn-group">
|
|
|
|
|
<u-button type="warning" shape="circle" size="small" text="移除" @click="handleRemoveProduct"></u-button>
|
|
|
|
|
<view class="btn-gap"></view>
|
|
|
|
|
<u-button style="margin-left: 10px" class="main-btn" type="primary" shape="circle" size="small" text="去结算" @click="handleCheckoutProduct"></u-button>
|
|
|
|
|
</view>
|
|
|
|
|
<view v-else class="cart-btn-group">
|
|
|
|
|
<u-button type="warning" shape="circle" size="small" text="移除" disabled></u-button>
|
|
|
|
|
<view class="btn-gap"></view>
|
|
|
|
|
<u-button style="margin-left: 10px" class="main-btn" type="primary" shape="circle" size="small" text="去结算" disabled></u-button>
|
|
|
|
|
</view>
|
2022-04-19 17:58:39 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</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>
|
|
|
|
|
.login-tips-box {
|
|
|
|
|
padding-top: 100rpx;
|
2022-12-05 21:51:39 +08:00
|
|
|
|
|
2022-04-19 17:58:39 +08:00
|
|
|
|
.login-tips {
|
|
|
|
|
@include flex-center;
|
|
|
|
|
color: #939393;
|
2022-12-05 21:51:39 +08:00
|
|
|
|
font-size: 24rpx;
|
2022-04-19 17:58:39 +08:00
|
|
|
|
letter-spacing: 5rpx;
|
|
|
|
|
}
|
2022-12-05 21:51:39 +08:00
|
|
|
|
|
2022-04-19 17:58:39 +08:00
|
|
|
|
.login-link {
|
2022-12-05 21:51:39 +08:00
|
|
|
|
width: 160rpx;
|
|
|
|
|
height: 50rpx;
|
|
|
|
|
line-height: 50rpx;
|
|
|
|
|
border-radius: 50rpx;
|
|
|
|
|
border: 1px solid #777;
|
|
|
|
|
color: #777;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.cart-btn-container {
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
|
|
|
|
|
.btn-box {
|
|
|
|
|
background: $custom-bg-color;
|
|
|
|
|
border-top: $custom-border-style;
|
|
|
|
|
|
|
|
|
|
width: 750rpx;
|
|
|
|
|
@include flex-space-between();
|
|
|
|
|
height: 100rpx;
|
|
|
|
|
|
|
|
|
|
.product-check-info {
|
|
|
|
|
@include flex-left;
|
|
|
|
|
|
|
|
|
|
.check-all-btn {
|
|
|
|
|
padding: 20rpx;
|
|
|
|
|
|
|
|
|
|
.un-check-box {
|
|
|
|
|
width: 20px;
|
|
|
|
|
height: 20px;
|
|
|
|
|
border: 1px solid #939393;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.info-text {
|
|
|
|
|
font-size: 26rpx;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
color: #666666;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.cart-btn-group {
|
|
|
|
|
@include flex-right();
|
|
|
|
|
width: 360rpx;
|
|
|
|
|
padding-right: 10px;
|
|
|
|
|
|
|
|
|
|
.btn-gap {
|
|
|
|
|
width: 20rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-19 17:58:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|