Files
device-voice-h5/pages/silence-orders/detail.vue
邹进 d13be3580f
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 19m17s
feat: 延期微信支付在微信内直接拉起
- 微信支付下单带 app_type;拿到 pay_config 后与套餐购买一样拉起微信支付,继续支付同样处理
- 微信内打开时支付方式默认微信;取消支付保留同一请求号,再次确认不重复建单
2026-11-07 21:57:26 +09:00

161 lines
5.0 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 || !!order.value?.pay_config));
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 {
const result = await openSilencePayment(order.value, SILENCE_REFRESH_TARGET.ORDER_DETAIL);
if (result?.paid) await load();
} 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>