From 802290838fd05c7236dae780900b4bacb20c82df Mon Sep 17 00:00:00 2001
From: xuxueyang <xuxy@fengyuntec.com>
Date: 星期五, 02 八月 2024 16:27:26 +0800
Subject: [PATCH] add 二维码格式

---
 pages/user/supplier-user.vue |   80 +++++++++++++++++++++++++---------------
 1 files changed, 50 insertions(+), 30 deletions(-)

diff --git a/pages/user/supplier-user.vue b/pages/user/supplier-user.vue
index 1f9cdfa..c9da5b7 100644
--- a/pages/user/supplier-user.vue
+++ b/pages/user/supplier-user.vue
@@ -179,13 +179,13 @@
 				<view class="right-icon">
 					<uni-icons type="right"></uni-icons>
 				</view>
-			</view>
-		<!-- 	<view class="user-util m-t-12 flex" v-if="selftype==='partner'"
-				@click="goto('/sub_pages/partner/partner-info/partner-code-v2',true)">
-				<view class="title">测试二维码</view>
-				<view class="right-icon">
-					<uni-icons type="right"></uni-icons>
-				</view>
+			</view>
+		<!-- 	<view class="user-util m-t-12 flex" v-if="selftype==='partner'"
+				@click="goto('/sub_pages/partner/partner-info/partner-code-v2',true)">
+				<view class="title">测试二维码</view>
+				<view class="right-icon">
+					<uni-icons type="right"></uni-icons>
+				</view>
 			</view> -->
 			<!-- #endif -->
 			<!-- #ifdef PUB_CUSTOMER -->
@@ -343,7 +343,11 @@
 		onLoad(options) {
 			// const url = options.q ? decodeURIComponent(options.q) : '';
 			// const urlcode = options.url && decodeURIComponent(options.url) || ''
-
+			// #ifdef PUB_CUSTOMER
+			if (options.partnerUserId) {
+				this.bindPartnerUser(options.partnerUserId, options.partnerUserName)
+			}
+			// #endif
 
 
 		},
@@ -355,8 +359,25 @@
 			uni.stopPullDownRefresh()
 		},
 		methods: {
+			async bindPartnerUser(userId, name) {
+				await this.$message.confirm(`确定要绑定${name}合伙人吗?`)
+				//调用接口绑定
+				this.$message.showLoading()
+				const {
+					code,
+					data
+				} = await this.$http.request('post', '/api/customer/bind/partner', {
+					data: {
+						partnerUserId: userId
+					}
+				})
+				this.$message.hideLoading()
+				if (code == 0) {
+					this.$message.showToast(`绑定合伙人${name}成功`)
+					await this.$store.dispatch('getCurrentInfo')
+				}
+			},
 			async scanPartnerCode() {
-				await this.$message.confirm('确定要绑定合伙人吗?')
 				//扫二维码确认
 				let that = this
 				uni.scanCode({
@@ -364,31 +385,28 @@
 						console.log('条码内容:' + res.result);
 						var dto = undefined
 						try {
-							dto = JSON.parse(res.result)
+							if (res.result && res.result.startsWith('http://') && res.result.indexOf(
+									'partnerUserId') >= 0) {
+								var arr = res.result.split("?")[1].split("&")
+								dto = {}
+								for (var item of arr) {
+									var tarr = item.split("=")
+									if (tarr[1]) {
+										dto[tarr[0]] = dto[tarr[1]]
+									}
+								}
+								dto['name'] = dto['partnerUserName'] || dto['partnerUserId'] || '佚名'
+								dto['userId'] = dto['partnerUserId'] || ''
+
+							} else {
+								dto = JSON.parse(res.result)
+
+							}
 							if (!!dto['userId']) {
 								var partnerName = dto['name'] || ''
 								var partnerId = dto['userId'] || ''
-								//调用接口绑定
-								that.$message.showLoading()
-								const {
-									code,
-									data
-								} = await that.$http.request('post', '/api/customer/bind/partner', {
-									data: {
-										partnerUserId: partnerId
-									}
-								})
-								that.$message.hideLoading()
-								if (code == 0) {
-									that.$message.showToast(`绑定合伙人${partnerName}成功`)
-									await that.$store.dispatch('getCurrentInfo')
+								that.bindPartnerUser(partnerId, partnerName)
 
-									// setTimeout(async () => {
-									// 	that.$message.showLoading()
-									// 	that.$message.hideLoading()
-									// }, 1000)
-
-								}
 							} else {
 								that.$message.showToast('二维码格式不正确扫码失败')
 							}
@@ -402,6 +420,8 @@
 					}
 				});
 			},
+
+
 			toInfo() {
 				var url = ''
 				if (this.currentInfo.id) {

--
Gitblit v1.9.3