feat: 出入库记录模块,产品模块开发

This commit is contained in:
louis 2024-03-05 22:26:43 +08:00
parent 11f9c58ee1
commit 55884200da
20 changed files with 302 additions and 202 deletions

View File

@ -77,7 +77,7 @@ export async function unlinkAttachments(
}
/** 更新原材料出入库记录 PUT /api/materials-in-out/${param0} */
export async function MaterialsInOutUpdate(
export async function materialsInOutUpdate(
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
params: API.MaterialsInOutUpdateParams,
body: API.MaterialsInOutUpdateDto,

View File

@ -1,5 +1,7 @@
import { request, type RequestOptions } from '@/utils/request';
/** 获取产品列表 GET /api/product */
export async function productList(params: API.ProductParams, options?: RequestOptions) {
return request<{

View File

@ -1536,7 +1536,8 @@ declare namespace API {
type CompanyParams = {
page?: number;
pageSize?: number;
name?:string;
name?: string;
productId?:number;
field?: string;
order?: 'ASC' | 'DESC';
_t?: number;
@ -1584,7 +1585,8 @@ declare namespace API {
type ProductParams = {
page?: number;
pageSize?: number;
company?:string;
company?: string;
name?: string;
field?: string;
order?: 'ASC' | 'DESC';
_t?: number;
@ -1609,6 +1611,7 @@ declare namespace API {
// Materials In out history
type MaterialsInOutUpdateParams = {
id: number;
fileIds?: number[];
};
type MaterialsInOutInfoParams = {
@ -1626,8 +1629,10 @@ declare namespace API {
type MaterialsInOutEntity = {
/** 公司名称 */
companyName: string;
/** 产品名称 */
product: number;
/** 产品Id */
productId: number;
/** 产品信息 */
product?: ProductEntity;
/** 出库或入库 */
inOrOut: number;
/** 单位(字典) */
@ -1658,8 +1663,10 @@ declare namespace API {
type MaterialsInOutDto = {
/** 公司名称 */
companyName: string;
/** 产品名称 */
product: number;
/** 产品Id */
productId: number;
/** 产品信息 */
product?: ProductEntity;
/** 出库或入库 */
inOrOut: number;
/** 单位(字典) */
@ -1680,14 +1687,12 @@ declare namespace API {
project: string;
/** 备注 */
remark: string;
/** 附件 */
files: StorageInfo[];
};
type MaterialsInOutUpdateDto = {
/** 公司名称 */
companyName: string;
/** 产品名称 */
product: number;
/** 产品Id */
productId: number;
/** 出库或入库 */
inOrOut: number;
/** 单位(字典) */
@ -1709,7 +1714,7 @@ declare namespace API {
/** 备注 */
remark: string;
/** 附件 */
fileIds: number[];
fileIds?: number[];
};
type MaterialsInOutDeleteParams = {
id: number;

View File

@ -3,6 +3,7 @@ import { columnKeyFlags } from '../types';
import type { DynamicTableProps } from '../dynamic-table';
import type { TableMethods, TableState } from './index';
import { exportJson2Excel } from '@/utils/Export2Excel';
import { unref } from 'vue';
export type UseExportData2ExcelContext = {
state: TableState;
@ -23,7 +24,7 @@ export const useExportData2Excel = ({ props, state, methods }: UseExportData2Exc
const theaders = columns.filter((n) => {
const key = getColumnKey(n);
return key && !columnKeyFlags.includes(key);
return key && !columnKeyFlags.includes(key) && n.hideInExport !== true;
});
if (exportFormatter) {
@ -40,9 +41,20 @@ export const useExportData2Excel = ({ props, state, methods }: UseExportData2Exc
});
}
} else {
const data = tableData.value.map((v) =>
theaders.map((header) => {
const { customRender } = unref(header);
if (customRender) {
const renderParam: any = { record: v };
return customRender(renderParam);
} else {
return get(v, getColumnKey(header)!);
}
}),
);
exportJson2Excel({
header: theaders.map((n) => n.title as string),
data: tableData.value.map((v) => theaders.map((header) => get(v, getColumnKey(header)!))),
data,
filename: exportFileName,
bookType: exportBookType,
autoWidth: exportAutoWidth,

View File

@ -36,6 +36,8 @@ export type TableColumn<T extends object = Recordable> = ColumnType<T> & {
searchField?: string;
/** 在查询表单中不展示此项 */
hideInSearch?: boolean;
/** 在表格中不导出此列 */
hideInExport?: boolean;
/** 在 Table 中不展示此列 */
hideInTable?: boolean;
/** 传递给搜索表单 Form.Item 的配置,可以配置 rules */

View File

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

View File

@ -6,7 +6,7 @@ import { ACCESS_TOKEN_KEY } from '@/enums/cacheEnum';
import { Storage } from '@/utils/Storage';
import { ResultEnum } from '@/enums/httpEnum';
import { useUserStore } from '@/store/modules/user';
import * as qs from 'qs';
export interface RequestOptions extends AxiosRequestConfig {
/** 是否直接将数据从响应中提取出,例如直接返回 res.data而忽略 res.code 等信息 */
isReturnResult?: boolean;
@ -123,15 +123,20 @@ export async function request(_url: string | RequestOptions, _config: RequestOpt
try {
// 兼容 from data 文件上传的情况
const { requestType, isReturnResult = true, ...rest } = config;
// 修复query传递数组时time变成time[]的解析问题
const paramsSerializer = (params) => {
return qs.stringify(params, { arrayFormat: 'repeat' });
};
const response = (await service.request({
url,
...rest,
paramsSerializer, //
headers: {
...rest.headers,
...(requestType === 'form' ? { 'Content-Type': 'multipart/form-data' } : {}),
},
})) as AxiosResponse<BaseResponse>;
const { data } = response;
const { code, message } = data || {};

View File

@ -57,6 +57,7 @@ export const baseColumns: TableColumnItem[] = [
width: 120,
align: 'center',
dataIndex: 'time',
formItemProps: { component: 'RangePicker' },
customRender: ({ record }) => {
return formatToDate(record.time);
},
@ -78,6 +79,7 @@ export const baseColumns: TableColumnItem[] = [
width: 80,
align: 'center',
dataIndex: 'amount',
hideInSearch: true,
},
{
title: '经办人',

View File

@ -0,0 +1,191 @@
import type { FormSchema } from '@/components/core/schema-form/';
import { ContractStatusEnum } from '@/enums/contractEnum';
import { formatStatus } from './columns';
import Api from '@/api';
import { debounce } from 'lodash-es';
import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum';
export const formSchemas: FormSchema<API.MaterialsInOutEntity>[] = [
{
field: 'productId',
component: 'Select',
label: '产品',
colProps: {
span: 16,
},
helpMessage:'如未找到对应产品,请先去产品管理添加产品。',
rules: [{ required: true, type: 'number' }],
componentProps: ({ formInstance, schema, formModel }) => ({
showSearch: true,
filterOption: false,
fieldNames: {
label: 'label',
value: 'value',
},
options: [],
getPopupContainer: () => document.body,
defaultActiveFirstOption: true,
onChange: async (value) => {
if (!value) {
const options = await getProductOptions();
const newSchema = {
field: schema.field,
componentProps: {
options,
},
};
formInstance?.updateSchema([newSchema]);
}
},
request: () => {
return getProductOptions();
},
onSearch: debounce(async (keyword) => {
schema.loading = true;
const newSchema = {
field: schema.field,
componentProps: {
options: [] as LabelValueOptions,
},
};
formInstance?.updateSchema([newSchema]);
const options = await getProductOptions(keyword).finally(() => (schema.loading = false));
newSchema.componentProps.options = options;
formInstance?.updateSchema([newSchema]);
}, 500),
}),
},
{
field: 'inOrOut',
component: 'Select',
label: '出入库',
rules: [{ required: true, type: 'number' }],
defaultValue: MaterialsInOutEnum.In,
colProps: {
span: 8,
},
componentProps: {
options: [
{ label: '出库', value: MaterialsInOutEnum.Out },
{ label: '入库', value: MaterialsInOutEnum.In },
],
},
},
// {
// field: 'title',
// 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: {
// title: '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 { items: result } = await Api.product.productList({ pageSize: 100, name: keyword });
return (
result?.map((item) => ({
label: `${item.name}` + (item.company?.name ? `(${item.company?.name})` : ''),
value: item.id,
})) || []
);
};
const getCompanyOptions = async ({ keyword, id }): Promise<LabelValueOptions> => {
const { items: result } = await Api.company.companyList({ pageSize: 100, name: keyword });
return (
result?.map((item) => ({
label: item.name,
value: item.id,
})) || []
);
};

View File

@ -30,6 +30,7 @@
import { onMounted, ref, type FunctionalComponent } from 'vue';
import { useFormModal, useModal } from '@/hooks/useModal';
import { Button } from 'ant-design-vue';
import { formSchemas } from './formSchemas';
import AttachmentManage from '@/components/business/attachment-manage/index.vue';
import AttachmentUpload from '@/components/business/attachment-upload/index.vue';
defineOptions({
@ -93,24 +94,24 @@
});
const openAttachmentUploadModal = async (record: TableListItem) => {
// isUploadPopupVisiable.value = true;
// fnModal.show({
// width: 800,
// title: `: ${record.contractNumber}`,
// content: () => {
// return (
// <AttachmentUpload
// onClose={handleUploadClose}
// afterUploadCallback={(files) => {
// afterUploadCallback(files, record.id);
// }}
// ></AttachmentUpload>
// );
// },
// destroyOnClose: true,
// open: isUploadPopupVisiable.value,
// footer: null,
// });
isUploadPopupVisiable.value = true;
fnModal.show({
width: 800,
title: `上传附件: ${record.id}`,
content: () => {
return (
<AttachmentUpload
onClose={handleUploadClose}
afterUploadCallback={(files) => {
afterUploadCallback(files, record.id);
}}
></AttachmentUpload>
);
},
destroyOnClose: true,
open: isUploadPopupVisiable.value,
footer: null,
});
};
const handleUploadClose = (hasSuccess: boolean) => {
fnModal.hide();
@ -128,37 +129,36 @@
* @description 打开新增/编辑弹窗
*/
const openEditModal = async (record: Partial<TableListItem>) => {
// const [formRef] = await showModal({
// modalProps: {
// title: `${record.id ? '' : ''}`,
// width: '50%',
// onFinish: async (values) => {
// const params = {
// ...values,
// signingDate: formatToDate(values.signingDate),
// deliveryDeadline: formatToDate(values.deliveryDeadline),
// };
// if (record.id) {
// await Api.contract.contractUpdate({ id: record.id }, params);
// } else {
// await Api.contract.contractCreate(params);
// }
// dynamicTableInstance?.reload();
// },
// },
// formProps: {
// labelWidth: 100,
// schemas: contractSchemas(contractTypes.value),
// },
// });
// //
// if (record.id) {
// const info = await Api.contract.contractInfo({ id: record.id });
// formRef?.setFieldsValue({
// ...info,
// });
// }
const [formRef] = await showModal({
modalProps: {
title: `${record.id ? '编辑' : '新增'}出入库记录`,
width: '50%',
onFinish: async (values) => {
const params: API.MaterialsInOutUpdateDto = {
...values,
// signingDate: formatToDate(values.signingDate),
// deliveryDeadline: formatToDate(values.deliveryDeadline),
};
if (record.id) {
await Api.materialsInOut.materialsInOutUpdate({ id: record.id }, params);
} else {
await Api.materialsInOut.materialsInOutCreate(params);
}
dynamicTableInstance?.reload();
},
},
formProps: {
labelWidth: 100,
schemas: formSchemas,
},
});
//
if (record.id) {
const info = await Api.contract.contractInfo({ id: record.id });
formRef?.setFieldsValue({
...info,
});
}
};
const delRowConfirm = async (record) => {
await Api.contract.contractDelete({ id: record });

View File

@ -37,7 +37,7 @@
import AttachmentManage from '@/components/business/attachment-manage/index.vue';
import AttachmentUpload from '@/components/business/attachment-upload/index.vue';
defineOptions({
name: 'MeterialsInventory',
name: 'MaterialsInventory',
});
const [DynamicTable, dynamicTableInstance] = useTable();
const [showModal] = useFormModal();

View File

@ -16,12 +16,7 @@ export const formSchemas: FormSchema<API.ProductDto>[] = [
field: 'companyId',
component: 'Select',
label: '所属公司',
// componentProps: {
// request: async () => {
// const { items: result } = await Api.company.companyList({ pageSize: 100 });
// return result?.map((item) => ({ label: item.name, value: item.id }));
// },
// },
helpMessage: '如未找到对应公司,请先去公司管理添加公司。',
componentProps: ({ formInstance, schema }) => ({
showSearch: true,
filterOption: false,
@ -32,24 +27,23 @@ export const formSchemas: FormSchema<API.ProductDto>[] = [
options: [],
getPopupContainer: () => document.body,
defaultActiveFirstOption: true,
onChange: async (value, option) => {
onChange: async (value) => {
console.log('onChange');
if (!value) {
formInstance?.setFieldsValue({ companyId: undefined });
const { items: result } = await Api.company.companyList({ pageSize: 100 });
const options = await getCompanyOptions();
const newSchema = {
field: schema.field,
componentProps: {
options: result?.map((item) => ({ label: item.name, value: item.id })),
options,
},
};
formInstance?.updateSchema([newSchema]);
}
},
request: () => {
return getCompanyOptions();
},
onSearch: debounce(async (keyword) => {
schema.loading = true;
@ -60,23 +54,16 @@ export const formSchemas: FormSchema<API.ProductDto>[] = [
},
};
formInstance?.updateSchema([newSchema]);
const { items: result } = await Api.company
.companyList({ pageSize: 100, name: keyword })
.finally(() => (schema.loading = false));
if (result) {
newSchema.componentProps.options = result.map((item) => ({
value: item.id,
label: item.name,
}));
}
const options = await getCompanyOptions(keyword).finally(() => (schema.loading = false));
newSchema.componentProps.options = options;
formInstance?.updateSchema([newSchema]);
}, 500),
}),
},
];
const getCompanyOptions = async (keyword?): Promise<LabelValueOptions> => {
const { items: result } = await Api.company.companyList({ pageSize: 100 });
const getCompanyOptions = async (keyword?: string): Promise<LabelValueOptions> => {
const { items: result } = await Api.company.companyList({ pageSize: 100, name: keyword });
return (
result?.map((item) => ({
label: item.name,

View File

@ -6,6 +6,7 @@
title-tooltip=""
:data-request="Api.product.productList"
:columns="columns"
:exportFileName="'产品'"
bordered
size="small"
>
@ -23,7 +24,7 @@
</template>
<script setup lang="tsx">
import { useTable, type LoadDataParams } from '@/components/core/dynamic-table';
import { useTable, type LoadDataParams, type TableColumn } from '@/components/core/dynamic-table';
import { baseColumns, type TableColumnItem, type TableListItem } from './columns';
import Api from '@/api/';
import { useFormModal, useModal } from '@/hooks/useModal';
@ -54,6 +55,9 @@
// });
// return data;
// };
const exportFormatter = (columns: TableColumn[], tableData: any[]) => {
return { header: columns.map((item) => item.title), data: [] };
};
onMounted(() => {
columns.value = [
...baseColumns,
@ -62,6 +66,7 @@
width: 50,
maxWidth: 50,
hideInSearch: true,
hideInExport: true,
dataIndex: 'files',
customRender: ({ record }) => <FilesRender {...record} />,
},

View File

@ -1,111 +0,0 @@
import type { FormSchema } from '@/components/core/schema-form/';
import { ContractStatusEnum } from '@/enums/contractEnum';
import { formatStatus } from './columns';
export const formSchemas: FormSchema<API.ContractEntity>[] = [
// {
// field: 'contractNumber',
// component: 'Input',
// label: '合同编号',
// rules: [{ required: true, type: 'string' }],
// colProps: {
// span: 12,
// },
// },
// {
// field: 'title',
// 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: {
// title: 'name',
// key: 'id',
// },
// style: {
// height: '350px',
// paddingTop: '5px',
// overflow: 'auto',
// borderRadius: '6px',
// border: '1px solid #dcdfe6',
// resize: 'vertical',
// },
// },
// },
];