diff --git a/src/pages/system/subAccount/add/adduserinfo/adduserinfo.js b/src/pages/system/subAccount/add/adduserinfo/adduserinfo.js index d66c879d..b41d1889 100644 --- a/src/pages/system/subAccount/add/adduserinfo/adduserinfo.js +++ b/src/pages/system/subAccount/add/adduserinfo/adduserinfo.js @@ -1,13 +1,13 @@ -import React from "react"; -import "./adduserinfo.less"; -import Ipt from "@/components/input/main"; -import Form from "@/components/form/main"; -import FormItem from "@/components/form-item/main"; -import "@/assets/comm.css"; -import Tree from "./tree"; -import { Select, Button, ImageUpload, Sweetalert, Notify, Card } from "zent"; -import Bus from "@/assets/eventBus.js"; -import cloneDeep from "lodash/cloneDeep"; +import React from 'react'; +import './adduserinfo.less'; +import Ipt from '@/components/input/main'; +import Form from '@/components/form/main'; +import FormItem from '@/components/form-item/main'; +import '@/assets/comm.css'; +import Tree from './tree'; +import { Select, Button, ImageUpload, Sweetalert, Notify, Card } from 'zent'; +import Bus from '@/assets/eventBus.js'; +import cloneDeep from 'lodash/cloneDeep'; import { handelResponse, uploadImg, @@ -17,7 +17,7 @@ import { getRole, postAddSubAcc, getDepartmentJob -} from "@/assets/api.js"; +} from '@/assets/api.js'; export default class addUserinfo extends React.Component { constructor(props) { super(props); @@ -25,23 +25,23 @@ export default class addUserinfo extends React.Component { this.state = { model: { //数据模型不可少 - user_name: "", - mobile: "", - password: "", - real_name: "", - company: "", - deparment: "", - post: "" + user_name: '', + mobile: '', + password: '', + real_name: '', + company: '', + deparment: '', + post: '' }, companyList: [], //公司 departmentList: [], //部门 departmentJob: [], //岗位 roleList: [], //角色 - headImg: "", - pwdtype: "text", - defaultFileList: [{ src: "" }], + headImg: '', + pwdtype: 'text', + defaultFileList: [{ src: '' }], disabled: false, - id: "", + id: '', ruleId: [] }; } @@ -50,7 +50,7 @@ export default class addUserinfo extends React.Component { componentWillMount() { let _self = this; this.getCompanyFn(); //获取公司 - let companys = JSON.parse(sessionStorage.getItem("company")); + let companys = JSON.parse(sessionStorage.getItem('company')); if (!companys) { this.getCompanyFn(); //获取公司 } @@ -58,12 +58,12 @@ export default class addUserinfo extends React.Component { this.getRoleFn(); //获取角色 let formInfo = this.props; if (formInfo && formInfo.enumer == 1) { - this.setState({ pwdtype: "password" }); + this.setState({ pwdtype: 'password' }); let acceptData = cloneDeep(formInfo.rowData); let data = { user_name: acceptData.user_name, mobile: acceptData.mobile, - password: "yxtx2021", + password: 'yxtx2021', real_name: acceptData.real_name, company: companys.find((o) => o.key == acceptData.company_id), deparment: { @@ -124,7 +124,7 @@ export default class addUserinfo extends React.Component { } } changeKind() { - this.setState({ pwdtype: "password" }); + this.setState({ pwdtype: 'password' }); } submit() { let valiform = this.refs.form1.validator(); @@ -132,111 +132,102 @@ export default class addUserinfo extends React.Component { let iptVal = this.state.model; let _this = this; if (valiform) { - if (!roleArr || roleArr.length < 1) { - Notify.clear(); - Notify.error("请设置子账号权限"); - } else { - //取消二次弹出框 - Sweetalert.confirm({ - type: "warning", - closeBtn: true, - title: "确认操作", - content: - _this.props.enumer == 0 ? ( -
- 是否新增[{iptVal.user_name}]账号? -
- ) : ( -- 是否修改[{iptVal.user_name}]账号信息? -
- ), - onConfirm: () => { - //提交接口 - let data = { - user_name: iptVal.user_name, - password: iptVal.password, - job_id: iptVal.post.key, - real_name: iptVal.real_name, - mobile: iptVal.mobile, - assist_user_id: sessionStorage.getItem("subaid"), - rule: roleArr - }; - if (_this.state.headImg) { - data.head = _this.state.headImg; - } + //取消二次弹出框 + Sweetalert.confirm({ + type: 'warning', + closeBtn: true, + title: '确认操作', + content: + _this.props.enumer == 0 ? ( ++ 是否新增[{iptVal.user_name}]账号? +
+ ) : ( ++ 是否修改[{iptVal.user_name}]账号信息? +
+ ), + onConfirm: () => { + //提交接口 + let data = { + user_name: iptVal.user_name, + password: iptVal.password, + job_id: iptVal.post.key, + real_name: iptVal.real_name, + mobile: iptVal.mobile, + assist_user_id: sessionStorage.getItem('subaid'), + rule: roleArr + }; + if (_this.state.headImg) { + data.head = _this.state.headImg; + } - if (_this.props.enumer == 0) { - postAddSubAcc(data) - .then((res) => { - handelResponse( - res, - (response, msg) => { - Notify.clear(); - Notify.success(msg); - setTimeout(() => { - // window.history.back() - window.location.replace( - "#/home/system/subaccount-list" - ); - sessionStorage.setItem( - "pathname2", - "/home/system/subaccount-list" - ); - }, 1000); - }, - (err) => { - Notify.error(err); - } - ); - }) - .catch((err) => {}); - } else { - //编辑 - let id = _this.state.id; - delete data.password; - data.head = _this.state.headImg; - putAddSubAcc(id, data) - .then((res) => { - handelResponse( - res, - (response, msg) => { - Notify.clear(); - Notify.success(msg); - setTimeout(() => { - // window.history.back() - window.location.replace( - "#/home/system/subaccount-list" - ); - sessionStorage.setItem( - "pathname2", - "/home/system/subaccount-list" - ); - }, 1000); - }, - (err) => { - Notify.error(err); - } - ); - }) - .catch((err) => {}); - } - }, - onCancel: this.onCancel, - className: "questModal", - parentComponent: this - }); - } + if (_this.props.enumer == 0) { + postAddSubAcc(data) + .then((res) => { + handelResponse( + res, + (response, msg) => { + Notify.clear(); + Notify.success(msg); + setTimeout(() => { + // window.history.back() + window.location.replace('#/home/system/subaccount-list'); + sessionStorage.setItem( + 'pathname2', + '/home/system/subaccount-list' + ); + }, 1000); + }, + (err) => { + Notify.error(err); + } + ); + }) + .catch((err) => {}); + } else { + //编辑 + let id = _this.state.id; + delete data.password; + data.head = _this.state.headImg; + putAddSubAcc(id, data) + .then((res) => { + handelResponse( + res, + (response, msg) => { + Notify.clear(); + Notify.success(msg); + setTimeout(() => { + // window.history.back() + window.location.replace('#/home/system/subaccount-list'); + sessionStorage.setItem( + 'pathname2', + '/home/system/subaccount-list' + ); + }, 1000); + }, + (err) => { + Notify.error(err); + } + ); + }) + .catch((err) => {}); + } + }, + onCancel: this.onCancel, + className: 'questModal', + parentComponent: this + }); } else { Notify.clear(); - Notify.error("请完善表单数据"); + Notify.error('请完善表单数据'); } } onUploadError = (type, data) => { - if (type === "overMaxAmount") { + if (type === 'overMaxAmount') { Notify.clear(); Notify.error(`最多可上传 ${data.maxAmount} 张图片`); - } else if (type === "overMaxSize") { + } else if (type === 'overMaxSize') { Notify.clear(); Notify.error(`图片大小不能超过 ${data.formattedMaxSize}b`); } @@ -247,8 +238,8 @@ export default class addUserinfo extends React.Component { let _self = this; if (files && files.length > 0) { let formdata = new FormData(); - formdata.append("file", files[0].file); - formdata.append("path", "account_avatar"); + formdata.append('file', files[0].file); + formdata.append('path', 'account_avatar'); uploadImg(formdata) .then((res) => { handelResponse( @@ -265,15 +256,15 @@ export default class addUserinfo extends React.Component { }) .catch((err) => {}); } else { - _self.setState({ headImg: "" }); + _self.setState({ headImg: '' }); } } onCompanyChange(e) { if (!e) { let _self = this; let model2 = this.state.model; - model2.deparment = ""; - model2.post = ""; + model2.deparment = ''; + model2.post = ''; this.setState({ model: model2 }); @@ -287,8 +278,8 @@ export default class addUserinfo extends React.Component { //调部门的数据 if (e) { let model3 = this.state.model; - model3.deparment = ""; - model3.post = ""; + model3.deparment = ''; + model3.post = ''; _self.setState({ departmentList: [] }); _self.setState({ departmentJob: [] }); _self.setState({ model: model3 }); @@ -300,7 +291,7 @@ export default class addUserinfo extends React.Component { (response, msg) => { let departmentList = response.map((item) => { return { key: item.id, text: item.department_name }; - _self.setState({ deparment: "" }); + _self.setState({ deparment: '' }); }); _self.setState({ departmentList }); }, @@ -319,7 +310,7 @@ export default class addUserinfo extends React.Component { if (!e) { let _self = this; let model2 = this.state.model; - model2.post = ""; + model2.post = ''; this.setState({ model: model2 }); @@ -343,7 +334,7 @@ export default class addUserinfo extends React.Component { }); _self.setState({ departmentJob }); let model3 = this.state.model; - model3.post = ""; + model3.post = ''; _self.setState({ model: model3 }); }, (err) => { @@ -375,7 +366,7 @@ export default class addUserinfo extends React.Component { let companyList = response.map((item) => { return { key: item.id, text: item.company_name }; }); - sessionStorage.setItem("company", JSON.stringify(companyList)); + sessionStorage.setItem('company', JSON.stringify(companyList)); _self.setState({ companyList }); }, (err) => { @@ -411,17 +402,17 @@ export default class addUserinfo extends React.Component { cancel() { //取消二次弹出框 Sweetalert.confirm({ - type: "warning", + type: 'warning', closeBtn: true, - title: "确认操作", + title: '确认操作', content:是否取消本次操作?
, onConfirm: () => { // window.history.back() - window.location.replace("#/home/system/subaccount-list"); - sessionStorage.setItem("pathname2", "/home/system/subaccount-list"); + window.location.replace('#/home/system/subaccount-list'); + sessionStorage.setItem('pathname2', '/home/system/subaccount-list'); }, onCancel: this.onCancel, - className: "questModal", + className: 'questModal', parentComponent: this }); } @@ -435,38 +426,19 @@ export default class addUserinfo extends React.Component { render() { //校验规则 const rules = { - account: [{ type: "required", message: "请输入手机号" }], + account: [{ type: 'required', message: '请输入手机号' }], phone: [ - { type: "required", message: "请输入手机号" }, + { type: 'required', message: '请输入手机号' }, { - type: "regExp", - message: "手机号格式不正确", - reg: "^[1][3,4,5,6,7,8,9][0-9]{9}$" + type: 'regExp', + message: '手机号格式不正确', + 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 (