Commit 7955ee38 authored by cellee's avatar cellee

Signed-off-by: cellee <893264950@qq.com>

parent c9b23759
import React, { useState,useEffect} from 'react';
import React, { useState, useEffect } from 'react';
import SelectOptions from '../SelectOptions';
import { connect } from 'umi'
import { connect } from 'umi';
const index = (props:any) => {
const {dispatch, CommunityList,value,onChange , checklist} = props;
const index = (props: any) => {
const { dispatch, CommunityList, value, onChange, checklist } = props;
// console.log(props)
const tosCommunityget = (values:any) => {dispatch({type: 'Init/tosCommunityget',playload:values})};
const tosCommunityget = (values: any) => {
dispatch({ type: 'Init/tosCommunityget', playload: values });
};
useEffect(() => {
if (CommunityList == null) {
tosCommunityget(null)
}
}, []);
tosCommunityget(null);
}
}, []);
// 给已选值默认 如果有默认就传递默认 否则传递列表数据
useEffect(() => {
if (checklist != null) {
onChange({ index:1,value: checklist})
}else{
onChange({ index:1,value: CommunityList})
onChange({ index: 1, value: checklist });
} else {
onChange({ index: 1, value: CommunityList });
}
}, [checklist]);
// 点击选择的时候传递给子组件 已选列表
const printContent = (values:any) => {
onChange({ index:CommunityList.length==values.length?1:0,value: values})
}
const printContent = (values: any) => {
onChange({ index: CommunityList.length == values.length ? 1 : 0, value: values });
};
return (
<>
{
CommunityList != null ?
<SelectOptions list={CommunityList.sort()} checklist={checklist} show={true} onSubmit={printContent} />:
null
}
{CommunityList != null ? (
<SelectOptions
list={CommunityList.sort()}
checklist={checklist}
show={true}
onSubmit={printContent}
/>
) : null}
</>
);
};
function mapStateToProps(state:any) {
const { CommunityList } = state.Init;
function mapStateToProps(state: any) {
const { CommunityList } = state.Init;
return {
CommunityList,
};
......
......@@ -75,7 +75,6 @@ class SelectOptions extends React.PureComponent {
lastValue: null,
};
} else {
// console.log(checklist);
this.state = {
menuList: ArrayToPingYin.get(list),
checkedListOptions: list,
......@@ -89,6 +88,17 @@ class SelectOptions extends React.PureComponent {
};
}
}
componentWillReceiveProps(nextProps) {
// 如果存在更新 就拿取最新的选中小区值
// 判断是不是props 的最新值 否则每次点击都要更新
if (nextProps.checklist !== this.props.checklist) {
this.setState({
checkedList: nextProps.checklist,
});
}
}
componentDidUpdate(prevProps) {
if (this.props.show != null) {
if (this.props.show == this.state.flag) {
......@@ -100,8 +110,8 @@ class SelectOptions extends React.PureComponent {
}
console.log(this.state.componetVisible);
}
if (this.props.list.length > this.state.checkedList.length) {
}
// if (this.props.list.length > this.state.checkedList.length) {
// }
// console.log(prevProps.list);
// if (this.props.list.length > prevProps.list.length) {
// console.log(this.props.list);
......
......@@ -16,9 +16,16 @@ export default {
Permission: null,
SubResult: null, // 结果
Info: null, // 二级管辖小区和权限
},
reducers: {
// 二级账户管辖小区和权限
returnInfo(state, { Info }) {
return { ...state, Info };
},
returnPage(state, { Data }) {
return { ...state, Data };
},
......@@ -110,6 +117,12 @@ export default {
localStorage.setItem('towAccount', JSON.stringify(resp.data));
}
break;
case 57: // 二级账号
{
let Info = resp.data;
yield put({ type: 'returnInfo', Info });
}
break;
}
}
},
......@@ -134,5 +147,11 @@ export default {
var SubResult = null;
yield put({ type: 'returnDelccount', SubResult });
},
// 清除二级账户选择
*InfoClear({}, { put }) {
var Info = null;
yield put({ type: 'returnInfo', Info });
},
},
};
......@@ -161,6 +161,8 @@ const Account = (props: any) => {
// 编辑- 新增
const edit = (item: any) => {
// console.log(item);
// 无论编辑还是新增都清掉二级账户选择
dispatch({ type: 'Account/InfoClear' });
if (item == 1) {
history.push('/AccountManagement/account/Add');
} else {
......
......@@ -14,10 +14,10 @@ import { RA } from '@/utils/method';
const Account = (props: any) => {
const module = 'Account';
const { dispatch, SubResult, CommunityList, loading, user } = props;
const { dispatch, SubResult, CommunityList, loading, user, Info } = props;
// 权限列表
const treeData = enUsFaci || zhCnFaci;
const treeData = localStorage.getItem('umi_locale') == 'zh-CN' ? zhCnFaci : enUsFaci;
const [expandedKeys, setExpandedKeys] = useState<string[]>([]); // 展开栏目
const [checkedKeys, setCheckedKeys] = useState([] as any); // 默认已选栏目
......@@ -28,6 +28,9 @@ const Account = (props: any) => {
const [values, setvalues] = useState(2); // 树形菜单展开关闭
const [disab, setdisab] = useState(false); // 是否禁止选择二级
const [towAccountId, settowAccountId] = useState(null); // 二级账户id
const [treeDataList, settreeDataList] = useState(treeData); // 权限列表
//默认选中的小区
const [community, setCommunity] = useState(CommunityList); // 默认全选
// 表单标识
const [form] = Form.useForm();
......@@ -40,8 +43,9 @@ const Account = (props: any) => {
// 当前账户权限
useEffect(() => {
if (user != null) {
let treeDatas = treeData;
if (user != null || values == 2) {
let _tmp = JSON.stringify(treeData); //将对象转换为json字符串形式
let treeDatas = JSON.parse(_tmp); //将转换而来的字符串转换为原生js对
let _a = user.currentUser.permission; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
......@@ -68,13 +72,10 @@ const Account = (props: any) => {
if (user.currentUser.userModel.tosUserLevel > 1) {
setvalues(3);
setdisab(true);
settowAccountId(user.currentUser.id);
// 如果是三级账户,禁用最后两个账户管理
if (user.currentUser.userModel.tosUserLevel == 3) {
// 禁用最后两个
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
}
settowAccountId(user.currentUser.userModel.id);
// 且禁用最后两个账户管理
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
} else {
// 如果是一级账户获取挂靠的二级账户名称
RA(56, {}, module, dispatch); // 权限上传
......@@ -82,9 +83,9 @@ const Account = (props: any) => {
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
settreeDataList(treeDatas as any); // 可勾选列表
}
}, [user]);
}, [user, values]);
useEffect(() => {
// 提交信息结果
......@@ -99,10 +100,57 @@ const Account = (props: any) => {
}
}, [SubResult]);
// 二级管辖小区和权限
useEffect(() => {
if (Info != null) {
setCommunity(Info.community);
power(Info.permissions);
}
}, [Info]);
//权限赋值
const power = (val: any) => {
let _tmp = JSON.stringify(treeData); //将对象转换为json字符串形式
let treeDatas = JSON.parse(_tmp); //将转换而来的字符串转换为原生js对
let _a = val; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
let arr: any = []; // 一级栏目权限
let erArr: any = []; // 一级栏目权限
// 循环一级 判断当前账户有没有权限修改增加
for (let i of _a) {
for (let j in _p) {
if (_p[j].key == i) {
arr.push(_p[j].key);
_p[j].disabled = false;
}
// 二级权限
for (let k in _p[j].children) {
if (_p[j].children[k].key == i) {
erArr.push(_p[j].children[k].key);
_p[j].children[k].disableCheckbox = false;
}
}
}
}
// 且禁用最后两个账户管理
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
// 赋值改变
treeDatas[0].children = _p;
settreeDataList(treeDatas as any); // 可勾选列表
};
// 保存提交
const onFinishContract = async (value: any) => {
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
console.log(treeDataList);
console.log();
if (
value.tosAccountName.length <= 2 &&
value.tosUserPhone.length != 8 &&
......@@ -111,7 +159,7 @@ const Account = (props: any) => {
// 姓名联系方式
message.error('Please enter the correct name and contact information!');
return false;
} else if (checkedKeys[0].key) {
} else if (checkedKeys.length == 0) {
// 如果存在key 就是没有选择
// 权限
message.error('Please Select Permission!');
......@@ -209,7 +257,7 @@ const Account = (props: any) => {
setvalues(e.target.value);
// 如果是3级,取消后面两个选择
let treeDatas = treeData;
let treeDatas = treeDataList; //将转换而来的字符串转换为原生js对
let _p = treeDatas[0].children; // 所有权限列表
// 禁用最后两个
if (e.target.value == 3) {
......@@ -221,10 +269,11 @@ const Account = (props: any) => {
_p[_p.length - 1].children[3].disableCheckbox = false;
settowAccountId(null);
setCommunity(CommunityList);
}
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
settreeDataList(treeDatas as any); // 可勾选列表
};
//手机号
......@@ -247,6 +296,8 @@ const Account = (props: any) => {
// 选择哪个二级账号
const handleChange = (value: any) => {
console.log(`selected ${value}`);
RA(57, { tosUserLevelId: value }, module, dispatch); // 根据用户id获取用户管辖小区名和权限
settowAccountId(value);
};
......@@ -300,7 +351,7 @@ const Account = (props: any) => {
</Descriptions>
<Form.Item name="community" label="Community">
<SelectCommunity checklist={CommunityList == null ? null : CommunityList} />
<SelectCommunity checklist={community ? community : null} />
</Form.Item>
<div className="diy" style={{ marginBottom: '14px' }}>
......@@ -346,7 +397,7 @@ const Account = (props: any) => {
checkedKeys={checkedKeys}
onSelect={onSelect}
selectedKeys={selectedKeys}
treeData={treeData}
treeData={treeDataList}
/>
</div>
</div>
......@@ -366,7 +417,7 @@ const Account = (props: any) => {
};
const AccountProps = (state: any) => {
const { Data, DataSave, DataSaveDetail, Result, SubResult } = state.Account;
const { Data, DataSave, DataSaveDetail, Result, SubResult, Info } = state.Account;
const { CommunityList } = state.Init; // 小区列表
const loading = state.loading.models.Account || false;
const { user } = state;
......@@ -379,6 +430,7 @@ const AccountProps = (state: any) => {
CommunityList,
user, // 获取当前账户信息
SubResult,
Info,
};
};
......
import React, { useState, useEffect, useRef } from 'react';
import { Form, Input, Button, Spin, message, Descriptions, Modal, Tree, Radio } from 'antd';
import { Form, Input, Button, Spin, message, Descriptions, Modal, Tree, Tag } from 'antd';
import { connect, history } from 'umi';
import { EditOutlined, LeftOutlined, PoweroffOutlined } from '@ant-design/icons';
import {
EditOutlined,
LeftOutlined,
PoweroffOutlined,
RightOutlined,
CheckCircleOutlined,
} from '@ant-design/icons';
import { getCookie } from '@/utils/method';
import './Account.less';
......@@ -92,10 +98,37 @@ const Account = (props: any) => {
useEffect(() => {
if (Permission != null) {
let newPer = eval('(' + Permission + ')');
let data: any = [];
let data: any = []; // 编辑的账户的权限
for (let i in newPer) {
data[i] = newPer[i] + '';
}
let _p = treeData[0].children; // 所有权限列表
// console.log(_p); // 所有权限列表
for (let i in _p) {
let arr = _p[i].children; // 每个权限
let newArr = []; // 每个权限下的子权限列表
for (let j in arr) {
newArr.push(arr[j].key);
}
// console.log(newArr);
if (!newArr.every((val) => data.includes(val))) {
// 判断数组是否包含另一个数组
// console.log('不包含' + _p[i].key);
// 不全部包含就删除数组的元素
var index = data.indexOf(_p[i].key);
if (index > -1) {
data.splice(index, 1);
}
} else {
// console.log('包含' + _p[i].key);
}
}
// 再赋值给列表
// data.push('0');
setCheckedKeys(data);
}
}, [Permission]);
......@@ -292,15 +325,26 @@ const Account = (props: any) => {
<span className="title">Privilege Level:</span>
</div>
<div className="label">
<Radio.Group defaultValue={DataSave.tosUserLevel} onChange={onRadio} disabled>
<Radio style={radioStyle} value={2}>
Two Level Administrator
</Radio>
<Radio style={radioStyle} value={3}>
Three Level Administrator
{/* <Input placeholder="三级管理员" style={{ width: 160, marginLeft: 10 }} /> */}
</Radio>
</Radio.Group>
<Tag
icon={<CheckCircleOutlined />}
color="success"
style={{ verticalAlign: 'sub', fontSize: 14, padding: '4px 7px' }}
>
{DataSave.tosUserLevel == 2
? 'Two Level Administrator '
: 'Three Level Administrator'}
</Tag>
{DataSave.tosUserLevel == 3 ? (
<Tag
icon={<RightOutlined />}
color="processing"
style={{ verticalAlign: 'sub', fontSize: 14, padding: '4px 7px' }}
>
Superiors:{DataSave.userLeaderAccountName} - {DataSave.userLeaderName}
</Tag>
) : (
''
)}
</div>
</div>
......
import React, { useState, useEffect, useRef } from 'react';
import { Form, Input, Button, Spin, message, Descriptions, Tree, Radio } from 'antd';
import { Form, Input, Button, message, Descriptions, Spin, Tree, Radio, Select } from 'antd';
import { connect, history } from 'umi';
import { EditOutlined, LeftOutlined } from '@ant-design/icons';
import { getCookie } from '@/utils/method';
import './Account.less';
import { zhCnFaci, enUsFaci } from '@/utils/power';
......@@ -15,45 +14,39 @@ import { RA } from '@/utils/method';
const Account = (props: any) => {
const module = 'Account';
const { dispatch, Data, DataSave, DataSaveDetail, SubResult, loading, Permission, user } = props;
const { dispatch, SubResult, CommunityList, loading, user, DataSave, Permission, Info } = props;
// 权限列表
const treeData = enUsFaci || zhCnFaci;
const treeData = localStorage.getItem('umi_locale') == 'zh-CN' ? zhCnFaci : enUsFaci;
const [expandedKeys, setExpandedKeys] = useState<string[]>([]); // 展开栏目
const [checkedKeys, setCheckedKeys] = useState<string[]>([]); // 默认已选栏目
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点
const [checkedKeys, setCheckedKeys] = useState([] as any); // 默认已选栏目
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点
const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭
const [treeDataList, settreeDataList] = useState(treeData); // 权限列表
// 单选 二级还是三级管理员
const [values, setvalues] = useState(2); // 树形菜单展开关闭
const [disab, setdisab] = useState(false); // 是否禁止选择二级
const [towAccountId, settowAccountId] = useState(null); // 二级账户id
//默认选中的小区
const [community, setCommunity] = useState([] as any);
// 表单标识
const [form] = Form.useForm();
const formRef = useRef(null);
// 数据
useEffect(() => {
if (DataSave != null) {
// 赋值
form.setFieldsValue({
tosUserName: DataSave.tosUserName,
tosUserPhone: DataSave.tosUserPhone,
tosAccountName: DataSave.tosAccountName,
});
const { Option } = Select;
setvalues(DataSave.tosUserLevel); // 等级
// 发起获取权限请求
RA(54, { tosUserName: DataSave.tosUserName }, module, dispatch); // 发起获取权限请求
}
}, [DataSave]);
//二级账户列表
const towAccount = JSON.parse(localStorage.getItem('towAccount') || '[]');
// 当前账户权限
useEffect(() => {
if (user != null) {
let treeDatas = treeData;
if (user != null || values == 2) {
let _tmp = JSON.stringify(treeData); //将对象转换为json字符串形式
let treeDatas = JSON.parse(_tmp); //将转换而来的字符串转换为原生js对
let _a = user.currentUser.permission; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
......@@ -78,23 +71,69 @@ const Account = (props: any) => {
// 当当前账户是二级以上禁用创建二级菜单
if (user.currentUser.userModel.tosUserLevel > 1) {
setvalues(user.currentUser.userModel.tosUserLevel);
setvalues(3);
setdisab(true);
// 禁用最后两个
settowAccountId(user.currentUser.userModel.id);
// 且禁用最后两个账户管理
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
// 如果是三级账户,删除最后两个账户管理
if (user.currentUser.userModel.tosUserLevel == 3) {
console.log(treeData);
}
} else {
// 如果是一级账户获取挂靠的二级账户名称
RA(56, {}, module, dispatch); // 权限上传
}
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
settreeDataList(treeDatas as any); // 可勾选列表
}
}, [user]);
}, [user, values]);
// 当前编辑账户的数据
useEffect(() => {
if (DataSave != null && user != null) {
// 赋值
form.setFieldsValue({
tosUserName: DataSave.tosUserName,
tosUserPhone: DataSave.tosUserPhone,
tosAccountName: DataSave.tosAccountName,
});
setvalues(DataSave.tosUserLevel); // 等级
setCommunity([...DataSave.tosUserServiceCell.split(',')]); // 默认小区
// 当前登录的不是admin 就 给默认id
if (user.currentUser.userModel.tosUserLevel > 1) {
settowAccountId(DataSave.userLeader); // 二级账户id
}
// 如果是3级,取消后面两个选择
if (DataSave.tosUserLevel == 3) {
let treeDatas = treeData;
let _p = treeDatas[0].children; // 所有权限列表
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
}
// 发起获取权限请求
RA(54, { tosUserName: DataSave.tosUserName }, module, dispatch); // 发起获取权限请求
}
}, [DataSave, user]);
// 提交信息结果
useEffect(() => {
if (SubResult != null) {
if (SubResult.statr == 0 && SubResult.desc == 0) {
// 保存成功, 清掉原来数据 并且跳转
message.success('Submitted Successfully !');
dispatch({ type: module + '/ReData' });
dispatch({ type: module + '/AccountClear' });
history.go(-1);
}
}
}, [SubResult]);
// 已选权限
useEffect(() => {
......@@ -104,7 +143,6 @@ const Account = (props: any) => {
for (let i in newPer) {
data[i] = newPer[i] + '';
}
// console.log(data); // 编辑的账户的权限
let _p = treeData[0].children; // 所有权限列表
// console.log(_p); // 所有权限列表
......@@ -129,25 +167,53 @@ const Account = (props: any) => {
// console.log('包含' + _p[i].key);
}
}
// console.log(data);
// 再赋值给列表
setCheckedKeys(data);
}
}, [Permission]);
// 监听改变状态提交结果
// 二级管辖小区和权限
useEffect(() => {
// 提交信息结果
if (SubResult != null) {
if (SubResult.statr == 0 && SubResult.desc == 0) {
// 保存成功, 清掉原来数据 并且跳转
message.success('Submitted Successfully !');
dispatch({ type: module + '/ReData' });
dispatch({ type: module + '/AccountClear' });
history.go(-1);
if (Info != null) {
setCommunity(Info.community);
power(Info.permissions);
}
}, [Info]);
//权限赋值
const power = (val: any) => {
let _tmp = JSON.stringify(treeData); //将对象转换为json字符串形式
let treeDatas = JSON.parse(_tmp); //将转换而来的字符串转换为原生js对
let _a = val; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
let arr: any = []; // 一级栏目权限
let erArr: any = []; // 一级栏目权限
// 循环一级 判断当前账户有没有权限修改增加
for (let i of _a) {
for (let j in _p) {
if (_p[j].key == i) {
arr.push(_p[j].key);
_p[j].disabled = false;
}
// 二级权限
for (let k in _p[j].children) {
if (_p[j].children[k].key == i) {
erArr.push(_p[j].children[k].key);
_p[j].children[k].disableCheckbox = false;
}
}
}
}
}, [SubResult]);
// 且禁用最后两个账户管理
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
// 赋值改变
treeDatas[0].children = _p;
settreeDataList(treeDatas as any); // 可勾选列表
};
// 保存提交
const onFinishContract = async (value: any) => {
......@@ -161,7 +227,8 @@ const Account = (props: any) => {
// 姓名联系方式
message.error('Please enter the correct name and contact information!');
return false;
} else if (checkedKeys.length == 0) {
} else if (checkedKeys[0].key) {
// 如果存在key 就是没有选择
// 权限
message.error('Please Select Permission!');
return false;
......@@ -173,19 +240,25 @@ const Account = (props: any) => {
// 账号长度
message.error('The Account Password is Greater Than 6 Digits!');
return false;
} else if (values == 3 && towAccountId == null) {
// 如果创建的是三级账号就要判断是否选择了绑定的二级账户
message.error('Please select affiliated account !');
return false;
} else {
value.tosUserServiceCellList = value.community.value; // 管辖小区
value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别
value.creatorName = getCookie('name'); //新建者账号
// value.creatorName = JSON.parse(userInfo).userModel.tosUserName; //新建者账号
value.creatorId = id; //新建者ID
if (values == 3) {
value.userLeader = towAccountId;
}
delete value.community;
value.id = DataSave.id;
DataSave ? (value.id = DataSave.id) : '';
// 判断有没有 0 有就删除
for (var i in checkedKeys) {
checkedKeys[i] == '0' ? checkedKeys.splice(i as any, 1) : '';
checkedKeys[i] == '0' ? checkedKeys.splice(i, 1) : '';
}
// 追加到上级id
......@@ -213,6 +286,7 @@ const Account = (props: any) => {
RA(38, value, module, dispatch); // 信息上传
RA(42, obj, module, dispatch); // 权限上传
return true;
}
};
......@@ -221,9 +295,6 @@ const Account = (props: any) => {
history.go(-1);
};
// 全选
const onCheckAllChange = (e: any) => {};
// 展开/收起树形菜单触发
const onExpand = (expandedKeys: any) => {
setExpandedKeys(expandedKeys);
......@@ -232,13 +303,13 @@ const Account = (props: any) => {
// 点击单个触发
const onCheck = (checkedKeys: any) => {
console.log('onCheck', checkedKeys);
// console.log('onCheck', checkedKeys);
setCheckedKeys(checkedKeys);
};
// 点击树节点触发 - 大栏目
const onSelect = (selectedKeys: any, info: any) => {
console.log('onSelect', info);
// console.log('onSelect', info);
setSelectedKeys(selectedKeys);
};
......@@ -252,7 +323,32 @@ const Account = (props: any) => {
//级别切换
const onRadio = (e: any) => {
setvalues(e.target.value);
// 当编辑自己的时候不能切换
if (user.currentUser.userModel.id === DataSave.id) {
message.info('You cannot modify your own level!');
return false;
} else {
setvalues(e.target.value);
// 如果是3级,取消后面两个选择
let treeDatas = treeData;
let _p = treeDatas[0].children; // 所有权限列表
// 禁用最后两个
if (e.target.value == 3) {
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
} else {
//否则打开
_p[_p.length - 1].children[2].disableCheckbox = false;
_p[_p.length - 1].children[3].disableCheckbox = false;
settowAccountId(null);
}
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
return;
}
};
//手机号
......@@ -263,6 +359,21 @@ const Account = (props: any) => {
return getNumber(value.replace(/[^\d^\.]+/g, ''));
};
// 二级账户
const listItems = towAccount.map((item: any) => {
return (
<Option key={item.id} value={item.id}>
{item.tosAccountName}-{item.tosUserEmail}
</Option>
);
});
// 选择哪个二级账号
const handleChange = (value: any) => {
RA(57, { tosUserLevelId: value }, module, dispatch); // 根据用户id获取用户管辖小区名和权限
settowAccountId(value);
};
return (
<Spin spinning={loading}>
<div className="contop" style={{ padding: '12px 20px' }}>
......@@ -277,7 +388,6 @@ const Account = (props: any) => {
</div>
</h3>
<hr></hr>
<Form
ref={formRef}
form={form}
......@@ -290,7 +400,7 @@ const Account = (props: any) => {
<Descriptions column={{ xs: 1, sm: 2, md: 3 }}>
<Descriptions.Item>
<Form.Item name="tosUserName" label="Account ID" rules={AccountTip[0] as any}>
<Input placeholder="Login Account" className="input" disabled />
<Input placeholder="Login Account" className="input" />
</Form.Item>
</Descriptions.Item>
</Descriptions>
......@@ -314,9 +424,7 @@ const Account = (props: any) => {
</Descriptions>
<Form.Item name="community" label="Community">
<SelectCommunity
checklist={DataSave == null ? null : DataSave.tosUserServiceCell.split(',')}
/>
<SelectCommunity checklist={community} />
</Form.Item>
<div className="diy" style={{ marginBottom: '14px' }}>
......@@ -330,9 +438,22 @@ const Account = (props: any) => {
</Radio>
<Radio style={radioStyle} value={3}>
Three Level Administrator
{/* <Input placeholder="三级管理员" style={{ width: 160, marginLeft: 10 }} /> */}
</Radio>
</Radio.Group>
{/* 选择挂靠的二级菜单 */}
{values === 3 && user.currentUser.userModel.tosUserLevel <= 1 ? (
<Select
style={{ width: 260 }}
onChange={handleChange}
placeholder="Please select affiliated account"
defaultValue={towAccountId as any}
>
{towAccount ? listItems : ''}
</Select>
) : (
''
)}
</div>
</div>
......@@ -350,8 +471,7 @@ const Account = (props: any) => {
checkedKeys={checkedKeys}
onSelect={onSelect}
selectedKeys={selectedKeys}
treeData={treeData}
// checkStrictly={true}
treeData={treeDataList}
/>
</div>
</div>
......@@ -371,7 +491,8 @@ const Account = (props: any) => {
};
const AccountProps = (state: any) => {
const { Data, DataSave, DataSaveDetail, Result, Permission, SubResult } = state.Account;
const { Data, DataSave, DataSaveDetail, Result, SubResult, Permission, Info } = state.Account;
const { CommunityList } = state.Init; // 小区列表
const loading = state.loading.models.Account || false;
const { user } = state;
return {
......@@ -381,8 +502,10 @@ const AccountProps = (state: any) => {
Result,
loading,
Permission,
user,
CommunityList,
user, // 获取当前账户信息
SubResult,
Info,
};
};
......
import React, { useState, useEffect, useRef } from 'react';
import { Form, Input, Button, message, Descriptions, Spin, Tree, Radio, Select } from 'antd';
import { Form, Input, Button, message, Descriptions, Spin, Tree, Tag, Select } from 'antd';
import { connect, history } from 'umi';
import { EditOutlined, LeftOutlined } from '@ant-design/icons';
import { EditOutlined, LeftOutlined, CheckCircleOutlined, RightOutlined } from '@ant-design/icons';
import './Account.less';
import { zhCnFaci, enUsFaci } from '@/utils/power';
......@@ -14,31 +14,29 @@ import { RA } from '@/utils/method';
const Account = (props: any) => {
const module = 'Account';
const { dispatch, SubResult, CommunityList, loading, user, DataSave, Permission } = props;
const { dispatch, SubResult, CommunityList, loading, user, DataSave, Permission, Info } = props;
// 权限列表
const treeData = enUsFaci || zhCnFaci;
const treeData = localStorage.getItem('umi_locale') == 'zh-CN' ? zhCnFaci : enUsFaci;
const [expandedKeys, setExpandedKeys] = useState<string[]>([]); // 展开栏目
const [expandedKeys, setExpandedKeys] = useState<string[]>(['0']); // 展开栏目
const [checkedKeys, setCheckedKeys] = useState([] as any); // 默认已选栏目
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点
const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭
const [treeDataList, settreeDataList] = useState(treeData); // 权限列表
// 单选 二级还是三级管理员
const [values, setvalues] = useState(2); // 树形菜单展开关闭
const [disab, setdisab] = useState(false); // 是否禁止选择二级
const [towAccountId, settowAccountId] = useState(null); // 二级账户id
//默认选中的小区
const [community, setCommunity] = useState([] as any);
// 表单标识
const [form] = Form.useForm();
const formRef = useRef(null);
const { Option } = Select;
//二级账户列表
const towAccount = JSON.parse(localStorage.getItem('towAccount') || '[]');
// 登录账户权限
// 当前账户权限
useEffect(() => {
if (user != null) {
let treeDatas = treeData;
......@@ -63,23 +61,6 @@ const Account = (props: any) => {
}
}
}
// 当当前账户是二级以上禁用创建二级菜单
if (user.currentUser.userModel.tosUserLevel > 1) {
setvalues(3);
setdisab(true);
settowAccountId(user.currentUser.id);
// 如果是三级账户,禁用最后两个账户管理
if (user.currentUser.userModel.tosUserLevel == 3) {
// 禁用最后两个
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
}
} else {
// 如果是一级账户获取挂靠的二级账户名称
RA(56, {}, module, dispatch); // 权限上传
}
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
......@@ -88,7 +69,7 @@ const Account = (props: any) => {
// 当前编辑账户的数据
useEffect(() => {
if (DataSave != null) {
if (DataSave != null && user != null) {
// 赋值
form.setFieldsValue({
tosUserName: DataSave.tosUserName,
......@@ -96,24 +77,22 @@ const Account = (props: any) => {
tosAccountName: DataSave.tosAccountName,
});
settowAccountId(DataSave.userLeader); // 二级账户id
setvalues(DataSave.tosUserLevel); // 等级
setCommunity([...DataSave.tosUserServiceCell.split(',')]); // 默认小区
// 当前登录的不是admin 就 给默认id
if (user.currentUser.userModel.tosUserLevel > 1) {
settowAccountId(DataSave.userLeader); // 二级账户id
}
// 如果是3级,取消后面两个选择
if (DataSave.tosUserLevel == 3) {
let treeDatas = treeData;
let _p = treeDatas[0].children; // 所有权限列表
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
settowAccountId(DataSave.userLeader); //上级id
}
// 发起获取权限请求
RA(54, { tosUserName: DataSave.tosUserName }, module, dispatch); // 发起获取权限请求
}
}, [DataSave]);
}, [DataSave, user]);
// 提交信息结果
useEffect(() => {
......@@ -160,11 +139,55 @@ const Account = (props: any) => {
// console.log('包含' + _p[i].key);
}
}
// 再赋值给列表
// data.push('0');
setCheckedKeys(data);
}
}, [Permission]);
// 二级管辖小区和权限
useEffect(() => {
if (Info != null) {
setCommunity(Info.community);
power(Info.permissions);
}
}, [Info]);
//权限赋值
const power = (val: any) => {
let _tmp = JSON.stringify(treeData); //将对象转换为json字符串形式
let treeDatas = JSON.parse(_tmp); //将转换而来的字符串转换为原生js对
let _a = val; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
let arr: any = []; // 一级栏目权限
let erArr: any = []; // 一级栏目权限
// 循环一级 判断当前账户有没有权限修改增加
for (let i of _a) {
for (let j in _p) {
if (_p[j].key == i) {
arr.push(_p[j].key);
_p[j].disabled = false;
}
// 二级权限
for (let k in _p[j].children) {
if (_p[j].children[k].key == i) {
erArr.push(_p[j].children[k].key);
_p[j].children[k].disableCheckbox = false;
}
}
}
}
// 且禁用最后两个账户管理
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
// 赋值改变
treeDatas[0].children = _p;
settreeDataList(treeDatas as any); // 可勾选列表
};
// 保存提交
const onFinishContract = async (value: any) => {
const userInfo = localStorage.getItem('userInfo') || '';
......@@ -198,7 +221,7 @@ const Account = (props: any) => {
value.tosUserServiceCellList = value.community.value; // 管辖小区
value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别
value.creatorName = JSON.parse(userInfo).userModel.tosUserName; //新建者账号
// value.creatorName = JSON.parse(userInfo).userModel.tosUserName; //新建者账号
value.creatorId = id; //新建者ID
if (values == 3) {
value.userLeader = towAccountId;
......@@ -263,37 +286,6 @@ const Account = (props: any) => {
setSelectedKeys(selectedKeys);
};
// 管理员级别样式
const radioStyle = {
display: 'block',
height: '30px',
lineHeight: '30px',
marginBottom: '15px',
};
//级别切换
const onRadio = (e: any) => {
setvalues(e.target.value);
// 如果是3级,取消后面两个选择
let treeDatas = treeData;
let _p = treeDatas[0].children; // 所有权限列表
// 禁用最后两个
if (e.target.value == 3) {
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
} else {
//否则打开
_p[_p.length - 1].children[2].disableCheckbox = false;
_p[_p.length - 1].children[3].disableCheckbox = false;
settowAccountId(null);
}
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
};
//手机号
const keyup_communityManagerFee = (e: any) => {
e.target.value = keyup_tool(e.target.value);
......@@ -302,21 +294,6 @@ const Account = (props: any) => {
return getNumber(value.replace(/[^\d^\.]+/g, ''));
};
// 二级账户
const listItems = towAccount.map((item: any) => {
return (
<Option key={item.id} value={item.id}>
{item.tosAccountName}-{item.tosUserEmail}
</Option>
);
});
// 选择哪个二级账号
const handleChange = (value: any) => {
// console.log(`selected ${value}`);
settowAccountId(value);
};
return (
<Spin spinning={loading}>
<div className="contop" style={{ padding: '12px 20px' }}>
......@@ -367,7 +344,7 @@ const Account = (props: any) => {
</Descriptions>
<Form.Item name="community" label="Community">
<SelectCommunity checklist={CommunityList == null ? null : CommunityList} />
<SelectCommunity checklist={community} />
</Form.Item>
<div className="diy" style={{ marginBottom: '14px' }}>
......@@ -375,25 +352,23 @@ const Account = (props: any) => {
<span className="title">Privilege Level:</span>
</div>
<div className="label">
<Radio.Group value={values} onChange={onRadio}>
<Radio style={radioStyle} disabled={disab} value={2}>
Two Level Administrator
</Radio>
<Radio style={radioStyle} value={3}>
Three Level Administrator
</Radio>
</Radio.Group>
{/* 选择挂靠的二级菜单 */}
{values === 3 && user.currentUser.userModel.tosUserLevel <= 1 ? (
<Select
style={{ width: 260 }}
onChange={handleChange}
placeholder="Please select affiliated account"
defaultValue={towAccountId as any}
<Tag
icon={<CheckCircleOutlined />}
color="success"
style={{ verticalAlign: 'sub', fontSize: 14, padding: '4px 7px' }}
>
{DataSave.tosUserLevel == 2
? 'Two Level Administrator '
: 'Three Level Administrator'}
</Tag>
{DataSave.tosUserLevel == 3 ? (
<Tag
icon={<RightOutlined />}
color="processing"
style={{ verticalAlign: 'sub', fontSize: 14, padding: '4px 7px' }}
>
{towAccount ? listItems : ''}
</Select>
Superiors:{DataSave.userLeaderAccountName} - {DataSave.userLeaderName}
</Tag>
) : (
''
)}
......@@ -414,7 +389,8 @@ const Account = (props: any) => {
checkedKeys={checkedKeys}
onSelect={onSelect}
selectedKeys={selectedKeys}
treeData={treeData}
treeData={treeDataList}
disabled
/>
</div>
</div>
......@@ -434,7 +410,7 @@ const Account = (props: any) => {
};
const AccountProps = (state: any) => {
const { Data, DataSave, DataSaveDetail, Result, SubResult, Permission } = state.Account;
const { Data, DataSave, DataSaveDetail, Result, SubResult, Permission, Info } = state.Account;
const { CommunityList } = state.Init; // 小区列表
const loading = state.loading.models.Account || false;
const { user } = state;
......@@ -448,6 +424,7 @@ const AccountProps = (state: any) => {
CommunityList,
user, // 获取当前账户信息
SubResult,
Info,
};
};
......
......@@ -167,9 +167,7 @@ const BookingDetail = (props: any) => {
<hr />
{/* 已交押金且未产生退费 */}
{DataSave != null &&
DataSave.managerFeeStatus == 1 &&
DataSave.communityManagerFee > 0 ? (
{DataSave != null && DataSave.managerFeeStatus == 1 && DataSave.backMarginFee > 0 ? (
<>
<Form
ref={formRef}
......
......@@ -130,4 +130,5 @@ export const requestList = [
['/tos/user/permission/get', '54 根据用户名称获取用户权限', {}],
['/tos/tosCommunity/get/user', '55 根据用户id获取用户管辖小区名', {}],
['/tos/user/twoLevel/get', '56 获取二级账号', {}],
['/tos/user/twoLevel/get/CommunityAuth', '57 根据用户id获取用户管辖小区名和权限', {}],
];
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