lyy@qq.com 1 year ago
parent
commit
758a833169

+ 22 - 1
components/cartPopup.vue

@@ -90,6 +90,7 @@
 				this.show = false;
 			},
 			changeValue(value, v) {
+				console.log('value, v', value, v)
 				const e = uni.getStorageSync('carl')
 				const userId = uni.getStorageSync('appUserId')
 				const params = {
@@ -125,7 +126,7 @@
 							duration: 2000
 						})
 						this.carList = []
-						this.$emit('selected-changed', []);
+						this.$emit('selected-changed', this.carList);
 						this.show = false
 					}
 				}).catch(error => {
@@ -166,6 +167,26 @@
 				// 将总价格转换回浮点数(以元为单位)
 				this.total = (total / 100).toFixed(2);
 			},
+			toBuy() {
+				const carlist = {
+					carlist: this.totalList,
+					total: this.total
+				}
+				if (carlist.carlist.length <= 0) {
+					// this.$refs.uNotify.show({'请选择'})
+					uni.showToast({
+						title: '请选择',
+						icon: 'error',
+						duration: 2000
+					});
+				} else {
+					uni.navigateTo({
+						url: `/pages/order/submitOrder/submitOrder?data=${encodeURIComponent(JSON.stringify(carlist))}`
+					})
+					this.selectAll()
+					this.show = false;
+				}
+			}
 		}
 	}
 </script>

+ 119 - 31
components/specPopup.vue

@@ -24,7 +24,7 @@
 		</scroll-view>
 		<view class="purchase-num padding-lr-sm">
 			<uni-section title="购买数量"></uni-section>
-			<uni-number-box v-model="vModelValue" @change="changeValue(value)" />
+			<uni-number-box v-model="vModelValue" :min="1" @change="changeValue()" />
 		</view>
 		<view class="btn-box">
 			<view class="btn reset" @click="toShop">加入购物车</view>
@@ -50,23 +50,28 @@
 				intSkuId: [], // 选择唯一的id
 				caMsg: [], // 根据id查出来的数据
 				isSelected: false,
