e0afa52e
刘淇
卡券发放
|
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
|
export default {
data() {
return {
acctBalance: '0.00',
wxopenId: '',
ListData: [],
currentIndex: 0,
rechargeFee: 0,
isShowInput: false,
rechargeNum: '',
maxlength: 6 //默认一个长度
}
},
onLoad() {
uni.setStorageSync("wxCode", '')
this.getCode();
this.recharge();
this.rechargeList();
},
mounted() {
},
onShow() {
},
methods: {
getCode() {
uni.login({
provider: 'weixin',
success: function (loginRes) {
console.log('获取微信code-loginRes.code: ' + loginRes.code);
uni.setStorageSync("wxCode", loginRes.code)
}
});
},
getOpenID() {
let that = this;
let code = uni.getStorageSync("wxCode");
console.log(code)
let data = {
appId: that.$common.hs_wxPay_appId,
// appId:"wxadb8caee05ab2981",
code: code,
};
that.$myRequest({
url: that.$common.getOpenIdByCode,
method: 'POST',
data: data
}).then(res => {
let data = res.data;
that.wxopenId = data.openid;
console.log(data.openid)
that.wxPayOrder()
})
},
recharge() {
let that = this;
that.$myRequest({
url: that.$common.walletAccount,
method: 'POST',
data: that.$common.requestSign()
}).then(res => {
console.log(res)
let data = res.data;
that.acctBalance = data.acctBalance;
})
},
rechargeList() {
let that = this;
that.$myRequest({
url: that.$common.rechargeList,
method: 'POST',
data: that.$common.requestSign()
}).then(res => {
console.log(res)
let data = res.data;
that.ListData = data;
that.rechargeFee = that.ListData[0].rechargeCode
})
},
change(e) {
let that = this;
let {
index
} = e.detail;
that.currentIndex = index;
if (that.ListData[index].rechargeCode == -1) {
console.log('1')
that.isShowInput = true;
that.rechargeNum = ''
} else {
that.isShowInput = false;
that.rechargeFee = that.ListData[index].rechargeCode;
}
},
checkNum(e) {
let value = e.detail.value;
let dot = value.indexOf('.'); //包含小数点
let reg = /^[0-9]+$/; //正整数
if (dot > -1) {
this.maxlength = dot + 3; //长度是小数点后两位
if (value.length > dot + 3) {
}
}
if (reg.test(value)) { //如果是正整数不包含小数点
this.maxlength = 6;
}
},
detailCell() {
uni.navigateTo({
url: '../rechargeDetail/rechargeDetail'
});
},
payClick() {
let that = this;
that.getOpenID()
},
wxPayOrder() {
let that = this;
let payMoney;
if (that.isShowInput) {
payMoney = that.rechargeNum * 100;
} else {
payMoney = that.rechargeFee;
}
console.log(that.wxopenId)
let data = {
openId: that.wxopenId,
rechargeType: '2',
acctType: '1',
paySrcType: '204',
payType: '12',
realPayMoney: payMoney.toString(),
rechargeFee: payMoney.toString(),
};
console.log(data)
that.$myRequest({
url: that.$common.publicUnifiedOrder,
method: 'POST',
data: that.$common.requestSign(data)
}).then(res => {
var mydata = res.data;
console.log(mydata);
that.MakeWxPay(mydata)
})
},
// 调用微信支付
MakeWxPay(mydata) {
console.log(mydata)
var me = this;
uni.requestPayment({
provider: 'wxpay',
timeStamp: mydata.timeStamp,
//随机字符串,长度为32个字符以下
nonceStr: mydata.nonceStr,
//统一下单接口返回的 prepay_id 参数值,提交格式如:prepay_id=xx。
package: mydata.package,
signType: mydata.signType,
paySign: mydata.paySign,
success: function (res) {
console.log('success:' + JSON.stringify(res));
me.recharge();
},
fail: function (err) {
console.log('fail:' + JSON.stringify(err));
uni.showModal({
title: '提示',
content: '支付失败/取消',
showCancel: false,
success: function (res) {
if (res.confirm) {
console.log('支付失败');
}
}
});
}
});
},
}
}
|