AddWindow.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. },{
  113. xtype:'textfield',
  114. fieldLabel: '邮箱',
  115. name: 'email',
  116. allowBlank:true,
  117. beforeLabelTextTpl: "",
  118. regex:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
  119. regexText:'请输入正确的邮箱',
  120. maxLength: 30,
  121. listeners:{
  122. blur:function(f,a,b,c){
  123. var form = f.ownerCt;
  124. if(f.value&&f.value!=''&&f.isValid()&&f._lastCheckValue!=f.value){
  125. form.setLoading(true);
  126. f._lastCheckValue = f.value
  127. Ext.Ajax.request({
  128. url: '/api/account/account/checkEmail?email='+f.value,
  129. method: 'GET',
  130. headers:{
  131. 'Access-Control-Allow-Origin': '*',
  132. "Content-Type": 'application/json;charset=UTF-8'
  133. },
  134. success: function (response) {
  135. form.setLoading(false);
  136. var localJson = Ext.decode(response.responseText);
  137. if(localJson.success){
  138. if(!localJson.data){
  139. saas.util.BaseUtil.showSuccessToast('校验成功:邮箱未注册');
  140. }else{
  141. saas.util.BaseUtil.showErrorToast('校验失败:该邮箱已被注册');
  142. f.setValue('');
  143. }
  144. }else{
  145. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  146. }
  147. },
  148. failure: function (response) {
  149. if(response.responseText){
  150. var localJson = Ext.decode(response.responseText);
  151. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  152. }else{
  153. saas.util.BaseUtil.showErrorToast('邮箱校验接口连接超时');
  154. }
  155. }
  156. });
  157. }
  158. }
  159. }
  160. },{
  161. xtype:'datamulticombo',
  162. dataUrl:'/api/account/role/list',
  163. fieldLabel: '岗位角色',
  164. name: 'roleIds',
  165. allowBlank:false,
  166. maxLength: 30,
  167. },{
  168. margin:'10 0 0 0',
  169. xtype:'displayfield',
  170. fieldLabel: '温馨提示',
  171. beforeLabelTextTpl: "",
  172. value:'已注册优软云可以访问优软云门户网',
  173. fieldStyle:'color:#999;margin-top: 9px;'
  174. }]
  175. }
  176. },
  177. onSave:function(){
  178. var me = this;
  179. var belong = this.belong;
  180. me.setLoading(true);
  181. var form=this.down('form');
  182. var params = {};
  183. var names = belong.columns.map(column => column.dataIndex);
  184. Ext.Array.each(names,function(name) {
  185. if(name){
  186. var dataField = form.down('[name='+name+']');
  187. if(dataField&&dataField.value){
  188. params[name] = dataField.value;
  189. }
  190. if(dataField.name=='mobile'){
  191. params['hasRegister'] = dataField.hasRegister;
  192. }
  193. }
  194. });
  195. //更改参数
  196. var o = '';
  197. var dataField = form.down('[name=roleIds]');
  198. Ext.Array.each(dataField.value,function(item) {
  199. o+=item.value+','
  200. });
  201. o = o.substring(0,o.length-1);
  202. params['username'] = params['mobile'];
  203. params['type'] = 1;
  204. params['roleIds'] = o;
  205. //保存接口
  206. saas.util.BaseUtil.request({
  207. url: belong.reqUrl,
  208. params: JSON.stringify(params),
  209. method: 'POST'
  210. })
  211. .then(function(localJson) {
  212. me.setLoading(false);
  213. if(localJson.success){
  214. form.ownerCt._parent.store.load();
  215. saas.util.BaseUtil.showSuccessToast('保存成功');
  216. form.ownerCt.close();
  217. }
  218. })
  219. .catch(function(res) {
  220. me.setLoading(false);
  221. console.error(res);
  222. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  223. });
  224. }
  225. });