+				isData: null,
+				preSele: [],
+				itemsL: [],
+				toList: [],
+				total: 0
 			}
 		},
 		methods: {
-			changeValue(e) {},
+			changeValue(value) {},
 			change(e) {
 				if (!e.show) { // 当弹出层关闭时
 					// 重置规格选择
-					if (this.specs.length > 0) {
+					if (this.specs.length > 0 && this.preSele.length < 0) {
 						this.specs.forEach(e => {
 							e.values.forEach(s => {
 								s.selected = false
 							})
 						})
+						//this.vModelValue = 1
 					}
 					this.speL = []
-					// 重置购买数量
-					this.vModelValue = 1
+					this.seleBack()
 				}
 			},
 			async selectSpec1(item, spec) {
@@ -74,19 +79,25 @@
 				item.values.forEach(value => {
 					value.selected = false
 				})
-				// 然后,选择当前点击的选项
-				spec.selected = true
-				if (spec.selected) {
-					this.speL.push(spec)
+
+				spec.selected = !spec.selected
+				const newIds = spec.ids
+				if (this.preSele.length > 0) {
+					this.speL = this.preSele
 				}
+				const filSpeL = this.speL.filter(value => value.ids !== newIds);
+
+				filSpeL.push(spec)
+
+				this.speL = filSpeL
 
 				const seleList = this.speL.filter(item => item.selected == true)
-				const items = seleList.map(item => item.label)
+				this.itemsL = seleList.map(item => item.label)
+
 				// 计算选中规格项的skuIds数组的交集
 				if (seleList.length > 0) {
 					let intersection = seleList[0].skuIds
 
-					// 遍历数组中的每个对象
 					for (let i = 1; i < seleList.length; i++) {
 						// 使用filter和includes方法找到交集
 						intersection = intersection.filter(skuId => {
@@ -102,40 +113,68 @@
 					// 如果没有选中的规格项,返回空字符串
 					this.intSkuId = '';
 				}
-				// console.log('speL', this.speL)
-				// 确定每一个都有选择后发起请求
+
 				this.isSelected = this.specs.every(spec => spec.values.some(value => value.selected))
-				// console.log('isSelected', this.isSelected)
+
 				if (this.isSelected) {
 					// 如果所有规格都至少有一个选项被选中
 					const res = await this.$request('get', `/item/sku/${this.intSkuId}`)
-					this.caMsg = res.data
-					// 返回选中规格项的label值
-					//console.log('intSkuId', this.intSkuId)
-					//console.log('items', items)
+					if (res) {
+						this.caMsg = res.data
+						this.vModelValue = 1
+						console.log('this.caMsg', this.caMsg)
+					}
+
 					//console.log('所有规格都已选择')
-					const itemDetal = {
-						id: this.intSkuId,
-						item: Array.from(items).join(','),
-						count: this.vModelValue
+					if (this.isData == true) {
+						this.preSele = seleList
 					}
-					this.$emit('seChanged', itemDetal);
+
 				} else {}
 			},
-			async open() {
+			// 返回选中的数据
+			seleBack() {
+				const itemDetal = {
+					id: this.intSkuId,
+					item: Array.from(this.itemsL).join(','),
+					count: this.vModelValue
+				}
+				this.$emit('seChanged', itemDetal);
+			},
+			async open(e) {
+				if (e || e != null) {
+					this.isData = e
+				}
 				this.$refs.popup.open('bottom')
-				// console.log("this.cardMsg")
+
 				const spuId = this.cardMsg.spuId
 				const res = await this.$request('get', `/item/sku/queryPropMapping?spuId=${spuId}`)
-				this.specs = res.data.filter(item => item.values && item.values.length > 0);
+				this.specs = res.data.filter(item => item.values && item.values.length > 0)
 				this.specs.forEach(item => {
 					Object.assign(item, {
 						values: item.values.map(value => ({
 							...value,
-							ids: item.id,
-							selected: false
+							ids: item.id
+							// selected: false
 						}))
 					})
+					if (this.preSele.length <= 0) {
+						Object.assign(item, {
+							values: item.values.map(value => ({
+								...value,
+								selected: false
+							}))
+						})
+					} else {
+						Object.assign(item, {
+							values: item.values.map(value => ({
+								...value,
+								selected: this.preSele.some(prevSpe =>
+									prevSpe.label === value.label && prevSpe.ids ===
+									value.ids)
+							}))
+						})
+					}
 				})
 			},
 			toShop() {
@@ -158,7 +197,6 @@
 						quantity: count,
 						extendProps: userId
 					}
-					// console.log('params', params)
 					this.$request('post', `/front/shoppingCart`, params, true).then(response => {
 						// 请求成功
 						if (response.code == 200) {
@@ -180,15 +218,65 @@
 						// 请求失败
 						console.error('请求失败:', error);
 					})
-					// this.$emit('update-shopmsg', this.shopMsg);
 					// 关闭弹出层
 					this.$refs.popup.close()
 				}
 			},
+			totalPrice() {
+				const e = uni.getStorageSync('carl')
+				const userId = uni.getStorageSync('appUserId')
+				const toList = {
+					storeId: e.id,
+					storeName: e.name,
+					skuId: this.caMsg.skuId,
+					basePrice: this.caMsg.retailPrice,
+					price: this.caMsg.retailPrice,
+					quantity: this.vModelValue,
+					extendProps: userId,
+					imgUrl: this.caMsg.img,
+					spuId: this.caMsg.spuId,
+					skuName: this.caMsg.skuName,
+					skuProperties: this.caMsg.skuProperties,
+					skuTitle: this.caMsg.title,
+				}
+				let total = 0;
+				// 如果 selected 属性不存在,直接计算所有商品
+				let priceInCents = Math.round(toList.price * 100);
+				let quant = toList.quantity;
+				total += priceInCents * quant;
+				
+				this.toList.push(toList)
+				// 将总价格转换回浮点数(以元为单位)
+				this.total = (total / 100).toFixed(2);
+			},
 			toBuy() {
+				this.totalPrice()
+				const carlist = {
+					carlist: this.toList,
+					total: this.total
+				}
 				uni.navigateTo({
-					url: `/pages/order/submitOrder/submitOrder`
+					url: `/pages/order/submitOrder/submitOrder?data=${encodeURIComponent(JSON.stringify(carlist))}`
 				})
+				this.toList = []
+				console.log('carlist', carlist)
+				this.$refs.popup.close()
+				// if (carlist.carlist.length <= 0) {
+				// 	// this.$refs.uNotify.show({'请选择'})
+				// 	uni.showToast({
+				// 		title: '请选择',
+				// 		icon: 'error',
+				// 		duration: 2000
+				// 	});
+				// } else {
+				// 	uni.navigateTo({
+				// 		url: `/pages/order/submitOrder/submitOrder?data=${encodeURIComponent(JSON.stringify(carlist))}`
+				// 	})
+				// 	this.$refs.popup.close()
+				// }
+				// uni.navigateTo({
+				// 	url: `/pages/order/submitOrder/submitOrder`
+				// })
 			}
 		}
 	}

+ 0 - 1
pages.json

@@ -15,7 +15,6 @@
 				"navigationBarTitleText" : "登录"
 			}
 		},
-		
 		{
 			"path": "pages/index/index",
 			"style": {

+ 1 - 0
pages/classify/classify.vue

@@ -179,6 +179,7 @@
 					})
 					this.$nextTick(() => {
 						this.$refs.cartPopup.setShow(false)
+						this.total = 0
 					})
 				}
 			},

+ 51 - 8
pages/goodDetail/goodDetail.vue

@@ -87,7 +87,7 @@
 		<!-- 置顶 -->
 		<use-totop ref="usetop" bottom="120"></use-totop>
 		<specPopup ref="specPopup" :cardMsg="cardMsg" @seChanged="seChanged" @addShop="carListMeg"></specPopup>
-		<cartPopupVue ref="cartPopup" />
+		<cartPopupVue ref="cartPopup" @selected-changed="handleSelectedChanged" />
 	</view>
 </template>
 
@@ -104,7 +104,7 @@
 		data() {
 			return {
 				cardMsg: {},
-				buyCount: '',
+				buyCount: 0,
 				total: 0,
 				carList: {},
 				detailMsg: {},
@@ -118,7 +118,8 @@
 				// 轮播图
 				scrollTop: 0,
 				count: 1,
-				dataDel: {}
+				dataDel: {},
+				toList:[]
 			}
 		},
 		onLoad(option) {
@@ -150,10 +151,17 @@
 					})
 				}
 			},
