feat:inventory

This commit is contained in:
louis 2024-03-27 14:10:56 +08:00
parent 8ffd117dcf
commit a1cf5fc468
8 changed files with 147 additions and 111 deletions

View File

@ -1389,6 +1389,8 @@ declare namespace API {
}; };
type MaterialsInventoryEntity = { type MaterialsInventoryEntity = {
/** 库存编号 */
inventoryNumber: string;
/** 项目 */ /** 项目 */
project: ProjectEntity; project: ProjectEntity;
/** 产品 */ /** 产品 */
@ -1621,7 +1623,7 @@ declare namespace API {
type ProductParams = { type ProductParams = {
page?: number; page?: number;
pageSize?: number; pageSize?: number;
keyword?:string; keyword?: string;
company?: string; company?: string;
name?: string; name?: string;
field?: string; field?: string;
@ -1769,14 +1771,14 @@ declare namespace API {
type MaterialsInOutInfoParams = { type MaterialsInOutInfoParams = {
id?: number; id?: number;
inventoryNumber?: string; inventoryInOutNumber?: string;
}; };
type MaterialsInOutListParams = { type MaterialsInOutListParams = {
page?: number; page?: number;
pageSize?: number; pageSize?: number;
time?: string; time?: string;
inventoryNumber?: string; inventoryInOutNumber?: string;
isCreateOut?: boolean; isCreateOut?: boolean;
project?: string; project?: string;
field?: string; field?: string;
@ -1787,8 +1789,8 @@ declare namespace API {
type MaterialsInOutEntity = { type MaterialsInOutEntity = {
/** 入库后的库存Id */ /** 入库后的库存Id */
inventoryId: number; inventoryId: number;
/** 编号 */ /** 出入库编号 */
inventoryNumber: string; inventoryInOutNumber: string;
/** 公司信息 */ /** 公司信息 */
company: CompanyEntity; company: CompanyEntity;
/** 产品Id */ /** 产品Id */

View File

@ -6,6 +6,7 @@ import { useFormModal } from '@/hooks/useModal/';
export type OpenModalOptions = { export type OpenModalOptions = {
onOk: (val: ExportModalResult) => any; onOk: (val: ExportModalResult) => any;
formSchemas?: FormSchema<ExportModalResult>[];
}; };
const getSchemas = (t): FormSchema<ExportModalResult>[] => [ const getSchemas = (t): FormSchema<ExportModalResult>[] => [
@ -15,44 +16,44 @@ const getSchemas = (t): FormSchema<ExportModalResult>[] => [
label: t('component.excel.fileName'), label: t('component.excel.fileName'),
rules: [{ required: true }], rules: [{ required: true }],
}, },
{ // {
field: 'bookType', // field: 'bookType',
component: 'Select', // component: 'Select',
label: t('component.excel.fileType'), // label: t('component.excel.fileType'),
defaultValue: 'xlsx', // defaultValue: 'xlsx',
rules: [{ required: true }], // rules: [{ required: true }],
componentProps: { // componentProps: {
options: [ // options: [
{ // {
label: 'xlsx', // label: 'xlsx',
value: 'xlsx', // value: 'xlsx',
key: 'xlsx', // key: 'xlsx',
}, // },
{ // {
label: 'html', // label: 'html',
value: 'html', // value: 'html',
key: 'html', // key: 'html',
}, // },
{ // {
label: 'csv', // label: 'csv',
value: 'csv', // value: 'csv',
key: 'csv', // key: 'csv',
}, // },
{ // {
label: 'txt', // label: 'txt',
value: 'txt', // value: 'txt',
key: 'txt', // key: 'txt',
}, // },
], // ],
}, // },
}, // },
]; ];
export const useExportExcelModal = () => { export const useExportExcelModal = () => {
const { t } = useI18n(); const { t } = useI18n();
const [showModal] = useFormModal(); const [showModal] = useFormModal();
const openModal = ({ onOk }: OpenModalOptions) => { const openModal = ({ onOk, formSchemas = [] }: OpenModalOptions) => {
showModal<ExportModalResult>({ showModal<ExportModalResult>({
modalProps: { modalProps: {
title: t('component.excel.exportModalTitle'), title: t('component.excel.exportModalTitle'),
@ -67,7 +68,7 @@ export const useExportExcelModal = () => {
}, },
formProps: { formProps: {
labelWidth: 100, labelWidth: 100,
schemas: getSchemas(t), schemas: [...formSchemas, ...getSchemas(t)],
}, },
}); });
}; };

View File

@ -24,4 +24,5 @@ export interface AoAToSheet<T = any> {
export interface ExportModalResult { export interface ExportModalResult {
filename: string; filename: string;
bookType: BookType; bookType: BookType;
time?: Date[];
} }

View File

@ -9,13 +9,22 @@ export type TableListItem = API.MaterialsInOutEntity;
export type TableQueryItem = API.MaterialsInOutListParams; export type TableQueryItem = API.MaterialsInOutListParams;
export type TableColumnItem = TableColumn<TableListItem>; export type TableColumnItem = TableColumn<TableListItem>;
export const baseColumns: TableColumnItem[] = [ export const baseColumns: TableColumnItem[] = [
{
title: '时间范围',
hideInTable: true,
dataIndex: 'time',
formItemProps: {
component: 'RangePicker',
componentProps: ({ formInstance, schema, formModel }) => ({}),
},
},
{ {
title: '出入库单号', title: '出入库单号',
width: 100, width: 100,
fixed: 'left', fixed: 'left',
dataIndex: 'inventoryNumber', dataIndex: 'inventoryInOutNumber',
customRender: ({ record }) => { customRender: ({ record }) => {
return record.inventoryNumber || ''; return record.inventoryInOutNumber || '';
}, },
formItemProps: { formItemProps: {
labelWidth: 120, labelWidth: 120,
@ -73,6 +82,7 @@ export const baseColumns: TableColumnItem[] = [
title: '所属公司', title: '所属公司',
width: 100, width: 100,
dataIndex: 'company', dataIndex: 'company',
hideInSearch: true,
customRender: ({ record }) => { customRender: ({ record }) => {
return record.product?.company?.name || ''; return record.product?.company?.name || '';
}, },
@ -118,6 +128,7 @@ export const baseColumns: TableColumnItem[] = [
width: 60, width: 60,
align: 'center', align: 'center',
dataIndex: 'time', dataIndex: 'time',
hideInSearch: true,
formItemProps: { formItemProps: {
component: 'MonthPicker', component: 'MonthPicker',
}, },

View File

@ -226,9 +226,9 @@ export const formSchemas = (isEdit?: boolean): FormSchema<API.MaterialsInOutEnti
colProps: { colProps: {
span: 12, span: 12,
}, },
rules: [{ required: true, type: 'number', min: 1 }], rules: [{ required: true, type: 'number', min: 1 }],
componentProps: ({ formInstance, formModel }) => ({ componentProps: ({ formInstance, formModel }) => ({
disabled: isEdit,
onBlur(e) { onBlur(e) {
const { quantity, unitPrice, amount, inOrOut } = toRaw(formModel); const { quantity, unitPrice, amount, inOrOut } = toRaw(formModel);
// 出库只关心数量,单价已经有了,直接算出出库金额 // 出库只关心数量,单价已经有了,直接算出出库金额
@ -267,6 +267,7 @@ export const formSchemas = (isEdit?: boolean): FormSchema<API.MaterialsInOutEnti
return formModel.inOrOut === MaterialsInOutEnum.Out; return formModel.inOrOut === MaterialsInOutEnum.Out;
}, },
componentProps: ({ formInstance, formModel }) => ({ componentProps: ({ formInstance, formModel }) => ({
disabled: isEdit,
onBlur(e) { onBlur(e) {
const { quantity, unitPrice } = toRaw(formModel); const { quantity, unitPrice } = toRaw(formModel);
if (quantity) { if (quantity) {
@ -291,6 +292,7 @@ export const formSchemas = (isEdit?: boolean): FormSchema<API.MaterialsInOutEnti
return formModel.inOrOut === MaterialsInOutEnum.Out; return formModel.inOrOut === MaterialsInOutEnum.Out;
}, },
componentProps: ({ formInstance, formModel }) => ({ componentProps: ({ formInstance, formModel }) => ({
disabled: isEdit,
onBlur(e) { onBlur(e) {
const { quantity, amount } = toRaw(formModel); const { quantity, amount } = toRaw(formModel);
if (quantity) { if (quantity) {
@ -346,16 +348,18 @@ const getProductOptions = async (keyword?: string): Promise<LabelValueOptions> =
); );
}; };
const getInventoryNumberOptions = async (inventoryNumber?: string): Promise<LabelValueOptions> => { const getInventoryNumberOptions = async (
inventoryInOutNumber?: string,
): Promise<LabelValueOptions> => {
const { items: result } = await Api.materialsInOut.materialsInOutList({ const { items: result } = await Api.materialsInOut.materialsInOutList({
inventoryNumber, inventoryInOutNumber,
isCreateOut: true, isCreateOut: true,
pageSize: 100, pageSize: 100,
}); });
return ( return (
result?.map((item) => ({ result?.map((item) => ({
label: `${item.inventoryNumber} (${item.project?.name || '-'}) (${item.product?.company?.name || '-'}) (${item.product?.name || '-'})`, label: `${item.inventoryInOutNumber} (${item.project?.name || '-'}) (${item.product?.company?.name || '-'}) (${item.product?.name || '-'})`,
value: item.inventoryNumber, value: item.inventoryInOutNumber,
})) || [] })) || []
); );
}; };

View File

@ -34,15 +34,15 @@
import { useFormModal, useModal } from '@/hooks/useModal'; import { useFormModal, useModal } from '@/hooks/useModal';
import { Button } from 'ant-design-vue'; import { Button } 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';
import { useExportExcelModal, jsonToSheetXlsx } from '@/components/basic/excel'; import { useExportExcelModal, jsonToSheetXlsx } from '@/components/basic/excel';
import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum'; import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum';
import { formatToDate } from '@/utils/dateUtil'; import { formatToDate } from '@/utils/dateUtil';
defineOptions({ defineOptions({
name: 'MaterialsInOut', name: 'MaterialsInOut',
}); });
const [DynamicTable, dynamicTableInstance] = useTable({ formProps: { autoSubmitOnEnter: true } }); const [DynamicTable, dynamicTableInstance] = useTable({ formProps: { autoSubmitOnEnter: true } });
const [showModal] = useFormModal(); const [showModal] = useFormModal();
const exportExcelModal = useExportExcelModal(); const exportExcelModal = useExportExcelModal();
@ -102,34 +102,42 @@ import { formatToDate } from '@/utils/dateUtil';
const openExportModal = () => { const openExportModal = () => {
exportExcelModal.openModal({ exportExcelModal.openModal({
formSchemas: [
{
field: 'time',
component: 'RangePicker',
label:'时间范围',
rules: [{ required: true }],
},
],
onOk: ({ filename, bookType }) => { onOk: ({ filename, bookType }) => {
const tableData: TableListItem[] = dynamicTableInstance.tableData; const tableData: TableListItem[] = dynamicTableInstance.tableData;
let exportData: any[] = [] let exportData: any[] = []
for (let item of tableData) { for (let item of tableData) {
exportData.push({ exportData.push({
projectName:item.project?.name, projectName: item.project?.name,
inOrOut: item.inOrOut === MaterialsInOutEnum.In ? '入库' : '出库', inOrOut: item.inOrOut === MaterialsInOutEnum.In ? '入库' : '出库',
inventoryNumber:item.inventoryNumber, inventoryInOutNumber: item.inventoryInOutNumber,
time:formatToDate(item.time), time: formatToDate(item.time),
company:item.product?.company?.name, company: item.product?.company?.name,
productName:item.product?.name, productName: item.product?.name,
productSpecification:item.product?.productSpecification, productSpecification: item.product?.productSpecification,
unit:item.product?.unit?.label, unit: item.product?.unit?.label,
quantity:item.quantity, quantity: item.quantity,
unitPrice:parseFloat(item.unitPrice), unitPrice: parseFloat(item.unitPrice),
amount:parseFloat(item.amount), amount: parseFloat(item.amount),
agent:item.agent, agent: item.agent,
issuanceNumber:item.issuanceNumber, issuanceNumber: item.issuanceNumber,
remark:item.remark remark: item.remark
}) })
} }
jsonToSheetXlsx({ jsonToSheetXlsx({
data: exportData, data: exportData,
header: { header: {
inOrOut: '出/入库', inOrOut: '出/入库',
inventoryNumber: '出入库单号', inventoryInOutNumber: '出入库单号',
time: '时间', time: '时间',
projectName:'项目', projectName: '项目',
company: '公司', company: '公司',
productName: '产品名', productName: '产品名',
productSpecification: "产品规格", productSpecification: "产品规格",
@ -148,7 +156,7 @@ import { formatToDate } from '@/utils/dateUtil';
json2sheetOpts: { json2sheetOpts: {
// //
header: [ header: [
'inOrOut', 'inventoryNumber', 'time','projectName', 'company', 'productName', 'productSpecification', 'unit', 'quantity', 'inOrOut', 'inventoryInOutNumber', 'time', 'projectName', 'company', 'productName', 'productSpecification', 'unit', 'quantity',
'unitPrice', 'amount', 'agent', 'issuanceNumber', 'remark'], 'unitPrice', 'amount', 'agent', 'issuanceNumber', 'remark'],
}, },
}); });

View File

@ -9,6 +9,15 @@ export type TableListItem = API.MaterialsInventoryEntity;
export type TableColumnItem = TableColumn<TableListItem>; export type TableColumnItem = TableColumn<TableListItem>;
const dictStore = useDictStore(); const dictStore = useDictStore();
export const baseColumns: TableColumnItem[] = [ export const baseColumns: TableColumnItem[] = [
{
title: '库存编号',
width: 120,
dataIndex: 'inventoryNumber',
fixed: 'left',
customRender: ({ record }) => {
return record?.inventoryNumber || '';
},
},
{ {
title: '所属项目', title: '所属项目',
width: 180, width: 180,
@ -66,12 +75,7 @@ export const baseColumns: TableColumnItem[] = [
return record?.product?.unit?.label || ''; return record?.product?.unit?.label || '';
}, },
}, },
{
title: '库存数量',
hideInSearch: true,
width: 80,
dataIndex: 'quantity',
},
{ {
title: '入库库存单价', title: '入库库存单价',
hideInSearch: true, hideInSearch: true,
@ -81,6 +85,13 @@ export const baseColumns: TableColumnItem[] = [
return parseFloat(record.unitPrice) || 0; return parseFloat(record.unitPrice) || 0;
}, },
}, },
{
title: '库存数量',
hideInSearch: true,
fixed:'right',
width: 80,
dataIndex: 'quantity',
},
]; ];
export function formatStatus(status: ContractStatusEnum): { export function formatStatus(status: ContractStatusEnum): {

View File

@ -1,28 +1,25 @@
<template> <template>
<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.materialsInventory.materialsInventoryList" :data-request="Api.materialsInventory.materialsInventoryList"
:columns="columns" :columns="columns"
bordered bordered
size="small" size="small"
> :scroll="{ x: 1920 }">
<template #toolbar> <template #toolbar>
<a-button <a-button type="primary"
type="primary"
:disabled="!$auth('app:materials_inventory:export')" :disabled="!$auth('app:materials_inventory:export')"
@click="exportMI()" @click="exportMI()">
>
导出原材料盘点表 导出原材料盘点表
</a-button></template </a-button></template>
>
</DynamicTable> </DynamicTable>
</div> </div>
</template> </template>
<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 } from './columns';
import Api from '@/api/'; import Api from '@/api/';
@ -43,36 +40,36 @@
columns.value = [ columns.value = [
...baseColumns, ...baseColumns,
{ // {
title: '操作', // title: '',
maxWidth: 60, // maxWidth: 60,
width: 60, // width: 60,
minWidth: 60, // minWidth: 60,
dataIndex: 'ACTION', // dataIndex: 'ACTION',
hideInSearch: true, // hideInSearch: true,
actions: ({ record }) => [ // actions: ({ record }) => [
{ // {
icon: 'ant-design:edit-outlined', // icon: 'ant-design:edit-outlined',
tooltip: '编辑', // tooltip: '',
auth: { // auth: {
perm: 'app:materials_inventory:update', // perm: 'app:materials_inventory:update',
effect: 'disable', // effect: 'disable',
}, // },
onClick: () => openEditModal(record), // onClick: () => openEditModal(record),
}, // },
// { // // {
// icon: 'ant-design:delete-outlined', // // icon: 'ant-design:delete-outlined',
// color: 'red', // // color: 'red',
// tooltip: '', // // tooltip: '',
// auth: 'app:materials_inventory:delete', // // auth: 'app:materials_inventory:delete',
// popConfirm: { // // popConfirm: {
// title: '', // // title: '',
// placement: 'left', // // placement: 'left',
// onConfirm: () => delRowConfirm(record.id), // // onConfirm: () => delRowConfirm(record.id),
// }, // // },
// }, // // },
], // ],
}, // },
]; ];
}); });
const exportMI = async () => { const exportMI = async () => {
@ -152,7 +149,8 @@
}; };
</script> </script>
<style lang="less" scoped></style> <style lang="less"
scoped></style>
import dayjs from 'dayjs'; import fileDownload from 'js-file-download'; import type { TableQueryItem import dayjs from 'dayjs'; import fileDownload from 'js-file-download'; import type { TableQueryItem
} from '../in-out/columns'; import { exportSchemas } from '../in-out/exportSchema'; import dayjs } from '../in-out/columns'; import { exportSchemas } from '../in-out/exportSchema'; import dayjs
from 'dayjs'; import fileDownload from 'js-file-download'; import type { TableQueryItem } from from 'dayjs'; import fileDownload from 'js-file-download'; import type { TableQueryItem } from