recharge.vue
8.1 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
<template>
<view>
<view class="topLine"></view>
<view class="recList">
<view class="recItem" @click="showPayType(index)" v-for="(item,index) in list" :key="index">
<view class="recVal">
<text>{{item.num}}</text>币
</view>
<view class="recPrice">
{{item.price}}元
</view>
</view>
<!-- <view class="recItem">
<view class="recVal">
<input type="number" v-model="custNum" placeholder="自定义" style="width: 50%;text-align: center;"
placeholder-style="font-size:28rpx;color:#4a8b94;" />
</view>
<view class="recPrice" style="font-weight: 600;" @click="custom">
立即充值
</view>
</view> -->
</view>
<navigator url="aboutUs"></navigator>
<view class="agreeCont">
<!-- <checkbox color="#4a8b94"/> -->充值即代表您同意<text
@click="$href('aboutUs?navTitle=问野币充值协议')">《问野币充值协议》</text>
</view>
<!-- 游侠付款弹框 -->
<pay-type v-if="showPay" @pay="pay" @changePayType="changePayType" :price="price"
@closePayAlert="showPay = false"></pay-type>
</view>
</template>
<script>
import payType from '@/components/payType.vue'
export default {
data() {
return {
custNum: '',
id: '',
param: {
number: '', //问野币数量
pay_type: 'wechat'
},
iosPay: {
order_id: '',
data: ''
},
showPay: false, //展示支付弹框
price: 0,
list: [
// {
// num: 10,
// price: 1,
// id: 'PTMH2SF',
// },
// {
// num: 60,
// price: 6,
// id: 'K93MD8T',
// },
// {
// num: 120,
// price: 12,
// id: 'TR5CNJF',
// },
// {
// num: 250,
// price: 25,
// id: 'AIDHZK4',
// },
// {
// num: 500,
// price: 50,
// id: '87FC0DH',
// }
]
}
},
components: {
payType
},
onLoad() {
this.getMoneyGoods()
uni.getProvider({
service: 'payment',
success: function(res) {
console.log('获取通道', res.provider)
}
});
let that = this
console.log('查看支付通道')
plus.payment.getChannels((channels) => {
console.log('判断是否是苹果支付', channels)
for (var i in channels) {
// 判断是否苹果支付
if (channels[i].id === 'appleiap') {
that.iapChannel = channels[i]
console.log('判断是否是苹果支付赋值', that.iapChannel)
// that.requestOrder()
}
}
})
},
methods: {
// {
// num: 120,
// price: 12,
// id: 'TR5CNJF',
// },
getMoneyGoods () {
return new Promise((reslove) => {
this.$request('/wallet/getMoneyGoods', {type:'ios'}).then((res) => {
console.log('充值选项列表', res)
this.list = res.data
this.list.forEach((item)=>{
item.num = item.number
item.price = item.number /10
})
reslove(res)
})
})
},
//修改支付类型
changePayType(e) {
console.log('修改支付类型', e)
this.param.pay_type = e
},
//显示支付类型选择弹框
showPayType(index) {
this.price = this.list[index].price
this.param.number = this.list[index].num
this.id = this.list[index].apple_goods_id
this.param.pay_type = 'wechat'
this.showPay = true
},
custom() {
if (this.custNum == '' || this.custNum <= 0) {
uni.showToast({
title: '请输入正确的问野币数量',
icon: 'none'
})
return
}
let flag = new RegExp("^[1-9]([0-9])*$").test(this.custNum);
if (!flag) {
uni.showToast({
title: '请输入正确的问野币数量',
icon: 'none'
})
return
}
this.param.number = this.custNum
this.price = this.param.number / 10
this.showPay = true
},
pay() {
const that = this
// uni.showLoading({
// title: '检测支付环境...',
// mask: true
// })
// plus.payment.getChannels((channels) => {
// console.log('判断是否是苹果支付1',channels)
// for (var i in channels) {
// // 判断是否苹果支付
// if (channels[i].id === 'appleiap') {
// that.iapChannel = channels[i]
// console.log('判断是否是苹果支付2',that.iapChannel)
that.requestOrder()
// } else {
// that.payment()
// // that.requestOrder()
// }
// }
// })
},
async payment() {
console.log('安卓')
var orderInfo = await this.getOrderInfo();
uni.requestPayment({
provider: this.param.pay_type == 'wechat' ? 'wxpay' : 'alipay',
orderInfo: this.param.pay_type == 'wechat' ? orderInfo.data : orderInfo.data
.body, //this.param.pay_type == 'wechat' ? JSON.stringify(orderInfo.data) : orderInfo.data, //微信、支付宝订单数据
success: (e) => {
uni.navigateBack({
delta: 1
})
setTimeout(() => {
uni.showToast({
title: '充值成功'
})
}, 500)
},
fail: function(err) {
console.log('充值失败', err)
}
});
},
requestOrder() {
const that = this
// ['xxxxx'] 是平台申请拿到的内购商品的id
console.log('苹果支付', that.iapChannel)
that.iapChannel.requestOrder([that.id],
function(event) {
// uni.hideLoading()
console.log('苹果支付1', event)
for (var index in event) {
var OrderItem = event[index]
console.log(OrderItem)
that.topay(OrderItem.productid)
}
},
function(erroemsg) {
// uni.hideLoading()
console.log('获取支付通道失败', erroemsg)
uni.showToast({
title: "获取支付通道失败:" + erroemsg.message,
icon: 'none'
})
})
console.log('苹果支付', that.iapChannel)
},
async topay(id) {
const that = this
that.param.pay_type = 'ios'
var orderInfo = await this.getOrderInfo();
uni.showLoading({
title: '充值中请勿离开',
mask: true
})
console.log(id)
uni.requestPayment({
provider: 'appleiap',
orderInfo: {
productid: id
},
success: (res => {
console.log(1)
console.log(res)
uni.hideLoading()
this.rechargeIosPay(res.transactionReceipt);
// 支付成功查询订单
// plus.payment.request(that.iapChannel, statement, function(res){
// console.log(res)
// })
}),
fail: (e) => {
uni.hideLoading()
uni.showModal({
content: "支付失败",
showCancel: false
})
},
complete: () => {
console.log("payment结束")
this.loading = false;
}
})
},
getOrderInfo() {
return new Promise((reslove) => {
this.$request('/wallet/recharge', this.param).then((res) => {
console.log('充值问野币', res)
this.iosPay.order_id = res.data.order_id
reslove(res)
})
})
},
rechargeIosPay(data) {
this.iosPay.data = data
return new Promise((reslove) => {
this.$request('/wallet/rechargeIosPay', this.iosPay).then((res) => {
console.log('充值问野币ios支付', res)
uni.navigateBack({
delta: 1
})
setTimeout(() => {
uni.showToast({
title: '充值成功'
})
}, 500)
reslove(res)
})
})
}
}
}
</script>
<style lang="scss" scoped>
page {
background: #f8f8f9;
}
.topLine {
height: 2rpx;
background: rgba(25, 24, 51, 0.06);
}
.recList {
padding: 0 32rpx;
display: flex;
flex-wrap: wrap;
.recItem {
width: 218rpx;
height: 240rpx;
background: #ffffff;
border-radius: 24rpx;
box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(0, 0, 0, 0.06);
margin: 24rpx 16rpx 0 0;
.recVal {
padding-top: 64rpx;
display: flex;
justify-content: center;
align-items: center;
color: #4a8b94;
text {
font-size: 40rpx;
}
}
.recPrice {
padding-top: 16rpx;
text-align: center;
font-size: 28rpx;
}
}
.recItem:nth-of-type(3n) {
margin-right: 0;
}
}
.agreeCont {
checkbox {
transform: scale(0.7);
}
padding-top: 42rpx;
font-size: 28rpx;
display: flex;
align-items: center;
justify-content: center;
text {
color: #4a8b94;
}
}
</style>