+			handleSelectedChanged(selectedItems) {
+				console.log('选中的数据:', selectedItems)
+				//this.carList = selectedItems
+				this.carListMeg()
+
+			},
 			clickSpec() {
 				this.cardMsg = this.goods
 				this.$nextTick(() => {
-					this.$refs.specPopup.open();
+					this.$refs.specPopup.open(true);
+
 				});
 			},
 			showCart() {
@@ -175,7 +183,7 @@
 				console.log('params', params)
 				this.$request('post', `/front/shoppingCart`, params, true).then(response => {
 					// 请求成功
-					console.log('response',response)
+					console.log('response', response)
 					if (response.code = 200) {
 						// 弹出消息
 						uni.showToast({
@@ -184,7 +192,7 @@
 							duration: 2000
 						})
 						this.carListMeg()
-					} else if (response.code = 500){
+					} else if (response.code = 500) {
 						uni.showToast({
 							title: response.msg,
 							icon: 'warning',
@@ -224,12 +232,47 @@
 				this.detailMsg = res.data
 				console.log('this.detailMsg', this.detailMsg)
 			},
+			totalPrice() {
+				const e = uni.getStorageSync('carl')
+				const userId = uni.getStorageSync('appUserId')
+				const toList = {
+					storeId: e.id,
+					storeName: e.name,
+					skuId: this.detailMsg.skuId,
+					basePrice: this.detailMsg.retailPrice,
+					price: this.detailMsg.retailPrice,
+					quantity: this.count,
+					extendProps: userId,
+					imgUrl: this.detailMsg.img,
+					spuId: this.detailMsg.spuId,
+					skuName: this.detailMsg.skuName,
+					skuProperties: this.detailMsg.skuProperties,
+					skuTitle: this.detailMsg.title,
+				}
+				let total = 0;
+				// 如果 selected 属性不存在,直接计算所有商品
+				let priceInCents = Math.round(toList.price * 100);
+				let quant = toList.quantity;
+				total += priceInCents * quant;
+				
+				this.toList.push(toList)
+				// 将总价格转换回浮点数(以元为单位)
+				this.total = (total / 100).toFixed(2);
+			},
 			// 去购买
 			toBuy() {
-				
+				this.totalPrice()
+				const carlist = {
+					carlist: this.toList,
+					total: this.total
+				}
 				uni.navigateTo({
-					url: `/pages/order/submitOrder/submitOrder`
+					url: `/pages/order/submitOrder/submitOrder?data=${encodeURIComponent(JSON.stringify(carlist))}`
 				})
+				this.toList = []
+				// uni.navigateTo({
+				// 	url: `/pages/order/submitOrder/submitOrder`
+				// })
 			}
 		}
 	}

+ 17 - 0
pages/order/myOrder/myOrder.vue

@@ -159,8 +159,25 @@
 		},
 		onLoad(e) {
 			this.tabCurrentIndex = parseFloat(e.type);
+			this.fatchDate()
 		},
 		methods: {
+			async fatchDate() {
+				const e = uni.getStorageSync('carl')
+				const params = {
+					storeId: e.id
+				}
+				const result = await this.$request('get', '/order/retailOrder/list', params)
+				if (result) {
+					console.log('result', result.rows)
+					this.navList.orderList = result.rows
+					console.log('orderList', this.navList.orderList)
+					this.navList.orderList.order_detail = result.rows.itemList
+					console.log('order_detail', result.rows.itemList)
+					this.navList.orderList.order = result.rows.pickupInfo
+					console.log('order', result.rows.pickupInfo)
+				}
+			},
 			loadData() {},
 			// swiper 切换
 			changeTab(e) {

+ 8 - 8
pages/order/orderPaid/orderPaid.vue

@@ -37,7 +37,7 @@
 				<view class="shop-check">
 					<text class="send-label">{{goods.storeName}}</text>
 				</view>
-				<view class="total-goods">共计{{goods.itemList.length}}件商品</view>
+				<view class="total-goods">共计{{lists}}件商品</view>
 			</view>
 			<view class="goods-cart w-full">
 				<view class="goods-cont padding-tb" v-for="(item, index) in goods.itemList" :key="index">
@@ -107,19 +107,18 @@
 	export default {
 		data() {
 			return {
-				goods: {}
+				goods: {},
+				lists: 0
 			}
 		},
 		onLoad(e) {
 			this.fatchDate(e)
 		},
 		onUnload() {
-			uni.navigateBack({
-				delta: 3, //返回上5层
-				success: () => {
-					uni.$emit('register_refresh') // 直接调用上个页面的刷新方法
-				}
-			})
+			uni.redirectTo({
+				url: `/pages/classify/classify` // 指定页面的路径
+			});
+			return true;
 		},
 		methods: {
 			async fatchDate(e) {
@@ -129,6 +128,7 @@
 				if (result) {
 					console.log('result', result.data)
 					this.goods = result.data
+					this.lists = this.goods.itemList.length
 				}
 			}
 		}

+ 25 - 23
pages/order/submitOrder/submitOrder.vue

@@ -146,6 +146,7 @@
 					})
 					return
 				}
+				const userId = uni.getStorageSync('appUserId');
 				const userName = uni.getStorageSync('userName');
 				const itemListArray = this.data.carlist.map(item => ({
 					skuId: item.skuId,
@@ -166,6 +167,7 @@
 					arriveCutTime: this.value,
 					sellerNick: this.cList.name,
 					buyerNick: userName,
+					customerId: userId,
 					itemList: itemListArray,
 					pickupInfo: {
 						pickupType: this.val,
@@ -173,30 +175,30 @@
 					}
 				}
 				console.log('params', params);
-				// uni.navigateTo({
-				// 	url: `/pages/order/orderPaid/orderPaid`
-				// })
-				this.$request('post', `/order/retailOrder`, params, true).then(response => {
-					// 请求成功
-					console.log('response', response)
-					if (response.code == 200) {
-						const ids = this.data.carlist.map(car => car.id);
-						this.$request('delete', `/front/shoppingCart/${ids}`)
-						console.log('response.data', response.data)
-						uni.navigateTo({
-							url: `/pages/order/orderPaid/orderPaid?id=${response.data}`
-						})
-					} else if (response.code == 500) {
-						uni.showToast({
-							title: response.msg,
-							icon: 'error',
-							duration: 2000
-						});
-					}
-				}).catch(error => {
-					// 请求失败
-					console.error('请求失败:', error);
+				uni.navigateTo({
+					url: `/pages/order/orderPaid/orderPaid`
 				})
+				// this.$request('post', `/order/retailOrder`, params, true).then(response => {
+				// 	// 请求成功
+				// 	console.log('response', response)
+				// 	if (response.code == 200) {
+				// 		const ids = this.data.carlist.map(car => car.id);
+				// 		this.$request('delete', `/front/shoppingCart/${ids}`)
+				// 		console.log('response.data', response.data)
+				// 		uni.navigateTo({
+				// 			url: `/pages/order/orderPaid/orderPaid?id=${response.data}`
+				// 		})
+				// 	} else if (response.code == 500) {
+				// 		uni.showToast({
+				// 			title: response.msg,
+				// 			icon: 'error',
+				// 			duration: 2000
+				// 		});
+				// 	}
+				// }).catch(error => {
+				// 	// 请求失败
+				// 	console.error('请求失败:', error);
+				// })
 			}
 		}
 	}