feat: 出入库模块完善

This commit is contained in:
louis 2024-03-06 17:13:27 +08:00
parent 989cbfc69a
commit 8bcae5be3f
5 changed files with 161 additions and 137 deletions

View File

@ -1621,14 +1621,19 @@ declare namespace API {
type MaterialsInOutListParams = { type MaterialsInOutListParams = {
page?: number; page?: number;
pageSize?: number; pageSize?: number;
time?: string;
inventoryNumber?: string;
isCreateOut?: boolean;
field?: string; field?: string;
order?: 'ASC' | 'DESC'; order?: 'ASC' | 'DESC';
_t?: number; _t?: number;
}; };
type MaterialsInOutEntity = { type MaterialsInOutEntity = {
/** 公司名称 */ /** 库存编号 */
companyName: string; inventoryNumber: string;
/** 公司信息 */
company: CompanyEntity;
/** 产品Id */ /** 产品Id */
productId: number; productId: number;
/** 产品信息 */ /** 产品信息 */

View File

@ -90,8 +90,9 @@ const permissions = [
'app:product:create', 'app:product:create',
'app:product:update', 'app:product:update',
'app:product:delete', 'app:product:delete',
'materials_inventory:history_in_out:export'
] as const; ] as const;
export type PermissionType = (typeof permissions)[number]; export type PermissionType = string;
// console.log('permissions', permissions); // console.log('permissions', permissions);

View File

@ -1,28 +1,48 @@
import type { TableColumn } from '@/components/core/dynamic-table'; import type { TableColumn } from '@/components/core/dynamic-table';
import { DictEnum } from '@/enums/dictEnum';
import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum'; import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum';
import { useDictStore } from '@/store/modules/dict';
import { formatToDate } from '@/utils/dateUtil'; import { formatToDate } from '@/utils/dateUtil';
import { Tag } from 'ant-design-vue'; import { Tag } from 'ant-design-vue';
export type TableListItem = API.MaterialsInOutEntity; export type TableListItem = API.MaterialsInOutEntity;
export type TableQueryItem = API.MaterialsInOutListParams;
export type TableColumnItem = TableColumn<TableListItem>; export type TableColumnItem = TableColumn<TableListItem>;
export const baseColumns: TableColumnItem[] = [ export const baseColumns: TableColumnItem[] = [
{
title: '原材料库存编号',
width: 100,
fixed: 'left',
dataIndex: 'inventoryNumber',
customRender: ({ record }) => {
return record.inventoryNumber || '';
},
formItemProps: {
labelWidth: 120,
},
},
{
title: '所属公司',
width: 100,
dataIndex: 'company',
customRender: ({ record }) => {
return record.product?.company?.name || '';
},
},
{ {
title: '产品名称', title: '产品名称',
width: 180, width: 100,
dataIndex: 'product', dataIndex: 'product',
customRender: ({ record }) => { customRender: ({ record }) => {
return record.product?.name || ''; return record.product?.name || '';
}, },
}, },
{ {
title: '单位', title: '单位',
width: 40, width: 40,
hideInSearch: true, hideInSearch: true,
dataIndex: 'unit', dataIndex: 'unit',
customRender: ({ record }) => { customRender: ({ record }) => {
return record.unit?.label || ''; return record?.product?.unit?.label || '';
}, },
}, },
@ -60,12 +80,18 @@ export const baseColumns: TableColumnItem[] = [
hideInSearch: true, hideInSearch: true,
width: 60, width: 60,
dataIndex: 'quantity', dataIndex: 'quantity',
customRender: ({ record }) => {
return parseFloat(record.quantity) || 0;
},
}, },
{ {
title: '单价', title: '单价',
hideInSearch: true, hideInSearch: true,
width: 80, width: 80,
dataIndex: 'unitPrice', dataIndex: 'unitPrice',
customRender: ({ record }) => {
return parseFloat(record.unitPrice) || 0;
},
}, },
{ {
title: '金额', title: '金额',
@ -73,6 +99,9 @@ export const baseColumns: TableColumnItem[] = [
align: 'center', align: 'center',
dataIndex: 'amount', dataIndex: 'amount',
hideInSearch: true, hideInSearch: true,
customRender: ({ record }) => {
return parseFloat(record.amount) || 0;
},
}, },
{ {
title: '经办人', title: '经办人',

View File

@ -3,14 +3,91 @@ import type { FormSchema } from '@/components/core/schema-form/';
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'; export const formSchemas = (isEdit?: boolean): FormSchema<API.MaterialsInOutEntity>[] => [
import { useDictStore } from '@/store/modules/dict'; {
import { toRaw } from 'vue'; field: 'inOrOut',
const { getDictItemsByCode } = useDictStore(); component: 'Select',
export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [ label: '出入库',
rules: [{ required: true, type: 'number' }],
defaultValue: MaterialsInOutEnum.In,
colProps: {
span: 8,
},
componentProps: {
allowClear: false,
disabled:isEdit,
options: [
{ label: '出库', value: MaterialsInOutEnum.Out },
{ label: '入库', value: MaterialsInOutEnum.In },
],
},
},
{
field: 'inventoryNumber',
component: 'Select',
label: '库存编号',
vIf: ({ formModel }) => formModel.inOrOut === MaterialsInOutEnum.Out,
colProps: {
span: 16,
},
helpMessage: '出库必须选择入库时的编号',
componentProps: ({ formInstance, schema, formModel }) => ({
showSearch: true,
filterOption: false,
disabled: isEdit,
fieldNames: {
label: 'label',
value: 'value',
},
options: [],
getPopupContainer: () => document.body,
defaultActiveFirstOption: true,
onClear: async () => {
const newSchema = {
field: schema.field,
componentProps: {
options: [] as LabelValueOptions,
},
};
const options = await getInventoryNumberOptions().finally(() => (schema.loading = false));
newSchema.componentProps.options = options;
formInstance?.updateSchema([newSchema]);
},
request: {
watchFields: ['inOrOut'],
options: {
immediate: true,
},
callback: async ({ formModel }) => {
if (formModel.inOrOut === MaterialsInOutEnum.Out) {
return getInventoryNumberOptions();
} else {
return Promise.resolve([] as LabelValueOptions);
}
},
},
onSearch: debounce(async (keyword) => {
schema.loading = true;
const newSchema = {
field: schema.field,
componentProps: {
options: [] as LabelValueOptions,
},
};
formInstance?.updateSchema([newSchema]);
const options = await getInventoryNumberOptions(keyword).finally(
() => (schema.loading = false),
);
newSchema.componentProps.options = options;
formInstance?.updateSchema([newSchema]);
}, 500),
}),
},
{ {
field: 'productId', field: 'productId',
component: 'Select', component: 'Select',
vIf: ({ formModel }) => formModel.inOrOut === MaterialsInOutEnum.In || isEdit,
label: '产品', label: '产品',
colProps: { colProps: {
span: 16, span: 16,
@ -20,6 +97,7 @@ export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [
componentProps: ({ formInstance, schema, formModel }) => ({ componentProps: ({ formInstance, schema, formModel }) => ({
showSearch: true, showSearch: true,
filterOption: false, filterOption: false,
disabled: isEdit,
fieldNames: { fieldNames: {
label: 'label', label: 'label',
value: 'value', value: 'value',
@ -56,24 +134,6 @@ export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [
}, 500), }, 500),
}), }),
}, },
{
field: 'inOrOut',
component: 'Select',
label: '出入库',
rules: [{ required: true, type: 'number' }],
defaultValue: MaterialsInOutEnum.In,
colProps: {
span: 8,
},
componentProps: {
allowClear: false,
options: [
{ label: '出库', value: MaterialsInOutEnum.Out },
{ label: '入库', value: MaterialsInOutEnum.In },
],
},
},
{ {
label: '时间', label: '时间',
field: 'time', field: 'time',
@ -136,102 +196,6 @@ export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [
field: 'remark', field: 'remark',
component: 'InputTextArea', component: 'InputTextArea',
}, },
// {
// field: 'label',
// component: 'Input',
// label: '合同标题',
// rules: [{ required: true, type: 'string' }],
// colProps: {
// span: 12,
// },
// },
// {
// field: 'partyA',
// component: 'Input',
// label: '甲方',
// rules: [{ required: true, type: 'string' }],
// colProps: {
// span: 12,
// },
// },
// {
// field: 'partyB',
// component: 'Input',
// label: '乙方',
// rules: [{ required: true, type: 'string' }],
// colProps: {
// span: 12,
// },
// },
// {
// field: 'signingDate',
// label: '签订时间',
// component: 'DatePicker',
// // defaultValue: new Date(),
// colProps: { span: 12 },
// componentProps: {},
// },
// {
// field: 'deliveryDeadline',
// label: '交付期限',
// component: 'DatePicker',
// // defaultValue: new Date(),
// colProps: { span: 12 },
// },
// {
// field: 'type',
// label: '合同类型',
// component: 'Select',
// required: true,
// colProps: {
// span: 12,
// },
// componentProps: {
// options: contractTypes.map(({ label, id }) => ({ value: id, label })),
// },
// },
// {
// field: 'status',
// label: '审核结果',
// component: 'Select',
// required:true,
// defaultValue: 0,
// colProps: {
// span: 12,
// },
// componentProps: {
// allowClear: false,
// options: Object.values(ContractStatusEnum)
// .filter((value) => typeof value === 'number')
// .map((item) => formatStatus(item as ContractStatusEnum)),
// },
// },
// {
// field: 'remark',
// component: 'InputTextArea',
// label: '备注',
// },
// {
// field: 'menuIds',
// component: 'Tree',
// label: '菜单权限',
// componentProps: {
// checkable: true,
// vModelKey: 'checkedKeys',
// fieldNames: {
// label: 'name',
// key: 'id',
// },
// style: {
// height: '350px',
// paddingTop: '5px',
// overflow: 'auto',
// borderRadius: '6px',
// border: '1px solid #dcdfe6',
// resize: 'vertical',
// },
// },
// },
]; ];
const getProductOptions = async (keyword?: string): Promise<LabelValueOptions> => { const getProductOptions = async (keyword?: string): Promise<LabelValueOptions> => {
@ -244,12 +208,16 @@ const getProductOptions = async (keyword?: string): Promise<LabelValueOptions> =
); );
}; };
const getCompanyOptions = async ({ keyword, id }): Promise<LabelValueOptions> => { const getInventoryNumberOptions = async (inventoryNumber?: string): Promise<LabelValueOptions> => {
const { items: result } = await Api.company.companyList({ pageSize: 100, name: keyword }); const { items: result } = await Api.materialsInOut.materialsInOutList({
inventoryNumber,
isCreateOut: true,
pageSize: 100,
});
return ( return (
result?.map((item) => ({ result?.map((item) => ({
label: item.name, label: item.inventoryNumber,
value: item.id, value: item.inventoryNumber,
})) || [] })) || []
); );
}; };

View File

@ -18,6 +18,13 @@
> >
新增 新增
</a-button> </a-button>
<a-button
type="primary"
:disabled="!$auth('materials_inventory:history_in_out:export')"
@click="exportMI()"
>
导出原材料盘点表
</a-button>
</template> </template>
</DynamicTable> </DynamicTable>
</div> </div>
@ -25,11 +32,16 @@
<script setup lang="tsx"> <script setup lang="tsx">
import { useTable } from '@/components/core/dynamic-table'; import { useTable } from '@/components/core/dynamic-table';
import { baseColumns, type TableColumnItem, type TableListItem } from './columns'; import {
baseColumns,
type TableColumnItem,
type TableListItem,
type TableQueryItem,
} from './columns';
import Api from '@/api/'; import Api from '@/api/';
import { onMounted, ref, type FunctionalComponent } from 'vue'; import { onMounted, ref, type FunctionalComponent, unref } from 'vue';
import { useFormModal, useModal } from '@/hooks/useModal'; import { useFormModal, useModal } from '@/hooks/useModal';
import { Button } from 'ant-design-vue'; import { Button, message } from 'ant-design-vue';
import { formSchemas } from './formSchemas'; import { formSchemas } from './formSchemas';
import AttachmentManage from '@/components/business/attachment-manage/index.vue'; import AttachmentManage from '@/components/business/attachment-manage/index.vue';
import AttachmentUpload from '@/components/business/attachment-upload/index.vue'; import AttachmentUpload from '@/components/business/attachment-upload/index.vue';
@ -47,8 +59,8 @@
...baseColumns, ...baseColumns,
{ {
title: '附件', title: '附件',
width: 50, width: 40,
maxWidth: 50, maxWidth: 40,
hideInSearch: true, hideInSearch: true,
fixed: 'right', fixed: 'right',
dataIndex: 'files', dataIndex: 'files',
@ -91,7 +103,15 @@
}, },
]; ];
}); });
const exportMI = async () => {
const { time } = unref<TableQueryItem>(
dynamicTableInstance?.queryFormRef?.formModel as TableQueryItem,
);
if (!time) {
message.warn('请先在查询区选择导出月份时间');
}
console.log('exportMI');
};
const openAttachmentUploadModal = async (record: TableListItem) => { const openAttachmentUploadModal = async (record: TableListItem) => {
isUploadPopupVisiable.value = true; isUploadPopupVisiable.value = true;
fnModal.show({ fnModal.show({
@ -133,6 +153,7 @@
const openEditModal = async (record: Partial<TableListItem>) => { const openEditModal = async (record: Partial<TableListItem>) => {
const [formRef] = await showModal({ const [formRef] = await showModal({
modalProps: { modalProps: {
title: `${record.id ? '编辑' : '新增'}出入库记录`, title: `${record.id ? '编辑' : '新增'}出入库记录`,
width: '50%', width: '50%',
onFinish: async (values) => { onFinish: async (values) => {
@ -154,7 +175,7 @@
}, },
formProps: { formProps: {
labelWidth: 100, labelWidth: 100,
schemas: formSchemas, schemas: formSchemas(!!record.id),
}, },
}); });
// //