ChildForm.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /**
  2. * Created by zhouy on 2018/10/18.
  3. */
  4. Ext.define('KitchenSink.view.binding.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: 260,
  13. listeners:{
  14. show:function(w){
  15. if(w.record){
  16. w.down('form').loadRecord(w.record);
  17. }
  18. }
  19. },
  20. initComponent:function(){
  21. var me=this;
  22. Ext.apply(me,{
  23. items:me.setFormItems()
  24. });
  25. me.callParent();
  26. },
  27. etc:{
  28. customerkind:{
  29. items:[{
  30. xtype:'hidden',
  31. name:'id'
  32. },{
  33. xtype:'textfield',
  34. name:'ck_name',
  35. allowBlank:false,
  36. fieldLabel:'客户类型',
  37. maxLength: 20
  38. }]
  39. },
  40. vendorkind:{
  41. items:[{
  42. xtype:'hidden',
  43. name:'id'
  44. },{
  45. xtype:'textfield',
  46. name:'vk_name',
  47. allowBlank:false,
  48. fieldLabel:'供应商类型',
  49. maxLength: 20
  50. }]
  51. },
  52. productkind:{
  53. items:[{
  54. xtype:'hidden',
  55. name:'id'
  56. },{
  57. xtype:'textfield',
  58. name:'pt_name',
  59. allowBlank:false,
  60. fieldLabel:'物料类型',
  61. maxLength: 20
  62. }]
  63. },
  64. personpower:{
  65. items:[{
  66. xtype:'hidden',
  67. name:'id'
  68. },{
  69. xtype:'textfield',
  70. name:'name',
  71. allowBlank:false,
  72. fieldLabel:'角色名称',
  73. maxLength: 20
  74. },{
  75. xtype:'textfield',
  76. name:'description',
  77. allowBlank:false,
  78. fieldLabel:'角色描述',
  79. maxLength: 20
  80. },{
  81. xtype:'textfield',
  82. hidden:true,
  83. name:'code',
  84. allowBlank:true,
  85. fieldLabel:'角色编号',
  86. maxLength: 20
  87. }]
  88. },
  89. bankinformation:{
  90. items:[{
  91. xtype:'hidden',
  92. name:'id'
  93. },{
  94. xtype:'textfield',
  95. name:'bk_bankcode',
  96. allowBlank:false,
  97. fieldLabel:'账户编号',
  98. maxLength: 20
  99. },{
  100. xtype:'textfield',
  101. name:'bk_bankname',
  102. allowBlank:false,
  103. fieldLabel:'账户名称',
  104. maxLength: 20
  105. },{
  106. xtype:'numberfield',
  107. name:'bk_beginamount',
  108. allowBlank:false,
  109. fieldLabel:'期初金额',
  110. hideTrigger: true,
  111. mouseWheelEnabled: false,
  112. minValue: 0,
  113. maxLength:15,
  114. decimalPrecision:2,
  115. enforceMaxLength:true
  116. },
  117. // {
  118. // xtype:'numberfield',
  119. // name:'bk_thisamount',
  120. // allowBlank:true,
  121. // fieldLabel:'当前余额',
  122. // hideTrigger: true,
  123. // mouseWheelEnabled: false,
  124. // beforeLabelTextTpl:'',
  125. // minValue: 0
  126. // }
  127. // ,
  128. {
  129. xtype:'combo',
  130. name:'bk_type',
  131. allowBlank:false,
  132. editable:false,
  133. fieldLabel:'账户类别',
  134. store: [
  135. '现金',
  136. '银行'
  137. ]
  138. },{
  139. xtype:'datefield',
  140. name:'bk_date',
  141. fieldLabel:'建账日期',
  142. format:'Y-m-d H:i:s',
  143. listeners:{
  144. beforerender:function(d){
  145. d.setValue(new Date())
  146. }
  147. }
  148. }, {
  149. xtype:'textfield',
  150. name:'bk_remark',
  151. allowBlank:true,
  152. fieldLabel:'备注',
  153. beforeLabelTextTpl:''
  154. }]
  155. },
  156. productbrand:{
  157. items:[{
  158. xtype:'hidden',
  159. name:'id'
  160. },{
  161. xtype:'textfield',
  162. name:'pb_name',
  163. allowBlank:false,
  164. fieldLabel:'物料品牌',
  165. maxLength: 20
  166. }]
  167. },
  168. productunit:{
  169. items:[{
  170. xtype:'hidden',
  171. name:'id'
  172. },{
  173. xtype:'textfield',
  174. name:'pu_name',
  175. allowBlank:false,
  176. fieldLabel:'计量单位',
  177. maxLength: 20
  178. }]
  179. },
  180. inoutkind:{
  181. items:[{
  182. xtype:'hidden',
  183. name:'id'
  184. },{
  185. xtype:'textfield',
  186. name:'ft_name',
  187. allowBlank:false,
  188. fieldLabel:'收支名称',
  189. maxLength: 20
  190. },{
  191. xtype:'combo',
  192. name:'ft_kind',
  193. allowBlank:false,
  194. fieldLabel:'收支类型',
  195. hideTrigger : false,
  196. maxLength : 100.0,
  197. minValue : null,
  198. positiveNum : false,
  199. queryMode : "local",
  200. valueField : "value",
  201. xtype : "combo",
  202. editable:false,
  203. displayField : "display",
  204. store:{
  205. fields: ['display', 'value'],
  206. data : [
  207. {"display":"收入", "value":'收入'},
  208. {"display":"支出", "value":'支出'}
  209. ]
  210. }
  211. }]
  212. },
  213. address:{
  214. items:[{
  215. xtype:'hidden',
  216. name:'id'
  217. },{
  218. xtype:'textfield',
  219. name:'ad_address',
  220. allowBlank:false,
  221. fieldLabel:'地址详情',
  222. maxLength: 200
  223. }]
  224. },
  225. accountinformation:{
  226. items:[{
  227. xtype:'hidden',
  228. name:'accountId',
  229. hidden:true,
  230. },{
  231. xtype:'textfield',
  232. fieldLabel: '真实姓名',
  233. name: 'realname',
  234. readOnly:true,
  235. editable:false,
  236. allowBlank:true,
  237. maxLength: 30,
  238. beforeLabelTextTpl: "",
  239. },{
  240. xtype:'datamulticombo',
  241. dataUrl:'/api/account/role/list',
  242. fieldLabel: '关联角色',
  243. name: 'roleNames',
  244. allowBlank:true,
  245. maxLength: 20,
  246. beforeLabelTextTpl: "",
  247. },{
  248. xtype:'textfield',
  249. fieldLabel: '手机号码',
  250. name: 'mobile',
  251. readOnly:true,
  252. editable:false,
  253. allowBlank:true,
  254. maxLength: 30,
  255. beforeLabelTextTpl: "",
  256. },{
  257. xtype:'textfield',
  258. fieldLabel: '邮箱',
  259. name: 'email',
  260. readOnly:true,
  261. editable:false,
  262. allowBlank:true,
  263. maxLength: 30,
  264. beforeLabelTextTpl: "",
  265. }]
  266. },
  267. accountadd:{
  268. items:[{
  269. xtype:'textfield',
  270. fieldLabel: '手机号码',
  271. name: 'mobile',
  272. hideTrigger:true,
  273. allowBlank:false,
  274. maxLength: 30,
  275. regex:/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/,
  276. regexText:'请输入正确的手机号码',
  277. listeners:{
  278. blur:function(f,a,b,c){
  279. if(f.value&&f.value!=''&&f.isValid()){
  280. Ext.Ajax.request({
  281. url: 'http://192.168.253.31:8560/api/account/account/checkMobile?mobile='+f.value,
  282. method: 'GET',
  283. headers:{
  284. 'Access-Control-Allow-Origin': '*',
  285. "Content-Type": 'application/json;charset=UTF-8'
  286. },
  287. success: function (response) {
  288. if(localJson.success){
  289. saas.util.BaseUtil.showSuccessToast('保存成功');
  290. form.ownerCt._parent.store.load()
  291. form.ownerCt.close();
  292. }
  293. },
  294. failure: function (response) {
  295. debugger
  296. }
  297. });
  298. }
  299. }
  300. }
  301. },{
  302. xtype:'textfield',
  303. fieldLabel: '真实姓名',
  304. name: 'realname',
  305. allowBlank:false,
  306. maxLength: 30,
  307. },{
  308. xtype:'textfield',
  309. fieldLabel: '邮箱',
  310. name: 'email',
  311. allowBlank:false,
  312. maxLength: 30,
  313. }]
  314. },
  315. warehouse:{
  316. items:[{
  317. xtype:'hidden',
  318. name:'id'
  319. },{
  320. xtype:'textfield',
  321. fieldLabel: '仓库编号',
  322. name: 'wh_code',
  323. allowBlank:false,
  324. maxLength: 20
  325. },{
  326. xtype:'textfield',
  327. fieldLabel: '仓库名称',
  328. name: 'wh_description',
  329. allowBlank:false,
  330. maxLength: 20
  331. },{
  332. xtype:'combo',
  333. fieldLabel: '仓库类型',
  334. name: 'wh_type',
  335. allowBlank:false,
  336. displayField : "display",
  337. editable:false,
  338. hideTrigger : false,
  339. maxLength : 100.0,
  340. minValue : null,
  341. positiveNum : false,
  342. queryMode : "local",
  343. valueField : "value",
  344. store:{
  345. fields: ['display', 'value'],
  346. data : [
  347. {"display":"良品仓", "value":'良品仓'},
  348. {"display":"不良品仓", "value":'不良品仓'}
  349. ]
  350. }
  351. },{
  352. readOnly:true,
  353. xtype:'textfield',
  354. fieldLabel: '仓库状态',
  355. name: 'wh_status',
  356. value:'已开启',
  357. maxLength: 20
  358. },{
  359. xtype:'hidden',
  360. fieldLabel: '仓库状态码',
  361. name: 'wh_statuscode',
  362. value:'OPEN'
  363. }]
  364. },
  365. employee:{
  366. items:[{
  367. xtype:'hidden',
  368. name:'id'
  369. },{
  370. xtype:'textfield',
  371. fieldLabel: '人员编号',
  372. name: 'em_code',
  373. allowBlank:false,
  374. maxLength: 20
  375. },{
  376. xtype:'textfield',
  377. fieldLabel: '人员名称',
  378. name: 'em_name',
  379. allowBlank:false,
  380. maxLength: 20
  381. },{
  382. xtype:'textfield',
  383. fieldLabel: '联系电话',
  384. name: 'em_mobile',
  385. allowBlank:true,
  386. beforeLabelTextTpl: '',
  387. maxLength: 20
  388. },{
  389. xtype:'textfield',
  390. fieldLabel: '邮箱',
  391. name: 'em_email',
  392. allowBlank:true,
  393. beforeLabelTextTpl: '',
  394. maxLength: 20
  395. },{
  396. value:'正式',
  397. xtype:'combo',
  398. fieldLabel: '人员状态',
  399. name: 'em_class',
  400. allowBlank:false,
  401. displayField : "display",
  402. editable:false,
  403. hideTrigger : false,
  404. maxLength : 100.0,
  405. minValue : null,
  406. positiveNum : false,
  407. queryMode : "local",
  408. valueField : "value",
  409. store:{
  410. fields: ['display', 'value'],
  411. data : [
  412. {"display":"正式", "value":'正式'},
  413. {"display":"离职", "value":'离职'}
  414. ]
  415. }
  416. },]
  417. },
  418. maxnumbers:{
  419. items:[{
  420. xtype:'hidden',
  421. name:'id'
  422. },{
  423. xtype:'textfield',
  424. fieldLabel: '单据名称',
  425. name: 'mn_name',
  426. allowBlank:false,
  427. editable:false,
  428. readOnly:true,
  429. maxLength: 20
  430. },{
  431. xtype:'textfield',
  432. fieldLabel: '单据前缀',
  433. name: 'mn_leadcode',
  434. beforeLabelTextTpl: '',
  435. allowBlank:true,
  436. maxLength: 20
  437. },{
  438. xtype:'combo',
  439. fieldLabel: '单据规则',
  440. name: 'mn_rule',
  441. displayField : "display",
  442. editable:false,
  443. hideTrigger : false,
  444. maxLength : 100.0,
  445. minValue : null,
  446. positiveNum : false,
  447. queryMode : "local",
  448. valueField : "value",
  449. store:{
  450. fields: ['display', 'value'],
  451. data : [
  452. {"display":"年月日", "value":'yyyymmdd'},
  453. {"display":"年月", "value":'yyyymm'},
  454. {"display":"无", "value":'无'}
  455. ]
  456. }
  457. },{
  458. xtype:'numberfield',
  459. hideTrigger : true,
  460. fieldLabel: '流水长度',
  461. name: 'mn_number',
  462. minValue : 0,
  463. allowBlank:false,
  464. mouseWheelEnabled: false
  465. }]
  466. }
  467. },
  468. setFormItems:function() {
  469. var me = this, kind = me.dataKind;
  470. var conf = {
  471. xtype: 'form',
  472. bodyPadding: 10,
  473. border: false,
  474. autoScroll:true,
  475. modelValidation: true,
  476. layout: {
  477. type: 'vbox',
  478. align: 'stretch'
  479. },
  480. defaults: {
  481. labelAlign:'right',
  482. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>",
  483. xtype: 'textfield'
  484. },
  485. buttons: [{
  486. text: '保存',
  487. formBind:true,
  488. handler: me.onSave,
  489. scope:me
  490. }, {
  491. text: '取消',
  492. handler: me.onCancel,
  493. scope:me
  494. }]
  495. };
  496. return Ext.apply(conf, me.etc[kind]);
  497. },
  498. onSave:function(){
  499. var me = this;
  500. var belong = this.belong;
  501. me.setLoading(true);
  502. var form=this.down('form');
  503. var combo = this._combo;
  504. var params = {};
  505. var names = belong.columns.map(column => column.dataIndex);
  506. //账户资料特殊保存逻辑
  507. if(me.dataKind=='accountinformation'){
  508. me.accountinformation();
  509. return;
  510. }
  511. //账户资料新增特殊保存逻辑
  512. if(me.dataKind=='accountadd'){
  513. me.accountadd();
  514. return;
  515. }
  516. Ext.Array.each(names,function(name) {
  517. if(name){
  518. var dataField = form.down('[name='+name+']');
  519. if(dataField&&dataField.value){
  520. params[name] = dataField.value;
  521. params._value = dataField.value;
  522. }
  523. }
  524. });
  525. var idField = form.down('[name='+belong.keyField+']');
  526. params[belong.keyField] = idField.value || 0;
  527. //保存接口
  528. saas.util.BaseUtil.request({
  529. url: belong.reqUrl,
  530. params: JSON.stringify(params),
  531. method: 'POST'
  532. })
  533. .then(function(localJson) {
  534. me.setLoading(false);
  535. if(localJson.success){
  536. var grid = form.ownerCt._parent ? form.ownerCt._parent.lookup('document-kind-Grid') : null;
  537. if(grid){
  538. grid.store.load();
  539. }
  540. if(combo){
  541. combo.store.load(function() {
  542. typeof combo.setValue == 'function' && combo.setValue(params._value);
  543. });
  544. }
  545. saas.util.BaseUtil.showSuccessToast('保存成功');
  546. form.ownerCt.close();
  547. }
  548. })
  549. .catch(function(res) {
  550. me.setLoading(false);
  551. console.error(res);
  552. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  553. });
  554. },
  555. onCancel:function(){
  556. this.hide();
  557. },
  558. accountinformation:function(){
  559. var me = this;
  560. var belong = this.belong;
  561. me.setLoading(true);
  562. var form=this.down('form');
  563. var combo = this._combo;
  564. var params = {};
  565. var names = belong.columns.map(column => column.dataIndex);
  566. Ext.Array.each(names,function(name) {
  567. if(name){
  568. var dataField = form.down('[name='+name+']');
  569. if(dataField&&dataField.value){
  570. params[name] = dataField.value;
  571. params._value = dataField.value;
  572. }
  573. }
  574. });
  575. //更改参数
  576. var o = '';
  577. Ext.Array.each(params.roleNames,function(item) {
  578. o+=item.value+','
  579. });
  580. o = o.substring(0,o.length-1);
  581. if(o==""){
  582. saas.util.BaseUtil.showErrorToast('关联角色未选择,无法保存!')
  583. }
  584. var _params = {
  585. accountId:Number(params['accountId']),
  586. roleIds:o,
  587. };
  588. //保存接口
  589. saas.util.BaseUtil.request({
  590. url: belong.reqUrl,
  591. params: _params,
  592. method: 'POST',
  593. headers:{
  594. 'Access-Control-Allow-Origin': '*',
  595. "Content-Type":'application/x-www-form-urlencoded'
  596. }
  597. })
  598. .then(function(localJson) {
  599. me.setLoading(false);
  600. if(localJson.success){
  601. saas.util.BaseUtil.showSuccessToast('保存成功');
  602. form.ownerCt._parent.store.load()
  603. form.ownerCt.close();
  604. }
  605. })
  606. .catch(function(res) {
  607. me.setLoading(false);
  608. console.error(res);
  609. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  610. });
  611. },
  612. accountadd:function(){
  613. var me = this;
  614. var belong = this.belong;
  615. me.setLoading(true);
  616. var form=this.down('form');
  617. var combo = this._combo;
  618. var params = {};
  619. var names = belong.columns.map(column => column.dataIndex);
  620. Ext.Array.each(names,function(name) {
  621. if(name){
  622. var dataField = form.down('[name='+name+']');
  623. if(dataField&&dataField.value){
  624. params[name] = dataField.value;
  625. params._value = dataField.value;
  626. }
  627. }
  628. });
  629. params['username'] = params['mobile'];
  630. params['type'] = 1;
  631. //保存接口
  632. saas.util.BaseUtil.request({
  633. url: belong.reqUrl,
  634. params: JSON.stringify(params),
  635. method: 'POST'
  636. })
  637. .then(function(localJson) {
  638. me.setLoading(false);
  639. if(localJson.success){
  640. var grid = form.ownerCt._parent ? form.ownerCt._parent.lookup('document-kind-Grid') : null;
  641. if(grid){
  642. grid.store.load();
  643. }
  644. if(combo){
  645. combo.store.load(function() {
  646. typeof combo.setValue == 'function' && combo.setValue(params._value);
  647. });
  648. }
  649. saas.util.BaseUtil.showSuccessToast('保存成功');
  650. form.ownerCt.close();
  651. }
  652. })
  653. .catch(function(res) {
  654. me.setLoading(false);
  655. console.error(res);
  656. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  657. });
  658. }
  659. });