AddWindow.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. * Created by zhouy on 2018/10/18.
  3. */
  4. Ext.define('saas.view.sys.account.AddWindow', {
  5. extend: 'saas.view.document.kind.ChildForm',
  6. xtype: 'sys-account-addwindow',
  7. dataKind:'accountadd',//类型标识
  8. height: 325,
  9. belong:{
  10. columns:[{
  11. dataIndex:'realname',
  12. },{
  13. dataIndex: 'mobile',
  14. },{
  15. dataIndex: 'email',
  16. }],
  17. reqUrl: '/api/account/account/register/add',
  18. },
  19. etc:{
  20. accountadd:{
  21. items:[{
  22. xtype: 'fieldcontainer',
  23. layout: 'column',
  24. items: [{
  25. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>",
  26. xtype:'textfield',
  27. fieldLabel: '手机号码',
  28. name: 'mobile',
  29. hideTrigger:true,
  30. allowBlank:false,
  31. maxLength: 30,
  32. columnWidth:0.7,
  33. regex:/^1(3|4|5|7|8|9)\d{9}$/,
  34. regexText:'请输入正确的手机号码',
  35. listeners:{
  36. change:function(f,a,b){
  37. if(a==''){
  38. f._lastCheckValue = ''
  39. }
  40. },
  41. blur:function(f,a,b,c){
  42. var form = f.ownerCt;
  43. if(f.value&&f.value!=''&&f.isValid()&&f._lastCheckValue!=f.value){
  44. f._lastCheckValue = f.value;
  45. form.setLoading(true);
  46. Ext.Ajax.request({
  47. url: '/api/account/account/checkMobile?mobile='+f.value,
  48. method: 'GET',
  49. headers:{
  50. 'Access-Control-Allow-Origin': '*',
  51. "Content-Type": 'application/json;charset=UTF-8',
  52. },
  53. success: function (response) {
  54. form.setLoading(false);
  55. var localJson = Ext.decode(response.responseText);
  56. if(localJson.success){
  57. f.hasRegister = localJson.data.hasRegister;
  58. if(localJson.data.hasRegister){
  59. f.ownerCt.down('[name=hasAccount]').show();
  60. f.ownerCt.down('[name=noAccount]').hide();
  61. }else{
  62. f.ownerCt.down('[name=hasAccount]').hide();
  63. f.ownerCt.down('[name=noAccount]').show();
  64. }
  65. }else{
  66. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  67. f.setValue('');
  68. f.ownerCt.down('[name=hasAccount]').hide();
  69. f.ownerCt.down('[name=noAccount]').hide();
  70. }
  71. },
  72. failure: function (response) {
  73. if(response.responseText){
  74. var localJson = Ext.decode(response.responseText);
  75. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  76. f.setValue('');
  77. }else{
  78. saas.util.BaseUtil.showErrorToast('手机号校验接口连接超时');
  79. f.setValue('');
  80. }
  81. }
  82. });
  83. }
  84. }
  85. }
  86. },{
  87. hidden:true,
  88. name:'hasAccount',
  89. xtype:'button',
  90. cls:'x-btn-showicon',
  91. style:'background:#fff;border:none;padding:7px 0 7px 0;',
  92. text:'已注册优软云',
  93. icon:'resources/images/default/toast_over.png',
  94. columnWidth:0.3,
  95. },{
  96. name:'noAccount',
  97. hidden:true,
  98. xtype:'button',
  99. cls:'x-btn-showicon',
  100. style:'background:#fff;border:none;padding:7px 0 7px 0;',
  101. text:'未注册优软云',
  102. icon:'resources/images/default/toast_close.png',
  103. columnWidth:0.3,
  104. }]
  105. },{
  106. xtype:'textfield',
  107. fieldLabel: '真实姓名',
  108. name: 'realname',
  109. // regex:/^[\u4e00-\u9fa5]+$/,
  110. // regexText:'请输入汉字',
  111. allowBlank:false,
  112. maxLength: 30,
  113. columnWidth:0.5
  114. },{
  115. xtype:'textfield',
  116. fieldLabel: '邮箱',
  117. name: 'email',
  118. allowBlank:true,
  119. beforeLabelTextTpl: "",
  120. regex:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
  121. regexText:'请输入正确的邮箱',
  122. maxLength: 30,
  123. listeners:{
  124. blur:function(f,a,b,c){
  125. var form = f.ownerCt;
  126. if(f.value&&f.value!=''&&f.isValid()&&f._lastCheckValue!=f.value){
  127. form.setLoading(true);
  128. Ext.Ajax.request({
  129. url: '/api/account/account/checkEmail?email='+f.value,
  130. method: 'GET',
  131. headers:{
  132. 'Access-Control-Allow-Origin': '*',
  133. "Content-Type": 'application/json;charset=UTF-8'
  134. },
  135. success: function (response) {
  136. form.setLoading(false);
  137. var localJson = Ext.decode(response.responseText);
  138. if(localJson.success){
  139. if(!localJson.data){
  140. f._lastCheckValue = f.value;
  141. saas.util.BaseUtil.showSuccessToast('校验成功:邮箱未注册');
  142. }else{
  143. saas.util.BaseUtil.showErrorToast('校验失败:该邮箱已被注册');
  144. f.setValue('');
  145. }
  146. }else{
  147. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  148. }
  149. },
  150. failure: function (response) {
  151. if(response.responseText){
  152. var localJson = Ext.decode(response.responseText);
  153. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  154. }else{
  155. saas.util.BaseUtil.showErrorToast('邮箱校验接口连接超时');
  156. }
  157. }
  158. });
  159. }
  160. }
  161. }
  162. },{
  163. xtype:'datamulticombo',
  164. dataUrl:'/api/account/role/list',
  165. fieldLabel: '岗位角色',
  166. name: 'roleIds',
  167. allowBlank:false,
  168. },{
  169. margin:'5 0 0 0',
  170. xtype:'displayfield',
  171. fieldLabel: '注意事项',
  172. beforeLabelTextTpl: "",
  173. value:'添加的账户拥有访问系统的权限,请勿随意添加',
  174. fieldStyle:'color:#999;margin-top: 9px;',
  175. lableStyle:'color: #f16161;'
  176. }]
  177. }
  178. },
  179. onSave:function(){
  180. var me = this;
  181. var belong = this.belong;
  182. me.setLoading(true);
  183. var form=this.down('form');
  184. var params = {};
  185. var names = belong.columns.map(column => column.dataIndex);
  186. Ext.Array.each(names,function(name) {
  187. if(name){
  188. var dataField = form.down('[name='+name+']');
  189. if(dataField&&dataField.value){
  190. params[name] = dataField.value;
  191. }
  192. if(dataField.name=='mobile'){
  193. params['hasRegister'] = dataField.hasRegister;
  194. }
  195. }
  196. });
  197. //更改参数
  198. var o = '';
  199. var dataField = form.down('[name=roleIds]');
  200. Ext.Array.each(dataField.value,function(item) {
  201. o+=item+','
  202. });
  203. o = o.substring(0,o.length-1);
  204. params['username'] = params['mobile'];
  205. params['type'] = 1;
  206. params['roleIds'] = o;
  207. //保存接口
  208. saas.util.BaseUtil.request({
  209. url: belong.reqUrl,
  210. params: JSON.stringify(params),
  211. method: 'POST'
  212. })
  213. .then(function(localJson) {
  214. me.setLoading(false);
  215. if(localJson.success){
  216. form.ownerCt._parent.store.load();
  217. saas.util.BaseUtil.showSuccessToast('保存成功');
  218. form.ownerCt.close();
  219. }
  220. })
  221. .catch(function(e) {
  222. me.setLoading(false);
  223. saas.util.BaseUtil.showErrorToast('保存失败: ' + e.message);
  224. });
  225. }
  226. });