liveh5-nuxt/app/pages/collectCode/payment/index.vue

131 lines
3.6 KiB
Vue
Raw Normal View History

<script setup>
2025-03-04 11:06:01 +00:00
import { liveStore } from "~/stores/live/index.js";
import { createBuyOrder } from "~/api/goods/index.js";
import { goodStore } from "~/stores/goods/index.js";
import { showLoadingToast, closeToast } from "vant";
import { authStore } from "~/stores/auth/index.js";
import { message } from "~/components/x-message/useMessage.js";
2025-03-04 12:25:44 +00:00
import { createOrder, offlineQrcode } from "~/api-collect-code/goods/index.js";
2025-05-19 03:44:09 +00:00
import {abroadCreateOrder} from "~/api-collect-code/abroad/index.js"
2025-03-04 11:06:01 +00:00
import { codeAuthStore } from "~/stores-collect-code/auth/index.js";
import { useI18n } from "vue-i18n";
2025-02-25 09:00:07 +00:00
2025-03-04 12:25:44 +00:00
const amount = ref("");
const router = useRouter();
const route = useRoute();
2025-05-19 03:44:09 +00:00
const type=route.query.type
2025-03-04 11:06:01 +00:00
const { t } = useI18n();
const { checkoutSessionUrl, qrUid, qrData, codePKey, codePayUid } =
codeAuthStore();
const payStatus = ref(0);
2025-03-04 12:25:44 +00:00
const state = reactive({
2025-05-23 02:13:44 +00:00
pageRequest: true,
2025-03-04 12:25:44 +00:00
});
definePageMeta({
2025-03-04 11:06:01 +00:00
i18n: "payment.title",
});
2025-03-04 12:25:44 +00:00
const getData = async () => {
state.pageRequest = true;
const res = await offlineQrcode({
qrUid: route.query.qrUid,
});
if (res.status === 0) {
qrData.value = res.data;
payStatus.value = res.data.payStatus;
if (qrData.value.payStatus === 2) {
state.pageRequest = false;
} else {
confirmPay();
}
}
2025-03-04 11:06:01 +00:00
};
2025-03-04 12:25:44 +00:00
// 获取二维码价格
2025-05-19 07:12:51 +00:00
// getData();
const confirmPay = async () => {
const res = await createOrder({
2025-03-04 12:25:44 +00:00
price: qrData.value.price,
currency: qrData.value.currency,
2025-03-04 12:25:44 +00:00
qrUid: route.query.qrUid,
2025-03-04 11:06:01 +00:00
testReturnHost: window.location.origin,
testReturnEndPoint: "/collectCode/payment/result",
});
if (res.status === 0) {
2025-03-04 11:06:01 +00:00
codePKey.value = res.data.checkoutSessionUrl;
codePayUid.value = res.data.payUid;
2025-03-04 12:34:27 +00:00
window.location.href = res.data.checkoutSessionUrl;
return;
router.push({
2025-03-04 11:06:01 +00:00
path: "/checkoutPage",
query: {
payUid: res.data.payUid,
returnUrl: "/collectCode/payment/result",
stripeKey: res.data.checkoutSessionUrl,
},
});
}
2025-03-04 11:06:01 +00:00
};
2025-05-19 07:12:51 +00:00
// 画家海外支付 扫码支付
2025-05-19 03:44:09 +00:00
const abroadPay=async ()=>{
if(!route.query.qrUid){
return
}
const res=await abroadCreateOrder({
QrUid:route.query.qrUid
});
if(res.status===0){
2025-05-23 02:13:44 +00:00
2025-05-19 03:44:09 +00:00
codePKey.value = res.data.checkoutSessionUrl;
codePayUid.value = res.data.payUid;
window.location.href = res.data.checkoutSessionUrl;
}
}
2025-05-19 07:12:51 +00:00
// 根据是否有type选择执行支付方式当type=abroad时属于画家海外支付
2025-05-19 03:44:09 +00:00
const payment=async ()=>{
if(type==="abroad"){
await abroadPay()
}else{
2025-05-19 07:12:51 +00:00
await getData()
2025-05-19 03:44:09 +00:00
}
}
2025-05-19 07:12:51 +00:00
payment()
</script>
<template>
<div
2025-03-04 11:06:01 +00:00
class="w-[100vw] h-screen-nav bg-[url('@/static/images/3532@2x.png')] bg-cover flex-grow-1 flex flex-col items-center pt-183px px-30px"
>
2025-03-04 12:25:44 +00:00
<div
v-if="state.pageRequest"
class="fixed left-0 top-0 w-full h-full bg-white/50 flex items-center justify-center z-50"
>
<van-loading color="#1989fa" size="36px" vertical
>跳转支付处理中...</van-loading
>
2025-03-04 11:06:01 +00:00
</div>
2025-03-04 12:25:44 +00:00
<div v-if="!state.pageRequest" class="mb-30px">
<img class="w-126px h-126px" src="@/static/images/dddf34@2x.png" alt="" />
</div>
2025-03-04 11:06:01 +00:00
<div
2025-03-04 12:25:44 +00:00
v-if="!state.pageRequest"
2025-03-04 11:06:01 +00:00
class="text-#999999 text-16px mb-24px font-bold"
>
2025-03-04 12:25:44 +00:00
{{ qrData.price + " " + qrData.currency }}
</div>
2025-03-04 12:25:44 +00:00
<div
v-if="!state.pageRequest"
class="text-#1A1A1A text-16px mb-25px font-bold"
>
你已完成全部支付
</div>
2025-03-04 12:25:44 +00:00
<!-- <div class="w-full mt-auto mb-40px">
<van-button type="primary" block @click="confirmPay">
2025-03-04 11:06:01 +00:00
{{ $t("collectCode.payment.confirmPayment") }}
</van-button>
2025-03-04 12:25:44 +00:00
</div> -->
</div>
</template>
2025-03-04 11:06:01 +00:00
<style scoped></style>