2023-11-14 17:21:03 +08:00
|
|
|
|
<!--
|
|
|
|
|
@name: 支付状态
|
|
|
|
|
@author: kahu
|
|
|
|
|
@date: 2023-11-08 12:10
|
|
|
|
|
@description:index
|
|
|
|
|
@update: 2023-11-08 12:10
|
|
|
|
|
-->
|
|
|
|
|
<script setup>
|
|
|
|
|
import { useRouter } from "@/hooks/useRouter";
|
2024-02-08 21:01:37 +08:00
|
|
|
|
import { computed, nextTick, ref, unref } from "vue";
|
|
|
|
|
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
2024-03-05 12:16:58 +08:00
|
|
|
|
import { checkPay, checkRecharge, orderInfo } from "@/api/order";
|
2023-11-14 17:21:03 +08:00
|
|
|
|
import { CacheKey } from "@/utils/config";
|
2023-11-15 19:59:37 +08:00
|
|
|
|
import Header from '@/components/Header/index.vue'
|
|
|
|
|
import Recommend from '@/components/Recommend/index.vue'
|
|
|
|
|
import { useInterface } from "@/hooks/useInterface";
|
|
|
|
|
import { useScroll } from "@/hooks/useScroll";
|
2023-11-17 20:55:32 +08:00
|
|
|
|
import Modal from "@/components/Modal/index.vue";
|
|
|
|
|
import ListLoadLoading from "@/components/ListLoadLoading/index.vue"
|
|
|
|
|
import { lazyLoading, payError, paySuccess } from "@/utils/images";
|
2023-11-14 17:21:03 +08:00
|
|
|
|
|
|
|
|
|
const {getParams, goBack, push, pushToTab} = useRouter()
|
2024-02-08 21:01:37 +08:00
|
|
|
|
const {loading, hideLoading} = useInterface()
|
|
|
|
|
const campaignType = ref(0) // 1拼团 2秒杀 3砍价 4拼团成团
|
2023-11-14 17:21:03 +08:00
|
|
|
|
const type = ref(0) // 支付状态 : 0支付中 1支付成功 2支付失败
|
2023-11-17 20:55:32 +08:00
|
|
|
|
const {scrollTop} = useScroll()
|
2023-11-14 17:21:03 +08:00
|
|
|
|
const title = computed(() => {
|
2023-11-17 20:55:32 +08:00
|
|
|
|
if (type.value === 0) return '查询中...'
|
2023-11-14 17:21:03 +08:00
|
|
|
|
if (type.value === 1) return '支付成功'
|
|
|
|
|
if (type.value === 2) return '支付失败'
|
|
|
|
|
})
|
|
|
|
|
|
2023-11-17 20:55:32 +08:00
|
|
|
|
|
|
|
|
|
const modalRef = ref()
|
2023-11-14 17:21:03 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2023-11-17 20:55:32 +08:00
|
|
|
|
* 打开弹窗
|
2023-11-14 17:21:03 +08:00
|
|
|
|
*/
|
2024-02-08 21:01:37 +08:00
|
|
|
|
function showModal() {
|
2023-11-17 20:55:32 +08:00
|
|
|
|
unref(modalRef).show()
|
2023-11-14 17:21:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-11-17 20:55:32 +08:00
|
|
|
|
const retryTime = ref(3) // 重试次数
|
2023-11-15 19:59:37 +08:00
|
|
|
|
|
2023-11-14 17:21:03 +08:00
|
|
|
|
/**
|
|
|
|
|
* 查询服务端支付状态
|
|
|
|
|
*/
|
|
|
|
|
async function queryOrderStatus() {
|
2024-03-05 12:16:58 +08:00
|
|
|
|
loading?.({title: '查询中...'})
|
2023-11-15 19:59:37 +08:00
|
|
|
|
// 异步去查,有可能接口比微信快
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
try {
|
|
|
|
|
const payInfoStr = uni.getStorageSync(CacheKey.PAY_INFO);
|
|
|
|
|
// 没有订单缓存直接跳到订单页面
|
2024-02-08 21:01:37 +08:00
|
|
|
|
if (!payInfoStr) {
|
|
|
|
|
return orderType.value === 2 ? toMyBalance() : toOrderList(0)
|
|
|
|
|
}
|
2023-11-15 19:59:37 +08:00
|
|
|
|
const parse = JSON.parse(payInfoStr);
|
2024-03-05 12:16:58 +08:00
|
|
|
|
// 商品
|
|
|
|
|
if (orderType.value === 1) {
|
|
|
|
|
if (parse.options && parse.options.isGroup) {
|
|
|
|
|
campaignType.value = 1
|
|
|
|
|
}
|
|
|
|
|
const res = await checkPay({
|
|
|
|
|
...parse.payData,
|
|
|
|
|
uni: parse.payData.orderId || ''
|
|
|
|
|
});
|
|
|
|
|
if (!res) {
|
|
|
|
|
// 支付失败重新查询
|
|
|
|
|
if (retryTime.value > 0) {
|
|
|
|
|
retryTime.value--
|
|
|
|
|
await queryOrderStatus()
|
|
|
|
|
} else {
|
|
|
|
|
type.value = 2
|
|
|
|
|
uni.removeStorageSync(CacheKey.PAY_INFO)
|
|
|
|
|
}
|
|
|
|
|
return
|
2023-11-15 19:59:37 +08:00
|
|
|
|
} else {
|
2024-03-05 12:16:58 +08:00
|
|
|
|
type.value = 1
|
2023-11-15 19:59:37 +08:00
|
|
|
|
uni.removeStorageSync(CacheKey.PAY_INFO)
|
|
|
|
|
}
|
2024-03-05 12:16:58 +08:00
|
|
|
|
// 平团
|
|
|
|
|
if (parse.options && parse.options.isGroup) {
|
|
|
|
|
const order = await orderInfo({key: parse.payData.orderId})
|
|
|
|
|
if (order && order._status._type === '8') {
|
|
|
|
|
campaignType.value = 4
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-15 19:59:37 +08:00
|
|
|
|
}
|
2024-03-05 12:16:58 +08:00
|
|
|
|
if (orderType.value === 2) {
|
|
|
|
|
const res = await checkRecharge({
|
|
|
|
|
id: parse.payData.orderId
|
|
|
|
|
})
|
|
|
|
|
console.log(res)
|
|
|
|
|
if (Number(res) === 0) {
|
|
|
|
|
// 支付失败重新查询
|
|
|
|
|
if (retryTime.value > 0) {
|
|
|
|
|
retryTime.value--
|
|
|
|
|
await queryOrderStatus()
|
|
|
|
|
} else {
|
|
|
|
|
type.value = 2
|
|
|
|
|
uni.removeStorageSync(CacheKey.PAY_INFO)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
type.value = 1
|
|
|
|
|
uni.removeStorageSync(CacheKey.PAY_INFO)
|
2024-02-08 21:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-05 12:16:58 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
retryTime.value = 0
|
|
|
|
|
type.value = 2
|
2023-11-15 19:59:37 +08:00
|
|
|
|
uni.removeStorageSync(CacheKey.PAY_INFO)
|
|
|
|
|
} finally {
|
2024-03-05 12:16:58 +08:00
|
|
|
|
hideLoading?.()
|
2023-11-15 19:59:37 +08:00
|
|
|
|
}
|
2023-11-17 20:55:32 +08:00
|
|
|
|
}, 500)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 去订单列表
|
2024-02-08 21:01:37 +08:00
|
|
|
|
* @param status 0 待支付 1 待发货 5待成团
|
2023-11-17 20:55:32 +08:00
|
|
|
|
*/
|
2024-02-08 21:01:37 +08:00
|
|
|
|
function toOrderList(status) {
|
|
|
|
|
// 支付成功才走
|
2024-03-05 12:16:58 +08:00
|
|
|
|
if (type.value === 1) {
|
|
|
|
|
if (campaignType.value === 1) {
|
2024-02-08 21:01:37 +08:00
|
|
|
|
status = 5
|
|
|
|
|
}
|
2024-03-05 12:16:58 +08:00
|
|
|
|
if (campaignType.value === 4) {
|
|
|
|
|
status = 1
|
2024-02-08 21:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-05 12:16:58 +08:00
|
|
|
|
push({url: '/pages/orderList/orderList'}, {data: {type: status}, type: 'reLaunch'})
|
2024-02-08 21:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toMyBalance() {
|
|
|
|
|
push({url: '/views/account/balance/index'}, {data: {}, type: 'reLaunch'})
|
2023-11-17 20:55:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回首页
|
|
|
|
|
*/
|
|
|
|
|
function toBackHome() {
|
2024-02-08 21:01:37 +08:00
|
|
|
|
pushToTab({url: '/root/index/index'})
|
2023-11-14 17:21:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 19:59:37 +08:00
|
|
|
|
const recommendRef = ref(null)
|
2023-11-17 20:55:32 +08:00
|
|
|
|
|
2023-11-15 19:59:37 +08:00
|
|
|
|
onReachBottom(() => {
|
|
|
|
|
unref(recommendRef).onReachBottom && unref(recommendRef).onReachBottom();
|
|
|
|
|
})
|
|
|
|
|
|
2024-02-08 21:01:37 +08:00
|
|
|
|
const orderType = ref(1) // 1商品 2充值
|
|
|
|
|
|
2023-11-14 17:21:03 +08:00
|
|
|
|
onLoad(async (options) => {
|
2024-03-05 12:16:58 +08:00
|
|
|
|
if (options.details) {
|
|
|
|
|
options = getParams?.(options)
|
|
|
|
|
}
|
|
|
|
|
console.log(options)
|
2024-02-08 21:01:37 +08:00
|
|
|
|
// type
|
2024-03-05 12:16:58 +08:00
|
|
|
|
orderType.value = Number(options.type) || 1
|
2024-02-08 21:01:37 +08:00
|
|
|
|
// const params = getParams(options)
|
|
|
|
|
// campaignType.value = params.campaignType
|
2023-11-15 19:59:37 +08:00
|
|
|
|
// H5 和 APP 需要弹窗去确认
|
2023-11-14 17:21:03 +08:00
|
|
|
|
// #ifdef H5
|
2024-02-08 21:01:37 +08:00
|
|
|
|
await nextTick(() => {
|
2023-11-17 20:55:32 +08:00
|
|
|
|
showModal()
|
2023-11-14 17:21:03 +08:00
|
|
|
|
})
|
|
|
|
|
// #endif
|
2023-11-17 20:55:32 +08:00
|
|
|
|
// #ifndef H5
|
2023-11-15 19:59:37 +08:00
|
|
|
|
await queryOrderStatus()
|
2023-11-17 20:55:32 +08:00
|
|
|
|
// #endif
|
2023-11-14 17:21:03 +08:00
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<view class="pay-status">
|
2023-11-17 20:55:32 +08:00
|
|
|
|
<Header :scroll-top="scrollTop">
|
2023-11-15 19:59:37 +08:00
|
|
|
|
{{ title }}
|
|
|
|
|
</Header>
|
2023-11-14 17:21:03 +08:00
|
|
|
|
<view class="status-main flex flex-column flex-ai__center">
|
|
|
|
|
<image
|
|
|
|
|
class="icon"
|
2023-11-17 20:55:32 +08:00
|
|
|
|
v-if="Number(type)===0"
|
|
|
|
|
:src="lazyLoading"
|
2023-11-14 17:21:03 +08:00
|
|
|
|
/>
|
|
|
|
|
<image
|
2023-11-17 20:55:32 +08:00
|
|
|
|
class="icon"
|
|
|
|
|
v-if="Number(type)===1"
|
|
|
|
|
:src="paySuccess"
|
2023-11-14 17:21:03 +08:00
|
|
|
|
/>
|
|
|
|
|
<image
|
|
|
|
|
class="icon"
|
2023-11-17 20:55:32 +08:00
|
|
|
|
v-if="Number(type)===2"
|
|
|
|
|
:src="payError"
|
2023-11-14 17:21:03 +08:00
|
|
|
|
/>
|
2024-02-08 21:01:37 +08:00
|
|
|
|
<view
|
|
|
|
|
class="text"
|
|
|
|
|
v-if="[1,2].includes(Number(type))">
|
2023-11-14 17:21:03 +08:00
|
|
|
|
{{ title }}
|
|
|
|
|
</view>
|
2024-02-08 21:01:37 +08:00
|
|
|
|
<ListLoadLoading
|
|
|
|
|
v-else
|
|
|
|
|
:show-line="false"
|
|
|
|
|
text="查询中..." />
|
2023-11-14 17:21:03 +08:00
|
|
|
|
</view>
|
|
|
|
|
<view class="button-group flex flex-ai__center flex-jc__center">
|
2024-03-05 12:16:58 +08:00
|
|
|
|
<template v-if="orderType === 1">
|
|
|
|
|
<view
|
|
|
|
|
class="animation-button button white-button"
|
|
|
|
|
v-if="Number(type)===1"
|
|
|
|
|
@click="toBackHome"
|
|
|
|
|
>
|
|
|
|
|
继续逛逛
|
|
|
|
|
</view>
|
2024-02-08 21:01:37 +08:00
|
|
|
|
<view
|
|
|
|
|
class="animation-button button"
|
|
|
|
|
v-if="Number(type)===1"
|
|
|
|
|
@click="toOrderList(1)"
|
|
|
|
|
>
|
|
|
|
|
查看订单
|
|
|
|
|
</view>
|
|
|
|
|
<view
|
|
|
|
|
class="animation-button button"
|
|
|
|
|
v-if="Number(type)===2"
|
|
|
|
|
@click="toOrderList(0)"
|
|
|
|
|
>
|
|
|
|
|
重新支付
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
|
|
|
|
<view
|
|
|
|
|
class="animation-button button"
|
|
|
|
|
v-if="Number(type)===1"
|
|
|
|
|
@click="toMyBalance"
|
|
|
|
|
>
|
|
|
|
|
我的余额
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
2023-11-14 17:21:03 +08:00
|
|
|
|
</view>
|
2023-11-15 19:59:37 +08:00
|
|
|
|
<!-- 商品推荐 -->
|
|
|
|
|
<Recommend ref="recommendRef" />
|
2024-02-08 21:01:37 +08:00
|
|
|
|
<Modal
|
|
|
|
|
ref="modalRef"
|
|
|
|
|
content="请确认支付是否完成?"
|
|
|
|
|
@confirm="queryOrderStatus"
|
|
|
|
|
@cancel="queryOrderStatus" />
|
2023-11-14 17:21:03 +08:00
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style
|
|
|
|
|
scoped
|
|
|
|
|
lang="scss"
|
|
|
|
|
>
|
|
|
|
|
.pay-status {
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
|
|
.status-main {
|
|
|
|
|
@include usePadding(0, 130);
|
|
|
|
|
width: 100%;
|
2024-02-08 21:01:37 +08:00
|
|
|
|
font-size: 36rpx;
|
2023-11-14 17:21:03 +08:00
|
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
|
width: 170rpx;
|
|
|
|
|
height: 170rpx;
|
2023-11-17 20:55:32 +08:00
|
|
|
|
margin-bottom: 30rpx;
|
2023-11-14 17:21:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.col-icon {
|
|
|
|
|
width: 240rpx;
|
|
|
|
|
height: 120rpx;
|
|
|
|
|
}
|
2023-11-17 20:55:32 +08:00
|
|
|
|
|
2023-11-14 17:21:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.button-group {
|
|
|
|
|
margin-bottom: 30rpx;
|
|
|
|
|
gap: 30rpx;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
|
|
.button {
|
|
|
|
|
width: 230rpx;
|
|
|
|
|
height: 80rpx;
|
|
|
|
|
background: #333333;
|
|
|
|
|
font-size: 34rpx;
|
|
|
|
|
color: #fff;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.white-button {
|
|
|
|
|
background: $white-color;
|
|
|
|
|
color: #333;
|
|
|
|
|
border: 1rpx solid #333;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|