1.优化充值问题

yj-dev
杨杰 4 years ago
parent 616d25db44
commit 3be3f813fb
  1. 97
      pages/user/deposit/deposit.vue

@ -74,10 +74,11 @@
<script> <script>
let app = getApp() let app = getApp()
import { import {
addOrder, addOrder,
orderToPay orderToPay
} from "../../../Utils/Api.js"; } from "../../../Utils/Api.js";
var jweixin = require('jweixin-module');
export default { export default {
data() { data() {
return { return {
@ -87,8 +88,11 @@
user: "", user: "",
}; };
}, },
methods: { onLoad() {
this.user = app.globalData.userInfo
},
methods: {
select(amount) { select(amount) {
this.inputAmount = amount; this.inputAmount = amount;
}, },
@ -126,11 +130,9 @@
}] }]
} }
addOrder(goods).then(res => { addOrder(goods).then(res => {
uni.hideLoading();
if (res.return_code == '000000') { if (res.return_code == '000000') {
/// ///
uni.showLoading({
title: '支付中...'
})
let params = { let params = {
"orderId": res.return_data.id, "orderId": res.return_data.id,
"openId": app.globalData.openId, "openId": app.globalData.openId,
@ -138,6 +140,10 @@
} }
orderToPay(params).then(res => { orderToPay(params).then(res => {
if (res.return_code == '000000') { if (res.return_code == '000000') {
// #ifdef MP
uni.showLoading({
title: '支付中...'
})
uni.requestPayment({ uni.requestPayment({
"appId": res.return_data.appId, "appId": res.return_data.appId,
"nonceStr": res.return_data.nonceStr, "nonceStr": res.return_data.nonceStr,
@ -159,23 +165,80 @@
console.log('fail:' + JSON.stringify(err)); console.log('fail:' + JSON.stringify(err));
} }
}); });
}else{ // #endif
uni.showToast({
title:'支付失败' //
}) // #ifdef H5
//
this.payRequest(res);
// #endif
} else {
uni.showToast({
title: '支付失败'
})
} }
}) })
} else { } else {
uni.showToast({ uni.showToast({
title: res.return_msg title: res.return_msg
}); });
} }
}) })
} },
}, payRequest: function(self) {
onLoad() { uni.showLoading({
this.user = app.globalData.userInfo title: '支付中...'
})
jweixin.config({
// debug: true, // ,apialertpclogpc
appId: self.return_data.appId, //
timestamp: self.return_data.timeStamp, //
nonceStr: self.return_data.nonceStr, //
signature: self.return_data.sign, // 1
jsApiList: ['chooseWXPay'] // 使JSJS2
});
uni.hideLoading();
jweixin.ready(function() {
jweixin.checkJsApi({
jsApiList: ['chooseWXPay'], // JSJS2,
success: function(res) {},
fail: function(res) {}
});
jweixin.chooseWXPay({
appId: self.return_data.appId,
timestamp: self.return_data
.timeStamp, // jssdk使timestamp使timeStampS
nonceStr: self.return_data.nonceStr, // 32
package: self.return_data
.package, // prepay_idprepay_id=***
signType: 'MD5', // 'SHA1'使'MD5'
paySign: self.return_data.sign, //
success: function(res) {
//
uni.showToast({
title: '支付成功'
})
uni.reLaunch({
url: '../success/success?id=' + that.couponId
});
},
cancel: function(r) {},
fail: function(res) {}
});
});
jweixin.error(function(res) {
uni.showToast({
icon: 'none',
title: '支付失败了',
duration: 4000
});
});
},
}, },
} }
</script> </script>

Loading…
Cancel
Save