386 lines
9.8 KiB
Vue
386 lines
9.8 KiB
Vue
<script setup lang="ts">
|
||
import { computed, onMounted, ref } from 'vue'
|
||
import { storeToRefs } from 'pinia'
|
||
import { useRoute, useRouter } from 'vue-router'
|
||
import { ElMessage } from 'element-plus'
|
||
import { AppButton, QrCodePanel } from '@/components'
|
||
// 页面容器:数据只经 store,不直接 import api
|
||
import { useFinanceStore } from '@/stores/modules/finance'
|
||
import type { PayMethod } from '@/types/business/finance'
|
||
import { formatMoney } from '@/utils/format'
|
||
import PayMethodDialog from './cpns/PayMethodDialog.vue'
|
||
|
||
const route = useRoute()
|
||
const router = useRouter()
|
||
const financeStore = useFinanceStore()
|
||
const { payment, currentBill } = storeToRefs(financeStore)
|
||
|
||
const billId = computed(() => String(route.params.id))
|
||
|
||
const dialogVisible = ref(false)
|
||
|
||
const method = computed<PayMethod>(() => payment.value?.method ?? 'wechat')
|
||
|
||
const methodLabel = computed(() => (method.value === 'wechat' ? '微信支付' : '支付宝支付'))
|
||
|
||
const steps = computed<string[]>(() =>
|
||
method.value === 'wechat'
|
||
? [
|
||
'打开手机微信',
|
||
'扫描左侧二维码',
|
||
'输入支付密码完成支付,本页将自动跳转至支付结果页',
|
||
]
|
||
: [
|
||
'打开手机支付宝',
|
||
'对准屏幕上方的二维码进行扫描,核对金额后确认支付',
|
||
'输入支付密码完成支付',
|
||
],
|
||
)
|
||
|
||
function onRefresh(): void {
|
||
void financeStore.switchPaymentMethod(billId.value, method.value)
|
||
ElMessage.success('二维码已刷新')
|
||
}
|
||
|
||
function onConfirmMethod(next: PayMethod): void {
|
||
void financeStore.switchPaymentMethod(billId.value, next)
|
||
ElMessage.success('二维码已刷新')
|
||
}
|
||
|
||
async function onPaid(): Promise<void> {
|
||
await financeStore.createPayment(billId.value, method.value)
|
||
void router.push(`/finance/bills/${billId.value}/pay/result`)
|
||
}
|
||
|
||
onMounted(() => {
|
||
void Promise.all([
|
||
financeStore.createPayment(billId.value, 'wechat'),
|
||
financeStore.fetchDetail(billId.value),
|
||
])
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<div class="pay">
|
||
<nav class="pay__breadcrumb text-secondary">
|
||
<RouterLink to="/finance" class="link">
|
||
财务中心
|
||
</RouterLink>
|
||
<span> > </span>
|
||
<RouterLink to="/finance/bills" class="link">
|
||
账单明细
|
||
</RouterLink>
|
||
<span> > </span>
|
||
<span>扫码支付</span>
|
||
</nav>
|
||
|
||
<!-- 设计 33/34:单张大白卡——左(渠道说明 + 切换)/ 中(金额 + 二维码)/ 右(步骤 + 订单明细 + 安全提示) -->
|
||
<div class="pay__body card">
|
||
<section class="pay__left">
|
||
<div class="pay__left-top">
|
||
<p class="pay__method">
|
||
{{ methodLabel }} · 请使用手机微信 <strong>[扫一扫]</strong> 扫描下方二维码完成支付
|
||
</p>
|
||
<AppButton class="pay__switch" @click="dialogVisible = true">
|
||
切换支付方式
|
||
</AppButton>
|
||
</div>
|
||
|
||
<div class="pay__amount-block">
|
||
<p class="pay__amount-label text-secondary">
|
||
支付金额
|
||
</p>
|
||
<p class="pay__amount">¥{{ formatMoney(payment?.amount ?? currentBill?.amount ?? 0) }}</p>
|
||
</div>
|
||
|
||
<QrCodePanel
|
||
:expires-in="payment?.qrExpiresInSeconds ?? 300"
|
||
@refresh="onRefresh"
|
||
/>
|
||
</section>
|
||
|
||
<section class="pay__right">
|
||
<div class="pay__steps">
|
||
<h4 class="pay__sub-title">
|
||
扫码支付操作步骤
|
||
</h4>
|
||
<ol class="pay__step-list">
|
||
<li v-for="(step, index) in steps" :key="step" class="pay__step">
|
||
<span class="pay__step-index">{{ index + 1 }}</span>
|
||
<span>{{ step }}</span>
|
||
</li>
|
||
</ol>
|
||
</div>
|
||
|
||
<div class="pay__detail">
|
||
<h4 class="pay__sub-title">
|
||
订单明细
|
||
</h4>
|
||
<ul class="pay__detail-list">
|
||
<li class="pay__detail-item">
|
||
<span class="pay__detail-label text-secondary">账单号</span>
|
||
<span>{{ currentBill?.billNo ?? '—' }}</span>
|
||
</li>
|
||
<li class="pay__detail-item">
|
||
<span class="pay__detail-label text-secondary">关联项目</span>
|
||
<span>{{ currentBill?.projectName ?? '—' }}</span>
|
||
</li>
|
||
<li class="pay__detail-item">
|
||
<span class="pay__detail-label text-secondary">期数</span>
|
||
<span>{{ currentBill?.planName ?? '—' }}</span>
|
||
</li>
|
||
<li class="pay__detail-item">
|
||
<span class="pay__detail-label text-secondary">金额</span>
|
||
<span class="pay__detail-amount">¥{{ formatMoney(payment?.amount ?? currentBill?.amount ?? 0) }}</span>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
|
||
<p class="pay__safe">
|
||
安全提示:本页面已通过安全验证,请勿向他人泄露付款码
|
||
</p>
|
||
</section>
|
||
</div>
|
||
|
||
<!-- 设计 33:操作按钮在大卡右下方 -->
|
||
<div class="pay__footer">
|
||
<AppButton type="primary" size="lg" @click="onPaid">
|
||
完成支付
|
||
</AppButton>
|
||
<AppButton @click="router.push('/finance/bills')">
|
||
返回
|
||
</AppButton>
|
||
</div>
|
||
|
||
<PayMethodDialog
|
||
v-model:visible="dialogVisible"
|
||
:method="method"
|
||
@confirm="onConfirmMethod"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<style lang="less" scoped>
|
||
.pay {
|
||
width: 100%;
|
||
max-width: @container-width;
|
||
margin: 0 auto;
|
||
padding: @spacing-lg @spacing-base @spacing-xxl;
|
||
|
||
// 设计 33:面包屑 13 设计px → 11px,前缀灰、当前页深灰
|
||
&__breadcrumb {
|
||
margin-bottom: @spacing-base;
|
||
font-size: 11px;
|
||
color: @text-color-disabled;
|
||
|
||
> span:last-child {
|
||
color: @text-color;
|
||
}
|
||
}
|
||
|
||
// 设计 33:整页单张大白卡,左中右三区
|
||
&__body {
|
||
.flex(row, flex-start, flex-start);
|
||
gap: 24px;
|
||
padding: 24px 32px;
|
||
border-radius: @radius-base;
|
||
background: @white;
|
||
box-shadow: @shadow-base;
|
||
}
|
||
|
||
&__left {
|
||
.flex(column, center, center);
|
||
flex: 1;
|
||
min-width: 0;
|
||
gap: @spacing-base;
|
||
}
|
||
|
||
// 左区顶行:渠道说明靠左、切换支付方式胶囊靠右(设计 33 右上角)
|
||
&__left-top {
|
||
.flex(row, space-between, center);
|
||
align-self: stretch;
|
||
gap: @spacing-base;
|
||
}
|
||
|
||
&__method {
|
||
font-size: 12px;
|
||
color: @text-color;
|
||
|
||
strong {
|
||
color: @primary-strong;
|
||
}
|
||
}
|
||
|
||
&__switch {
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
:deep(.pay__switch.app-button--default) {
|
||
height: 24px;
|
||
padding: 0 10px;
|
||
border: 1px solid fade(@primary-strong, 30%);
|
||
background: fade(@primary-strong, 10%);
|
||
color: @primary-strong;
|
||
font-size: 11px;
|
||
|
||
&:hover {
|
||
border-color: @primary-strong;
|
||
background: fade(@primary-strong, 18%);
|
||
color: @primary-strong;
|
||
}
|
||
}
|
||
|
||
// 中区:支付金额标签 15 设计px → 12px,金额 34 设计px → 26px 粗体红
|
||
&__amount-block {
|
||
text-align: center;
|
||
}
|
||
|
||
&__amount-label {
|
||
font-size: 12px;
|
||
color: @text-color;
|
||
}
|
||
|
||
&__amount {
|
||
margin-top: 4px;
|
||
font-size: 26px;
|
||
font-weight: 700;
|
||
color: @danger-color;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
// 二维码占位(QrCodePanel 内部压成设计稿的灰色方块)
|
||
:deep(.qr-panel__box) {
|
||
border: none;
|
||
background: @contract-qr-bg;
|
||
border-radius: @radius-base;
|
||
}
|
||
|
||
// 倒计时行 → 浅红胶囊(设计 33「二维码将在 04:32 后失效」)
|
||
:deep(.qr-panel__status) {
|
||
font-size: 11px;
|
||
color: @danger-color;
|
||
background: fade(@danger-color, 8%);
|
||
border-radius: @radius-round;
|
||
padding: 5px 14px;
|
||
}
|
||
|
||
:deep(.qr-panel__count) {
|
||
color: @danger-color;
|
||
font-weight: 700;
|
||
}
|
||
|
||
// 右区:步骤 + 订单明细 + 安全提示(设计 33 右列 400 设计px ≈ 310px)
|
||
&__right {
|
||
flex: 0 0 310px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: @spacing-base;
|
||
}
|
||
|
||
&__sub-title {
|
||
margin-bottom: 12px;
|
||
font-size: 15px;
|
||
font-weight: 700;
|
||
color: @heading-color;
|
||
|
||
// 「订单明细」小节按设计 33 降为 13 设计px → 11px
|
||
}
|
||
|
||
&__detail &__sub-title {
|
||
font-size: 11px;
|
||
}
|
||
|
||
&__steps &__sub-title {
|
||
font-size: 15px;
|
||
}
|
||
|
||
// 三步指引:序号实底蓝圆 024FFF,步骤文字 14 设计px → 11px
|
||
&__step-list {
|
||
.flex(column, flex-start, stretch);
|
||
gap: 12px;
|
||
padding-left: 0;
|
||
list-style: none;
|
||
}
|
||
|
||
&__step {
|
||
.flex(row, flex-start, flex-start);
|
||
gap: @spacing-sm;
|
||
font-size: 11px;
|
||
line-height: 1.7;
|
||
color: @text-color;
|
||
}
|
||
|
||
&__step-index {
|
||
.flex(row, center);
|
||
width: 16px;
|
||
height: 16px;
|
||
margin-top: 1px;
|
||
border-radius: @radius-round;
|
||
background: @primary-strong;
|
||
color: @white;
|
||
font-size: 11px;
|
||
font-weight: 700;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
// 订单明细:浅灰底板 + 白底行卡(设计 33 实取 #F7F8F9 / #FFFFFF)
|
||
&__detail-list {
|
||
.flex(column, flex-start, stretch);
|
||
gap: 6px;
|
||
margin: 0;
|
||
padding: 6px;
|
||
list-style: none;
|
||
border-radius: 6px;
|
||
background: @bg-color;
|
||
}
|
||
|
||
&__detail-item {
|
||
.flex(row, flex-start, center);
|
||
gap: @spacing-sm;
|
||
padding: 8px 10px;
|
||
border-radius: @radius-sm;
|
||
background: @white;
|
||
font-size: 11px;
|
||
color: @heading-color;
|
||
}
|
||
|
||
&__detail-label {
|
||
width: 56px;
|
||
flex-shrink: 0;
|
||
font-size: 11px;
|
||
}
|
||
|
||
&__detail-amount {
|
||
margin-left: auto;
|
||
font-weight: 700;
|
||
color: @danger-color;
|
||
}
|
||
|
||
// 安全提示横幅:浅绿底 + 绿字(设计 33 实取 #D2EEDC / #16A34A)
|
||
&__safe {
|
||
padding: 8px 12px;
|
||
border-radius: @radius-sm;
|
||
background: @finance-safe-bg;
|
||
color: @success-color;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
// 卡下操作区:右对齐(设计 33 返回按钮在卡右下)
|
||
&__footer {
|
||
.flex(row, flex-end, center);
|
||
gap: @spacing-base;
|
||
margin-top: @spacing-base;
|
||
}
|
||
|
||
:deep(.app-button--primary) {
|
||
background: @primary-strong;
|
||
|
||
&:hover {
|
||
background: @primary-color;
|
||
}
|
||
}
|
||
}
|
||
</style>
|