courseBill.vue
9.2 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
<template>
<view>
<view class="list">
<view class="kcitem">
<image v-if="form.coursePic" :src="config.baseUrl_api+form.coursePic" mode="aspectFill"></image>
<image v-if="form.activityPic" :src="config.baseUrl_api+form.activityPic" mode="aspectFill"></image>
<view class="info">
<view class="tt esp_2" v-if="form.courseName">{{form.courseName}}</view>
<view class="tt esp_2" v-if="form.activityName">{{form.activityName}}</view>
<!-- <view class="pp"><uni-icons type="chatboxes" size="12" />209w 学习</view> -->
<!-- <view class="text-warning">{{form.explains}}</view> -->
</view>
</view>
</view>
<view class="rrcard">
<view class="t" v-if="system!='iPhone'&&system!='iPad'">支付方式</view>
<view class="t" v-else>兑换方式</view>
<view class="whitebg">
<radio-group @change="payChange">
<label class="uni-list-cell uni-list-cell-pd" v-if="form.allScore>0">
<view class="littleimgBox">
{{form.allScore}} 积分
</view>
<view>
<radio checked="checked" value="0" />
</view>
</label>
<label class="uni-list-cell uni-list-cell-pd" v-if="form.allGold>0&&system!='iPhone'&&system!='iPad'">
<view class="littleimgBox">
{{form.allGold}} 金币
</view>
<view>
<radio value="1" />
</view>
</label>
<label class="uni-list-cell uni-list-cell-pd" v-if="form.gold>0&&form.score>0&&system!='iPhone'&&system!='iPad'">
<view class="littleimgBox">
{{form.gold}} 金币 + {{form.score}} 积分
</view>
<view>
<radio value="2" />
</view>
</label>
</radio-group>
</view>
</view>
<view class="rrcard mt-30" v-if="form.sale">
<view class="t">可支持的优惠</view>
<view class="whitebg">
<radio-group>
<label class="uni-list-cell uni-list-cell-pd">
<view class="littleimgBox text-warning">
VIP会员
<text>{{form.sale/10}}</text>
折
</view>
<view v-if="system!='iPhone'&&system!='iPad'">
<radio v-if="mm.memType=='1'" checked="checked"/>
<view v-else @click="beVip">成为VIP 享受此优惠></view>
</view>
</label>
</radio-group>
</view>
</view>
<view class="rrcard mt-30">
<view class="t">我的余额</view>
<view class="whitebg">
<label class="uni-list-cell uni-list-cell-pd">
<view class="littleimgBox">
金币:{{mm.gold||0}}
</view>
<view style="color: #999;" v-if="system!='iPhone'&&system!='iPad'" @click="goPath('/usercenter/mycard/renew')">去充值></view>
</label>
<label class="uni-list-cell uni-list-cell-pd">
<view class="littleimgBox">
积分:{{mm.score||0}}
</view>
<view>
</view>
</label>
</view>
<view class="explains" v-if="form.explains">{{form.explains}}</view>
</view>
<view class="fixedBottom">
<view class="flexbox">
<view>
<view class="text-warning" v-if="mm.memType=='1'">
<text v-if="form.payType==1">{{form.allGold*form.sale/100}} 金币</text>
<text v-if="form.payType==0">{{form.allScore*form.sale/100}} 积分</text>
<text v-if="form.payType==2">{{form.gold*form.sale/100}} 金币 + {{form.score*form.sale/100}} 积分</text>
</view>
<view class="text-del" v-if="mm.memType=='1'">
<text v-if="form.payType==1">{{form.allGold}} 金币</text>
<text v-if="form.payType==0">{{form.allScore}} 积分</text>
<text v-if="form.payType==2">{{form.gold}} 金币 + {{form.score}} 积分</text>
</view>
<view class="text-warning" v-else>
<text v-if="form.payType==1">{{form.allGold}} 金币</text>
<text v-if="form.payType==0">{{form.allScore}} 积分</text>
<text v-if="form.payType==2">{{form.gold}} 金币 + {{form.score}} 积分</text>
</view>
</view>
<view v-if="system!='iPhone'&&system!='iPad'">
<button class="btn btn-submit" v-if="orderType==0" @click="pay">确定购买</button>
<button class="btn btn-submit" v-else @click="pay">确定报名</button>
</view>
<view v-else>
<button class="btn btn-submit" @click="pay">立即兑换</button>
</view>
</view>
</view>
<uni-popup ref="vippay" type="center">
<view style="position: relative;">
<image src="@/usercenter/img/popup2.png" style="width: 620rpx;height: 568rpx;"></image>
<view class="bigPrice">{{vipPrice}}</view>
<button class="btn btn-submit priceBtn" style="width: 400rpx;" @click="payVip">
立即支付 ¥{{vipPrice}}/年</button>
</view>
</uni-popup>
</view>
</template>
<script setup>
import {
onLoad,
onShow,onReady
} from '@dcloudio/uni-app';
import config from '@/config.js';
import {
ref,
getCurrentInstance
} from 'vue';
import * as api from '@/common/api.js';
const form = ref({})
const mm = ref({})
const orderType = ref(0)
const vipPrice = ref(0)
const vippay = ref(null)
const system = uni.getStorageSync('systemType')
let shareId = '0'
onLoad((option) => {
if ('form' in option) {
form.value = JSON.parse(decodeURIComponent(option.form))
if (form.value.courseId) {
orderType.value = 0
} else {
orderType.value = 1
}
}
if (option.shareId) {
shareId = option.shareId
}
getUserExt()
})
onReady(() => {
if (orderType.value = 1) {
uni.setNavigationBarTitle({
title: '活动兑换'
});
} else {
uni.setNavigationBarTitle({
title: '课程兑换'
});
}
})
function getUserExt(){
api.getUserExtByUserId().then(res=>{
mm.value = res.data
})
}
function payChange(e) {
console.log(e.detail.value)
form.value.payType = e.detail.value
}
function pay() {
console.log(form.value.payType,mm.value.gold,mm.value.score)
if(form.value.payType==1&&(form.value.allGold>mm.value.gold)){
let msg = '去充值'
uni.showModal({
content: '金币不足',
confirmText: msg,
success:function(res){
if(res.confirm){
goPath('/usercenter/mycard/renew')
}
}
})
return
}
if(form.value.payType==0&&(form.value.allScore>mm.value.score)){
uni.showModal({
content: '积分不足',
success:function(res){
if(res.confirm){
}
}
})
return
}
if(form.value.payType==2&&(form.value.score>mm.value.score||form.value.gold>mm.value.gold)){
uni.showModal({
content: '余额不足',
confirmText:'去充值',
success:function(res){
if(res.confirm){
goPath('/usercenter/mycard/renew')
}
}
})
return
}
var obj = {}
if (orderType.value == 0) {
obj = {
orderType: 0,
goodsId: form.value.courseId,
payType: form.value.payType,
shareId:shareId
}
} else {
obj = {
orderType: 1,
goodsId: form.value.activityId,
payType: form.value.payType,
shareId:shareId
}
}
uni.showModal({
content:'确定购买吗',
success:function(resp){
if(resp.confirm){
api.submitOrder(obj).then(res => {
console.log(res)
if(res.data == -100){
uni.showToast({
title: '余额不足',
icon:'none'
})
} else {
uni.showToast({
title: '操作成功'
})
uni.navigateBack()
}
})
}
}
})
}
function goPath(path) {
uni.navigateTo({
url: path
});
}
function beVip(){
api.getVipPrice().then(res => {
vipPrice.value = res.msg
vippay.value.open()
})
}
function payVip() {
api.createOrder({
total: vipPrice.value,
payType: 0
}).then(res => {
const openId = currUser.openId
// const openId = 'oRufa4ifoP2I3hnoLAwoAreKkppA'
api.payForOrder({
payId: res.data.payId,
openId: openId,
shareId:shareId
}).then(Response => {
wePay(Response.data.weixinData)
})
})
}
function wePay(configdata) {
console.log(configdata)
// 微信支付
uni.requestPayment({
"provider": "wxpay",
"appId": configdata.appId,
"nonceStr": configdata.nonceStr,
"package": configdata.packageValue, // 随机字符串
"timeStamp": configdata.timeStamp, // 时间戳(单位:秒)
"signType": configdata.signType, // 签名,这里用的 MD5/RSA 签名
"paySign": configdata.paySign,
success(res) {
console.log(res)
uni.showModal({
content: '支付成功',
success: function(resp) {
if (resp.confirm) {
init()
}
}
})
},
fail(e) {
console.log(e)
uni.showToast({
title: '支付取消',
icon: 'none'
});
}
})
}
</script>
<style lang="scss" scoped>
.explains{font-size: 28rpx;color: #999;margin-top: 40rpx;line-height: 2;}
:deep(.uni-list-cell::after) {
background-color: #eee;
width: 94%;
left: 3%;
}
.kcitem {
margin: 30rpx auto;
width: 700rpx;
box-sizing: border-box;
}
.whitebg {
background: #fff;
}
.rrcard .box {
padding: 0 0 1px;
margin: 20rpx 0 0;
}
.rrcard {
position: relative;
padding: 0 25rpx;
box-sizing: border-box;
}
.rrcard .t {
font-weight: 500;
color: #2B3133;
margin: 0 0 20rpx;
font-size: 32rpx;
}
.fixedBottom {
.flexbox {
width: 100%;
justify-content: space-between;
padding: 0 30rpx;
}
}
</style>