Commit df9f916a authored by XieZhiXiong's avatar XieZhiXiong

完成库存相关

parent 11bb64cf
......@@ -222,9 +222,14 @@ export const auditModalSchema: ISchema = {
'x-component': 'textarea',
'x-component-props': {
placeholder: '在此输入你的内容,最长120个字符,60个汉字',
maxLength: 60,
rows: 5,
},
'x-rules': [
{
limitByte: true, // 自定义校验规则
maxByte: 120,
}
],
},
},
},
......
.safe {
padding: 4px 11px;
min-height: 32px;
border-radius: 4px;
border: 1px solid #d9d9d9;
cursor: pointer;
}
\ No newline at end of file
import React, { useState, useEffect, useRef } from 'react';
import { history } from 'umi';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Input, Card } from 'antd';
import { Input, Card, Space, Modal } from 'antd';
import {
SettingOutlined,
} from '@ant-design/icons';
import { StandardTable } from 'god';
import { ColumnType } from 'antd/lib/table/interface';
import EyePreview from '@/components/EyePreview';
......@@ -9,47 +12,39 @@ import NiceForm from '@/components/NiceForm';
import { createFormActions, FormEffectHooks } from '@formily/antd';
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch';
import { FORM_FILTER_PATH } from '@/formSchema/const';
import { inventorySchema } from './schema';
import { PublicApi } from '@/services/api';
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
import { inventorySchema, safetyModalSchema } from './schema';
import styles from './index.less';
const formActions = createFormActions();
// 模拟请求
const fetchData = (params: any) => {
return new Promise((resolve, reject) => {
PublicApi.getWarehouseInventoryList({
itemNo: '',
goodsName: '',
specifications: '',
category: '',
brand: '',
warehouseId: '',
current: params.current,
pageSize: params.pageSize,
}).then(res => {
resolve(res.data);
});
});
};
const modalFormActions = createFormActions();
const Inventory: React.FC<{}> = () => {
const [current, setCurrent] = useState(null);
const [modalVisible, setModalVisible] = useState(false);
const [confirmLoading, setConfirmLoading] = useState(false);
const ref = useRef<any>({});
const handleUpdateSafetyStock = record => {
setCurrent(record);
setModalVisible(true);
};
const columns: ColumnType<any>[] = [
{
title: 'ID',
align: 'center',
dataIndex: 'id',
key: 'id',
},
{
title: '商品名称',
dataIndex: 'goodsName',
align: 'center',
key: 'goodsName',
render: (text: any, record: any) => (
<EyePreview
url={`/repositories/viewRepository?id=${record.key}&preview=1`}
url={`/repositories/viewRepository?id=${record.id}&preview=1`}
>
{text}
</EyePreview>
......@@ -57,65 +52,98 @@ const Inventory: React.FC<{}> = () => {
},
{
title: '规格型号',
align: 'center',
dataIndex: 'specifications',
key: 'specifications',
align: 'center',
},
{
title: '品类',
align: 'center',
dataIndex: 'category',
key: 'category',
align: 'center',
},
{
title: '品牌',
align: 'center',
dataIndex: 'brand',
key: 'brand',
align: 'center',
},
{
title: '单位',
align: 'center',
dataIndex: 'unit',
key: 'unit',
align: 'center',
},
{
title: '价格',
align: 'center',
dataIndex: 'price',
key: 'price',
dataIndex: 'costPrice',
align: 'center',
render: text => ${text}`
},
{
title: '仓库',
align: 'center',
dataIndex: 'warehouse',
key: 'warehouse',
align: 'center',
},
{
title: '库存',
align: 'center',
dataIndex: 'inventory',
key: 'inventory',
align: 'center',
},
{
title: '安全库存',
align: 'center',
title: '金额',
dataIndex: 'price',
align: 'center',
render: text => ${text}`
},
{
title: (
<Space>
安全库存
<SettingOutlined />
</Space>
),
dataIndex: 'safeStock',
key: 'safeStock',
render: (text: any, record: any) => {
return (
<Input
value={record.safeInventory}
allowClear
onChange={e => handleChange(e)}
></Input>
);
},
align: 'center',
render: (text, record) => (
<div className={styles.safe} onClick={() => handleUpdateSafetyStock(record)}>
{text}
</div>
),
},
];
const handleChange = (e: any) => {
console.log(e);
const fetchListData = (params: any) => {
return new Promise((resolve, reject) => {
PublicApi.getWarehouseInventoryList(params)
.then(res => {
if (res.code === 1000) {
resolve(res.data);
}
reject();
})
.catch(() => {
reject();
});
});
};
// 获取对应仓库
const fetchInventory = async () => {
const { data } = await PublicApi.getWarehouseWarehouseAll();
return data.map(v => ({ label: v.name, value: v.id }));
};
// 修改安全库存
const handleSubmit = async values => {
setConfirmLoading(true);
const res = await PublicApi.postWarehouseInventorySafetyUpdate({
id: current.id,
safetyInvoices: +values.safetyInvoices,
});
if (res.code === 1000) {
setModalVisible(false);
ref.current.reload();
}
setConfirmLoading(false);
};
return (
......@@ -124,8 +152,10 @@ const Inventory: React.FC<{}> = () => {
<StandardTable
columns={columns}
currentRef={ref}
tableProps={{ rowKey: 'key' }}
fetchTableData={(params: any) => fetchData(params)}
tableProps={{
rowKey: 'id',
}}
fetchTableData={(params: any) => fetchListData(params)}
controlRender={
<NiceForm
actions={formActions}
......@@ -134,15 +164,37 @@ const Inventory: React.FC<{}> = () => {
useStateFilterSearchLinkageEffect(
$,
actions,
'search',
'goodsName',
FORM_FILTER_PATH,
);
useAsyncSelect('warehouseId', fetchInventory);
}}
schema={inventorySchema}
/>
}
/>
</Card>
<Modal
title="调整安全库存"
visible={modalVisible}
confirmLoading={confirmLoading}
onOk={() => modalFormActions.submit()}
onCancel={() => setModalVisible(false)}
destroyOnClose
>
<NiceForm
effects={($, { setFieldState }) => {
}}
initialValues={{
safetyInvoices: current?.safeStock,
}}
actions={modalFormActions}
schema={safetyModalSchema}
onSubmit={handleSubmit}
/>
</Modal>
</PageHeaderWrapper>
);
};
......
import { ISchema } from '@formily/antd';
import { FORM_FILTER_PATH } from '@/formSchema/const';
import { PATTERN_MAPS } from '@/constants/regExp';
export const inventorySchema: ISchema = {
type: 'object',
properties: {
megaLayout: {
type: 'object',
'x-component': 'mega-layout',
'x-component': 'mega-layout',
properties: {
search: {
goodsName: {
type: 'string',
'x-component': 'Search',
'x-mega-props': {},
......@@ -21,36 +22,51 @@ export const inventorySchema: ISchema = {
type: 'object',
'x-component': 'mega-layout',
'x-component-props': {
inline: true,
grid: true,
full: true,
autoRow: true,
columns: 6,
},
properties: {
itemNo: {
type: 'string',
'x-component-props': {
placeholder: '货号',
},
},
specifications: {
type: 'string',
'x-component-props': {
placeholder: '请选择',
placeholder: '规格型号',
},
enum: [],
},
category: {
type: 'string',
'x-component-props': {
placeholder: '请选择品类',
placeholder: '品类',
},
enum: [],
},
brand: {
type: 'string',
'x-component-props': {
placeholder: '请选择品牌',
placeholder: '品牌',
},
enum: [],
},
warehouse: {
warehouseId: {
type: 'string',
'x-component-props': {
placeholder: '请选择仓库',
placeholder: '仓库',
},
enum: [],
},
submit: {
'x-component': 'Submit',
'x-mega-props': {
span: 1,
},
'x-component-props': {
children: '查询',
},
enum: [],
},
},
},
......@@ -58,3 +74,32 @@ export const inventorySchema: ISchema = {
},
},
};
export const safetyModalSchema: ISchema = {
type: 'object',
properties: {
MEAGLAYOUT: {
type: 'object',
'x-component': 'Mega-Layout',
'x-component-props': {
labelAlign: 'top',
},
properties: {
safetyInvoices: {
type: 'string',
title: '安全库存',
required: true,
'x-component-props': {
placeholder: '请输入',
},
'x-rules': [
{
pattern: PATTERN_MAPS.weight,
message: '请输入正数',
},
],
},
},
},
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment