From cd4fa2cfed76c15143511a40783abf3a75eb3146 Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期三, 10 九月 2025 19:13:24 +0800
Subject: [PATCH] 扫码修改地址

---
 pages/order/editOrderAddress/editOrderAddress.vue |  565 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 565 insertions(+), 0 deletions(-)

diff --git a/pages/order/editOrderAddress/editOrderAddress.vue b/pages/order/editOrderAddress/editOrderAddress.vue
new file mode 100644
index 0000000..ef01bd7
--- /dev/null
+++ b/pages/order/editOrderAddress/editOrderAddress.vue
@@ -0,0 +1,565 @@
+<template>
+	<view class="edit-address-page">
+		<!-- 璁㈠崟淇℃伅 -->
+		<view class="order-info">
+			<view class="order-title">璁㈠崟淇℃伅</view>
+			<view class="order-sn">璁㈠崟鍙凤細{{ orderDetail.order.sn || '' }}</view>
+
+			<!-- 鍟嗗搧鍒楄〃 -->
+			<view class="goods-list">
+				<view class="goods-item" v-for="item in orderDetail.orderItems" :key="item.id">
+					<image class="goods-image" :src="item.image" mode="aspectFill"></image>
+					<view class="goods-info">
+						<view class="goods-name">{{ item.goodsName }}</view>
+						<view class="goods-price-qty">
+							<text class="price">楼{{ item.flowPrice }}</text>
+							<text class="qty">x{{ item.num }}</text>
+						</view>
+					</view>
+				</view>
+			</view>
+		</view>
+
+		<!-- 鍦板潃濉啓琛ㄥ崟 -->
+		<view class="address-form">
+			<view class="form-title">閰嶉�佸湴鍧�</view>
+
+			<view class="form-item">
+				<text class="label">鏀惰揣浜�</text>
+				<input class="input" v-model="addressForm.consigneeName" placeholder="璇疯緭鍏ユ敹璐т汉濮撳悕" />
+			</view>
+
+			<view class="form-item">
+				<text class="label">鑱旂郴鐢佃瘽</text>
+				<input class="input" v-model="addressForm.consigneeMobile" placeholder="璇疯緭鍏ヨ仈绯荤數璇�" type="number" />
+			</view>
+
+			<view class="form-item">
+				<text class="label">鎵�鍦ㄥ湴鍖�</text>
+				<view class="picker-text" @click="showPicker">
+					{{ addressForm.___path || '璇烽�夋嫨鎵�鍦ㄥ湴鍖�' }}
+				</view>
+			</view>
+
+			<view class="form-item">
+				<text class="label">璇︾粏鍦板潃</text>
+				<textarea class="textarea" v-model="addressForm.consigneeDetail"
+					placeholder="璇疯緭鍏ヨ缁嗗湴鍧�锛堝琛楅亾銆侀棬鐗屽彿绛夛級"></textarea>
+			</view>
+		</view>
+
+		<!-- 鎻愪氦鎸夐挳锛堝凡閫傞厤瀹夊叏鍖哄煙锛� -->
+		<view class="submit-btn" @tap="submitAddress">淇濆瓨鍦板潃</view>
+
+		<!-- 鍦板潃閫夋嫨缁勪欢 -->
+		<m-city :provinceData="list" headTitle="鍖哄煙閫夋嫨" ref="cityPicker" @funcValue="getpickerParentValue" pickerSize="4">
+		</m-city>
+	</view>
+</template>
+
+<script>
+	import {
+		getOrderDetailEdit
+	} from '@/api/order.js'
+	import {
+		http
+	} from '@/utils/request.js'
+	import '@/components/uview-components/uview-ui';
+	import city from "../m-city/m-city.vue";
+	export default {
+		components: {
+			"m-city": city
+		},
+		data() {
+			return {
+				orderSn: '', // 璁㈠崟缂栧彿
+				orderDetail: {
+					orderItems: []
+				}, // 璁㈠崟璇︽儏
+				addressForm: {
+					consigneeName: '',
+					consigneeMobile: '',
+					consigneeAddressPath: '',
+					consigneeAddressIdPath: '',
+					consigneeDetail: '',
+					___path: '' // 鏄剧ず鐢ㄧ殑鍦板尯鏂囨湰
+				},
+				regionData: [
+					[],
+					[],
+					[]
+				], // 鐪佸競鍖烘暟鎹�
+				regionIndex: [0, 0, 0], // 閫変腑鐨勭储寮�
+				regionText: '', // 鏄剧ず鐨勫湴鍖烘枃鏈�
+				regionCodes: [], // 鍦板尯缂栫爜
+				list: [{
+					id: "",
+					localName: "璇烽�夋嫨",
+					children: [],
+				}, ]
+			}
+		},
+		onShow(){
+			console.log('瑙﹀彂onShow-------------------------->',this.orderSn)
+			this.loadOrderDetail()
+		},
+		onLoad(options) {
+			console.log('椤甸潰鍙傛暟:', options)
+			if (options.q) {
+				// 鍙岄噸瑙g爜锛氬井淇″URL杩涜浜嗕袱娆$紪鐮�
+				const decodedUrl = decodeURIComponent(decodeURIComponent(options.q));
+				console.log('鍘熷URL:', decodedUrl);
+			
+				// 瑙f瀽URL涓殑鏌ヨ鍙傛暟
+				const params = this.parseUrlParams(decodedUrl);
+				this.orderSn =  params.orderSn;
+				this.loadOrderDetail()
+			}
+		},
+		methods: {
+			// 瀹夊叏鐨則oast鏂规硶锛岄�傞厤灏忕▼搴忕幆澧�
+			safeShowToast(options) {
+				// 纭繚loading鍜屼箣鍓嶇殑toast宸插叧闂�
+				uni.hideLoading();
+				uni.hideToast();
+				// 浣跨敤nextTick纭繚鍦ㄤ笅涓�涓簨浠跺惊鐜腑鎵ц
+				this.$nextTick(() => {
+					uni.showToast({
+						...options,
+						duration: options.duration || 2000
+					});
+				});
+			},
+			
+			// 瑙f瀽URL鍙傛暟
+			parseUrlParams(url) {
+				const params = {};
+				// 澶勭悊鍙兘瀛樺湪鐨刪ash锛堝鏋滄湁鐨勮瘽锛�
+				const cleanUrl = url.split('#')[0];
+				const queryStr = cleanUrl.split('?')[1] || '';
+			
+				queryStr.split('&').forEach(pair => {
+					const [key, value] = pair.split('=');
+					if (key) {
+						// 濡傛灉鍊煎瓨鍦紝鍒欒В鐮侊紝鍚﹀垯璁句负绌哄瓧绗︿覆
+						params[key] = value ? decodeURIComponent(value) : '';
+					}
+				});
+			
+				return params;
+			},
+			// 鍔犺浇璁㈠崟璇︽儏
+			async loadOrderDetail() {
+				if (!this.orderSn) {
+					console.log('璁㈠崟鍙蜂负绌猴紝鏃犳硶鍔犺浇璁㈠崟璇︽儏');
+					this.safeShowToast({
+						title: '璁㈠崟鍙蜂笉鑳戒负绌�',
+						icon: 'none'
+					});
+					return;
+				}
+				
+				let loadingShown = false;
+				try {
+					uni.showLoading({
+						title: '鍔犺浇涓�...'
+					});
+					loadingShown = true;
+					
+					console.log('寮�濮嬭姹傝鍗曡鎯咃紝璁㈠崟鍙�:', this.orderSn);
+					const res = await getOrderDetailEdit(this.orderSn);
+					console.log('----------鑾峰彇璁㈠崟杩斿洖缁撴灉------------->',res);
+					
+					// 妫�鏌ュ搷搴旂姸鎬�
+					if (res && res.data) {
+						if (res.data.success) {
+							this.orderDetail = res.data.result;
+							console.log('----------------------->璁㈠崟鏁版嵁', JSON.stringify(this.orderDetail));
+						} else {
+							console.log('API杩斿洖澶辫触:', res.data.message);
+							// 鍏堝叧闂璴oading鍐嶆樉绀簍oast
+							uni.hideLoading();
+							loadingShown = false;
+							this.safeShowToast({
+								title: res.data.message || '鑾峰彇璁㈠崟淇℃伅澶辫触',
+								icon: 'none'
+							});
+						}
+					} else {
+						console.log('鏈嶅姟鍣ㄥ搷搴斿紓甯�:', res);
+						uni.hideLoading();
+						loadingShown = false;
+						this.safeShowToast({
+							title: '鏈嶅姟鍣ㄥ搷搴斿紓甯�',
+							icon: 'none'
+						});
+					}
+				} catch (error) {
+					console.error('鑾峰彇璁㈠崟璇︽儏澶辫触:', error);
+					// 缃戠粶寮傚父鎴栧叾浠栭敊璇�
+					if (loadingShown) {
+						uni.hideLoading();
+						loadingShown = false;
+					}
+					this.safeShowToast({
+						title: '缃戠粶寮傚父锛岃绋嶅悗閲嶈瘯',
+						icon: 'none'
+					});
+				} finally {
+					// 纭繚loading琚叧闂�
+					if (loadingShown) {
+						uni.hideLoading();
+					}
+				}
+			},
+
+			// 鍦板尯閫夋嫨鏀瑰彉
+			async onColumnChange(e) {
+				const {
+					column,
+					value
+				} = e.detail
+				this.regionIndex[column] = value
+
+				if (column === 0) {
+					// 閫夋嫨鐪佷唤鏃讹紝鍔犺浇鍩庡競鏁版嵁
+					const provinceId = this.regionData[0][value].id
+					try {
+						const cityRes = await http.request({
+							url: '/common/common/region/tree',
+							method: 'GET',
+							params: {
+								parentId: provinceId
+							}
+						})
+						if (cityRes.data.success) {
+							this.regionData[1] = cityRes.data.result.map(item => ({
+								name: item.name,
+								id: item.id
+							}))
+							this.regionData[2] = []
+							this.regionIndex[1] = 0
+							this.regionIndex[2] = 0
+						}
+					} catch (error) {
+						console.error('鍔犺浇鍩庡競鏁版嵁澶辫触:', error)
+					}
+				} else if (column === 1) {
+					// 閫夋嫨鍩庡競鏃讹紝鍔犺浇鍖哄幙鏁版嵁
+					const cityId = this.regionData[1][value].id
+					try {
+						const areaRes = await http.request({
+							url: '/common/common/region/tree',
+							method: 'GET',
+							params: {
+								parentId: cityId
+							}
+						})
+						if (areaRes.data.success) {
+							this.regionData[2] = areaRes.data.result.map(item => ({
+								name: item.name,
+								id: item.id
+							}))
+							this.regionIndex[2] = 0
+						}
+					} catch (error) {
+						console.error('鍔犺浇鍖哄幙鏁版嵁澶辫触:', error)
+					}
+				}
+			},
+
+			// 鍦板尯閫夋嫨纭
+			onRegionChange(e) {
+				const {
+					value
+				} = e.detail
+				this.regionIndex = value
+
+				const province = this.regionData[0][value[0]]
+				const city = this.regionData[1][value[1]]
+				const area = this.regionData[2][value[2]]
+
+				if (province && city && area) {
+					this.regionText = `${province.name} ${city.name} ${area.name}`
+					this.addressForm.consigneeAddressIdPath = `${province.id},${city.id},${area.id}`
+				}
+			},
+
+			// 鏄剧ず鍦板潃閫夋嫨鍣�
+			showPicker() {
+				this.$nextTick(() => {
+					if (this.$refs.cityPicker) {
+						this.$refs.cityPicker.show();
+					}
+				});
+			},
+
+			// 鍦板潃閫夋嫨鍥炶皟
+			getpickerParentValue(e) {
+				// 灏嗛渶瑕佺粦瀹氱殑鍦板潃璁剧疆涓虹┖锛屽苟璧嬪��
+				this.addressForm.consigneeAddressIdPath = '';
+				let name = "";
+				let idPath = [];
+				let namePath = []
+
+				e.forEach((item, index) => {
+					if (item.id) {
+						// 閬嶅巻鏁版嵁
+						idPath.push(item.id);
+						namePath.push(item.localName);
+						name += item.localName;
+						this.addressForm.___path = name;
+					}
+				});
+
+				// 璁剧疆鍦板潃璺緞
+				this.addressForm.consigneeAddressIdPath = idPath.join(',');
+				this.addressForm.consigneeAddressPath = namePath.join(',');
+			},
+
+			// 鎻愪氦鍦板潃
+			async submitAddress() {
+				// 琛ㄥ崟楠岃瘉
+				if (!this.addressForm.consigneeName) {
+					uni.showToast({
+						title: '璇疯緭鍏ユ敹璐т汉濮撳悕',
+						icon: 'none'
+					})
+					return
+				}
+				if (!this.addressForm.consigneeMobile) {
+					uni.showToast({
+						title: '璇疯緭鍏ヨ仈绯荤數璇�',
+						icon: 'none'
+					})
+					return
+				}
+				if (!/^1[3-9]\d{9}$/.test(this.addressForm.consigneeMobile)) {
+					uni.showToast({
+						title: '璇疯緭鍏ユ纭殑鎵嬫満鍙�',
+						icon: 'none'
+					})
+					return
+				}
+				if (!this.addressForm.consigneeAddressIdPath || !this.addressForm.___path) {
+					uni.showToast({
+						title: '璇烽�夋嫨鎵�鍦ㄥ湴鍖�',
+						icon: 'none'
+					})
+					return
+				}
+				if (!this.addressForm.consigneeDetail) {
+					uni.showToast({
+						title: '璇疯緭鍏ヨ缁嗗湴鍧�',
+						icon: 'none'
+					})
+					return
+				}
+
+				try {
+					uni.showLoading({
+						title: '淇濆瓨涓�...'
+					})
+					console.log('-------------------->', JSON.stringify(this.addressForm))
+					// 鎻愪氦鍦板潃鍒拌鍗曪紙娉ㄩ噴閮ㄥ垎涓哄疄闄呮帴鍙h皟鐢ㄩ�昏緫锛�
+					const res = await http.request({
+						url: `/order/order/update/editAddress/${this.orderSn}/consignee`,
+						method: 'POST',
+						needToken: true,
+						data: this.addressForm
+					})
+					console.log("鍦板潃淇濆瓨")
+					if (res.data.success) {
+						// uni.showToast({
+						// 	title: '鍦板潃淇濆瓨鎴愬姛',
+						// 	icon: 'success'
+						// })
+						uni.redirectTo({
+							url:'/pages/tabbar/index/home',
+							fail(e) {
+								console.log("璺宠浆澶辫触鍘熷洜",e)
+							}
+						})
+					} else {
+						uni.showToast({
+							title: res.data.message || '淇濆瓨澶辫触',
+							icon: 'none'
+						})
+					}
+				} catch (error) {
+					console.error('鎻愪氦鍦板潃澶辫触:', error)
+					uni.showToast({
+						title: '淇濆瓨澶辫触锛岃閲嶈瘯',
+						icon: 'none'
+					})
+				} finally {
+					uni.hideLoading()
+				}
+			}
+		}
+	}
+</script>
+
+<style scoped>
+	/* 鏍瑰鍣細搴曢儴鍐呰竟璺濋�傞厤鎸夐挳+瀹夊叏鍖哄煙 */
+	.edit-address-page {
+		background-color: #f5f5f5;
+		min-height: 100vh;
+		/* 鎸夐挳楂樺害(100rpx) + 瀹夊叏鍖哄煙楂樺害 + 棰濆闂磋窛(20rpx)锛岄伩鍏嶅唴瀹硅鎸夐挳閬尅 */
+		padding-bottom: calc(100rpx + 20rpx + constant(safe-area-inset-bottom));
+		padding-bottom: calc(100rpx + 20rpx + env(safe-area-inset-bottom));
+	}
+
+	/* 璁㈠崟淇℃伅鍖哄煙 */
+	.order-info {
+		background: white;
+		margin: 20rpx;
+		padding: 30rpx;
+		border-radius: 16rpx;
+	}
+
+	.order-title {
+		font-size: 32rpx;
+		font-weight: bold;
+		margin-bottom: 20rpx;
+		color: #333;
+	}
+
+	.order-sn {
+		font-size: 28rpx;
+		color: #666;
+		margin-bottom: 30rpx;
+	}
+
+	/* 鍟嗗搧鍒楄〃 */
+	.goods-item {
+		display: flex;
+		align-items: center;
+		padding: 20rpx 0;
+		border-bottom: 1rpx solid #f0f0f0;
+	}
+
+	.goods-item:last-child {
+		border-bottom: none;
+	}
+
+	.goods-image {
+		width: 120rpx;
+		height: 120rpx;
+		border-radius: 12rpx;
+		margin-right: 20rpx;
+	}
+
+	.goods-info {
+		flex: 1;
+	}
+
+	.goods-name {
+		font-size: 28rpx;
+		color: #333;
+		margin-bottom: 10rpx;
+		line-height: 1.4;
+	}
+
+	.goods-price-qty {
+		display: flex;
+		justify-content: space-between;
+		align-items: center;
+	}
+
+	.price {
+		font-size: 28rpx;
+		color: #ff6b35;
+		font-weight: bold;
+	}
+
+	.qty {
+		font-size: 24rpx;
+		color: #666;
+	}
+
+	/* 鍦板潃琛ㄥ崟鍖哄煙 */
+	.address-form {
+		background: white;
+		margin: 20rpx;
+		padding: 30rpx;
+		border-radius: 16rpx;
+	}
+
+	.form-title {
+		font-size: 32rpx;
+		font-weight: bold;
+		margin-bottom: 30rpx;
+		color: #333;
+	}
+
+	.form-item {
+		display: flex;
+		align-items: flex-start;
+		margin-bottom: 30rpx;
+		min-height: 80rpx;
+	}
+
+	.label {
+		width: 160rpx;
+		font-size: 28rpx;
+		color: #333;
+		line-height: 80rpx;
+		flex-shrink: 0;
+	}
+
+	.input {
+		flex: 1;
+		height: 80rpx;
+		line-height: 80rpx;
+		font-size: 28rpx;
+		color: #333;
+		padding: 0 20rpx;
+		border: 1rpx solid #e0e0e0;
+		border-radius: 8rpx;
+	}
+
+	.picker-text {
+		flex: 1;
+		height: 80rpx;
+		line-height: 80rpx;
+		font-size: 28rpx;
+		color: #333;
+		padding: 0 20rpx;
+		border: 1rpx solid #e0e0e0;
+		border-radius: 8rpx;
+		background: white;
+	}
+
+	.textarea {
+		flex: 1;
+		min-height: 120rpx;
+		font-size: 28rpx;
+		color: #333;
+		padding: 20rpx;
+		border: 1rpx solid #e0e0e0;
+		border-radius: 8rpx;
+		line-height: 1.4;
+	}
+
+	/* 搴曢儴鎻愪氦鎸夐挳锛堟牳蹇冿細閫傞厤瀹夊叏鍖哄煙锛� */
+	.submit-btn {
+		position: fixed;
+		bottom: 0;
+		left: 0;
+		right: 0;
+		height: 100rpx;
+		line-height: 100rpx;
+		/* 淇濊瘉鏂囧瓧鍨傜洿灞呬腑 */
+		background: #ff6b35;
+		color: white;
+		text-align: center;
+		font-size: 32rpx;
+		font-weight: bold;
+		/* 鍏煎鏂版棫iOS鍜屽畨鍗撶殑瀹夊叏鍖哄煙 */
+		padding-bottom: constant(safe-area-inset-bottom);
+		/* iOS 11.0-11.1 */
+		padding-bottom: env(safe-area-inset-bottom);
+		/* iOS 11.2+ 鍙婂畨鍗� */
+	}
+</style>
\ No newline at end of file

--
Gitblit v1.8.0