<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { BaseDataEntity } from '../data';
|
|
import { useVbenModal } from '@vben/common-ui';
|
import { $t } from '@vben/locales';
|
import { downloadFileFromBlobPart } from '@vben/utils';
|
|
import { message } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
|
import Form from './form.vue';
|
import PriceCalc from './price-calc.vue';
|
|
const props = defineProps<{ config: BaseDataEntity }>();
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
const [PriceCalcModal, priceCalcModalApi] = useVbenModal({
|
connectedComponent: PriceCalc,
|
destroyOnClose: true,
|
});
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 新增 */
|
function handleCreate() {
|
formModalApi.setData({ config: props.config, formType: 'create' }).open();
|
}
|
|
/** 查看 */
|
function handleDetail(row: any) {
|
formModalApi
|
.setData({ config: props.config, formType: 'detail', id: row.id })
|
.open();
|
}
|
|
/** 编辑 */
|
function handleEdit(row: any) {
|
formModalApi
|
.setData({ config: props.config, formType: 'update', id: row.id })
|
.open();
|
}
|
|
/** 删除 */
|
async function handleDelete(row: any) {
|
const hideLoading = message.loading({
|
content: $t('ui.actionMessage.deleting', [row.name ?? row.code ?? '']),
|
duration: 0,
|
});
|
try {
|
await props.config.api.remove(row.id);
|
message.success($t('ui.actionMessage.deleteSuccess', [row.name ?? row.code ?? '']));
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 导出 */
|
async function handleExport() {
|
const data = await props.config.api.exportExcel(
|
await gridApi.formApi.getValues(),
|
);
|
downloadFileFromBlobPart({ fileName: `${props.config.title}.xls`, source: data });
|
}
|
|
/** 阶梯电价测算 */
|
function handleCalc() {
|
priceCalcModalApi.open();
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: props.config.gridFormSchema,
|
},
|
gridOptions: {
|
columns: props.config.columns,
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) =>
|
await props.config.api.page({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
}),
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<any>,
|
});
|
</script>
|
|
<template>
|
<FormModal @success="handleRefresh" />
|
<PriceCalcModal v-if="config.key === 'tieredPrice'" />
|
<Grid :table-title="`${config.title}列表`">
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: $t('ui.actionTitle.create', [config.title]),
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['mes:pd-basedata:create'],
|
onClick: handleCreate,
|
},
|
{
|
label: '阶梯电价测算',
|
type: 'primary',
|
icon: ACTION_ICON.CALC,
|
auth: ['mes:pd-basedata:query'],
|
ifShow: config.key === 'tieredPrice',
|
onClick: handleCalc,
|
},
|
{
|
label: $t('ui.actionTitle.export'),
|
type: 'primary',
|
icon: ACTION_ICON.DOWNLOAD,
|
auth: ['mes:pd-basedata:export'],
|
onClick: handleExport,
|
},
|
]"
|
/>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: $t('common.edit'),
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['mes:pd-basedata:update'],
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: $t('common.delete'),
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['mes:pd-basedata:delete'],
|
popConfirm: {
|
title: $t('ui.actionMessage.deleteConfirm', [
|
row.name ?? row.code ?? '',
|
]),
|
confirm: handleDelete.bind(null, row),
|
},
|
},
|
{
|
label: $t('common.detail'),
|
type: 'link',
|
icon: ACTION_ICON.VIEW,
|
auth: ['mes:pd-basedata:query'],
|
onClick: handleDetail.bind(null, row),
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</template>
|