EnableWallet.js
2.89 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
// pages/Login/components/EnableWallet/EnableWallet.js
import commonApi from '~/api/module/common.js'
Component({
/**
* 组件的属性列表
*/
properties: {
show: {
type: Boolean,
observer: function(n) {
this.setData({
copyWalletObj: JSON.parse(JSON.stringify(this.data.walletObj))
})
}
},
walletObj: {
type: Object
}
},
/**
* 组件的初始数据
*/
data: {
stepDataArr: [{
icon: 'wallet-icon-1',
label: '开通钱包',
tips: '一站式积分管理体验'
}, {
icon: 'wallet-icon-2',
label: '查询积分',
tips: '您的第一笔可用积分',
pointsFlag: true
}, {
icon: 'wallet-icon-3',
label: '积分随心用',
tips: '兑换商品/分享亲友/话费充值, 想怎么用就怎么用!'
}]
},
/**
* 组件的方法列表
*/
methods: {
// 关闭弹窗
closeWallet() {
let { copyWalletObj } = this.data
this.setData({show: false})
// 仅替换积分数据返回的内容,使用copyWalletObj 防止修改弹窗内容也做了替换
this.replaceNickName(copyWalletObj)
},
// 替换积分钱包名称
replaceNickName(data) {
let userInfo = wx.p.storage.get('userInfo')
let { phone, scoreSource } = data
if (!phone || !scoreSource) {
wx.p.sentry.reportParamError(
'替换积分钱包姓名异常:phone, scoreSource',
data
)
}
commonApi.replaceWalletName({
nickName: data?.name,
phone: data?.phone,
scoreSource: data?.scoreSource
}).then(res => {
let { code, message } = res
if (code == 0) {
wx.p.storage.set('userInfo', {...userInfo, nickName: data?.name}) // 更新storage中的nickName
} else {
wx.p.wxApi.showToast(message)
}
})
},
input(e) {
let { target } = e.currentTarget.dataset
let { value } = e.detail
value = target == 'phone' ? value.replace(/[^0-9]/g, '') : value
this.setData({
[`walletObj.${target}`]: value
})
},
// 一键开通积分钱包
enableWalletConfirm() {
let { walletObj } = this.data
commonApi.openPointsWallet(walletObj).then(res => {
let { code, message } = res
if (code == 0) {
this.setData({
showEnableSuccess: true,
show: false
})
this.replaceNickName(walletObj)
this.triggerEvent('open')
} else {
wx.p.wxApi.showToast(message)
}
})
},
// 开通
confirm() {
let { walletObj } = this.data
if (!walletObj?.name) return wx.p.wxApi.showToast('姓名不能为空')
if (!walletObj?.phone || !/^[1]([3-9])[0-9]{9}$/.test(walletObj?.phone)) return wx.p.wxApi.showToast('请输入正确手机号')
this.enableWalletConfirm()
}
}
})