|
@@ -2,13 +2,14 @@
|
|
import { showConfirm } from '@/components/Toast'
|
|
import { showConfirm } from '@/components/Toast'
|
|
import { ref, computed, onMounted } from 'vue'
|
|
import { ref, computed, onMounted } from 'vue'
|
|
import { useUserStore } from '@/stores/user'
|
|
import { useUserStore } from '@/stores/user'
|
|
-import { openPay, getOrderInfo } from '@/api/api'
|
|
|
|
-import { useRoute } from 'vue-router';
|
|
|
|
-import { GetRequest } from '@/utils/index'
|
|
|
|
|
|
+import { openPay, getOrderInfo, wxLogin } from '@/api/api'
|
|
|
|
+import { useRoute } from 'vue-router'
|
|
|
|
+import { GetRequest, getWeChatCode } from '@/utils/index'
|
|
const payType = ref('0')
|
|
const payType = ref('0')
|
|
const route = useRoute()
|
|
const route = useRoute()
|
|
const orderDetal = ref({})
|
|
const orderDetal = ref({})
|
|
const orderSn = ref(route.query.id || GetRequest('orderSn'))
|
|
const orderSn = ref(route.query.id || GetRequest('orderSn'))
|
|
|
|
+const { getToken, openId, isEur, info, setUserData } = useUserStore()
|
|
const is_weixn = computed(() => {
|
|
const is_weixn = computed(() => {
|
|
if (typeof WeixinJSBridge == 'undefined') {
|
|
if (typeof WeixinJSBridge == 'undefined') {
|
|
return false
|
|
return false
|
|
@@ -23,29 +24,31 @@ const is_weixn = computed(() => {
|
|
// }
|
|
// }
|
|
//判断是否微信
|
|
//判断是否微信
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
|
+ console.log('useUserStore',getToken, openId, isEur, info)
|
|
getDetial()
|
|
getDetial()
|
|
})
|
|
})
|
|
-const { token, info, isEur } = useUserStore()
|
|
|
|
async function handelPay() {
|
|
async function handelPay() {
|
|
let apiData = {
|
|
let apiData = {
|
|
orderSn: orderSn.value,
|
|
orderSn: orderSn.value,
|
|
- payType: !is_weixn.value ? '1' : payType.value,
|
|
|
|
|
|
+ payType: is_weixn.value ? '1' : payType.value,
|
|
openId: 'dolor exercitation velit'
|
|
openId: 'dolor exercitation velit'
|
|
}
|
|
}
|
|
- // const res = await openPay(apiData)
|
|
|
|
|
|
+ const res = await openPay(apiData)
|
|
// console.log('apiData', res)
|
|
// console.log('apiData', res)
|
|
if (is_weixn.value) {
|
|
if (is_weixn.value) {
|
|
//微信内支付
|
|
//微信内支付
|
|
onBridgeReady(res)
|
|
onBridgeReady(res)
|
|
|
|
+ } else if (res.form || res.h5Url) {
|
|
|
|
+ console.log('payType', res.form || res.h5Url)
|
|
|
|
+ window.location.href = res.form || res.h5Url
|
|
} else {
|
|
} else {
|
|
showConfirm({
|
|
showConfirm({
|
|
- text: '成功了',
|
|
|
|
- type: 'warn',
|
|
|
|
- callback: (val) => {
|
|
|
|
- console.log('我的测试计划', val)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- // window.location.href = res.form || res.h5Url
|
|
|
|
|
|
+ text: '支付异常',
|
|
|
|
+ type: 'err',
|
|
|
|
+ callback: (val) => {
|
|
|
|
+ console.log('我的测试计划', val)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 调微信支付
|
|
// 调微信支付
|
|
@@ -95,8 +98,19 @@ function handleType(params: string) {
|
|
function getDetial() {
|
|
function getDetial() {
|
|
getOrderInfo(orderSn.value).then((res) => {
|
|
getOrderInfo(orderSn.value).then((res) => {
|
|
orderDetal.value = res
|
|
orderDetal.value = res
|
|
|
|
+ handleWxlogin(res.wxAppId)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+async function handleWxlogin(wxAppId:string) {
|
|
|
|
+ const code = GetRequest('code')
|
|
|
|
+ if(!openId && !code){//微信登录
|
|
|
|
+ getWeChatCode(wxAppId)
|
|
|
|
+ }else if(code){//存在code 换取openid
|
|
|
|
+ const res = wxLogin({code,orderSn})
|
|
|
|
+ setUserData(res.openId,'openId')
|
|
|
|
+ console.log('wxLogin', res)
|
|
|
|
+ }
|
|
|
|
+}
|
|
async function handleOpenPay() {
|
|
async function handleOpenPay() {
|
|
openPay({
|
|
openPay({
|
|
orderSn: GetRequest('orderSn'),
|
|
orderSn: GetRequest('orderSn'),
|
|
@@ -147,7 +161,7 @@ async function handleOpenPay() {
|
|
</div>
|
|
</div>
|
|
<div class="bottomInfo">
|
|
<div class="bottomInfo">
|
|
<div class="price">
|
|
<div class="price">
|
|
- 应付金额<span>¥{{ orderDetal?.orderMoney || 0.00 }}</span>
|
|
|
|
|
|
+ 应付金额<span>¥{{ orderDetal?.orderMoney || 0.0 }}</span>
|
|
</div>
|
|
</div>
|
|
<div class="payBut" @click="handelPay">付款</div>
|
|
<div class="payBut" @click="handelPay">付款</div>
|
|
</div>
|
|
</div>
|