costBreakdown.vue
12.3 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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
<template>
<view class="box">
<view class="box1" v-if="trainList">
<trainFold title="科目费用" :cost="projectCost" :text="trainList.length + '项'">
<view class="conter-liner" v-for="item in trainList" :key="item.id">
<view class="liner-left">{{ item.projectName }}</view>
<view class="liner-right">{{ item.cost }}元</view>
</view>
</trainFold>
</view>
<view class="box1" v-if="trainList">
<trainFold title="考试费用" :cost="examCost" :text="insuranceList.length + '项'">
<view class="conter-liner" v-for="item in insuranceList" :key="item.id">
<view class="liner-left">{{ item.projectName }}</view>
<view class="liner-right">{{ item.cost }}元</view>
</view>
</trainFold>
</view>
<view class="box1" v-if="hotelList">
<trainFold title="食宿费用" :cost="accommodationCost" :text="nights + '晚'">
<view class="conter-liner" v-for="item in hotelList" :key="item.id">
<view class="liner-left">{{ item.name }}</view>
<view class="liner-right">{{ item.spend }}元</view>
</view>
</trainFold>
</view>
<view class="box1" v-if="otherList">
<trainFold title="其他费用" :cost="otherCost" :text="otherList.length + '项'">
<view class="conter-liner" v-for="item in otherList" :key="item.id">
<view class="liner-left">{{ item.name }}</view>
<view class="liner-right">{{ item.spend }}元</view>
</view>
</trainFold>
</view>
<view class="box2">
<view class="text">支付方式</view>
<view class="conter">
<view>
<radio-group @change="radioChange">
<label class="radio">
<view class="radio-cost">
<view class="left"><image class="image" src="@/static/zf01.png"></image></view>
<view class="radio-right">微信支付</view>
</view>
<radio value="0" class="check" />
</label>
<label class="radio">
<view class="radio-cost">
<view class="left"><image class="image" src="@/static/zf02.png"></image></view>
<view class="radio-right">会员卡支付</view>
<view class="vip">(余额:¥{{ (vip * 1).toFixed(2) }})</view>
</view>
<radio value="2" class="check" />
</label>
<label class="radio">
<view class="radio-cost">
<view class="left"><image class="image" src="@/static/zf03.png"></image></view>
<view class="radio-right">线下支付</view>
</view>
<radio value="1" class="check" checked="true" />
</label>
</radio-group>
</view>
</view>
</view>
<view class="box3">
<view class="left">
合计:
<view class="cost">{{ (totalCost * 1).toFixed(2) }}元</view>
</view>
<view class="ToPay" @click="payment">去支付</view>
</view>
<!-- 弹框 -->
<view class="box4">
<uni-popup
ref="popup"
:is-mask-click="true"
@maskClick="maskClick"
type="center"
@close="close"
:animation="true"
background-color="#fff"
>
<view class="popup" @click="copyPlat">
<view class="title">线下支付</view>
<view class="liner">
<view class="left">公司:</view>
<view class="right">{{ bank.accountName }}</view>
</view>
<view class="liner">
<view class="left">开户:</view>
<view class="right">{{ bank.accountBank }}</view>
</view>
<view class="liner">
<view class="left">账户:</view>
<view class="right">{{ bank.accountNum }}</view>
</view>
<view class="butotn" @click="btnOK">确定</view>
</view>
</uni-popup>
</view>
<view class="dialog" v-if="dialog">
<view class="size">支付成功,请看订单状态!</view>
<view class="butotn" @click="okFN">确定</view>
</view>
</view>
</template>
<script setup>
import { ref, getCurrentInstance, reactive, toRef, toRefs } from 'vue';
import { onLoad, onReady, onShareAppMessage, onShareTimeline, onPullDownRefresh } from '@dcloudio/uni-app';
import trainFold from '@/components/train/train-apply-four/fold/fold.vue';
import * as train from '@/common/train.js';
// import * as api from "@/common/login.js"
import * as api from '@/common/api.js';
import { getMyBalance } from '../../../common/api';
const value = ref();
const nuiCollapse = ref();
const dialog = ref(false);
const nuiDom = ref();
const popup = ref();
const id = ref();
const hotelList = ref();
const trainList = ref();
const insuranceList = ref();
const totalCost = ref();
const accommodationCost = ref();
const projectCost = ref();
const otherList = ref();
const otherCost = ref();
const examCost = ref();
const orderNumber = ref();
const payWay = ref(1);
const timer = ref();
const trainId = ref();
const ids = ref();
const code = ref();
const vip = ref();
const suo = ref(true);
const nights = ref();
const orderFlag = ref();
const payFalg = ref(true);
const data = reactive({
addForm: {},
bank: {}
});
const { addForm, bank } = toRefs(data);
// 打开弹框
function open() {
popup.value.open('center');
}
function close() {
popup.value.close();
}
// 点击蒙版关闭弹框, 跳转页面
function maskClick() {
btnOK();
}
function btnOK() {
copyPlat();
close();
clearTimeout(timer.value);
setTimeout(() => {
myTrain();
}, 500);
}
onLoad(option => {
// ids.value = option.ids;
trainId.value = option.id;
orderNumber.value = option.ids;
id.value = option.id;
initData();
VIPFN();
});
// 复制银行账户信息
function copyPlat() {
let str = `公司:${bank.value.accountName};开户行:${bank.value.accountBank};账户:${bank.value.accountNum};`;
uni.setClipboardData({
data: str,
success: function() {
console.log('success');
}
});
}
// // 提示信息
// function tipForPayMation() {
// uni.showModal({
// title: '提示',
// content: '点击信息复制到剪贴板',
// cancelText: '好的',
// confirmText: '我已复制',
// success: function(res) {
// if (res.confirm) {
// // 去订单详情页
// goDetail()
// } else if (res.cancel) {
// console.log('返回');
// }
// }
// });
// }
// 支付方式
function radioChange(e) {
payWay.value = e.target.value;
}
function myTrain() {
let path = `/pages/train/payScuess/payScuess?payType=${payWay.value}&payTotal=${totalCost.value}`;
wx.redirectTo({
url: path
});
}
function okFN() {
let path = `/pages/train/payScuess/payScuess?payType=${payWay.value}&payTotal=${totalCost.value}`;
wx.redirectTo({
url: path
});
}
// 获取用户支付信息
async function initData() {
addForm.value.trainId = id.value;
const res = await train.searchTrainCost(addForm.value);
hotelList.value = res.data.accommodationVoList;
insuranceList.value = res.data.examVoList;
trainList.value = res.data.trainVoList;
totalCost.value = res.data.totalCost;
accommodationCost.value = res.data.accommodationCost;
projectCost.value = res.data.projectCost;
otherList.value = res.data.otherList;
otherCost.value = res.data.otherCost;
examCost.value = res.data.examCost;
nights.value = res.data.nights;
console.log(res);
}
// 1.生成订单
function createOrder() {
return new Promise(async (resolve, reject) => {
addForm.value.trainId = id.value;
addForm.value.orderAmount = totalCost.value;
const res = await train.createOrder(addForm.value);
orderNumber.value = res.data;
console.log(res, orderNumber.value);
addForm.value = {};
if (res.code == 200) {
resolve();
} else {
reject();
}
});
}
// 2.支付 flag= 0微信/1线下/2会员
async function payFN() {
return new Promise(async (resolve, reject) => {
if (payFalg.value == false) {
return false;
}
const nowOpenId = uni.getStorageSync('nowOpenId');
addForm.value.openId = nowOpenId;
addForm.value.id = orderNumber.value;
addForm.value.flag = payWay.value;
addForm.value.amount = totalCost.value;
const res = await train.pay(addForm.value);
addForm.value = {};
if (res.code == 200) {
payFalg.value = false;
resolve('成功');
code.value = res.code;
if (payWay.value == 2) {
// dialog.value = true;
myTrain();
}
} else {
reject('失败');
}
});
}
// 获取线下支付时银行账户信息
async function bankInfo() {
return new Promise(async (resolve, reject) => {
addForm.value.id = orderNumber.value;
let res = await train.bankSlip(addForm.value);
bank.value = res.data;
if (res.code == 200 && payWay.value == 1) {
open();
}
if (res.code == 200) {
resolve();
} else {
reject();
}
});
}
// 支付按钮
async function payment() {
if (suo.value) {
suo.value = true;
if (payWay.value == 0) {
uni.showToast({
title: '暂未开通',
duration: 2000,
icon: 'error'
});
return false;
}
// 生成订单
if (!orderNumber.value) await createOrder();
// 支付
await payFN();
await bankInfo();
if (code.value) suo.value = true;
}
}
// 获取会员余额信息
async function VIPFN() {
let res = await getMyBalance();
vip.value = res.data;
}
</script>
<style scoped lang="scss">
.box {
padding: 35rpx 25rpx;
padding-bottom: 100rpx;
.box1 {
background-color: #fff;
margin-bottom: 40rpx;
padding: 10rpx;
border-radius: 15rpx;
.text {
font-size: 32rpx;
font-family: PingFang SC;
font-weight: 500;
color: #2b3133;
}
.conter-liner {
display: flex;
justify-content: space-between;
margin-top: 32rpx;
padding-bottom: 30rpx;
.liner-left {
font-size: 28rpx;
font-family: PingFang SC;
font-weight: 400;
color: #7b7f83;
}
.liner-right {
font-size: 28rpx;
font-family: PingFang SC;
font-weight: 400;
color: #ff8124;
}
}
}
.box2 {
padding: 10rpx;
.text {
font-size: 32rpx;
font-family: PingFang SC;
font-weight: 500;
color: #2b3133;
margin-bottom: 40rpx;
}
.conter {
background-color: #fff;
border-radius: 15rpx;
padding: 25rpx 10rpx;
}
.radio {
display: flex;
justify-content: space-between;
margin-bottom: 30rpx;
.radio-cost {
display: flex;
.left {
width: 50rpx;
height: 50rpx;
.image {
width: 50rpx;
height: 50rpx;
}
}
.radio-right {
font-size: 28rpx;
font-family: PingFang SC;
font-weight: 400;
color: #000000;
margin-left: 10rpx;
}
.vip {
font-size: 28rpx;
font-family: PingFang SC;
font-weight: 400;
color: #4c5359;
}
}
}
}
.box3 {
display: flex;
justify-content: space-between;
border: 1rpx solid #dcdcdc;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: #fff;
.left {
display: flex;
line-height: 100rpx;
font-size: 24rpx;
font-family: PingFang SC;
font-weight: 400;
color: #7b7f83;
padding-left: 30rpx;
.cost {
font-size: 45rpx;
font-family: DIN Alternate;
font-weight: bold;
color: #ff8124;
padding-left: 10rpx;
}
}
.ToPay {
background: #ff8124;
border: 1px solid #dcdcdc;
color: #fff;
width: 214rpx;
height: 100rpx;
text-align: center;
line-height: 100rpx;
}
}
.box4 {
:deep(.uni-popup__wrapper) {
border-radius: 15rpx;
}
.popup {
padding: 44rpx;
width: 550rpx;
height: 450rpx;
border-radius: 15rpx;
.title {
font-size: 34rpx;
font-family: PingFang SC;
font-weight: 500;
color: #7b7f83;
text-align: center;
margin-bottom: 40rpx;
}
.liner {
display: flex;
margin-bottom: 30rpx;
.left {
font-size: 30rpx;
font-family: PingFang SC;
font-weight: 500;
color: #7b7f83;
}
.right {
font-size: 30rpx;
font-family: PingFang SC;
font-weight: 500;
color: #000;
}
}
.butotn {
margin: 0 auto;
margin-top: 63rpx;
width: 268rpx;
height: 80rpx;
background: linear-gradient(270deg, #54e1b9, #00caa6);
border-radius: 40rpx;
text-align: center;
line-height: 80rpx;
color: #fff;
font-size: 32rpx;
font-family: PingFang SC;
font-weight: 500;
}
}
}
}
.dialog {
width: 95%;
background-color: #000;
border-radius: 30rpx;
padding: 50rpx 0;
margin: 0 auto;
opacity: 0.8;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
.size {
color: #fff;
text-align: center;
}
.butotn {
margin: 0 auto;
margin-top: 63rpx;
width: 268rpx;
height: 80rpx;
background: linear-gradient(270deg, #54e1b9, #00caa6);
border-radius: 40rpx;
text-align: center;
line-height: 80rpx;
color: #fff;
font-size: 32rpx;
font-family: PingFang SC;
font-weight: 500;
}
}
</style>