From 6e4b859a05e29eb75ff39c340e015265c3be85e9 Mon Sep 17 00:00:00 2001
From: xuxueyang <xuxy@fengyuntec.com>
Date: 星期日, 04 八月 2024 11:51:43 +0800
Subject: [PATCH] update 合伙人、花店端

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

diff --git a/sub_pages/customer/trade/detail.vue b/sub_pages/customer/trade/detail.vue
index 0b17700..1748d7e 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,12 @@
 				shopnum: 0,
 			}
 		},
+		onShow() {
+			if (this.id) {
+				this.getDetail()
+			}
+			this.refreshShopNum()
+		},
 		onLoad(options) {
 			this.id = options.id || ''
 			if (this.id) {
@@ -145,9 +161,99 @@
 			}
 			this.refreshShopNum()
 		},
+		// #ifdef PUB_CUSTOMER
+		onShareAppMessage() {
+			let that = this;
+			var name = that.currentInfo.customerDTO && currentInfo.customerDTO.name || that.currentInfo.supplierDTO &&
+				currentInfo.supplierDTO.name || that.currentInfo.partnerDTO && currentInfo.partnerDTO.name || ''
+			var url =
+				`/sub_pages/customer/trade/detail?id=${this.id}&shareId=${this.currentInfo&&this.currentInfo.id||''}&shareName=${name||''}`; //你的转发页面路径拼接参数
+			return {
+
+				title: this.dto.id ? (this.dto.name + " " + (this.dto.price || '-') + '元/扎 ' + (this.dto.unit || '')) : "花满芫",
+				path: url,
+			}
+		},
+		onShareTimeline() {
+			let that = this;
+			var name = that.currentInfo.customerDTO && currentInfo.customerDTO.name || that.currentInfo.supplierDTO &&
+				currentInfo.supplierDTO.name || that.currentInfo.partnerDTO && currentInfo.partnerDTO.name || ''
+			var url =
+				`/sub_pages/customer/trade/detail?id=${this.id}&shareId=${this.currentInfo&&this.currentInfo.id||''}&shareName=${name||''}`; //你的转发页面路径拼接参数
+			return {
+				title: this.dto.id ? (this.dto.name + " " + (this.dto.price || '-') + '元/扎 ' + (this.dto.unit || '')) : "花满芫",
+				path: url,
+			}
+		},
+		// #endif
 		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');
+				this.$store.dispatch('sign_add', 'shopnum')
+
 			},
 			async collectItem(dto) {
 				if (!this.currentInfo.id) {
@@ -180,11 +286,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 +364,15 @@
 				}
 			}
 
+			.button-icons {
+				line-height: 40rpx;
+
+				.curnums {
+					padding-left: 20rpx;
+					padding-right: 20rpx;
+				}
+			}
+
 			.desc {
 				font-weight: 400;
 				font-size: 28rpx;

--
Gitblit v1.9.3