<template>
|
<view class="content"></view>
|
</template>
|
|
<script>
|
import { ref, reactive, toRefs, onMounted, getCurrentInstance } from "vue";
|
import { useBasicInfoStore } from "../../store/basicInfo"
|
import { PayUseWXViaMiniProgram, PaySuccess, walletRecharge } from "../../apis/api";
|
import { guid } from "../../common/common";
|
export default {
|
setup() {
|
const userStore = useBasicInfoStore()
|
const { proxy } = getCurrentInstance();
|
const state = reactive({
|
})
|
|
onMounted(() => {
|
Init();
|
});
|
|
const Init = () => {
|
getWXLoginCode()
|
}
|
|
const getWXLoginCode = () => {
|
uni.login({
|
provider: 'weixin',
|
success: function (res) {
|
doPay(res.code,);
|
},
|
fail: () => { },
|
complete: () => { },
|
})
|
}
|
|
const doPay = (code) => {
|
|
const payData = {
|
requesturl: "",
|
code: code,
|
orderid: guid(),
|
totalprice: userStore.payInfo.payPrice,
|
}
|
|
PayUseWXViaMiniProgram(payData).then(payRes => {
|
|
if (payRes.code == 200) {
|
let pay = payRes.data;
|
|
wx_pay(
|
pay.timestamp,
|
pay.nonceStr,
|
pay.prepay_id,
|
pay.signType,
|
pay.paySign,
|
doPaySuccess, doPayFailed, doPayCompleted);
|
} else {
|
//this.$messagebox.show(payRes.message, 5000);
|
}
|
})
|
}
|
|
const doPaySuccess = (res) => {
|
uni.$u.toast('支付成功!');
|
PaySuccess(userStore.payInfo).then(resp => {
|
if (resp) {
|
switch (userStore.routePage) {
|
case 'list':
|
uni.navigateTo({
|
url: '/pages/question/type'
|
});
|
break;
|
case 'recharge':
|
let obj = {
|
pageIndex: 1,
|
pageSize: 101,
|
masterid: userStore.userinfo.id,
|
amount: userStore.payInfo.payPrice
|
}
|
walletRecharge(obj).then((res) => {
|
if (res.code == 200) {
|
uni.navigateTo({
|
url: '/pages/my/recharge'
|
});
|
} else {
|
uni.navigateTo({
|
url: '/pages/my/recharge'
|
});
|
}
|
})
|
break;
|
|
default:
|
break;
|
}
|
}
|
})
|
}
|
|
|
const doPayFailed = (res) => {
|
uni.$u.toast('支付失败!');
|
uni.navigateBack();
|
}
|
const doPayCompleted = (res) => {
|
if (res.errMsg === 'requestPayment:ok') {
|
// uni.navigateTo({
|
// url: `/pages/category/productstatus`
|
// })
|
|
} else if (res.errMsg === 'requestPayment:fail cancel') {
|
// uni.navigateTo({
|
// url: `/pages/category/productstatus`
|
// })
|
|
} else {
|
|
//this.$messagebox.show(res.errMsg, 5000);
|
}
|
|
uni.navigateBack();
|
}
|
const wx_pay = (timeStamp, nonceStr, pack, signType, paySign, successFun = null, failfun = null,
|
completeFun = null) => {
|
wx.requestPayment({
|
provider: 'wxpay',
|
orderInfo: "orderInfo",
|
timeStamp: timeStamp,
|
nonceStr: nonceStr,
|
package: "prepay_id=" + pack,
|
signType: signType,
|
paySign: paySign,
|
success(res) {
|
successFun(res)
|
},
|
fail(err) {
|
if (failfun) {
|
failfun(err)
|
}
|
},
|
complete(result) {
|
if (completeFun) {
|
completeFun(result)
|
}
|
}
|
});
|
}
|
|
|
|
|
return { ...toRefs(state), userStore }
|
}
|
}
|
|
|
|
</script>
|
|
<style scoped lang="scss">
|
.center {
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
//justify-content: center;
|
}
|
|
.content {
|
@extend .center;
|
//background-color: #f5efd9;
|
height: 100vh;
|
width: 100%;
|
}
|
</style>
|