feat(energy): 实现能源账单列表页(含生成弹窗)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
kkfluous
2026-03-16 01:36:07 +08:00
parent 12d19c93e9
commit ad84c21e84
3 changed files with 599 additions and 0 deletions

View File

@@ -0,0 +1,188 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { EnergyBillApi } from '#/api/energy/bill';
import { useActionColumn } from '#/utils/table';
export const COOPERATION_TYPE_OPTIONS = [
{ label: '预充值', value: 1, color: 'blue' },
{ label: '月结算', value: 2, color: 'pink' },
];
export const BILL_STATUS_OPTIONS = [
{ label: '草稿', value: 0, color: 'orange' },
{ label: '已确认', value: 1, color: 'green' },
];
export const BILL_AUDIT_STATUS_OPTIONS = [
{ label: '待审核', value: 0, color: 'orange' },
{ label: '已通过', value: 1, color: 'green' },
{ label: '已驳回', value: 2, color: 'red' },
];
export const PAYMENT_STATUS_OPTIONS = [
{ label: '未支付', value: 0, color: 'default' },
{ label: '部分支付', value: 1, color: 'orange' },
{ label: '已支付', value: 2, color: 'green' },
];
/** 搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'customerName',
label: '客户名称',
component: 'Input',
componentProps: {
placeholder: '请输入客户名称',
allowClear: true,
},
},
{
fieldName: 'stationName',
label: '加氢站',
component: 'Input',
componentProps: {
placeholder: '请输入加氢站',
allowClear: true,
},
},
{
fieldName: 'billPeriod',
label: '账单周期',
component: 'DatePicker',
componentProps: {
picker: 'month',
format: 'YYYY-MM',
valueFormat: 'YYYY-MM',
placeholder: '选择月份',
allowClear: true,
class: 'w-full',
},
},
{
fieldName: 'cooperationType',
label: '合作模式',
component: 'Select',
componentProps: {
options: COOPERATION_TYPE_OPTIONS,
placeholder: '请选择合作模式',
allowClear: true,
},
},
{
fieldName: 'status',
label: '账单状态',
component: 'Select',
componentProps: {
options: BILL_STATUS_OPTIONS,
placeholder: '请选择账单状态',
allowClear: true,
},
},
{
fieldName: 'auditStatus',
label: '审核状态',
component: 'Select',
componentProps: {
options: BILL_AUDIT_STATUS_OPTIONS,
placeholder: '请选择审核状态',
allowClear: true,
},
},
{
fieldName: 'paymentStatus',
label: '付款状态',
component: 'Select',
componentProps: {
options: PAYMENT_STATUS_OPTIONS,
placeholder: '请选择付款状态',
allowClear: true,
},
},
];
}
/** 表格列配置 */
export function useGridColumns(): VxeTableGridOptions<EnergyBillApi.Bill>['columns'] {
return [
{
field: 'billCode',
title: '账单编号',
minWidth: 180,
fixed: 'left',
slots: { default: 'billCode' },
},
{
field: 'customerName',
title: '客户名称',
minWidth: 150,
},
{
field: 'stationName',
title: '加氢站',
minWidth: 150,
},
{
field: 'cooperationType',
title: '合作模式',
minWidth: 100,
align: 'center',
slots: { default: 'cooperationType' },
},
{
field: 'billPeriodStart',
title: '账单周期',
minWidth: 100,
align: 'center',
formatter: ({ row }: { row: EnergyBillApi.Bill }) => {
if (row.billPeriodStart) {
return row.billPeriodStart.substring(0, 7);
}
return '—';
},
},
{
field: 'receivableAmount',
title: '应收金额',
minWidth: 100,
align: 'right',
},
{
field: 'adjustmentAmount',
title: '调整金额',
minWidth: 100,
align: 'right',
slots: { default: 'adjustmentAmount' },
},
{
field: 'actualAmount',
title: '实收金额',
minWidth: 100,
align: 'right',
slots: { default: 'actualAmount' },
},
{
field: 'status',
title: '账单状态',
minWidth: 100,
align: 'center',
slots: { default: 'status' },
},
{
field: 'auditStatus',
title: '审核状态',
minWidth: 100,
align: 'center',
slots: { default: 'auditStatus' },
},
{
field: 'paymentStatus',
title: '付款状态',
minWidth: 100,
align: 'center',
slots: { default: 'paymentStatus' },
},
useActionColumn(3),
];
}

View File

