directional.js
6.74 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
// packageEquity/pages/directional/directional.js
import {
ssoApi,
couponsApi,
shopmallApi
} from '../../../api/api'
import {
defaultMerchantId
} from '../../../api/environment'
Page({
data: {
imgBaseURL: 'https://img02.glsx.com.cn/weapp/resource/equity-h5-new/mini/',
errorMsg: '',
phoneNum: '',
isFocus: false,
showInput:false
},
onbindblur() {
// this.setData({
// isFocus:false
// })
},
clickFocus() {
this.setData({
isFocus: true
})
},
deleteInput() {
this.setData({
phoneNum: '',
isFocus: false
})
},
intPhoneNum(e) {
let value = e.detail.value
const {
giftsData
} = this.data
let flag = false
if (giftsData.receiveWay == 1) {
const mPattern = /^1[34578]\d{9}$/;
if (!value.match(mPattern)) {
flag = true
}
}
this.setData({
phoneNum: e.detail.value,
errorPhone: flag,
errorMsg: ''
})
},
toRecivedGifts() {
const {
phoneNum,
errorPhone,
giftsData
} = this.data
if (!phoneNum && giftsData.receiveWay == 1) {
this.setData({
errorMsg: '请输入手机号码!'
})
return
}
if (errorPhone && giftsData.receiveWay == 1) {
this.setData({
errorMsg: '请输入正确的手机号码!'
})
return
}
if ((phoneNum.length < 6 || !phoneNum) && giftsData.receiveWay == 2) {
this.setData({
errorMsg: '请输入您车架号后6位领取!'
})
return
}
// if(giftsData.receivedFlag==2){
// wx.$util.showToast('该礼包已被领取')
// return
// }
this.handlerHttp(phoneNum)
},
// 领取礼包接口处理
handlerHttp(phoneNum) {
const merchantId = wx.$util.getStorageSync('srcm_shopmall_merchant_id')
let newMerchantId = merchantId || defaultMerchantId
const {
giftsData,
loginInfo
} = this.data
let para = {
directionalGiftId: giftsData.id,
nickName: loginInfo.nickName,
nickUrl: loginInfo.headImgUrl,
phone: loginInfo.phone,
receiveCondition: phoneNum,
merchantId: newMerchantId,
directionalGiftChildId:this.data.childId
}
if(this.data.staff){
Object.assign(para,this.data.staff)
}
wx.$util.showLoading()
wx.$Track.setTrack({
...para,
type: '领取定向礼包'
}, 7)
couponsApi.giftsRecive(para).then(res => {
wx.$util.showLoading()
if (res) {
res.map(item => {
item.receiveStartTime = new Date(item.receiveStartTime).format('yyyy.MM.dd')
if (item.effectiveType == 1) {
item.receiveEndTime = new Date(item.receiveEndTime).format('yyyy.MM.dd hh:mm:ss')
} else {
item.receiveEndTime = new Date(item.receiveEndTime).format('yyyy.MM.dd')
}
// 这是为了适应详情跳转
item.couponId = item.id
item.id = item.userCouponId
return item
})
}
let temp = JSON.stringify(res)
wx.navigateTo({
url: '/packageMine/pages/coupon/index/index?pageFrom=directional&list=' + temp
})
})
},
login(options) {
getApp().login(true).then(res => {
if (res.data) {
let {
phone,
sessionId,
headImgUrl,
nickName
} = res.data
wx.$authStatus = phone ? false : true
if (res.data.isLogin) {
wx.$util.setUserInfo(res.data)
wx.$util.setSessionId(res.data.sessionId)
}
this.setData({
loginInfo: res.data,
showAuthBtn: phone ? false : true,
sessionId,
showAvatarBtn: headImgUrl ? false : true
}, () => {
if (options.scene) { //扫码
this.getLiveActivityId(decodeURIComponent(options.scene))
} else { // 短链
wx.$util.decodeUrlLink(options)
if (!options.id) {
return
}
if(options.staffUUID){
const {staffUUID,staffName} = options
this.data.staff = {
staffUUID,
staffName
}
}
if(options.childId){
this.data.childId = options.childId
}
this.getGiftsDetailData(options.id)
}
})
}
})
},
// 授权手机号
getPhoneNumber({
detail
}) {
delete detail.errMsg
if (detail.iv && detail.encryptedData) {
const {
sessionId
} = this.data
if (!sessionId) return
wx.$util.showLoading()
detail.sessionId = sessionId
ssoApi.authUserPhone(detail).then(({
data,
code
}) => {
wx.hideLoading()
if (code == '0') {
wx.$Track.setTrack({},3)
wx.$authStatus = false
wx.$util.setUserInfo(data)
wx.$util.setSessionId(data.sessionId)
this.data.sessionId = data.sessionId
this.setData({
showAuthBtn: false,
loginInfo: data
})
this.toRecivedGifts()
}
})
}
},
getUserInfo(e) {
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
let {
loginInfo
} = this.data
loginInfo.headImgUrl = res.userInfo.avatarUrl
loginInfo.nickName = res.userInfo.nickName
this.setData({
loginInfo: res.userInfo,
showAvatarBtn: false
})
}
})
},
async onLoad(options) {
await this.login(options)
},
setNaviTitle(title) {
wx.setNavigationBarTitle({
title
})
},
// 查询定向礼包详情
getGiftsDetailData(id) {
wx.$util.showLoading()
couponsApi.giftsDetail({
id,
sessionId: this.data.sessionId,
childId:this.data.childId
}).then(res => {
wx.hideLoading()
this.setNaviTitle(res.name)
this.setData({
giftsData: res,
showInput:true
})
})
},
// 获取scene
getLiveActivityId(str) {
console.log(str);
shopmallApi.getLiveActivityId({
id: str.split('=')[1]
}).then(({
code,
data,
}) => {
if (code == 0) {
let op = {}
data.scene.split('&').map(item => {
const [key, val] = item.split("=")
op[key] = val
})
if (op.merchantId) wx.$util.setStorageSync('srcm_shopmall_merchant_id', op.merchantId)
if(op.staffUUID){
const {staffUUID,staffName} = op
this.data.staff = {
staffUUID,
staffName
}
}
if(op.childId){
this.data.childId = op.childId
}
this.getGiftsDetailData(op.id)
}
})
},
})