feat: 出入库模块完善,组件封装完善

This commit is contained in:
louis 2024-03-06 11:39:41 +08:00
parent 55884200da
commit 989cbfc69a
13 changed files with 280 additions and 189 deletions

View File

@ -12,8 +12,10 @@
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { transformI18n } from './hooks/useI18n'; import { transformI18n } from './hooks/useI18n';
import { LockScreen } from '@/components/basic/lockscreen'; import { LockScreen } from '@/components/basic/lockscreen';
const route = useRoute(); const route = useRoute();
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
dayjs.locale('zh-cn');
watchEffect(() => { watchEffect(() => {
if (route.meta?.title) { if (route.meta?.title) {
// //

View File

@ -50,7 +50,7 @@ export async function materialsInOutInfo(
options?: RequestOptions, options?: RequestOptions,
) { ) {
const { id: param0, ...queryParams } = params; const { id: param0, ...queryParams } = params;
return request<API.MaterialsInOutEntity>(`/api/contract/${param0}`, { return request<API.MaterialsInOutEntity>(`/api/materials-in-out/${param0}`, {
method: 'GET', method: 'GET',
params: { ...queryParams }, params: { ...queryParams },
...(options || {}), ...(options || {}),
@ -61,7 +61,7 @@ export async function materialsInOutInfo(
export async function unlinkAttachments( export async function unlinkAttachments(
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象) // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
params: API.MaterialsInOutUpdateParams, params: API.MaterialsInOutUpdateParams,
body: API.MaterialsInOutDto, body: API.MaterialsInOutUpdateDto,
options?: RequestOptions, options?: RequestOptions,
) { ) {
const { id: param0, ...queryParams } = params; const { id: param0, ...queryParams } = params;

View File

@ -1537,7 +1537,7 @@ declare namespace API {
page?: number; page?: number;
pageSize?: number; pageSize?: number;
name?: string; name?: string;
productId?:number; productId?: number;
field?: string; field?: string;
order?: 'ASC' | 'DESC'; order?: 'ASC' | 'DESC';
_t?: number; _t?: number;
@ -1561,7 +1561,7 @@ declare namespace API {
/** 所属公司 */ /** 所属公司 */
company: CompanyEntity; company: CompanyEntity;
/** 单位 */ /** 单位 */
unit: string; unit: DictItemEntity;
/** 是否删除 */ /** 是否删除 */
isDelete: string; isDelete: string;
/** 附件 */ /** 附件 */
@ -1576,7 +1576,7 @@ declare namespace API {
/** 所属公司 */ /** 所属公司 */
companyId?: number; companyId?: number;
/** 单位 */ /** 单位 */
unit?: string; unitId?: number;
fileIds?: number[]; fileIds?: number[];
}; };
type ProductUpdateParams = { type ProductUpdateParams = {
@ -1636,7 +1636,7 @@ declare namespace API {
/** 出库或入库 */ /** 出库或入库 */
inOrOut: number; inOrOut: number;
/** 单位(字典) */ /** 单位(字典) */
unit: number; unit: DictItemEntity;
/** 时间 */ /** 时间 */
time: Date; time: Date;
/** 数量 */ /** 数量 */
@ -1661,16 +1661,12 @@ declare namespace API {
}; };
type MaterialsInOutDto = { type MaterialsInOutDto = {
/** 公司名称 */
companyName: string;
/** 产品Id */ /** 产品Id */
productId: number; productId: number;
/** 产品信息 */ /** 产品信息 */
product?: ProductEntity; product?: ProductEntity;
/** 出库或入库 */ /** 出库或入库 */
inOrOut: number; inOrOut: number;
/** 单位(字典) */
unit: number;
/** 时间 */ /** 时间 */
time: Date; time: Date;
/** 数量 */ /** 数量 */
@ -1680,39 +1676,37 @@ declare namespace API {
/** 金额 */ /** 金额 */
amount: number; amount: number;
/** 经办人 */ /** 经办人 */
agent: string; agent?: string;
/** 领料单号 */ /** 领料单号 */
issuanceNumber?: number; issuanceNumber?: number;
/** 项目 */ /** 项目 */
project: string; project?: string;
/** 备注 */ /** 备注 */
remark: string; remark?: string;
/** 附件 */
fileIds?: number[];
}; };
type MaterialsInOutUpdateDto = { type MaterialsInOutUpdateDto = {
/** 公司名称 */
companyName: string;
/** 产品Id */ /** 产品Id */
productId: number; productId?: number;
/** 出库或入库 */ /** 出库或入库 */
inOrOut: number; inOrOut?: number;
/** 单位(字典) */
unit: number;
/** 时间 */ /** 时间 */
time: Date; time?: Date;
/** 数量 */ /** 数量 */
quantity: number; quantity?: number;
/** 单价 */ /** 单价 */
unitPrice: number; unitPrice?: number;
/** 金额 */ /** 金额 */
amount: number; amount?: number;
/** 经办人 */ /** 经办人 */
agent: string; agent?: string;
/** 领料单号 */ /** 领料单号 */
issuanceNumber?: number; issuanceNumber?: number;
/** 项目 */ /** 项目 */
project: string; project?: string;
/** 备注 */ /** 备注 */
remark: string; remark?: string;
/** 附件 */ /** 附件 */
fileIds?: number[]; fileIds?: number[];
}; };

View File

@ -27,9 +27,9 @@
:is="getComponent" :is="getComponent"
v-else-if="getComponent" v-else-if="getComponent"
:ref="setItemRef(schema.field)" :ref="setItemRef(schema.field)"
:allow-clear="true"
v-bind="getComponentProps" v-bind="getComponentProps"
v-model:[modelValueType]="modelValue" v-model:[modelValueType]="modelValue"
:allow-clear="true"
:disabled="getDisable" :disabled="getDisable"
:loading="schema.loading" :loading="schema.loading"
v-on="componentEvents" v-on="componentEvents"

View File

@ -8,6 +8,7 @@ import type { LocaleType } from './config';
import type { Locale } from 'ant-design-vue/es/locale-provider'; import type { Locale } from 'ant-design-vue/es/locale-provider';
import { useLocaleStoreWithOut } from '@/store/modules/locale'; import { useLocaleStoreWithOut } from '@/store/modules/locale';
import dayjs from 'dayjs';
interface LangModule { interface LangModule {
message: Recordable; message: Recordable;
@ -35,6 +36,7 @@ export function useLocale() {
return i18n.global.getLocaleMessage(unref(getLocale)).antdLocale; return i18n.global.getLocaleMessage(unref(getLocale)).antdLocale;
}); });
// Switching the language will change the locale of useI18n // Switching the language will change the locale of useI18n
// And submit to configuration modification // And submit to configuration modification
async function changeLocale(locale: LocaleType) { async function changeLocale(locale: LocaleType) {
@ -43,7 +45,8 @@ export function useLocale() {
if (currentLocale === locale) { if (currentLocale === locale) {
return locale; return locale;
} }
dayjs.locale(locale.toLocaleLowerCase());
// dayjs.locale(locale);
if (loadLocalePool.includes(locale)) { if (loadLocalePool.includes(locale)) {
setI18nLanguage(locale); setI18nLanguage(locale);
return locale; return locale;

View File

@ -3,93 +3,93 @@
* @description , ts * @description , ts
*/ */
const permissions = [ const permissions = [
"system:user:list", 'system:user:list',
"system:role:list", 'system:role:list',
"system:menu:list", 'system:menu:list',
"system:online:list", 'system:online:list',
"system:log:login:list", 'system:log:login:list',
"system:serve:stat", 'system:serve:stat',
"system:task:list", 'system:task:list',
"system:user:create", 'system:user:create',
"system:user:delete", 'system:user:delete',
"system:user:update", 'system:user:update',
"system:user:read", 'system:user:read',
"system:role:create", 'system:role:create',
"system:role:delete", 'system:role:delete',
"system:role:update", 'system:role:update',
"system:role:read", 'system:role:read',
"system:menu:create", 'system:menu:create',
"system:menu:delete", 'system:menu:delete',
"system:menu:update", 'system:menu:update',
"system:menu:read", 'system:menu:read',
"system:online:kick", 'system:online:kick',
"system:task:create", 'system:task:create',
"system:task:delete", 'system:task:delete',
"system:task:once", 'system:task:once',
"system:task:read", 'system:task:read',
"system:task:start", 'system:task:start',
"system:task:stop", 'system:task:stop',
"system:task:update", 'system:task:update',
"system:log:task:list", 'system:log:task:list',
"system:tools:email", 'system:tools:email',
"tools:email:send", 'tools:email:send',
"tool:storage:list", 'tool:storage:list',
"upload:upload", 'upload:upload',
"tool:storage:delete", 'tool:storage:delete',
"system:user:password", 'system:user:password',
"system:dict-type:list", 'system:dict-type:list',
"system:dict-type:create", 'system:dict-type:create',
"system:dict-type:update", 'system:dict-type:update',
"system:dict-type:delete", 'system:dict-type:delete',
"system:dict-type:info", 'system:dict-type:info',
"system:dept:list", 'system:dept:list',
"system:dept:create", 'system:dept:create',
"system:dept:update", 'system:dept:update',
"system:dept:delete", 'system:dept:delete',
"system:dept:read", 'system:dept:read',
"app:health:network", 'app:health:network',
"app:health: database", 'app:health: database',
"system:param-config:list", 'system:param-config:list',
"system:param-config:read", 'system:param-config:read',
"system:param-config:create", 'system:param-config:create',
"system:param-config:update", 'system:param-config:update',
"system:param-config:delete", 'system:param-config:delete',
"system:dict-item:list", 'system:dict-item:list',
"system:dict-item:create", 'system:dict-item:create',
"system:dict-item:update", 'system:dict-item:update',
"system:dict-item:delete", 'system:dict-item:delete',
"system:dict-item:info", 'system:dict-item:info',
"netdisk:manage:list", 'netdisk:manage:list',
"netdisk:manage:create", 'netdisk:manage:create',
"netdisk:manage:read", 'netdisk:manage:read',
"netdisk:manage:update", 'netdisk:manage:update',
"netdisk:manage:delete", 'netdisk:manage:delete',
"netdisk:manage:token", 'netdisk:manage:token',
"netdisk:manage:mark", 'netdisk:manage:mark',
"netdisk:manage:download", 'netdisk:manage:download',
"netdisk:manage:rename", 'netdisk:manage:rename',
"netdisk:manage:copy", 'netdisk:manage:copy',
"netdisk:manage:cut", 'netdisk:manage:cut',
"netdisk:overview:desc", 'netdisk:overview:desc',
"app:contract:list", 'app:contract:list',
"app:materials_inventory:list", 'materials_inventory:history_in_out:list',
"app:contract:update", 'app:contract:update',
"app:contract:delete", 'app:contract:delete',
"app:contract:read", 'app:contract:read',
"app:contract:create", 'app:contract:create',
"app:materials_inventory:create", 'materials_inventory:history_in_out:create',
"app:materials_inventory:update", 'materials_inventory:history_in_out:update',
"app:materials_inventory:delete", 'materials_inventory:history_in_out:delete',
"app:company:list", 'app:company:list',
"app:company:read", 'app:company:read',
"app:company:create", 'app:company:create',
"app:company:update", 'app:company:update',
"app:company:delete", 'app:company:delete',
"app:product:list", 'app:product:list',
"app:product:read", 'app:product:read',
"app:product:create", 'app:product:create',
"app:product:update", 'app:product:update',
"app:product:delete" 'app:product:delete',
] as const; ] as const;
export type PermissionType = (typeof permissions)[number]; export type PermissionType = (typeof permissions)[number];

View File

@ -2,4 +2,4 @@ import dashboard from './dashboard';
import demos from './demos'; import demos from './demos';
import account from './account'; import account from './account';
export default [...demos, ...dashboard, ...account]; export default [/* ...demos, */...dashboard, ...account];

View File

@ -17,7 +17,7 @@ export const useDictStore = defineStore('dict', () => {
}); });
}; };
getDictTypes(); getDictTypes();
const getDictItemsByCode = (code: string): API.DictItemEntity[] => { const getDictItemsByCode = (code: DictEnum): API.DictItemEntity[] => {
return dictTypes.value.find((item) => item.code === code)?.dictItems || []; return dictTypes.value.find((item) => item.code === code)?.dictItems || [];
}; };

View File

@ -7,37 +7,28 @@ import { Tag } from 'ant-design-vue';
export type TableListItem = API.MaterialsInOutEntity; export type TableListItem = API.MaterialsInOutEntity;
export type TableColumnItem = TableColumn<TableListItem>; export type TableColumnItem = TableColumn<TableListItem>;
const dictStore = useDictStore();
export const baseColumns: TableColumnItem[] = [ export const baseColumns: TableColumnItem[] = [
{ {
title: '产品名称', title: '产品名称',
width: 180, width: 180,
dataIndex: 'product', dataIndex: 'product',
customRender: ({ record }) => {
return record.product?.name || '';
},
}, },
{ {
title: '单位', title: '单位',
width: 60, width: 40,
hideInSearch: true, hideInSearch: true,
dataIndex: 'unit', dataIndex: 'unit',
formItemProps: {
component: 'Select',
componentProps: {
options: dictStore
.getDictItemsByCode(DictEnum.Unit)
.map(({ label, id }) => ({ value: id, label })),
},
},
customRender: ({ record }) => { customRender: ({ record }) => {
return dictStore.getDictItemsByCode(DictEnum.Unit)?.length return record.unit?.label || '';
? dictStore.getDictItemsByCode(DictEnum.Unit).find((item) => item.id === record.unit)
?.label || ''
: '';
}, },
}, },
{ {
title: '入库/出库', title: '入库/出库',
width: 80, width: 60,
dataIndex: 'inOrOut', dataIndex: 'inOrOut',
formItemProps: { formItemProps: {
component: 'Select', component: 'Select',
@ -54,10 +45,12 @@ export const baseColumns: TableColumnItem[] = [
}, },
{ {
title: '时间', title: '时间',
width: 120, width: 60,
align: 'center', align: 'center',
dataIndex: 'time', dataIndex: 'time',
formItemProps: { component: 'RangePicker' }, formItemProps: {
component: 'MonthPicker',
},
customRender: ({ record }) => { customRender: ({ record }) => {
return formatToDate(record.time); return formatToDate(record.time);
}, },
@ -65,7 +58,7 @@ export const baseColumns: TableColumnItem[] = [
{ {
title: '数量', title: '数量',
hideInSearch: true, hideInSearch: true,
width: 80, width: 60,
dataIndex: 'quantity', dataIndex: 'quantity',
}, },
{ {

View File

@ -1,10 +1,12 @@
import type { FormSchema } from '@/components/core/schema-form/'; import type { FormSchema } from '@/components/core/schema-form/';
import { ContractStatusEnum } from '@/enums/contractEnum';
import { formatStatus } from './columns';
import Api from '@/api'; import Api from '@/api';
import { debounce } from 'lodash-es'; import { debounce } from 'lodash-es';
import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum'; import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum';
import { DictEnum } from '@/enums/dictEnum';
import { useDictStore } from '@/store/modules/dict';
import { toRaw } from 'vue';
const { getDictItemsByCode } = useDictStore();
export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [ export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [
{ {
field: 'productId', field: 'productId',
@ -13,7 +15,7 @@ export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [
colProps: { colProps: {
span: 16, span: 16,
}, },
helpMessage:'如未找到对应产品,请先去产品管理添加产品。', helpMessage: '如未找到对应产品,请先去产品管理添加产品。',
rules: [{ required: true, type: 'number' }], rules: [{ required: true, type: 'number' }],
componentProps: ({ formInstance, schema, formModel }) => ({ componentProps: ({ formInstance, schema, formModel }) => ({
showSearch: true, showSearch: true,
@ -25,17 +27,16 @@ export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [
options: [], options: [],
getPopupContainer: () => document.body, getPopupContainer: () => document.body,
defaultActiveFirstOption: true, defaultActiveFirstOption: true,
onChange: async (value) => { onClear: async () => {
if (!value) { const newSchema = {
const options = await getProductOptions(); field: schema.field,
const newSchema = { componentProps: {
field: schema.field, options: [] as LabelValueOptions,
componentProps: { },
options, };
}, const options = await getProductOptions().finally(() => (schema.loading = false));
}; newSchema.componentProps.options = options;
formInstance?.updateSchema([newSchema]); formInstance?.updateSchema([newSchema]);
}
}, },
request: () => { request: () => {
return getProductOptions(); return getProductOptions();
@ -66,14 +67,77 @@ export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [
span: 8, span: 8,
}, },
componentProps: { componentProps: {
allowClear: false,
options: [ options: [
{ label: '出库', value: MaterialsInOutEnum.Out }, { label: '出库', value: MaterialsInOutEnum.Out },
{ label: '入库', value: MaterialsInOutEnum.In }, { label: '入库', value: MaterialsInOutEnum.In },
], ],
}, },
}, },
{
label: '时间',
field: 'time',
component: 'DatePicker',
colProps: {
span: 12,
},
},
{
label: '数量',
field: 'quantity',
component: 'InputNumber',
colProps: {
span: 12,
},
},
{
label: '单价',
field: 'unitPrice',
component: 'InputNumber',
colProps: {
span: 12,
},
},
{
label: '金额',
field: 'amount',
component: 'InputNumber',
colProps: {
span: 12,
},
},
{
label: '经办人',
field: 'agent',
component: 'Input',
colProps: {
span: 12,
},
},
{
label: '领料单号',
field: 'issuanceNumber',
component: 'Input',
colProps: {
span: 12,
},
},
{
label: '项目',
field: 'project',
component: 'Input',
colProps: {
span: 12,
},
},
{
label: '备注',
field: 'remark',
component: 'InputTextArea',
},
// { // {
// field: 'title', // field: 'label',
// component: 'Input', // component: 'Input',
// label: '合同标题', // label: '合同标题',
// rules: [{ required: true, type: 'string' }], // rules: [{ required: true, type: 'string' }],
@ -155,7 +219,7 @@ export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [
// checkable: true, // checkable: true,
// vModelKey: 'checkedKeys', // vModelKey: 'checkedKeys',
// fieldNames: { // fieldNames: {
// title: 'name', // label: 'name',
// key: 'id', // key: 'id',
// }, // },
// style: { // style: {

View File

@ -2,7 +2,7 @@
<div v-if="columns?.length"> <div v-if="columns?.length">
<DynamicTable <DynamicTable
row-key="id" row-key="id"
header-title="原材料盘点" header-title="原材料出入库记录"
title-tooltip="" title-tooltip=""
:data-request="Api.materialsInOut.materialsInOutList" :data-request="Api.materialsInOut.materialsInOutList"
:columns="columns" :columns="columns"
@ -13,7 +13,7 @@
<template #toolbar> <template #toolbar>
<a-button <a-button
type="primary" type="primary"
:disabled="!$auth('system:role:create')" :disabled="!$auth('materials_inventory:history_in_out:create')"
@click="openEditModal({})" @click="openEditModal({})"
> >
新增 新增
@ -56,9 +56,8 @@
}, },
{ {
title: '操作', title: '操作',
maxWidth: 150, maxWidth: 80,
width: 150, width: 80,
minWidth: 150,
dataIndex: 'ACTION', dataIndex: 'ACTION',
hideInSearch: true, hideInSearch: true,
fixed: 'right', fixed: 'right',
@ -67,7 +66,7 @@
icon: 'ant-design:edit-outlined', icon: 'ant-design:edit-outlined',
tooltip: '编辑', tooltip: '编辑',
auth: { auth: {
perm: 'app:contract:update', perm: 'materials_inventory:history_in_out:update',
effect: 'disable', effect: 'disable',
}, },
onClick: () => openEditModal(record), onClick: () => openEditModal(record),
@ -76,7 +75,7 @@
icon: 'ant-design:delete-outlined', icon: 'ant-design:delete-outlined',
color: 'red', color: 'red',
tooltip: '删除此记录', tooltip: '删除此记录',
auth: 'app:contract:delete', auth: 'materials_inventory:history_in_out:delete',
popConfirm: { popConfirm: {
title: '你确定要删除吗?', title: '你确定要删除吗?',
placement: 'left', placement: 'left',
@ -121,7 +120,10 @@
files: { filename: { path: string; id: number } }[], files: { filename: { path: string; id: number } }[],
id: number, id: number,
) => { ) => {
await Api.contract.contractUpdate({ id }, { fileIds: files.map((item) => item.filename.id) }); await Api.materialsInOut.materialsInOutUpdate(
{ id },
{ fileIds: files.map((item) => item.filename.id) },
);
dynamicTableInstance?.reload(); dynamicTableInstance?.reload();
}; };
@ -134,15 +136,18 @@
title: `${record.id ? '编辑' : '新增'}出入库记录`, title: `${record.id ? '编辑' : '新增'}出入库记录`,
width: '50%', width: '50%',
onFinish: async (values) => { onFinish: async (values) => {
const params: API.MaterialsInOutUpdateDto = { const params = {
...values, ...values,
// signingDate: formatToDate(values.signingDate), // signingDate: formatToDate(values.signingDate),
// deliveryDeadline: formatToDate(values.deliveryDeadline), // deliveryDeadline: formatToDate(values.deliveryDeadline),
}; };
if (record.id) { if (record.id) {
await Api.materialsInOut.materialsInOutUpdate({ id: record.id }, params); await Api.materialsInOut.materialsInOutUpdate(
{ id: record.id },
params as API.MaterialsInOutUpdateDto,
);
} else { } else {
await Api.materialsInOut.materialsInOutCreate(params); await Api.materialsInOut.materialsInOutCreate(params as API.MaterialsInOutDto);
} }
dynamicTableInstance?.reload(); dynamicTableInstance?.reload();
}, },
@ -154,50 +159,50 @@
}); });
// //
if (record.id) { if (record.id) {
const info = await Api.contract.contractInfo({ id: record.id }); const info = await Api.materialsInOut.materialsInOutInfo({ id: record.id });
formRef?.setFieldsValue({ formRef?.setFieldsValue({
...info, ...info,
}); });
} }
}; };
const delRowConfirm = async (record) => { const delRowConfirm = async (record) => {
await Api.contract.contractDelete({ id: record }); await Api.materialsInOut.materialsInOutDelete({ id: record });
dynamicTableInstance?.reload(); dynamicTableInstance?.reload();
}; };
const FilesRender: FunctionalComponent<TableListItem> = (contract: TableListItem) => { const FilesRender: FunctionalComponent<TableListItem> = (materialsInOut: TableListItem) => {
const [fnModal] = useModal(); const [fnModal] = useModal();
return ( return (
<Button <Button
type="link" type="link"
onClick={() => { onClick={() => {
openFilesManageModal(fnModal, contract); openFilesManageModal(fnModal, materialsInOut);
}} }}
> >
{contract.files?.length || 0} {materialsInOut.files?.length || 0}
</Button> </Button>
); );
}; };
const openFilesManageModal = (fnModal, contract: TableListItem) => { const openFilesManageModal = (fnModal, tableData: TableListItem) => {
// const fileIds = contract.files?.map((item) => item.id) || []; const fileIds = tableData.files?.map((item) => item.id) || [];
// fnModal.show({ fnModal.show({
// width: 1200, width: 1200,
// title: ``, title: `附件管理`,
// content: () => { content: () => {
// return ( return (
// <AttachmentManage <AttachmentManage
// fileIds={fileIds} fileIds={fileIds}
// onDelete={(unlinkIds) => unlinkAttachments(contract.id, unlinkIds)} onDelete={(unlinkIds) => unlinkAttachments(tableData.id, unlinkIds)}
// ></AttachmentManage> ></AttachmentManage>
// ); );
// }, },
// destroyOnClose: true, destroyOnClose: true,
// footer: null, footer: null,
// }); });
}; };
const unlinkAttachments = async (id: number, unlinkIds: number[]) => { const unlinkAttachments = async (id: number, unlinkIds: number[]) => {
await Api.contract.unlinkAttachments({ id }, { fileIds: unlinkIds }); await Api.materialsInOut.unlinkAttachments({ id }, { fileIds: unlinkIds });
dynamicTableInstance?.reload(); dynamicTableInstance?.reload();
}; };
</script> </script>

View File

@ -15,4 +15,11 @@ export const baseColumns: TableColumnItem[] = [
return record?.company?.name || ''; return record?.company?.name || '';
}, },
}, },
{
title: '单位',
dataIndex: 'unit',
customRender: ({ record }) => {
return record?.unit?.label || '';
},
},
]; ];

View File

@ -1,7 +1,9 @@
import Api from '@/api'; import Api from '@/api';
import type { FormSchema } from '@/components/core/schema-form/'; import type { FormSchema } from '@/components/core/schema-form/';
import { DictEnum } from '@/enums/dictEnum';
import { useDictStore } from '@/store/modules/dict';
import { debounce } from 'lodash-es'; import { debounce } from 'lodash-es';
import { nextTick, toRaw } from 'vue'; const { getDictItemsByCode } = useDictStore();
export const formSchemas: FormSchema<API.ProductDto>[] = [ export const formSchemas: FormSchema<API.ProductDto>[] = [
{ {
field: 'name', field: 'name',
@ -12,6 +14,28 @@ export const formSchemas: FormSchema<API.ProductDto>[] = [
span: 12, span: 12,
}, },
}, },
{
label: '单位',
component: 'Select',
field: 'unitId',
componentProps: ({ formInstance, schema, formModel }) => ({
showSearch: true,
filterOption: (input: string, option: any) => {
return option.label.indexOf(input) >= 0;
},
fieldNames: {
label: 'label',
value: 'value',
},
options: getDictItemsByCode(DictEnum.Unit).map((item) => ({
value: item.id,
label: item.label,
})),
getPopupContainer: () => document.body,
defaultActiveFirstOption: true,
}),
},
{ {
field: 'companyId', field: 'companyId',
component: 'Select', component: 'Select',
@ -28,7 +52,6 @@ export const formSchemas: FormSchema<API.ProductDto>[] = [
getPopupContainer: () => document.body, getPopupContainer: () => document.body,
defaultActiveFirstOption: true, defaultActiveFirstOption: true,
onChange: async (value) => { onChange: async (value) => {
console.log('onChange');
if (!value) { if (!value) {
formInstance?.setFieldsValue({ companyId: undefined }); formInstance?.setFieldsValue({ companyId: undefined });
const options = await getCompanyOptions(); const options = await getCompanyOptions();