index.js
8.35 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
const app = getApp()
import mapApi from '../../../utils/mapapi/mapapi'
Page({
options: {
styleIsolation: 'shared'
},
/**
* 组件的属性列表
*/
properties: {},
/**
* 组件的初始数据
*/
data: {
IMGURL: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/hmd/',
IMGURKBASE: 'equity/version/1_0_0/',
userInfo: {},
isOpen: true,
menuList: [{
title: '惠享生活',
desc: '5折起',
icon: 'share_icon',
url: '/packageEquity/pages/commodity/list/list'
},
{
title: '充值优惠',
desc: '5折起',
icon: 'charge_vip',
url: '/packageEquity/pages/commodity/charge/charge'
},
{
title: '全部服务',
desc: '更多',
icon: 'all_icon',
url: '/packageEquity/pages/allEquity/allEquity'
}
],
storePackageList: [],
showMorePack: false,
tabList: ['附近优惠'],
curTabIndex: 0,
pageParam: {
appearance: 1,
pageSize: 0,
pageCount: 10
},
commodityList: [],
loadingMore: false,
loadOver: false,
// 是否登录
showLogin: false,
showPage: true,
// 会员类型-背景
vipStatus: {
1: 'gold_vip_bg',
2: 'silver_vip_bg',
3: 'pt_vip_bg'
},
// 普通会员3 银卡2 金卡1 非会员 0
identity: 0,
titleClass: {
0: '',
1: 'gold_title',
2: 'sliver_title',
3: 'card_title',
},
dateClass: {
0: '',
1: 'gold_date',
2: 'sliver_date',
3: 'card_date',
}
},
/**
* 组件的方法列表
*/
onLoad() {
this.getShopPackage()
this.getMemberCardData()
let freecard = wx.p.storage.get('bindInfo')
if (freecard) {
let bingInfo = JSON.parse(decodeURIComponent(freecard))
const sid = bingInfo.data.sessionId
wx.p.cache.storageApi.setSessionId(sid)
this.handleFreeCard(bingInfo)
}
this.setData({
isOpen: wx.p.storage.get('sessionId') ? true : false
})
},
onShow() {
let authComponent = this.selectComponent('#authorize')
if (authComponent) authComponent.check()
// if (this.data.userInfo && !this.data.userInfo.phone) return
this.toCheckMember()
},
onPullDownRefresh() {
this.getShopPackage()
this.toCheckMember()
app.globalData.goodsCommodityList = []
app.globalData.goodsPageParam.pageSize = 0
app.globalData.goodsLoaded = false
let { currentAddress } = this.data
if(!currentAddress) return
const { lat, lng } = currentAddress.location
this.toGetCommodity(lat, lng, false, 1)
},
onReachBottom() {
if (this.data.unauthorized) {
return
}
if (!this.data.commodityList.length) {
return
}
let {
currentAddress
} = this.data
if(!currentAddress) return
const {
lat,
lng
} = currentAddress.location
this.toGetCommodity(lat, lng)
},
// 新版
openMorePack(e) {
const {
show
} = e.currentTarget.dataset
this.setData({
showMorePack: !show
})
},
// 页面跳转
// toAllEquityPage() {
// wx.p.router.go('/packageEquity/pages/allEquity/allEquity')
// },
toBuyMember() {
wx.p.router.go('/packageEquity/pages/open/open', {
notIntercept: true
})
},
toNewPage(e) {
const {
index,
item
} = e.currentTarget.dataset
wx.p.router.go(item.url, {
notIntercept: true
})
},
// 定位
async getLocation() {
try {
const res = await this.getAddressInfo()
this.toGetCommodity(res.location.lat, res.location.lng, 1)
this.setData({
currentAddress: res,
unauthorized: false
})
wx.p.storage.set('unauthorized', false)
} catch (error) {
console.log(error)
}
},
// 获取附近优惠数据
toGetCommodity(lat, lng, firstLoad) {
let para = {
lat,
lng,
...app.globalData.goodsPageParam
}
if (app.globalData.goodsLoaded || (firstLoad && app.globalData.goodsPageParam?.length)) {
this.setData({
commodityList: app.globalData.goodsCommodityList,
})
return
}
para.pageOffset = para.pageSize
wx.p.api.equityApi.getLasteCommodity(para).then(res => {
if (!res?.data?.length) {
app.globalData.goodsLoaded = true
return
}
app.globalData.goodsPageParam.pageSize = res.pageOffset
let tempArr = []
res.data.forEach(item => {
tempArr.push(item)
})
app.globalData.goodsCommodityList = app.globalData.goodsCommodityList.concat(tempArr)
app.globalData.goodsLoaded = false
this.setData({
commodityList: app.globalData.goodsCommodityList,
})
})
},
// 重新收起获取定位
relocation() {
this.setData({
showAuth: true
})
},
/**授权失败 */
authFail() {
wx.p.storage.set('unauthorized', true)
this.setData({
unauthorized: true
})
},
/**授权成功 */
authSuccess() {
this.getLocation()
},
// 获取门店套餐
getShopPackage() {
const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = {
merchantId
}
wx.p.api.equityApi.storePackage(para).then(res => {
this.setData({
storePackageList: res || []
})
})
},
// 去套餐详情页
toPackageDetail(e) {
const {
id
} = e.currentTarget.dataset
wx.p.router.go('/packageEquity/pages/package/package', {
id,
notIntercept: true
})
},
// 获取用户会员信息
toCheckMember() {
let sid = wx.p.storage.get('sessionId')
if (!sid) {
this.setData({
isOpen: false
})
return
}
wx.p.api.equityApi.checkOpenMember().then(res => {
let flag = false,
identity = 0 // 普通会员3 银卡2 金卡1 非会员 0
if (res.data && res.data.validitDate) {
res.data.time = new Date(res.data.validitDate).format('yyyy.MM.dd')
}
if (res.data && res.data.endTime) {
res.data.endTime = new Date(res.data.endTime).format('yyyy.MM.dd')
}
// 普通会员
if (res.code == 0 && res.data) {
flag = true
identity = 3
if (res.data && res.data.cardTypeSpecial) {
identity = res.data.cardTypeSpecial
}
}
wx.p.storage.set('isVIP', flag)
this.setData({
isOpen: flag,
vipInfo: res.data,
identity
})
})
},
// 获取门店会员卡信息
getMemberCardData() {
const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = {
merchantId
}
wx.p.api.equityApi.memberCard(para).then(res => {
this.setData({
memberInfo: res
})
})
},
// 处理免费领取权益页面带来的参数---弹框显示
handleFreeCard(bindInfo) {
wx.p.storage.rm('bindInfo')
const {
code,
errId,
message
} = bindInfo
if (code == 0) {
wx.showModal({
title: '提示',
content: '领取成功',
confirmText: '确定',
showCancel: false,
confirmColor: '#F13C3D'
})
this.toCheckMember()
} else if (code == -1 && errId == 20321) {
wx.showModal({
title: '提示',
content: message,
confirmText: '续费开通',
cancelText: '不用了',
confirmColor: '#F13C3D'
}).then(res => {
if (res.confirm) {
this.toBuyMember()
}
})
} else if (errId == 20320 || errId == 20322) {
wx.showModal({
title: '提示',
content: message,
confirmText: '确定',
showCancel: false,
confirmColor: '#F13C3D'
})
}
},
// 检测是否已经登录
checkLogin() {
return wx.p.authStatus
},
async getAddressInfo() {
let addressInfo = wx.p.storage.get('address_info')
return new Promise(resolve => {
if (addressInfo && Date.now() - addressInfo.createTime < 2 * 60 * 1e3) resolve(addressInfo)
else
wx.getLocation({
type: 'gcj02'
}).then(({
latitude,
longitude
}) => {
mapApi.detailedAdrress([latitude, longitude]).then(detail => {
let info = {
...detail,
createTime: Date.now()
}
resolve(info)
wx.p.storage.set('address_info', info)
})
})
})
}
})