
列表计量单位显示
E:\javaDev\tender-project-vben5\apps\web-antd\src\views\tender\material\data.ts
import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';
import { materialUnitList } from '#/api/tender/materialUnit';
export const querySchema: FormSchemaGetter = () => [
{
component: 'Input',
fieldName: 'materialCategoryId',
label: '物料分组id',
},
{
component: 'Input',
fieldName: 'materialNumber',
label: '物料名称',
},
{
component: 'Input',
fieldName: 'materialName',
label: '物料编码',
},
{
component: 'Input',
fieldName: 'orderNum',
label: '显示顺序',
},
{
component: 'Select',
componentProps: {
// 可选从DictEnum中获取 DictEnum.BILL_STATUS 便于维护
options: getDictOptions('bill_status'),
},
fieldName: 'status',
label: '物料状态',
},
{
component: 'Input',
fieldName: 'materialModel',
label: '型号',
},
{
component: 'Input',
fieldName: 'materialUnit',
label: '计量单位',
},
];
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
// 单位id到名称的映射 计量单位实现
export const materialUnitMap: Record<string | number, string> = {};
// 异步加载单位映射 计量单位实现
export async function loadMaterialUnitMap() {
const res = await materialUnitList();
(res.rows || []).forEach((item: any) => {
materialUnitMap[item.materialUnitId] = item.materialUnitName;
});
}
export const columns: VxeGridProps['columns'] = [
{
title: '物料分组id',
field: 'materialCategoryId',
width: 120,
visible: false,
},
{
title: '物料id',
field: 'materialId',
width: 120,
visible: false,
},
{
title: '物料编码',
field: 'materialNumber',
width: 150,
},
{
title: '物料名称',
field: 'materialName',
width: 200,
},
{
title: '型号',
field: 'materialModel',
width: 150,
},
{
title: '计量单位',
field: 'materialUnit',
width: 100,
slots: {
default: ({ row }) => {
// 优先显示 materialUnitName 字段,否则用映射 计量单位实现
return row.materialUnitName || materialUnitMap[row.materialUnit] || row.materialUnit || '-';
},
},
},
{
title: '显示顺序',
field: 'orderNum',
width: 100,
},
{
title: '状态',
field: 'status',
width: 100,
slots: {
default: ({ row }) => {
return renderDict(row.status, 'bill_status');
},
},
},
{
field: 'action',
fixed: 'right',
title: '操作',
width: 180,
slots: { default: 'action' },
},
];
E:\javaDev\tender-project-vben5\apps\web-antd\src\views\tender\material\components\MaterialTable.vue


293

被折叠的 条评论
为什么被折叠?



