ChildForm.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /**
  2. * Created by zhouy on 2018/10/18.
  3. */
  4. Ext.define('saas.view.document.kind.ChildForm', {
  5. extend: 'Ext.window.Window',
  6. xtype: 'document-kind-childwin',
  7. cls:'x-window-dbfind',
  8. layout: 'fit',
  9. modal: true,
  10. width: 500,
  11. //工具类
  12. height: 280,
  13. listeners:{
  14. show:function(w){
  15. //自动适应窗口
  16. var items = w.down('form').items.items;
  17. var count = 0;
  18. var codeField;
  19. Ext.Array.each(items,function(item) {
  20. if(item.xtype!='hidden'){
  21. count++;
  22. }
  23. if(item.autoCode){
  24. codeField = item.name
  25. }
  26. });
  27. if(count!=0&&count<4){
  28. w.setHeight(114+40*count)
  29. }
  30. if(w.record){
  31. w.down('form').loadRecord(w.record);
  32. }else{
  33. //判断是否有code字段
  34. if(codeField){
  35. w.setLoading(true);
  36. //取后台编号
  37. var caller = w.caller || w._parent.caller;
  38. saas.util.BaseUtil.request({
  39. url: '/api/commons/number/getMaxnumber',
  40. headers: {
  41. "Content-Type": 'application/x-www-form-urlencoded;charset=UTF-8'
  42. },
  43. params: {
  44. caller:caller
  45. },
  46. method: 'POST',
  47. }).then(function(res) {
  48. w.setLoading(false);
  49. if(res.success){
  50. w.down('[name='+codeField+']').setValue(res.data);
  51. }else {
  52. saas.util.BaseUtil.showErrorToast(res.message);
  53. }
  54. }).catch(function(res) {
  55. saas.util.BaseUtil.showErrorToast(res.message);
  56. w.setLoading(true);
  57. })
  58. }
  59. }
  60. }
  61. },
  62. initComponent:function(){
  63. var me=this;
  64. Ext.apply(me,{
  65. items:me.setFormItems()
  66. });
  67. me.callParent();
  68. },
  69. etc:{
  70. customerkind:{
  71. items:[{
  72. xtype:'hidden',
  73. name:'id'
  74. },{
  75. xtype:'textfield',
  76. name:'ck_name',
  77. allowBlank:false,
  78. fieldLabel:'客户类型',
  79. maxLength: 20
  80. }]
  81. },
  82. vendorkind:{
  83. items:[{
  84. xtype:'hidden',
  85. name:'id'
  86. },{
  87. xtype:'textfield',
  88. name:'vk_name',
  89. allowBlank:false,
  90. fieldLabel:'供应商类型',
  91. maxLength: 20
  92. }]
  93. },
  94. productkind:{
  95. items:[{
  96. xtype:'hidden',
  97. name:'id'
  98. },{
  99. xtype:'textfield',
  100. name:'pt_name',
  101. allowBlank:false,
  102. fieldLabel:'物料类型',
  103. maxLength: 20
  104. }]
  105. },
  106. personpower:{
  107. items:[{
  108. xtype:'hidden',
  109. name:'id'
  110. },{
  111. xtype:'textfield',
  112. name:'name',
  113. allowBlank:false,
  114. fieldLabel:'角色名称',
  115. maxLength: 20
  116. },{
  117. xtype:'textfield',
  118. name:'description',
  119. allowBlank:false,
  120. fieldLabel:'角色描述',
  121. maxLength: 20
  122. },{
  123. xtype:'textfield',
  124. hidden:true,
  125. name:'code',
  126. allowBlank:true,
  127. fieldLabel:'角色编号',
  128. maxLength: 20
  129. }]
  130. },
  131. inoutkind:{
  132. items:[{
  133. xtype:'hidden',
  134. name:'id'
  135. },{
  136. xtype:'textfield',
  137. name:'ft_name',
  138. allowBlank:false,
  139. relativeField:'ord_type',
  140. fieldLabel:'收支名称',
  141. maxLength: 20
  142. },{
  143. xtype:'combo',
  144. name:'ft_kind',
  145. allowBlank:false,
  146. fieldLabel:'收支类型',
  147. hideTrigger : false,
  148. maxLength : 100.0,
  149. minValue : null,
  150. positiveNum : false,
  151. queryMode : "local",
  152. valueField : "value",
  153. xtype : "combo",
  154. editable:false,
  155. displayField : "display",
  156. store:{
  157. fields: ['display', 'value'],
  158. data : [
  159. {"display":"收入", "value":'收入'},
  160. {"display":"支出", "value":'支出'}
  161. ]
  162. }
  163. }]
  164. },
  165. accountinformation:{
  166. items:[{
  167. xtype:'hidden',
  168. name:'accountId',
  169. hidden:true,
  170. },{
  171. xtype:'textfield',
  172. fieldLabel: '真实姓名',
  173. name: 'realname',
  174. readOnly:true,
  175. editable:false,
  176. allowBlank:true,
  177. maxLength: 30,
  178. beforeLabelTextTpl: "",
  179. },{
  180. xtype:'datamulticombo',
  181. dataUrl:'/api/account/role/list',
  182. fieldLabel: '岗位角色',
  183. name: 'roleNames',
  184. allowBlank:true,
  185. maxLength: 20,
  186. beforeLabelTextTpl: "",
  187. },{
  188. xtype:'textfield',
  189. fieldLabel: '联系电话',
  190. name: 'mobile',
  191. readOnly:true,
  192. editable:false,
  193. allowBlank:true,
  194. maxLength: 30,
  195. beforeLabelTextTpl: "",
  196. },{
  197. xtype:'textfield',
  198. fieldLabel: '邮箱',
  199. name: 'email',
  200. readOnly:true,
  201. editable:false,
  202. allowBlank:true,
  203. maxLength: 30,
  204. beforeLabelTextTpl: "",
  205. }]
  206. },
  207. accountadd:{
  208. items:[{
  209. xtype:'textfield',
  210. fieldLabel: '联系号码',
  211. name: 'mobile',
  212. hideTrigger:true,
  213. allowBlank:false,
  214. maxLength: 30,
  215. regex:/^1(3|4|5|7|8)\d{9}$/,
  216. regexText:'请输入正确的手机号码',
  217. listeners:{
  218. change:function(f,a,b){
  219. if(a==''){
  220. f._lastCheckValue = ''
  221. }
  222. },
  223. blur:function(f,a,b,c){
  224. var form = f.ownerCt;
  225. if(f.value&&f.value!=''&&f.isValid()&&f._lastCheckValue!=f.value){
  226. f._lastCheckValue = f.value;
  227. form.setLoading(true);
  228. Ext.Ajax.request({
  229. url: '/api/account/account/checkMobile?mobile='+f.value,
  230. method: 'GET',
  231. headers:{
  232. 'Access-Control-Allow-Origin': '*',
  233. "Content-Type": 'application/json;charset=UTF-8',
  234. },
  235. success: function (response) {
  236. form.setLoading(false);
  237. var localJson = Ext.decode(response.responseText);
  238. if(localJson.success){
  239. if(localJson.data.hasRegister){
  240. saas.util.BaseUtil.showSuccessToast('校验成功:手机号已在优软云注册');
  241. }else{
  242. saas.util.BaseUtil.showErrorToast('校验失败:手机号未在优软云注册');
  243. f.setValue('');
  244. }
  245. }else{
  246. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  247. f.setValue('');
  248. }
  249. },
  250. failure: function (response) {
  251. if(response.responseText){
  252. var localJson = Ext.decode(response.responseText);
  253. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  254. f.setValue('');
  255. }else{
  256. saas.util.BaseUtil.showErrorToast('手机号校验接口连接超时');
  257. f.setValue('');
  258. }
  259. }
  260. });
  261. }
  262. }
  263. }
  264. },{
  265. xtype:'textfield',
  266. fieldLabel: '真实姓名',
  267. name: 'realname',
  268. regex:/^[\u4e00-\u9fa5]+$/,
  269. regexText:'请输入汉字',
  270. allowBlank:false,
  271. maxLength: 30,
  272. },{
  273. xtype:'textfield',
  274. fieldLabel: '邮箱',
  275. name: 'email',
  276. allowBlank:true,
  277. beforeLabelTextTpl: "",
  278. regex:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
  279. regexText:'请输入正确的邮箱',
  280. maxLength: 30,
  281. listeners:{
  282. blur:function(f,a,b,c){
  283. var form = f.ownerCt;
  284. if(f.value&&f.value!=''&&f.isValid()&&f._lastCheckValue!=f.value){
  285. form.setLoading(true);
  286. f._lastCheckValue = f.value
  287. Ext.Ajax.request({
  288. url: '/api/account/account/checkEmail?email='+f.value,
  289. method: 'GET',
  290. headers:{
  291. 'Access-Control-Allow-Origin': '*',
  292. "Content-Type": 'application/json;charset=UTF-8'
  293. },
  294. success: function (response) {
  295. form.setLoading(false);
  296. var localJson = Ext.decode(response.responseText);
  297. if(localJson.success){
  298. if(!localJson.data){
  299. saas.util.BaseUtil.showSuccessToast('校验成功:邮箱未注册');
  300. }else{
  301. saas.util.BaseUtil.showErrorToast('校验失败:该邮箱已被注册');
  302. f.setValue('');
  303. }
  304. }else{
  305. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  306. }
  307. },
  308. failure: function (response) {
  309. if(response.responseText){
  310. var localJson = Ext.decode(response.responseText);
  311. saas.util.BaseUtil.showErrorToast('校验失败:'+localJson.message);
  312. }else{
  313. saas.util.BaseUtil.showErrorToast('邮箱校验接口连接超时');
  314. }
  315. }
  316. });
  317. }
  318. }
  319. }
  320. },{
  321. xtype:'datamulticombo',
  322. dataUrl:'/api/account/role/list',
  323. fieldLabel: '岗位角色',
  324. name: 'roleIds',
  325. allowBlank:false,
  326. maxLength: 30,
  327. }]
  328. },
  329. maxnumbers:{
  330. items:[{
  331. xtype:'hidden',
  332. name:'id'
  333. },{
  334. xtype:'textfield',
  335. fieldLabel: '单据名称',
  336. name: 'mn_name',
  337. allowBlank:false,
  338. editable:false,
  339. readOnly:true,
  340. maxLength: 20
  341. },{
  342. xtype:'textfield',
  343. fieldLabel: '单据前缀',
  344. name: 'mn_leadcode',
  345. beforeLabelTextTpl: '',
  346. allowBlank:true,
  347. maxLength: 20
  348. },{
  349. xtype:'combo',
  350. fieldLabel: '单据规则',
  351. name: 'mn_rule',
  352. displayField : "display",
  353. editable:false,
  354. hideTrigger : false,
  355. maxLength : 100.0,
  356. minValue : null,
  357. positiveNum : false,
  358. queryMode : "local",
  359. valueField : "value",
  360. store:{
  361. fields: ['display', 'value'],
  362. data : [
  363. {"display":"年月日", "value":'yyyymmdd'},
  364. {"display":"年月", "value":'yyyymm'},
  365. {"display":"无", "value":'无'}
  366. ]
  367. }
  368. },{
  369. xtype:'numberfield',
  370. hideTrigger : true,
  371. fieldLabel: '流水长度',
  372. name: 'mn_number',
  373. minValue : 0,
  374. allowBlank:false,
  375. mouseWheelEnabled: false
  376. }]
  377. }
  378. },
  379. setFormItems:function() {
  380. var me = this, kind = me.dataKind;
  381. var conf = {
  382. xtype: 'form',
  383. bodyPadding: 10,
  384. border: false,
  385. autoScroll:true,
  386. modelValidation: true,
  387. layout: {
  388. type: 'vbox',
  389. align: 'stretch'
  390. },
  391. defaults: {
  392. labelAlign:'right',
  393. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>",
  394. xtype: 'textfield'
  395. },
  396. buttons: [{
  397. text: '保存',
  398. formBind:true,
  399. handler: me.onSave,
  400. scope:me
  401. }, {
  402. text: '取消',
  403. handler: me.onCancel,
  404. scope:me
  405. }]
  406. };
  407. return Ext.apply(conf, me.etc[kind]);
  408. },
  409. onSave:function(){
  410. var me = this;
  411. var belong = this.belong;
  412. me.setLoading(true);
  413. var form=this.down('form');
  414. var combo = this._combo;
  415. var params = {};
  416. var relativeField,relativeValue;//要赋值的字段和值
  417. var names = belong.columns.map(column => column.dataIndex);
  418. //账户资料特殊保存逻辑
  419. if(me.dataKind=='accountinformation'){
  420. me.accountinformation();
  421. return;
  422. }
  423. //账户资料新增特殊保存逻辑
  424. if(me.dataKind=='accountadd'){
  425. me.accountadd();
  426. return;
  427. }
  428. Ext.Array.each(names,function(name) {
  429. if(name){
  430. var dataField = form.down('[name='+name+']');
  431. if(dataField){
  432. var value = dataField.getValue();
  433. if(Ext.isDate(value)) {
  434. value = Ext.Date.format(value, 'Y-m-d H:i:s');
  435. }
  436. params[name] = value;
  437. if(!relativeValue){
  438. relativeField = dataField.relativeField;
  439. relativeValue = value;
  440. }
  441. }
  442. }
  443. });
  444. var idField = form.down('[name='+belong.keyField+']');
  445. params[belong.keyField] = idField.value || 0;
  446. //保存接口
  447. saas.util.BaseUtil.request({
  448. url: belong.reqUrl,
  449. params: JSON.stringify(params),
  450. method: 'POST'
  451. })
  452. .then(function(localJson) {
  453. me.setLoading(false);
  454. if(localJson.success){
  455. var grid = form.ownerCt._parent ? form.ownerCt._parent.lookup('document-kind-Grid') : null;
  456. if(grid){
  457. grid.store.load();
  458. }
  459. if(relativeField&&relativeValue&&form.ownerCt._parent){
  460. var grid = form.ownerCt._parent.down('grid');
  461. var rec = grid.getSelectionModel().getLastSelected();
  462. rec.set(relativeField,relativeValue);
  463. }
  464. if(combo){
  465. combo.store.load(function() {
  466. typeof combo.setValue == 'function' && combo.setValue(relativeValue);
  467. });
  468. }
  469. saas.util.BaseUtil.showSuccessToast('保存成功');
  470. form.ownerCt.close();
  471. }
  472. })
  473. .catch(function(res) {
  474. me.setLoading(false);
  475. console.error(res);
  476. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  477. });
  478. },
  479. onCancel:function(){
  480. this.hide();
  481. },
  482. accountinformation:function(){
  483. var me = this;
  484. var belong = this.belong;
  485. me.setLoading(true);
  486. var form=this.down('form');
  487. var combo = this._combo;
  488. var params = {};
  489. var names = belong.columns.map(column => column.dataIndex);
  490. Ext.Array.each(names,function(name) {
  491. if(name){
  492. var dataField = form.down('[name='+name+']');
  493. if(dataField&&dataField.value){
  494. params[name] = dataField.value;
  495. }
  496. }
  497. });
  498. //更改参数
  499. var o = '';
  500. Ext.Array.each(params.roleNames,function(item) {
  501. o+=item.value+','
  502. });
  503. o = o.substring(0,o.length-1);
  504. if(o==""){
  505. saas.util.BaseUtil.showErrorToast('岗位角色未选择,无法保存!')
  506. }
  507. var _params = {
  508. accountId:Number(params['accountId']),
  509. roleIds:o,
  510. };
  511. //保存接口
  512. saas.util.BaseUtil.request({
  513. url: belong.reqUrl,
  514. params: _params,
  515. method: 'POST',
  516. headers:{
  517. 'Access-Control-Allow-Origin': '*',
  518. "Content-Type":'application/x-www-form-urlencoded'
  519. }
  520. })
  521. .then(function(localJson) {
  522. me.setLoading(false);
  523. if(localJson.success){
  524. saas.util.BaseUtil.showSuccessToast('保存成功');
  525. form.ownerCt._parent.store.load()
  526. form.ownerCt.close();
  527. }
  528. })
  529. .catch(function(res) {
  530. me.setLoading(false);
  531. console.error(res);
  532. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  533. });
  534. },
  535. accountadd:function(){
  536. var me = this;
  537. var belong = this.belong;
  538. me.setLoading(true);
  539. var form=this.down('form');
  540. var combo = this._combo;
  541. var params = {};
  542. var names = belong.columns.map(column => column.dataIndex);
  543. Ext.Array.each(names,function(name) {
  544. if(name){
  545. var dataField = form.down('[name='+name+']');
  546. if(dataField&&dataField.value){
  547. params[name] = dataField.value;
  548. params._value = dataField.value;
  549. }
  550. }
  551. });
  552. //更改参数
  553. var o = '';
  554. var dataField = form.down('[name=roleIds]');
  555. Ext.Array.each(dataField.value,function(item) {
  556. o+=item.value+','
  557. });
  558. o = o.substring(0,o.length-1);
  559. params['username'] = params['mobile'];
  560. params['type'] = 1;
  561. params['roleIds'] = o;
  562. //保存接口
  563. saas.util.BaseUtil.request({
  564. url: belong.reqUrl,
  565. params: JSON.stringify(params),
  566. method: 'POST'
  567. })
  568. .then(function(localJson) {
  569. me.setLoading(false);
  570. if(localJson.success){
  571. form.ownerCt._parent.store.load();
  572. saas.util.BaseUtil.showSuccessToast('保存成功');
  573. form.ownerCt.close();
  574. }
  575. })
  576. .catch(function(res) {
  577. me.setLoading(false);
  578. console.error(res);
  579. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  580. });
  581. }
  582. });