Some checks failed
构建并部署前端到测试环境 / build-and-deploy (push) Has been cancelled
- 延期订单详情待支付时显示作废订单,作废后可重新办理延期 - 延期页有未完成订单时直接打开该订单详情;作废返回后重新查资格
160 lines
4.9 KiB
Vue
160 lines
4.9 KiB
Vue
<template>
|
|
<view class="container">
|
|
<view v-if="loading && !order" class="loading-state">
|
|
<up-loading-icon text="加载中" size="30"></up-loading-icon>
|
|
</view>
|
|
<view v-else-if="!order" class="card empty-card">未找到延期订单</view>
|
|
<template v-else>
|
|
<view class="card">
|
|
<view class="detail-header flex-row-sb">
|
|
<view class="detail-title">{{ order.package_name || '套餐沉默期延期' }}</view>
|
|
<view class="detail-status">{{ order.status_name || order.status }}</view>
|
|
</view>
|
|
<view v-for="row in rows" :key="row.label" class="detail-row flex-row-sb">
|
|
<text class="label">{{ row.label }}</text>
|
|
<text class="value" :class="row.className">{{ row.value }}</text>
|
|
</view>
|
|
</view>
|
|
<view v-if="canContinuePay" class="btn-apple btn-primary pay-btn" @tap="continuePay">继续支付</view>
|
|
<view v-if="canCancel" class="btn-apple btn-secondary cancel-btn" @tap="cancelOrder">
|
|
{{ cancelling ? '作废中...' : '作废订单' }}
|
|
</view>
|
|
</template>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed, ref } from 'vue';
|
|
import { onLoad, onShow } from '@dcloudio/uni-app';
|
|
import { packageSilenceApi } from '@/api/index.js';
|
|
import { formatDateTime, formatMoney } from '@/utils/display.js';
|
|
import { consumePendingPaymentRefresh } from '@/utils/payment.js';
|
|
import { formatSilenceDate, getSilenceErrorMessage, SILENCE_PAYMENT_LABELS } from '@/utils/silence.js';
|
|
import { openSilencePayment, SILENCE_REFRESH_TARGET } from '@/utils/silence-payment.js';
|
|
|
|
const orderId = ref(0);
|
|
const order = ref(null);
|
|
const loading = ref(false);
|
|
|
|
const rows = computed(() => {
|
|
const item = order.value || {};
|
|
return [
|
|
{ label: '订单号', value: item.order_no || '-' },
|
|
{ label: '输入天数', value: item.input_days ? `${item.input_days} 天` : '-' },
|
|
{ label: '计费 / 延长天数', value: item.extension_days ? `${item.extension_days} 天` : '-' },
|
|
{ label: '金额', value: `¥${formatMoney(item.amount)}`, className: 'amount' },
|
|
{ label: '支付方式', value: SILENCE_PAYMENT_LABELS[item.payment_method] || item.payment_method || '-' },
|
|
{ label: '原截止日期', value: formatSilenceDate(item.before_deadline_at) },
|
|
{ label: '延期后截止日期', value: formatSilenceDate(item.expected_deadline_at) },
|
|
{ label: '支付时间', value: formatDateTime(item.paid_at) },
|
|
{ label: '延期生效时间', value: formatDateTime(item.completed_at) },
|
|
{ label: '下单时间', value: formatDateTime(item.created_at) }
|
|
];
|
|
});
|
|
|
|
const canContinuePay = computed(() => order.value?.status === 'pending_payment' && !!order.value?.qr_content);
|
|
const canCancel = computed(() => order.value?.status === 'pending_payment');
|
|
const cancelling = ref(false);
|
|
|
|
const cancelOrder = () => {
|
|
if (cancelling.value || !order.value) return;
|
|
uni.showModal({
|
|
title: '作废延期订单',
|
|
content: '作废后该订单不能再支付,可以重新办理延期。确定作废吗?',
|
|
success: async (res) => {
|
|
if (!res.confirm) return;
|
|
cancelling.value = true;
|
|
try {
|
|
order.value = await packageSilenceApi.cancelOrder(order.value.id);
|
|
uni.showToast({ title: '已作废', icon: 'success' });
|
|
} catch (error) {
|
|
uni.showToast({ title: getSilenceErrorMessage(error, '作废失败,请稍后重试'), icon: 'none', duration: 2500 });
|
|
await load();
|
|
} finally {
|
|
cancelling.value = false;
|
|
}
|
|
}
|
|
});
|
|
};
|
|
|
|
const load = async () => {
|
|
if (!orderId.value) return;
|
|
loading.value = true;
|
|
try {
|
|
order.value = await packageSilenceApi.getOrder(orderId.value);
|
|
} catch (error) {
|
|
uni.showToast({ title: getSilenceErrorMessage(error, '加载订单失败'), icon: 'none' });
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
};
|
|
|
|
const continuePay = async () => {
|
|
try {
|
|
await openSilencePayment(order.value, SILENCE_REFRESH_TARGET.ORDER_DETAIL);
|
|
} catch (error) {
|
|
uni.showToast({ title: error?.message || '拉起支付失败', icon: 'none' });
|
|
}
|
|
};
|
|
|
|
onLoad((query) => {
|
|
orderId.value = Number(query?.id) || 0;
|
|
});
|
|
|
|
onShow(async () => {
|
|
const fromPayment = consumePendingPaymentRefresh(SILENCE_REFRESH_TARGET.ORDER_DETAIL);
|
|
await load();
|
|
if (fromPayment && order.value?.status === 'completed') {
|
|
uni.showToast({ title: '延期成功', icon: 'success' });
|
|
uni.setStorageSync('silence_extension_completed', Date.now());
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.loading-state {
|
|
display: flex;
|
|
justify-content: center;
|
|
padding: 200rpx 0;
|
|
}
|
|
|
|
.empty-card {
|
|
margin-top: 40rpx;
|
|
text-align: center;
|
|
color: var(--text-tertiary);
|
|
}
|
|
|
|
.detail-header {
|
|
margin-bottom: var(--space-md);
|
|
}
|
|
|
|
.detail-title {
|
|
font-size: 30rpx;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.detail-status {
|
|
font-size: 26rpx;
|
|
color: var(--primary-dark);
|
|
}
|
|
|
|
.detail-row {
|
|
padding: 10rpx 0;
|
|
font-size: 26rpx;
|
|
|
|
.label {
|
|
color: var(--text-tertiary);
|
|
}
|
|
|
|
.amount {
|
|
color: var(--danger);
|
|
}
|
|
}
|
|
|
|
.pay-btn,
|
|
.cancel-btn {
|
|
margin-top: 32rpx;
|
|
text-align: center;
|
|
}
|
|
</style>
|