From af2a86dbbe05d74b00a6e7bdc426e26bb0453654 Mon Sep 17 00:00:00 2001
From: xuxueyang <xuxy@fengyuntec.com>
Date: 星期三, 31 七月 2024 11:35:34 +0800
Subject: [PATCH] fix bug

---
 sub_pages/customer/trade/detail.vue |   92 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 90 insertions(+), 2 deletions(-)

diff --git a/sub_pages/customer/trade/detail.vue b/sub_pages/customer/trade/detail.vue
index 0b17700..5bf0d9e 100644
--- a/sub_pages/customer/trade/detail.vue
+++ b/sub_pages/customer/trade/detail.vue
@@ -39,9 +39,19 @@
 					<image src="../../../static/common/icon-kf.png" class="icon-kf m-l-15 img100"></image>
 
 				</view>
-				<view class="m-r-0 gwc" @click="submitShopping(dto)">
+				<view class="m-r-0 gwc" @click="submitShopping(dto)" v-if="!dto.shopnum">
 					+ 购物车
 				</view>
+				<view class="m-r-0 button-icons flex" v-if="dto.shopnum">
+					<uni-icons v-if="dto.shopnum&&dto.shopnum>=1" type="minus" size="32"
+						@click.stop="addnum(dto,-1)"></uni-icons>
+					<view class="curnums" @click.stop="updateItemNum(dto)" v-if="dto.shopnum&&dto.shopnum>=1">
+						{{ dto.shopnum }}
+					</view>
+					<uni-icons v-if="!dto.shopnum||dto.shopnum<=99" type="plus-filled" size="32"
+						@click.stop="addnum(dto,1)"></uni-icons>
+				</view>
+
 			</view>
 		</view>
 		<view class="line">
@@ -138,6 +148,9 @@
 				shopnum: 0,
 			}
 		},
+		onShow() {
+			this.refreshShopNum()
+		},
 		onLoad(options) {
 			this.id = options.id || ''
 			if (this.id) {
@@ -146,6 +159,69 @@
 			this.refreshShopNum()
 		},
 		methods: {
+			async updateItemNum(item) {
+				const res = await this.$message.confirm('', {
+					editable: true,
+					title: '请输入想要购买的数量'
+				})
+				if (res.content && res.confirm) {
+					// 发送请求
+					var t = parseInt(res.content)
+					if (isNaN(t) || t < 0) {
+						this.$message.showToast('数目需要大于等于0')
+
+					} else {
+						if (!item.stock || t > item.stock) {
+							this.$message.showToast('库存不足无法修改')
+							return
+						}
+						this.addnum(item, (t - item.shopnum))
+
+					}
+				} else {
+
+				}
+			},
+			async addnum(item, addnum) {
+				if (!this.currentInfo.id) {
+					await this.$message.confirm('请前往登录')
+					uni.navigateTo({
+						url: '/pages/user/supplier-user'
+					})
+					return
+				}
+				if (!item.shopnum) {
+					item.shopnum = 0
+				}
+				if (!item.stock) {
+					item.stock = 0
+				}
+				if (addnum > 0 & item.shopnum + addnum > item.stock) {
+					this.$message.showToast('库存不足,无法修改')
+					return
+				}
+				if (item.shopnum + addnum >= 0) {
+
+				} else {
+					return
+				}
+				this.$message.showLoading()
+				const {
+					code
+				} = await this.$http.request('post', '/api/customer/flower/cart/change-num', {
+					data: {
+						id: item.id,
+						num: addnum
+					}
+				})
+				this.$message.hideLoading()
+				if (code === 0) {
+					item.shopnum += addnum
+					this.refreshShopNum()
+					this.$forceUpdate()
+				}
+			},
+
 			async refreshShopNum() {
 				this.shopnum = await this.$store.dispatch('countShopping');
 			},
@@ -180,11 +256,14 @@
 				//提交到购物车中
 				// this.$message.showLoading()
 				const {
-					code
+					code,
+					data
 				} = await this.$store.dispatch('submitShopping', dto);
 				// this.$message.hideLoading()
 				if (code == 0) {
+					dto.shopnum = data || 0
 					this.refreshShopNum()
+					this.$forceUpdate()
 
 				}
 			},
@@ -255,6 +334,15 @@
 				}
 			}
 
+			.button-icons {
+				line-height: 40rpx;
+
+				.curnums {
+					padding-left: 20rpx;
+					padding-right: 20rpx;
+				}
+			}
+
 			.desc {
 				font-weight: 400;
 				font-size: 28rpx;

--
Gitblit v1.9.3