From e4f9739d74323aacf09d139700f22a383910ee97 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期三, 04 三月 2026 10:38:32 +0800
Subject: [PATCH] 合并
---
mini-program/pages/shopping-cart/shopping-cart.vue | 227 +++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 199 insertions(+), 28 deletions(-)
diff --git a/mini-program/pages/shopping-cart/shopping-cart.vue b/mini-program/pages/shopping-cart/shopping-cart.vue
index 5f52812..9009f3a 100644
--- a/mini-program/pages/shopping-cart/shopping-cart.vue
+++ b/mini-program/pages/shopping-cart/shopping-cart.vue
@@ -1,42 +1,58 @@
<template>
<view class="cart">
- <u-swipe-action>
- <u-swipe-action-item :options="options" v-for="(item, index) in list" :name="index" :key="index">
- <view class="cart-item">
- <view class="cart-item-check">
- <image src="/static/icon/ic_agree@2x.png" mode="widthFix" v-if="!item.active"></image>
- <image src="/static/icon/cart_ic_sel@2x.png" mode="widthFix" v-else></image>
- </view>
- <view class="cart-item-image">
- <view class="cart-item-image-xj" v-if="item.status === 1">鍟嗗搧涓嬫灦</view>
- <image :src="item.imgUrl" mode="widthFix"></image>
- </view>
- <view class="cart-item-info">
- <view class="title">{{item.goodsName}}</view>
- <view class="bottom">
- <view class="bottom-price">
- <text>{{item.price[0]}}</text>
- <text>.{{item.price[1]}}</text>
+ <template v-if="list.length > 0">
+ <u-swipe-action>
+ <u-swipe-action-item :options="options" v-for="(item, index) in list" :name="index" :key="item.id" @click="deleRow" ref="item">
+ <view class="cart-item" @click="jumpDetails(index)">
+ <view class="cart-item-check" @click.stop="select(index)" v-if="item.status !== 1">
+ <image src="/static/icon/ic_agree@2x.png" mode="widthFix" v-if="!item.active"></image>
+ <image src="/static/icon/cart_ic_sel@2x.png" mode="widthFix" v-else></image>
+ </view>
+ <view class="cart-item-check" v-else>
+ <view class="cart-item-check-yuan"></view>
+ </view>
+ <view class="cart-item-image">
+ <view class="cart-item-image-xj" v-if="item.status === 1">鍟嗗搧涓嬫灦</view>
+ <image :src="item.imgUrl" mode="widthFix"></image>
+ </view>
+ <view class="cart-item-info">
+ <view class="title" :style="{ color: item.status === 1 ? '#999999' : '' }">{{item.goodsName}}</view>
+ <view class="bottom">
+ <view class="bottom-price" v-if="item.status !== 1">
+ <text>{{item.price[0]}}</text>
+ <text>.{{item.price[1]}}</text>
+ </view>
+ <view class="bottom-price1" v-else>
+ <text>{{item.price[0]}}</text>
+ <text>.{{item.price[1]}}</text>
+ </view>
+ <u-number-box v-model="list[index].num" @change.stop="changeNum(index)" v-if="item.status !== 1"></u-number-box>
</view>
- <u-number-box v-model="item.num"></u-number-box>
</view>
</view>
- </view>
- </u-swipe-action-item>
- </u-swipe-action>
+ </u-swipe-action-item>
+ </u-swipe-action>
+ </template>
+ <template v-else>
+ <view class="wushuju">
+ <image src="/static/images/default_nodata_white.png" mode="widthFix"></image>
+ </view>
+ </template>
+ <view style="width: 100%; height: calc(env(safe-area-inset-bottom) + 108rpx);"></view>
<view class="footer">
<view class="edit">
- <view class="edit-left">
- <image src="/static/icon/ic_agree@2x.png" mode="widthFix"></image>
+ <view class="edit-left" @click="quanxuan">
+ <image src="/static/icon/cart_ic_sel@2x.png" mode="widthFix" v-if="selectAll"></image>
+ <image src="/static/icon/ic_agree@2x.png" mode="widthFix" v-else></image>
<text>鍏ㄩ��</text>
</view>
<view class="edit-right">
<view class="edit-right-label">鍚堣锛�</view>
<view class="edit-right-price">
- <text>499</text>
- <text>.00</text>
+ <text>{{totalPrice[0]}}</text>
+ <text>.{{totalPrice[1]}}</text>
</view>
- <view class="edit-right-btn">缁撶畻</view>
+ <view class="edit-right-btn" @click="jiesuan">缁撶畻</view>
</view>
</view>
<view style="width: 100%; height: env(safe-area-inset-bottom);"></view>
@@ -45,7 +61,34 @@
</template>
<script>
+ import { mapState } from 'vuex'
export default {
+ computed: {
+ ...mapState(['userInfo']),
+ totalPrice() {
+ let price = 0
+ this.list.forEach((item, index) => {
+ if (item.active && item.status !== 1) {
+ price += Number(item.price[0] + '.' +item.price[1]) * item.num
+ }
+ })
+ return price.toFixed(2).split('.')
+ },
+ // 鍏ㄩ��
+ selectAll() {
+ let open = true
+ if (this.list.length > 0) {
+ this.list.forEach(item => {
+ if (!item.active) {
+ open = false
+ }
+ })
+ return open;
+ } else {
+ return false;
+ }
+ }
+ },
data() {
return {
value: 1,
@@ -59,8 +102,85 @@
},
onLoad() {
this.getList()
+ uni.$on('shuaxin', () => {
+ this.next = true
+ this.page = 1
+ this.list = []
+ this.getList()
+ })
+ },
+ onReachBottom() {
+ this.getList()
},
methods: {
+ jumpDetails(index) {
+ uni.navigateTo({
+ url: '/pages/details/details?id=' + this.list[index].goodsId
+ })
+ },
+ jiesuan() {
+ let arr = this.list.filter(item => {
+ if (item.active && item.status !== 1) {
+ return item
+ }
+ })
+ if (arr.length === 0) return uni.showToast({
+ title: '鑷冲皯閫夋嫨涓�椤瑰晢鍝�',
+ icon: 'none'
+ })
+ for (let i = 0; i < arr.length; i++) {
+ if (arr[i].status === 1) {
+ return uni.showToast({
+ title: '璇峰厛鍒犻櫎宸蹭笅鏋剁殑鍟嗗搧',
+ icon: 'none'
+ })
+ }
+ }
+ let shop = arr.map(item => {
+ return {
+ goodsNum: item.num,
+ goodsSkuId: item.goodsSkuId
+ }
+ })
+ uni.setStorageSync('shop', shop)
+ uni.navigateTo({
+ url: '/pages/confirm-order/confirm-order'
+ })
+ },
+ // 鍏ㄩ��
+ quanxuan() {
+ if (this.selectAll) {
+ this.list.forEach((item) => {
+ item.active = false
+ })
+ } else {
+ this.list.forEach((item) => {
+ item.active = true
+ })
+ }
+ },
+ // 鍗曢��
+ select(index) {
+ this.list[index].active = !this.list[index].active
+ },
+ // 鏇存柊鍟嗗搧鏁伴噺
+ changeNum(index) {
+ console.log(index)
+ this.$u.api.updateNum({
+ id: this.list[index].shopCartId,
+ memberId: this.userInfo.id,
+ num: this.list[index].num
+ })
+ },
+ deleRow(e) {
+ this.$u.api.deleteBatch({ ids: this.list[e.name].shopCartId })
+ .then(res => {
+ if (res.code === 200) {
+ this.list.splice(e.name, 1)
+ this.$refs.item.forEach(item => item.closeHandler(true))
+ }
+ })
+ },
getList() {
if (!this.next) return;
this.$u.api.shopCartPage({
@@ -69,7 +189,6 @@
model: {}
}).then(res => {
if (res.code === 200) {
- console.log(res)
res.data.records.forEach(item => {
item.price = item.price.toFixed(2).split('.')
item.active = false
@@ -92,12 +211,25 @@
padding: 30rpx 0;
box-sizing: border-box;
+ .wushuju {
+ width: 100%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ margin-top: 200rpx;
+ image {
+ width: 320rpx;
+ height: 320rpx;
+ }
+ }
+
.footer {
width: 100%;
position: fixed;
bottom: 0;
left: 0;
padding: 0 30rpx;
+ z-index: 999;
box-sizing: border-box;
box-shadow: 0rpx -2rpx 4rpx 0rpx rgba(0,0,0,0.06);
background-color: #ffffff;
@@ -181,6 +313,14 @@
width: 40rpx;
height: 40rpx;
margin-right: 30rpx;
+
+ .cart-item-check-yuan {
+ width: 40rpx;
+ height: 40rpx;
+ background: #EEEEEE;
+ border-radius: 50%;
+ border: 2rpx solid #E5E5E5;
+ }
image {
width: 100%;
@@ -225,6 +365,11 @@
justify-content: space-between;
.title {
+ width: 100%;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+ overflow: hidden;
font-weight: 400;
font-size: 28rpx;
color: #111111;
@@ -238,7 +383,7 @@
.bottom-price {
display: flex;
- align-items: center;
+ align-items: baseline;
justify-content: space-between;
text {
@@ -262,6 +407,32 @@
}
}
}
+ .bottom-price1 {
+ display: flex;
+ align-items: baseline;
+ justify-content: space-between;
+
+ text {
+ &:nth-child(1) {
+ font-weight: 500;
+ font-size: 32rpx;
+ color: #999999;
+
+ &::before {
+ content: '锟�';
+ font-weight: 500;
+ font-size: 24rpx;
+ color: #999999;
+ }
+ }
+
+ &:nth-child(2) {
+ font-weight: 500;
+ font-size: 24rpx;
+ color: #999999;
+ }
+ }
+ }
}
}
}
--
Gitblit v1.9.3