payResult.js
2.53 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
import {
shopmallApi
} from '~/api/api'
Page({
/**
* 页面的初始数据
*/
data: {
count: 5,
payStatus: 0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log(options,123355);
wx.p.wxApi.showLoading('加载中')
if (options && options.orderCode) {
this.checkPay(options.orderCode)
this.query = JSON.parse(options.query)
this.ids = JSON.parse(options.ids)
this.orderCode = options.orderCode
this.buyType = options.buyType
}
},
// 查询支付状态
checkPay(orderCode) {
this.inval = setInterval(() => {
this.checkOrderDetail(orderCode)
}, 1000)
},
countdown() {
this.timer = setInterval(() => {
let { count } = this.data
if (count == 0) {
clearInterval(this.timer)
this.toOrder()
return
}
this.setData({
count: --count
})
}, 1 * 1000)
},
pay() {
let _this = this
wx.p.wxApi.showLoading('加载中')
shopmallApi
.createOrder(this.query)
.then(data => {
if (data.code == -1) {
wx.hideLoading()
wx.showToast({
title: data.message,
icon: 'error'
})
return
}
if(this.buyType!='pay'){
this.removeCar(this.ids)
}
let subOrderCode = data.subOrderDTOS[0].subOrderCode
wx.hideLoading()
wx.navigateToMiniProgram({
appId: 'wx06d1198e751435d1',
path: `packagesPayment/pages/payment/index?orderCode=${subOrderCode}`,
envVersion: 'trial',
success(res) {
_this.checkPay(_this.orderCode)
}
})
})
},
// 查询订单详情
checkOrderDetail(orderCode) {
shopmallApi.orderDetailInfo({ orderCode }).then(res => {
if (res && res.payStatus && res.payStatus > 1) {
clearInterval(this.inval)
this.countdown()
wx.hideLoading();
this.setData({
payStatus: res.payStatus == 2 ? 1 : 2,
giveIntegral: res.giveIntegral
})
}
})
},
// 支付前移除购物车
removeCar(ids) {
shopmallApi
.removeBuuCar({
ids
})
.then(data => { })
},
toCar() {
wx.$router.reLaunch('/packageMall/pages/shoppingCart/shoppingCart')
},
toOrder() {
wx.$router.reLaunch('/packageMine/pages/order/index/index')
},
onUnload(){
clearInterval(this.timer)
clearInterval(this.inval)
},
onHide() {
clearInterval(this.timer)
clearInterval(this.inval)
},
})