bindPhone.vue
10.6 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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<template>
<view class="container flex-items-plus flex-column">
<global-loading />
<view class="login-logoBox">
<image class="login-logo" src="@/static/logo.png"></image>
</view>
<view class="loginInfo fs26 font-color-999">
<p>共建真实、安全的交易环境</p>
<p>本平台承诺不会滥用您授权的信息</p>
</view>
<view class="verifyTypeBox" v-show="verifyType === 0">
<view class="verifyItem" @click="verifyType = 1">
短信验证码
</view>
<view class="verifyItem verify-checked" @click="verifyType = 2">
小程序授权
</view>
</view>
<view class="phoneVerify" v-if="verifyType == 1">
<view class="iphoneNum-box flex-row-plus flex-items">
<view style="margin-right: 30rpx">
<image class="loginIcon" src="https://zhgw-uat.028wlkj.com/cdwlMall/zsfwzxt/file/static/images/phone.png"></image>
</view>
<view>
<input v-model="phone" placeholder-class="iphoneNum-input" type="number" placeholder="请输入您的手机号" />
</view>
</view>
<view class="flex-row-plus mar-top-20">
<view class="code-box">
<view style="margin-right: 30rpx">
<image class="loginIcon" src="https://zhgw-uat.028wlkj.com/cdwlMall/zsfwzxt/file/static/images/code.png"></image>
</view>
<view>
<input v-model="code" placeholder-class="codeNum-input" placeholder="请输入验证码" />
</view>
</view>
<view :class="disabled === true ? 'on' : ''" :disabled="disabled" class="getcode" @click="codede">{{text}}
</view>
</view>
<view class="mar-top-60">
<view class="registerBut mar-top-100" :class="{bindCls: phone !== '' && code !== ''}" @click="bindPhone">确认</view>
</view>
<!--<u-popup v-model="bindPhoneShow" class="popupbind" mode="center" border-radius="14" @close="closepopupbind"
:closeable="true" close-icon-pos="top-right" close-icon-size="20">
<view class="popupbind-box flex-items-plus">
<view class="flex-column flex-items-plus" style="width: 95%;">
<view class="fa38 font-color-C5AA7B">提示</view>
<view class="mar-top-50" style="width: 90%;">此手机号已经绑定其他微信号,暂时无法与您的微信账号进行绑定。</view>
</view>
</view>
</u-popup>-->
</view>
<view class="mpVerify" v-if="verifyType == 2">
<button v-if="mpAlipay" class="verifyPhone" open-type="getAuthorize" @getAuthorize="onGetAuthorize" @error="onAuthError"
scope='phoneNumber'>授权手机号验证</button>
<button class="verifyPhone fs28 mar-top-100" open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber">微信手机号授权</button>
</view>
<view v-if="verifyType !== 0" class="backBtn" @click="verifyType = 0">返回</view>
</view>
</template>
<script>
import sendVerifyCode from "@/mixins/SendVerifyCode";
const NET = require('../../utils/request')
const API = require('../../config/api')
export default {
data() {
return {
disabled: false,
phone: '',
code: '',
wechatOpenId: '',
headImage: '',
bindPhoneShow: false,
verifyType: 0,
buyerUserId: 0,
isMp: false,
mpAlipay: false,
mpWechat: false
};
},
onLoad(options) {
if (options.data) {
const bindPhoneData = JSON.parse(options.data)
this.wechatOpenId = bindPhoneData.wechatOpenId
this.headImage = bindPhoneData.headImage
this.buyerUserId = bindPhoneData.buyerUserId
}
// #ifdef MP
this.isMp = true
// #endif
// #ifdef MP-ALIPAY
this.mpAlipay = true
// #endif
// #ifdef MP-WEIXIN
this.mpWechat = true
// #endif
},
mixins: [sendVerifyCode],
methods: {
closepopupbind() {
this.bindPhoneShow = false
},
codede() {
let phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
if (this.phone == '') {
uni.showToast({
title: '请输入手机号!',
duration: 2000,
icon: 'none'
});
} else if (!phoneCodeVerification.test(this.phone)) {
uni.showToast({
title: '请输入正确的手机号!',
duration: 2000,
icon: 'none'
});
} else {
NET.request(API.Verify, {
phone: this.phone,
}, 'GET').then(res => {
this.sendCode()
}).catch(res => {
uni.showToast({
title: res.data.message,
duration: 2000,
icon: 'none'
});
})
}
},
bindPhone() {
// #ifdef MP-ALIPAY
this.updateAliPhone(this.phone, false)
// #endif
// #ifdef MP-WEIXIN
this.updateWxPhone()
// #endif
},
onGetAuthorize() {
const that = this
// uni.showLoading({
// mask: true,
// title: '验证中...',
// })
this.$showLoading()
my.getPhoneNumber({
success: (res) => {
this.$hideLoading()
let encryptedData = res.response;
that.updateAliPhone(encryptedData, true)
},
fail: (res) => {
this.$hideLoading()
console.log('getPhoneNumber failed', res);
uni.hideLoading()
uni.showToast({
title: '验证失败',
icon: 'none'
})
}
});
},
onAuthError() {
console.log('onAuthError')
},
getPhoneNumber(e) {
if (e.detail.errMsg === "getPhoneNumber:ok") {
console.log(e)
uni.login({
provider: 'weixin',
success: (res) => {
NET.request(API.GetSessionKey, {
code: res.code,
}, 'POST').then(res1 => {
NET.request(API.SetWxPhone, {
wechatOpenId: res1.data.wechatOpenId,
sessionKey: res1.data.sessionKey,
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
headImage: this.headImage
}, 'POST').then(res2 => {
const item = res2.data
uni.setStorageSync('storage_key', item);
console.log(uni.getStorageSync('storage_key'))
this.bindSalesCustomer()
this.gotoHome()
}).catch(res => {})
}).catch(err => {
console.log(err, 22222)
})
},
fail: () => {
uni.showToast({
title: "微信登录授权失败",
icon: "none"
});
}
})
} else {
uni.showToast({
title: "获取手机授权失败",
icon: "none"
});
}
},
updateWxPhone() {
NET.request(API.UpdateWxPhone, {
phone: this.phone,
wechatOpenId: this.wechatOpenId,
headImage: this.headImage,
verificationCode: this.code,
channelCode: this.channelCode
}, 'POST').then(res => {
const item = res.data
uni.setStorageSync('storage_key', item);
this.bindSalesCustomer()
uni.showToast({
title: '绑定成功',
duration: 2000,
icon: 'none'
});
this.gotoHome()
}).catch(res => {
this.bindPhoneShow = true
})
},
updateAliPhone(encryptedData, encrypted) {
NET.request(API.UpdateAliPhone, {
'phone': encryptedData,
'buyerUserId': this.buyerUserId,
'encrypted': encrypted
}, 'POST').then(res => {
console.log('UpdateAliPhone res: ', res)
const item = res.data
uni.setStorageSync('storage_key', item);
this.bindSalesCustomer()
this.phone = item.phone
uni.showToast({
title: '绑定成功',
duration: 2000,
icon: 'none'
});
this.gotoHome()
}).finally(res => {
uni.hideLoading()
})
},
bindSalesCustomer() {
const shopId = uni.getStorageSync('shopId')
const salesId = uni.getStorageSync('salesId')
if (shopId && salesId) {
// 多次调用绑定方法,不提示任何信息即可
console.log('bindPhone bindSalesCustomer')
NET.request(API.BindSalesCustomer, {
shopId: shopId,
distributorId: salesId
}, 'POST').then(res => {
uni.removeStorageSync('salesId');
uni.removeStorageSync('shopId');
}).catch(res => {
console.log('bindPhone bindSalesCustomer error')
console.dir(res)
})
}
},
gotoHome() {
// #ifdef MP-ALIPAY
uni.navigateTo({
url: '/pages/tabbar/user/index'
})
// #endif
// #ifndef MP-ALIPAY
uni.switchTab({
url: '/pages/tabbar/user/index'
})
// #endif
}
}
}
</script>
<style lang="scss">
.container {
background-color: #FFFFFF;
height: 100vh;
.login-logoBox {
margin-top: 100upx;
.login-logo {
width: 234upx;
height: 193upx;
}
}
.loginInfo {
margin: 130rpx 0 50rpx 0;
text-align: center;
}
.verifyTypeBox {
width: 98%;
.verifyItem {
width: 80%;
display: block;
text-align: center;
border: 2upx solid #F3F4F5;
padding: 30upx;
font-size: 34upx;
margin: 0 auto 30rpx auto;
color: #C5AA7B;
}
.verify-checked {
color: white;
background: #C5AA7B;
}
}
.phoneVerify {
height: 450upx;
.iphoneNum-box {
border-bottom: 1rpx solid #DDDDDD;
height: 100rpx;
width: 600rpx;
.loginIcon {
width: 40rpx;
height: 53rpx;
}
.iphoneNum-input {
color: #999999;
font-size: 28rpx;
font-weight: 400;
}
}
.passwordNum-box {
border-bottom: 1rpx solid #DDDDDD;
height: 100rpx;
width: 600rpx;
.passwordNum-input {
color: #999999;
font-size: 28rpx;
font-weight: 400;
width: 346rpx;
}
}
.code-box {
border-bottom: 1rpx solid #DDDDDD;
height: 100rpx;
width: 360rpx;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
.loginIcon {
width: 44rpx;
height: 50rpx;
}
.code-lab {
width: 200rpx;
}
.codeNum-input {
color: #999999;
font-size: 28rpx;
font-weight: 400;
}
}
.getcode {
background-color: #39be7a;
height: 100rpx;
width: 230rpx;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
margin-left: 20rpx;
color: #FFFFFF;
}
.registerBut {
background: #F3F4F5;
color: #999999;
height: 100rpx;
width: 600rpx;
text-align: center;
line-height: 100rpx;
margin-top: 30rpx;
}
.bindCls {
background: #333333;
color: #F5DEB2;
}
}
.mpVerify {
height: 300upx;
.verifyPhone {
background: #333333;
color: #FFEBC4;
height: 100upx;
width: 600upx;
text-align: center;
line-height: 100upx;
margin-top: 88upx;
border-radius: 0;
}
}
.backBtn {
color: #C5AA7B;
text-decoration: underline;
}
}
</style>