Commit d03e4b30 authored by zengqiang's avatar zengqiang

feat: H5提现功能对齐小程序实现

- 对齐后端api-jksxb-app和api-jksxb-mini的提现接口响应 - 修复提现列表页按钮显示逻辑,使用withdrawStatus判断WAIT_CONFIRM状态 - ProcessingStatus页面样式改用vw单位适配移动端 - 移除ProcessingStatus页面不应有的"去确认收款"按钮 - ProcessingStatus页面卡片文本对齐P3b设计文档 - ConfirmReceipt页面支持从列表页进入时获取packageInfo - 修复withdrawService接口类型定义(axios拦截器已解包)
parent abfbbfac
......@@ -42,7 +42,12 @@ export enum ErrCode {
// 提现记录状态
export enum WithdrawStatus {
WITHDRAWING = 'WITHDRAWING',
RECEIVED = 'RECEIVED',
FAILED = 'FAILED'
WITHDRAWING = 'WITHDRAWING', // 提现中
RECEIVED = 'RECEIVED', // 已到账
FAILED = 'FAILED', // 提现失败
WAIT_CONFIRM = 'WAIT_CONFIRM', // 待用户确认收款
TRANSFERING = 'TRANSFERING', // 转账中
ACCEPTED = 'ACCEPTED', // 已受理
CANCELING = 'CANCELING', // 撤销中
CANCELLED = 'CANCELLED' // 已撤销
}
......@@ -65,7 +65,9 @@ export interface WithdrawListResponse {
withdrawApplyTime: string;
withdrawAmount: number;
withdrawPayTime: string;
status: string;
status: string; // 显示状态 (WithdrawDisplayStatusEnum)
withdrawStatus?: string; // 原始提现状态 (WithdrawStatusEnum)
withdrawNo?: string; // 提现流水号
expectedPayTime: string;
failTime: string;
reason: string;
......@@ -85,10 +87,13 @@ export interface WithdrawParams {
export interface WithdrawResponse {
serialNo: string;
withdrawNo: string;
withdrawAccount: string;
amount: number;
withdrawApplyTime: string;
expectedPayTime: string;
packageInfo?: string;
mchId?: string;
}
export interface WithdrawRiskResponse {
......
......@@ -29,12 +29,12 @@ const routes: Array<RouteRecordRaw> = [
{
path: '/withdraw/confirm-receipt',
name: 'WithdrawConfirmReceipt',
component: () => import('../views/withdraw/ConfirmReceipt.vue'),
component: () => import('../views/withdraw/ConfirmReceipt.vue')
},
{
path: '/withdraw/processing-status',
name: 'WithdrawProcessingStatus',
component: () => import('../views/withdraw/ProcessingStatus.vue'),
component: () => import('../views/withdraw/ProcessingStatus.vue')
}
]
......
import { post, get } from '../request';
import { get } from '../request'
interface WithdrawRequestData {
interface WithdrawStatusResponseData {
withdrawNo: string;
amount: string;
accountInfo: {
name: string;
bank: string;
type: string;
};
// Add other necessary fields as per backend API
}
interface WithdrawResponseData {
code: number;
message?: string;
data?: {
orderId: string;
packageInfo?: string; // For WeChat Pay H5 or other payment bridge data
};
withdrawStatus: string;
failReason?: string;
withdrawApplyTime: string;
withdrawPayTime: string;
}
interface WithdrawStatusResponseData {
code: number;
message?: string;
data?: {
state: string; // e.g., PROCESSING, SUCCESS, FAILED
// Add other status details
};
interface WithdrawPackageInfoResponseData {
packageInfo: string;
mchId: string;
}
/**
* 发起提现申请
* @param {WithdrawRequestData} data - 提现请求数据
* @returns {Promise<WithdrawResponseData>}
* 查询提现明细
* @param {string} withdrawNo - 提现流水号
* @returns {Promise<WithdrawStatusResponseData>}
*/
export function postWithdraw(data: WithdrawRequestData): Promise<WithdrawResponseData> {
return post(
'/api-jksxb-h5/withdraw',
data,
);
export function queryWithdrawStatus (withdrawNo: string): Promise<WithdrawStatusResponseData> {
return get(
`/api-jksxb-app/v1/withdraw/detail?withdrawNo=${withdrawNo}`
)
}
/**
* 查询转账状态
* @param {string} orderId - 订单ID
* @returns {Promise<WithdrawStatusResponseData>}
* 获取提现确认参数
* @param {string} withdrawNo - 提现流水号
* @returns {Promise<WithdrawPackageInfoResponseData>}
*/
export function queryWithdrawStatus(orderId: string): Promise<WithdrawStatusResponseData> {
export function getWithdrawPackageInfo (withdrawNo: string): Promise<WithdrawPackageInfoResponseData> {
return get(
`/api-jksxb-h5/withdraw/status?orderId=${orderId}`,
);
`/api-jksxb-app/v1/withdraw/packageInfo?withdrawNo=${withdrawNo}`
)
}
......@@ -5,33 +5,14 @@
<div class="header-status">
<i
class="iconfont"
:class="
item.status === WithdrawStatus.WITHDRAWING
? 'icon-shijian'
: item.status === WithdrawStatus.RECEIVED
? 'icon-jindutiaoqiandai'
: 'icon-xiazaishibai'
"
:style="{
color:
item.status === WithdrawStatus.WITHDRAWING
? '#46BB36'
: item.status === WithdrawStatus.RECEIVED
? '#027AFF'
: '#F1551E'
}"
:class="getStatusIconClass(item.withdrawStatus || item.status)"
:style="{ color: getStatusIconColor(item.withdrawStatus || item.status) }"
></i>
<span>{{
item.status === WithdrawStatus.WITHDRAWING
? "提现中"
: item.status === WithdrawStatus.RECEIVED
? "提现成功"
: "提现失败"
}}</span>
<label v-if="item.status === WithdrawStatus.WITHDRAWING">请耐心等候~</label>
<span>{{ getStatusText(item.withdrawStatus || item.status) }}</span>
<label v-if="isProcessingStatus(item.withdrawStatus || item.status)">请耐心等候~</label>
</div>
<p class="apply-money">
{{ item.status === WithdrawStatus.RECEIVED ? "-" : "" }}¥{{
{{ item.status === 'RECEIVED' ? "-" : "" }}¥{{
item.withdrawAmount.toFixed(2)
}}
</p>
......@@ -39,38 +20,115 @@
<ul class="withdraw-list-detail">
<li>微信提现:{{ item.accountName }}</li>
<li>申请时间:{{ item.withdrawApplyTime }}</li>
<li v-if="item.status === WithdrawStatus.WITHDRAWING">
<li v-if="isProcessingStatus(item.withdrawStatus || item.status)">
预计时间:{{ item.expectedPayTime }}
</li>
<li v-if="item.status === WithdrawStatus.RECEIVED">到账时间:{{ item.withdrawPayTime }}</li>
<li v-if="item.status === WithdrawStatus.FAILED">失败时间:{{ item.failTime }}</li>
<li v-if="item.status === WithdrawStatus.FAILED">失败原因:{{ item.reason }}</li>
<li v-if="item.status === 'RECEIVED'">到账时间:{{ item.withdrawPayTime }}</li>
<li v-if="item.status === 'FAILED'">失败时间:{{ item.failTime }}</li>
<li v-if="item.status === 'FAILED'">失败原因:{{ item.reason }}</li>
</ul>
<van-button class="action-btn" v-if="needConfirmAction(item.withdrawStatus) && item.withdrawNo" round type="primary" color="#07c160" block @click="handleConfirmReceipt(item)">去确认收款</van-button>
<div class="action-hint" v-if="needConfirmAction(item.withdrawStatus) && !item.withdrawNo">
<span class="hint-text">请在微信中确认收款</span>
</div>
</div>
</pull-refresh-list>
</template>
<script lang="ts">
import { defineComponent, computed } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
import { Button } from 'vant'
import { getWithdrawList } from '@/server/api/bonus'
import { WithdrawStatus } from '@/model/bonus/constant'
import PullRefreshList from './components/pull-pefresh-list.vue'
export default defineComponent({
components: {
PullRefreshList
PullRefreshList,
[Button.name]: Button
},
setup () {
const store = useStore()
const router = useRouter()
const bonusStoreState = computed(() => store.state.bonus)
const paramsFn = () => ({
studentId: bonusStoreState.value.studentId
})
return { WithdrawStatus, getWithdrawList, paramsFn }
// 处理中的状态
const processingStatuses = ['APPROVING', 'TRANSFERING', 'WITHDRAWING', 'WAIT_CONFIRM']
const isProcessingStatus = (status: string) => processingStatuses.includes(status)
// 判断是否需要显示"去确认收款"按钮
const needConfirmAction = (withdrawStatus: string) => {
return withdrawStatus === 'WAIT_CONFIRM' || withdrawStatus === 'APPROVING'
}
// 获取状态图标类名
const getStatusIconClass = (status: string) => {
const classMap: Record<string, string> = {
APPROVING: 'icon-shijian',
TRANSFERING: 'icon-shijian',
WITHDRAWING: 'icon-shijian',
WAIT_CONFIRM: 'icon-shijian',
RECEIVED: 'icon-jindutiaoqiandai',
FAILED: 'icon-xiazaishibai'
}
return classMap[status] || 'icon-shijian'
}
// 获取状态图标颜色
const getStatusIconColor = (status: string) => {
const colorMap: Record<string, string> = {
APPROVING: '#46BB36',
TRANSFERING: '#46BB36',
WITHDRAWING: '#46BB36',
WAIT_CONFIRM: '#fa8c16',
RECEIVED: '#027AFF',
FAILED: '#F1551E'
}
return colorMap[status] || '#46BB36'
}
// 获取状态文本
const getStatusText = (status: string) => {
const textMap: Record<string, string> = {
APPROVING: '审批中',
TRANSFERING: '转账中',
WITHDRAWING: '提现中',
WAIT_CONFIRM: '待确认收款',
RECEIVED: '提现成功',
FAILED: '提现失败'
}
return textMap[status] || '处理中'
}
// 去确认收款
const handleConfirmReceipt = (item: any) => {
router.push({
path: '/withdraw/confirm-receipt',
query: {
withdrawNo: item.withdrawNo,
amount: item.withdrawAmount?.toFixed(2) || '0.00',
withdrawAccount: encodeURIComponent(item.accountName || '')
}
})
}
return {
getWithdrawList,
paramsFn,
isProcessingStatus,
needConfirmAction,
getStatusIconClass,
getStatusIconColor,
getStatusText,
handleConfirmReceipt
}
}
})
</script>
......@@ -119,5 +177,18 @@ export default defineComponent({
line-height: 1.6em;
}
}
.action-btn {
margin-top: 20px;
height: 44px;
font-size: 16px;
}
.action-hint {
margin-top: 40rpx;
text-align: center;
.hint-text {
color: #fa8c16;
font-size: 28rpx;
}
}
}
</style>
......@@ -53,17 +53,12 @@
:withdraw-account="withdrawAccount"
@withdraw-success="withdrawSuccess"
/>
<!-- 提现成功弹窗 -->
<WithdrawSuccessDialog
v-model:show="showWithdrawSuccess"
:withdraw-response="withdrawResponse"
/>
</div>
</template>
<script lang="ts">
import { computed, defineComponent, onMounted, reactive, toRefs } from 'vue'
import { useRoute } from 'vue-router'
import { useRoute, useRouter } from 'vue-router'
import { useStore } from 'vuex'
import { Button, Cell, Dialog, Field, Toast } from 'vant'
......@@ -71,7 +66,6 @@ import { Button, Cell, Dialog, Field, Toast } from 'vant'
import { sendNativeMessage } from '@/util/use-native-bridge'
import { getWithdrawRisk } from '@/server/api/bonus'
import { WithdrawResponse } from '@/model/bonus'
import WithdrawSuccessDialog from './withdraw-success-dialog.vue'
import WithdrawDialog from './withdraw-dialog.vue'
interface State {
......@@ -86,11 +80,11 @@ const Withdraw = defineComponent({
[Cell.name]: Cell,
[Field.name]: Field,
[Dialog.Component.name]: Dialog.Component,
WithdrawSuccessDialog,
WithdrawDialog
},
setup () {
const route = useRoute()
const router = useRouter()
const store = useStore()
const bonusStoreState = computed(() => store.state.bonus)
......@@ -99,7 +93,6 @@ const Withdraw = defineComponent({
withdrawableTotal: 0,
maxWithDraw: 0,
showWithdraw: false,
showWithdrawSuccess: false,
withdrawAccount: '',
withdrawAccountId: '',
withdrawResponse: {},
......@@ -134,9 +127,33 @@ const Withdraw = defineComponent({
}
// 提现成功
const withdrawSuccess = (data: any) => {
const withdrawSuccess = (data: WithdrawResponse) => {
state.withdrawResponse = data
state.showWithdrawSuccess = true
// 新版流程:根据是否有 packageInfo 决定跳转
if (data.packageInfo) {
// 跳转到确认收款页
router.replace({
path: '/withdraw/confirm-receipt',
query: {
withdrawNo: data.withdrawNo || data.serialNo,
amount: data.amount.toFixed(2),
withdrawAccount: encodeURIComponent(data.withdrawAccount),
packageInfo: encodeURIComponent(data.packageInfo),
mchId: data.mchId || ''
}
})
} else {
// 无需确认,直接跳转到处理状态页
router.replace({
path: '/withdraw/processing-status',
query: {
status: 'TRANSFERING',
withdrawNo: data.withdrawNo || data.serialNo,
amount: data.amount.toFixed(2)
}
})
}
}
// 获取风控值
......
......@@ -169,7 +169,15 @@ export default defineComponent({
}
const data = await withdraw(params)
context.emit('update:show', false)
context.emit('withdrawSuccess', data)
// 新版流程:判断是否有 packageInfo
if (data.packageInfo) {
// 跳转到确认收款页
context.emit('withdrawSuccess', data)
} else {
// 无需确认,直接跳转到处理状态页
context.emit('withdrawSuccess', data)
}
} catch (err: any) {
Toast(err)
} finally {
......
<template>
<div class="container">
<div class="info-card">
<span class="label">提现金额</span>
<span class="value amount">¥ {{ amount }}</span>
<div class="confirm-page">
<!-- 加载中 -->
<div class="loading" v-if="loading">
<span>加载中...</span>
</div>
<div class="info-card">
<div class="info-item">
<span class="label">收款账户</span>
<span class="value">{{ accountInfo.name }} ({{ accountInfo.bank }})</span>
</div>
<div class="info-item">
<span class="label">账户类型</span>
<span class="value">{{ accountInfo.type }}</span>
<template v-else>
<div class="confirm-icon">💰</div>
<div class="confirm-title">提现申请已提交</div>
<div class="confirm-amount">¥{{ amount }}</div>
<div class="confirm-card">
<p>请在微信中确认收款</p>
<p>转账金额将在您确认后实时到账微信零钱</p>
<p class="to-account" v-if="withdrawAccount">提现至:{{ withdrawAccount }}</p>
<p class="timeout-hint">⏰ 请在24小时内确认,超时将自动退回</p>
</div>
</div>
<button class="confirm-button" @click="handleConfirm">确认提现</button>
<button class="btn-confirm" @click="handleConfirm">👆 确认收款</button>
<button class="btn-back" @click="handleBack">返回奖励金首页</button>
<div class="footer-tip">
点击确认即表示您同意XXXX协议
</div>
<div class="confirm-faq">
<span class="faq-icon">?</span>
<span>点击后没反应?请更新微信至最新版本</span>
</div>
</template>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { postWithdraw } from '@/server/api/withdrawService';
import { requestNativeMerchantTransfer } from '@/server/api/withdrawNativeService';
import { defineComponent } from 'vue'
import { getWithdrawPackageInfo } from '@/server/api/withdrawService'
export default defineComponent({
name: 'ConfirmReceipt',
data() {
data () {
return {
amount: '0.00',
accountInfo: {
name: '',
bank: '',
type: '',
},
};
withdrawNo: '',
withdrawAccount: '',
packageInfo: '',
mchId: '',
loading: true
}
},
created() {
// In H5, parameters would typically come from route query or state management
const query = this.$route.query;
this.amount = (query.amount as string) || '0.00';
try {
this.accountInfo = JSON.parse(decodeURIComponent((query.accountInfo as string) || '{}'));
} catch (e) {
console.error('Failed to parse accountInfo', e);
this.accountInfo = { name: '', bank: '', type: '' };
async created () {
const query = this.$route.query
this.amount = (query.amount as string) || '0.00'
this.withdrawNo = (query.withdrawNo as string) || ''
this.withdrawAccount = query.withdrawAccount ? decodeURIComponent(query.withdrawAccount as string) : ''
if (query.packageInfo) {
// 场景1:从提现表单页进入,已有 packageInfo
this.packageInfo = decodeURIComponent(query.packageInfo as string)
this.mchId = (query.mchId as string) || ''
this.loading = false
} else if (this.withdrawNo) {
// 场景2:从列表页进入,需要查询 packageInfo
await this.fetchPackageInfo()
} else {
this.loading = false
}
// H5 specific compatibility check or logic can go here if needed
// For now, we assume canUseMerchantTransfer is true for H5 context unless specific platform bridges are identified.
},
methods: {
async handleConfirm() {
async fetchPackageInfo () {
try {
// const withdrawRes = await postWithdraw({
// amount: this.amount,
// accountInfo: this.accountInfo,
// });
// Placeholder for H5 specific payment logic
// This is where the "三端确认收款适配" (three-end confirm receipt adaptation) logic would reside.
// For H5 embedded in App, this might involve calling a JSBridge.
// For Official Account H5, this might involve redirecting to WeChat Pay H5.
// Since specifics are not provided, this will be a generic placeholder.
const withdrawRes = await postWithdraw({
amount: this.amount,
accountInfo: this.accountInfo,
});
if (withdrawRes.code === 0 && withdrawRes.data) {
const { orderId, packageInfo } = withdrawRes.data;
if (packageInfo) {
console.log('Processing packageInfo for H5 payment via JSBridge...', packageInfo);
try {
const nativeTransferRes = await requestNativeMerchantTransfer(packageInfo);
if (nativeTransferRes.errMsg === 'requestMerchantTransfer:ok') {
this.$router.replace({
path: '/withdraw/processing-status',
query: { status: 'WAIT_USER_CONFIRM', orderId: orderId },
});
} else {
alert(nativeTransferRes.errMsg || '用户取消或提现失败');
}
} catch (nativeError) {
console.error('Native transfer request error:', nativeError);
alert((nativeError as Error).message || 'Native transfer failed, please retry.');
}
} else {
// Direct to processing status if no further payment step needed
this.$router.replace({
path: '/withdraw/processing-status',
query: { status: 'PROCESSING', orderId: orderId },
});
}
console.log('fetchPackageInfo called, withdrawNo:', this.withdrawNo)
const res = await getWithdrawPackageInfo(this.withdrawNo)
console.log('packageInfo response:', JSON.stringify(res))
if (res) {
this.packageInfo = res.packageInfo || ''
this.mchId = res.mchId || ''
console.log('packageInfo:', this.packageInfo, 'mchId:', this.mchId)
} else {
// Handle backend API error
// this.$toast.fail(withdrawRes.message || '提现请求失败');
alert(withdrawRes.message || '提现请求失败'); // Generic alert
console.log('no data in response')
alert('获取提现信息失败')
}
} catch (error) {
console.error('Withdrawal request error:', error);
// this.$toast.fail(error.message || '网络请求失败,请稍后重试');
alert(error.message || '网络请求失败,请稍后重试'); // Generic alert
console.error('fetchPackageInfo error:', error)
alert('网络请求失败: ' + error)
} finally {
// Hide loading indicator
// this.$toast.clear();
this.loading = false
}
},
},
});
async handleConfirm () {
// H5 唤起用户确认收款弹窗 - 使用 alert 模拟
alert('H5确认收款功能:packageInfo=' + this.packageInfo + ', mchId=' + this.mchId)
// 模拟确认成功,跳转到处理状态页面
this.$router.replace({
path: '/withdraw/processing-status',
query: {
status: 'WAIT_CONFIRM',
withdrawNo: this.withdrawNo,
amount: this.amount
}
})
},
handleBack () {
this.$router.replace({ path: '/' })
}
}
})
</script>
<style scoped>
.container {
padding: 4vw; /* 30rpx = 4vw (30 * 0.1333) */
background-color: #f8f8f8;
.confirm-page {
display: flex;
flex-direction: column;
align-items: center;
padding: 12vw 4vw;
text-align: center;
background: #ffffff;
min-height: 100vh;
box-sizing: border-box;
}
.info-card {
background-color: #ffffff;
border-radius: 2.133vw; /* 16rpx */
padding: 4vw; /* 30rpx */
margin-bottom: 2.666vw; /* 20rpx */
box-shadow: 0 0.266vw 1.333vw rgba(0, 0, 0, 0.05); /* 0 2rpx 10rpx */
.loading {
display: flex;
align-items: center;
justify-content: center;
min-height: 50vh;
color: #999;
font-size: 4vw;
}
.info-card .label {
font-size: 3.733vw; /* 28rpx */
color: #888888;
margin-right: 2.666vw; /* 20rpx */
.confirm-icon {
font-size: 10vw;
margin-bottom: 4vw;
}
.info-card .value {
font-size: 3.733vw; /* 28rpx */
color: #333333;
.confirm-title {
font-size: 5vw;
font-weight: 600;
color: #212121;
margin-bottom: 1vw;
}
.info-card .amount {
font-size: 6.4vw; /* 48rpx */
font-weight: bold;
color: #333333;
display: block;
text-align: center;
margin-top: 2.666vw; /* 20rpx */
.confirm-amount {
font-size: 9vw;
font-weight: 700;
color: #212121;
margin-bottom: 8vw;
letter-spacing: -0.02em;
}
.info-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1.333vw 0; /* 10rpx */
.confirm-card {
width: 100%;
background: #f5f5f5;
border-radius: 3vw;
padding: 4vw;
margin-bottom: 4vw;
box-sizing: border-box;
text-align: left;
}
.confirm-card p {
font-size: 3.5vw;
color: #616161;
line-height: 1.8;
margin: 0;
}
.confirm-card .to-account {
font-size: 3.2vw;
color: #9e9e9e;
margin-top: 2vw;
}
.info-item + .info-item {
border-top: 0.133vw solid #eee; /* 1rpx */
margin-top: 1.333vw; /* 10rpx */
padding-top: 2.666vw; /* 20rpx */
.confirm-card .timeout-hint {
color: #fa8c16;
font-weight: 500;
margin-top: 2vw;
}
.confirm-button {
.btn-confirm {
width: 100%;
height: 12vw; /* 90rpx */
line-height: 12vw; /* 90rpx */
background-color: #07c160;
color: #ffffff;
font-size: 4.533vw; /* 34rpx */
border-radius: 6vw; /* 45rpx */
margin-top: 5.333vw; /* 40rpx */
border: none; /* Add border none for button */
padding: 4.5vw;
background: linear-gradient(135deg, #07c160 0%, #38cd7f 100%);
color: white;
border: none;
border-radius: 3vw;
font-size: 4vw;
font-weight: 600;
margin-bottom: 3vw;
box-sizing: border-box;
cursor: pointer;
}
.footer-tip {
text-align: center;
font-size: 3.2vw; /* 24rpx */
color: #aaaaaa;
margin-top: 4vw; /* 30rpx */
.btn-back {
width: 100%;
padding: 3.5vw;
background: #f5f5f5;
color: #757575;
border: none;
border-radius: 3vw;
font-size: 3.5vw;
font-weight: 500;
box-sizing: border-box;
cursor: pointer;
}
.confirm-faq {
width: 100%;
text-align: left;
margin-top: 4vw;
font-size: 3vw;
color: #9e9e9e;
display: flex;
align-items: center;
gap: 1vw;
}
.confirm-faq .faq-icon {
width: 4vw;
height: 4vw;
background: #fa8c16;
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 2.5vw;
font-weight: bold;
}
</style>
\ No newline at end of file
</style>
<template>
<div class="container">
<img class="status-icon" :src="icon" mode="aspectFit" alt="Status Icon" />
<p class="status-text" :class="statusClass">{{ statusText }}</p>
<div class="detail-card" v-if="orderId">
<div class="detail-item">
<span class="label">订单号</span>
<span class="value">{{ orderId }}</span>
</div>
<div class="detail-item">
<span class="label">当前状态</span>
<span class="value">{{ status }}</span>
</div>
<div class="processing-page">
<!-- Spinner -->
<div class="spinner" v-if="!isFinalStatus"></div>
<!-- 标题 -->
<div class="processing-title">
{{ getTitleText }}
</div>
<button v-if="statusMap[status] && statusMap[status].action" class="action-button" @click="handleAction">
{{ statusMap[status].action === 'confirm' ? '去确认收款' : '重新提现' }}
</button>
<!-- 金额 -->
<div class="processing-amount">¥{{ amount }}</div>
<!-- 卡片 -->
<div class="processing-card">
<template v-if="isFinalStatus">
<template v-if="status === 'RECEIVED'">
<p>提现金额已到账微信零钱</p>
<p class="to-account">感谢您的使用</p>
</template>
<template v-else>
<p class="fail-text">{{ failReason || '提现失败' }}</p>
<p class="to-account">奖励金已退回账户余额</p>
</template>
</template>
<template v-else>
<p>您已确认收款</p>
<p>资金正在转入微信零钱,请稍候...</p>
<div class="progress-bar">
<div class="progress-fill"></div>
</div>
</template>
</div>
<div class="footer-tip">
如有疑问,请联系客服
<!-- 提示 -->
<div class="processing-hint" v-if="!isFinalStatus">
自动查询状态中,请勿关闭
</div>
<!-- 按钮 -->
<button class="btn-back" @click="handleBackHome">返回首页</button>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { queryWithdrawStatus } from '@/server/api/withdrawService';
interface StatusConfig {
text: string;
icon: string;
action?: 'confirm' | 'retry';
}
interface StatusMap {
[key: string]: StatusConfig;
}
import { defineComponent } from 'vue'
import { queryWithdrawStatus } from '@/server/api/withdrawService'
export default defineComponent({
name: 'ProcessingStatus',
data() {
data () {
return {
status: 'PROCESSING', // PROCESSING, SUCCESS, FAIL, etc.
statusText: '提现处理中...',
icon: '/assets/images/processing.png', // Placeholder for actual image path
orderId: '',
status: 'TRANSFERING',
withdrawNo: '',
amount: '0.00',
failReason: '',
packageInfo: '',
mchId: '',
pollingInterval: null as ReturnType<typeof setInterval> | null,
pollingCount: 0,
maxPollingAttempts: 10,
statusMap: {
'ACCEPTED': { text: '提现处理中...', icon: '/assets/images/processing.png' },
'PROCESSING': { text: '提现处理中...', icon: '/assets/images/processing.png' },
'WAIT_USER_CONFIRM': { text: '提现处理中,待用户确认收款', icon: '/assets/images/processing.png', action: 'confirm' },
'TRANSFERING': { text: '转账处理中...', icon: '/assets/images/processing.png' },
'SUCCESS': { text: '提现成功', icon: '/assets/images/success.png' },
'FAILED': { text: '提现失败', icon: '/assets/images/fail.png', action: 'retry' },
'CANCELING': { text: '转账撤销中...', icon: '/assets/images/processing.png' },
'CANCELLED': { text: '转账已撤销', icon: '/assets/images/fail.png', action: 'retry' },
'UNKNOWN': { text: '状态未知,请稍后查询', icon: '/assets/images/processing.png' },
} as StatusMap,
};
maxPollingAttempts: 10
}
},
created() {
const query = this.$route.query;
this.orderId = (query.orderId as string) || '';
this.status = (query.status as string) || 'PROCESSING';
this.updateStatusDisplay(this.status);
computed: {
isFinalStatus (): boolean {
return ['RECEIVED', 'FAILED', 'CANCELLED'].includes(this.status)
},
getTitleText (): string {
if (this.isFinalStatus) {
return this.status === 'RECEIVED' ? '提现成功' : '提现失败'
}
return '提现处理中'
}
},
mounted() {
this.startPolling();
created () {
const query = this.$route.query
this.withdrawNo = (query.withdrawNo as string) || ''
this.amount = (query.amount as string) || '0.00'
this.status = (query.status as string) || 'TRANSFERING'
this.packageInfo = query.packageInfo ? decodeURIComponent(query.packageInfo as string) : ''
this.mchId = (query.mchId as string) || ''
},
beforeUnmount() {
this.stopPolling();
mounted () {
this.startPolling()
},
beforeUnmount () {
this.stopPolling()
},
methods: {
updateStatusDisplay(statusCode: string) {
const displayStatus = this.statusMap[statusCode] || this.statusMap['UNKNOWN'];
this.statusText = displayStatus.text;
// Assuming image assets are in `/public/assets/images/` or handled by webpack aliasing
// For now, use relative path or direct path if assets are served from root
this.icon = displayStatus.icon.replace('/assets/images/', '/img/'); // Adjust path based on H5 asset structure
},
startPolling() {
this.stopPolling(); // Ensure no duplicate intervals
startPolling () {
this.stopPolling()
this.pollingInterval = setInterval(async () => {
this.pollingCount++;
this.pollingCount++
if (this.pollingCount > this.maxPollingAttempts) {
this.stopPolling();
console.warn('Max polling attempts reached. Stopping polling.');
this.updateStatusDisplay('UNKNOWN');
return;
this.stopPolling()
console.warn('Max polling attempts reached.')
return
}
await this.queryTransferStatus();
}, 5000); // Poll every 5 seconds
await this.queryWithdrawStatus()
}, 5000)
},
stopPolling() {
stopPolling () {
if (this.pollingInterval) {
clearInterval(this.pollingInterval);
this.pollingInterval = null;
clearInterval(this.pollingInterval)
this.pollingInterval = null
}
},
async queryTransferStatus() {
if (!this.orderId) {
console.error('No orderId available for status query.');
this.stopPolling();
return;
async queryWithdrawStatus () {
if (!this.withdrawNo) {
console.error('No withdrawNo available.')
this.stopPolling()
return
}
console.log(`Polling status for orderId: ${this.orderId}, attempt: ${this.pollingCount}`);
console.log('Polling status for withdrawNo:', this.withdrawNo, 'attempt:', this.pollingCount)
try {
// const res = await queryWithdrawStatus(this.orderId);
const res = await queryWithdrawStatus(this.orderId);
if (res.code === 0 && res.data && res.data.state) {
const newStatus = res.data.state;
this.status = newStatus;
this.updateStatusDisplay(newStatus);
if (['SUCCESS', 'FAILED', 'CANCELLED'].includes(newStatus)) {
this.stopPolling();
const res = await queryWithdrawStatus(this.withdrawNo)
if (res && res.withdrawStatus) {
const newStatus = res.withdrawStatus
this.status = newStatus
if (res.amount) {
this.amount = res.amount
}
if (res.failReason) {
this.failReason = res.failReason
}
if (['RECEIVED', 'FAILED', 'CANCELLED'].includes(newStatus)) {
this.stopPolling()
}
} else {
console.error('Failed to query transfer status:', res.message || 'Unknown error');
}
} catch (error) {
console.error('Error querying transfer status:', error);
}
},
handleAction() {
const currentAction = this.statusMap[this.status]?.action;
if (currentAction === 'confirm') {
// Navigate back to confirm page
this.$router.replace({ path: '/withdraw/confirm-receipt', query: { ...this.$route.query } });
} else if (currentAction === 'retry') {
// Navigate to withdrawal initiation page (placeholder)
this.$router.replace({ path: '/withdraw/initiate-withdrawal' });
}
},
},
computed: {
statusClass(): string {
const currentStatus = this.status.toLowerCase();
if (['accepted', 'processing', 'transfering', 'unknown'].includes(currentStatus)) {
return 'status-processing';
} else if (currentStatus === 'wait_user_confirm') {
return 'status-wait-confirm';
} else if (currentStatus === 'success') {
return 'status-success';
} else if (['failed', 'cancelled'].includes(currentStatus)) {
return 'status-failed';
console.error('Error querying status:', error)
}
return '';
},
},
});
handleBackHome () {
this.$router.replace({ path: '/' })
}
}
})
</script>
<style scoped>
.container {
/* P3b 处理中页样式 - 基于 features/withdraw/prd/frontend-design/index.html */
.processing-page {
display: flex;
flex-direction: column;
align-items: center;
padding: 8vw 4vw; /* 60rpx 30rpx */
background-color: #f8f8f8;
padding: 12vw 4vw;
text-align: center;
background: #ffffff;
min-height: 100vh;
box-sizing: border-box;
}
.status-icon {
width: 21.333vw; /* 160rpx */
height: 21.333vw; /* 160rpx */
margin-bottom: 5.333vw; /* 40rpx */
.spinner {
width: 14vw;
height: 14vw;
border: 1vw solid #eeeeee;
border-top-color: #07c160;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-bottom: 6vw;
}
.status-text {
font-size: 5.066vw; /* 38rpx */
font-weight: bold;
color: #333333;
margin-bottom: 8vw; /* 60rpx */
text-align: center;
@keyframes spin {
to { transform: rotate(360deg); }
}
.status-text.status-processing {
color: #1989fa; /* Blue for processing */
.processing-title {
font-size: 5vw;
font-weight: 600;
color: #212121;
margin-bottom: 1vw;
}
.status-text.status-wait-confirm {
color: #ff976a; /* Orange for waiting confirmation */
.processing-amount {
font-size: 9vw;
font-weight: 700;
color: #212121;
margin-bottom: 8vw;
letter-spacing: -0.02em;
}
.status-text.status-success {
color: #07c160; /* Green for success */
.processing-card {
width: 100%;
background: #fafafa;
border-radius: 3vw;
padding: 6vw;
margin-bottom: 6vw;
box-sizing: border-box;
}
.status-text.status-failed {
color: #ee0a24; /* Red for failed/cancelled */
.processing-card p {
font-size: 3.5vw;
color: #616161;
line-height: 1.8;
margin: 0;
}
.detail-card {
background-color: #ffffff;
border-radius: 2.133vw; /* 16rpx */
padding: 4vw; /* 30rpx */
width: 100%;
max-width: 80vw; /* Approx 600rpx */
box-shadow: 0 0.266vw 1.333vw rgba(0, 0, 0, 0.05); /* 0 2rpx 10rpx */
margin-bottom: 8vw; /* 60rpx */
.processing-card .to-account {
font-size: 3.2vw;
color: #9e9e9e;
margin-top: 2vw;
}
.detail-item {
.processing-card .fail-text {
color: #ff4d4f;
font-weight: 500;
}
.progress-bar {
height: 1.5vw;
background: #eeeeee;
border-radius: 9999px;
margin-top: 4vw;
overflow: hidden;
}
.progress-fill {
height: 100%;
width: 30%;
background: linear-gradient(90deg, #07c160, #38cd7f);
border-radius: 9999px;
animation: progress 2s ease-in-out infinite;
}
@keyframes progress {
0% { transform: translateX(0); width: 30%; }
50% { width: 70%; }
100% { transform: translateX(200%); width: 30%; }
}
.processing-hint {
font-size: 3vw;
color: #9e9e9e;
margin-bottom: 6vw;
display: flex;
justify-content: space-between;
padding: 1.333vw 0; /* 10rpx */
font-size: 3.733vw; /* 28rpx */
color: #555555;
align-items: center;
justify-content: center;
gap: 1vw;
}
.detail-item + .detail-item {
border-top: 0.133vw solid #eee; /* 1rpx */
margin-top: 1.333vw; /* 10rpx */
padding-top: 2.666vw; /* 20rpx */
.processing-hint::before {
content: '';
width: 1.5vw;
height: 1.5vw;
background: #07c160;
border-radius: 50%;
animation: pulse 1s ease-in-out infinite;
}
.detail-item .label {
color: #888888;
@keyframes pulse {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.5; transform: scale(1.2); }
}
.action-button {
.btn-back {
width: 100%;
max-width: 80vw; /* Approx 600rpx */
height: 12vw; /* 90rpx */
line-height: 12vw; /* 90rpx */
background-color: #07c160;
color: #ffffff;
font-size: 4.533vw; /* 34rpx */
border-radius: 6vw; /* 45rpx */
margin-top: 5.333vw; /* 40rpx */
border: none; /* Add border none for button */
}
.footer-tip {
text-align: center;
font-size: 3.2vw; /* 24rpx */
color: #aaaaaa;
margin-top: 8vw; /* 60rpx */
padding: 3.5vw;
background: #f5f5f5;
color: #757575;
border: none;
border-radius: 3vw;
font-size: 3.5vw;
font-weight: 500;
box-sizing: border-box;
cursor: pointer;
}
</style>
\ No newline at end of file
</style>
import { mount, flushPromises } from '@vue/test-utils';
import { mount } from '@vue/test-utils';
import ConfirmReceipt from '../ConfirmReceipt.vue';
import { postWithdraw } from '@/server/api/withdrawService';
import { requestNativeMerchantTransfer } from '@/server/api/withdrawNativeService';
// Mock vue-router
const mockRouter = {
......@@ -10,13 +8,13 @@ const mockRouter = {
const mockRoute = {
query: {
amount: '100.00',
accountInfo: encodeURIComponent(JSON.stringify({ name: 'Test User', bank: 'Test Bank', type: 'Debit' })),
withdrawNo: 'WD123456',
withdrawAccount: encodeURIComponent('微信用户'),
packageInfo: encodeURIComponent('test_package'),
mchId: 'test_mch_id',
},
};
jest.mock('@/server/api/withdrawService');
jest.mock('@/server/api/withdrawNativeService');
describe('ConfirmReceipt.vue', () => {
beforeEach(() => {
jest.clearAllMocks();
......@@ -32,16 +30,12 @@ describe('ConfirmReceipt.vue', () => {
},
});
expect(wrapper.find('.amount').text()).toBe('¥ 100.00');
expect(wrapper.findAll('.info-item .value')[0].text()).toBe('Test User (Test Bank)');
expect(wrapper.findAll('.info-item .value')[1].text()).toBe('Debit');
expect(wrapper.find('.confirm-amount').text()).toBe('¥100.00');
expect(wrapper.find('.confirm-title').text()).toBe('提现申请已提交');
});
it('calls postWithdraw and redirects to processing status on success without packageInfo', async () => {
(postWithdraw as jest.Mock).mockResolvedValueOnce({
code: 0,
data: { orderId: 'ORDER123', packageInfo: null },
});
it('shows alert and navigates to processing-status on confirm click', () => {
const alertSpy = jest.spyOn(window, 'alert').mockImplementation(() => {});
const wrapper = mount(ConfirmReceipt, {
global: {
......@@ -52,96 +46,22 @@ describe('ConfirmReceipt.vue', () => {
},
});
wrapper.find('.confirm-button').trigger('click');
await flushPromises();
wrapper.find('.btn-confirm').trigger('click');
expect(postWithdraw).toHaveBeenCalledTimes(1);
expect(postWithdraw).toHaveBeenCalledWith({
amount: '100.00',
accountInfo: { name: 'Test User', bank: 'Test Bank', type: 'Debit' },
});
expect(mockRouter.replace).toHaveBeenCalledTimes(1);
expect(alertSpy).toHaveBeenCalled();
expect(mockRouter.replace).toHaveBeenCalledWith({
path: '/withdraw/processing-status',
query: { status: 'PROCESSING', orderId: 'ORDER123' },
});
});
it('calls postWithdraw, then requestNativeMerchantTransfer, and redirects to processing status with WAIT_USER_CONFIRM if packageInfo is present and native call succeeds', async () => {
(postWithdraw as jest.Mock).mockResolvedValueOnce({
code: 0,
data: { orderId: 'ORDER456', packageInfo: 'some_package_info_string' },
});
(requestNativeMerchantTransfer as jest.Mock).mockResolvedValueOnce({
errMsg: 'requestMerchantTransfer:ok',
});
const wrapper = mount(ConfirmReceipt, {
global: {
mocks: {
$route: mockRoute,
$router: mockRouter,
},
query: {
status: 'WAIT_CONFIRM',
withdrawNo: 'WD123456',
amount: '100.00',
},
});
wrapper.find('.confirm-button').trigger('click');
await flushPromises();
expect(postWithdraw).toHaveBeenCalledTimes(1);
expect(postWithdraw).toHaveBeenCalledWith({
amount: '100.00',
accountInfo: { name: 'Test User', bank: 'Test Bank', type: 'Debit' },
});
expect(requestNativeMerchantTransfer).toHaveBeenCalledTimes(1);
expect(requestNativeMerchantTransfer).toHaveBeenCalledWith('some_package_info_string');
expect(mockRouter.replace).toHaveBeenCalledTimes(1);
expect(mockRouter.replace).toHaveBeenCalledWith({
path: '/withdraw/processing-status',
query: { status: 'WAIT_USER_CONFIRM', orderId: 'ORDER456' },
});
});
it('handles native transfer error when packageInfo is present', async () => {
(postWithdraw as jest.Mock).mockResolvedValueOnce({
code: 0,
data: { orderId: 'ORDER789', packageInfo: 'some_package_info_string' },
});
(requestNativeMerchantTransfer as jest.Mock).mockRejectedValueOnce(new Error('Native transfer error'));
const alertSpy = jest.spyOn(window, 'alert').mockImplementation(() => {});
const wrapper = mount(ConfirmReceipt, {
global: {
mocks: {
$route: mockRoute,
$router: mockRouter,
},
},
});
wrapper.find('.confirm-button').trigger('click');
await flushPromises();
expect(postWithdraw).toHaveBeenCalledTimes(1);
expect(requestNativeMerchantTransfer).toHaveBeenCalledTimes(1);
expect(alertSpy).toHaveBeenCalledWith('Native transfer error');
expect(mockRouter.replace).not.toHaveBeenCalled();
alertSpy.mockRestore();
});
it('handles native transfer cancellation/failure when packageInfo is present', async () => {
(postWithdraw as jest.Mock).mockResolvedValueOnce({
code: 0,
data: { orderId: 'ORDER901', packageInfo: 'some_package_info_string' },
});
(requestNativeMerchantTransfer as jest.Mock).mockResolvedValueOnce({
errMsg: 'requestMerchantTransfer:fail user cancel',
});
const alertSpy = jest.spyOn(window, 'alert').mockImplementation(() => {});
it('navigates back on back button click', () => {
const wrapper = mount(ConfirmReceipt, {
global: {
mocks: {
......@@ -151,14 +71,10 @@ describe('ConfirmReceipt.vue', () => {
},
});
wrapper.find('.confirm-button').trigger('click');
await flushPromises();
expect(postWithdraw).toHaveBeenCalledTimes(1);
expect(requestNativeMerchantTransfer).toHaveBeenCalledTimes(1);
expect(alertSpy).toHaveBeenCalledWith('requestMerchantTransfer:fail user cancel');
expect(mockRouter.replace).not.toHaveBeenCalled();
wrapper.find('.btn-back').trigger('click');
alertSpy.mockRestore();
expect(mockRouter.replace).toHaveBeenCalledWith({
path: '/bonus/withdraw',
});
});
});
......@@ -8,8 +8,9 @@ const mockRouter = {
};
const mockRoute = {
query: {
orderId: 'ORDER789',
status: 'PROCESSING',
withdrawNo: 'WD123456',
amount: '100.00',
status: 'TRANSFERING',
},
};
......@@ -21,7 +22,7 @@ describe('ProcessingStatus.vue', () => {
beforeEach(() => {
jest.clearAllMocks();
setIntervalSpy = jest.spyOn(window, 'setInterval').mockReturnValue(123 as any); // Mock interval ID
setIntervalSpy = jest.spyOn(window, 'setInterval').mockReturnValue(123 as any);
clearIntervalSpy = jest.spyOn(window, 'clearInterval');
});
......@@ -30,7 +31,7 @@ describe('ProcessingStatus.vue', () => {
clearIntervalSpy.mockRestore();
});
it('renders correctly with initial data and starts polling', () => {
it('renders correctly with initial data', () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
......@@ -40,59 +41,41 @@ describe('ProcessingStatus.vue', () => {
},
});
expect(wrapper.find('.status-text').text()).toBe('提现处理中...');
expect(wrapper.find('.detail-item .value').text()).toBe('ORDER789');
expect(setIntervalSpy).toHaveBeenCalledTimes(1);
expect(clearIntervalSpy).toHaveBeenCalledTimes(0); // No clearInterval on initial mount as pollingInterval is null
expect(wrapper.find('.processing-title').text()).toBe('提现处理中');
expect(wrapper.find('.processing-amount').text()).toBe('¥100.00');
expect(wrapper.find('.spinner').exists()).toBe(true);
});
it('stops polling on unmount', () => {
it('shows success state without spinner', () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
$route: mockRoute,
$route: { query: { withdrawNo: 'WD123456', amount: '100.00', status: 'RECEIVED' } },
$router: mockRouter,
},
},
});
wrapper.unmount();
expect(clearIntervalSpy).toHaveBeenCalledTimes(1); // One from unmount
expect(clearIntervalSpy).toHaveBeenCalledWith(123);
expect(wrapper.find('.processing-title').text()).toBe('提现成功');
expect(wrapper.find('.spinner').exists()).toBe(false);
});
it('updates status display based on API response and stops polling on success', async () => {
(queryWithdrawStatus as jest.Mock).mockResolvedValueOnce({
code: 0,
data: { state: 'SUCCESS' },
});
it('shows failed state without spinner', () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
$route: mockRoute,
$route: { query: { withdrawNo: 'WD123456', amount: '100.00', status: 'FAILED' } },
$router: mockRouter,
},
},
});
// Manually trigger polling interval logic
// The setInterval is mocked, so we need to manually call the handler
await (wrapper.vm as any).queryTransferStatus();
await flushPromises();
expect(wrapper.find('.status-text').text()).toBe('提现成功');
expect(wrapper.vm.status).toBe('SUCCESS');
expect(clearIntervalSpy).toHaveBeenCalledTimes(1); // One after success
expect(wrapper.find('.processing-title').text()).toBe('提现失败');
expect(wrapper.find('.spinner').exists()).toBe(false);
});
it('updates status display based on API response and stops polling on failed', async () => {
(queryWithdrawStatus as jest.Mock).mockResolvedValueOnce({
code: 0,
data: { state: 'FAILED' },
});
const wrapper = mount(ProcessingStatus, {
it('starts polling on mount', () => {
mount(ProcessingStatus, {
global: {
mocks: {
$route: mockRoute,
......@@ -101,119 +84,28 @@ describe('ProcessingStatus.vue', () => {
},
});
await (wrapper.vm as any).queryTransferStatus();
await flushPromises();
expect(wrapper.find('.status-text').text()).toBe('提现失败');
expect(wrapper.vm.status).toBe('FAILED');
expect(clearIntervalSpy).toHaveBeenCalledTimes(1); // One after failed
});
it('applies "status-processing" class for PROCESSING status', () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
$route: { query: { orderId: 'ORDER789', status: 'PROCESSING' } },
$router: mockRouter,
},
},
});
expect(wrapper.find('.status-text').classes()).toContain('status-processing');
});
it('applies "status-wait-confirm" class for WAIT_USER_CONFIRM status', () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
$route: { query: { orderId: 'ORDER789', status: 'WAIT_USER_CONFIRM' } },
$router: mockRouter,
},
},
});
expect(wrapper.find('.status-text').classes()).toContain('status-wait-confirm');
});
it('applies "status-success" class for SUCCESS status', () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
$route: { query: { orderId: 'ORDER789', status: 'SUCCESS' } },
$router: mockRouter,
},
},
});
expect(wrapper.find('.status-text').classes()).toContain('status-success');
});
it('applies "status-failed" class for FAILED status', () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
$route: { query: { orderId: 'ORDER789', status: 'FAILED' } },
$router: mockRouter,
},
},
});
expect(wrapper.find('.status-text').classes()).toContain('status-failed');
});
it('applies "status-failed" class for CANCELLED status', () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
$route: { query: { orderId: 'ORDER789', status: 'CANCELLED' } },
$router: mockRouter,
},
},
});
expect(wrapper.find('.status-text').classes()).toContain('status-failed');
expect(setIntervalSpy).toHaveBeenCalledTimes(1);
});
it('redirects to confirm-receipt on handleAction when status is WAIT_USER_CONFIRM', async () => {
it('stops polling on unmount', () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
$route: { query: { orderId: 'ORDER789', status: 'WAIT_USER_CONFIRM' } },
$route: mockRoute,
$router: mockRouter,
},
},
});
await wrapper.vm.$nextTick(); // Wait for data to be set up
wrapper.find('.action-button').trigger('click');
await flushPromises();
expect(mockRouter.replace).toHaveBeenCalledTimes(1);
expect(mockRouter.replace).toHaveBeenCalledWith({
path: '/withdraw/confirm-receipt',
query: { orderId: 'ORDER789', status: 'WAIT_USER_CONFIRM' },
});
wrapper.unmount();
expect(clearIntervalSpy).toHaveBeenCalled();
});
it('redirects to initiate-withdrawal on handleAction when status is FAILED (retry)', async () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
$route: { query: { orderId: 'ORDER789', status: 'FAILED' } },
$router: mockRouter,
},
},
});
await wrapper.vm.$nextTick(); // Wait for data to be set up
wrapper.find('.action-button').trigger('click');
await flushPromises();
expect(mockRouter.replace).toHaveBeenCalledTimes(1);
expect(mockRouter.replace).toHaveBeenCalledWith({
path: '/withdraw/initiate-withdrawal',
it('updates status on API response', async () => {
(queryWithdrawStatus as jest.Mock).mockResolvedValueOnce({
code: 0,
data: { withdrawStatus: 'RECEIVED', amount: '100.00' },
});
});
it('handles API error during polling', async () => {
(queryWithdrawStatus as jest.Mock).mockRejectedValueOnce(new Error('Network error during polling'));
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const wrapper = mount(ProcessingStatus, {
global: {
......@@ -224,25 +116,13 @@ describe('ProcessingStatus.vue', () => {
},
});
await (wrapper.vm as any).queryTransferStatus();
await (wrapper.vm as any).queryWithdrawStatus();
await flushPromises();
expect(consoleErrorSpy).toHaveBeenCalledWith('Error querying transfer status:', expect.any(Error));
expect(wrapper.vm.status).toBe('PROCESSING'); // Status should remain unchanged or go to UNKNOWN after max attempts
// Polling continues until max attempts or terminal state is reached
consoleErrorSpy.mockRestore();
expect(wrapper.vm.status).toBe('RECEIVED');
});
it('handles non-successful API response during polling', async () => {
(queryWithdrawStatus as jest.Mock).mockResolvedValueOnce({
code: 1, // Non-zero code
message: 'Transfer status query failed',
data: null,
});
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
it('navigates back to withdraw page on button click', () => {
const wrapper = mount(ProcessingStatus, {
global: {
mocks: {
......@@ -252,14 +132,10 @@ describe('ProcessingStatus.vue', () => {
},
});
await (wrapper.vm as any).queryTransferStatus();
await flushPromises();
expect(consoleErrorSpy).toHaveBeenCalledWith(
'Failed to query transfer status:', 'Transfer status query failed'
);
expect(wrapper.vm.status).toBe('PROCESSING'); // Status should remain unchanged
wrapper.find('.btn-back').trigger('click');
consoleErrorSpy.mockRestore();
expect(mockRouter.replace).toHaveBeenCalledWith({
path: '/bonus/withdraw',
});
});
});
......@@ -13,7 +13,7 @@ const { getPublicPath, Plugin: WebpackUploadAssetsPlugin } = createUploadAssetsP
console.log('upload assets to cdn', shouldUploadAssetsToCdn)
const proxyUrl = 'https://geek.jkwljy.com'
const proxyUrl = 'http://172.16.62.125'
const proxyOptions = {
target: proxyUrl,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment