|
@@ -1,27 +1,34 @@
|
|
|
import { useEffect, useState } from 'react';
|
|
|
-import { useSelector } from 'react-redux'
|
|
|
-import { Table, Modal, message, Menu, Breadcrumb, Dropdown, Space, Form, Radio, Input, Button, Tabs, Row, Col, Select } from 'antd';
|
|
|
+import { Breadcrumb, Form, Radio, Input, Button, Tabs } from 'antd';
|
|
|
import { DownOutlined, PlusOutlined } from '@ant-design/icons';
|
|
|
-import Quill from '@common/QuillEditor';
|
|
|
+import Quill from 'quill';
|
|
|
import SelectedTag from '@common/SelectedTag.js';
|
|
|
+import MyDeptStruct from '@common/MyDeptStruct.js';
|
|
|
import UserList from './UserList';
|
|
|
-import DeptTree from './DeptTree';
|
|
|
import './index.less';
|
|
|
-import "quill/dist/quill.core.css";
|
|
|
import "quill/dist/quill.snow.css";
|
|
|
import backIcon from "@images/back.png";
|
|
|
-import apiObj from '@api/index';
|
|
|
-import utils from '@utils/index'
|
|
|
-const { post, api, xPost } = apiObj;
|
|
|
-const { Option } = Select;
|
|
|
+/*import apiObj from '@api/index';
|
|
|
+const { post, api, xPost } = apiObj;*/
|
|
|
const { TabPane } = Tabs;
|
|
|
-function AddNewMsg() {
|
|
|
+function AddNewMsg(props) {
|
|
|
+ const {goBack} = props;
|
|
|
const [form] = Form.useForm();
|
|
|
const initialValues={receiveType:0,type:1};
|
|
|
- const [showCustom,setShowCustom] = useState(false);
|
|
|
+ const [showCustom,setShowCustom] = useState(false); //是否显示自定义内容
|
|
|
+ const [checkedUser, setCheckedUser] = useState([]); //指定用户选中项
|
|
|
+ const [checkedIds, setCheckedIds] = useState([]); //指定用户选中项id
|
|
|
+ const [checkedDepts, setCheckedDepts] = useState([]); //指定科室选中项
|
|
|
+ const [checkedDeptIds, setCheckedDeptIds] = useState([]); //指定科室选中项id
|
|
|
+
|
|
|
|
|
|
useEffect(() => {
|
|
|
- /*var toolbarOptions = [
|
|
|
+ initQuillEditor();
|
|
|
+
|
|
|
+ }, []);
|
|
|
+ //初始化quill富文本编辑器
|
|
|
+ function initQuillEditor(){
|
|
|
+ var toolbarOptions = [
|
|
|
['bold', 'italic', 'underline', 'strike'], // toggled buttons
|
|
|
['blockquote', 'code-block'],
|
|
|
|
|
@@ -46,29 +53,21 @@ function AddNewMsg() {
|
|
|
let quill = new Quill(editor,{
|
|
|
modules:{
|
|
|
toolbar: {
|
|
|
- container: [['bold', 'italic'], ['link', 'image']],
|
|
|
+ container: toolbarOptions,
|
|
|
}
|
|
|
},
|
|
|
theme:'snow'
|
|
|
- });*/
|
|
|
- //刷新列表
|
|
|
- getUserData();
|
|
|
-
|
|
|
- }, []);
|
|
|
- function getUserData(){
|
|
|
- post(api.getHospitalUser, {}).then((res) => {
|
|
|
- const { code } = res.data;
|
|
|
- if (code === 200) {
|
|
|
-
|
|
|
- } else {
|
|
|
- message.warning(res.data.msg || '获取用户列表失败,请重试')
|
|
|
- }
|
|
|
});
|
|
|
+ //注册事件
|
|
|
+ quill.on('selection-change',(range)=>{
|
|
|
+ if(range===null){ //为空代表失焦
|
|
|
+ const content = quill.root.innerHTML;
|
|
|
+ form.setFieldsValue({content:content});
|
|
|
+ //console.log(quill.getContents(),quill.root.innerHTML);
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
- //返回通知管理页
|
|
|
- function goBack(){
|
|
|
|
|
|
- }
|
|
|
//发送消息
|
|
|
function sendMsg(){
|
|
|
console.log(form.getFieldsValue())
|
|
@@ -85,6 +84,61 @@ function AddNewMsg() {
|
|
|
//切换tab
|
|
|
function handleTabChange(){
|
|
|
|
|
|
+ }
|
|
|
+ //选中用户
|
|
|
+ function handleTableCheck(userIdArr,userArr){
|
|
|
+ setCheckedUser(userArr);
|
|
|
+ setCheckedIds(userIdArr);
|
|
|
+ form.setFieldsValue({sendUsers:userIdArr})
|
|
|
+ }
|
|
|
+ //选中科室
|
|
|
+ function handleCheckDept(checks,e){
|
|
|
+ const checkedDepts = structureDeptTag(checks);
|
|
|
+ let deptIdsArr=[...checkedDepts.ids];
|
|
|
+ let deptArr=[...checkedDepts.obj];
|
|
|
+ setCheckedDepts(deptArr);
|
|
|
+ setCheckedDeptIds(deptIdsArr);
|
|
|
+ form.setFieldsValue({sendDepts:deptIdsArr});
|
|
|
+ }
|
|
|
+ //格式化选中科室数据
|
|
|
+ function structureDeptTag(arr){ //全选传医院id,非全选传科室id
|
|
|
+ let temp=[],hosIds=[],hosArr=[],len=0,deptIds=[],deptArr=[];
|
|
|
+ const arrSorted = arr.sort(()=>{return 1});
|
|
|
+ arrSorted.map((it)=>{
|
|
|
+ //it由 医院id-科室id(如果有)-医院/科室名称 组成
|
|
|
+ temp = it.split("-");
|
|
|
+ len=temp.length;
|
|
|
+ console.log(arrSorted,it,hosIds);
|
|
|
+ //if(len===2){
|
|
|
+ //医院id存入sendHospitals,科室id存入sendDepts
|
|
|
+ hosArr.push({id:temp[len-2],name:temp[len-1]});
|
|
|
+ hosIds.push(temp[len-2]);
|
|
|
+ /*}else{
|
|
|
+ if(!hosIds.includes(temp[0])){
|
|
|
+ deptArr.push({id:temp[1],name:temp[2]});
|
|
|
+ deptIds.push(temp[1]);
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ });
|
|
|
+ return {ids:hosIds,obj:hosArr};
|
|
|
+ }
|
|
|
+ //删除已选用户
|
|
|
+ function handleTagDel(id){
|
|
|
+ if(!id){ //无入参,清空所有
|
|
|
+ setCheckedUser([]);
|
|
|
+ setCheckedIds([]);
|
|
|
+ form.setFieldsValue({sendUsers:[]});
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const idx=checkedIds.findIndex((it)=>it===id);
|
|
|
+ let checkedIdsArr=[...checkedIds];
|
|
|
+ let checkedUserArr=[...checkedUser];
|
|
|
+ checkedIdsArr.splice(idx,1);
|
|
|
+ checkedUserArr.splice(idx,1);
|
|
|
+ setCheckedUser(checkedUserArr);
|
|
|
+ setCheckedIds(checkedIdsArr);
|
|
|
+ form.setFieldsValue({sendUsers:checkedIdsArr})
|
|
|
}
|
|
|
return (
|
|
|
<>
|
|
@@ -106,7 +160,7 @@ function AddNewMsg() {
|
|
|
</Radio.Group>
|
|
|
</Form.Item>
|
|
|
<Form.Item name='title' label='标题' required>
|
|
|
- <Input />
|
|
|
+ <Input autoComplete='off'/>
|
|
|
</Form.Item>
|
|
|
<Form.Item name='content' label='内容' required>
|
|
|
<div className="ql-snow">
|
|
@@ -120,16 +174,22 @@ function AddNewMsg() {
|
|
|
<Radio value={1}>自定义</Radio>
|
|
|
</Radio.Group>
|
|
|
</Form.Item>
|
|
|
+ <Form.Item name='sendUsers' hidden>
|
|
|
+ <Input autoComplete='off'/>
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item name='sendDepts' hidden>
|
|
|
+ <Input autoComplete='off'/>
|
|
|
+ </Form.Item>
|
|
|
</Form>
|
|
|
- {showCustom?<div className="choose-container">
|
|
|
- <SelectedTag></SelectedTag>
|
|
|
+ {showCustom?<div className="receive-container">
|
|
|
+ <SelectedTag data={[...checkedUser,...checkedDepts]} delTag={handleTagDel}></SelectedTag>
|
|
|
<div className="user-type-box">
|
|
|
<Tabs defaultActiveKey="1" onChange={handleTabChange}>
|
|
|
<TabPane tab="指定用户" key="1">
|
|
|
- <UserList></UserList>
|
|
|
+ <UserList setChecked={handleTableCheck} checkedIds={checkedIds}></UserList>
|
|
|
</TabPane>
|
|
|
<TabPane tab="指定科室" key="2">
|
|
|
- <DeptTree></DeptTree>
|
|
|
+ <MyDeptStruct checkEv={handleCheckDept} checkeds={checkedDepts}></MyDeptStruct>
|
|
|
</TabPane>
|
|
|
</Tabs>
|
|
|
</div>
|