feat(energy): 实现加氢站配置和价格管理页面
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
147
apps/web-antd/src/views/energy/station-config/data.ts
Normal file
147
apps/web-antd/src/views/energy/station-config/data.ts
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { EnergyStationConfigApi } from '#/api/energy/station-config';
|
||||||
|
|
||||||
|
import { useActionColumn } from '#/utils/table';
|
||||||
|
|
||||||
|
export const DEDUCT_MODE_OPTIONS = [
|
||||||
|
{ label: '审核即扣款', value: true },
|
||||||
|
{ label: '出账单后扣款', value: false },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const AUTO_MATCH_OPTIONS = [
|
||||||
|
{ label: '开启', value: true },
|
||||||
|
{ label: '关闭', value: false },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const COOPERATION_TYPE_OPTIONS = [
|
||||||
|
{ label: '预充值', value: 1 },
|
||||||
|
{ label: '月结算', value: 2 },
|
||||||
|
];
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
fieldName: 'id',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'stationId',
|
||||||
|
label: '加氢站',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入加氢站ID',
|
||||||
|
style: { width: '100%' },
|
||||||
|
},
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'cooperationType',
|
||||||
|
label: '合作模式',
|
||||||
|
component: 'RadioGroup',
|
||||||
|
componentProps: {
|
||||||
|
options: COOPERATION_TYPE_OPTIONS,
|
||||||
|
buttonStyle: 'solid',
|
||||||
|
optionType: 'button',
|
||||||
|
},
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'autoDeduct',
|
||||||
|
label: '扣款模式',
|
||||||
|
component: 'RadioGroup',
|
||||||
|
componentProps: {
|
||||||
|
options: DEDUCT_MODE_OPTIONS,
|
||||||
|
buttonStyle: 'solid',
|
||||||
|
optionType: 'button',
|
||||||
|
},
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'autoMatch',
|
||||||
|
label: '自动匹配',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
options: AUTO_MATCH_OPTIONS,
|
||||||
|
placeholder: '请选择是否开启自动匹配',
|
||||||
|
},
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'remark',
|
||||||
|
label: '备注',
|
||||||
|
component: 'Textarea',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入备注',
|
||||||
|
rows: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 搜索表单 */
|
||||||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'stationName',
|
||||||
|
label: '站点名称',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入站点名称',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'autoDeduct',
|
||||||
|
label: '扣款模式',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
options: DEDUCT_MODE_OPTIONS,
|
||||||
|
placeholder: '请选择扣款模式',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 表格列配置 */
|
||||||
|
export function useGridColumns(): VxeTableGridOptions<EnergyStationConfigApi.Config>['columns'] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
field: 'stationName',
|
||||||
|
title: '站点名称',
|
||||||
|
minWidth: 150,
|
||||||
|
fixed: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'cooperationType',
|
||||||
|
title: '合作模式',
|
||||||
|
minWidth: 120,
|
||||||
|
slots: { default: 'cooperationType' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'autoDeduct',
|
||||||
|
title: '扣款模式',
|
||||||
|
minWidth: 130,
|
||||||
|
slots: { default: 'autoDeduct' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'autoMatch',
|
||||||
|
title: '自动匹配',
|
||||||
|
minWidth: 100,
|
||||||
|
slots: { default: 'autoMatch' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 180,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
useActionColumn(1),
|
||||||
|
];
|
||||||
|
}
|
||||||
133
apps/web-antd/src/views/energy/station-config/index.vue
Normal file
133
apps/web-antd/src/views/energy/station-config/index.vue
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { EnergyStationConfigApi } from '#/api/energy/station-config';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { Tag } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import { getStationConfigPage } from '#/api/energy/station-config';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import {
|
||||||
|
COOPERATION_TYPE_OPTIONS,
|
||||||
|
useGridColumns,
|
||||||
|
useGridFormSchema,
|
||||||
|
} from './data';
|
||||||
|
import FormModal from './modules/form-modal.vue';
|
||||||
|
|
||||||
|
const [Form, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: FormModal,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function handleRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建站点配置 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData(null).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑站点配置 */
|
||||||
|
function handleEdit(row: EnergyStationConfigApi.Config) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
formOptions: {
|
||||||
|
collapsed: true,
|
||||||
|
schema: useGridFormSchema(),
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useGridColumns(),
|
||||||
|
height: 'auto',
|
||||||
|
keepSource: true,
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
return await getStationConfigPage({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: true,
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<EnergyStationConfigApi.Config>,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<Form @success="handleRefresh" />
|
||||||
|
<Grid table-title="站点配置列表">
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['站点配置']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['energy:station-config:create'],
|
||||||
|
onClick: handleCreate,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #cooperationType="{ row }">
|
||||||
|
<Tag
|
||||||
|
v-if="row.cooperationType != null"
|
||||||
|
:color="
|
||||||
|
COOPERATION_TYPE_OPTIONS.find(
|
||||||
|
(o) => o.value === row.cooperationType,
|
||||||
|
)?.value === 1
|
||||||
|
? 'blue'
|
||||||
|
: 'purple'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
COOPERATION_TYPE_OPTIONS.find(
|
||||||
|
(o) => o.value === row.cooperationType,
|
||||||
|
)?.label ?? '—'
|
||||||
|
}}
|
||||||
|
</Tag>
|
||||||
|
<span v-else>—</span>
|
||||||
|
</template>
|
||||||
|
<template #autoDeduct="{ row }">
|
||||||
|
<Tag :color="row.autoDeduct ? 'orange' : 'cyan'">
|
||||||
|
{{ row.autoDeduct ? '审核即扣款' : '出账单后扣款' }}
|
||||||
|
</Tag>
|
||||||
|
</template>
|
||||||
|
<template #autoMatch="{ row }">
|
||||||
|
<Tag :color="row.autoMatch ? 'green' : 'default'">
|
||||||
|
{{ row.autoMatch ? '开启' : '关闭' }}
|
||||||
|
</Tag>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'link',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['energy:station-config:update'],
|
||||||
|
onClick: handleEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import type { EnergyStationConfigApi } from '#/api/energy/station-config';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import {
|
||||||
|
createStationConfig,
|
||||||
|
updateStationConfig,
|
||||||
|
} from '#/api/energy/station-config';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<EnergyStationConfigApi.Config>();
|
||||||
|
const isUpdate = computed(() => !!formData.value?.id);
|
||||||
|
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return isUpdate.value
|
||||||
|
? $t('ui.actionTitle.edit', ['站点配置'])
|
||||||
|
: $t('ui.actionTitle.create', ['站点配置']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 120,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
const data = (await formApi.getValues()) as EnergyStationConfigApi.Config;
|
||||||
|
try {
|
||||||
|
await (isUpdate.value
|
||||||
|
? updateStationConfig(data)
|
||||||
|
: createStationConfig(data));
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
formData.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = modalApi.getData<EnergyStationConfigApi.Config>();
|
||||||
|
if (!data || !data.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
|
// 编辑时禁用加氢站选择
|
||||||
|
await formApi.updateSchema([
|
||||||
|
{
|
||||||
|
fieldName: 'stationId',
|
||||||
|
componentProps: { disabled: true },
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle" class="w-2/3">
|
||||||
|
<Form class="mx-4" />
|
||||||
|
<div class="mx-4 mb-4 rounded bg-blue-50 px-3 py-2 text-sm text-blue-600">
|
||||||
|
此配置仅对预充值模式客户生效,月结算客户不涉及账户扣款
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
178
apps/web-antd/src/views/energy/station-price/data.ts
Normal file
178
apps/web-antd/src/views/energy/station-price/data.ts
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { EnergyStationPriceApi } from '#/api/energy/station-price';
|
||||||
|
|
||||||
|
import { useActionColumn } from '#/utils/table';
|
||||||
|
|
||||||
|
export const PRICE_STATUS_OPTIONS = [
|
||||||
|
{ label: '生效中', value: 1, color: 'green' },
|
||||||
|
{ label: '已过期', value: 0, color: 'default' },
|
||||||
|
];
|
||||||
|
|
||||||
|
/** 新增/修改的表单 */
|
||||||
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
fieldName: 'id',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'stationId',
|
||||||
|
label: '加氢站',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入加氢站ID',
|
||||||
|
style: { width: '100%' },
|
||||||
|
},
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'customerId',
|
||||||
|
label: '客户',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入客户ID',
|
||||||
|
style: { width: '100%' },
|
||||||
|
},
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'costPrice',
|
||||||
|
label: '成本价(元/KG)',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入成本价',
|
||||||
|
min: 0,
|
||||||
|
precision: 2,
|
||||||
|
style: { width: '100%' },
|
||||||
|
},
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'customerPrice',
|
||||||
|
label: '客户价(元/KG)',
|
||||||
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入客户价',
|
||||||
|
min: 0,
|
||||||
|
precision: 2,
|
||||||
|
style: { width: '100%' },
|
||||||
|
},
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'effectiveDate',
|
||||||
|
label: '生效日期',
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择生效日期',
|
||||||
|
format: 'YYYY-MM-DD',
|
||||||
|
valueFormat: 'YYYY-MM-DD',
|
||||||
|
},
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'expiryDate',
|
||||||
|
label: '过期日期',
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择过期日期(可选)',
|
||||||
|
format: 'YYYY-MM-DD',
|
||||||
|
valueFormat: 'YYYY-MM-DD',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 搜索表单 */
|
||||||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'stationName',
|
||||||
|
label: '站点名称',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入站点名称',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'customerName',
|
||||||
|
label: '客户名称',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入客户名称',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'status',
|
||||||
|
label: '状态',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
options: PRICE_STATUS_OPTIONS,
|
||||||
|
placeholder: '请选择状态',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 表格列配置 */
|
||||||
|
export function useGridColumns(): VxeTableGridOptions<EnergyStationPriceApi.Price>['columns'] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
field: 'stationName',
|
||||||
|
title: '站点名称',
|
||||||
|
minWidth: 150,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'customerName',
|
||||||
|
title: '客户名称',
|
||||||
|
minWidth: 150,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'costPrice',
|
||||||
|
title: '成本价',
|
||||||
|
minWidth: 100,
|
||||||
|
align: 'right',
|
||||||
|
slots: { default: 'costPrice' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'customerPrice',
|
||||||
|
title: '客户价',
|
||||||
|
minWidth: 100,
|
||||||
|
align: 'right',
|
||||||
|
slots: { default: 'customerPrice' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'effectiveDate',
|
||||||
|
title: '生效日期',
|
||||||
|
minWidth: 120,
|
||||||
|
formatter: 'formatDate',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'expiryDate',
|
||||||
|
title: '过期日期',
|
||||||
|
minWidth: 120,
|
||||||
|
slots: { default: 'expiryDate' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'status',
|
||||||
|
title: '状态',
|
||||||
|
minWidth: 100,
|
||||||
|
slots: { default: 'status' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
title: '创建时间',
|
||||||
|
minWidth: 180,
|
||||||
|
formatter: 'formatDateTime',
|
||||||
|
},
|
||||||
|
useActionColumn(2),
|
||||||
|
];
|
||||||
|
}
|
||||||
155
apps/web-antd/src/views/energy/station-price/index.vue
Normal file
155
apps/web-antd/src/views/energy/station-price/index.vue
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { EnergyStationPriceApi } from '#/api/energy/station-price';
|
||||||
|
|
||||||
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { message, Tag } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import {
|
||||||
|
deleteStationPrice,
|
||||||
|
getStationPricePage,
|
||||||
|
} from '#/api/energy/station-price';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { PRICE_STATUS_OPTIONS, useGridColumns, useGridFormSchema } from './data';
|
||||||
|
import FormModal from './modules/form-modal.vue';
|
||||||
|
|
||||||
|
const [Form, formModalApi] = useVbenModal({
|
||||||
|
connectedComponent: FormModal,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function handleRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建价格 */
|
||||||
|
function handleCreate() {
|
||||||
|
formModalApi.setData(null).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑价格 */
|
||||||
|
function handleEdit(row: EnergyStationPriceApi.Price) {
|
||||||
|
formModalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除价格 */
|
||||||
|
async function handleDelete(row: EnergyStationPriceApi.Price) {
|
||||||
|
const hideLoading = message.loading({
|
||||||
|
content: $t('ui.actionMessage.deleting', [row.stationName]),
|
||||||
|
duration: 0,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteStationPrice(row.id!);
|
||||||
|
message.success($t('ui.actionMessage.deleteSuccess', [row.stationName]));
|
||||||
|
handleRefresh();
|
||||||
|
} finally {
|
||||||
|
hideLoading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
formOptions: {
|
||||||
|
collapsed: true,
|
||||||
|
schema: useGridFormSchema(),
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useGridColumns(),
|
||||||
|
height: 'auto',
|
||||||
|
keepSource: true,
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
return await getStationPricePage({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: true,
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<EnergyStationPriceApi.Price>,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<Form @success="handleRefresh" />
|
||||||
|
<Grid table-title="价格管理列表">
|
||||||
|
<template #toolbar-tools>
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.create', ['价格']),
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['energy:station-price:create'],
|
||||||
|
onClick: handleCreate,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #costPrice="{ row }">
|
||||||
|
<span class="font-bold text-orange-600">
|
||||||
|
{{ row.costPrice != null ? row.costPrice.toFixed(2) : '—' }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #customerPrice="{ row }">
|
||||||
|
<span class="font-bold text-blue-600">
|
||||||
|
{{ row.customerPrice != null ? row.customerPrice.toFixed(2) : '—' }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #expiryDate="{ row }">
|
||||||
|
{{ row.expiryDate ?? '—' }}
|
||||||
|
</template>
|
||||||
|
<template #status="{ row }">
|
||||||
|
<Tag
|
||||||
|
:color="
|
||||||
|
PRICE_STATUS_OPTIONS.find((o) => o.value === row.status)?.color ??
|
||||||
|
'default'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
PRICE_STATUS_OPTIONS.find((o) => o.value === row.status)?.label ??
|
||||||
|
'—'
|
||||||
|
}}
|
||||||
|
</Tag>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'link',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['energy:station-price:update'],
|
||||||
|
onClick: handleEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.delete'),
|
||||||
|
type: 'link',
|
||||||
|
danger: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['energy:station-price:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: $t('ui.actionMessage.deleteConfirm', [row.stationName]),
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import type { EnergyStationPriceApi } from '#/api/energy/station-price';
|
||||||
|
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import {
|
||||||
|
createStationPrice,
|
||||||
|
updateStationPrice,
|
||||||
|
} from '#/api/energy/station-price';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<EnergyStationPriceApi.Price>();
|
||||||
|
const isUpdate = computed(() => !!formData.value?.id);
|
||||||
|
|
||||||
|
const getTitle = computed(() => {
|
||||||
|
return isUpdate.value
|
||||||
|
? $t('ui.actionTitle.edit', ['价格'])
|
||||||
|
: $t('ui.actionTitle.create', ['价格']);
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 120,
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: useFormSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
const data = (await formApi.getValues()) as EnergyStationPriceApi.Price;
|
||||||
|
try {
|
||||||
|
await (isUpdate.value
|
||||||
|
? updateStationPrice(data)
|
||||||
|
: createStationPrice(data));
|
||||||
|
await modalApi.close();
|
||||||
|
emit('success');
|
||||||
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen: boolean) {
|
||||||
|
if (!isOpen) {
|
||||||
|
formData.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = modalApi.getData<EnergyStationPriceApi.Price>();
|
||||||
|
if (!data || !data.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
|
} finally {
|
||||||
|
modalApi.unlock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal :title="getTitle" class="w-2/3">
|
||||||
|
<Form class="mx-4" />
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user