Commit c9b23759 authored by cellee's avatar cellee

账号权限

Signed-off-by: cellee's avatarcellee <893264950@qq.com>
parent d1381930
import React, { useState, useEffect, useRef } from 'react';
import './index.less';
import { Button, Form, message, Modal, Input, Upload } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
// import FacilitysTow from './FacilitysTow';
import { Link, useIntl, connect, Dispatch, history } from 'umi';
function getBase64(file: any) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
});
}
const module = 'FacilityBookings';
const Facilitys = (props: any) => {
//传递值
const { updata, disabled, FacilitysList, dispatch, dumps } = props;
//上传列表
// const [FacilitysList, setFileList] = useState(FacilitysList);
//显示隐藏
const [previewVisible, setpreviewVisible] = useState(false);
// 名称
const [previewTitle, setpreviewTitle] = useState('');
// 图片地址
const [previewImage, setpreviewImage] = useState('');
// 传递给后台加 key
const updetaTow = (key: any) => {
let data = updata;
data.identification = key;
return data;
};
//绑定值
const updetaList = (key: any) => {
return FacilitysList[key].fileList;
};
// 预览
const handlePreview = async (file: any) => {
if (!file.url && !file.preview) {
file.preview = await getBase64(file.originFileObj);
}
setpreviewImage(file.url || file.preview);
setpreviewTitle(file.name);
setpreviewVisible(true);
};
// 点击遮罩回调
const handleCancel = () => {
setpreviewVisible(false);
};
// 上传属性
const uploadProps: any = {
listType: 'picture-card',
accept: '.jpeg,.png,.jpg',
action: '/tos/image/upload',
onChange(info: any) {
// console.log(info);
if (info.file.status === 'done') {
message.success(`${info.file.name} file uploaded successfully`);
// 拿到key 值 开始存储
let key = info.fileList[0].response.data.identification;
let list = FacilitysList;
list[key].id = key;
list[key].fileList = info.fileList;
// 存储到mode里面去
dispatch({ type: module + '/genxin', list });
// 当前页面也要刷新
// let list = fileList;
// setFileList(list); // 注意 不能直接赋值 因为使用完全绑定需要全部更新
// setFileList(list);
// let list: any = [...fileList, ...info.fileList];
// setFileList(list);
console.log(list);
// 将图片信息提交给state
// let data = { val: info.file.name, key: keys };
// dispatch({ type: module + '/retImgsList', data });
// 结束
} else if (info.file.status === 'error') {
message.error(`${info.file.name} file upload failed.`);
}
},
};
// 新增动作
const add = () => {
let list = FacilitysList;
let adds = {
id: '-1',
fileList: [],
name: '',
};
// 验证已添加的是否上传完整
let complete = list.every((item: any) => {
// return item.fileList.length > 0 && item.name !== '';
return item.fileList.length > 0;
});
if (list.length == 0 || complete) {
list.push(adds);
// 存储到mode里面去
dispatch({ type: module + '/genxin', list });
} else {
// 提示每一项都要填写完
message.error('Please fill out each item !');
}
};
//删除动作
const deleteImg = (key: any) => {
console.log(key);
let list = FacilitysList;
// list[key].name = '';
// 这里还要清除表单的值,否则再次新增输入框的值会重复出现
dumps(key);
list.splice(key, 1);
console.log(list);
// // 存储到mode里面去
dispatch({ type: module + '/genxin', list });
};
// 新增按钮
const uploadButton = (
<div>
<PlusOutlined />
<div className="ant-upload-text">Upload</div>
</div>
);
// 输入框内容
const monitor = (e: any) => {
let list = FacilitysList;
let { id, value } = e.target;
if (id == 'basic_shebei_0') {
id = 0;
}
list[id].name = value;
dispatch({ type: module + '/genxin', list });
};
return (
<>
<Form.Item name="picList" required={false} style={{ marginBottom: 0 }}>
{FacilitysList.map((item: any, index: any, keys: any) => {
console.log(item);
return (
<div className={'test'} key={item.id}>
<div className={'diybox'} key={item.id}>
<Upload
{...uploadProps}
fileList={
FacilitysList[index].fileList.length > 0 ? FacilitysList[index].fileList : false
}
// data={updata}
data={updetaTow(index)} // 携带数据
disabled={disabled} // 禁止
onPreview={handlePreview} // 预览
onRemove={() => {
deleteImg(index);
}} //移除
>
{FacilitysList[index].fileList.length > 0 ? null : uploadButton}
</Upload>
<div className={'Facility'} key={item.id}>
<Form.Item
label={`Facility Name ${index + 1}`}
name={'shebei_' + index}
rules={[{ required: true, message: 'Please input Facility Name!' }]}
>
<Input
placeholder="Facility Name"
disabled={disabled}
id={index}
onChange={(e: any) => monitor(e)}
value={FacilitysList[index].name}
/>
</Form.Item>
<div className={'over'}>
<Button type="link" disabled={disabled} onClick={() => deleteImg(index)}>
Delete
</Button>
</div>
</div>
</div>
</div>
);
})}
</Form.Item>
<Form.Item>
<Button
type="dashed"
onClick={() => add()}
style={{ width: '100px', height: '100px' }}
icon={<PlusOutlined />}
disabled={disabled}
></Button>
</Form.Item>
{/* 预览表格 */}
<Modal visible={previewVisible} title={previewTitle} footer={null} onCancel={handleCancel}>
<img alt="example" style={{ width: '100%' }} src={previewImage} />
</Modal>
</>
);
};
function mapStateToProps(state: any) {
const { FacilitysList } = state.FacilityBookings;
return {
FacilitysList,
};
}
export default connect(mapStateToProps)(Facilitys);
......@@ -50,13 +50,6 @@ const Facilitys = (props: any) => {
setpreviewVisible(true);
};
// 点击移除图片
const handRemove = (key: any) => {
// let list = fileList;
// 将图片信息提交给state
deleteImg(key);
};
// 点击遮罩回调
const handleCancel = () => {
setpreviewVisible(false);
......@@ -123,12 +116,13 @@ const Facilitys = (props: any) => {
};
//删除动作
const deleteImg = (key: any) => {
const deleteImg = (key: any, id: any) => {
let list = FacilitysList;
list[key].name = '';
// 这里还要清除表单的值,否则再次新增输入框的值会重复出现
dumps(key);
dumps(id);
list.splice(key, 1);
// 存储到mode里面去
......@@ -159,8 +153,8 @@ const Facilitys = (props: any) => {
<Form.Item name="picList" required={false} style={{ marginBottom: 0 }}>
{FacilitysList.map((item: any, index: any, key: any) => {
return (
<div className={'test'} key={'pic_' + index}>
<div className={'diybox'} key={'pic_' + index}>
<div className={'test'} key={item.id}>
<div className={'diybox'} key={item.id}>
<Upload
{...uploadProps}
fileList={
......@@ -171,16 +165,16 @@ const Facilitys = (props: any) => {
disabled={disabled} // 禁止
onPreview={handlePreview} // 预览
onRemove={() => {
handRemove(index);
deleteImg(index, item.id);
}} //移除
>
{FacilitysList[index].fileList.length > 0 ? null : uploadButton}
</Upload>
<div className={'Facility'} key={'pic_' + index}>
<div className={'Facility'} key={item.id}>
<Form.Item
label={`Facility Name ${index + 1}`}
name={'shebei_' + index}
name={'shebei_' + item.id}
rules={[{ required: true, message: 'Please input Facility Name!' }]}
>
<Input
......@@ -192,7 +186,11 @@ const Facilitys = (props: any) => {
/>
</Form.Item>
<div className={'over'}>
<Button type="link" disabled={disabled} onClick={() => deleteImg(index)}>
<Button
type="link"
disabled={disabled}
onClick={() => deleteImg(index, item.id)}
>
Delete
</Button>
</div>
......
......@@ -115,7 +115,7 @@ const PictureOptionsRow = (props: any) => {
}
return isJpgOrPng && isLt2M;
}
console.log(props);
// console.log(props);
return (
<div>
<Upload
......
......@@ -105,6 +105,11 @@ export default {
// yield put({ type: 'returnResult', Result });
}
break;
case 56: // 二级账号
{
localStorage.setItem('towAccount', JSON.stringify(resp.data));
}
break;
}
}
},
......
......@@ -110,8 +110,8 @@ const Account = (props: any) => {
},
{
title: 'Creation Time',
dataIndex: 'createTime',
key: 'createTime',
dataIndex: 'updateTime',
key: 'updateTime',
render: (text: any) => {
return moment(text).format('YYYY-MM-DD');
},
......
import React, { useState, useEffect, useRef } from 'react';
import { Form, Input, Button, message, Descriptions, Spin, 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';
......@@ -27,11 +26,18 @@ const Account = (props: any) => {
// 单选 二级还是三级管理员
const [values, setvalues] = useState(2); // 树形菜单展开关闭
const [disab, setdisab] = useState(false); // 是否禁止选择二级
const [towAccountId, settowAccountId] = useState(null); // 二级账户id
// 表单标识
const [form] = Form.useForm();
const formRef = useRef(null);
const { Option } = Select;
//二级账户列表
const towAccount = JSON.parse(localStorage.getItem('towAccount') || '[]');
// 当前账户权限
useEffect(() => {
if (user != null) {
......@@ -57,6 +63,23 @@ 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); // 可勾选列表
......@@ -101,12 +124,19 @@ 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 = JSON.parse(userInfo).userModel.tosUserName; //新建者账号
value.creatorId = id; //新建者ID
if (values == 3) {
value.userLeader = towAccountId;
}
delete value.community;
// 判断有没有 0 有就删除
......@@ -177,6 +207,24 @@ const Account = (props: any) => {
//级别切换
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); // 可勾选列表
};
//手机号
......@@ -186,7 +234,21 @@ const Account = (props: any) => {
const keyup_tool = (value: 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}>
......@@ -246,15 +308,27 @@ const Account = (props: any) => {
<span className="title">Privilege Level:</span>
</div>
<div className="label">
<Radio.Group defaultValue={values} onChange={onRadio}>
<Radio style={radioStyle} value={2}>
<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
{/* <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"
>
{towAccount ? listItems : ''}
</Select>
) : (
''
)}
</div>
</div>
......
import React, { useState, useEffect, useRef } from 'react';
import { Form, Input, Button, Spin, message, Descriptions, Tree, Radio } 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';
import { AccountTip } from '@/utils/tip';
import SelectCommunity from '@/components/SelectCommunity';
import { getNumber } from '@/utils/string'; // 正则
import { RA } from '@/utils/method';
const Account = (props: any) => {
const module = 'Account';
const { dispatch, Data, DataSave, DataSaveDetail, SubResult, loading, Permission, user } = props;
// 权限列表
const treeData = enUsFaci || zhCnFaci;
const [expandedKeys, setExpandedKeys] = useState<string[]>([]); // 展开栏目
const [checkedKeys, setCheckedKeys] = useState<string[]>([]); // 默认已选栏目
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树大节点
const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭
// 单选 二级还是三级管理员
const [values, setvalues] = useState(2); // 树形菜单展开关闭
const [disab, setdisab] = useState(false); // 是否禁止选择二级
// 表单标识
const [form] = Form.useForm();
const formRef = useRef(null);
// 数据
useEffect(() => {
if (DataSave != null) {
// 赋值
form.setFieldsValue({
tosUserName: DataSave.tosUserName,
tosUserPhone: DataSave.tosUserPhone,
tosAccountName: DataSave.tosAccountName,
});
setvalues(DataSave.tosUserLevel); // 等级
// 发起获取权限请求
RA(54, { tosUserName: DataSave.tosUserName }, module, dispatch); // 发起获取权限请求
}
}, [DataSave]);
// 当前账户权限
useEffect(() => {
if (user != null) {
let treeDatas = treeData;
let _a = user.currentUser.permission; // 当前账户权限
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;
}
}
}
}
// 当当前账户是二级以上禁用创建二级菜单
if (user.currentUser.userModel.tosUserLevel > 1) {
setvalues(user.currentUser.userModel.tosUserLevel);
setdisab(true);
// 禁用最后两个
_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);
}
}
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
}
}, [user]);
// 已选权限
useEffect(() => {
if (Permission != null) {
let newPer = eval('(' + Permission + ')');
let data: any = []; // 编辑的账户的权限
for (let i in newPer) {
data[i] = newPer[i] + '';
}
// console.log(data); // 编辑的账户的权限
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);
}
}
// 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);
}
}
}, [SubResult]);
// 保存提交
const onFinishContract = async (value: any) => {
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
if (
value.tosAccountName.length <= 2 &&
value.tosUserPhone.length != 8 &&
value.tosUserPhone.length != 11
) {
// 姓名联系方式
message.error('Please enter the correct name and contact information!');
return false;
} else if (checkedKeys.length == 0) {
// 权限
message.error('Please Select Permission!');
return false;
} else if (value.community.value == null || value.community.value.length == 0) {
// 小区
message.error('Please Select The Jurisdiction Area!');
return false;
} else if (value.tosUserName.length < 6) {
// 账号长度
message.error('The Account Password is Greater Than 6 Digits!');
return false;
} else {
value.tosUserServiceCellList = value.community.value; // 管辖小区
value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别
value.creatorName = getCookie('name'); //新建者账号
value.creatorId = id; //新建者ID
delete value.community;
value.id = DataSave.id;
// 判断有没有 0 有就删除
for (var i in checkedKeys) {
checkedKeys[i] == '0' ? checkedKeys.splice(i as any, 1) : '';
}
// 追加到上级id
let Obj = treeData[0].children;
console.log(Obj);
for (let i in Obj) {
for (let j in checkedKeys) {
if (JSON.stringify(Obj[i].children).indexOf(JSON.stringify(checkedKeys[j])) != -1) {
// 提取出上级id 并且追加
checkedKeys.push(Obj[i].key);
}
}
}
// 去重后在排序
let newData = Array.from(new Set(checkedKeys)).sort((n1: any, n2: any) => {
return parseInt(n1) - parseInt(n2);
});
// 另传权限
let obj = {
userName: value.tosUserName,
userPassword: value.tosUserPwd,
permissionArray: newData,
};
RA(38, value, module, dispatch); // 信息上传
RA(42, obj, module, dispatch); // 权限上传
}
};
//goToReturn
const goToReturn = () => {
history.go(-1);
};
// 全选
const onCheckAllChange = (e: any) => {};
// 展开/收起树形菜单触发
const onExpand = (expandedKeys: any) => {
setExpandedKeys(expandedKeys);
setAutoExpandParent(false);
};
// 点击单个触发
const onCheck = (checkedKeys: any) => {
console.log('onCheck', checkedKeys);
setCheckedKeys(checkedKeys);
};
// 点击树节点触发 - 大栏目
const onSelect = (selectedKeys: any, info: any) => {
console.log('onSelect', info);
setSelectedKeys(selectedKeys);
};
// 管理员级别样式
const radioStyle = {
display: 'block',
height: '30px',
lineHeight: '30px',
marginBottom: '15px',
};
//级别切换
const onRadio = (e: any) => {
setvalues(e.target.value);
};
//手机号
const keyup_communityManagerFee = (e: any) => {
e.target.value = keyup_tool(e.target.value);
};
const keyup_tool = (value: any) => {
return getNumber(value.replace(/[^\d^\.]+/g, ''));
};
return (
<Spin spinning={loading}>
<div className="contop" style={{ padding: '12px 20px' }}>
<h3 className="capi">
<EditOutlined />
&nbsp; Edit Account
<div className="back">
<Button onClick={goToReturn}>
<LeftOutlined />
Back
</Button>
</div>
</h3>
<hr></hr>
<Form
ref={formRef}
form={form}
autoComplete="off"
// layout="inline"
layout="horizontal"
name="contract"
onFinish={onFinishContract}
>
<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 />
</Form.Item>
</Descriptions.Item>
</Descriptions>
<Descriptions column={{ xs: 1, sm: 2, md: 3 }}>
<Descriptions.Item>
<Form.Item name="tosAccountName" label="Name" rules={AccountTip[1] as any}>
<Input placeholder="Name Of Administrator" className="input" />
</Form.Item>
</Descriptions.Item>
<Descriptions.Item>
<Form.Item name="tosUserPhone" label="Phone" rules={AccountTip[2] as any}>
<Input
placeholder="Contact Information"
className="input"
maxLength={11}
onKeyUp={keyup_communityManagerFee}
/>
</Form.Item>
</Descriptions.Item>
</Descriptions>
<Form.Item name="community" label="Community">
<SelectCommunity
checklist={DataSave == null ? null : DataSave.tosUserServiceCell.split(',')}
/>
</Form.Item>
<div className="diy" style={{ marginBottom: '14px' }}>
<div className="label">
<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
{/* <Input placeholder="三级管理员" style={{ width: 160, marginLeft: 10 }} /> */}
</Radio>
</Radio.Group>
</div>
</div>
<div className="diy" style={{ marginBottom: '24px' }}>
<div className="label">
<span className="title">Permission List:</span>
</div>
<div className="label">
<Tree
checkable
onExpand={onExpand}
expandedKeys={expandedKeys}
autoExpandParent={autoExpandParent}
onCheck={onCheck}
checkedKeys={checkedKeys}
onSelect={onSelect}
selectedKeys={selectedKeys}
treeData={treeData}
// checkStrictly={true}
/>
</div>
</div>
<div className="diy">
<div className="label"></div>
<div className="label">
<Button type="primary" htmlType="submit" loading={loading}>
Submit
</Button>
</div>
</div>
</Form>
</div>
</Spin>
);
};
const AccountProps = (state: any) => {
const { Data, DataSave, DataSaveDetail, Result, Permission, SubResult } = state.Account;
const loading = state.loading.models.Account || false;
const { user } = state;
return {
Data,
DataSave,
DataSaveDetail,
Result,
loading,
Permission,
user,
SubResult,
};
};
export default connect(AccountProps)(Account);
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,47 +14,31 @@ 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 } = props;
// 权限列表
const treeData = enUsFaci || zhCnFaci;
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 [values, setvalues] = useState(2); // 树形菜单展开关闭
const [disab, setdisab] = useState(false); // 是否禁止选择二级
const [towAccountId, settowAccountId] = useState(null); // 二级账户id
// 表单标识
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); // 等级
//二级账户列表
const towAccount = JSON.parse(localStorage.getItem('towAccount') || '[]');
// 发起获取权限请求
RA(54, { tosUserName: DataSave.tosUserName }, module, dispatch); // 发起获取权限请求
}
// let a = [];
// for (var i = 0; i <= 66; i++) {
// a.push(i);
// }
// console.log(a);
}, [DataSave]);
// 当前账户权限
// 登录账户权限
useEffect(() => {
if (user != null) {
let treeDatas = treeData;
......@@ -80,12 +63,71 @@ 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); // 可勾选列表
}
}, [user]);
// 当前编辑账户的数据
useEffect(() => {
if (DataSave != null) {
// 赋值
form.setFieldsValue({
tosUserName: DataSave.tosUserName,
tosUserPhone: DataSave.tosUserPhone,
tosAccountName: DataSave.tosAccountName,
});
settowAccountId(DataSave.userLeader); // 二级账户id
setvalues(DataSave.tosUserLevel); // 等级
// 如果是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]);
// 提交信息结果
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(() => {
if (Permission != null) {
......@@ -94,7 +136,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); // 所有权限列表
......@@ -119,26 +160,11 @@ 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);
}
}
}, [SubResult]);
// 保存提交
const onFinishContract = async (value: any) => {
const userInfo = localStorage.getItem('userInfo') || '';
......@@ -151,7 +177,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;
......@@ -163,19 +190,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
......@@ -203,6 +236,7 @@ const Account = (props: any) => {
RA(38, value, module, dispatch); // 信息上传
RA(42, obj, module, dispatch); // 权限上传
return true;
}
};
......@@ -211,9 +245,6 @@ const Account = (props: any) => {
history.go(-1);
};
// 全选
const onCheckAllChange = (e: any) => {};
// 展开/收起树形菜单触发
const onExpand = (expandedKeys: any) => {
setExpandedKeys(expandedKeys);
......@@ -222,13 +253,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);
};
......@@ -243,6 +274,24 @@ const Account = (props: any) => {
//级别切换
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); // 可勾选列表
};
//手机号
......@@ -253,6 +302,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) => {
// console.log(`selected ${value}`);
settowAccountId(value);
};
return (
<Spin spinning={loading}>
<div className="contop" style={{ padding: '12px 20px' }}>
......@@ -267,7 +331,6 @@ const Account = (props: any) => {
</div>
</h3>
<hr></hr>
<Form
ref={formRef}
form={form}
......@@ -280,7 +343,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>
......@@ -304,9 +367,7 @@ const Account = (props: any) => {
</Descriptions>
<Form.Item name="community" label="Community">
<SelectCommunity
checklist={DataSave == null ? null : DataSave.tosUserServiceCell.split(',')}
/>
<SelectCommunity checklist={CommunityList == null ? null : CommunityList} />
</Form.Item>
<div className="diy" style={{ marginBottom: '14px' }}>
......@@ -314,15 +375,28 @@ const Account = (props: any) => {
<span className="title">Privilege Level:</span>
</div>
<div className="label">
<Radio.Group defaultValue={DataSave ? DataSave.tosUserLevel : 2} onChange={onRadio}>
<Radio style={radioStyle} value={2}>
<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
{/* <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>
......@@ -341,7 +415,6 @@ const Account = (props: any) => {
onSelect={onSelect}
selectedKeys={selectedKeys}
treeData={treeData}
// checkStrictly={true}
/>
</div>
</div>
......@@ -361,7 +434,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 } = state.Account;
const { CommunityList } = state.Init; // 小区列表
const loading = state.loading.models.Account || false;
const { user } = state;
return {
......@@ -371,7 +445,8 @@ const AccountProps = (state: any) => {
Result,
loading,
Permission,
user,
CommunityList,
user, // 获取当前账户信息
SubResult,
};
};
......
......@@ -135,11 +135,16 @@ const CardDetail = (props: any) => {
{listData.apply_status === 0 ? (
<Form ref={formRef} name="basic" onFinish={onFinish}>
<Row gutter={8} style={{ marginTop: 16 }}>
<Col span={3}>Examine:</Col>
<Col span={3}>Approval For Application:</Col>
<Col span={5}>
<Form.Item
name="applyStatus"
rules={[{ required: true, message: 'Please select the reply result!' }]}
rules={[
{
required: true,
message: 'Please choose Approve or Reject for the application!',
},
]}
>
<Radio.Group>
<Radio.Button value={'1'}>Approve</Radio.Button>
......
......@@ -136,7 +136,12 @@ const RenovationDetail = (props: any) => {
<Col>
<Form.Item
name="decorationStatus"
rules={[{ required: true, message: 'You have to choose an outcome!' }]}
rules={[
{
required: true,
message: 'Please choose Approve or Reject the application! ',
},
]}
>
<Radio.Group>
<Radio.Button value={'1'}>Approve</Radio.Button>{' '}
......
......@@ -45,6 +45,8 @@ const Facility = (props: any) => {
const [ctyName, setCtyName] = useState(null);
const [soltTime, setSoltTime] = useState(['', '']); // 已选时间
const [Cycle, setCycle] = useState(null as any); // Appointment Cycle下拉
// 表单标识
const [form] = Form.useForm();
......@@ -102,9 +104,14 @@ const Facility = (props: any) => {
setFileList(sourceData.categoriesDetailsImageName); //设置图片组名称
// delete sourceData.categoriesDetailsImageName;
setCycle(sourceData.periodType + '');
// delete sourceData.periodType;
// 设置表单默认值
formRef.current.setFieldsValue(sourceData);
console.log(Cycle);
} else {
// 新增页面进来 先清一遍 图片列表
let list: any = [];
......@@ -175,6 +182,8 @@ const Facility = (props: any) => {
result.categoriesOpenTime = `${soltTime[0]}-${soltTime[1]}`; // 预约时间段 二开需要
result.communityManagerFee = result.communityManagerFee ? result.communityManagerFee : '0.00'; // 价格押金没有为0
result.communityMargin = result.communityMargin ? result.communityMargin : '0.00'; // 价格押金没有为0
result.periodType = Cycle;
delete result.startTime;
delete result.endTime;
delete result.picList;
......@@ -216,6 +225,11 @@ const Facility = (props: any) => {
formRef.current.setFieldsValue(tmp);
};
//选择周期
function handleChange(value: any) {
setCycle(value);
}
// 选择小区名字并赋值
const opname = (value: any) => {
console.log('选择的小区是:' + value);
......@@ -455,12 +469,14 @@ const Facility = (props: any) => {
{/* 设置次数 */}
<Input.Group>
<Form.Item label="Appointment Cycle" name="periodType" rules={NewFaci[8]}>
<Form.Item label="Appointment Cycle" rules={NewFaci[8]}>
<Select
placeholder="Period"
allowClear
style={{ width: 120 }}
disabled={facilityDetail}
value={Cycle ? Cycle : ''}
onChange={handleChange}
>
<Option value="1">Week</Option>
<Option value="2">Month</Option>
......
......@@ -392,7 +392,7 @@ const FacilityBookings = (props: any) => {
};
function mapStateToProps(state: any) {
console.log(state);
// console.log(state);
const { Data, Data2, DataSave, curString, Result } = state.FacilityBookings;
const { token } = state.login;
const loading =
......
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