Ver código fonte

feat(订单): 实现订单一键加购功能并优化减钱助力

- 在 API 模块新增 `orderAddToCartAjax` 方法,支持将订单商品重新加入购物车
- 在订单列表页和详情页的“再次购买”/“加入购物车”操作中调用新接口,并优化成功提示
- 修复减钱助力弹窗中显示价格计算错误,使用商品原价减去已减金额
- 优化助力用户列表显示逻辑,优先使用昵称判断,并为空头像设置默认图片
- 调整购物车项价格字段从 `productPrice` 改为 `price`,并微调减钱按钮样式
ylong 3 semanas atrás
pai
commit
afc7aa6082

+ 5 - 2
api/modules/mall.js

@@ -84,9 +84,12 @@ export const useMallApi = (Vue, vm) => {
         reduceHelpQueryAjax: (reduceCode) => vm.$u.post('/token/shop/order/inviteHelpQuery?reduceCode=' + reduceCode),
         
         // 减钱助力点击
-        reduceClickHelpAjax: (data) => vm.$u.post('/token/shop/order/inviteClickHelp', data),
+        reduceClickHelpAjax: (data) => vm.$u.post('/token/shop/order/inviteClickHelp?reduceCode=' + data.reduceCode, data),
         
         // 减钱去分享
-        goToReduceShareAjax: (params) => vm.$u.get('/token/shop/order/goToShare', params),
+		goToReduceShareAjax: (params) => vm.$u.get('/token/shop/order/goToShare', params),
+
+        // 订单一键加购
+        orderAddToCartAjax: (data) => vm.$u.post('/token/shop/order/orderAddToCart', data),
 	}
 }

+ 3 - 3
pages-car/components/cart-item.vue

@@ -52,7 +52,7 @@
             <view class="bottom-row">
                 <view class="price-box">
                     <text class="symbol">¥</text>
-                    <text class="amount">{{ item.productPrice }}</text>
+                    <text class="amount">{{ item.price }}</text>
                 </view>
 
                 <!-- 去减钱按钮 -->
@@ -309,9 +309,9 @@
                 .reduce-btn {
                     background-color: #38C148;
                     color: #fff;
-                    font-size: 20rpx;
+                    font-size: 24rpx;
                     padding: 6rpx 16rpx;
-                    border-radius: 20rpx;
+                    border-radius: 26rpx;
                     margin-left: 10rpx;
                     margin-right: auto; // 将数字框推到右边
                 }

+ 12 - 5
pages-car/components/price-reduction-popup.vue

@@ -16,7 +16,7 @@
 				</view>
 				<view class="price-row">
 					<text class="price-label">助力成功减至</text>
-					<text class="price-value increased">¥ {{ bookInfo.reduceMoney || 0 }}</text>
+					<text class="price-value increased">¥ {{ bookInfo.price - (bookInfo.reduceMoney || 0) }}</text>
 					<image class="up-icon" src="/static/img/activity/up2.png" mode="widthFix"
 						style="transform: rotate(180deg);">
 					</image>
@@ -31,13 +31,17 @@
 				<view class="share-text">分享{{ inviteUsers.length }}位好友砍价</view>
 				<view class="add-button">
 					<block v-for="(item, index) in inviteUsers" :key="index">
-						<view class="add-item" v-if="item.imgPath">
-							<image class="hand-icon" :src="item.imgPath" mode="widthFix"></image>
+						<view class="add-item" v-if="item.nickName">
+							<image class="hand-icon" v-if="item.imgPath" :src="item.imgPath" mode="widthFix"></image>
+							<image class="hand-icon" v-else
+								src="https://www.dtsyyy.cn/doctor_preview/doctor/2024/11/05/be047e6459944ddfaa83add45346ad09.jpg"
+								mode="widthFix"></image>
 							<view class="add-text">{{ formatName(item.nickName) }}</view>
 						</view>
 
 						<button v-else open-type="share" class="hand-btn">
-							<image open-type="share" class="hand-icon" src="/static/img/activity/invite.png" mode="widthFix"></image>
+							<image open-type="share" class="hand-icon" src="/static/img/activity/invite.png"
+								mode="widthFix"></image>
 						</button>
 					</block>
 				</view>
@@ -84,7 +88,7 @@
 				}).then((res) => {
 					if (res.code == 200) {
 						this.bookInfo = res.data;
-						let needInviteNum = res.data.maxInviteNum;
+						let needInviteNum = res.data.canInvite;
 						let inviteUsers = res.data.inviteUsers || [];
 						let length = inviteUsers.length;
 						for (let index = 0; index < needInviteNum - length; index++) {
@@ -94,6 +98,7 @@
 							});
 						}
 						this.inviteUsers = inviteUsers;
+						console.log(this.inviteUsers, 'inviteUsers');
 						uni.setStorageSync("reduceCodeShare", res.data.reduceCode);
 					} else {
 						uni.$u.toast(res.msg);
@@ -234,6 +239,7 @@
 			.hand-icon {
 				width: 100rpx;
 				height: 100rpx;
+				border-radius: 50%;
 			}
 		}
 
@@ -248,6 +254,7 @@
 
 		.add-item {
 			position: relative;
+			border-radius: 50%;
 
 			.add-text {
 				position: absolute;

+ 10 - 1
pages-car/pages/my-order.vue

@@ -140,7 +140,16 @@
             },
             processAction(type, order) {
                 if (type === 'rebuy' || type === 'addToCart') {
-                    uni.showToast({ title: '已加入购物车', icon: 'none' });
+                    this.$u.api.orderAddToCartAjax({
+                        orderId: order.orderId
+                    }).then(res => {
+                        if (res.code == 200) {
+                            uni.showToast({
+                                title: '已加入购物车',
+                                icon: 'success'
+                            });
+                        }
+                    });
                 } else if (type === 'remind') {
                     this.$refs.urgeDialog.open(order);
                 } else if (type === 'refund') {

+ 15 - 0
pages-car/pages/order-detail.vue

@@ -255,6 +255,21 @@
                     this.viewLogistics();
                     return;
                 }
+                if (type === 'addToCart') {
+                    uni.showLoading({ title: '加载中' });
+                    this.$u.api.orderAddToCartAjax({
+                        orderId: this.orderInfo.orderId
+                    }).then(res => {
+                        uni.hideLoading();
+                        if (res.code == 200) {
+                            uni.showToast({
+                                title: '已加入购物车',
+                                icon: 'success'
+                            });
+                        }
+                    });
+                    return;
+                }
                 uni.showToast({ title: `点击了${type}`, icon: 'none' });
             }
         }