/** * Created by zhouy on 2018/10/18. */ Ext.define('saas.view.sys.account.AddWindow', { extend: 'saas.view.document.kind.ChildForm', xtype: 'sys-account-addwindow', dataKind:'accountadd',//类型标识 height: 325, belong:{ columns:[{ dataIndex:'realname', },{ dataIndex: 'mobile', },{ dataIndex: 'email', }], reqUrl: '/api/account/account/register/add', }, etc:{ accountadd:{ items:[{ xtype: 'fieldcontainer', layout: 'column', items: [{ beforeLabelTextTpl: "*", xtype:'textfield', fieldLabel: '手机号码', name: 'mobile', hideTrigger:true, allowBlank:false, maxLength: 30, columnWidth:0.7, regex:/^1(3|4|5|7|8|9)\d{9}$/, regexText:'请输入正确的手机号码', listeners:{ change:function(f,a,b){ if(a==''){ f._lastCheckValue = '' } }, blur:function(f,a,b,c){ var form = f.ownerCt; if(f.value&&f.value!=''&&f.isValid()&&f._lastCheckValue!=f.value){ f._lastCheckValue = f.value; form.setLoading(true); Ext.Ajax.request({ url: '/api/account/account/checkMobile?mobile='+f.value, method: 'GET', headers:{ 'Access-Control-Allow-Origin': '*', "Content-Type": 'application/json;charset=UTF-8', }, success: function (response) { form.setLoading(false); var localJson = Ext.decode(response.responseText); if(localJson.success){ f.hasRegister = localJson.data.hasRegister; if(localJson.data.hasRegister){ f.ownerCt.down('[name=hasAccount]').show(); f.ownerCt.down('[name=noAccount]').hide(); }else{ f.ownerCt.down('[name=hasAccount]').hide(); f.ownerCt.down('[name=noAccount]').show(); } }else{ saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message); f.setValue(''); f.ownerCt.down('[name=hasAccount]').hide(); f.ownerCt.down('[name=noAccount]').hide(); } }, failure: function (response) { if(response.responseText){ var localJson = Ext.decode(response.responseText); saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message); f.setValue(''); }else{ saas.util.BaseUtil.showErrorToast('手机号校验接口连接超时'); f.setValue(''); } } }); } } } },{ hidden:true, name:'hasAccount', xtype:'button', cls:'x-btn-showicon', style:'background:#fff;border:none;padding:7px 0 7px 0;', text:'已注册优软云', icon:'resources/images/default/toast_over.png', columnWidth:0.3, },{ name:'noAccount', hidden:true, xtype:'button', cls:'x-btn-showicon', style:'background:#fff;border:none;padding:7px 0 7px 0;', text:'未注册优软云', icon:'resources/images/default/toast_close.png', columnWidth:0.3, }] },{ xtype:'textfield', fieldLabel: '真实姓名', name: 'realname', // regex:/^[\u4e00-\u9fa5]+$/, // regexText:'请输入汉字', allowBlank:false, maxLength: 30, columnWidth:0.5 },{ xtype:'textfield', fieldLabel: '邮箱', name: 'email', allowBlank:true, beforeLabelTextTpl: "", regex:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, regexText:'请输入正确的邮箱', maxLength: 30, listeners:{ blur:function(f,a,b,c){ var form = f.ownerCt; if(f.value&&f.value!=''&&f.isValid()&&f._lastCheckValue!=f.value){ form.setLoading(true); Ext.Ajax.request({ url: '/api/account/account/checkEmail?email='+f.value, method: 'GET', headers:{ 'Access-Control-Allow-Origin': '*', "Content-Type": 'application/json;charset=UTF-8' }, success: function (response) { form.setLoading(false); var localJson = Ext.decode(response.responseText); if(localJson.success){ if(!localJson.data){ f._lastCheckValue = f.value; saas.util.BaseUtil.showSuccessToast('校验成功:邮箱未注册'); }else{ saas.util.BaseUtil.showErrorToast('校验失败:该邮箱已被注册'); f.setValue(''); } }else{ saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message); } }, failure: function (response) { if(response.responseText){ var localJson = Ext.decode(response.responseText); saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message); }else{ saas.util.BaseUtil.showErrorToast('邮箱校验接口连接超时'); } } }); } } } },{ xtype:'datamulticombo', dataUrl:'/api/account/role/list', fieldLabel: '岗位角色', name: 'roleIds', allowBlank:false, },{ margin:'5 0 0 0', xtype:'displayfield', fieldLabel: '注意事项', beforeLabelTextTpl: "", value:'添加的账户拥有访问系统的权限,请勿随意添加', fieldStyle:'color:#999;margin-top: 9px;', lableStyle:'color: #f16161;' }] } }, onSave:function(){ var me = this; var belong = this.belong; me.setLoading(true); var form=this.down('form'); var params = {}; var names = belong.columns.map(column => column.dataIndex); Ext.Array.each(names,function(name) { if(name){ var dataField = form.down('[name='+name+']'); if(dataField&&dataField.value){ params[name] = dataField.value; } if(dataField.name=='mobile'){ params['hasRegister'] = dataField.hasRegister; } } }); //更改参数 var o = ''; var dataField = form.down('[name=roleIds]'); Ext.Array.each(dataField.value,function(item) { o+=item+',' }); o = o.substring(0,o.length-1); params['username'] = params['mobile']; params['type'] = 1; params['roleIds'] = o; //保存接口 saas.util.BaseUtil.request({ url: belong.reqUrl, params: JSON.stringify(params), method: 'POST' }) .then(function(localJson) { me.setLoading(false); if(localJson.success){ form.ownerCt._parent.store.load(); saas.util.BaseUtil.showSuccessToast('保存成功'); form.ownerCt.close(); } }) .catch(function(e) { me.setLoading(false); saas.util.BaseUtil.showErrorToast('保存失败: ' + e.message); }); } });