修改
This commit is contained in:
@@ -11,7 +11,7 @@ import BillTable from './cpns/BillTable.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const financeStore = useFinanceStore()
|
||||
const { query, list, total } = storeToRefs(financeStore)
|
||||
const { query, list, total, billStats } = storeToRefs(financeStore)
|
||||
|
||||
const keyword = ref('')
|
||||
const selectedIds = ref<string[]>([])
|
||||
@@ -24,9 +24,9 @@ const STATUS_TABS: Array<{ label: string; value: BillStatus | 'all' }> = [
|
||||
]
|
||||
|
||||
const STATS = computed(() => [
|
||||
{ label: '总笔数', value: String(total.value) },
|
||||
{ label: '总金额', value: String(list.value.reduce((sum, bill) => sum + bill.amount, 0)) },
|
||||
{ label: '待支付', value: String(list.value.filter((bill) => bill.status === '待支付').length) },
|
||||
{ label: '总笔数', value: String(billStats.value.totalCount) },
|
||||
{ label: '总金额', value: String(billStats.value.totalAmount) },
|
||||
{ label: '待支付', value: String(billStats.value.pendingCount) },
|
||||
])
|
||||
|
||||
function onTab(value: BillStatus | 'all'): void {
|
||||
@@ -195,10 +195,12 @@ onMounted(() => {
|
||||
}
|
||||
|
||||
&__stat {
|
||||
.flex(column, flex-start, flex-start);
|
||||
.flex(column, center, center);
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
gap: 6px;
|
||||
width: 592.67px;
|
||||
padding: 22px 0 0 269px;
|
||||
padding: 22px 0 0;
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
@@ -249,6 +251,8 @@ onMounted(() => {
|
||||
}
|
||||
|
||||
:deep(.el-radio-button.is-active .el-radio-button__inner) {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
border-color: @primary-strong;
|
||||
background: @filter-selected-bg;
|
||||
color: @primary-strong;
|
||||
|
||||
@@ -3,24 +3,20 @@ import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage, ElButton } from 'element-plus'
|
||||
import { usePayPoll } from '@/composables/usePayPoll'
|
||||
import { useFinanceStore } from '@/stores/modules/finance'
|
||||
import type { PayMethod } from '@/types/business/finance'
|
||||
import { createMerchantOrderNo, PAY_METHODS } from '@/utils/payMeta'
|
||||
import { PAY_METHODS } from '@/utils/payMeta'
|
||||
import { formatMoney } from '@/utils/format'
|
||||
import CheckoutBillCard from './cpns/CheckoutBillCard.vue'
|
||||
import PayMethodList from './cpns/PayMethodList.vue'
|
||||
import WechatQrDialog from './cpns/WechatQrDialog.vue'
|
||||
import PayQrDialog from './cpns/PayQrDialog.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const financeStore = useFinanceStore()
|
||||
const { checkoutBills, checkoutLoading, payOrder } = storeToRefs(financeStore)
|
||||
|
||||
const requirementId = computed(() => {
|
||||
const raw = route.query.requirementId
|
||||
return String(Array.isArray(raw) ? raw[0] : (raw ?? '')).trim()
|
||||
})
|
||||
|
||||
const planIds = computed(() => {
|
||||
const raw = route.query.ids
|
||||
const text = Array.isArray(raw) ? raw.join(',') : String(raw ?? '')
|
||||
@@ -29,10 +25,12 @@ const planIds = computed(() => {
|
||||
|
||||
const billIds = computed(() => checkoutBills.value.map((bill) => bill.id))
|
||||
|
||||
const method = ref<PayMethod>('wechat')
|
||||
const method = ref<PayMethod>('alipay')
|
||||
const submitting = ref(false)
|
||||
const qrVisible = ref(false)
|
||||
|
||||
const { start: startPoll, stop: stopPoll, check } = usePayPoll(onPaySuccess)
|
||||
|
||||
const totalAmount = computed(() =>
|
||||
checkoutBills.value.reduce((sum, bill) => sum + Number(bill.amount || 0), 0),
|
||||
)
|
||||
@@ -44,55 +42,28 @@ const methodLabel = computed(
|
||||
const canPay = computed(() => checkoutBills.value.length > 0 && !submitting.value)
|
||||
|
||||
async function load(): Promise<void> {
|
||||
await financeStore.loadCheckout(requirementId.value, planIds.value)
|
||||
}
|
||||
|
||||
function openAlipay(body: string): void {
|
||||
if (/^\s*https?:\/\//i.test(body)) {
|
||||
window.open(body, '_blank', 'noopener')
|
||||
return
|
||||
}
|
||||
|
||||
const holder = document.createElement('div')
|
||||
holder.style.display = 'none'
|
||||
holder.innerHTML = body
|
||||
document.body.appendChild(holder)
|
||||
|
||||
const form = holder.querySelector('form')
|
||||
if (form) {
|
||||
form.submit()
|
||||
window.setTimeout(() => holder.remove(), 0)
|
||||
return
|
||||
}
|
||||
|
||||
holder.remove()
|
||||
ElMessage.error('支付宝下单返回内容无法识别')
|
||||
await financeStore.loadCheckout(planIds.value)
|
||||
}
|
||||
|
||||
async function onConfirm(): Promise<void> {
|
||||
if (!canPay.value) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const orderNo = createMerchantOrderNo()
|
||||
await financeStore.payOrders(billIds.value, method.value)
|
||||
|
||||
if (method.value === 'wechat') {
|
||||
await financeStore.payByWechatNative(orderNo, totalAmount.value, billIds.value)
|
||||
const codeUrl = payOrder.value?.codeUrl
|
||||
if (!codeUrl) {
|
||||
ElMessage.error('微信下单失败:未返回二维码内容')
|
||||
return
|
||||
}
|
||||
qrVisible.value = true
|
||||
const qrCode = payOrder.value?.qrCode
|
||||
if (!qrCode) {
|
||||
ElMessage.error('支付宝下单失败:未返回二维码内容')
|
||||
return
|
||||
}
|
||||
const outTradeNo = financeStore.payOutTradeNo
|
||||
if (!outTradeNo) {
|
||||
ElMessage.error('未获取到支付单号,请重新发起支付')
|
||||
return
|
||||
}
|
||||
|
||||
await financeStore.payByAlipayPage(orderNo, totalAmount.value, billIds.value)
|
||||
const body = payOrder.value?.formBody
|
||||
if (!body) {
|
||||
ElMessage.error('支付宝下单失败:未返回跳转地址')
|
||||
return
|
||||
}
|
||||
openAlipay(body)
|
||||
qrVisible.value = true
|
||||
startPoll(outTradeNo)
|
||||
}
|
||||
catch {
|
||||
}
|
||||
@@ -101,21 +72,22 @@ async function onConfirm(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function onRefreshQr(): Promise<void> {
|
||||
try {
|
||||
await financeStore.payByWechatNative(createMerchantOrderNo(), totalAmount.value, billIds.value)
|
||||
}
|
||||
catch {
|
||||
async function onCheckPaid(): Promise<void> {
|
||||
const outTradeNo = financeStore.payOutTradeNo
|
||||
if (!outTradeNo) return
|
||||
const done = await check(outTradeNo)
|
||||
if (!done && qrVisible.value) {
|
||||
ElMessage.warning('支付结果确认中,请稍后再试')
|
||||
}
|
||||
}
|
||||
|
||||
function onPaid(): void {
|
||||
function onPaySuccess(outTradeNo: string): void {
|
||||
qrVisible.value = false
|
||||
const first = checkoutBills.value[0]
|
||||
if (!first) return
|
||||
void router.push({
|
||||
path: `/finance/bills/${first.id}/pay/result`,
|
||||
query: { requirementId: requirementId.value },
|
||||
query: { outTradeNo, ids: billIds.value.join(',') },
|
||||
})
|
||||
}
|
||||
|
||||
@@ -123,11 +95,16 @@ function goBack(): void {
|
||||
void router.push('/finance/bills')
|
||||
}
|
||||
|
||||
watch([requirementId, planIds], () => {
|
||||
watch(planIds, () => {
|
||||
void load()
|
||||
}, { immediate: true })
|
||||
|
||||
watch(qrVisible, (visible) => {
|
||||
if (!visible) stopPoll()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stopPoll()
|
||||
financeStore.clearPayOrder()
|
||||
})
|
||||
</script>
|
||||
@@ -196,12 +173,11 @@ onBeforeUnmount(() => {
|
||||
</el-button>
|
||||
</section>
|
||||
|
||||
<WechatQrDialog
|
||||
<PayQrDialog
|
||||
v-model:visible="qrVisible"
|
||||
:content="payOrder?.codeUrl ?? ''"
|
||||
:content="payOrder?.qrCode ?? ''"
|
||||
:amount="totalAmount"
|
||||
@refresh="onRefreshQr"
|
||||
@paid="onPaid"
|
||||
@check="onCheckPaid"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -92,7 +92,7 @@ watch(
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
label="操作"
|
||||
width="96"
|
||||
width="110"
|
||||
fixed="right"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
@@ -189,6 +189,7 @@ watch(
|
||||
font-size: @font-size-sm;
|
||||
font-weight: 400;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&__empty {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed } from 'vue'
|
||||
import { ElButton } from 'element-plus'
|
||||
import type { FinancePeriod } from '@/types/business/finance'
|
||||
|
||||
interface DistributionItem {
|
||||
name: string
|
||||
@@ -10,10 +11,15 @@ interface DistributionItem {
|
||||
|
||||
interface Props {
|
||||
distribution: DistributionItem[]
|
||||
/** 全年逐月金额(dimension=YEAR 时接口返回,12 项) */
|
||||
monthly: number[]
|
||||
period: FinancePeriod
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const emit = defineEmits<{ periodChange: [period: FinancePeriod] }>()
|
||||
|
||||
const total = computed(() => props.distribution.reduce((sum, item) => sum + item.value, 0))
|
||||
|
||||
const gradient = computed(() => {
|
||||
@@ -27,13 +33,9 @@ const gradient = computed(() => {
|
||||
return `conic-gradient(${stops.join(', ')})`
|
||||
})
|
||||
|
||||
const AXIS = [250, 200, 150, 100, 50]
|
||||
const AXIS_MAX = AXIS[0]
|
||||
const MONTHS = ['1月', '2月', '3月', '4月', '5月']
|
||||
|
||||
interface PeriodOption {
|
||||
label: string
|
||||
value: 'month' | 'half'
|
||||
value: FinancePeriod
|
||||
}
|
||||
|
||||
// 设计稿 #20 右上角切换:月度账单(激活)/ 上半
|
||||
@@ -42,16 +44,42 @@ const PERIODS: PeriodOption[] = [
|
||||
{ label: '上半', value: 'half' },
|
||||
]
|
||||
|
||||
const period = ref<'month' | 'half'>('month')
|
||||
const TICK_COUNT = 5
|
||||
const DEFAULT_AXIS_MAX = 250
|
||||
|
||||
function onPeriodChange(value: 'month' | 'half'): void {
|
||||
period.value = value
|
||||
}
|
||||
/** 月度账单按业务类型分布取值;上半年取 YEAR 维度的 1-6 月逐月金额。 */
|
||||
const bars = computed(() => {
|
||||
if (props.period === 'half') {
|
||||
return props.monthly.slice(0, 6).map((value, index) => ({
|
||||
label: `${index + 1}月`,
|
||||
value,
|
||||
}))
|
||||
}
|
||||
return props.distribution.map((item) => ({
|
||||
label: item.name,
|
||||
value: item.value,
|
||||
}))
|
||||
})
|
||||
|
||||
// 柱高按 Y 轴量程绝对值换算(设计稿 #20:Y 轴 250 为满量程),非占比
|
||||
const axisMax = computed(() => {
|
||||
const max = Math.max(0, ...bars.value.map((bar) => bar.value))
|
||||
if (max <= 0) return DEFAULT_AXIS_MAX
|
||||
const rough = max / TICK_COUNT
|
||||
const magnitude = 10 ** Math.floor(Math.log10(rough))
|
||||
const step = Math.ceil(rough / magnitude) * magnitude
|
||||
return step * TICK_COUNT
|
||||
})
|
||||
|
||||
const axis = computed(() =>
|
||||
Array.from({ length: TICK_COUNT }, (_, index) =>
|
||||
Math.round((axisMax.value / TICK_COUNT) * (TICK_COUNT - index)),
|
||||
),
|
||||
)
|
||||
|
||||
// 柱高按 Y 轴量程绝对值换算,非占比
|
||||
function heightPercentOf(value: number): number {
|
||||
if (value <= 0) return 0
|
||||
return Math.min((value / AXIS_MAX) * 100, 100)
|
||||
return Math.min((value / axisMax.value) * 100, 100)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -67,7 +95,7 @@ function heightPercentOf(value: number): number {
|
||||
:key="item.value"
|
||||
class="finance-chart__switch-btn"
|
||||
:class="{ 'is-active': period === item.value }"
|
||||
@click="onPeriodChange(item.value)"
|
||||
@click="emit('periodChange', item.value)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</el-button>
|
||||
@@ -75,30 +103,30 @@ function heightPercentOf(value: number): number {
|
||||
|
||||
<div class="finance-chart__body">
|
||||
<ul class="finance-chart__axis" aria-hidden="true">
|
||||
<li v-for="v in AXIS" :key="v" class="finance-chart__axis-item">
|
||||
<li v-for="v in axis" :key="v" class="finance-chart__axis-item">
|
||||
{{ v }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="finance-chart__plot">
|
||||
<div class="finance-chart__grid" aria-hidden="true">
|
||||
<i v-for="v in AXIS" :key="v" class="finance-chart__line" />
|
||||
<i v-for="v in axis" :key="v" class="finance-chart__line" />
|
||||
</div>
|
||||
|
||||
<div class="finance-chart__bars">
|
||||
<span
|
||||
v-for="(m, i) in MONTHS"
|
||||
:key="m"
|
||||
v-for="(bar, i) in bars"
|
||||
:key="`${bar.label}-${i}`"
|
||||
class="finance-chart__bar"
|
||||
:style="{ height: `${heightPercentOf(distribution[i]?.value ?? 0)}%` }"
|
||||
:style="{ height: `${heightPercentOf(bar.value)}%` }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="finance-chart__pie" :style="{ background: gradient }" />
|
||||
|
||||
<ul class="finance-chart__months" aria-hidden="true">
|
||||
<li v-for="m in MONTHS" :key="m" class="finance-chart__month">
|
||||
{{ m }}
|
||||
<li v-for="(bar, i) in bars" :key="`${bar.label}-${i}`" class="finance-chart__month">
|
||||
{{ bar.label }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -1,17 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
import { ElDatePicker } from 'element-plus'
|
||||
import type { FinanceStats } from '@/types/business/finance'
|
||||
import { formatMoney } from '@/utils/format'
|
||||
|
||||
interface Props {
|
||||
stats: FinanceStats | null
|
||||
/** 'year' 表示当年全年,或具体月份 YYYY-MM */
|
||||
period: string
|
||||
}
|
||||
|
||||
defineProps<Props>()
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
periodChange: [period: string]
|
||||
export: []
|
||||
}>()
|
||||
|
||||
const year = new Date().getFullYear()
|
||||
|
||||
/** 不允许选择未来月份 */
|
||||
function isFutureMonth(date: Date): boolean {
|
||||
const today = new Date()
|
||||
return date.getFullYear() > today.getFullYear()
|
||||
|| (date.getFullYear() === today.getFullYear() && date.getMonth() > today.getMonth())
|
||||
}
|
||||
|
||||
/** 清空月份时回到「全年」 */
|
||||
function onPeriodChange(value: string | number | Date | null): void {
|
||||
emit('periodChange', typeof value === 'string' && value ? value : 'year')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -25,10 +42,19 @@ const emit = defineEmits<{
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button class="finance-overview__period-link" @click="emit('periodChange', 'year')">
|
||||
{{ stats?.month || '2026年账单' }}
|
||||
<span aria-hidden="true">›</span>
|
||||
</button>
|
||||
<div class="finance-overview__month">
|
||||
<ElDatePicker
|
||||
:model-value="props.period === 'year' ? '' : props.period"
|
||||
type="month"
|
||||
format="YYYY年MM月"
|
||||
value-format="YYYY-MM"
|
||||
:placeholder="`${year}年全年`"
|
||||
:clearable="true"
|
||||
:editable="false"
|
||||
:disabled-date="isFutureMonth"
|
||||
@update:model-value="onPeriodChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -62,20 +88,48 @@ const emit = defineEmits<{
|
||||
color: @white;
|
||||
}
|
||||
|
||||
&__period-link {
|
||||
&__month {
|
||||
position: absolute;
|
||||
top: 25px;
|
||||
right: 27px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
line-height: 15px;
|
||||
color: @white;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
top: 22px;
|
||||
right: 17px;
|
||||
width: 125px;
|
||||
|
||||
&:hover {
|
||||
:deep(.el-date-editor) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(.el-input__wrapper) {
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
:deep(.el-input__inner) {
|
||||
min-width: 0;
|
||||
padding: 0 16px 0 0;
|
||||
color: @white;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
|
||||
&::placeholder {
|
||||
color: @white;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 日历图标和文字挨在一起
|
||||
:deep(.el-input__prefix) {
|
||||
margin-right: 2px;
|
||||
}
|
||||
|
||||
:deep(.el-input__prefix),
|
||||
:deep(.el-input__suffix) {
|
||||
color: @white;
|
||||
}
|
||||
|
||||
&:hover :deep(.el-input__inner) {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
|
||||
248
src/views/finance/cpns/InvoiceApplyDialog.vue
Normal file
248
src/views/finance/cpns/InvoiceApplyDialog.vue
Normal file
@@ -0,0 +1,248 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { ElMessage, ElSelect, ElOption, ElRadio, ElButton } from 'element-plus'
|
||||
import type {
|
||||
InvoiceApplyPayload,
|
||||
InvoiceAvailableBill,
|
||||
InvoiceTitle,
|
||||
InvoiceType,
|
||||
} from '@/types/business/finance'
|
||||
import { INVOICE_TYPE_LABELS } from '@/utils/invoiceVo'
|
||||
import { formatMoney } from '@/utils/format'
|
||||
|
||||
interface Props {
|
||||
bills: InvoiceAvailableBill[]
|
||||
titles: InvoiceTitle[]
|
||||
/** 从某条已驳回记录进入时,优先选中的账单 */
|
||||
preselectBillId?: string
|
||||
submitting?: boolean
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const visible = defineModel<boolean>('visible', { default: false })
|
||||
|
||||
const emit = defineEmits<{ submit: [payload: InvoiceApplyPayload] }>()
|
||||
|
||||
const billId = ref('')
|
||||
const titleId = ref('')
|
||||
const invoiceType = ref<InvoiceType>('GENERAL')
|
||||
|
||||
function defaultTitleId(): string {
|
||||
return props.titles.find((item) => item.isDefault)?.id ?? props.titles[0]?.id ?? ''
|
||||
}
|
||||
|
||||
function reset(): void {
|
||||
const preferred = props.preselectBillId
|
||||
const preferredExists = Boolean(preferred) && props.bills.some((bill) => bill.billId === preferred)
|
||||
billId.value = preferredExists && preferred ? preferred : (props.bills[0]?.billId ?? '')
|
||||
titleId.value = defaultTitleId()
|
||||
invoiceType.value = 'GENERAL'
|
||||
}
|
||||
|
||||
watch(visible, (open) => {
|
||||
if (open) reset()
|
||||
})
|
||||
|
||||
// 抬头/账单可能在弹窗打开后才加载完成,补选默认项
|
||||
watch(
|
||||
() => props.titles,
|
||||
(list) => {
|
||||
if (visible.value && !titleId.value && list.length > 0) titleId.value = defaultTitleId()
|
||||
},
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.bills,
|
||||
(list) => {
|
||||
if (visible.value && !billId.value && list.length > 0) billId.value = list[0].billId
|
||||
},
|
||||
)
|
||||
|
||||
function onSubmit(): void {
|
||||
if (!billId.value) {
|
||||
ElMessage.warning('请选择要开票的账单')
|
||||
return
|
||||
}
|
||||
if (!titleId.value) {
|
||||
ElMessage.warning('请选择发票抬头')
|
||||
return
|
||||
}
|
||||
emit('submit', {
|
||||
billId: billId.value,
|
||||
titleId: titleId.value,
|
||||
invoiceType: invoiceType.value,
|
||||
})
|
||||
}
|
||||
|
||||
function onCancel(): void {
|
||||
visible.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div v-if="visible" class="invoice-apply" @click.self="onCancel">
|
||||
<div class="invoice-apply__panel">
|
||||
<h3 class="invoice-apply__title">
|
||||
申请开票
|
||||
</h3>
|
||||
|
||||
<div class="invoice-apply__field">
|
||||
<span class="invoice-apply__label">选择账单</span>
|
||||
<el-select
|
||||
v-model="billId"
|
||||
class="invoice-apply__control"
|
||||
placeholder="请选择可开票账单"
|
||||
:disabled="bills.length === 0"
|
||||
>
|
||||
<el-option
|
||||
v-for="bill in bills"
|
||||
:key="bill.billId"
|
||||
:value="bill.billId"
|
||||
:label="`${bill.billNo} · ${bill.periodName} · ¥${formatMoney(bill.amount)}`"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<div class="invoice-apply__field">
|
||||
<span class="invoice-apply__label">发票抬头</span>
|
||||
<el-select
|
||||
v-model="titleId"
|
||||
class="invoice-apply__control"
|
||||
placeholder="请选择发票抬头"
|
||||
:disabled="titles.length === 0"
|
||||
>
|
||||
<el-option
|
||||
v-for="title in titles"
|
||||
:key="title.id"
|
||||
:value="title.id"
|
||||
:label="`${title.title}(${title.type})`"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<div class="invoice-apply__field">
|
||||
<span class="invoice-apply__label">发票类型</span>
|
||||
<el-radio v-model="invoiceType" value="GENERAL">
|
||||
{{ INVOICE_TYPE_LABELS.GENERAL }}
|
||||
</el-radio>
|
||||
<el-radio v-model="invoiceType" value="SPECIAL">
|
||||
{{ INVOICE_TYPE_LABELS.SPECIAL }}
|
||||
</el-radio>
|
||||
</div>
|
||||
|
||||
<p v-if="bills.length === 0" class="invoice-apply__empty">
|
||||
暂无可开票账单(仅已支付且未开票的账单可申请)
|
||||
</p>
|
||||
|
||||
<div class="invoice-apply__footer">
|
||||
<el-button class="invoice-apply__btn" @click="onCancel">
|
||||
取消
|
||||
</el-button>
|
||||
<el-button
|
||||
class="invoice-apply__btn invoice-apply__btn--confirm"
|
||||
:disabled="bills.length === 0 || titles.length === 0 || submitting"
|
||||
@click="onSubmit"
|
||||
>
|
||||
{{ submitting ? '提交中…' : '提交申请' }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.invoice-apply {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1000;
|
||||
.flex(row, center);
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
|
||||
&__panel {
|
||||
width: 480px;
|
||||
max-width: calc(100vw - 32px);
|
||||
padding: @spacing-lg;
|
||||
border-radius: @radius-lg;
|
||||
background: @white;
|
||||
box-shadow: @shadow-lg;
|
||||
}
|
||||
|
||||
&__title {
|
||||
margin-bottom: @spacing-base;
|
||||
font-size: @font-size-lg;
|
||||
font-weight: 600;
|
||||
color: @heading-color;
|
||||
}
|
||||
|
||||
&__field {
|
||||
.flex(row, flex-start, center);
|
||||
gap: @spacing-sm;
|
||||
margin-bottom: @spacing-base;
|
||||
|
||||
:deep(.el-radio__label) {
|
||||
color: @text-color;
|
||||
font-size: @font-size-base;
|
||||
}
|
||||
}
|
||||
|
||||
&__label {
|
||||
width: 72px;
|
||||
flex-shrink: 0;
|
||||
font-size: @font-size-base;
|
||||
color: @text-color;
|
||||
}
|
||||
|
||||
&__control {
|
||||
flex: 1;
|
||||
|
||||
:deep(.el-select__wrapper) {
|
||||
min-height: 34px;
|
||||
background: @bg-color-light;
|
||||
box-shadow: none;
|
||||
border-radius: @radius-base;
|
||||
}
|
||||
}
|
||||
|
||||
&__empty {
|
||||
margin-top: @spacing-sm;
|
||||
font-size: @font-size-sm;
|
||||
color: @text-color-secondary;
|
||||
}
|
||||
|
||||
&__footer {
|
||||
.flex(row, flex-end);
|
||||
gap: @spacing-sm;
|
||||
margin-top: @spacing-lg;
|
||||
}
|
||||
|
||||
&__btn {
|
||||
height: 34px;
|
||||
padding: 0 @spacing-base;
|
||||
border: 1px solid @border-color-dark;
|
||||
border-radius: @radius-base;
|
||||
background: @white;
|
||||
color: @text-color;
|
||||
font-size: @font-size-base;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
border-color: @primary-color;
|
||||
color: @primary-color;
|
||||
}
|
||||
|
||||
&--confirm {
|
||||
border-color: @primary-color;
|
||||
background: @primary-color;
|
||||
color: @white;
|
||||
|
||||
&:hover {
|
||||
background: @primary-hover;
|
||||
color: @white;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -22,12 +22,13 @@ const emit = defineEmits<{
|
||||
<span v-else class="invoice-title-card__badge-placeholder" />
|
||||
<div class="invoice-title-card__actions">
|
||||
<el-button
|
||||
v-if="!invoiceTitle.isDefault"
|
||||
link
|
||||
type="primary"
|
||||
class="invoice-title-card__btn"
|
||||
@click="emit('setDefault', invoiceTitle.id)"
|
||||
>
|
||||
{{ invoiceTitle.isDefault ? '取消默认' : '设为默认' }}
|
||||
设为默认
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
|
||||
@@ -27,8 +27,12 @@ watch(visible, (open) => {
|
||||
})
|
||||
|
||||
function onSave(): void {
|
||||
if (!form.title.trim() || !form.taxNo.trim()) {
|
||||
ElMessage.warning('请填写发票抬头与税号')
|
||||
if (!form.title.trim()) {
|
||||
ElMessage.warning('请填写发票抬头')
|
||||
return
|
||||
}
|
||||
if (form.type === '企业单位' && !form.taxNo.trim()) {
|
||||
ElMessage.warning('企业单位请填写税号')
|
||||
return
|
||||
}
|
||||
emit('save', { type: form.type, title: form.title.trim(), taxNo: form.taxNo.trim() })
|
||||
|
||||
@@ -1,177 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { ElRadio, ElButton } from 'element-plus'
|
||||
import type { PayMethod } from '@/types/business/finance'
|
||||
|
||||
interface Props {
|
||||
method: PayMethod
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const visible = defineModel<boolean>('visible', { default: false })
|
||||
|
||||
const emit = defineEmits<{ confirm: [method: PayMethod] }>()
|
||||
|
||||
const selected = ref<PayMethod>(props.method)
|
||||
|
||||
watch(
|
||||
() => props.method,
|
||||
(value) => {
|
||||
selected.value = value
|
||||
},
|
||||
)
|
||||
|
||||
watch(visible, (open) => {
|
||||
if (open) selected.value = props.method
|
||||
})
|
||||
|
||||
function onConfirm(): void {
|
||||
emit('confirm', selected.value)
|
||||
visible.value = false
|
||||
}
|
||||
|
||||
function onCancel(): void {
|
||||
visible.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div v-if="visible" class="pay-method-dialog" @click.self="onCancel">
|
||||
<div class="pay-method-dialog__panel">
|
||||
<h3 class="pay-method-dialog__title">
|
||||
切换支付方式
|
||||
</h3>
|
||||
|
||||
<label
|
||||
class="pay-method-dialog__option"
|
||||
:class="{ 'is-active': selected === 'wechat' }"
|
||||
>
|
||||
<el-radio
|
||||
v-model="selected"
|
||||
value="wechat"
|
||||
class="pay-method-dialog__radio"
|
||||
>
|
||||
微信支付
|
||||
</el-radio>
|
||||
<span class="pay-method-dialog__tip text-secondary">推荐使用</span>
|
||||
</label>
|
||||
|
||||
<label
|
||||
class="pay-method-dialog__option"
|
||||
:class="{ 'is-active': selected === 'alipay' }"
|
||||
>
|
||||
<el-radio
|
||||
v-model="selected"
|
||||
value="alipay"
|
||||
class="pay-method-dialog__radio"
|
||||
>
|
||||
支付宝支付
|
||||
</el-radio>
|
||||
<span class="pay-method-dialog__tip text-secondary">其他用户选择</span>
|
||||
</label>
|
||||
|
||||
<div class="pay-method-dialog__footer">
|
||||
<el-button class="pay-method-dialog__btn" @click="onCancel">
|
||||
取消
|
||||
</el-button>
|
||||
<el-button class="pay-method-dialog__btn pay-method-dialog__btn--confirm" @click="onConfirm">
|
||||
确认
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.pay-method-dialog {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1000;
|
||||
.flex(row, center);
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
|
||||
&__panel {
|
||||
width: 420px;
|
||||
max-width: calc(100vw - 32px);
|
||||
padding: @spacing-lg;
|
||||
border-radius: @radius-lg;
|
||||
background: @white;
|
||||
box-shadow: @shadow-lg;
|
||||
}
|
||||
|
||||
&__title {
|
||||
margin-bottom: @spacing-base;
|
||||
font-size: @font-size-lg;
|
||||
font-weight: 600;
|
||||
color: @heading-color;
|
||||
}
|
||||
|
||||
&__option {
|
||||
.flex(row, flex-start, center);
|
||||
gap: @spacing-sm;
|
||||
padding: @spacing-base;
|
||||
margin-bottom: @spacing-sm;
|
||||
border: 1px solid @border-color;
|
||||
border-radius: @radius-base;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
border-color: @primary-color;
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
border-color: @primary-color;
|
||||
background: @primary-light;
|
||||
}
|
||||
}
|
||||
|
||||
&__radio {
|
||||
.el-radio__label {
|
||||
color: @heading-color;
|
||||
font-size: @font-size-base;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
&__tip {
|
||||
margin-left: auto;
|
||||
font-size: @font-size-sm;
|
||||
}
|
||||
|
||||
&__footer {
|
||||
.flex(row, flex-end);
|
||||
gap: @spacing-sm;
|
||||
margin-top: @spacing-base;
|
||||
}
|
||||
|
||||
&__btn {
|
||||
height: 34px;
|
||||
padding: 0 @spacing-base;
|
||||
border: 1px solid @border-color-dark;
|
||||
border-radius: @radius-base;
|
||||
background: @white;
|
||||
color: @text-color;
|
||||
font-size: @font-size-base;
|
||||
transition: all 0.2s;
|
||||
&:hover {
|
||||
border-color: @primary-color;
|
||||
color: @primary-color;
|
||||
}
|
||||
|
||||
&--confirm {
|
||||
border-color: @primary-color;
|
||||
background: @primary-color;
|
||||
color: @white;
|
||||
|
||||
&:hover {
|
||||
background: @primary-hover;
|
||||
color: @white;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,35 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { computed } from 'vue'
|
||||
import qrcode from 'qrcode-generator'
|
||||
import { useCountDown } from '@/composables/useCountDown'
|
||||
import { formatMoney } from '@/utils/format'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
/** 后端返回的二维码内容字符串 */
|
||||
content: string
|
||||
amount: number
|
||||
expiresIn?: number
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), { expiresIn: 300 })
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:visible': [visible: boolean]
|
||||
refresh: []
|
||||
paid: []
|
||||
check: []
|
||||
}>()
|
||||
|
||||
const { seconds, start, reset: resetCountDown } = useCountDown(props.expiresIn)
|
||||
const started = ref(false)
|
||||
|
||||
const expired = computed(() => started.value && seconds.value <= 0)
|
||||
|
||||
const countdownText = computed(() => {
|
||||
const m = Math.floor(seconds.value / 60)
|
||||
const s = seconds.value % 60
|
||||
return `${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`
|
||||
})
|
||||
|
||||
const qrSvg = computed(() => {
|
||||
if (!props.content) return ''
|
||||
try {
|
||||
@@ -37,78 +24,45 @@ const qrSvg = computed(() => {
|
||||
qr.addData(props.content)
|
||||
qr.make()
|
||||
return qr.createSvgTag({ cellSize: 4, margin: 2, scalable: true })
|
||||
} catch {
|
||||
}
|
||||
catch {
|
||||
return ''
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => [props.visible, props.content] as const,
|
||||
([visible, content]) => {
|
||||
if (visible && content) {
|
||||
start(props.expiresIn)
|
||||
started.value = true
|
||||
return
|
||||
}
|
||||
if (!visible) {
|
||||
resetCountDown()
|
||||
started.value = false
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
function close(): void {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
function refresh(): void {
|
||||
start(props.expiresIn)
|
||||
started.value = true
|
||||
emit('refresh')
|
||||
}
|
||||
|
||||
function onPaid(): void {
|
||||
emit('paid')
|
||||
}
|
||||
|
||||
function onBoxClick(): void {
|
||||
if (expired.value) refresh()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div v-if="visible" class="wx-qr" @click.self="close">
|
||||
<div class="wx-qr__panel">
|
||||
<h3 class="wx-qr__title">微信扫码支付</h3>
|
||||
<p class="wx-qr__amount">¥{{ formatMoney(amount) }}</p>
|
||||
<div v-if="visible" class="pay-qr" @click.self="close">
|
||||
<div class="pay-qr__panel">
|
||||
<h3 class="pay-qr__title">
|
||||
支付宝扫码支付
|
||||
</h3>
|
||||
<p class="pay-qr__amount">
|
||||
¥{{ formatMoney(amount) }}
|
||||
</p>
|
||||
|
||||
<div
|
||||
class="wx-qr__box"
|
||||
:class="{ 'is-expired': expired }"
|
||||
@click="onBoxClick"
|
||||
>
|
||||
<div v-if="!expired && qrSvg" class="wx-qr__code" v-html="qrSvg" />
|
||||
<div v-else class="wx-qr__mask">
|
||||
<span class="wx-qr__mask-icon">⟳</span>
|
||||
<span class="wx-qr__mask-text">
|
||||
{{ expired ? '二维码已过期' : '二维码生成中' }}<br />点击刷新
|
||||
</span>
|
||||
<div class="pay-qr__box">
|
||||
<div v-if="qrSvg" class="pay-qr__code" v-html="qrSvg" />
|
||||
<div v-else class="pay-qr__mask">
|
||||
<span class="pay-qr__mask-icon">▦</span>
|
||||
<span class="pay-qr__mask-text">二维码生成中</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="wx-qr__status">
|
||||
<template v-if="!expired">
|
||||
请使用手机微信 <strong>[扫一扫]</strong> 扫描上方二维码, 二维码
|
||||
<strong class="wx-qr__count">{{ countdownText }}</strong> 后失效
|
||||
</template>
|
||||
<template v-else> 二维码已过期,请点击二维码或下方按钮刷新 </template>
|
||||
<p class="pay-qr__status">
|
||||
请使用手机支付宝 <strong>[扫一扫]</strong> 扫描上方二维码完成支付,支付成功后自动跳转
|
||||
</p>
|
||||
|
||||
<div class="wx-qr__actions">
|
||||
<button class="wx-qr__btn" @click="refresh">刷新二维码</button>
|
||||
<button class="wx-qr__btn wx-qr__btn--cta" @click="onPaid">
|
||||
<div class="pay-qr__actions">
|
||||
<button class="pay-qr__btn" @click="close">
|
||||
取消支付
|
||||
</button>
|
||||
<button class="pay-qr__btn pay-qr__btn--cta" @click="emit('check')">
|
||||
我已完成支付
|
||||
</button>
|
||||
</div>
|
||||
@@ -118,7 +72,7 @@ function onBoxClick(): void {
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.wx-qr {
|
||||
.pay-qr {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1000;
|
||||
@@ -156,11 +110,6 @@ function onBoxClick(): void {
|
||||
border: 1px solid @checkout-line;
|
||||
border-radius: @radius-base;
|
||||
background: @checkout-card;
|
||||
|
||||
&.is-expired {
|
||||
background: @bg-color;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
&__code {
|
||||
@@ -204,11 +153,6 @@ function onBoxClick(): void {
|
||||
}
|
||||
}
|
||||
|
||||
&__count {
|
||||
color: @checkout-amount;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&__actions {
|
||||
.flex(row, center);
|
||||
gap: @spacing-sm;
|
||||
@@ -3,9 +3,8 @@ export { default as FinanceOverview } from './cpns/FinanceOverview.vue'
|
||||
export { default as FinanceChart } from './cpns/FinanceChart.vue'
|
||||
export { default as BillTable } from './cpns/BillTable.vue'
|
||||
export { default as BillSummaryBar } from './cpns/BillSummaryBar.vue'
|
||||
export { default as PayMethodDialog } from './cpns/PayMethodDialog.vue'
|
||||
export { default as InvoiceTitleCard } from './cpns/InvoiceTitleCard.vue'
|
||||
export { default as InvoiceTitleDialog } from './cpns/InvoiceTitleDialog.vue'
|
||||
export { default as CheckoutBillCard } from './cpns/CheckoutBillCard.vue'
|
||||
export { default as PayMethodList } from './cpns/PayMethodList.vue'
|
||||
export { default as WechatQrDialog } from './cpns/WechatQrDialog.vue'
|
||||
export { default as PayQrDialog } from './cpns/PayQrDialog.vue'
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
<!-- 页面:财务中心(Finance) -->
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { RouterLink } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { PageHead } from '@/components'
|
||||
import { useFinanceStore } from '@/stores/modules/finance'
|
||||
import type { FinancePeriod, FinanceSummaryQuery } from '@/types/business/finance'
|
||||
import FinanceChart from './cpns/FinanceChart.vue'
|
||||
import FinanceOverview from './cpns/FinanceOverview.vue'
|
||||
|
||||
const financeStore = useFinanceStore()
|
||||
const { stats } = storeToRefs(financeStore)
|
||||
const { stats, overviewStats } = storeToRefs(financeStore)
|
||||
|
||||
const ENTRIES = [
|
||||
{ key: 'bill', label: '账单明细', to: '/finance/bills' },
|
||||
@@ -19,17 +20,86 @@ const ENTRIES = [
|
||||
{ key: 'export', label: '报表导出', to: '' },
|
||||
] as const
|
||||
|
||||
function onPeriodChange(period: string): void {
|
||||
void financeStore.fetchStats(period)
|
||||
const chartPeriod = ref<FinancePeriod>('month')
|
||||
const now = new Date()
|
||||
|
||||
/** 累计消费总额:默认当年全年,可切换具体月份 */
|
||||
const overviewPeriod = ref('year')
|
||||
|
||||
/** 下方图表仍按当前月/当前年请求,不受月份选择器影响 */
|
||||
function buildChartQuery(): FinanceSummaryQuery {
|
||||
if (chartPeriod.value === 'half') {
|
||||
return { dimension: 'YEAR', year: now.getFullYear() }
|
||||
}
|
||||
return {
|
||||
dimension: 'MONTH',
|
||||
year: now.getFullYear(),
|
||||
month: now.getMonth() + 1,
|
||||
}
|
||||
}
|
||||
|
||||
function buildOverviewQuery(): FinanceSummaryQuery {
|
||||
if (overviewPeriod.value === 'year') {
|
||||
return { dimension: 'YEAR', year: now.getFullYear() }
|
||||
}
|
||||
const [year, month] = overviewPeriod.value.split('-').map(Number)
|
||||
return {
|
||||
dimension: 'MONTH',
|
||||
year: year || now.getFullYear(),
|
||||
month: month || now.getMonth() + 1,
|
||||
}
|
||||
}
|
||||
|
||||
function loadStats(): void {
|
||||
void financeStore.fetchStats(buildChartQuery())
|
||||
}
|
||||
|
||||
function loadOverviewStats(): void {
|
||||
void financeStore.fetchOverviewStats(buildOverviewQuery())
|
||||
}
|
||||
|
||||
function onPeriodChange(period: FinancePeriod): void {
|
||||
if (chartPeriod.value === period) return
|
||||
chartPeriod.value = period
|
||||
loadStats()
|
||||
}
|
||||
|
||||
function onOverviewPeriodChange(period: string): void {
|
||||
if (!period || period === overviewPeriod.value) return
|
||||
overviewPeriod.value = period
|
||||
// 只刷新累计消费总额,不动下方图表
|
||||
loadOverviewStats()
|
||||
}
|
||||
|
||||
function downloadBlob(blob: Blob, filename: string): void {
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = filename
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
async function onExport(): Promise<void> {
|
||||
await financeStore.export()
|
||||
ElMessage.success('报表导出成功(演示)')
|
||||
try {
|
||||
const blob = await financeStore.export('excel')
|
||||
if (!blob || blob.size === 0) {
|
||||
ElMessage.error('导出内容为空')
|
||||
return
|
||||
}
|
||||
downloadBlob(blob, `账单明细_${new Date().toISOString().slice(0, 10)}.xlsx`)
|
||||
ElMessage.success('报表导出成功')
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void financeStore.fetchStats()
|
||||
loadStats()
|
||||
loadOverviewStats()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -43,8 +113,9 @@ onMounted(() => {
|
||||
<div class="container">
|
||||
<div class="finance__top">
|
||||
<FinanceOverview
|
||||
:stats="stats"
|
||||
@period-change="onPeriodChange"
|
||||
:stats="overviewStats"
|
||||
:period="overviewPeriod"
|
||||
@period-change="onOverviewPeriodChange"
|
||||
@export="onExport"
|
||||
/>
|
||||
|
||||
@@ -156,7 +227,12 @@ onMounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<FinanceChart :distribution="stats?.distribution ?? []" />
|
||||
<FinanceChart
|
||||
:distribution="stats?.distribution ?? []"
|
||||
:monthly="stats?.monthly ?? []"
|
||||
:period="chartPeriod"
|
||||
@period-change="onPeriodChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -41,13 +41,18 @@ function onEdit(item: InvoiceTitle): void {
|
||||
}
|
||||
|
||||
async function onSave(payload: InvoiceTitlePayload): Promise<void> {
|
||||
if (editing.value) {
|
||||
await financeStore.updateTitle(editing.value.id, payload)
|
||||
ElMessage.success('抬头已更新')
|
||||
try {
|
||||
if (editing.value) {
|
||||
await financeStore.updateTitle(editing.value.id, payload)
|
||||
ElMessage.success('抬头已更新')
|
||||
}
|
||||
else {
|
||||
await financeStore.createTitle(payload)
|
||||
ElMessage.success('抬头已新增')
|
||||
}
|
||||
}
|
||||
else {
|
||||
await financeStore.createTitle(payload)
|
||||
ElMessage.success('抬头已新增')
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,16 +62,27 @@ function onDelete(id: string): void {
|
||||
}
|
||||
|
||||
async function onConfirmDelete(): Promise<void> {
|
||||
await financeStore.deleteTitle(pendingDeleteId.value)
|
||||
pendingDeleteId.value = ''
|
||||
ElMessage.success('抬头已删除')
|
||||
try {
|
||||
await financeStore.deleteTitle(pendingDeleteId.value)
|
||||
pendingDeleteId.value = ''
|
||||
if (page.value > pageCount.value) page.value = pageCount.value
|
||||
ElMessage.success('抬头已删除')
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
async function onSetDefault(id: string): Promise<void> {
|
||||
const item = titles.value.find((title) => title.id === id)
|
||||
if (!item) return
|
||||
await financeStore.setDefaultTitle(id)
|
||||
ElMessage.success(item.isDefault ? '已取消默认抬头' : '已设为默认抬头')
|
||||
if (!item || item.isDefault) return
|
||||
try {
|
||||
await financeStore.setDefaultTitle(id)
|
||||
ElMessage.success('已设为默认抬头')
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -1,81 +1,166 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { RouterLink } from 'vue-router'
|
||||
import { ElMessage, ElButton, ElTable, ElTableColumn } from 'element-plus'
|
||||
import { FilterPanel, PaginationBar, StatusTag } from '@/components'
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox, ElButton, ElTable, ElTableColumn } from 'element-plus'
|
||||
import { PaginationBar, StatusTag } from '@/components'
|
||||
import { useFinanceStore } from '@/stores/modules/finance'
|
||||
import type { Invoice, InvoiceStatus } from '@/types/business/finance'
|
||||
import { useProfileStore } from '@/stores/modules/profile'
|
||||
import type { Invoice, InvoiceApplyPayload, InvoiceStatus } from '@/types/business/finance'
|
||||
import { formatMoney } from '@/utils/format'
|
||||
import { INVOICE_TYPE_LABELS } from '@/utils/invoiceVo'
|
||||
import InvoiceApplyDialog from './cpns/InvoiceApplyDialog.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const financeStore = useFinanceStore()
|
||||
const { titles, invoices, invoiceQuery, invoiceTotal } = storeToRefs(financeStore)
|
||||
const { titles, invoices, invoiceQuery, invoiceTotal, availableBills, invoiceStatusOptions } = storeToRefs(financeStore)
|
||||
|
||||
const keyword = ref('')
|
||||
const selectedIds = ref<string[]>([])
|
||||
const profileStore = useProfileStore()
|
||||
const { profile } = storeToRefs(profileStore)
|
||||
|
||||
const applyVisible = ref(false)
|
||||
const applying = ref(false)
|
||||
const applyBillId = ref<string | undefined>(undefined)
|
||||
|
||||
const defaultTitle = computed(() => titles.value.find((item) => item.isDefault) ?? titles.value[0] ?? null)
|
||||
|
||||
const STATUS_TABS: Array<{ label: string; value: InvoiceStatus | 'all' }> = [
|
||||
{ label: '全部', value: 'all' },
|
||||
{ label: '已开票', value: '已开票' },
|
||||
{ label: '开票中', value: '开票中' },
|
||||
{ label: '未开票', value: '未开票' },
|
||||
]
|
||||
type TagVariant = 'primary' | 'success' | 'warning' | 'danger' | 'info'
|
||||
|
||||
const STATUS_VARIANTS: Record<InvoiceStatus, 'success' | 'warning' | 'info'> = {
|
||||
已开票: 'success',
|
||||
开票中: 'warning',
|
||||
未开票: 'info',
|
||||
/** 发票状态选项卡:字典 + 首项「全部」(value 为空,表示不传 status)。 */
|
||||
const STATUS_TABS = computed<Array<{ label: string; value: InvoiceStatus | '' }>>(() => [
|
||||
{ label: '全部', value: '' },
|
||||
...invoiceStatusOptions.value.map((item) => ({
|
||||
label: item.dictLabel,
|
||||
value: item.dictValue as InvoiceStatus,
|
||||
})),
|
||||
])
|
||||
|
||||
/** 状态文案优先用后端 statusName,缺失时回退字典文案。 */
|
||||
function statusLabel(invoice: Invoice): string {
|
||||
return invoice.statusName
|
||||
|| invoiceStatusOptions.value.find((item) => item.dictValue === invoice.status)?.dictLabel
|
||||
|| '—'
|
||||
}
|
||||
|
||||
function onTab(value: InvoiceStatus | 'all'): void {
|
||||
/** 标签颜色取字典 listClass(info/warning/success)。 */
|
||||
function statusVariant(status: InvoiceStatus): TagVariant {
|
||||
const listClass = invoiceStatusOptions.value.find((item) => item.dictValue === status)?.listClass
|
||||
if (listClass === 'primary' || listClass === 'success' || listClass === 'warning' || listClass === 'danger') {
|
||||
return listClass
|
||||
}
|
||||
return 'info'
|
||||
}
|
||||
|
||||
function onTab(value: InvoiceStatus | ''): void {
|
||||
if (invoiceQuery.value.status === value) return
|
||||
financeStore.setInvoiceQuery({ ...invoiceQuery.value, status: value, keyword: keyword.value })
|
||||
selectedIds.value = []
|
||||
financeStore.setInvoiceQuery({ ...invoiceQuery.value, status: value })
|
||||
void financeStore.searchInvoices()
|
||||
}
|
||||
|
||||
function onSearch(): void {
|
||||
financeStore.setInvoiceQuery({ ...invoiceQuery.value, keyword: keyword.value })
|
||||
void financeStore.searchInvoices()
|
||||
}
|
||||
|
||||
function onReset(): void {
|
||||
keyword.value = ''
|
||||
selectedIds.value = []
|
||||
financeStore.setInvoiceQuery({ keyword: '', status: 'all', page: 1, pageSize: invoiceQuery.value.pageSize })
|
||||
void financeStore.fetchInvoices()
|
||||
}
|
||||
|
||||
function onPageChange(page: number): void {
|
||||
void financeStore.changeInvoicePage(page)
|
||||
}
|
||||
|
||||
async function onApply(invoice: Invoice): Promise<void> {
|
||||
await financeStore.applyInvoice(invoice.id)
|
||||
ElMessage.success('开票申请已提交')
|
||||
async function onOpenApply(billId?: string): Promise<void> {
|
||||
applyBillId.value = billId || undefined
|
||||
try {
|
||||
await financeStore.fetchAvailableBills()
|
||||
applyVisible.value = true
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
function onPreview(): void {
|
||||
ElMessage.info('附件待接口接入')
|
||||
async function onSubmitApply(payload: InvoiceApplyPayload): Promise<void> {
|
||||
applying.value = true
|
||||
try {
|
||||
await financeStore.applyInvoice(payload)
|
||||
applyVisible.value = false
|
||||
ElMessage.success('开票申请已提交')
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
finally {
|
||||
applying.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onDownload(): void {
|
||||
ElMessage.info('附件待接口接入')
|
||||
/** 已驳回的发票可重新发起开票申请。 */
|
||||
function onApplyForRow(invoice: Invoice): void {
|
||||
void onOpenApply(invoice.billId)
|
||||
}
|
||||
|
||||
function onSendEmail(): void {
|
||||
ElMessage.success('发票已发送至绑定邮箱(演示)')
|
||||
async function onPreview(invoice: Invoice): Promise<void> {
|
||||
try {
|
||||
const url = await financeStore.fetchPreviewUrl(invoice.id)
|
||||
if (!url) {
|
||||
ElMessage.warning('暂无可预览的发票文件')
|
||||
return
|
||||
}
|
||||
window.open(url, '_blank', 'noopener')
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
function onSelectionChange(rows: Invoice[]): void {
|
||||
selectedIds.value = rows.map((row) => row.id)
|
||||
async function onDownload(invoice: Invoice): Promise<void> {
|
||||
try {
|
||||
const { blob, fileName } = await financeStore.fetchDownloadFile(invoice.id)
|
||||
if (!blob || blob.size === 0) {
|
||||
ElMessage.warning('暂无可下载的发票文件')
|
||||
return
|
||||
}
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = fileName || `${invoice.invoiceNo || 'invoice'}.pdf`
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
async function onSendEmail(invoice: Invoice): Promise<void> {
|
||||
if (!profile.value?.email) {
|
||||
try {
|
||||
await ElMessageBox.confirm('您还未绑定邮箱,请先绑定邮箱后再发送发票', '提示', {
|
||||
confirmButtonText: '去绑定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
void router.push({ name: 'ProfileBindEmail', query: { redirect: route.fullPath } })
|
||||
}
|
||||
catch {
|
||||
// 用户取消
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await financeStore.sendInvoiceEmail(invoice.id)
|
||||
ElMessage.success('发票已发送至绑定邮箱')
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
keyword.value = invoiceQuery.value.keyword
|
||||
void Promise.all([financeStore.fetchTitles(), financeStore.fetchInvoices()])
|
||||
void Promise.all([
|
||||
financeStore.fetchInvoiceStatusOptions(),
|
||||
financeStore.fetchTitles(),
|
||||
financeStore.fetchInvoices(),
|
||||
profileStore.fetchProfile().catch(() => null),
|
||||
])
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -108,59 +193,44 @@ onMounted(() => {
|
||||
</RouterLink>
|
||||
</section>
|
||||
|
||||
<div class="invoices__tabs">
|
||||
<el-button
|
||||
v-for="tab in STATUS_TABS"
|
||||
:key="tab.value"
|
||||
class="invoices__tab"
|
||||
:class="{ 'is-active': invoiceQuery.status === tab.value }"
|
||||
@click="onTab(tab.value)"
|
||||
>
|
||||
{{ tab.label }}
|
||||
<div class="invoices__toolbar">
|
||||
<div class="invoices__tabs">
|
||||
<el-button
|
||||
v-for="tab in STATUS_TABS"
|
||||
:key="tab.value"
|
||||
class="invoices__tab"
|
||||
:class="{ 'is-active': invoiceQuery.status === tab.value }"
|
||||
@click="onTab(tab.value)"
|
||||
>
|
||||
{{ tab.label }}
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-button class="invoices__apply" @click="onOpenApply()">
|
||||
+ 申请开票
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<FilterPanel
|
||||
v-model:keyword="keyword"
|
||||
keyword-placeholder="搜索发票抬头 / 账单号 / 项目名称"
|
||||
@search="onSearch"
|
||||
@reset="onReset"
|
||||
/>
|
||||
|
||||
<div class="invoices__table card">
|
||||
<el-table
|
||||
class="invoices__table-el"
|
||||
:data="invoices"
|
||||
row-key="id"
|
||||
@selection-change="onSelectionChange"
|
||||
>
|
||||
<el-table-column
|
||||
type="selection"
|
||||
width="48"
|
||||
/>
|
||||
<el-table-column
|
||||
type="index"
|
||||
label="序号"
|
||||
width="60"
|
||||
/>
|
||||
<el-table-column
|
||||
prop="planName"
|
||||
label="账单名称"
|
||||
min-width="180"
|
||||
label="发票号码"
|
||||
min-width="150"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
prop="billNo"
|
||||
label="账单号"
|
||||
width="150"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
prop="tradeNo"
|
||||
label="交易流水号"
|
||||
min-width="180"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
>
|
||||
<template #default="{ row }">
|
||||
{{ (row as Invoice).invoiceNo || '—' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="projectName"
|
||||
label="项目名称"
|
||||
@@ -168,21 +238,41 @@ onMounted(() => {
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="订单金额"
|
||||
prop="titleName"
|
||||
label="发票抬头"
|
||||
min-width="180"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="发票类型"
|
||||
width="100"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
{{ INVOICE_TYPE_LABELS[(row as Invoice).invoiceType ?? ''] ?? '—' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
label="开票金额"
|
||||
width="110"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<span class="invoices__amount">¥{{ formatMoney((row as Invoice).amount) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="transactionNo"
|
||||
label="交易流水号"
|
||||
min-width="180"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="状态"
|
||||
width="90"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<StatusTag
|
||||
:label="(row as Invoice).status"
|
||||
:variant="STATUS_VARIANTS[(row as Invoice).status]"
|
||||
:label="statusLabel(row as Invoice)"
|
||||
:variant="statusVariant((row as Invoice).status)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -199,12 +289,12 @@ onMounted(() => {
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<span class="invoices__ops">
|
||||
<template v-if="(row as Invoice).status === '已开票'">
|
||||
<template v-if="(row as Invoice).status === '2'">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
class="invoices__link"
|
||||
@click="onPreview"
|
||||
@click="onPreview(row as Invoice)"
|
||||
>
|
||||
预览
|
||||
</el-button>
|
||||
@@ -212,7 +302,7 @@ onMounted(() => {
|
||||
link
|
||||
type="primary"
|
||||
class="invoices__link"
|
||||
@click="onDownload"
|
||||
@click="onDownload(row as Invoice)"
|
||||
>
|
||||
下载
|
||||
</el-button>
|
||||
@@ -220,21 +310,21 @@ onMounted(() => {
|
||||
link
|
||||
type="primary"
|
||||
class="invoices__link"
|
||||
@click="onSendEmail"
|
||||
@click="onSendEmail(row as Invoice)"
|
||||
>
|
||||
发送邮箱
|
||||
</el-button>
|
||||
</template>
|
||||
<span v-else-if="(row as Invoice).status === '开票中'" class="invoices__dash">—</span>
|
||||
<el-button
|
||||
v-else
|
||||
v-else-if="(row as Invoice).status === '0'"
|
||||
link
|
||||
type="primary"
|
||||
class="invoices__link"
|
||||
@click="onApply(row as Invoice)"
|
||||
@click="onApplyForRow(row as Invoice)"
|
||||
>
|
||||
申请开票
|
||||
</el-button>
|
||||
<span v-else class="invoices__dash">—</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -253,8 +343,18 @@ onMounted(() => {
|
||||
/>
|
||||
|
||||
<p class="invoices__tip text-secondary">
|
||||
开票将使用默认抬头,如需调整请前往 <RouterLink to="/finance/invoice-titles" class="link">管理抬头</RouterLink>。
|
||||
仅已支付且未开票的账单可申请开票,开票进度可在本页查看。抬头管理请前往
|
||||
<RouterLink to="/finance/invoice-titles" class="link">管理抬头</RouterLink>。
|
||||
</p>
|
||||
|
||||
<InvoiceApplyDialog
|
||||
v-model:visible="applyVisible"
|
||||
:bills="availableBills"
|
||||
:titles="titles"
|
||||
:preselect-bill-id="applyBillId"
|
||||
:submitting="applying"
|
||||
@submit="onSubmitApply"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -321,6 +421,11 @@ onMounted(() => {
|
||||
}
|
||||
}
|
||||
|
||||
&__toolbar {
|
||||
.flex(row, space-between, center);
|
||||
gap: @spacing-base;
|
||||
}
|
||||
|
||||
&__tabs {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
@@ -328,6 +433,23 @@ onMounted(() => {
|
||||
gap: @spacing-sm;
|
||||
}
|
||||
|
||||
&__apply {
|
||||
height: 34px;
|
||||
padding: 0 @spacing-base;
|
||||
border: none;
|
||||
border-radius: @radius-base;
|
||||
background: @primary-strong;
|
||||
color: @white;
|
||||
font-size: @font-size-base;
|
||||
font-weight: 500;
|
||||
transition: background 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: @primary-color;
|
||||
color: @white;
|
||||
}
|
||||
}
|
||||
|
||||
&__tab {
|
||||
height: 34px;
|
||||
margin: 0;
|
||||
|
||||
@@ -13,18 +13,25 @@ const { result } = storeToRefs(financeStore)
|
||||
|
||||
const billId = computed(() => String(route.params.id))
|
||||
|
||||
const requirementId = computed(() => {
|
||||
const raw = route.query.requirementId
|
||||
const outTradeNo = computed(() => {
|
||||
const raw = route.query.outTradeNo
|
||||
return String(Array.isArray(raw) ? raw[0] : (raw ?? '')).trim()
|
||||
})
|
||||
|
||||
const ids = computed(() => {
|
||||
const raw = route.query.ids
|
||||
const text = Array.isArray(raw) ? raw.join(',') : String(raw ?? '')
|
||||
const list = text.split(',').map((id) => id.trim()).filter(Boolean)
|
||||
return list.length > 0 ? list : [billId.value]
|
||||
})
|
||||
|
||||
const methodLabel = computed(() => {
|
||||
if (!result.value) return '—'
|
||||
return result.value.method === 'wechat' ? '微信支付' : '支付宝支付'
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
void financeStore.fetchResult(billId.value, requirementId.value)
|
||||
void financeStore.fetchResult(outTradeNo.value, ids.value)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,62 +1,56 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onBeforeUnmount, onMounted } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { AppButton, QrCodePanel } from '@/components'
|
||||
import { usePayPoll } from '@/composables/usePayPoll'
|
||||
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 { payment, currentBill, payOrder } = storeToRefs(financeStore)
|
||||
const { start: startPoll, stop: stopPoll, check } = usePayPoll(onPaySuccess)
|
||||
|
||||
const billId = computed(() => String(route.params.id))
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const methodLabel = '支付宝支付'
|
||||
|
||||
const method = computed<PayMethod>(() => payment.value?.method ?? 'wechat')
|
||||
const steps = [
|
||||
'打开手机支付宝',
|
||||
'对准屏幕上方的二维码进行扫描,核对金额后确认支付',
|
||||
'输入支付密码完成支付,本页将自动跳转至支付结果页',
|
||||
]
|
||||
|
||||
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 onPaySuccess(outTradeNo: string): void {
|
||||
void router.push({
|
||||
path: `/finance/bills/${billId.value}/pay/result`,
|
||||
query: { outTradeNo, ids: billId.value },
|
||||
})
|
||||
}
|
||||
|
||||
function onConfirmMethod(next: PayMethod): void {
|
||||
void financeStore.switchPaymentMethod(billId.value, next)
|
||||
ElMessage.success('二维码已刷新')
|
||||
async function onCheckPaid(): Promise<void> {
|
||||
const outTradeNo = financeStore.payOutTradeNo
|
||||
if (!outTradeNo) return
|
||||
const done = await check(outTradeNo)
|
||||
if (!done) ElMessage.warning('支付结果确认中,请稍后再试')
|
||||
}
|
||||
|
||||
async function onPaid(): Promise<void> {
|
||||
await financeStore.createPayment(billId.value, method.value)
|
||||
void router.push(`/finance/bills/${billId.value}/pay/result`)
|
||||
async function initPayment(): Promise<void> {
|
||||
await financeStore.fetchDetail(billId.value)
|
||||
if (currentBill.value?.status !== '待支付') return
|
||||
await financeStore.createPayment(billId.value, 'alipay')
|
||||
const outTradeNo = financeStore.payOutTradeNo
|
||||
if (outTradeNo) startPoll(outTradeNo)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void Promise.all([
|
||||
financeStore.createPayment(billId.value, 'wechat'),
|
||||
financeStore.fetchDetail(billId.value),
|
||||
])
|
||||
void initPayment()
|
||||
})
|
||||
|
||||
onBeforeUnmount(stopPoll)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -77,11 +71,8 @@ onMounted(() => {
|
||||
<section class="pay__left">
|
||||
<div class="pay__left-top">
|
||||
<p class="pay__method">
|
||||
{{ methodLabel }} · 请使用手机微信 <strong>[扫一扫]</strong> 扫描下方二维码完成支付
|
||||
{{ methodLabel }} · 请使用手机支付宝 <strong>[扫一扫]</strong> 扫描下方二维码完成支付
|
||||
</p>
|
||||
<AppButton class="pay__switch" @click="dialogVisible = true">
|
||||
切换支付方式
|
||||
</AppButton>
|
||||
</div>
|
||||
|
||||
<div class="pay__amount-block">
|
||||
@@ -92,8 +83,8 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<QrCodePanel
|
||||
:expires-in="payment?.qrExpiresInSeconds ?? 300"
|
||||
@refresh="onRefresh"
|
||||
:content="payOrder?.qrCode ?? ''"
|
||||
:countdown="false"
|
||||
/>
|
||||
</section>
|
||||
|
||||
@@ -141,19 +132,13 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<div class="pay__footer">
|
||||
<AppButton type="primary" size="lg" @click="onPaid">
|
||||
完成支付
|
||||
<AppButton type="primary" size="lg" @click="onCheckPaid">
|
||||
我已完成支付
|
||||
</AppButton>
|
||||
<AppButton @click="router.push('/finance/bills')">
|
||||
返回
|
||||
</AppButton>
|
||||
</div>
|
||||
|
||||
<PayMethodDialog
|
||||
v-model:visible="dialogVisible"
|
||||
:method="method"
|
||||
@confirm="onConfirmMethod"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user