@@ -0,0 +1,275 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { EnergyBillApi } from '#/api/energy/bill';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { Tag, message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteBill,
exportBill,
getBillPage,
} from '#/api/energy/bill';
import { $t } from '#/locales';
import {
BILL_AUDIT_STATUS_OPTIONS,
BILL_STATUS_OPTIONS,
COOPERATION_TYPE_OPTIONS,
PAYMENT_STATUS_OPTIONS,
useGridColumns,
useGridFormSchema,
} from './data';
import GenerateModal from './modules/generate-modal.vue';
const router = useRouter();
const generateModalRef = ref<InstanceType<typeof GenerateModal>>();
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 导出 */
async function handleExport() {
const formValues = await gridApi.formApi?.getValues();
const blob = await exportBill(formValues ?? {});
downloadFileFromBlobPart({ fileName: '能源账单.xlsx', source: blob });
}
/** 生成账单 */
function handleGenerate() {
generateModalRef.value?.open('single');
}
/** 批量生成 */
function handleBatchGenerate() {
generateModalRef.value?.open('batch');
}
/** 跳转详情 */
function handleView(row: EnergyBillApi.Bill) {
router.push({ name: 'EnergyBillDetail', params: { id: row.id } });
}
/** 编辑(占位) */
function handleEdit(_row: EnergyBillApi.Bill) {
// TODO: open edit modal
}
/** 删除 */
async function handleDelete(row: EnergyBillApi.Bill) {
try {
await deleteBill(row.id!);
message.success('删除成功');
handleRefresh();
} catch (e: any) {
message.error(e.message || '删除失败');
}
}
/** 审核跳转详情 */
function handleAudit(row: EnergyBillApi.Bill) {
router.push({ name: 'EnergyBillDetail', params: { id: row.id } });
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
collapsed: true,
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getBillPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<EnergyBillApi.Bill>,
});
</script>
<template>
<Page auto-content-height>
<GenerateModal ref="generateModalRef" @success="handleRefresh" />
<Grid table-title="能源账单列表">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: '生成账单',
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['energy:bill:create'],
onClick: handleGenerate,
},
{
label: '批量生成',
icon: ACTION_ICON.ADD,
auth: ['energy:bill:create'],
onClick: handleBatchGenerate,
},
{
label: $t('ui.actionTitle.export'),
icon: ACTION_ICON.DOWNLOAD,
auth: ['energy:bill:export'],
onClick: handleExport,
},
]"
/>
</template>
<!-- 账单编号 - router-link -->
<template #billCode="{ row }">
<router-link
:to="{ name: 'EnergyBillDetail', params: { id: row.id } }"
class="text-blue-500 hover:underline"
>
{{ row.billCode }}
</router-link>
</template>
<!-- 合作模式 -->
<template #cooperationType="{ row }">
<Tag
v-if="row.cooperationType != null"
:color="
COOPERATION_TYPE_OPTIONS.find(
(o) => o.value === row.cooperationType,
)?.color
"
>
{{
COOPERATION_TYPE_OPTIONS.find(
(o) => o.value === row.cooperationType,
)?.label ?? row.cooperationType
}}
</Tag>
<span v-else></span>
</template>
<!-- 调整金额 - 负数红色 -->
<template #adjustmentAmount="{ row }">
<span :class="{ 'text-red-500': (row.adjustmentAmount ?? 0) < 0 }">
{{ row.adjustmentAmount ?? '—' }}
</span>
</template>
<!-- 实收金额 - 加粗 -->
<template #actualAmount="{ row }">
<span class="font-bold">{{ row.actualAmount ?? '—' }}</span>
</template>
<!-- 账单状态 -->
<template #status="{ row }">
<Tag
v-if="row.status != null"
:color="
BILL_STATUS_OPTIONS.find((o) => o.value === row.status)?.color
"
>
{{
BILL_STATUS_OPTIONS.find((o) => o.value === row.status)?.label ??
row.status
}}
</Tag>
<span v-else></span>
</template>
<!-- 审核状态 -->
<template #auditStatus="{ row }">
<Tag
v-if="row.auditStatus != null"
:color="
BILL_AUDIT_STATUS_OPTIONS.find((o) => o.value === row.auditStatus)
?.color
"
>
{{
BILL_AUDIT_STATUS_OPTIONS.find((o) => o.value === row.auditStatus)
?.label ?? row.auditStatus
}}
</Tag>
<span v-else></span>
</template>
<!-- 付款状态 -->
<template #paymentStatus="{ row }">
<Tag
v-if="row.paymentStatus != null"
:color="
PAYMENT_STATUS_OPTIONS.find((o) => o.value === row.paymentStatus)
?.color
"
>
{{
PAYMENT_STATUS_OPTIONS.find((o) => o.value === row.paymentStatus)
?.label ?? row.paymentStatus
}}
</Tag>
<span v-else></span>
</template>
<!-- 操作列 -->
<template #actions="{ row }">
<TableAction
:actions="[
{
label: '详情',
type: 'link',
icon: ACTION_ICON.VIEW,
onClick: () => handleView(row),
},
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
show: row.status === 0,
auth: ['energy:bill:update'],
onClick: () => handleEdit(row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
show: row.status === 0,
auth: ['energy:bill:delete'],
onClick: () => handleDelete(row),
},
{
label: '审核',
type: 'link',
icon: ACTION_ICON.AUDIT,
show: row.status === 1 && row.auditStatus === 0,
auth: ['energy:bill:audit'],
onClick: () => handleAudit(row),
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,136 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { Alert, DatePicker, InputNumber, message, Modal } from 'ant-design-vue';
import dayjs from 'dayjs';
import {
batchGenerateByPeriod,
generateBill,
} from '#/api/energy/bill';
import type { EnergyBillApi } from '#/api/energy/bill';
const emit = defineEmits(['success']);
const visible = ref(false);
const loading = ref(false);
const mode = ref<'batch' | 'single'>('single');
// Single mode fields
const customerId = ref<number>();
const contractId = ref<number>();
const stationId = ref<number>();
const billPeriod = ref<any>();
function open(m: 'batch' | 'single' = 'single') {
mode.value = m;
customerId.value = undefined;
contractId.value = undefined;
stationId.value = undefined;
billPeriod.value = undefined;
visible.value = true;
}
async function handleConfirm() {
if (!billPeriod.value) {
message.warning('请选择账单周期');
return;
}
loading.value = true;
try {
const periodStr = dayjs(billPeriod.value).format('YYYY-MM');
if (mode.value === 'single') {
if (!customerId.value || !stationId.value) {
message.warning('请填写完整信息');
loading.value = false;
return;
}
const data: EnergyBillApi.GenerateReq = {
customerId: customerId.value,
contractId: contractId.value!,
stationId: stationId.value,
billPeriodStart: dayjs(billPeriod.value).startOf('month').format('YYYY-MM-DD'),
billPeriodEnd: dayjs(billPeriod.value).endOf('month').format('YYYY-MM-DD'),
};
await generateBill(data);
message.success('账单生成成功');
} else {
const result = await batchGenerateByPeriod(periodStr);
const generated = result.generatedCount ?? 0;
const skipped = result.skippedCount ?? 0;
message.success(`批量生成完成:成功 ${generated} 条,跳过 ${skipped}`);
}
visible.value = false;
emit('success');
} catch (e: any) {
message.error(e.message || '生成失败');
} finally {
loading.value = false;
}
}
defineExpose({ open });
</script>
<template>
<Modal
v-model:open="visible"
:title="mode === 'single' ? '生成账单' : '批量生成账单'"
:confirm-loading="loading"
@ok="handleConfirm"
@cancel="visible = false"
>
<template v-if="mode === 'single'">
<div class="mb-4">
<label class="mb-1 block font-medium">
客户 <span class="text-red-500">*</span>
</label>
<InputNumber
v-model:value="customerId"
placeholder="请输入客户ID"
class="w-full"
/>
</div>
<div class="mb-4">
<label class="mb-1 block font-medium">合同</label>
<InputNumber
v-model:value="contractId"
placeholder="请输入合同ID"
class="w-full"
/>
</div>
<div class="mb-4">
<label class="mb-1 block font-medium">
加氢站 <span class="text-red-500">*</span>
</label>
<InputNumber
v-model:value="stationId"
placeholder="请输入站点ID"
class="w-full"
/>
</div>
</template>
<div class="mb-4">
<label class="mb-1 block font-medium">
账单周期 <span class="text-red-500">*</span>
</label>
<DatePicker
v-model:value="billPeriod"
picker="month"
class="w-full"
placeholder="选择月份"
/>
</div>
<Alert
v-if="mode === 'single'"
type="info"
show-icon
message="系统将自动汇总该客户+合同+站点在所选周期内已审核且未出账的加氢明细,生成草稿账单。"
/>
<Alert
v-if="mode === 'batch'"
type="info"
show-icon
message="系统将自动为所有有未出账明细的客户+合同+站点组合生成当月草稿账单。"
/>
</Modal>
</template>