|
|
@@ -94,6 +94,7 @@ import HomeActivitySection from '@/components/home/activitySection.vue'
|
|
|
import HomeGoodsSection from '@/components/home/goodsSection.vue'
|
|
|
import ShopTabBar from '@/components/shop-tab-bar/index.vue'
|
|
|
import { getHome } from '@/api/home-page-config'
|
|
|
+import { getHdInfo } from '@/api/hd'
|
|
|
import { getInfo } from '@/api/shop'
|
|
|
|
|
|
export default {
|
|
|
@@ -131,10 +132,7 @@ export default {
|
|
|
this.refreshCartBadgeCount()
|
|
|
},
|
|
|
onShareAppMessage() {
|
|
|
- let path = 'pages/home/index?account=' + this.account
|
|
|
- if (this.myCustomId > 0) {
|
|
|
- path += '&inviterCustomId=' + this.myCustomId
|
|
|
- }
|
|
|
+ const path = this.appendInviterCustomId('pages/home/index?account=' + this.account)
|
|
|
return {
|
|
|
title: this.merchantName || '店铺首页',
|
|
|
path
|
|
|
@@ -200,28 +198,57 @@ export default {
|
|
|
})
|
|
|
this.cartBadgeCount = count
|
|
|
},
|
|
|
+ /** 拉取当前用户 custom.id,仅用于分享追加 inviterCustomId */
|
|
|
+ syncMyCustomId() {
|
|
|
+ const hdId = Number(this.hdId) || Number(uni.getStorageSync('hdId')) || 0
|
|
|
+ const applyShopRes = (shopRes) => {
|
|
|
+ if (!shopRes || shopRes.code !== 1 || !shopRes.data) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (shopRes.data.custom && shopRes.data.custom.id) {
|
|
|
+ this.myCustomId = Number(shopRes.data.custom.id)
|
|
|
+ }
|
|
|
+ if (shopRes.data.info) {
|
|
|
+ this.shopInfo = shopRes.data.info
|
|
|
+ uni.setStorageSync('currentShop', shopRes.data.info)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (hdId > 0) {
|
|
|
+ return getInfo({ hdId }).then(applyShopRes)
|
|
|
+ }
|
|
|
+ const account = Number(this.account) || 0
|
|
|
+ if (account <= 0) {
|
|
|
+ return Promise.resolve()
|
|
|
+ }
|
|
|
+ uni.setStorageSync('account', account)
|
|
|
+ return getHdInfo().then((res) => {
|
|
|
+ if (res.code == 1 && res.data.hd && res.data.hd.id) {
|
|
|
+ uni.setStorageSync('hdId', res.data.hd.id)
|
|
|
+ return getInfo({ hdId: res.data.hd.id }).then(applyShopRes)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /** 在分享 path 后追加 inviterCustomId */
|
|
|
+ appendInviterCustomId(path) {
|
|
|
+ if (this.myCustomId <= 0) {
|
|
|
+ return path
|
|
|
+ }
|
|
|
+ const sep = path.indexOf('?') >= 0 ? '&' : '?'
|
|
|
+ return path + sep + 'inviterCustomId=' + this.myCustomId
|
|
|
+ },
|
|
|
/** 页面初始化:并行拉取首页配置与门店信息(merchantName) */
|
|
|
init() {
|
|
|
this.loading = true
|
|
|
this.refreshCartBadgeCount()
|
|
|
- const tasks = [getHome()]
|
|
|
- if (this.hdId) {
|
|
|
- tasks.push(getInfo({ hdId: this.hdId }))
|
|
|
+ const account = this.account
|
|
|
+ if (account) {
|
|
|
+ uni.setStorageSync('account', account)
|
|
|
}
|
|
|
- Promise.all(tasks)
|
|
|
- .then((results) => {
|
|
|
- const homeRes = results[0]
|
|
|
- const shopRes = results[1]
|
|
|
+ Promise.all([getHome(), this.syncMyCustomId()])
|
|
|
+ .then(([homeRes]) => {
|
|
|
if (homeRes.code === 1 && homeRes.data) {
|
|
|
this.pageData = homeRes.data
|
|
|
}
|
|
|
- if (shopRes && shopRes.code === 1 && shopRes.data && shopRes.data.info) {
|
|
|
- this.shopInfo = shopRes.data.info
|
|
|
- uni.setStorageSync('currentShop', shopRes.data.info)
|
|
|
- }
|
|
|
- if (shopRes && shopRes.code === 1 && shopRes.data.custom && shopRes.data.custom.id) {
|
|
|
- this.myCustomId = Number(shopRes.data.custom.id)
|
|
|
- }
|
|
|
})
|
|
|
.finally(() => {
|
|
|
this.loading = false
|