首页添加本地店铺和旗舰店的切换功能
This commit is contained in:
@ -87,6 +87,14 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="">
|
||||
<view class="flex row-center white br60 sm flex-none switch-btn" @tap="switchFlagship" v-if="cityInfo && cityInfo.id !== 0 && shopInfo.id !== 1">
|
||||
切换旗舰店
|
||||
</view>
|
||||
<view class="flex row-center white br60 sm flex-none switch-btn" @tap="switchLocal" v-else-if="appConfig.is_open_nearby && cityInfo && cityInfo.id === 0">
|
||||
切换当地店
|
||||
</view>
|
||||
</view>
|
||||
<!-- <view
|
||||
class="flex row-center white br60 sm flex-none subscribe-btn"
|
||||
:class="{ gray: shopInfo.shop_follow_status === 1 }"
|
||||
@ -228,6 +236,8 @@ import { getShopLive } from '@/api/live'
|
||||
import { getGoodsList } from '@/api/store'
|
||||
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js'
|
||||
import { getCouponList } from '@/api/activity'
|
||||
import { strToParams } from '../../utils/tools'
|
||||
import { scanHome } from '@/api/user'
|
||||
|
||||
export default {
|
||||
mixins: [MescrollMixin], // 使用mixin
|
||||
@ -264,11 +274,17 @@ export default {
|
||||
enableFix: true,
|
||||
id: '',
|
||||
shopLive: {},
|
||||
|
||||
superiorUserId: 0,
|
||||
hasHandleSuperior: false
|
||||
}
|
||||
},
|
||||
async onLoad() {
|
||||
// this.id = this.$Route.query.id
|
||||
if (this.$Route.query && this.$Route.query.scene) {
|
||||
const params = strToParams(this.$Route.query.scene)
|
||||
this.superiorUserId = params.user_id || 0
|
||||
}
|
||||
console.log("🚀 ~ this.superiorUserId:", this.superiorUserId)
|
||||
console.log("🚀 ~ this.$Route.query:", this.$Route.query)
|
||||
this.sys = uni.getSystemInfoSync()
|
||||
await this.getShopInfoFun()
|
||||
await this.getShopGoodsCategoryFun()
|
||||
@ -278,6 +294,7 @@ export default {
|
||||
// #endif
|
||||
this.isFirstLoading = false
|
||||
this.mescroll.resetUpScroll()
|
||||
this.handleSuperiorUser()
|
||||
},
|
||||
onHide() {
|
||||
// #ifdef H5
|
||||
@ -288,6 +305,7 @@ export default {
|
||||
// #ifdef H5
|
||||
this.enableFix = true
|
||||
// #endif
|
||||
this.handleSuperiorUser()
|
||||
},
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
@ -297,6 +315,43 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
...mapActions(['initLocationFunc']),
|
||||
|
||||
switchFlagship() {
|
||||
this.$store.commit('setCityInfo', { id: 0, name: '旗舰店' })
|
||||
},
|
||||
|
||||
switchLocal() {
|
||||
this.initLocationFunc() // This sets cityInfo which triggers the watcher to refresh content due to id > 0
|
||||
},
|
||||
|
||||
handleSuperiorUser() {
|
||||
console.log("🚀 ~ this.superiorUserId:", this.superiorUserId)
|
||||
console.log("🚀 ~ this.hasHandleSuperior:", this.hasHandleSuperior)
|
||||
if (this.superiorUserId > 0 && !this.hasHandleSuperior) {
|
||||
if (!this.isLogin) {
|
||||
this.$Router.push('/pages/login/login')
|
||||
return
|
||||
}
|
||||
this.hasHandleSuperior = true
|
||||
this.scanHomeFun()
|
||||
}
|
||||
},
|
||||
|
||||
async scanHomeFun() {
|
||||
try {
|
||||
const { code, msg } = await scanHome({
|
||||
user_id: this.superiorUserId
|
||||
})
|
||||
if (code === 1) {
|
||||
console.log('scanHome success:', msg)
|
||||
} else {
|
||||
console.log('scanHome error:', msg)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('scanHome error:', error)
|
||||
}
|
||||
},
|
||||
|
||||
getCurrentCity() {
|
||||
if (!this.appConfig.is_open_nearby) return
|
||||
this.initLocationFunc()
|
||||
@ -430,7 +485,7 @@ export default {
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['sysInfo', 'appConfig', 'cityInfo']),
|
||||
...mapGetters(['sysInfo', 'appConfig', 'cityInfo', 'isLogin']),
|
||||
navHeight() {
|
||||
return this.sysInfo.navHeight + 'px'
|
||||
},
|
||||
@ -451,7 +506,7 @@ export default {
|
||||
watch: {
|
||||
'cityInfo.id': {
|
||||
async handler(val, oldVal) {
|
||||
if (val && val !== oldVal) {
|
||||
if (val !== undefined && val !== oldVal) {
|
||||
await this.getShopInfoFun()
|
||||
await this.getShopGoodsCategoryFun()
|
||||
// #ifdef MP-WEIXIN
|
||||
@ -500,6 +555,13 @@ page {
|
||||
background: #ccc;
|
||||
}
|
||||
}
|
||||
|
||||
.switch-btn {
|
||||
background: linear-gradient(97deg, #ff5784 0%, #ff2c3c 100%);
|
||||
height: 52rpx;
|
||||
padding: 0 16rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user