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";
|
|
|
|
|
import { computed, ref, unref } from "vue";
|
2023-11-15 19:59:37 +08:00
|
|
|
|
import { onLoad, onPageScroll, onReachBottom } from "@dcloudio/uni-app";
|
|
|
|
|
import { checkPay } 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-14 17:21:03 +08:00
|
|
|
|
|
|
|
|
|
const {getParams, goBack, push, pushToTab} = useRouter()
|
2023-11-15 19:59:37 +08:00
|
|
|
|
const {loading,hideLoading} = useInterface()
|
2023-11-14 17:21:03 +08:00
|
|
|
|
const type = ref(0) // 支付状态 : 0支付中 1支付成功 2支付失败
|
2023-11-15 19:59:37 +08:00
|
|
|
|
useScroll()
|
2023-11-14 17:21:03 +08:00
|
|
|
|
const title = computed(() => {
|
|
|
|
|
if (type.value === 0) return '支付中...'
|
|
|
|
|
if (type.value === 1) return '支付成功'
|
|
|
|
|
if (type.value === 2) return '支付失败'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const routerParams = ref({})
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 去订单列表
|
|
|
|
|
* @param type 0 待支付 1 待发货
|
|
|
|
|
*/
|
|
|
|
|
function toOrderList(type) {
|
|
|
|
|
push({url: '/pages/orderList/orderList'}, {data: {type}, type: 'reLaunch'})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toBackHome() {
|
|
|
|
|
pushToTab({url: '/pages/index/index'})
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 19:59:37 +08:00
|
|
|
|
const retryTime = ref(3)
|
|
|
|
|
|
2023-11-14 17:21:03 +08:00
|
|
|
|
/**
|
|
|
|
|
* 查询服务端支付状态
|
|
|
|
|
*/
|
|
|
|
|
async function queryOrderStatus() {
|
2023-11-15 19:59:37 +08:00
|
|
|
|
loading({title: '查询中...'})
|
|
|
|
|
// 异步去查,有可能接口比微信快
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
try {
|
|
|
|
|
const payInfoStr = uni.getStorageSync(CacheKey.PAY_INFO);
|
|
|
|
|
// 没有订单缓存直接跳到订单页面
|
|
|
|
|
if (!payInfoStr) return toOrderList(0)
|
|
|
|
|
|
|
|
|
|
const parse = JSON.parse(payInfoStr);
|
|
|
|
|
const res = await checkPay(parse);
|
|
|
|
|
if (!res) {
|
|
|
|
|
// 支付失败重新查询
|
|
|
|
|
if (retryTime.value > 0) {
|
|
|
|
|
retryTime.value--
|
|
|
|
|
await queryOrderStatus()
|
|
|
|
|
} else {
|
|
|
|
|
type.value = 2
|
|
|
|
|
uni.removeStorageSync(CacheKey.PAY_INFO)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
type.value = 1
|
|
|
|
|
uni.removeStorageSync(CacheKey.PAY_INFO)
|
|
|
|
|
} finally {
|
|
|
|
|
hideLoading()
|
|
|
|
|
}
|
|
|
|
|
}, 1000)
|
2023-11-14 17:21:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 19:59:37 +08:00
|
|
|
|
const recommendRef = ref(null)
|
|
|
|
|
onReachBottom(() => {
|
|
|
|
|
unref(recommendRef).onReachBottom && unref(recommendRef).onReachBottom();
|
|
|
|
|
})
|
|
|
|
|
|
2023-11-14 17:21:03 +08:00
|
|
|
|
onLoad(async (options) => {
|
2023-11-15 19:59:37 +08:00
|
|
|
|
// H5 和 APP 需要弹窗去确认
|
2023-11-14 17:21:03 +08:00
|
|
|
|
// #ifdef H5
|
|
|
|
|
uni.showModal({
|
|
|
|
|
content: '请确认支付是否完成',
|
|
|
|
|
success: async () => {
|
|
|
|
|
await queryOrderStatus()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// #endif
|
2023-11-15 19:59:37 +08:00
|
|
|
|
await queryOrderStatus()
|
2023-11-14 17:21:03 +08:00
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<view class="pay-status">
|
2023-11-15 19:59:37 +08:00
|
|
|
|
<Header>
|
|
|
|
|
{{ title }}
|
|
|
|
|
</Header>
|
2023-11-14 17:21:03 +08:00
|
|
|
|
<view class="status-main flex flex-column flex-ai__center">
|
|
|
|
|
<image
|
|
|
|
|
class="icon"
|
|
|
|
|
v-if="Number(type)===2"
|
|
|
|
|
|
|
|
|
|
src="@/static/icon/pay/pay-error.png"
|
|
|
|
|
/>
|
|
|
|
|
<image
|
|
|
|
|
class="icon col-icon"
|
|
|
|
|
v-else-if="Number(type)===0"
|
|
|
|
|
src="@/static/icon/logo.png"
|
|
|
|
|
/>
|
|
|
|
|
<image
|
|
|
|
|
class="icon"
|
|
|
|
|
v-else
|
|
|
|
|
src="@/static/icon/pay/pay-success.png"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<view class="text">
|
|
|
|
|
{{ title }}
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="button-group flex flex-ai__center flex-jc__center">
|
|
|
|
|
<view
|
|
|
|
|
class="animation-button button white-button"
|
|
|
|
|
v-if="Number(type)===1"
|
|
|
|
|
@click="toBackHome"
|
|
|
|
|
>
|
|
|
|
|
继续逛逛
|
|
|
|
|
</view>
|
|
|
|
|
<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>
|
|
|
|
|
</view>
|
2023-11-15 19:59:37 +08:00
|
|
|
|
<!-- 商品推荐 -->
|
|
|
|
|
<Recommend ref="recommendRef" />
|
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%;
|
|
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
|
width: 170rpx;
|
|
|
|
|
height: 170rpx;
|
|
|
|
|
margin-bottom: 20rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.col-icon {
|
|
|
|
|
width: 240rpx;
|
|
|
|
|
height: 120rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.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>
|