|
@@ -11,35 +11,37 @@ import DoctorList from "./doctorList"
|
|
|
import Item from 'antd/lib/list/Item';
|
|
|
const { post, api, xPost } = apiObj;
|
|
|
const { SHOW_PARENT } = TreeSelect;
|
|
|
-const { unique, organizationData } = utils;
|
|
|
+const { organizationData } = utils;
|
|
|
const { Step } = Steps;
|
|
|
const { TabPane } = Tabs;
|
|
|
function AddData(props) {
|
|
|
+ const { save, formData, type, val, tag } = useContext(DataContext);
|
|
|
useEffect(() => {
|
|
|
getCreateRoles()
|
|
|
getHospitalTree()
|
|
|
getOrgList()
|
|
|
+ setValue(val)
|
|
|
+
|
|
|
}, []);
|
|
|
- const { back } = props;
|
|
|
+ const { back, } = props;
|
|
|
const [form] = Form.useForm();
|
|
|
const [value, setValue] = useState([]);
|
|
|
const [key, setKey] = useState();
|
|
|
const [index, setIndex] = useState('0');
|
|
|
const [treeRloe, setTreeRloe] = useState([]);
|
|
|
- const [tags, setTags] = useState([[]]);
|
|
|
+ const [tags, setTags] = useState(tag);
|
|
|
const [treeData, setTreeData] = useState([]);
|
|
|
const [selectedKeys, setSelectedKeys] = useState([]);
|
|
|
const [orgList, setOrgList] = useState([]);
|
|
|
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
|
|
const [autoExpandParent, setAutoExpandParent] = useState(true);
|
|
|
- const { save, detail } = useContext(DataContext);
|
|
|
+
|
|
|
const staticInfo = useSelector(state => {
|
|
|
return state.staticInfo;
|
|
|
});
|
|
|
+
|
|
|
const { dataList } = staticInfo;
|
|
|
- const initialValues = detail || {
|
|
|
- status: '1',
|
|
|
- };
|
|
|
+ const initialValues = formData
|
|
|
const validateMessages = {
|
|
|
required: '${label}不能为空',
|
|
|
};
|
|
@@ -69,11 +71,11 @@ function AddData(props) {
|
|
|
//数据转换为树形结构所需字段
|
|
|
function structureTreeData(arr) {
|
|
|
arr.forEach(item => {
|
|
|
- item.key = item.hospitalId + '-' + item.hospitalName
|
|
|
+ item.key = item.hospitalId + '-' + item.hospitalName
|
|
|
item.title = item.hospitalName
|
|
|
if (!item.children && item.depts) {
|
|
|
item.depts.forEach(it => {
|
|
|
- it.key = item.parentId + '-' + it.deptId + '-' + it.deptName
|
|
|
+ it.key = item.hospitalId + '-' + it.deptId + '-' + it.deptName
|
|
|
})
|
|
|
item.children = JSON.parse(JSON.stringify(item.depts).replaceAll(/deptName/g, 'title').replaceAll(/deptId/g, 'key'))
|
|
|
return
|
|
@@ -107,10 +109,16 @@ function AddData(props) {
|
|
|
const { software } = data;
|
|
|
setOrgList(software);
|
|
|
setKey(software[0].id)
|
|
|
- software.forEach((it, index) => {
|
|
|
- tags[index] = []
|
|
|
- setTags([...tags])
|
|
|
- })
|
|
|
+ if (type == 3) {
|
|
|
+ setTags([...tag])
|
|
|
+ } else {
|
|
|
+ software.forEach((it, index) => {
|
|
|
+ tags[index] = []
|
|
|
+ setTags([...tags])
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
} else {
|
|
|
message.warning(res.data.msg || '获取医院列表失败');
|
|
|
}
|
|
@@ -123,16 +131,24 @@ function AddData(props) {
|
|
|
let val = value
|
|
|
const formData = form.getFieldsValue();
|
|
|
let arr = formData.softwareVOS;
|
|
|
- arr[i].id = key
|
|
|
+ arr[index].id = key
|
|
|
+ arr[index].softwareMenuIds = []
|
|
|
+ arr[index].dataAuthDetails = []
|
|
|
+ arr[index].selectedRowKeys = []
|
|
|
+ if (e.target.value != 7) {
|
|
|
+ arr[index].dataAuthDetails = [{
|
|
|
+ dataType: e.target.value
|
|
|
+ }]
|
|
|
+ }
|
|
|
tags[index] = []
|
|
|
- setTags([...tags])
|
|
|
+ val[i] = e.target.value
|
|
|
selectedRowKeys[index] = []
|
|
|
- setSelectedRowKeys([...selectedRowKeys])
|
|
|
form.setFieldsValue({
|
|
|
softwareVOS: arr
|
|
|
});
|
|
|
- val[i] = e.target.value
|
|
|
+ setTags([...tags])
|
|
|
setValue([...val])
|
|
|
+ setSelectedRowKeys([...selectedRowKeys])
|
|
|
};
|
|
|
// 删除选择标签
|
|
|
function delTag(type, id, i) {
|
|
@@ -145,13 +161,13 @@ function AddData(props) {
|
|
|
})
|
|
|
} else if (type == 1) {
|
|
|
formData.softwareVOS[index].softwareMenuIds.forEach((item, inx) => {
|
|
|
- if (item.split('-')[1] == id) {
|
|
|
+ if (item.split('-')[0] == id) {
|
|
|
formData.softwareVOS[index].softwareMenuIds.splice(inx)
|
|
|
}
|
|
|
})
|
|
|
} else if (type == 2) {
|
|
|
formData.softwareVOS[index].softwareMenuIds.forEach((item, inx) => {
|
|
|
- if (item.split('-')[2] == id) {
|
|
|
+ if (item.split('-')[1] == id) {
|
|
|
formData.softwareVOS[index].softwareMenuIds.splice(inx)
|
|
|
}
|
|
|
})
|
|
@@ -161,18 +177,39 @@ function AddData(props) {
|
|
|
});
|
|
|
tags[index].splice(i)
|
|
|
setTags([...tags])
|
|
|
+ console.log(form.getFieldsValue())
|
|
|
}
|
|
|
function callback(key) {
|
|
|
setKey(key.split('-')[0])
|
|
|
setIndex(key.split('-')[1])
|
|
|
}
|
|
|
- function callbacks(keys) {
|
|
|
+ function treeChange(value) {
|
|
|
+ const formData = form.getFieldsValue();
|
|
|
+ let arr = formData.softwareVOS;
|
|
|
+ arr[index].roles = value
|
|
|
+ form.setFieldsValue({
|
|
|
+ softwareVOS: arr
|
|
|
+ });
|
|
|
+ console.log(form.getFieldsValue())
|
|
|
+ }
|
|
|
+ // 去重
|
|
|
+ function unique(arr) {
|
|
|
+ let result = {};
|
|
|
+ let finalResult = [];
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ result[arr[i].detailId] = arr[i];
|
|
|
+ }
|
|
|
|
|
|
+ for (let item in result) {
|
|
|
+ finalResult.push(result[item]);
|
|
|
+ }
|
|
|
+ return finalResult;
|
|
|
}
|
|
|
//医生选中
|
|
|
function checkDoctEvent(selectedRowKeys) {
|
|
|
+ console.log(tags)
|
|
|
const formData = form.getFieldsValue();
|
|
|
- let arr = []
|
|
|
+ let arr = formData.softwareVOS[index].dataAuthDetails ? formData.softwareVOS[index].dataAuthDetails : []
|
|
|
selectedRowKeys.forEach(it => {
|
|
|
arr.push({
|
|
|
dataType: 7,
|
|
@@ -180,34 +217,37 @@ function AddData(props) {
|
|
|
detailType: 3
|
|
|
})
|
|
|
});
|
|
|
- formData.softwareVOS[index].dataAuthDetails = arr
|
|
|
+
|
|
|
+ formData.softwareVOS[index].dataAuthDetails = unique(arr)
|
|
|
formData.softwareVOS[index].selectedRowKeys = selectedRowKeys
|
|
|
form.setFieldsValue({
|
|
|
softwareVOS: formData.softwareVOS
|
|
|
});
|
|
|
getTags()
|
|
|
+ console.log(form.getFieldsValue())
|
|
|
}
|
|
|
//树形结构选中事件
|
|
|
function checkTreeEvent(idsArr) {
|
|
|
const formData = form.getFieldsValue();
|
|
|
- let arr = []
|
|
|
+ let arr = formData.softwareVOS[index].dataAuthDetails ? formData.softwareVOS[index].dataAuthDetails : []
|
|
|
let result = idsArr.find(ele => ele.split('-').length == 2)
|
|
|
if (result) {
|
|
|
arr.push({
|
|
|
dataType: 7,
|
|
|
- detailId: result.split('1')[0],
|
|
|
+ detailId: result.split('-')[0],
|
|
|
detailType: 1
|
|
|
})
|
|
|
} else {
|
|
|
idsArr.forEach(it => {
|
|
|
+ console.log(it)
|
|
|
arr.push({
|
|
|
dataType: 7,
|
|
|
- detailId: it.split('1')[2],
|
|
|
+ detailId: it.split('-')[1],
|
|
|
detailType: 2
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
- formData.softwareVOS[index].dataAuthDetails = arr
|
|
|
+ formData.softwareVOS[index].dataAuthDetails = unique(arr)
|
|
|
formData.softwareVOS[index].softwareMenuIds = idsArr
|
|
|
form.setFieldsValue({
|
|
|
softwareVOS: formData.softwareVOS
|
|
@@ -258,180 +298,138 @@ function AddData(props) {
|
|
|
<>
|
|
|
<Breadcrumb separator="">
|
|
|
<Breadcrumb.Item><img className='back-icon' src={backIcon} onClick={back} alt="返回上一页" /></Breadcrumb.Item>
|
|
|
- <Breadcrumb.Item>组织管理</Breadcrumb.Item>
|
|
|
+ <Breadcrumb.Item>数据权限</Breadcrumb.Item>
|
|
|
<Breadcrumb.Separator />
|
|
|
- <Breadcrumb.Item>新增子组织</Breadcrumb.Item>
|
|
|
+ <Breadcrumb.Item>{type == 3 ? '修改' : '新增'}数据权限</Breadcrumb.Item>
|
|
|
</Breadcrumb>
|
|
|
- <Form labelCol={{ span: 4 }} wrapperCol={{ span: 18 }} form={form} name="nest-messages" onFinish={onFinish} initialValues={initialValues} validateMessages={validateMessages}>
|
|
|
- <Form.Item name="name" label="数据权限名称" rules={[{ required: true }]}>
|
|
|
- <Input placeholder="请填写数据权限名称" />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item label="权限范围" required >
|
|
|
- <Tabs type="card" onChange={callback} >
|
|
|
- {
|
|
|
- orgList.map((it, i) => {
|
|
|
- return (
|
|
|
- <TabPane tab={it.name} key={it.id + "-" + i}>
|
|
|
- <Form.Item
|
|
|
- key={i}
|
|
|
- name={['softwareVOS', i, 'datatype']} noStyle>
|
|
|
- <Radio.Group onChange={e => { onChange(e, i) }} className="radio">
|
|
|
- <Space direction="vertical">
|
|
|
- {dataList.map((Item) => {
|
|
|
- return (
|
|
|
- <Radio key={i} value={Item.name}>{Item.val}</Radio>
|
|
|
- )
|
|
|
- })
|
|
|
- }
|
|
|
- </Space>
|
|
|
- </Radio.Group>
|
|
|
- </Form.Item>
|
|
|
- <Form.Item key={i + "a"} hidden={true} name={['softwareVOS', i, 'id']} noStyle>
|
|
|
- <Input />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item key={i + "b"} hidden={true} name={['softwareVOS', i, 'dataAuthDetails']} noStyle>
|
|
|
- <Input />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item key={i + "c"} style={{ display: value[index] == 7 && it.id == key ? 'block' : 'none' }}>
|
|
|
- <Card title="已选中" extra={<a href="#">More</a>} >
|
|
|
- {tags[index].map((tag, i) => {
|
|
|
- return (
|
|
|
- <Tag key={i} closable onClose={e => delTag(tag.type, tag.id, i)}>{tag.name}</Tag>
|
|
|
- );
|
|
|
- })}
|
|
|
- </Card>
|
|
|
- </Form.Item>
|
|
|
- <Form.Item key={i + "d"} style={{ display: value[index] == 7 && it.id == key ? 'block' : 'none' }}>
|
|
|
- <Tabs defaultActiveKey="0" onChange={callbacks} >
|
|
|
- <TabPane tab="可看医生" key="0">
|
|
|
- <Form.Item
|
|
|
- key={i}
|
|
|
- name={['softwareVOS', i, 'selectedRowKeys']}
|
|
|
- >
|
|
|
- <DoctorList checkeds={form.getFieldValue().softwareVOS ? form.getFieldValue().softwareVOS[i] : []} checkDoct={(selectedRowKeys) => checkDoctEvent(selectedRowKeys)} />
|
|
|
- </Form.Item>
|
|
|
- </TabPane>
|
|
|
- <TabPane tab="可看科室" key="1">
|
|
|
- <Form.Item
|
|
|
- key={i}
|
|
|
- name={['softwareVOS', i, 'softwareMenuIds']}
|
|
|
- >
|
|
|
- <MenuTree data={treeData} checkeds={form.getFieldValue().softwareVOS ? form.getFieldValue().softwareVOS[i] : []} checkEv={(checkedKeys, sourceIds) => checkTreeEvent(checkedKeys, sourceIds)} />
|
|
|
- </Form.Item>
|
|
|
- </TabPane>
|
|
|
- </Tabs>
|
|
|
- </Form.Item>
|
|
|
- </TabPane>
|
|
|
- )
|
|
|
- })
|
|
|
- }
|
|
|
- </Tabs>
|
|
|
- </Form.Item>
|
|
|
+ <div className='form-center'>
|
|
|
|
|
|
- {/* {value[index] == 7 ?
|
|
|
- <Form.Item wrapperCol={{ offset: 3, span: 20 }} >
|
|
|
- {
|
|
|
- orgList.map((it, i) => {
|
|
|
- return (
|
|
|
- <Form.Item
|
|
|
- key={i}
|
|
|
- >
|
|
|
- {
|
|
|
- it.id == key ?
|
|
|
+
|
|
|
+ <Form labelCol={{ span: 4 }} wrapperCol={{ span: 18 }} form={form} name="nest-messages" onFinish={onFinish} initialValues={initialValues} validateMessages={validateMessages}>
|
|
|
+ <Form.Item name="name" label="数据权限名称" rules={[{ required: true }]}>
|
|
|
+ <Input placeholder="请填写数据权限名称" />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item label="权限范围" rules={[{ required: true }]} >
|
|
|
+ <Tabs type="card" onChange={callback}>
|
|
|
+ {
|
|
|
+ orgList.map((it, i) => {
|
|
|
+ return (
|
|
|
+ <TabPane tab={it.name} key={it.id + "-" + i}>
|
|
|
+ <Form.Item
|
|
|
+ key={i}
|
|
|
+ name={['softwareVOS', i, 'datatype']} noStyle>
|
|
|
+ <Radio.Group onChange={e => { onChange(e, i) }} className="radio">
|
|
|
+ <Space direction="vertical">
|
|
|
+ {dataList.map((Item) => {
|
|
|
+ return (
|
|
|
+ <Radio key={i} value={Item.name}>{Item.val}</Radio>
|
|
|
+ )
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </Space>
|
|
|
+ </Radio.Group>
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "a"} hidden={true} name={['softwareVOS', i, 'id']} noStyle>
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "b"} hidden={true} name={['softwareVOS', i, 'dataAuthDetails']} noStyle>
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "c"} style={{ display: value[index] == 7 && it.id == key ? 'block' : 'none' }}>
|
|
|
<Card title="已选中" extra={<a href="#">More</a>} >
|
|
|
{tags[index].map((tag, i) => {
|
|
|
return (
|
|
|
- <Tag key={i} closable onClose={e => delTag(i)}>{tag}</Tag>
|
|
|
+ <Tag key={i} closable onClose={e => delTag(tag.type, tag.id, i)}>{tag.name}</Tag>
|
|
|
);
|
|
|
})}
|
|
|
</Card>
|
|
|
- :
|
|
|
- null
|
|
|
- }
|
|
|
- </Form.Item>
|
|
|
- )
|
|
|
- })
|
|
|
- }
|
|
|
- </Form.Item>
|
|
|
- :
|
|
|
- null}
|
|
|
-
|
|
|
- {value[index] == 7 ?
|
|
|
- <Form.Item
|
|
|
- wrapperCol={{ offset: 3, span: 20 }}
|
|
|
- >
|
|
|
- {
|
|
|
- orgList.map((it, i) => {
|
|
|
- return (
|
|
|
- <Form.Item
|
|
|
- key={i}
|
|
|
- >
|
|
|
- {
|
|
|
- it.id == key ?
|
|
|
- <Tabs defaultActiveKey="0" onChange={callbacks} >
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "d"} style={{ display: value[index] == 7 && it.id == key ? 'block' : 'none' }}>
|
|
|
+ <Tabs defaultActiveKey="0">
|
|
|
<TabPane tab="可看医生" key="0">
|
|
|
<Form.Item
|
|
|
key={i}
|
|
|
name={['softwareVOS', i, 'selectedRowKeys']}
|
|
|
>
|
|
|
- <DataContext.Provider value={{ data: selectedRowKey[index] }}>
|
|
|
- <DoctorList checkDoct={(selectedRowKeys) => checkDoctEvent(selectedRowKeys)} />
|
|
|
- </DataContext.Provider>
|
|
|
+ <DoctorList checkeds={form.getFieldValue().softwareVOS ? form.getFieldValue().softwareVOS[i] : []} checkDoct={(selectedRowKeys) => checkDoctEvent(selectedRowKeys)} />
|
|
|
</Form.Item>
|
|
|
</TabPane>
|
|
|
<TabPane tab="可看科室" key="1">
|
|
|
<Form.Item
|
|
|
key={i}
|
|
|
name={['softwareVOS', i, 'softwareMenuIds']}
|
|
|
- valuePropName='checked'
|
|
|
- getValueFromEvent={(checked) => {
|
|
|
- console.log(321, checked)
|
|
|
- return [];
|
|
|
- }} noStyle>
|
|
|
- <MenuTree data={treeData} checkeds={form.getFieldValue().softwareVOS ? form.getFieldValue().softwareVOS[i] : []} checkEv={(checkedKeys, sourceIds) => checkTreeEvent(checkedKeys, sourceIds)} />
|
|
|
+ >
|
|
|
+ <MenuTree data={treeData} checkeds={form.getFieldValue().softwareVOS ? form.getFieldValue().softwareVOS[i] : []} checkEv={(checkedKeys) => checkTreeEvent(checkedKeys)} />
|
|
|
</Form.Item>
|
|
|
</TabPane>
|
|
|
</Tabs>
|
|
|
- :
|
|
|
- null
|
|
|
- }
|
|
|
+ </Form.Item>
|
|
|
+ </TabPane>
|
|
|
+ )
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </Tabs>
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item label="所属角色" required >
|
|
|
+ {
|
|
|
+ orgList.map((it, i) => {
|
|
|
+ return (
|
|
|
+ <Form.Item
|
|
|
+ style={{ display: i == index ? 'block' : 'none' }}
|
|
|
+ key={i}
|
|
|
+ >
|
|
|
+ <Form.Item style={{ display: i == index ? 'block' : 'none' }} key={i + "b"} hidden={true} name={['softwareVOS', i, 'roles']} rules={[
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '请选择所属角色',
|
|
|
+ },
|
|
|
+ ]}>
|
|
|
+ <TreeSelect
|
|
|
+ showSearch={false}
|
|
|
+ treeData={treeRloe}
|
|
|
+ onChange={treeChange}
|
|
|
+ maxTagCount={1}
|
|
|
+ treeCheckable
|
|
|
+ showCheckedStrategy={SHOW_PARENT}
|
|
|
+ placeholder="请选择角色"
|
|
|
+ style={{ width: '100%' }}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "a"} hidden={true} name={['softwareVOS', i, 'datatype']} noStyle>
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "c"} hidden={true} name={['softwareVOS', i, 'id']} noStyle>
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "d"} hidden={true} name={['softwareVOS', i, 'dataAuthDetails']} noStyle>
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "e"} hidden={true} name={['softwareVOS', i, 'selectedRowKeys']} noStyle>
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item key={i + "f"} hidden={true} name={['softwareVOS', i, 'softwareMenuIds']} noStyle>
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
</Form.Item>
|
|
|
)
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
</Form.Item>
|
|
|
- :
|
|
|
- null} */}
|
|
|
-
|
|
|
- <Form.Item
|
|
|
- name="roles"
|
|
|
- label="所属角色"
|
|
|
- rules={[{ required: true }]}
|
|
|
- >
|
|
|
- <TreeSelect
|
|
|
- showSearch={false}
|
|
|
- treeData={treeRloe}
|
|
|
- treeCheckable
|
|
|
- showCheckedStrategy={SHOW_PARENT}
|
|
|
- placeholder="请选择角色"
|
|
|
- style={{ width: '100%' }}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item
|
|
|
- name="status"
|
|
|
- valuePropName="checked"
|
|
|
- label="当前状态"
|
|
|
- rules={[{ required: true, message: '请选择状态' }]}
|
|
|
- >
|
|
|
- <Switch onChange={swichChange} />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item wrapperCol={{ span: 20, offset: 8 }}>
|
|
|
- <Button type="primary" htmlType="submit">
|
|
|
- Submit
|
|
|
+ <Form.Item
|
|
|
+ name="status"
|
|
|
+ valuePropName="checked"
|
|
|
+ label="当前状态"
|
|
|
+ rules={[{ required: true, message: '请选择状态' }]}
|
|
|
+ >
|
|
|
+ <Switch onChange={swichChange} />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item wrapperCol={{ span: 20, offset: 8 }}>
|
|
|
+ <Button type="primary" htmlType="submit">
|
|
|
+ Submit
|
|
|
</Button>
|
|
|
- </Form.Item>
|
|
|
- </Form>
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
</>
|
|
|
)
|
|
|
}
|