|
|
@@ -90,7 +90,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { checkPurchase, createPurchaseOrder } from '../../utils/api.js'
|
|
|
+import { checkPurchase, createPurchaseOrder, getPurchasePayParams } from '../../utils/api.js'
|
|
|
+import { requestVirtualPayment } from '../../utils/api.js'
|
|
|
|
|
|
export default {
|
|
|
data() {
|
|
|
@@ -131,18 +132,44 @@ export default {
|
|
|
var self = this
|
|
|
self.submitting = true
|
|
|
createPurchaseOrder().then(function(res) {
|
|
|
- self.submitting = false
|
|
|
- if (res.data && res.data.success) {
|
|
|
- // 跳转到支付页面(这里先提示,实际需对接支付)
|
|
|
- uni.showModal({
|
|
|
- title: '确认支付',
|
|
|
- content: '支付199元开启7天全功能体验,完成挑战可返还199元CF值',
|
|
|
- success: function(modalRes) {
|
|
|
- if (modalRes.confirm) {
|
|
|
- uni.showToast({ title: '支付功能开发中', icon: 'none' })
|
|
|
- }
|
|
|
+ if (res.data && res.data.success && res.data.orderNo) {
|
|
|
+ var orderNo = res.data.orderNo
|
|
|
+ // 获取虚拟支付参数并拉起支付
|
|
|
+ getPurchasePayParams(orderNo).then(function(payRes) {
|
|
|
+ var dto = payRes.data || {}
|
|
|
+ if (dto.orderInfo && dto.sign) {
|
|
|
+ requestVirtualPayment(dto, {
|
|
|
+ success: function() {
|
|
|
+ self.submitting = false
|
|
|
+ uni.showToast({ title: '支付成功,开通中…', icon: 'none' })
|
|
|
+ setTimeout(function() {
|
|
|
+ uni.redirectTo({ url: '/pages/growth/challenge-progress' })
|
|
|
+ }, 800)
|
|
|
+ },
|
|
|
+ fail: function(err) {
|
|
|
+ self.submitting = false
|
|
|
+ var errCode = err && err.errCode
|
|
|
+ var msg = '支付取消'
|
|
|
+ if (errCode === -15007 || errCode === -15005) msg = '登录态已过期,请重新登录'
|
|
|
+ else if (err && err.errMsg) msg = err.errMsg
|
|
|
+ uni.showToast({ title: msg, icon: 'none' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ self.submitting = false
|
|
|
+ uni.showToast({ title: payRes.message || '支付参数获取失败', icon: 'none' })
|
|
|
+ }
|
|
|
+ }).catch(function(err) {
|
|
|
+ self.submitting = false
|
|
|
+ if (err && err.code === 46001) {
|
|
|
+ uni.showToast({ title: '该商品暂未开放购买', icon: 'none' })
|
|
|
+ } else {
|
|
|
+ uni.showToast({ title: (err && err.message) || '支付参数获取失败', icon: 'none' })
|
|
|
}
|
|
|
})
|
|
|
+ } else {
|
|
|
+ self.submitting = false
|
|
|
+ uni.showToast({ title: (res.data && res.data.message) || '创建订单失败', icon: 'none' })
|
|
|
}
|
|
|
}).catch(function(err) {
|
|
|
self.submitting = false
|