diff --git a/src/pages/distributor/adddistributorinfo/adddistributorinfo.js b/src/pages/distributor/adddistributorinfo/adddistributorinfo.js index 25a1c220..3c35b06f 100644 --- a/src/pages/distributor/adddistributorinfo/adddistributorinfo.js +++ b/src/pages/distributor/adddistributorinfo/adddistributorinfo.js @@ -1,707 +1,739 @@ -import ReactDOM from 'react-dom'; -import React from "react" -import "./adddistributorinfo.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 {Select,Dialog,Button,ImageUpload ,onUpload,FormInputField,Notify,CopyButton } from "zent" -import Bus from "../../../assets/eventBus.js" -import _ from "lodash"; -import {getExistName,getCompany,uploadImg,getPersonnel,handelResponse,getExistAccount} from "../../../assets/api.js" -export default class adduserinfo extends React.Component{ - - constructor(props){ - super(props) - this.state={ - phone_nums:1, - id:'', - headImg:'',//上传文件的path - uploadimgFile:'',//分销商头像files - email_nums:1, - disabled:false, - defaultFileList:[{src:'',}],//默认回显头像,//默认回显头像 - model:{ //数据模型不可少 - name:'', - account:'', - password:'', - contact_name:'', - contact_phone:'', - contact_email:'', - salesman_id:'', - company_id:'', - identity_type:'', - phone1:'', - phone2:'', - phone3:'', - phone4:'', - email1:"", - email2:"", - email3:"", - email4:"", - }, - rules:{ - fullname: [ - { type: "required", message: "请输入分销商名称"}, - ], - account: [ - { type: "required", message: "请输入登录账号"}, - ], - pwd:[ - { type: "required", message: "请输入密码"}, - { type: "regExp", message: "6-16位字符,数字+字母组成,(字母区分大小写)",reg:"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$"} - ], - contacts: [ - { type: "required", message: "请输入联系人"}, - { type: "regExp", message: "2-16字汉字/字母组成",reg:"^([\u4e00-\u9fa5]|[a-zA-Z]){2,16}$"} - ], - contacts_phone:[ - { type: "required", message: "请输入联系人手机号"}, - { type: "regExp", message: "手机号格式不对",reg:"^[1][3,5,7,8][0-9]\\d{8}$"} - ], - contacts_email:[ - { type: "required", message: "请输入联系人邮箱"}, - { type: "regExp", message: "联系人邮箱格式不对",reg:"^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$"} - ], - sale: [ - { type: "required", message: "请选择销售人员"}, - - ], - identity: [ - { type: "required", message: "请选择身份类型"}, - - ], - sign:[ - { type: "required", message: "请选择签约公司"}, - ] - - - }, - companyList:[], - personnelList:[], - fieldArr:[],//添加项目 - fieldTitle:'', - addfield:{},//添加 - identityType:[{ - key:1, - text:'直客' - }, - { - key:2, - text:'友商' - }] //身份类型 - } - } - - componentDidMount(e){ - - - } - - submit(){ - return this.refs.form1.validator() - } - - //选择图片 - onUploadChange(files){ - let _self=this; - if(files&&files.length>0){ - let formdata= new FormData(); - formdata.append("file",files[0].file) - formdata.append("path","reseller_avatar") - uploadImg(formdata).then((res)=>{ - handelResponse(res,(req,msg)=>{ - _self.setState({headImg:req.path}) - Notify.clear(); - Notify.success(msg); - },(err)=>{ - - }) - }).catch(err=>{ - }); - }else{ - _self.setState({headImg:''}) - } - }; - - //选择销售人员 - onsaleChange(e){ - let model2 = this.state.model - model2.salesman_id = e; - this.setState({ - model:model2 - }); - } - //身份类型 - onidentityChange(e){ - let model2 = this.state.model - model2.identity_type = e; - this.setState({ - model:model2 - }); - } - //签约公司 - onsignChange(e) - { - let model2 = this.state.model - model2.company_id = e; - this.setState({ - model:model2 - }); - } - //校验分销商名称 - NameblurFn(e){ - getExistName(e).then(res=>{ - handelResponse(res,(response,msg)=>{ - Notify.clear(); - Notify.success(msg); - },err=>{ - Notify.clear(); - Notify.error(res.data.message); - return false; - }); - }).catch(err=>{ - - }); - } - //校验登陆账号名称 - AccountblurFn(e){ - getExistAccount(e).then(res=>{ - handelResponse(res,(response,msg)=>{ - Notify.clear(); - Notify.success(msg); - },err=>{ - Notify.clear(); - Notify.error(res.data.message); - return false; - }); - }).catch(err=>{ - - }); -} - cancel(){ - let model2 = {} - this.setState({model:model2}); - this.refs.form1.cancel(); - } - componentWillMount(){ - this.getPersonnelFn(); - this.getCompanyFn(); - let formInfo=JSON.parse(sessionStorage.getItem('dataInfo')); - if(this.props.enumer==1){ - let reselData=_.cloneDeep(formInfo);//表单的信息 - let data={ - "name":reselData.name, - "password": 'yxxt2021', - "account": reselData.account, - "contact_name": reselData.contact_name, - "company_id":{key:reselData.company_id,text:reselData.company_name}, - "identity_type":{key:reselData.identity_type,text:reselData.identity_type_text}, - "salesman_id":{key:reselData.salesman_id,text:reselData.salesman_name}, - } - let phoneTo=reselData.contact_phone; - for(let i=0;i0){ - let phoneName='phone'+i; - data[phoneName]=phoneTo[i]; - } - } - //邮箱回显 - let emailTo=reselData.contact_email; - for(let i=0;i0){ - let emailName='email'+i; - data[emailName]=emailTo[i]; - } - } - let img={} - img.src=reselData.head_img; - this.setState({id:reselData.id,phone_nums:phoneTo.length,email_nums:emailTo.length,model:data,disabled:true,defaultFileList:[img],id:reselData.id,headImg:reselData.head_img}); - } - } - //销售人员 - getPersonnelFn(){ - let _self=this; - getPersonnel().then(res=>{ - handelResponse(res,(response,msg)=>{ - let personnelList=response.map(item=>{ - return {key:item.id,text:item.real_name} - }); - - _self.setState({personnelList}); - },(err)=>{ - - }) - }).catch(err=>{ - }); -} - - //签约公司 - getCompanyFn(){ - let _self=this; - getCompany().then(res=>{ - handelResponse(res,(response,msg)=>{ - let companyList=response.map(item=>{ - return {key:item.id,text:item.company_name} - }); - _self.setState({companyList}); - },(err)=>{ - - }) - }).catch(err=>{ - }); - } - //添加号码 - addfieldArr(){ - let num = this.state.phone_nums + 1; - this.setState({phone_nums:num}) - if(this.state.phone_nums>5){ - Notify.clear(); - Notify.error('添加的手机号码数量已经达到上限!'); - num=5; - this.setState({phone_nums:num}) - }else{ - let contacts_email=[ - { type: "required", message: "请输入联系人手机号码"}, - { type: "regExp", message: "手机号格式不对",reg:"^[1][3,5,7,8][0-9]\\d{8}$"} - ] - let obj = {} - - let rules = this.state.rules; - rules["phone"+ this.state.phone_nums] = contacts_email; - this.setState({rules:rules}); - } - - } - //添加邮箱 - addEmailArr(){ - let emilnum = this.state.email_nums + 1; - - - if(this.state.email_nums>5){ - Notify.clear(); - Notify.error('添加的联系人邮箱数量已经达到上限!'); - emilnum=5; - }else{ - let contacts_phone=[ - { type: "required", message: "请输入联系人邮箱"}, - { type: "regExp", message: "联系人邮箱格式不对",reg:"^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$"} - ] - let obj = {} - - let rules = this.state.rules; - rules["email"+ this.state.email_nums] = contacts_phone; - this.setState({rules:rules}); - } - this.setState({email_nums:emilnum}) - console.log(this.state); - } - render(){ - const companyOptions =this.state.companyList; - //校验规则 - - - //销售人员 - - return( -
-
- - { - let model2 = this.state.model; - model2.name = e; - this.setState({model:model2}) - }} - - onClearItem={(e)=>{ - let model2 = this.state.model; - model2.name = ""; - this.setState({model:model2}) - }} - onblurFn={(e)=>{this.NameblurFn(e)}} - countShow= {false} - value={this.state.model.name} placeholder={"请输入分销商全称"} labelWidth={'0px'} maxLength={32} height={'36px'} width={'520px'} alignment={'left'}/> - - - -
- { - let model2 = this.state.model; - model2.account = e; - this.setState({model:model2}) - }} - disabled={this.state.disabled} - onblurFn={(e)=>{this.AccountblurFn(e)}} - onClearItem={(e)=>{ - let model2 = this.state.model; - model2.account = ""; - this.setState({model:model2}) - }} - countShow= {false} - value={this.state.model.account} placeholder={"请输入登录账号"} labelWidth={'0px'} maxLength={32} height={'36px'} width={'520px'} alignment={'left'}/> - {Notify.clear();Notify.success('复制成功!');}}> - - -
-
- - - - { - - let model2 = this.state.model; - model2.password = e; - this.setState({model:model2}) - }} - disabled={this.state.disabled} - countShow= {true} - onClearItem={(e)=>{ - let model2 = this.state.model; - model2.password = ''; - this.setState({model:model2}) - }} - value={this.state.model.password} placeholder={"请输入密码"} - labelWidth={'0px'} maxLength={16} height={'36px'} width={'520px'} alignment={'left'}/> - - - { - let model2 = this.state.model; - model2.contact_name = e; - this.setState({model:model2}) - }} - - onClearItem={(e)=>{ - let model2 = this.state.model; - model2.contact_name = ''; - this.setState({model:model2}) - }} - countShow= {true} - value={this.state.model.contact_name} placeholder={"请输入联系人"} labelWidth={'0px'} maxLength={16} height={'36px'} width={'520px'} alignment={'left'}/> - - -
- { - let model2 = this.state.model; - model2.contact_phone = e; - this.setState({model:model2}) - }} - - onClearItem={(e)=>{ - let model2 = this.state.model; - model2.contact_phone = ''; - this.setState({model:model2}) - }} - countShow= {false} - value={this.state.model.contact_phone} placeholder={"请输入联系人手机号"} labelWidth={'0px'} maxLength={11} height={'36px'} width={'520px'} alignment={'left'}/> - -
-
- - { - this.state.phone_nums > 1 ? - ( - - { - let model2 = this.state.model; - model2.phone1 = e; - this.setState({model:model2}) - // Bus.emit('input',"phone1" ,e); - }} - - onClearItem={(e)=>{ - console.log(this.state.phone_nums); - let model2 = this.state.model; - model2.phone1 = ""; - this.setState({model:model2}) - let nums = this.state.phone_nums - 1; - delete this.state.rules.phone1; - this.setState({phone_nums:nums,rules:this.state.rules }) - - - - - }} - countShow= {false} - value={this.state.model.phone1} placeholder={"请输入联系人手机号"} labelWidth={'0px'} maxLength={11} height={'36px'} width={'520px'} alignment={'left'}/> - - ) : null - - - } - { - this.state.phone_nums > 2 ? - ( - - { - console.log(777777) - let model2 = this.state.model; - model2.phone2 = e; - this.setState({model:model2}) - }} - - onClearItem={(e)=>{ - - let model2 = this.state.model; - model2.phone2 = ""; - delete this.state.rules.phone2; - this.setState({model:model2}) - let nums = this.state.phone_nums - 1; - this.setState({phone_nums:nums,rules:this.state.rules }) - - }} - countShow= {false} - value={this.state.model.phone2} placeholder={"请输入联系人手机号"} labelWidth={'0px'} maxLength={11} height={'36px'} width={'520px'} alignment={'left'}/> - - ) : null - - - } - { - this.state.phone_nums > 3 ? - ( - - { - console.log(777777) - let model2 = this.state.model; - model2.phone3 = e; - this.setState({model:model2}) - // Bus.emit('input',"phone3" ,e); - }} - - onClearItem={(e)=>{ - - let model2 = this.state.model; - model2.phone3 = ""; - delete this.state.rules.phone3; - this.setState({model:model2,rules:this.state.rules}) - - let nums = this.state.phone_nums - 1; - this.setState({phone_nums:nums}) - - }} - countShow= {false} - value={this.state.model.phone3} placeholder={"请输入联系人手机号"} labelWidth={'0px'} maxLength={11} height={'36px'} width={'520px'} alignment={'left'}/> - - ) : null - - - } - { - this.state.phone_nums > 4 ? - ( - - { - console.log(777777) - let model2 = this.state.model; - model2.phone4 = e; - this.setState({model:model2}) - // Bus.emit('input',"phone1" ,e); - }} - - onClearItem={(e)=>{ - - let model2 = this.state.model; - model2.phone4 = ""; - delete this.state.rules.phone4; - this.setState({model:model2,rules:this.state.rules}) - let nums = this.state.phone_nums - 1; - - this.setState({phone_nums:nums}) - - }} - countShow= {false} - value={this.state.model.phone4} placeholder={"请输入联系人手机号"} labelWidth={'0px'} maxLength={11} height={'36px'} width={'520px'} alignment={'left'}/> - - ) : null - - - } - - - -
- { - - let model2 = this.state.model; - model2.contact_email = e; - this.setState({model:model2}) - }} - - onClearItem={(e)=>{ - let model2 = this.state.model; - model2.contact_email = ''; - this.setState({model:model2}) - }} - countShow= {false} - value={this.state.model.contact_email} placeholder={"请输入联系人邮箱"} labelWidth={'0px'} maxLength={50} height={'36px'} width={'520px'} alignment={'left'}/> - - - -
-
- { - this.state.email_nums > 1 ? - ( - - { - let model2 = this.state.model; - model2.email1 = e; - this.setState({model:model2}) - // Bus.emit('input',"email1" ,e); - }} - - onClearItem={(e)=>{ - - let model2 = this.state.model; - model2.email1 = ""; - delete this.state.rules.email1; - this.setState({model:model2,rules:this.state.rules}) - let nums = this.state.email_nums - 1; - this.setState({email_nums:nums}) - - }} - countShow= {false} - value={this.state.model.email1} placeholder={"请输入联系人邮箱"} labelWidth={'0px'} maxLength={50} height={'36px'} width={'520px'} alignment={'left'}/> - - ) : null - - - } - { - this.state.email_nums > 2 ? - ( - - { - let model2 = this.state.model; - model2.email2 = e; - this.setState({model:model2}) - // Bus.emit('input',"email2" ,e); - }} - - onClearItem={(e)=>{ - - let model2 = this.state.model; - model2.email2 = ""; - delete this.state.rules.email2; - this.setState({model:model2,rules:this.state.rules}) - let nums = this.state.email_nums - 1; - this.setState({email_nums:nums}) - - }} - - countShow= {false} - value={this.state.model.email2} placeholder={"请输入联系人邮箱"} labelWidth={'0px'} maxLength={50} height={'36px'} width={'520px'} alignment={'left'}/> - - ) : null - - - } - { - this.state.email_nums > 3 ? - ( - - { - let model2 = this.state.model; - model2.email3 = e; - this.setState({model:model2}) - // Bus.emit('input',"email3" ,e); - }} - - onClearItem={(e)=>{ - - let model2 = this.state.model; - model2.email3 = ""; - delete this.state.rules.email3; - this.setState({model:model2,rules:this.state.rules}) - - let nums = this.state.email_nums - 1; - this.setState({phone_nums:nums}) - - }} - - countShow= {false} - value={this.state.model.email3} placeholder={"请输入联系人邮箱"} labelWidth={'0px'} maxLength={50} height={'36px'} width={'520px'} alignment={'left'}/> - - ) : null - - - } - { - this.state.email_nums > 4 ? - ( - - { - let model2 = this.state.model; - model2.email4 = e; - this.setState({model:model2}) - // Bus.emit('input',"email4" ,e); - }} - - onClearItem={(e)=>{ - - let model2 = this.state.model; - model2.email4 = ""; - delete this.state.rules.email4; - this.setState({model:model2,rules:this.state.rules}) - let nums = this.state.email_nums - 1; - this.setState({phone_nums:nums}) - - }} - - countShow= {false} - value={this.state.model.email4} placeholder={"请输入联系人邮箱"} labelWidth={'0px'} maxLength={50} height={'36px'} width={'520px'} alignment={'left'}/> - - ) : null - - - } - - { - this.onidentityChange(e) - Bus.emit('change',"identity" ,e); - }} popupWidth="360px" width="520px"/> - - - { + this.onsaleChange(e) + Bus.emit('change',"sale" ,e); + }} popupWidth="360px" width="520px"/> + + + { + this.onsignChange(e) + Bus.emit('change',"sign" ,e); + }} popupWidth="520px" width="520px"/> + +
+ +
+ 分销商头像 +
+ { + this.state.defaultFileList[0].src.includes('lsxd')?({this.onUploadChange(e)}} + onUpload={this.onUpload} + defaultFileList={this.state.defaultFileList} + />):({this.onUploadChange(e)}} + onUpload={this.onUpload} + />) + } +
+
+
+ ) + } +} +