Commit 5e587c42 authored by Damon's avatar Damon

feat: 购买

parent 1b360b91
...@@ -52,6 +52,7 @@ export default { ...@@ -52,6 +52,7 @@ export default {
data() { data() {
return { return {
relationId: 0, // 绑卡用 relationId: 0, // 绑卡用
info: {}
} }
}, },
...@@ -99,7 +100,27 @@ export default { ...@@ -99,7 +100,27 @@ export default {
}, },
}) })
}, },
handleClickBuy() {}, handleClickBuy() {
const lists = [
{
questionWarehouseId: this.questionWarehouseId,
amount: this.info.discount,
count: 1,
}
]
const data = {
instrtutionId: getApp().globalData.orgId,
orders: JSON.stringify(lists),
openId: this.openId,
}
uni.showLoading({
title: '加载中',
})
this.$u.api.payOrder(data).then((res) => {
uni.hideLoading()
this.pay(res)
})
},
handleChange() { handleChange() {
this.$u.route({ this.$u.route({
url: 'pages/learn/manualBinding', url: 'pages/learn/manualBinding',
...@@ -108,6 +129,48 @@ export default { ...@@ -108,6 +129,48 @@ export default {
}, },
}) })
}, },
pay(data) {
uni.requestPayment({
provider: 'wxpay',
timeStamp: data.timeStamp,
nonceStr: data.nonce_str,
package: `prepay_id=${data.prepay_id}`,
signType: 'MD5',
paySign: data.sign,
success: (res) => {
console.log('success:' + JSON.stringify(res))
this.checkPayStatus(data.out_trade_no)
},
fail: (err) => {
console.log('fail:' + JSON.stringify(err))
if (err.errMsg === 'requestPayment:fail cancel') {
this.$u.toast('取消支付')
} else {
this.checkPayStatus(data.out_trade_no)
}
},
})
},
checkPayStatus(no) {
const params = {
outTradeNo: no,
}
uni.showLoading({
title: '支付中',
})
this.$u.api.payQuery(params).then((res) => {
uni.hideLoading()
if (res.trade_state === 'SUCCESS') {
this.$u.toast('支付成功')
} else if (res.trade_state === 'NOTPAY') {
this.$u.toast('请稍后核实订单状态,不要重复发起支付')
} else if (res.trade_state === 'PAYERROR') {
this.$u.toast('支付失败')
} else {
this.$u.toast(res.trade_state_desc)
}
})
},
}, },
} }
</script> </script>
......
...@@ -87,7 +87,6 @@ ...@@ -87,7 +87,6 @@
</template> </template>
<script> <script>
import md5 from '@/common/md5.js'
export default { export default {
data() { data() {
return { return {
...@@ -100,14 +99,7 @@ export default { ...@@ -100,14 +99,7 @@ export default {
multipleChoice: 322, multipleChoice: 322,
trueOrFalse: 526, trueOrFalse: 526,
total: 986, total: 986,
}, }
lists: [
{
questionWarehouseId: 1,
amount: 0.01,
count: 1,
},
],
} }
}, },
...@@ -196,9 +188,16 @@ export default { ...@@ -196,9 +188,16 @@ export default {
}) })
}, },
handleClickBuy() { handleClickBuy() {
const lists = [
{
questionWarehouseId: this.questionWarehouseId,
amount: this.info.discount,
count: 1,
}
]
const data = { const data = {
instrtutionId: 1, instrtutionId: getApp().globalData.orgId,
orders: JSON.stringify(this.lists), orders: JSON.stringify(lists),
openId: this.openId, openId: this.openId,
} }
uni.showLoading({ uni.showLoading({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment