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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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