🦺 新建、编辑子账号只校验账号和手机号

This commit is contained in:
wangsongsole 2023-04-27 16:30:29 +08:00
parent b6b5a96b17
commit 799a288849
1 changed files with 173 additions and 204 deletions

View File

@ -1,13 +1,13 @@
import React from "react"; import React from 'react';
import "./adduserinfo.less"; import './adduserinfo.less';
import Ipt from "@/components/input/main"; import Ipt from '@/components/input/main';
import Form from "@/components/form/main"; import Form from '@/components/form/main';
import FormItem from "@/components/form-item/main"; import FormItem from '@/components/form-item/main';
import "@/assets/comm.css"; import '@/assets/comm.css';
import Tree from "./tree"; import Tree from './tree';
import { Select, Button, ImageUpload, Sweetalert, Notify, Card } from "zent"; import { Select, Button, ImageUpload, Sweetalert, Notify, Card } from 'zent';
import Bus from "@/assets/eventBus.js"; import Bus from '@/assets/eventBus.js';
import cloneDeep from "lodash/cloneDeep"; import cloneDeep from 'lodash/cloneDeep';
import { import {
handelResponse, handelResponse,
uploadImg, uploadImg,
@ -17,7 +17,7 @@ import {
getRole, getRole,
postAddSubAcc, postAddSubAcc,
getDepartmentJob getDepartmentJob
} from "@/assets/api.js"; } from '@/assets/api.js';
export default class addUserinfo extends React.Component { export default class addUserinfo extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -25,23 +25,23 @@ export default class addUserinfo extends React.Component {
this.state = { this.state = {
model: { model: {
//数据模型不可少 //数据模型不可少
user_name: "", user_name: '',
mobile: "", mobile: '',
password: "", password: '',
real_name: "", real_name: '',
company: "", company: '',
deparment: "", deparment: '',
post: "" post: ''
}, },
companyList: [], //公司 companyList: [], //公司
departmentList: [], //部门 departmentList: [], //部门
departmentJob: [], //岗位 departmentJob: [], //岗位
roleList: [], //角色 roleList: [], //角色
headImg: "", headImg: '',
pwdtype: "text", pwdtype: 'text',
defaultFileList: [{ src: "" }], defaultFileList: [{ src: '' }],
disabled: false, disabled: false,
id: "", id: '',
ruleId: [] ruleId: []
}; };
} }
@ -50,7 +50,7 @@ export default class addUserinfo extends React.Component {
componentWillMount() { componentWillMount() {
let _self = this; let _self = this;
this.getCompanyFn(); //获取公司 this.getCompanyFn(); //获取公司
let companys = JSON.parse(sessionStorage.getItem("company")); let companys = JSON.parse(sessionStorage.getItem('company'));
if (!companys) { if (!companys) {
this.getCompanyFn(); //获取公司 this.getCompanyFn(); //获取公司
} }
@ -58,12 +58,12 @@ export default class addUserinfo extends React.Component {
this.getRoleFn(); //获取角色 this.getRoleFn(); //获取角色
let formInfo = this.props; let formInfo = this.props;
if (formInfo && formInfo.enumer == 1) { if (formInfo && formInfo.enumer == 1) {
this.setState({ pwdtype: "password" }); this.setState({ pwdtype: 'password' });
let acceptData = cloneDeep(formInfo.rowData); let acceptData = cloneDeep(formInfo.rowData);
let data = { let data = {
user_name: acceptData.user_name, user_name: acceptData.user_name,
mobile: acceptData.mobile, mobile: acceptData.mobile,
password: "yxtx2021", password: 'yxtx2021',
real_name: acceptData.real_name, real_name: acceptData.real_name,
company: companys.find((o) => o.key == acceptData.company_id), company: companys.find((o) => o.key == acceptData.company_id),
deparment: { deparment: {
@ -124,7 +124,7 @@ export default class addUserinfo extends React.Component {
} }
} }
changeKind() { changeKind() {
this.setState({ pwdtype: "password" }); this.setState({ pwdtype: 'password' });
} }
submit() { submit() {
let valiform = this.refs.form1.validator(); let valiform = this.refs.form1.validator();
@ -132,15 +132,11 @@ export default class addUserinfo extends React.Component {
let iptVal = this.state.model; let iptVal = this.state.model;
let _this = this; let _this = this;
if (valiform) { if (valiform) {
if (!roleArr || roleArr.length < 1) {
Notify.clear();
Notify.error("请设置子账号权限");
} else {
//取消二次弹出框 //取消二次弹出框
Sweetalert.confirm({ Sweetalert.confirm({
type: "warning", type: 'warning',
closeBtn: true, closeBtn: true,
title: "确认操作", title: '确认操作',
content: content:
_this.props.enumer == 0 ? ( _this.props.enumer == 0 ? (
<p> <p>
@ -159,7 +155,7 @@ export default class addUserinfo extends React.Component {
job_id: iptVal.post.key, job_id: iptVal.post.key,
real_name: iptVal.real_name, real_name: iptVal.real_name,
mobile: iptVal.mobile, mobile: iptVal.mobile,
assist_user_id: sessionStorage.getItem("subaid"), assist_user_id: sessionStorage.getItem('subaid'),
rule: roleArr rule: roleArr
}; };
if (_this.state.headImg) { if (_this.state.headImg) {
@ -176,12 +172,10 @@ export default class addUserinfo extends React.Component {
Notify.success(msg); Notify.success(msg);
setTimeout(() => { setTimeout(() => {
// window.history.back() // window.history.back()
window.location.replace( window.location.replace('#/home/system/subaccount-list');
"#/home/system/subaccount-list"
);
sessionStorage.setItem( sessionStorage.setItem(
"pathname2", 'pathname2',
"/home/system/subaccount-list" '/home/system/subaccount-list'
); );
}, 1000); }, 1000);
}, },
@ -205,12 +199,10 @@ export default class addUserinfo extends React.Component {
Notify.success(msg); Notify.success(msg);
setTimeout(() => { setTimeout(() => {
// window.history.back() // window.history.back()
window.location.replace( window.location.replace('#/home/system/subaccount-list');
"#/home/system/subaccount-list"
);
sessionStorage.setItem( sessionStorage.setItem(
"pathname2", 'pathname2',
"/home/system/subaccount-list" '/home/system/subaccount-list'
); );
}, 1000); }, 1000);
}, },
@ -223,20 +215,19 @@ export default class addUserinfo extends React.Component {
} }
}, },
onCancel: this.onCancel, onCancel: this.onCancel,
className: "questModal", className: 'questModal',
parentComponent: this parentComponent: this
}); });
}
} else { } else {
Notify.clear(); Notify.clear();
Notify.error("请完善表单数据"); Notify.error('请完善表单数据');
} }
} }
onUploadError = (type, data) => { onUploadError = (type, data) => {
if (type === "overMaxAmount") { if (type === 'overMaxAmount') {
Notify.clear(); Notify.clear();
Notify.error(`最多可上传 ${data.maxAmount} 张图片`); Notify.error(`最多可上传 ${data.maxAmount} 张图片`);
} else if (type === "overMaxSize") { } else if (type === 'overMaxSize') {
Notify.clear(); Notify.clear();
Notify.error(`图片大小不能超过 ${data.formattedMaxSize}b`); Notify.error(`图片大小不能超过 ${data.formattedMaxSize}b`);
} }
@ -247,8 +238,8 @@ export default class addUserinfo extends React.Component {
let _self = this; let _self = this;
if (files && files.length > 0) { if (files && files.length > 0) {
let formdata = new FormData(); let formdata = new FormData();
formdata.append("file", files[0].file); formdata.append('file', files[0].file);
formdata.append("path", "account_avatar"); formdata.append('path', 'account_avatar');
uploadImg(formdata) uploadImg(formdata)
.then((res) => { .then((res) => {
handelResponse( handelResponse(
@ -265,15 +256,15 @@ export default class addUserinfo extends React.Component {
}) })
.catch((err) => {}); .catch((err) => {});
} else { } else {
_self.setState({ headImg: "" }); _self.setState({ headImg: '' });
} }
} }
onCompanyChange(e) { onCompanyChange(e) {
if (!e) { if (!e) {
let _self = this; let _self = this;
let model2 = this.state.model; let model2 = this.state.model;
model2.deparment = ""; model2.deparment = '';
model2.post = ""; model2.post = '';
this.setState({ this.setState({
model: model2 model: model2
}); });
@ -287,8 +278,8 @@ export default class addUserinfo extends React.Component {
//调部门的数据 //调部门的数据
if (e) { if (e) {
let model3 = this.state.model; let model3 = this.state.model;
model3.deparment = ""; model3.deparment = '';
model3.post = ""; model3.post = '';
_self.setState({ departmentList: [] }); _self.setState({ departmentList: [] });
_self.setState({ departmentJob: [] }); _self.setState({ departmentJob: [] });
_self.setState({ model: model3 }); _self.setState({ model: model3 });
@ -300,7 +291,7 @@ export default class addUserinfo extends React.Component {
(response, msg) => { (response, msg) => {
let departmentList = response.map((item) => { let departmentList = response.map((item) => {
return { key: item.id, text: item.department_name }; return { key: item.id, text: item.department_name };
_self.setState({ deparment: "" }); _self.setState({ deparment: '' });
}); });
_self.setState({ departmentList }); _self.setState({ departmentList });
}, },
@ -319,7 +310,7 @@ export default class addUserinfo extends React.Component {
if (!e) { if (!e) {
let _self = this; let _self = this;
let model2 = this.state.model; let model2 = this.state.model;
model2.post = ""; model2.post = '';
this.setState({ this.setState({
model: model2 model: model2
}); });
@ -343,7 +334,7 @@ export default class addUserinfo extends React.Component {
}); });
_self.setState({ departmentJob }); _self.setState({ departmentJob });
let model3 = this.state.model; let model3 = this.state.model;
model3.post = ""; model3.post = '';
_self.setState({ model: model3 }); _self.setState({ model: model3 });
}, },
(err) => { (err) => {
@ -375,7 +366,7 @@ export default class addUserinfo extends React.Component {
let companyList = response.map((item) => { let companyList = response.map((item) => {
return { key: item.id, text: item.company_name }; return { key: item.id, text: item.company_name };
}); });
sessionStorage.setItem("company", JSON.stringify(companyList)); sessionStorage.setItem('company', JSON.stringify(companyList));
_self.setState({ companyList }); _self.setState({ companyList });
}, },
(err) => { (err) => {
@ -411,17 +402,17 @@ export default class addUserinfo extends React.Component {
cancel() { cancel() {
//取消二次弹出框 //取消二次弹出框
Sweetalert.confirm({ Sweetalert.confirm({
type: "warning", type: 'warning',
closeBtn: true, closeBtn: true,
title: "确认操作", title: '确认操作',
content: <p>是否取消本次操作</p>, content: <p>是否取消本次操作</p>,
onConfirm: () => { onConfirm: () => {
// window.history.back() // window.history.back()
window.location.replace("#/home/system/subaccount-list"); window.location.replace('#/home/system/subaccount-list');
sessionStorage.setItem("pathname2", "/home/system/subaccount-list"); sessionStorage.setItem('pathname2', '/home/system/subaccount-list');
}, },
onCancel: this.onCancel, onCancel: this.onCancel,
className: "questModal", className: 'questModal',
parentComponent: this parentComponent: this
}); });
} }
@ -435,38 +426,19 @@ export default class addUserinfo extends React.Component {
render() { render() {
//校验规则 //校验规则
const rules = { const rules = {
account: [{ type: "required", message: "请输入手机号" }], account: [{ type: 'required', message: '请输入手机号' }],
phone: [ phone: [
{ type: "required", message: "请输入手机号" }, { type: 'required', message: '请输入手机号' },
{ {
type: "regExp", type: 'regExp',
message: "手机号格式不正确", message: '手机号格式不正确',
reg: "^[1][3,4,5,6,7,8,9][0-9]{9}$" reg: '^[1][3,4,5,6,7,8,9][0-9]{9}$'
} }
], ]
pwd: [
{ type: "required", message: "请输入密码" },
{
type: "regExp",
message: "6-16位字符,数字+字母组成(字母区分大小写)",
reg: "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$"
}
],
name: [
{ type: "required", message: "请输入真实姓名" },
{
type: "regExp",
message: "2-16字汉字/字母组成",
reg: "^([\u4e00-\u9fa5]|[a-zA-Z]){2,16}$"
}
],
company: [{ type: "required", message: "请选择公司" }],
deparment: [{ type: "required", message: "请选择部门" }],
post: [{ type: "required", message: "请选择岗位" }]
}; };
return ( return (
<div> <div>
<Card style={{ width: "100%" }} title={this.props.title}> <Card style={{ width: '100%' }} title={this.props.title}>
<div id='addaccinfo'> <div id='addaccinfo'>
<Form <Form
model={this.state.model} model={this.state.model}
@ -482,16 +454,16 @@ export default class addUserinfo extends React.Component {
}} }}
onClearItem={(e) => { onClearItem={(e) => {
let model2 = this.state.model; let model2 = this.state.model;
model2.user_name = ""; model2.user_name = '';
this.setState({ model: model2 }); this.setState({ model: model2 });
}} }}
value={this.state.model.user_name} value={this.state.model.user_name}
placeholder={"请输入手机号"} placeholder={'请输入手机号'}
labelWidth={"0px"} labelWidth={'0px'}
maxLength={12} maxLength={12}
height={"36px"} height={'36px'}
width={"520px"} width={'520px'}
alignment={"left"} alignment={'left'}
/> />
</FormItem> </FormItem>
@ -505,19 +477,19 @@ export default class addUserinfo extends React.Component {
}} }}
onClearItem={(e) => { onClearItem={(e) => {
let model2 = this.state.model; let model2 = this.state.model;
model2.mobile = ""; model2.mobile = '';
this.setState({ model: model2 }); this.setState({ model: model2 });
}} }}
value={this.state.model.mobile} value={this.state.model.mobile}
placeholder={"请输入手机号"} placeholder={'请输入手机号'}
labelWidth={"0px"} labelWidth={'0px'}
maxLength={11} maxLength={11}
height={"36px"} height={'36px'}
width={"520px"} width={'520px'}
alignment={"left"} alignment={'left'}
/> />
</FormItem> </FormItem>
<FormItem labelname='密码' prop='pwd' id='pwd'> <FormItem labelname='密码' id='pwd' required=''>
<Ipt <Ipt
onChange={(e) => { onChange={(e) => {
let model2 = this.state.model; let model2 = this.state.model;
@ -532,20 +504,20 @@ export default class addUserinfo extends React.Component {
disabled={this.state.disabled} disabled={this.state.disabled}
onClearItem={(e) => { onClearItem={(e) => {
let model2 = this.state.model; let model2 = this.state.model;
model2.password = ""; model2.password = '';
this.setState({ model: model2 }); this.setState({ model: model2 });
}} }}
value={this.state.model.password} value={this.state.model.password}
placeholder={"请输入密码"} placeholder={'请输入密码'}
labelWidth={"0px"} labelWidth={'0px'}
maxLength={16} maxLength={16}
height={"36px"} height={'36px'}
width={"520px"} width={'520px'}
alignment={"left"} alignment={'left'}
/> />
</FormItem> </FormItem>
<FormItem labelname='真实姓名' prop='name'> <FormItem labelname='真实姓名' required=''>
<Ipt <Ipt
onChange={(e) => { onChange={(e) => {
let model2 = this.state.model; let model2 = this.state.model;
@ -554,38 +526,38 @@ export default class addUserinfo extends React.Component {
}} }}
onClearItem={(e) => { onClearItem={(e) => {
let model2 = this.state.model; let model2 = this.state.model;
model2.real_name = ""; model2.real_name = '';
this.setState({ model: model2 }); this.setState({ model: model2 });
}} }}
value={this.state.model.real_name} value={this.state.model.real_name}
placeholder={"请输入真实姓名"} placeholder={'请输入真实姓名'}
labelWidth={"0px"} labelWidth={'0px'}
maxLength={16} maxLength={16}
height={"36px"} height={'36px'}
width={"520px"} width={'520px'}
alignment={"left"} alignment={'left'}
/> />
</FormItem> </FormItem>
<FormItem <FormItem
id='company' id='company'
labelname='岗位' labelname='岗位'
prop='company' myClassName='sel1'
myClassName='sel1'> required=''>
<Select <Select
options={this.state.companyList} options={this.state.companyList}
placeholder='请选择公司' placeholder='请选择公司'
value={this.state.model.company} value={this.state.model.company}
onChange={(e) => { onChange={(e) => {
this.onCompanyChange(e); this.onCompanyChange(e);
Bus.emit("change", "company", e); Bus.emit('change', 'company', e);
}} }}
/> />
</FormItem> </FormItem>
<FormItem <FormItem
id='deparment' id='deparment'
prop='deparment'
myClassName='sel2' myClassName='sel2'
labelwidth='0px'> labelwidth='0px'
required=''>
<Select <Select
options={this.state.departmentList} options={this.state.departmentList}
placeholder='请选择部门' placeholder='请选择部门'
@ -593,15 +565,11 @@ export default class addUserinfo extends React.Component {
value={this.state.model.deparment} value={this.state.model.deparment}
onChange={(e) => { onChange={(e) => {
this.onDepartmentChange(e); this.onDepartmentChange(e);
Bus.emit("change", "deparment", e); Bus.emit('change', 'deparment', e);
}} }}
/> />
</FormItem> </FormItem>
<FormItem <FormItem id='post' myClassName='sel2 sel3' labelwidth='0px'>
id='post'
prop='post'
myClassName='sel2 sel3'
labelwidth='0px'>
<Select <Select
options={this.state.departmentJob} options={this.state.departmentJob}
placeholder='请选择岗位' placeholder='请选择岗位'
@ -609,11 +577,12 @@ export default class addUserinfo extends React.Component {
value={this.state.model.post} value={this.state.model.post}
onChange={(e) => { onChange={(e) => {
this.onPostChange(e); this.onPostChange(e);
Bus.emit("change", "post", e); Bus.emit('change', 'post', e);
}} }}
/> />
</FormItem> </FormItem>
<FormItem <FormItem
required=''
labelname='设置权限' labelname='设置权限'
myClassName='rolechoose' myClassName='rolechoose'
id='station'> id='station'>
@ -627,7 +596,7 @@ export default class addUserinfo extends React.Component {
<div className='mypic'> <div className='mypic'>
<b>头像</b> <b>头像</b>
<div className='changepic dflexac'> <div className='changepic dflexac'>
{this.state.defaultFileList[0].src == "" ? ( {this.state.defaultFileList[0].src == '' ? (
<ImageUpload <ImageUpload
className='zent-image-upload-demo' className='zent-image-upload-demo'
maxSize={500 * 1024} maxSize={500 * 1024}