AddWindow.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. xtype:'textfield',
  26. fieldLabel: '手机号码',
  27. name: 'mobile',
  28. hideTrigger:true,
  29. allowBlank:false,
  30. maxLength: 30,
  31. columnWidth:0.7,
  32. regex:/^1(3|4|5|7|8)\d{9}$/,
  33. regexText:'请输入正确的手机号码',
  34. listeners:{
  35. change:function(f,a,b){
  36. if(a==''){
  37. f._lastCheckValue = ''
  38. }
  39. },
  40. blur:function(f,a,b,c){
  41. var form = f.ownerCt;
  42. if(f.value&&f.value!=''&&f.isValid()&&f._lastCheckValue!=f.value){
  43. f._lastCheckValue = f.value;
  44. form.setLoading(true);
  45. Ext.Ajax.request({
  46. url: '/api/account/account/checkMobile?mobile='+f.value,
  47. method: 'GET',
  48. headers:{
  49. 'Access-Control-Allow-Origin': '*',
  50. "Content-Type": 'application/json;charset=UTF-8',
  51. },
  52. success: function (response) {
  53. form.setLoading(false);
  54. var localJson = Ext.decode(response.responseText);
  55. if(localJson.success){
  56. f.hasRegister = localJson.data.hasRegister;
  57. if(localJson.data.hasRegister){
  58. f.ownerCt.down('[name=hasAccount]').show();
  59. f.ownerCt.down('[name=noAccount]').hide();
  60. }else{
  61. f.ownerCt.down('[name=hasAccount]').hide();
  62. f.ownerCt.down('[name=noAccount]').show();
  63. }
  64. }else{
  65. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  66. f.setValue('');
  67. f.ownerCt.down('[name=hasAccount]').hide();
  68. f.ownerCt.down('[name=noAccount]').hide();
  69. }
  70. },
  71. failure: function (response) {
  72. if(response.responseText){
  73. var localJson = Ext.decode(response.responseText);
  74. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  75. f.setValue('');
  76. }else{
  77. saas.util.BaseUtil.showErrorToast('手机号校验接口连接超时');
  78. f.setValue('');
  79. }
  80. }
  81. });
  82. }
  83. }
  84. }
  85. },{
  86. hidden:true,
  87. name:'hasAccount',
  88. xtype:'button',
  89. cls:'x-btn-showicon',
  90. style:'background:#fff;border:none;padding:7px 0 7px 0;',
  91. text:'已注册优软云',
  92. icon:'resources/images/default/toast_over.png',
  93. columnWidth:0.3,
  94. },{
  95. name:'noAccount',
  96. hidden:true,
  97. xtype:'button',
  98. cls:'x-btn-showicon',
  99. style:'background:#fff;border:none;padding:7px 0 7px 0;',
  100. text:'未注册优软云',
  101. icon:'resources/images/default/toast_close.png',
  102. columnWidth:0.3,
  103. }]
  104. },{
  105. xtype:'textfield',
  106. fieldLabel: '真实姓名',
  107. name: 'realname',
  108. regex:/^[\u4e00-\u9fa5]+$/,
  109. regexText:'请输入汉字',
  110. allowBlank:false,
  111. maxLength: 30,
  112. columnWidth:0.5
  113. },{
  114. xtype:'textfield',
  115. fieldLabel: '邮箱',
  116. name: 'email',
  117. allowBlank:true,
  118. beforeLabelTextTpl: "",
  119. regex:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
  120. regexText:'请输入正确的邮箱',
  121. maxLength: 30,
  122. listeners:{
  123. blur:function(f,a,b,c){
  124. var form = f.ownerCt;
  125. if(f.value&&f.value!=''&&f.isValid()&&f._lastCheckValue!=f.value){
  126. form.setLoading(true);
  127. f._lastCheckValue = f.value
  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. saas.util.BaseUtil.showSuccessToast('校验成功:邮箱未注册');
  141. }else{
  142. saas.util.BaseUtil.showErrorToast('校验失败:该邮箱已被注册');
  143. f.setValue('');
  144. }
  145. }else{
  146. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  147. }
  148. },
  149. failure: function (response) {
  150. if(response.responseText){
  151. var localJson = Ext.decode(response.responseText);
  152. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  153. }else{
  154. saas.util.BaseUtil.showErrorToast('邮箱校验接口连接超时');
  155. }
  156. }
  157. });
  158. }
  159. }
  160. }
  161. },{
  162. xtype:'datamulticombo',
  163. dataUrl:'/api/account/role/list',
  164. fieldLabel: '岗位角色',
  165. name: 'roleIds',
  166. allowBlank:false,
  167. maxLength: 30,
  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.value+','
  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(res) {
  222. me.setLoading(false);
  223. console.error(res);
  224. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  225. });
  226. }
  227. });