四好公路
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

96 lines
2.4 KiB

import React, { useRef, useState } from 'react';
import { connect } from 'react-redux';
import { Spin, Card, Modal, TreeSelect } from 'antd';
import ProForm, { ProFormText, ModalForm, ProFormSwitch, ProFormTreeSelect } from '@ant-design/pro-form';
const DepModal = (props) => {
const { visible, onVisibleChange, onConfirm, depModalType, depData, data } = props;
const formRef = useRef();
const onFinish = (values) => {
console.log('values:',values);
if (onConfirm) {
if (depModalType === 'edit') {
let value = {
name: values.name,
depId: data.id,
dependence:values.dependence
}
onConfirm(value)
} else {
onConfirm(values);
}
}
}
return (
<Spin spinning={false}>
<ModalForm
title={depModalType === 'edit' ? '编辑部门' : '新增部门'}
visible={visible}
onVisibleChange={onVisibleChange}
onFinish={onFinish}
formRef={formRef}
destroyOnClose
initialValues={depModalType === 'edit' ? data : null}
>
<ProFormText
name={['name']}
width="md"
label="部门名称"
required
maxLength={10}
placeholder="请输入部门名称"
fieldProps={{
autocomplete: 'new-password'
}}
rules={[
{ required: true, message: '请输入部门名称' }, { max: 10, message: '请输入10个字以内的名称' }
]}
/>
<ProFormTreeSelect
name={['dependence']}
width="md"
label="上级部门"
autocomplete='off'
placeholder="选择上级部门"
fieldNames={{
title: 'name',
key: 'id',
children: 'subordinate'
}}
request={async () => {
return depData
}}
/>
</ModalForm>
</Spin>
)
}
function mapStateToProps(state) {
const { depMessage } = state;
const pakData = (dep) => {
return dep.map((d) => {
return {
title: d.name,
value: d.id,
// key: d.id,
children: d.subordinate.map(s => {
return {
title: s.name,
value: s.id,
}
})
}
})
}
let depData = pakData(depMessage.data || [])
return {
loading: depMessage.isRequesting,
depData,
};
}
export default connect(mapStateToProps)(DepModal);