Commit 957f033f by zhaochengxiang

资产目录编号问题

parent 71f293f1
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useMemo } from 'react';
import { Modal, Form, Input, Space, Button, Radio, Select } from 'antd';
import { dispatch } from '../../../../model';
......@@ -38,6 +38,18 @@ const UpdateDirectoryModal = (props) => {
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [ visible ])
const codeRestrict = useMemo(() => {
if (action === 'add') {
if (isThemeAdd) return true;
return (dir && dir.level === 1) ? true : false;
} else {
return (dir && dir.level <= 2) ? true : false;
}
return false;
}, [action, dir, isThemeAdd])
const getDirectory = () => {
setDir(null);
dispatch({
......@@ -105,6 +117,7 @@ const UpdateDirectoryModal = (props) => {
payload: payload,
callback: data => {
setConfirmLoading(false);
reset();
onCancel && onCancel(true, data?.id||'');
},
error: () => {
......@@ -117,6 +130,12 @@ const UpdateDirectoryModal = (props) => {
}
}
const reset = () => {
setIsThemeAdd(false);
setDir(undefined);
form.resetFields();
}
const onReset = () => {
if(action === 'add') {
setIsThemeAdd(false);
......@@ -134,7 +153,10 @@ const UpdateDirectoryModal = (props) => {
const onValuesChange = (changedValues, allValues) => {
if (action==='add') {
if (changedValues.type === 'theme') {
setIsThemeAdd(true);
setIsThemeAdd(true);
if (allValues.code?.length > 3) {
form.setFieldsValue({ code: '' });
}
} else if (changedValues.type === 'directory') {
setIsThemeAdd(false);
}
......@@ -158,12 +180,18 @@ const UpdateDirectoryModal = (props) => {
title={'资产目录信息'}
visible={visible}
width={600}
onCancel={() => { onCancel && onCancel() }}
onCancel={() => {
reset();
onCancel && onCancel();
}}
footer={
<Space>
<Button type="primary" onClick={onOk} loading={confirmLoading}>提交</Button>
<Button onClick={onReset} >重置</Button>
<Button onClick={() => onCancel && onCancel() }>返回</Button>
<Button onClick={() => {
reset();
onCancel && onCancel();
}}>返回</Button>
</Space>
}
>
......@@ -203,7 +231,7 @@ const UpdateDirectoryModal = (props) => {
name="code"
rules={[{ required: true, message: '必填项' }]}
>
<Input placeholder="请输入编号" disabled={action!=='add'} />
<Input placeholder="请输入编号" disabled={action!=='add'} maxLength={codeRestrict?3:null} />
</Form.Item>
<Form.Item
label="名称"
......
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