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