|
@@ -1,4 +1,5 @@
|
|
|
var _request = require('../../../../utils/request.js')
|
|
var _request = require('../../../../utils/request.js')
|
|
|
|
|
+var PENDING_VIRTUAL_RECHARGE_ORDER_KEY = 'pendingVirtualRechargeOrderId'
|
|
|
Page({
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -8,6 +9,7 @@ Page({
|
|
|
price: '',
|
|
price: '',
|
|
|
cashTotal: 0,
|
|
cashTotal: 0,
|
|
|
lock: false,
|
|
lock: false,
|
|
|
|
|
+ syncingPendingRecharge: false,
|
|
|
source:''
|
|
source:''
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
@@ -22,6 +24,9 @@ Page({
|
|
|
}
|
|
}
|
|
|
this.getCashTotal()
|
|
this.getCashTotal()
|
|
|
},
|
|
},
|
|
|
|
|
+ onShow: function () {
|
|
|
|
|
+ this.syncPendingVirtualRecharge()
|
|
|
|
|
+ },
|
|
|
getCashTotal () {
|
|
getCashTotal () {
|
|
|
var that = this
|
|
var that = this
|
|
|
var url = 'v1/user/cash/balance/info'
|
|
var url = 'v1/user/cash/balance/info'
|
|
@@ -51,6 +56,9 @@ Page({
|
|
|
}
|
|
}
|
|
|
var success = function (res) {
|
|
var success = function (res) {
|
|
|
if (res.data) {
|
|
if (res.data) {
|
|
|
|
|
+ if (res.data.order_id) {
|
|
|
|
|
+ wx.setStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY, res.data.order_id)
|
|
|
|
|
+ }
|
|
|
that.rechargeClick(res.data)
|
|
that.rechargeClick(res.data)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -118,14 +126,20 @@ Page({
|
|
|
},
|
|
},
|
|
|
fail: function (err) {
|
|
fail: function (err) {
|
|
|
console.error('requestVirtualPayment fail', err)
|
|
console.error('requestVirtualPayment fail', err)
|
|
|
- that.setData({
|
|
|
|
|
- lock: false
|
|
|
|
|
- })
|
|
|
|
|
- wx.showModal({
|
|
|
|
|
- confirmColor: '#eab86a',
|
|
|
|
|
- content: (err && (err.errMsg || err.err_code || err.errCode)) ? ('虚拟支付调起失败:' + (err.errMsg || err.err_code || err.errCode)) : '虚拟支付调起失败',
|
|
|
|
|
- showCancel: false
|
|
|
|
|
|
|
+ var errMsg = err && (err.errMsg || err.err_code || err.errCode) ? (err.errMsg || err.err_code || err.errCode) : ''
|
|
|
|
|
+ if (errMsg.indexOf('cancel') >= 0 || errMsg.indexOf('取消') >= 0) {
|
|
|
|
|
+ wx.removeStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY)
|
|
|
|
|
+ that.setData({
|
|
|
|
|
+ lock: false
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '支付结果确认中',
|
|
|
|
|
+ icon: 'none',
|
|
|
|
|
+ duration: 1500
|
|
|
})
|
|
})
|
|
|
|
|
+ that.waitRechargePaid(payData.order_id, 0)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
@@ -134,6 +148,7 @@ Page({
|
|
|
var url = 'v1/virtual_pay/recharge/status'
|
|
var url = 'v1/virtual_pay/recharge/status'
|
|
|
var success = function (res) {
|
|
var success = function (res) {
|
|
|
if (res.data && res.data.state === 1) {
|
|
if (res.data && res.data.state === 1) {
|
|
|
|
|
+ wx.removeStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY)
|
|
|
getApp().globalData.rechargeChanged = true
|
|
getApp().globalData.rechargeChanged = true
|
|
|
that.getCashTotal()
|
|
that.getCashTotal()
|
|
|
wx.showToast({
|
|
wx.showToast({
|
|
@@ -167,6 +182,40 @@ Page({
|
|
|
}
|
|
}
|
|
|
_request.$get(url, { order_id: oid }, success, fail)
|
|
_request.$get(url, { order_id: oid }, success, fail)
|
|
|
},
|
|
},
|
|
|
|
|
+ syncPendingVirtualRecharge () {
|
|
|
|
|
+ var that = this
|
|
|
|
|
+ if (that.data.syncingPendingRecharge) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ var pendingOrderId = wx.getStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY)
|
|
|
|
|
+ var url = 'v1/virtual_pay/recharge/sync_pending'
|
|
|
|
|
+ var success = function (res) {
|
|
|
|
|
+ that.setData({
|
|
|
|
|
+ syncingPendingRecharge: false
|
|
|
|
|
+ })
|
|
|
|
|
+ if (res.data && res.data.synced_count > 0) {
|
|
|
|
|
+ wx.removeStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY)
|
|
|
|
|
+ getApp().globalData.rechargeChanged = true
|
|
|
|
|
+ that.getCashTotal()
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '充值成功',
|
|
|
|
|
+ icon: 'success',
|
|
|
|
|
+ duration: 1000
|
|
|
|
|
+ })
|
|
|
|
|
+ } else if (pendingOrderId) {
|
|
|
|
|
+ that.waitRechargePaid(pendingOrderId, 0)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ var fail = function () {
|
|
|
|
|
+ that.setData({
|
|
|
|
|
+ syncingPendingRecharge: false
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ that.setData({
|
|
|
|
|
+ syncingPendingRecharge: true
|
|
|
|
|
+ })
|
|
|
|
|
+ _request.$get(url, {}, success, fail)
|
|
|
|
|
+ },
|
|
|
backAfterRecharge () {
|
|
backAfterRecharge () {
|
|
|
var that = this
|
|
var that = this
|
|
|
that.setData({
|
|
that.setData({
|