feat(wms): 优化 md unit 的迁移代码
parent
c11db17376
commit
b35ce18c6e
|
|
@ -5,14 +5,15 @@ import { requestClient } from '#/api/request';
|
|||
export namespace MesMdUnitMeasureApi {
|
||||
/** MES 计量单位 */
|
||||
export interface UnitMeasure {
|
||||
id: number;
|
||||
code?: string;
|
||||
name?: string;
|
||||
primaryFlag?: boolean;
|
||||
primaryId?: number;
|
||||
changeRate?: number;
|
||||
status?: number;
|
||||
remark?: string;
|
||||
id?: number; // 单位编号
|
||||
code?: string; // 单位编码
|
||||
name?: string; // 单位名称
|
||||
primaryFlag?: boolean; // 是否主单位
|
||||
primaryId?: number; // 主单位编号
|
||||
changeRate?: number; // 与主单位换算比例
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
createTime?: Date; // 创建时间
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +55,6 @@ export function deleteUnitMeasure(id: number) {
|
|||
}
|
||||
|
||||
/** 导出计量单位 */
|
||||
export function exportUnitMeasure(params: any) {
|
||||
export function exportUnitMeasure(params: PageParam) {
|
||||
return requestClient.download('/mes/md/unit-measure/export-excel', { params });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,17 +29,18 @@ const emit = defineEmits<{
|
|||
'update:modelValue': [value: number | undefined];
|
||||
}>();
|
||||
|
||||
const allList = ref<MesMdUnitMeasureApi.UnitMeasure[]>([]);
|
||||
const filteredList = ref<MesMdUnitMeasureApi.UnitMeasure[]>([]);
|
||||
const selectedItem = ref<MesMdUnitMeasureApi.UnitMeasure>();
|
||||
const allList = ref<MesMdUnitMeasureApi.UnitMeasure[]>([]); // 计量单位列表
|
||||
const filteredList = ref<MesMdUnitMeasureApi.UnitMeasure[]>([]); // 过滤后的计量单位列表
|
||||
const selectedItem = ref<MesMdUnitMeasureApi.UnitMeasure>(); // 当前选中计量单位
|
||||
|
||||
const selectValue = computed({
|
||||
const selectValue = computed({ // 选择器绑定值
|
||||
get: () => props.modelValue,
|
||||
set: (value: number | undefined) => {
|
||||
emit('update:modelValue', value);
|
||||
},
|
||||
});
|
||||
|
||||
/** 前端按名称和编码过滤计量单位 */
|
||||
function handleFilter(input: string, option: any) {
|
||||
const keyword = input.toLowerCase();
|
||||
const item = option?.item as MesMdUnitMeasureApi.UnitMeasure | undefined;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,196 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdUnitMeasureApi } from '#/api/mes/md/unitmeasure';
|
||||
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getUnitMeasureSimpleList } from '#/api/mes/md/unitmeasure';
|
||||
|
||||
/** 新增/修改计量单位的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '单位编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入单位编码',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '单位名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入单位名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'primaryFlag',
|
||||
label: '是否主单位',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
|
||||
},
|
||||
rules: z.boolean().default(true),
|
||||
},
|
||||
{
|
||||
fieldName: 'primaryId',
|
||||
label: '主单位',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
api: async () => {
|
||||
const list = await getUnitMeasureSimpleList();
|
||||
return list.filter((item) => item.primaryFlag === true);
|
||||
},
|
||||
labelField: 'name',
|
||||
placeholder: '请选择主单位',
|
||||
valueField: 'id',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['primaryFlag'],
|
||||
show: (values) => values.primaryFlag === false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'changeRate',
|
||||
label: '与主单位换算比例',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
min: 0,
|
||||
precision: 4,
|
||||
step: 1,
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['primaryFlag'],
|
||||
show: (values) => values.primaryFlag === false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '单位编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入单位编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '单位名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入单位名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<MesMdUnitMeasureApi.UnitMeasure>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'code',
|
||||
title: '单位编码',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '单位名称',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'primaryFlag',
|
||||
title: '是否主单位',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'changeRate',
|
||||
title: '与主单位换算比例',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdUnitMeasureApi } from '#/api/mes/md/unitmeasure';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteUnitMeasure,
|
||||
exportUnitMeasure,
|
||||
getUnitMeasurePage,
|
||||
} from '#/api/mes/md/unitmeasure';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
defineOptions({ name: 'MesMdUnitMeasure' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportUnitMeasure(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '计量单位.xls', source: data });
|
||||
}
|
||||
|
||||
/** 创建计量单位 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑计量单位 */
|
||||
function handleEdit(row: MesMdUnitMeasureApi.UnitMeasure) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除计量单位 */
|
||||
async function handleDelete(row: MesMdUnitMeasureApi.UnitMeasure) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteUnitMeasure(row.id!);
|
||||
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getUnitMeasurePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdUnitMeasureApi.UnitMeasure>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【基础】物料产品、分类、计量单位"
|
||||
url="https://doc.iocoder.cn/mes/md/product/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="计量单位列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['计量单位']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:md-unit-measure:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['mes:md-unit-measure:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:md-unit-measure:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:md-unit-measure:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdUnitMeasureApi } from '#/api/mes/md/unitmeasure';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createUnitMeasure,
|
||||
getUnitMeasure,
|
||||
updateUnitMeasure,
|
||||
} from '#/api/mes/md/unitmeasure';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
defineOptions({ name: 'MesMdUnitMeasureForm' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<MesMdUnitMeasureApi.UnitMeasure>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['计量单位'])
|
||||
: $t('ui.actionTitle.create', ['计量单位']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 140,
|
||||
},
|
||||
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 MesMdUnitMeasureApi.UnitMeasure;
|
||||
if (data.primaryFlag) {
|
||||
data.primaryId = undefined;
|
||||
data.changeRate = undefined;
|
||||
}
|
||||
try {
|
||||
await (formData.value?.id
|
||||
? updateUnitMeasure(data)
|
||||
: createUnitMeasure(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;
|
||||
}
|
||||
await formApi.resetForm();
|
||||
// 加载数据
|
||||
const data = modalApi.getData<MesMdUnitMeasureApi.UnitMeasure>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getUnitMeasure(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-1/3">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -5,14 +5,15 @@ import { requestClient } from '#/api/request';
|
|||
export namespace MesMdUnitMeasureApi {
|
||||
/** MES 计量单位 */
|
||||
export interface UnitMeasure {
|
||||
id: number;
|
||||
code?: string;
|
||||
name?: string;
|
||||
primaryFlag?: boolean;
|
||||
primaryId?: number;
|
||||
changeRate?: number;
|
||||
status?: number;
|
||||
remark?: string;
|
||||
id?: number; // 单位编号
|
||||
code?: string; // 单位编码
|
||||
name?: string; // 单位名称
|
||||
primaryFlag?: boolean; // 是否主单位
|
||||
primaryId?: number; // 主单位编号
|
||||
changeRate?: number; // 与主单位换算比例
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
createTime?: Date; // 创建时间
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +55,6 @@ export function deleteUnitMeasure(id: number) {
|
|||
}
|
||||
|
||||
/** 导出计量单位 */
|
||||
export function exportUnitMeasure(params: any) {
|
||||
export function exportUnitMeasure(params: PageParam) {
|
||||
return requestClient.download('/mes/md/unit-measure/export-excel', { params });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,17 +29,18 @@ const emit = defineEmits<{
|
|||
'update:modelValue': [value: number | undefined];
|
||||
}>();
|
||||
|
||||
const allList = ref<MesMdUnitMeasureApi.UnitMeasure[]>([]);
|
||||
const filteredList = ref<MesMdUnitMeasureApi.UnitMeasure[]>([]);
|
||||
const selectedItem = ref<MesMdUnitMeasureApi.UnitMeasure>();
|
||||
const allList = ref<MesMdUnitMeasureApi.UnitMeasure[]>([]); // 计量单位列表
|
||||
const filteredList = ref<MesMdUnitMeasureApi.UnitMeasure[]>([]); // 过滤后的计量单位列表
|
||||
const selectedItem = ref<MesMdUnitMeasureApi.UnitMeasure>(); // 当前选中计量单位
|
||||
|
||||
const selectValue = computed({
|
||||
const selectValue = computed({ // 选择器绑定值
|
||||
get: () => props.modelValue,
|
||||
set: (value: number | undefined) => {
|
||||
emit('update:modelValue', value);
|
||||
},
|
||||
});
|
||||
|
||||
/** 前端按名称和编码过滤计量单位 */
|
||||
function handleFilter(query: string) {
|
||||
if (!query) {
|
||||
filteredList.value = allList.value;
|
||||
|
|
@ -107,7 +108,7 @@ onMounted(async () => {
|
|||
v-for="item in filteredList"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
:value="item.id!"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<span>{{ item.name }}</span>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,193 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdUnitMeasureApi } from '#/api/mes/md/unitmeasure';
|
||||
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getUnitMeasureSimpleList } from '#/api/mes/md/unitmeasure';
|
||||
|
||||
/** 新增/修改计量单位的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '单位编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入单位编码',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '单位名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入单位名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'primaryFlag',
|
||||
label: '是否主单位',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
|
||||
},
|
||||
rules: z.boolean().default(true),
|
||||
},
|
||||
{
|
||||
fieldName: 'primaryId',
|
||||
label: '主单位',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: async () => {
|
||||
const list = await getUnitMeasureSimpleList();
|
||||
return list.filter((item) => item.primaryFlag === true);
|
||||
},
|
||||
clearable: true,
|
||||
labelField: 'name',
|
||||
placeholder: '请选择主单位',
|
||||
valueField: 'id',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['primaryFlag'],
|
||||
show: (values) => values.primaryFlag === false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'changeRate',
|
||||
label: '与主单位换算比例',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
controlsPosition: 'right',
|
||||
min: 0,
|
||||
precision: 4,
|
||||
step: 1,
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['primaryFlag'],
|
||||
show: (values) => values.primaryFlag === false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '单位编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入单位编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '单位名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入单位名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<MesMdUnitMeasureApi.UnitMeasure>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'code',
|
||||
title: '单位编码',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '单位名称',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'primaryFlag',
|
||||
title: '是否主单位',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'changeRate',
|
||||
title: '与主单位换算比例',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdUnitMeasureApi } from '#/api/mes/md/unitmeasure';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteUnitMeasure,
|
||||
exportUnitMeasure,
|
||||
getUnitMeasurePage,
|
||||
} from '#/api/mes/md/unitmeasure';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
defineOptions({ name: 'MesMdUnitMeasure' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportUnitMeasure(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '计量单位.xls', source: data });
|
||||
}
|
||||
|
||||
/** 创建计量单位 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑计量单位 */
|
||||
function handleEdit(row: MesMdUnitMeasureApi.UnitMeasure) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除计量单位 */
|
||||
async function handleDelete(row: MesMdUnitMeasureApi.UnitMeasure) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.name]),
|
||||
});
|
||||
try {
|
||||
await deleteUnitMeasure(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getUnitMeasurePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdUnitMeasureApi.UnitMeasure>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【基础】物料产品、分类、计量单位"
|
||||
url="https://doc.iocoder.cn/mes/md/product/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="计量单位列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['计量单位']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:md-unit-measure:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['mes:md-unit-measure:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:md-unit-measure:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:md-unit-measure:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdUnitMeasureApi } from '#/api/mes/md/unitmeasure';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createUnitMeasure,
|
||||
getUnitMeasure,
|
||||
updateUnitMeasure,
|
||||
} from '#/api/mes/md/unitmeasure';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
defineOptions({ name: 'MesMdUnitMeasureForm' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<MesMdUnitMeasureApi.UnitMeasure>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['计量单位'])
|
||||
: $t('ui.actionTitle.create', ['计量单位']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 140,
|
||||
},
|
||||
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 MesMdUnitMeasureApi.UnitMeasure;
|
||||
if (data.primaryFlag) {
|
||||
data.primaryId = undefined;
|
||||
data.changeRate = undefined;
|
||||
}
|
||||
try {
|
||||
await (formData.value?.id
|
||||
? updateUnitMeasure(data)
|
||||
: createUnitMeasure(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
await formApi.resetForm();
|
||||
// 加载数据
|
||||
const data = modalApi.getData<MesMdUnitMeasureApi.UnitMeasure>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getUnitMeasure(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-1/3">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
Loading…
Reference in New Issue