支持学费重算与项目收费

This commit is contained in:
biss committed 2026-11-14 21:57:42 +08:00
1 parent 3dce2c0db1
commit 3dacb48b53
16 files changed
+13305 -29

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { ElMessage, ElMessageBox } from 'element-plus'
import http, { apiErrorMessage } from '../api/http'
import { useAuthStore } from '../stores/auth'
interface FeeItem { id: string; name: string; description: string | null; presetAmounts: number[]; allowCustomAmount: boolean; isEnabled: boolean }
interface FeePayment { id: string; itemName: string; amount: number; createdAt: string; studentNumber: string; studentName: string }
const { t, locale } = useI18n()
const auth = useAuthStore()
const student = computed(() => auth.user?.roles.includes('Student') ?? false)
const items = ref<FeeItem[]>([])
const payments = ref<FeePayment[]>([])
const editVisible = ref(false)
const paying = ref(false)
const editingId = ref('')
const form = reactive({ name: '', description: '', presets: '', allowCustomAmount: false, isEnabled: true })
const selections = reactive<Record<string, number | undefined>>({})
const pending = reactive<Record<string, { amount: number; id: string }>>({})
function newRequestId() {
if (typeof crypto.randomUUID === 'function') return crypto.randomUUID()
const bytes = crypto.getRandomValues(new Uint8Array(16))
bytes[6] = (bytes[6]! & 15) | 64; bytes[8] = (bytes[8]! & 63) | 128
const hex = Array.from(bytes, x => x.toString(16).padStart(2, '0')).join('')
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
}
const money = (n: number) => new Intl.NumberFormat(locale.value, { style: 'currency', currency: 'CNY' }).format(n)
async function load() {
try {
const [catalog, history] = await Promise.all([http.get('/fee-catalog'), http.get('/fee-catalog/payments')])
items.value = catalog.data; payments.value = history.data
} catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
function edit(item?: FeeItem) {
editingId.value = item?.id ?? ''
Object.assign(form, { name: item?.name ?? '', description: item?.description ?? '', presets: item?.presetAmounts.join(', ') ?? '', allowCustomAmount: item?.allowCustomAmount ?? false, isEnabled: item?.isEnabled ?? true })
editVisible.value = true
}
async function save() {
const presets = form.presets.trim() ? form.presets.split(/[,,]/).map(x => Number(x.trim())) : []
if (!form.name.trim() || presets.some(x => !Number.isFinite(x) || x <= 0 || Math.abs(Math.round(x * 100) - x * 100) > 1e-7) || (!presets.length && !form.allowCustomAmount)) return ElMessage.warning(t('feeCatalog.invalid'))
try {
const data = { name: form.name, description: form.description, presetAmounts: presets, allowCustomAmount: form.allowCustomAmount, isEnabled: form.isEnabled }
if (editingId.value) await http.put(`/fee-catalog/${editingId.value}`, data); else await http.post('/fee-catalog', data)
editVisible.value = false; ElMessage.success(t('feeCatalog.saved')); await load()
} catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
async function pay(item: FeeItem) {
const amount = selections[item.id]
if (!amount || amount <= 0) return ElMessage.warning(t('feeCatalog.selectAmount'))
try {
await ElMessageBox.confirm(t('feeCatalog.confirmPay', { name: item.name, amount: money(amount) }), t('feeCatalog.pay'), { type: 'warning' })
paying.value = true
const key = `fee-payment:${auth.user?.id}:${item.id}`
if (!pending[item.id]) {
try { const saved = sessionStorage.getItem(key); if (saved) pending[item.id] = JSON.parse(saved) } catch { sessionStorage.removeItem(key) }
}
if (!pending[item.id] || pending[item.id].amount !== amount) pending[item.id] = { amount, id: newRequestId() }
sessionStorage.setItem(key, JSON.stringify(pending[item.id]))
await http.post(`/fee-catalog/${item.id}/pay`, { amount, requestId: pending[item.id].id })
delete pending[item.id]; sessionStorage.removeItem(key); ElMessage.success(t('feeCatalog.paid')); await load()
} catch (error) { if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error)) }
finally { paying.value = false }
}
onMounted(load)
</script>
<template>
<div class="fee-catalog">
<el-card>
<template #header><div class="card-heading"><strong>{{ t('feeCatalog.title') }}</strong><el-button v-if="!student" type="primary" @click="edit()">{{ t('feeCatalog.create') }}</el-button></div></template>
<el-table :data="items">
<el-table-column prop="name" :label="t('feeCatalog.name')" min-width="150" />
<el-table-column prop="description" :label="t('feeCatalog.description')" min-width="180" />
<el-table-column :label="t('feeCatalog.presets')" min-width="170"><template #default="{ row }">{{ (row as FeeItem).presetAmounts.map(money).join(' / ') || '—' }}</template></el-table-column>
<el-table-column v-if="!student" :label="t('feeCatalog.status')" width="110"><template #default="{ row }">{{ (row as FeeItem).isEnabled ? t('feeCatalog.enabled') : t('feeCatalog.disabled') }}</template></el-table-column>
<el-table-column v-if="!student" :label="t('feeCatalog.custom')" width="120"><template #default="{ row }">{{ (row as FeeItem).allowCustomAmount ? t('feeCatalog.yes') : t('feeCatalog.no') }}</template></el-table-column>
<el-table-column :label="t('feeCatalog.actions')" min-width="280"><template #default="{ row }">
<template v-if="student">
<el-select v-if="!(row as FeeItem).allowCustomAmount" v-model="selections[(row as FeeItem).id]" :placeholder="t('feeCatalog.selectAmount')" style="width: 140px"><el-option v-for="amount in (row as FeeItem).presetAmounts" :key="amount" :label="money(amount)" :value="amount" /></el-select>
<template v-else><el-select v-if="(row as FeeItem).presetAmounts.length" v-model="selections[(row as FeeItem).id]" :placeholder="t('feeCatalog.selectAmount')" style="width: 130px"><el-option v-for="amount in (row as FeeItem).presetAmounts" :key="amount" :label="money(amount)" :value="amount" /></el-select><el-input-number v-model="selections[(row as FeeItem).id]" :min="0.01" :max="99999999.99" :precision="2" :controls="false" style="width: 120px" /></template>
<el-button link type="primary" :loading="paying" @click="pay(row as FeeItem)">{{ t('feeCatalog.pay') }}</el-button>
</template>
<el-button v-else link type="primary" @click="edit(row as FeeItem)">{{ t('feeCatalog.edit') }}</el-button>
</template></el-table-column>
</el-table>
</el-card>
<el-card>
<template #header>{{ t('feeCatalog.history') }}</template>
<el-table :data="payments">
<el-table-column v-if="!student" prop="studentNumber" :label="t('tuition.studentNumber')" />
<el-table-column v-if="!student" prop="studentName" :label="t('tuition.student')" />
<el-table-column prop="itemName" :label="t('feeCatalog.name')" />
<el-table-column :label="t('feeCatalog.amount')"><template #default="{ row }">{{ money((row as FeePayment).amount) }}</template></el-table-column>
<el-table-column :label="t('feeCatalog.time')"><template #default="{ row }">{{ new Date((row as FeePayment).createdAt).toLocaleString(locale) }}</template></el-table-column>
</el-table>
</el-card>
<el-dialog v-model="editVisible" :title="t(editingId ? 'feeCatalog.edit' : 'feeCatalog.create')" width="min(560px, 95%)">
<el-form label-position="top">
<el-form-item :label="t('feeCatalog.name')"><el-input v-model="form.name" maxlength="100" /></el-form-item>
<el-form-item :label="t('feeCatalog.description')"><el-input v-model="form.description" maxlength="500" type="textarea" /></el-form-item>
<el-form-item :label="t('feeCatalog.presetsHint')"><el-input v-model="form.presets" placeholder="10, 20, 50" /></el-form-item>
<el-form-item :label="t('feeCatalog.custom')"><el-switch v-model="form.allowCustomAmount" /></el-form-item>
<el-form-item :label="t('feeCatalog.enabled')"><el-switch v-model="form.isEnabled" /></el-form-item>
</el-form>
<template #footer><el-button @click="editVisible = false">{{ t('feeCatalog.cancel') }}</el-button><el-button type="primary" @click="save">{{ t('feeCatalog.save') }}</el-button></template>
</el-dialog>
</div>
</template>
<style scoped>.fee-catalog{display:grid;gap:18px}.card-heading{display:flex;align-items:center;justify-content:space-between}</style>
+42 -4
View File
@@ -5,6 +5,7 @@ import { ElMessage, ElMessageBox } from 'element-plus'
import http, { apiErrorMessage } from '../api/http'
import { downloadApiFile } from '../api/excel'
import { useAuthStore } from '../stores/auth'
import FeeCatalogPanel from './FeeCatalogPanel.vue'
interface Term { id: string; name: string; status: string; creditPrice: number; isCurrent: boolean }
interface Bill {
@@ -18,7 +19,10 @@ const auth = useAuthStore()
const { locale, t } = useI18n()
const isStudent = computed(() => auth.user?.roles.includes('Student') ?? false)
const terms = ref<Term[]>([])
interface Payment { id: string; termName: string; item: string; amount: number; method: string; confirmedAt: string }
const rows = ref<Bill[]>([])
const payments = ref<Payment[]>([])
const activeTab = ref('tuition')
const termId = ref('')
const creditPrice = ref<number | undefined>()
const loading = ref(false)
@@ -37,7 +41,8 @@ async function load() {
loading.value = true
try {
if (isStudent.value) {
rows.value = (await http.get('/tuition/mine')).data
const [bills, history] = await Promise.all([http.get('/tuition/mine'), http.get('/tuition/mine/payments')])
rows.value = bills.data; payments.value = history.data
return
}
const { data } = await http.get('/tuition/terms')
@@ -104,6 +109,13 @@ async function pay(row: Bill, item: string) {
try { await http.post(`/tuition/bills/${row.id}/items/${item}/pay-balance`); ElMessage.success(t('tuition.messages.paid')); await load() }
catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
async function charge(row: Bill, item: string, amount: number) {
try {
await ElMessageBox.confirm(t('feeCatalog.confirmCharge', { name: row.studentName, amount: money(amount) }), t('feeCatalog.charge'), { type: 'warning' })
await http.post(`/tuition/bills/${row.id}/items/${item}/charge-balance`)
ElMessage.success(t('tuition.messages.paid')); await load()
} catch (error) { if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error)) }
}
onMounted(load)
</script>
@@ -115,6 +127,8 @@ onMounted(load)
<span>{{ t('tuition.description') }}</span>
</header>
<el-tabs v-model="activeTab">
<el-tab-pane :label="t(isStudent ? 'feeCatalog.myBill' : 'tuition.managementTitle')" name="tuition">
<el-card v-if="!isStudent" class="workbench">
<div class="toolbar">
<el-select v-model="termId" :placeholder="t('tuition.selectTerm')" @change="page = 1; load()">
@@ -138,7 +152,7 @@ onMounted(load)
<el-table-column v-if="!isStudent" prop="studentName" :label="t('tuition.student')" width="120" />
<el-table-column v-if="isStudent" prop="termName" :label="t('tuition.term')" min-width="160" />
<el-table-column :label="t('tuition.baseTuition')" min-width="155"><template #default="{ row }">{{ money(bill(row).baseTuition) }}<small>{{ t('tuition.remaining', { amount: money(remaining(bill(row).baseTuition, bill(row).basePaid)) }) }}</small></template></el-table-column>
<el-table-column :label="t('tuition.creditFee')" min-width="155"><template #default="{ row }">{{ money(bill(row).creditFee) }}<small>{{ t('tuition.remaining', { amount: money(remaining(bill(row).creditFee, bill(row).creditPaid)) }) }}</small></template></el-table-column>
<el-table-column :label="t('tuition.creditFee')" min-width="155"><template #default="{ row }">{{ money(bill(row).creditFee) }}<small>{{ t('tuition.remaining', { amount: money(remaining(bill(row).creditFee, bill(row).creditPaid)) }) }}</small><small v-if="bill(row).creditPaid > bill(row).creditFee">{{ t('tuition.overpaid', { amount: money(bill(row).creditPaid - bill(row).creditFee) }) }}</small></template></el-table-column>
<el-table-column :label="t('tuition.accommodationFee')" min-width="155"><template #default="{ row }">{{ money(bill(row).accommodationFee) }}<small>{{ t('tuition.remaining', { amount: money(remaining(bill(row).accommodationFee, bill(row).accommodationPaid)) }) }}</small></template></el-table-column>
<el-table-column :label="t('tuition.adjustment')" min-width="155"><template #default="{ row }">{{ money(bill(row).reconciliationAdjustment) }}<small>{{ t('tuition.remaining', { amount: money(remaining(bill(row).reconciliationAdjustment, bill(row).adjustmentPaid)) }) }}</small></template></el-table-column>
<el-table-column v-if="isStudent" :label="t('tuition.balancePayment')" width="260" fixed="right">
@@ -149,13 +163,37 @@ onMounted(load)
<el-button v-if="bill(row).isPayable && remaining(bill(row).reconciliationAdjustment, bill(row).adjustmentPaid) > 0" link type="primary" @click="pay(bill(row), 'ReconciliationAdjustment')">{{ t('tuition.payAdjustment') }}</el-button>
</template>
</el-table-column>
<el-table-column v-else :label="t('tuition.reconciliation')" width="110" fixed="right"><template #default="{ row }"><el-button link type="warning" @click="reconcile(bill(row))">{{ t('tuition.reconcile') }}</el-button></template></el-table-column>
<el-table-column v-else :label="t('feeCatalog.actions')" width="220" fixed="right"><template #default="{ row }">
<el-button link type="warning" @click="reconcile(bill(row))">{{ t('tuition.reconcile') }}</el-button>
<el-dropdown trigger="click" @command="(item: string) => charge(bill(row), item, item === 'BaseTuition' ? remaining(bill(row).baseTuition, bill(row).basePaid) : item === 'CreditFee' ? remaining(bill(row).creditFee, bill(row).creditPaid) : item === 'AccommodationFee' ? remaining(bill(row).accommodationFee, bill(row).accommodationPaid) : remaining(bill(row).reconciliationAdjustment, bill(row).adjustmentPaid))">
<el-button link type="primary">{{ t('feeCatalog.charge') }}</el-button>
<template #dropdown><el-dropdown-menu>
<el-dropdown-item command="BaseTuition" :disabled="remaining(bill(row).baseTuition, bill(row).basePaid) <= 0">{{ t('tuition.baseTuition') }}</el-dropdown-item>
<el-dropdown-item command="CreditFee" :disabled="remaining(bill(row).creditFee, bill(row).creditPaid) <= 0">{{ t('tuition.creditFee') }}</el-dropdown-item>
<el-dropdown-item command="AccommodationFee" :disabled="remaining(bill(row).accommodationFee, bill(row).accommodationPaid) <= 0">{{ t('tuition.accommodationFee') }}</el-dropdown-item>
<el-dropdown-item command="ReconciliationAdjustment" :disabled="remaining(bill(row).reconciliationAdjustment, bill(row).adjustmentPaid) <= 0">{{ t('tuition.adjustment') }}</el-dropdown-item>
</el-dropdown-menu></template>
</el-dropdown>
</template></el-table-column>
</el-table>
<el-pagination v-if="!isStudent && total > pageSize" v-model:current-page="page" :page-size="pageSize" :total="total" layout="total, prev, pager, next" @current-change="load" />
</el-card>
<el-card v-if="isStudent" class="history">
<template #header>{{ t('feeCatalog.tuitionHistory') }}</template>
<el-table :data="payments">
<el-table-column prop="termName" :label="t('tuition.term')" />
<el-table-column :label="t('feeCatalog.name')"><template #default="{ row }">{{ t(`feeCatalog.items.${(row as Payment).item}`) }}</template></el-table-column>
<el-table-column :label="t('feeCatalog.amount')"><template #default="{ row }">{{ money((row as Payment).amount) }}</template></el-table-column>
<el-table-column :label="t('feeCatalog.method')"><template #default="{ row }">{{ t(`feeCatalog.methods.${(row as Payment).method}`) }}</template></el-table-column>
<el-table-column :label="t('feeCatalog.time')"><template #default="{ row }">{{ new Date((row as Payment).confirmedAt).toLocaleString(locale) }}</template></el-table-column>
</el-table>
</el-card>
</el-tab-pane>
<el-tab-pane :label="t('feeCatalog.title')" name="catalog"><FeeCatalogPanel /></el-tab-pane>
</el-tabs>
</section>
</template>
<style scoped>
.tuition{display:grid;gap:18px}.tuition header p{margin:0;color:#17867c;font-size:12px;font-weight:800;letter-spacing:.16em}.tuition h2{margin:6px 0;color:#183b56}.tuition header span,small{color:#738596}.toolbar,.bill-filter{display:flex;gap:10px;flex-wrap:wrap;margin-bottom:14px}.toolbar .el-select,.bill-filter .el-input{width:260px}small{display:block;margin-top:4px}.el-pagination{justify-content:flex-end;margin-top:16px}@media(max-width:720px){.toolbar>*,.bill-filter>*{width:100%!important}}
.tuition{display:grid;gap:18px}.workbench,.history{margin-bottom:18px}.history{margin-top:18px}.tuition header p{margin:0;color:#17867c;font-size:12px;font-weight:800;letter-spacing:.16em}.tuition h2{margin:6px 0;color:#183b56}.tuition header span,small{color:#738596}.toolbar,.bill-filter{display:flex;gap:10px;flex-wrap:wrap;margin-bottom:14px}.toolbar .el-select,.bill-filter .el-input{width:260px}small{display:block;margin-top:4px}.el-pagination{justify-content:flex-end;margin-top:16px}@media(max-width:720px){.toolbar>*,.bill-filter>*{width:100%!important}}
</style>