Commit 452e54a3 authored by XieZhiXiong's avatar XieZhiXiong

完善进销存 -》 仓库相关

parent 461808eb
/*
* @Author: XieZhiXiong
* @Date: 2020-08-06 11:20:13
* @LastEditors: XieZhiXiong
* @LastEditTime: 2020-09-12 17:17:31
* @Description:
*/
import { useValueLinkageEffect, FormPath, FormEffectHooks } from '@formily/antd' import { useValueLinkageEffect, FormPath, FormEffectHooks } from '@formily/antd'
...@@ -76,8 +83,13 @@ export const useLinkEnumEffect = (childKey, transformFn?, findKey = 'id') => { ...@@ -76,8 +83,13 @@ export const useLinkEnumEffect = (childKey, transformFn?, findKey = 'id') => {
if (state.value === undefined) { if (state.value === undefined) {
} else { } else {
if (originData.length > 0) { if (originData.length > 0) {
const result = originData.find(v => v[findKey] === state.value)[childKey] || [] const current = originData.find(v => v[findKey] === state.value)
if (state.modified && state.initialValue) {
if (!current) {
return
}
const result = current[childKey] || []
if (state.modified) {
targetState.value = undefined targetState.value = undefined
} }
targetState.originData = result targetState.originData = result
...@@ -86,7 +98,6 @@ export const useLinkEnumEffect = (childKey, transformFn?, findKey = 'id') => { ...@@ -86,7 +98,6 @@ export const useLinkEnumEffect = (childKey, transformFn?, findKey = 'id') => {
} }
}) })
}) })
}, },
reject: ({ target }, { setFieldState, getFieldState }) => { reject: ({ target }, { setFieldState, getFieldState }) => {
setFieldState(target, targetState => { setFieldState(target, targetState => {
......
...@@ -255,31 +255,44 @@ export const initDetailSchema = (props: any) => { ...@@ -255,31 +255,44 @@ export const initDetailSchema = (props: any) => {
'x-component-props': { 'x-component-props': {
label: '注册手机', label: '注册手机',
required: true, required: true,
inline: true, wrapperCol: 24,
}, },
properties: { properties: {
countryCodeId: { MEGA_LAYOUT1_1_1: {
type: 'string', type: 'object',
enum: [], 'x-component': 'mega-layout',
'x-component-props': { 'x-component-props': {
placeholder: '请选择', grid: true,
full: true,
}, },
required: true, properties: {
}, countryCodeId: {
phone: { type: 'string',
type: 'string', enum: [],
required: true, 'x-component-props': {
'x-component-props': { placeholder: '请选择',
placeholder: '请输入你的手机号码', },
maxLength: 11, required: true,
},
'x-rules': [
{
pattern: PATTERN_MAPS.phone,
message: '请输入正确格式的手机号',
}, },
], phone: {
}, type: 'string',
required: true,
'x-mega-props': {
span: 2,
},
'x-component-props': {
placeholder: '请输入你的手机号码',
maxLength: 11,
},
'x-rules': [
{
pattern: PATTERN_MAPS.phone,
message: '请输入正确格式的手机号',
},
],
},
},
},
}, },
}, },
email: { email: {
......
import React from 'react'; import React, { useState, useEffect } from 'react';
import { history } from 'umi'; import { history, Prompt } from 'umi';
import { PageHeaderWrapper } from '@ant-design/pro-layout'; import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { SaveOutlined } from '@ant-design/icons'; import { SaveOutlined } from '@ant-design/icons';
import { createFormActions, FormEffectHooks } from '@formily/antd'; import { createFormActions, FormEffectHooks } from '@formily/antd';
import { Button, Card } from 'antd'; import { Button, Card, Spin } from 'antd';
import ReutrnEle from '@/components/ReturnEle'; import ReutrnEle from '@/components/ReturnEle';
import NiceForm from '@/components/NiceForm'; import NiceForm from '@/components/NiceForm';
import { warehouseDetailSchema } from './schema'; import { warehouseDetailSchema } from './schema';
import { useLinkEnumEffect } from '@/components/NiceForm/linkages/linkEnum'; import { useLinkEnumEffect } from '@/components/NiceForm/linkages/linkEnum';
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect'; import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
import { usePageStatus, PageStatus } from '@/hooks/usePageStatus'; import { usePageStatus, PageStatus } from '@/hooks/usePageStatus';
import { useInitValue } from '@/formSchema/effects/useInitValue';
import { PublicApi } from '@/services/api'; import { PublicApi } from '@/services/api';
const addSchemaAction = createFormActions(); const formActions = createFormActions();
const {
onFormInputChange$,
} = FormEffectHooks;
const AddWarehouse: React.FC<{}> = (props: any) => { const AddWarehouse: React.FC<{}> = (props: any) => {
const { pageStatus, preview, id } = usePageStatus(); const { pageStatus, preview, id } = usePageStatus();
const initValue = useInitValue(PublicApi.getWarehouseWarehouseDetails); const [info, setInfo] = useState({});
const [unsaved, setUnsaved] = useState(false);
const [infoLoading, setInfoLoading] = useState(false);
const [submitLoading, setSubmitLoading] = useState(false);
const getWarehouseInfo = async () => {
setInfoLoading(true);
const infoRes = await PublicApi.getWarehouseWarehouseDetails({
id,
});
const areaRes = await PublicApi.getManageAreaAll();
if (areaRes.code === 1000) {
const { data } = areaRes;
formActions.setFieldState('provinceId', targetState => {
targetState.originData = data;
targetState.props.enum = data.map(v => ({
label: v.name,
value: v.id,
}));
});
}
if (infoRes.code === 1000) {
setInfo(infoRes.data);
}
setInfoLoading(false);
};
useEffect(() => {
getWarehouseInfo();
}, []);
// 获取手机code // 获取手机code
const fetchTelCode = async () => { const fetchTelCode = async () => {
...@@ -26,78 +59,90 @@ const AddWarehouse: React.FC<{}> = (props: any) => { ...@@ -26,78 +59,90 @@ const AddWarehouse: React.FC<{}> = (props: any) => {
}; };
const handleSubmit = value => { const handleSubmit = value => {
if (pageStatus === 0) if (!id) {
return PublicApi.postWarehouseWarehouseAdd({ ...value }).then(res => { setSubmitLoading(true);
if (res.code === 1000) return history.goBack(); PublicApi.postWarehouseWarehouseAdd({ ...value }).then(res => {
if (res.code === 1000) {
setTimeout(() => {
history.goBack();
}, 800);
};
}).finally(() => {
setSubmitLoading(false);
}); });
else } else {
return PublicApi.postWarehouseWarehouseUpdate({ setSubmitLoading(true);
PublicApi.postWarehouseWarehouseUpdate({
id: id, id: id,
...value, ...value,
}).then(res => { }).then(res => {
if (res.code === 1000) return history.goBack(); if (res.code === 1000) {
setTimeout(() => {
history.goBack();
}, 800);
};
}).finally(() => {
setSubmitLoading(false);
}); });
}
setUnsaved(false);
}; };
return ( return (
<PageHeaderWrapper <Spin spinning={infoLoading}>
onBack={() => history.goBack()} <PageHeaderWrapper
backIcon={<ReutrnEle description="返回" />} onBack={() => history.goBack()}
title={ backIcon={<ReutrnEle description="返回" />}
pageStatus === 0 title={
? '新建仓库' pageStatus === 0
: pageStatus === 1 ? '新建仓库'
? '编辑仓库' : pageStatus === 1
: '查看仓库' ? '编辑仓库'
} : '查看仓库'
extra={ }
preview != '1' extra={
? [ preview != '1'
<Button ? [
key="1" <Button
type="primary" key="1"
icon={<SaveOutlined />} type="primary"
onClick={() => addSchemaAction.submit()} icon={<SaveOutlined />}
> loading={submitLoading}
保存 onClick={() => formActions.submit()}
</Button>, >
] 保存
: [] </Button>,
} ]
> : []
<Card> }
<NiceForm >
previewPlaceholder="' '" <Card>
editable={pageStatus !== PageStatus.PREVIEW} <NiceForm
effects={($, { setFieldState }) => { previewPlaceholder="' '"
$('onFormMount').subscribe(state => { editable={pageStatus !== PageStatus.PREVIEW}
PublicApi.getManageAreaAll().then(res => { effects={($, { setFieldState }) => {
if (res.code === 1000) { useLinkEnumEffect('areaResponses', result =>
const { data } = res; result.map(v => ({
setFieldState('provinceId', targetState => { label: v.name,
targetState.originData = data; value: v.id,
targetState.props.enum = data.map(v => ({ })),
label: v.name, );
value: v.id, useAsyncSelect('telCode', fetchTelCode);
})); onFormInputChange$().subscribe(() => {
}); if (!unsaved) {
setUnsaved(true);
} }
}); });
}); }}
useLinkEnumEffect('areaResponses', result => initialValues={info}
result.map(v => ({ onSubmit={handleSubmit}
label: v.name, actions={formActions}
value: v.id, schema={warehouseDetailSchema}
})), />
); </Card>
useAsyncSelect('telCode', fetchTelCode); </PageHeaderWrapper>
}} <Prompt when={unsaved} message="您还有未保存的内容,是否确定要离开?" />
initialValues={initValue} </Spin>
onSubmit={handleSubmit}
actions={addSchemaAction}
schema={warehouseDetailSchema}
/>
</Card>
</PageHeaderWrapper>
); );
}; };
......
import { ISchema } from '@formily/antd'; import { ISchema } from '@formily/antd';
import { FORM_FILTER_PATH } from '@/formSchema/const'; import { FORM_FILTER_PATH } from '@/formSchema/const';
import { PATTERN_MAPS } from '@/constants/regExp';
export const warehouseSchema: ISchema = { export const warehouseSchema: ISchema = {
type: 'object', type: 'object',
...@@ -166,11 +167,18 @@ export const warehouseDetailSchema: ISchema = { ...@@ -166,11 +167,18 @@ export const warehouseDetailSchema: ISchema = {
}, },
address: { address: {
type: 'string', type: 'string',
required: true,
'x-component': 'TextArea', 'x-component': 'TextArea',
'x-component-props': { 'x-component-props': {
placeholder: '请输入详细地址(最长50个字符,25个汉字)', placeholder: '请输入详细地址(最长50个字符,25个汉字)',
rows: 5,
}, },
required: true, 'x-rules': [
{
limitByte: true, // 自定义校验规则
maxByte: 50,
}
],
}, },
}, },
}, },
...@@ -199,16 +207,28 @@ export const warehouseDetailSchema: ISchema = { ...@@ -199,16 +207,28 @@ export const warehouseDetailSchema: ISchema = {
type: 'string', type: 'string',
enum: [], enum: [],
'x-component-props': { 'x-component-props': {
placeholder: '', placeholder: '请选择',
}, },
}, },
tel: { tel: {
type: 'string', type: 'string',
'x-mega-props': { span: 3 }, 'x-mega-props': {
span: 3,
},
'x-component-props': { 'x-component-props': {
placeholder: '请输入你的手机号码', placeholder: '请输入你的手机号码',
maxLength: 11, maxLength: 11,
}, },
'x-rules': [
{
required: true,
message: '请输入你的手机号码',
},
{
pattern: PATTERN_MAPS.phone,
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