index.js
3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
Page({
/**
* 页面的初始数据
*/
data: {
tabBarList: [{
name: '工作台',
iconPath: '/packageStoreAssistant/images/icon_activity.png',
selectedIconPath: '/packageStoreAssistant/images/icon_activity_active.png',
}, {
name: '发现',
iconPath: '/packageStoreAssistant/images/icon_discovery.png',
selectedIconPath: '/packageStoreAssistant/images/icon_discovery_active.png',
}, {
name: '我的',
iconPath: '/packageStoreAssistant/images/icon_mine.png',
selectedIconPath: '/packageStoreAssistant/images/icon_mine_active.png',
}],
tabIndex: 0,
pageShow: new Array(3).fill(false)
},
onPageScroll({
scrollTop
}) {
this.getComponentPage().onPageScroll && this.getComponentPage().onPageScroll(scrollTop)
},
/**
* 生命周期函数--监听页面加载
*/
onRoute: function (options) {
if (!wx.$storage.get('userInfo')) wx.$router.go('/pages/Login/Login')
const { tabIndex } = this.data
if (options && options.tabIndex) {
if (tabIndex == 0 && !this.pageShow) {
this.setData({
tabIndex: options.tabIndex,
[`pageShow[${options.tabIndex}]`]: true
})
this.pageShow = true
}
} else
this.setData({
['pageShow[0]']: true
})
this.getComponentPage().onLoad && this.getComponentPage().onLoad(options)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () { },
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getComponentPage().onShow && this.getComponentPage().onShow()
},
getComponentPage() {
const {
tabIndex
} = this.data
return this.selectComponent(`#page-${tabIndex}`)
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () { },
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () { },
changeTabBar(e) {
let {
pageShow
} = this.data,
tabIndex = e.detail, {
loginData,
options
} = this
this.setData({
tabIndex,
myTabIdx: e.myTabIdx
})
if (!pageShow[tabIndex]) {
if (!loginData) this.onRoute()
else this.getComponentPage().onLoad && this.getComponentPage().onLoad(loginData, options)
}
this.setData({
[`pageShow[${tabIndex}]`]: true
})
this.onShow()
// 修复核销扫码后进入此tab不刷新问题
if (options && options.indexFresh) {
this.options.indexFresh = null
this.getComponentPage().onLoad && this.getComponentPage().onLoad(loginData, options)
}
},
onShareAppMessage: function (options) {
if (options.target && options.target.dataset.tab == 2) {
const { merchantId } = wx.$storage.get("userInfo");
const {channel} = options.target.dataset
let path = '/packageDiscovery/pages/index/index'
if (merchantId) path = `${path}?merchantId=${merchantId}&channel=${channel.channelType}`
return {
path,
title: channel.promotion,
imageUrl: channel.publicityImg
}
}
},
})