index.js
5.47 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
const navStyle = "background-color: transparent;";
import { IMG_URL } from '~/config';
import { env } from '~/api/env/index'
import { MERCHANT_STATIC_LIST} from '~/utils/constants'
Page({
data: {
IMG_URL,
navStyle,
noticeContent: '',
bannerList: [],
codeList: [{
title: '官方',
desc: '福利群',
tip: '优惠资讯,先人一步',
url: 'welfareGroupQRCode',
banner:'fuliqun_banner'
}, {
title: '专属',
desc: '福利官',
tip: '超多福利,不容错过',
url: 'welfareOfficerQRCode',
banner:'fuliguan_banner'
}],
showModal: false,
urlName: '',
merchantName: '深圳中海美居',
// 门店列表
storeList: []
},
navbarReady(e) {
let { height } = e.detail;
this.setData({
navBarHeight: height,
user_box_style: `padding-top:${height + 10}px`,
});
},
// 处理滚动事件
onPageScroll(e) {
const { navBarHeight } = this.data;
this.setData({
navStyle: e.scrollTop >= navBarHeight - 50 ? "" : navStyle,
});
},
onLoad(options) {
this.defaultMerchant = wx.$merchant_id
const FIRST = wx.p.storage.get('first_enter_miniprograme')
if (FIRST) {
this.getMerchantList()
} else {
wx.p.eventbus.on('STORE', () => {
this.getMerchantList()
})
}
this.getStrategyList();
this.shareTitle = "甄选福利"
},
// 获取省钱攻略
getStrategyList() {
wx.p.api.strategyApi
.getStrategyList({
pageNum: 1,
pageSize: 100,
mainFlag: 1,
})
.then((res) => {
this.setData({
strategyList: res.list,
});
});
},
selectStrategy(e) {
const { id } = e.detail;
wx.p.router.go("/packageStrategy/pages/strategyDetail/index", {
id,
notIntercept: true
});
},
toShowQrCode(e) {
const { item } = e.currentTarget.dataset;
const { currentStore } = this.data
this.setData({
urlName: currentStore[item.url] || '',
showModal: true,
bannerName:item.banner
});
},
closeModal() {
this.setData({
showModal: false,
urlName: "",
});
},
toHomeLife() {
wx.p.router.go("/packageIndex/pages/homeLife/index", { notIntercept: true });
},
toCarLife() {
wx.p.router.go("/packageIndex/pages/carLife/index", { notIntercept: true });
},
// 门店切换
changeStore(e) {
const index = +e.detail.value
const { storeList } = this.data
const currentStore = storeList[index]
wx.$merchant_id = currentStore.merchantId
wx.p.storage.set('merchant_info', {
merchantId: currentStore.merchantId,
})
wx.p.eventbus.emit('MALL_FRESH')
this.setData({
currentStore
},()=>{
this.getMerchantIdDetail(currentStore.merchantId)
})
},
// 获取门店列表
async getMerchantList() {
// 获取mock配置门店
const MOCKDATA = wx.p.storage.get("mock_data");
let MerchantList = MERCHANT_STATIC_LIST[env]
if (MOCKDATA && MOCKDATA.add_wuye_merchant) {
const ADD_MERCHANT_LIST = MOCKDATA.add_wuye_merchant[env]
if (ADD_MERCHANT_LIST && ADD_MERCHANT_LIST.length) {
MerchantList = [...MerchantList, ...ADD_MERCHANT_LIST]
}
}
const HAVE_ENTER = wx.p.storage.get('first_enter_miniprograme')
// 获取扫码链接带入的门店
if (HAVE_ENTER && !this.fresh) {
const merchant = wx.p.storage.get('first_enter_merchantId')
const ISNEWMERCHANT = MerchantList.includes(JSON.parse(merchant))
this.defaultMerchant = merchant
if(!ISNEWMERCHANT){
MerchantList.push(merchant)
}
}
let storeList = [], index = 0
storeList = await this.getMerchantListData(MerchantList) || []
storeList.forEach((ele, i) => {
ele.merchantId = ele.merchantNo
if (this.defaultMerchant == ele.merchantId) {
index = i
}
})
const currentStore = storeList[index]
wx.$merchant_id = currentStore.merchantId
wx.p.storage.set('merchant_info', {
merchantId: currentStore.merchantId,
})
this.setData({
storeList,
currentStore
}, () => {
this.getMerchantIdDetail(currentStore.merchantId)
})
},
onPullDownRefresh() {
this.fresh = true
this.defaultMerchant = this.getStorageMerchantId()
this.getMerchantList()
this.getStrategyList();
},
onShow() {
const FIRST = wx.p.storage.get('first_enter_miniprograme')
this.setData({
showStore: !FIRST
})
},
// 获取门店id
getStorageMerchantId() {
const {
merchantId
} = wx.p.storage.get('merchant_info')
return merchantId
},
// 获取门店列表
async getMerchantListData(merchantIdList) {
const res = await wx.p.api.shopmallApi.getStoreList({ merchantIdList })
if(res.code==0) return res.data
else return false
},
// 获取选择门店的信息
getMerchantIdDetail(merchantId) {
wx.$merchant_id = merchantId
wx.p.api.homeApi.getHomeConfig({ merchantId }).then(data => {
let {
noticeContent,welfareGroupQRCode,welfareOfficerQRCode
} = data
let bannerList = [], { currentStore } = this.data
if (data.bannerList && data.bannerList.length) bannerList = data.bannerList
currentStore.noticeContent = noticeContent
currentStore.bannerList = bannerList
currentStore.welfareGroupQRCode = welfareGroupQRCode
currentStore.welfareOfficerQRCode = welfareOfficerQRCode
this.setData({
currentStore
})
})
},
onShareAppMessage(){}
});