Bläddra i källkod

邀请注册问题

shish 2 månader sedan
förälder
incheckning
2f8f6b9a64

+ 25 - 48
hdApp/src/admin/home/login.vue

@@ -71,6 +71,7 @@ import { getDictionaries,postWxCode } from '@/api/mini'
 import { replaceClientId } from '@/api/admin'
 import { phoneLogin,wxMobileLogin } from "@/api/auth";
 import { ghsInfo } from "@/api/ghs/index";
+import { navigateAfterLogin, defaultNavigateBack } from "@/utils/pendingGhsInvite";
 export default {
 	name: "login",
 	mixins: [],
@@ -120,6 +121,27 @@ export default {
 	},
 	methods: {
 		...mapActions(['setUserShopAll']),
+		handleLoginSuccessNavigation(){
+			let that = this
+			if(this.option.fromType && this.option.fromType == 2){
+				that.$util.pageTo({url: "/admin/ll/list", type:2})
+				return
+			}
+			if(this.option.itemId && Number(this.option.itemId)>0 && this.option.ghsShopId && Number(this.option.ghsShopId)>0){
+				ghsInfo({shopId:this.option.ghsShopId}).then(resInfo => {
+					let ghsId = resInfo.data.id
+					if(Number(ghsId)>0){
+						that.$util.pageTo({url: "/admin/ghsProduct/detail?id="+that.option.itemId+'&ghsId='+ghsId, type:2})
+					}
+				})
+				return
+			}
+			navigateAfterLogin(that, that.option).then(handled => {
+				if (!handled) {
+					defaultNavigateBack()
+				}
+			})
+		},
 		register(){
 			let itemId = this.option.itemId ? this.option.itemId : 0
 			let ghsShopId = this.option.ghsShopId ? this.option.ghsShopId : 0
@@ -277,32 +299,7 @@ export default {
 							that.$store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
 							getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
 							that.setUserShopAll()
-
-							if(this.option.fromType && this.option.fromType == 2){
-								//跳转失信人员页面
-								that.$util.pageTo({url: "/admin/ll/list", type:2})
-								return false
-							}
-
-							if(this.option.itemId && Number(this.option.itemId)>0 && this.option.ghsShopId && Number(this.option.ghsShopId)>0){
-								ghsInfo({shopId:this.option.ghsShopId}).then(resInfo => {
-									let ghsId = resInfo.data.id
-									if(Number(ghsId)>0){
-										that.$util.pageTo({url: "/admin/ghsProduct/detail?id="+that.option.itemId+'&ghsId='+ghsId, type:2})
-									}
-								})
-							}else{
-								//返回上一页带参数
-								let pages = getCurrentPages();
-								let prevPage = pages[ pages.length - 2 ];
-								if (prevPage && prevPage.$vm) {
-									prevPage.$vm.backAction = 'login'
-									uni.navigateBack()
-								} else {
-									// H5 直接访问登录页,没有上一页,回首页
-									uni.reLaunch({ url: '/admin/home/workbench' })
-								}
-						}
+							that.handleLoginSuccessNavigation()
 					}
 				});
 		} else {
@@ -367,17 +364,7 @@ export default {
 										that.$store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
 										getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
 										that.setUserShopAll()
-
-										//返回上一页带参数
-										let pages = getCurrentPages();
-										let prevPage = pages[ pages.length - 2 ];
-										if (prevPage && prevPage.$vm) {
-											prevPage.$vm.backAction = 'login'
-											uni.navigateBack()
-										} else {
-											// H5 直接访问登录页,没有上一页,回首页
-											uni.reLaunch({ url: '/admin/home/workbench' })
-										}
+										that.handleLoginSuccessNavigation()
 
 										// #ifdef APP-PLUS
 										//保存安卓的clientId
@@ -467,17 +454,7 @@ export default {
 
 						getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
 						that.setUserShopAll()
-
-						//返回上一页带参数
-						let pages = getCurrentPages();
-						let prevPage = pages[ pages.length - 2 ];
-						if (prevPage && prevPage.$vm) {
-							prevPage.$vm.backAction = 'login'
-							uni.navigateBack()
-						} else {
-							// H5 直接访问登录页,没有上一页,回首页
-							uni.reLaunch({ url: '/admin/home/workbench' })
-						}
+						that.handleLoginSuccessNavigation()
 
 						// #ifdef APP-PLUS
 						//保存安卓的clientId

+ 25 - 2
hdApp/src/admin/home/workbench.vue

@@ -158,8 +158,14 @@
 
             <block v-else>
 
-              <!-- 如果没有请求过接口,不确定这个花店,有没批发店,暂时不显示找批发店的入口,避免引起争议 -->
-              <block v-if="hasRequestApi == 0">
+              <block v-if="hasPendingGhsInvite">
+                <view class="location-empty-box">
+                  <view class="location-empty-title">您有未完成的批发店邀请</view>
+                  <view class="location-empty-subtitle">请先完成绑定后再采购</view>
+                  <button class="location-empty-btn" @click="goPendingInviteGhs()">去购买</button>
+                </view>
+              </block>
+              <block v-else-if="hasRequestApi == 0">
                   <view  class="location-empty-box">
                     <view class="location-empty-title">暂无批发店</view>
                   </view>
@@ -237,6 +243,7 @@
   import { hasNotice } from "@/api/admin";
   import { APIHOST } from "@/config";
   import permision from "@/utils/wa-permission_1.1/permission.js";
+  import { hasPendingInvite, getGhsProductQueryFromPending } from "@/utils/pendingGhsInvite";
   export default {
     name: "workbench",
     mixins: [autoUpdateMixins],
@@ -268,6 +275,9 @@
         if (!this.supplierSearchTime) return false;
         const twoDays = 2 * 24 * 60 * 60 * 1000;
         return (Date.now() - this.supplierSearchTime) < twoDays;
+      },
+      hasPendingGhsInvite() {
+        return hasPendingInvite()
       }
     },
     watch: {
@@ -326,6 +336,12 @@
         this.showBoughtTooltip = false;
         uni.setStorageSync('boughtTooltipClosed', '1');
       },
+      goPendingInviteGhs() {
+        const query = getGhsProductQueryFromPending()
+        if (query) {
+          this.pageTo({ url: '/pagesPurchase/ghsProduct', query: query })
+        }
+      },
       onChooseAvatar(e){
         if(this.loginInfo && this.loginInfo.staff && this.loginInfo.staff.founder != 2){
           this.$msg('门店LOGO请老板修改')
@@ -1109,6 +1125,13 @@
     margin-bottom: 40upx;
   }
 
+  .location-empty-subtitle {
+    font-size: 28upx;
+    color: #999;
+    margin-top: -20upx;
+    margin-bottom: 40upx;
+  }
+
   .location-empty-btn {
     background-color: #09C567;
     color: #fff;

+ 26 - 23
hdApp/src/pagesClient/official/apply.vue

@@ -133,6 +133,7 @@ import { checkShop } from '@/api/shop'
 import { ghsInfo } from "@/api/ghs/index";
 import { getMobile } from "@/api/auth";
 import {getHasMap} from "@/api/express"
+import { savePendingInviteFromOption, tryBindPendingInvite, optionHasInviteContext, clearPendingInvite } from "@/utils/pendingGhsInvite";
 export default {
   name: "apply-data",
   components: {
@@ -184,6 +185,11 @@ export default {
 		...mapGetters(["getLoginInfo"])
 	},
   onLoad () {
+    if (optionHasInviteContext(this.option)) {
+      savePendingInviteFromOption(this.option)
+    } else {
+      clearPendingInvite()
+    }
     const token = uni.getStorageSync('token')
     this.headers.token = token
     // #ifdef APP-PLUS
@@ -420,34 +426,31 @@ export default {
             uni.setNavigationBarTitle({ title: res.name }) 
           })
           that.setUserShopAll()
-          // #ifdef APP-PLUS
-          //保存安卓的clientId
-          // let hasClientId = !that.$util.isEmpty(subRes.data.admin.clientId) ? subRes.data.admin.clientId : ''
-          // const clientInfo = plus.push.getClientInfo()
-          // let currentClientId = !that.$util.isEmpty(clientInfo.clientid) ? clientInfo.clientid : ''
-          // if(hasClientId == '' || hasClientId != currentClientId){
-          //   replaceClientId({id:currentClientId})
-          // }
-          // #endif
 
         }
 
-        //去失信人员列表
-        if(this.option.fromType && this.option.fromType == 2){
-          this.$util.pageTo({url: "/admin/ll/list", type:2})
-          return
-        }
+        const goAfterRegister = () => {
+          //去失信人员列表
+          if(this.option.fromType && this.option.fromType == 2){
+            this.$util.pageTo({url: "/admin/ll/list", type:2})
+            return
+          }
 
-        if(this.option.itemId && Number(this.option.itemId)>0 && this.option.ghsShopId && Number(this.option.ghsShopId)>0){
-          ghsInfo({shopId:this.option.ghsShopId}).then(resInfo => {
-            let ghsId = resInfo.data.id
-            if(Number(ghsId)>0){
-              that.$util.pageTo({url: "/admin/ghsProduct/detail?id="+that.option.itemId+'&ghsId='+ghsId, type:2})
-            }
-          })
-        }else{
-          this.$util.pageTo({url: "/pagesClient/official/result", type:2})
+          if(this.option.itemId && Number(this.option.itemId)>0 && this.option.ghsShopId && Number(this.option.ghsShopId)>0){
+            ghsInfo({shopId:this.option.ghsShopId}).then(resInfo => {
+              let ghsId = resInfo.data.id
+              if(Number(ghsId)>0){
+                that.$util.pageTo({url: "/admin/ghsProduct/detail?id="+that.option.itemId+'&ghsId='+ghsId, type:2})
+              }
+            })
+          }else{
+            this.$util.pageTo({url: "/pagesClient/official/result", type:2})
+          }
         }
+
+        tryBindPendingInvite().then(() => {
+          goAfterRegister()
+        })
       });
     }
   },

+ 14 - 0
hdApp/src/pagesClient/official/result.vue

@@ -12,6 +12,7 @@
 </template>
 <script>
 import appResult from '@/components/app-result'
+import { getGhsProductQueryFromPending, getPendingInvite } from '@/utils/pendingGhsInvite'
 export default {
 	name: "ApplyResult",
 	components:{
@@ -26,6 +27,14 @@ export default {
     onUnload() {
     },
     onLoad () {
+      const pending = getPendingInvite()
+      if (pending) {
+        this.fromCg = pending.fromCg || 0
+        if (pending.source == 'mall_sun_code' || pending.source == 'ghsCgOption') {
+          this.scene = pending.ghsShopId ? 'pending' : ''
+        }
+        return
+      }
       //供货商打开小程序分享给客户,客户需要采购进来
       let ghsCgOption = uni.getStorageSync('ghsCgOption')
       if(ghsCgOption.fromCg){
@@ -45,6 +54,11 @@ export default {
         this.$util.pageTo({url: "/admin/home/workbench", type:3})
       },
       beginCg(){
+        const pendingQuery = getGhsProductQueryFromPending()
+        if (pendingQuery) {
+          this.$util.pageTo({url: "/pagesPurchase/ghsProduct", query: pendingQuery, type:2})
+          return
+        }
         if(this.fromCg == 1){
           // #ifdef APP-PLUS
           this.$util.pageTo({url: "/admin/home/workbench", type:3})

+ 19 - 4
hdApp/src/pagesPurchase/ghsProduct.vue

@@ -207,6 +207,7 @@ import AppActivilyCoupon from "@/components/module/app-activily-coupon";
 import { mapGetters } from "vuex";
 import { getGhsDataApi, ghsInfo, visitMall } from "@/api/ghs";
 import { getLimitBuyInfo } from "@/api/purchase";
+import { savePendingInviteFromOption, tryBindPendingInvite, getPendingInvite, restorePendingInviteFromLegacy } from "@/utils/pendingGhsInvite";
 export default {
 	name: "ghsProduct",
 	components: {
@@ -276,12 +277,17 @@ export default {
 	watch: {
 		loginInfo: {
 			deep: true,
-			handler: function(val) {
+			handler: function(val, oldVal) {
 				if(this.$util.isEmpty(val)){
 					this.notOpenShop = true
-				}else{
-					this.hdShopAdminId = val.shopAdminId
-					this.notOpenShop = false
+					return
+				}
+				this.hdShopAdminId = val.shopAdminId
+				this.notOpenShop = false
+				if (oldVal !== undefined && this.$util.isEmpty(oldVal)) {
+					tryBindPendingInvite().then(() => {
+						this.init()
+					})
 				}
 			},
 			immediate:true
@@ -513,6 +519,15 @@ export default {
 			uni.setNavigationBarTitle({title: this.ghsInfo.name})
 		},
 		init(){
+			savePendingInviteFromOption(this.option)
+			if (!getPendingInvite()) {
+				const legacyScene = uni.getStorageSync('ghsCgScene')
+				if (legacyScene) {
+					savePendingInviteFromOption({ scene: legacyScene })
+				} else {
+					restorePendingInviteFromLegacy()
+				}
+			}
 
 			//通过供货商小程序分享进采购页,注册的客户,注册后引导返回采购页
 			if(this.option.fromCg && this.option.fromCg == 1){

+ 197 - 0
hdApp/src/utils/pendingGhsInvite.js

@@ -0,0 +1,197 @@
+import { ghsInfo } from '@/api/ghs/index'
+
+const PENDING_KEY = 'pendingGhsInvite'
+const TTL_MS = 7 * 24 * 60 * 60 * 1000
+
+function parseSceneToInvite(scene) {
+	if (!scene) {
+		return null
+	}
+	const sceneStr = decodeURIComponent(scene)
+	const sceneArray = {}
+	sceneStr.split('&').forEach(item => {
+		const arr = item.split('=')
+		if (arr[0]) {
+			sceneArray[arr[0]] = arr[1] || ''
+		}
+	})
+	const ghsShopId = sceneArray.sId || sceneArray.shopId || 0
+	if (!ghsShopId) {
+		return null
+	}
+	return {
+		ghsShopId: ghsShopId,
+		ghsShopAdminId: sceneArray.gId || sceneArray.ghsShopAdminId || 0,
+		fromCg: 0,
+		source: 'mall_sun_code'
+	}
+}
+
+function migrateFromLegacy() {
+	const ghsCgOption = uni.getStorageSync('ghsCgOption')
+	if (ghsCgOption && ghsCgOption.shopId) {
+		const invite = {
+			ghsShopId: ghsCgOption.shopId,
+			ghsShopAdminId: ghsCgOption.ghsShopAdminId || 0,
+			fromCg: ghsCgOption.fromCg || 0,
+			source: 'ghsCgOption',
+			ts: Date.now()
+		}
+		uni.setStorageSync(PENDING_KEY, invite)
+		return invite
+	}
+	const scene = uni.getStorageSync('ghsCgScene')
+	if (scene) {
+		const invite = parseSceneToInvite(scene)
+		if (invite) {
+			invite.ts = Date.now()
+			uni.setStorageSync(PENDING_KEY, invite)
+			return invite
+		}
+	}
+	return null
+}
+
+export function optionHasInviteContext(option) {
+	if (!option) {
+		return false
+	}
+	if (option.scene) {
+		return true
+	}
+	if (option.shopId || option.sId) {
+		return true
+	}
+	if (option.fromCg == 1) {
+		return true
+	}
+	if (option.ghsShopAdminId && Number(option.ghsShopAdminId) > 0) {
+		return true
+	}
+	if (option.fromGhsId && Number(option.fromGhsId) > 0) {
+		return true
+	}
+	return false
+}
+
+export function savePendingInviteFromOption(option) {
+	if (!option) {
+		option = {}
+	}
+	let invite = null
+	if (option.scene) {
+		invite = parseSceneToInvite(option.scene)
+		if (invite) {
+			invite.fromCg = option.fromCg || 0
+		}
+	} else if (option.shopId || option.sId) {
+		invite = {
+			ghsShopId: option.shopId || option.sId,
+			ghsShopAdminId: option.ghsShopAdminId || option.gId || 0,
+			fromCg: option.fromCg || 0,
+			source: option.fromCg == 1 ? 'from_cg' : 'query'
+		}
+	} else if (option.ghsShopAdminId) {
+		const scene = uni.getStorageSync('ghsCgScene')
+		if (scene) {
+			invite = parseSceneToInvite(scene)
+		}
+	}
+	if (!invite || !invite.ghsShopId) {
+		return false
+	}
+	invite.ts = Date.now()
+	uni.setStorageSync(PENDING_KEY, invite)
+	return true
+}
+
+export function getPendingInvite() {
+	let data = uni.getStorageSync(PENDING_KEY)
+	if (!data || !data.ghsShopId) {
+		return null
+	}
+	if (data.ts && Date.now() - data.ts > TTL_MS) {
+		clearPendingInvite()
+		return null
+	}
+	return data
+}
+
+export function restorePendingInviteFromLegacy() {
+	if (getPendingInvite()) {
+		return getPendingInvite()
+	}
+	return migrateFromLegacy()
+}
+
+export function hasPendingInvite() {
+	return !!getPendingInvite()
+}
+
+export function clearPendingInvite() {
+	uni.removeStorageSync(PENDING_KEY)
+}
+
+export function getGhsProductQueryFromPending(pending) {
+	if (!pending) {
+		pending = getPendingInvite()
+	}
+	if (!pending || !pending.ghsShopId) {
+		return null
+	}
+	return {
+		shopId: pending.ghsShopId,
+		id: 0,
+		ghsShopAdminId: pending.ghsShopAdminId || 0,
+		fromCg: pending.fromCg || 0
+	}
+}
+
+export function tryBindPendingInvite() {
+	const token = uni.getStorageSync('token')
+	if (!token) {
+		return Promise.resolve(false)
+	}
+	const pending = getPendingInvite()
+	if (!pending || !pending.ghsShopId) {
+		return Promise.resolve(false)
+	}
+	return ghsInfo({ shopId: pending.ghsShopId }).then(res => {
+		if (res.code == 1 && res.data && res.data.id > 0) {
+			clearPendingInvite()
+			return true
+		}
+		return false
+	}).catch(() => false)
+}
+
+export function navigateAfterLogin(vm, option) {
+	const pending = getPendingInvite()
+	if (!pending || !pending.ghsShopId) {
+		return Promise.resolve(false)
+	}
+	if (option && option.fromType && option.fromType == 2) {
+		return Promise.resolve(false)
+	}
+	if (option && option.itemId && Number(option.itemId) > 0 && option.ghsShopId && Number(option.ghsShopId) > 0) {
+		return Promise.resolve(false)
+	}
+	const query = getGhsProductQueryFromPending(pending)
+	return tryBindPendingInvite().then(() => {
+		if (vm && vm.$util && query) {
+			vm.$util.pageTo({ url: '/pagesPurchase/ghsProduct', query: query, type: 2 })
+		}
+		return true
+	})
+}
+
+export function defaultNavigateBack() {
+	const pages = getCurrentPages()
+	const prevPage = pages[pages.length - 2]
+	if (prevPage && prevPage.$vm) {
+		prevPage.$vm.backAction = 'login'
+		uni.navigateBack()
+	} else {
+		uni.reLaunch({ url: '/admin/home/workbench' })
+	}
+}