FormPanelController.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. Ext.define('saas.view.money.verification.FormPanelController', {
  2. extend: 'saas.view.core.form.FormPanelController',
  3. alias: 'controller.money-verification-formpanel',
  4. init: function (form) {
  5. var me = this;
  6. this.control({
  7. // 客户
  8. 'dbfindtrigger[name=vc_custname]':{
  9. beforerender:function(f){
  10. Ext.apply(f,{
  11. dbColumns: [{
  12. conditionCode: 'id',
  13. text: "客户ID",
  14. dataIndex: "id",
  15. hidden:true,
  16. xtype: "",
  17. }, {
  18. conditionCode: 'cu_code',
  19. text: "客户编号",
  20. dataIndex: "cu_code",
  21. width: 150,
  22. xtype: "",
  23. }, {
  24. conditionCode: 'cu_name',
  25. text: "客户名称",
  26. dataIndex: "cu_name",
  27. width: 200,
  28. xtype: "",
  29. }, {
  30. conditionCode: 'cu_type',
  31. text: "客户类型",
  32. dataIndex: "cu_type",
  33. width: 110,
  34. xtype: "",
  35. }, {
  36. text: "业务员编号",
  37. dataIndex: "cu_sellercode",
  38. width:110
  39. }, {
  40. text: "业务员",
  41. dataIndex: "cu_sellername",
  42. width:110
  43. }, {
  44. text: "税率(%)",
  45. dataIndex: "cu_taxrate",
  46. xtype: 'numbercolumn',
  47. width:80,
  48. renderer: function(v, m, r) {
  49. return saas.util.BaseUtil.numberFormat(v, 2, false);
  50. }
  51. },{
  52. text: "应收款余额",
  53. dataIndex: "cu_leftamount",
  54. width:110,
  55. xtype: 'numbercolumn',
  56. renderer : function(v, m, r) {
  57. return saas.util.BaseUtil.numberFormat(v, 2, true);
  58. }
  59. }, {
  60. text: "结算天数",
  61. dataIndex: "cu_promisedays",
  62. width:110,
  63. xtype: 'numbercolumn',
  64. renderer: function(v, m, r) {
  65. return Ext.util.Format.number(v, '0');
  66. }
  67. }, {
  68. text: "额度",
  69. dataIndex: "cu_credit",
  70. width:110,
  71. xtype: 'numbercolumn',
  72. }, {
  73. text: "客户地址",
  74. dataIndex: "ca_address",
  75. width: 250
  76. }],
  77. //赋值
  78. dbfinds:[{
  79. from: 'id', to: 'vc_custid',ignore:true
  80. }, {
  81. from:'cu_code', to:'vc_custcode'
  82. },{
  83. from:'cu_name', to:'vc_custname'
  84. },{
  85. from:'cu_currency',to:'vc_currency'
  86. },{
  87. from:'cr_rate',to:'vc_rate'
  88. }
  89. ],
  90. }) ;
  91. }
  92. },
  93. // 转入客户
  94. 'dbfindtrigger[name=vc_turncustname]':{
  95. beforerender:function(f){
  96. Ext.apply(f,{
  97. dbColumns: [{
  98. conditionCode: 'id',
  99. text: "客户ID",
  100. dataIndex: "id",
  101. hidden:true,
  102. xtype: "",
  103. }, {
  104. conditionCode: 'cu_code',
  105. text: "客户编号",
  106. dataIndex: "cu_code",
  107. width: 150,
  108. xtype: "",
  109. }, {
  110. conditionCode: 'cu_name',
  111. text: "客户名称",
  112. dataIndex: "cu_name",
  113. width: 200,
  114. xtype: "",
  115. }, {
  116. conditionCode: 'cu_type',
  117. text: "客户类型",
  118. dataIndex: "cu_type",
  119. width: 110,
  120. xtype: "",
  121. }, {
  122. text: "业务员编号",
  123. dataIndex: "cu_sellercode",
  124. width:110
  125. }, {
  126. text: "业务员",
  127. dataIndex: "cu_sellername",
  128. width:110
  129. }, {
  130. text: "税率(%)",
  131. dataIndex: "cu_taxrate",
  132. xtype: 'numbercolumn',
  133. width:80,
  134. renderer: function(v, m, r) {
  135. return saas.util.BaseUtil.numberFormat(v, 2, false);
  136. }
  137. },{
  138. text: "应收款余额",
  139. dataIndex: "cu_leftamount",
  140. width:110,
  141. xtype: 'numbercolumn',
  142. renderer : function(v, m, r) {
  143. return saas.util.BaseUtil.numberFormat(v, 2, true);
  144. }
  145. }, {
  146. text: "结算天数",
  147. dataIndex: "cu_promisedays",
  148. width:110,
  149. xtype: 'numbercolumn',
  150. renderer: function(v, m, r) {
  151. return Ext.util.Format.number(v, '0');
  152. }
  153. }, {
  154. text: "额度",
  155. dataIndex: "cu_credit",
  156. width:110,
  157. xtype: 'numbercolumn',
  158. }, {
  159. text: "客户地址",
  160. dataIndex: "ca_address",
  161. width: 250
  162. }],
  163. //赋值
  164. dbfinds:[{
  165. from: 'id', to: 'vc_turncustid',ignore:true
  166. }, {
  167. from:'cu_code', to:'vc_turncustcode'
  168. },{
  169. from:'cu_name', to:'vc_turncustname'
  170. }],
  171. }) ;
  172. }
  173. },
  174. // 供应商
  175. 'dbfindtrigger[name=vc_vendname]':{
  176. beforerender: function (f) {
  177. Ext.apply(f, {
  178. dbColumns:[{
  179. text: "供应商ID",
  180. hidden: true,
  181. dataIndex: "id",
  182. xtype: "numbercolumn"
  183. },{
  184. text: "供应商编号",
  185. dataIndex: "ve_code",
  186. width: 150
  187. }, {
  188. text: "供应商名称",
  189. dataIndex: "ve_name",
  190. width: 200
  191. }, {
  192. text: "供应商类型",
  193. dataIndex: "ve_type",
  194. width: 110,
  195. }, {
  196. text: "税率(%)",
  197. dataIndex: "ve_taxrate",
  198. width: 80,
  199. xtype: 'numbercolumn',
  200. align:'end',
  201. renderer : function(v, m, r) {
  202. return saas.util.BaseUtil.numberFormat(v, 2, false);
  203. }
  204. }, {
  205. text: "应付款余额",
  206. dataIndex: "ve_leftamount",
  207. width:110,
  208. xtype: 'numbercolumn',
  209. renderer : function(v, m, r) {
  210. return saas.util.BaseUtil.numberFormat(v, 2, true);
  211. }
  212. },{
  213. text: "结算天数",
  214. dataIndex: "ve_promisedays",
  215. width: 110,
  216. xtype: 'numbercolumn',
  217. align: 'end',
  218. renderer : function(v, m, r) {
  219. return Ext.util.Format.number(v, '0');
  220. }
  221. }, {
  222. text: "纳税人识别号",
  223. dataIndex: "ve_nsrzh",
  224. width: 150
  225. }, {
  226. text: "开户银行",
  227. dataIndex: "ve_bankcode",
  228. width: 150
  229. }, {
  230. text: "银行账户",
  231. dataIndex: "ve_bankaccount",
  232. width: 200
  233. }],
  234. dbfinds: [{
  235. from: 'id',
  236. to: 'vc_vendid',
  237. ignore: true
  238. }, {
  239. from: 've_code',
  240. to: 'vc_vendcode'
  241. }, {
  242. from: 've_name',
  243. to: 'vc_vendname'
  244. },{
  245. from:'cu_currency',to:'vc_currency'
  246. },{
  247. from:'cr_rate',to:'vc_rate'
  248. }
  249. ],
  250. });
  251. }
  252. },
  253. // 转入供应商
  254. 'dbfindtrigger[name=vc_turnvendname]':{
  255. beforerender: function (f) {
  256. Ext.apply(f, {
  257. dbColumns:[{
  258. text: "供应商ID",
  259. hidden: true,
  260. dataIndex: "id",
  261. xtype: "numbercolumn"
  262. },{
  263. text: "供应商编号",
  264. dataIndex: "ve_code",
  265. width: 150
  266. }, {
  267. text: "供应商名称",
  268. dataIndex: "ve_name",
  269. width: 200
  270. }, {
  271. text: "供应商类型",
  272. dataIndex: "ve_type",
  273. width: 110,
  274. }, {
  275. text: "税率(%)",
  276. dataIndex: "ve_taxrate",
  277. width: 80,
  278. xtype: 'numbercolumn',
  279. align:'end',
  280. renderer : function(v, m, r) {
  281. return saas.util.BaseUtil.numberFormat(v, 2, false);
  282. }
  283. }, {
  284. text: "应付款余额",
  285. dataIndex: "ve_leftamount",
  286. width:110,
  287. xtype: 'numbercolumn',
  288. renderer : function(v, m, r) {
  289. return saas.util.BaseUtil.numberFormat(v, 2, true);
  290. }
  291. },{
  292. text: "结算天数",
  293. dataIndex: "ve_promisedays",
  294. width: 110,
  295. xtype: 'numbercolumn',
  296. align: 'end',
  297. renderer : function(v, m, r) {
  298. return Ext.util.Format.number(v, '0');
  299. }
  300. }, {
  301. text: "纳税人识别号",
  302. dataIndex: "ve_nsrzh",
  303. width: 150
  304. }, {
  305. text: "开户银行",
  306. dataIndex: "ve_bankcode",
  307. width: 150
  308. }, {
  309. text: "银行账户",
  310. dataIndex: "ve_bankaccount",
  311. width: 200
  312. }],
  313. dbfinds: [{
  314. from: 'id',
  315. to: 'vc_turnvendid',
  316. ignore: true
  317. }, {
  318. from: 've_code',
  319. to: 'vc_turnvendcode'
  320. }, {
  321. from: 've_name',
  322. to: 'vc_turnvendname'
  323. }],
  324. });
  325. }
  326. },
  327. // 来源单号1
  328. 'oriOrderMutiDbfindTrigger[name=vd_slcode]': {
  329. beforerender: function (f) {
  330. Ext.apply(f, {
  331. dbfinds: [{
  332. from: 'id',
  333. to: 'vd_slid',ignore:true
  334. }, {
  335. from: 'sl_code',
  336. to: 'vd_slcode'
  337. },{
  338. from: 'sl_orderamount',
  339. to: 'vd_amount'
  340. },{
  341. from: 'sl_yamount',
  342. to: 'sl_yamount'
  343. },{
  344. from: 'sl_namount',
  345. to: 'sl_namount'
  346. },{
  347. from:'sl_date',
  348. to:'vd_sldate'
  349. },{
  350. from:'sl_kind',
  351. to:'vd_slkind'
  352. },{
  353. from: 'sl_namount',
  354. to: 'vd_nowbalance'
  355. }],
  356. });
  357. },
  358. beforequery: function(f) {
  359. var defaultCondition = this.getDefaultCondition(0);
  360. if(!defaultCondition) {
  361. return false;
  362. }
  363. Ext.apply(f, {
  364. defaultCondition: defaultCondition
  365. });
  366. },
  367. beforetriggerclick: function(f) {
  368. var defaultCondition = this.getDefaultCondition(0);
  369. if(!defaultCondition) {
  370. return false;
  371. }
  372. Ext.apply(f, {
  373. defaultCondition: defaultCondition
  374. });
  375. }
  376. },
  377. // 来源单号2
  378. 'oriOrderMutiDbfindTrigger[name=vcd_slcode]': {
  379. beforerender: function (f) {
  380. Ext.apply(f, {
  381. dbfinds: [{
  382. from: 'id',
  383. to: 'vcd_slid',ignore:true
  384. }, {
  385. from: 'sl_code',
  386. to: 'vcd_slcode'
  387. },{
  388. from: 'sl_orderamount',
  389. to: 'vcd_amount'
  390. },{
  391. from: 'sl_yamount',
  392. to: 'sl_yamount'
  393. },{
  394. from: 'sl_namount',
  395. to: 'sl_namount'
  396. },{
  397. from:'sl_date',
  398. to:'vcd_sldate'
  399. },{
  400. from:'sl_kind',
  401. to:'vcd_slkind'
  402. },{
  403. from: 'sl_namount',
  404. to: 'vcd_nowbalance'
  405. }],
  406. });
  407. },
  408. beforequery: function(f) {
  409. var defaultCondition = this.getDefaultCondition(1);
  410. if(!defaultCondition) {
  411. return false;
  412. }
  413. Ext.apply(f, {
  414. defaultCondition: defaultCondition
  415. });
  416. },
  417. beforetriggerclick: function(f) {
  418. var defaultCondition = this.getDefaultCondition(1);
  419. if(!defaultCondition) {
  420. return false;
  421. }
  422. Ext.apply(f, {
  423. defaultCondition: defaultCondition
  424. });
  425. }
  426. },
  427. });
  428. },
  429. getDefaultCondition: function(idx) {
  430. var me = this,
  431. form = me.getView(),
  432. formItems = form.formItems,
  433. viewModel = me.getViewModel(),
  434. acitveType = form.acitveType,
  435. etc = form.etc,
  436. defaultConditions = etc.defaultConditions,
  437. defaultConditionMode = defaultConditions[acitveType][idx];
  438. var reg = /(.*){(.*)}(.*)/g;
  439. var fieldName = defaultConditionMode.match(/(.*){(.*)}(.*)/)[2];
  440. var fieldLabel = Ext.Array.findBy(formItems, function(f) {
  441. return f.name == fieldName;
  442. }).fieldLabel;
  443. var fieldValue = viewModel.get(fieldName);
  444. if(!fieldValue) {
  445. saas.util.BaseUtil.showErrorToast('请先选择【' + '<span style="color: red;">' + fieldLabel + '</span>】');
  446. return null;
  447. }
  448. var defaultCondition = defaultConditionMode.replace(reg, '$1' + fieldValue + '$3');
  449. return defaultCondition;
  450. },
  451. /**
  452. * 清空所有从表数据
  453. */
  454. clearDetails: function() {
  455. var me = this;
  456. me.clearDetail0();
  457. me.clearDetail1();
  458. },
  459. /**
  460. * 清空第一个从表数据
  461. */
  462. clearDetail0: function(f, n, o) {
  463. var me = this,
  464. form = me.getView(),
  465. grid = form.query('detailGridField')[0];
  466. me.clearDetail(grid);
  467. },
  468. /**
  469. * 清空第二个从表数据
  470. */
  471. clearDetail1: function() {
  472. var me = this,
  473. form = me.getView(),
  474. grid = form.query('detailGridField')[1];
  475. me.clearDetail(grid);
  476. },
  477. /**
  478. * 清空一个从表数据
  479. */
  480. clearDetail: function(grid) {
  481. var datas = [],
  482. emptyRows = grid.emptyRows,
  483. detnoColumn = grid.detnoColumn,
  484. detno = 0,
  485. store = grid.getStore();
  486. Ext.Array.each(new Array(emptyRows), function() {
  487. detno += 1;
  488. var data = {};
  489. data[detnoColumn] = detno;
  490. datas.push(data);
  491. })
  492. store.removeAll();
  493. store.add(datas);
  494. // 不写该方法合计列会错位,这里触发afterEdit事件用来刷新grid
  495. store.getAt(0) ? store.afterEdit(store.getAt(0), ['']) : null;
  496. },
  497. onSave: function() {
  498. var me = this,
  499. form = me.getView(),
  500. viewModel = me.getViewModel(),
  501. store1 = viewModel.get('detail0').detailStore,
  502. store2 = viewModel.get('detail1').detailStore;
  503. var valid = form.isValid();
  504. if(!valid) {
  505. saas.util.BaseUtil.showErrorToast(form.invalidText);
  506. return false;
  507. }
  508. var sum_detail1 = store1.sum('vd_nowbalance'); // 从表1核销合计
  509. var sum_detail2 = store2.sum('vcd_nowbalance'); // 从表2核销合计
  510. viewModel.set("vc_amount1",sum_detail1);
  511. viewModel.set("vc_amount2",sum_detail2);
  512. me.save();
  513. },
  514. save:function(){
  515. var me = this,
  516. form = this.getView(),
  517. codeField = form.getForm().findField(form._codeField),
  518. detailCount = form.detailCount,
  519. viewModel = me.getViewModel(),
  520. codeModified = codeField && codeField.isDirty();
  521. //form里面数据
  522. var formData = form.getSaveData();
  523. var params = {
  524. main:formData.main
  525. };
  526. for(var i = 0; i < detailCount; i++) {
  527. params['items' + ( i + 1)] = formData['detail' + i];
  528. }
  529. params.codeModified = codeModified;
  530. form.setLoading(true);
  531. saas.util.BaseUtil.request({
  532. url: form._saveUrl,
  533. params: JSON.stringify(params),
  534. method: 'POST',
  535. })
  536. .then(function(localJson) {
  537. form.setLoading(false);
  538. if(localJson.success){
  539. var id = localJson.data.id;
  540. var code = localJson.data.code;
  541. form.initId = id;
  542. saas.util.FormUtil.loadData(form);
  543. saas.util.BaseUtil.showSuccessToast('保存成功');
  544. var newId = form.xtype + '-' + id;
  545. var newTitle = form._title + '(' + code + ')';
  546. saas.util.BaseUtil.refreshTabTitle(newId, newTitle);
  547. form.fireEvent('aftersave', true, form, localJson);
  548. }
  549. })
  550. .catch(function(e) {
  551. form.setLoading(false);
  552. saas.util.BaseUtil.showErrorToast('保存失败: ' + e.message);
  553. form.fireEvent('aftersave', false, form);
  554. });
  555. },
  556. audit: function() {
  557. var me = this,
  558. form = me.getView(),
  559. viewModel = me.getViewModel(),
  560. detailCount = form.detailCount,
  561. codeField = form.getForm().findField(form._codeField),
  562. codeModified = !form.initId || (codeField && codeField.isDirty());;
  563. //form里面数据
  564. var formData = form.getFormData();
  565. var params = {
  566. main: formData.main
  567. };
  568. for(var i = 0; i < detailCount; i++) {
  569. params['items' + ( i + 1)] = formData['detail' + i];
  570. }
  571. params.codeModified = codeModified;
  572. form.setLoading(true);
  573. saas.util.BaseUtil.request({
  574. url: form._auditUrl,
  575. params: JSON.stringify(params),
  576. method: 'POST',
  577. })
  578. .then(function(localJson) {
  579. form.setLoading(false);
  580. if(localJson.success){
  581. // 未保存直接审核会返回id
  582. if(localJson.data) {
  583. var id = localJson.data.id;
  584. var code = localJson.data.code;
  585. form.initId = id;
  586. var newId = form.xtype + '-' + id;
  587. var newTitle = form._title + '(' + code + ')';
  588. saas.util.BaseUtil.refreshTabTitle(newId, newTitle);
  589. }
  590. saas.util.FormUtil.loadData(form);
  591. form.setEditable(false);
  592. saas.util.BaseUtil.showSuccessToast('审核成功' + (localJson.message ? ': ' + localJson.message : ''));
  593. form.fireEvent('afteraudit', true, form, localJson);
  594. }
  595. })
  596. .catch(function(e) {
  597. form.setLoading(false);
  598. saas.util.BaseUtil.showErrorToast('审核失败: ' + e.message);
  599. form.fireEvent('afteraudit', false, form);
  600. });
  601. },
  602. myInitCopyData: function(formData) {
  603. var me = this,
  604. form = me.getView();
  605. //录入人,录入日期,审核人,审核日期清空
  606. formData.main['creatorId'] = saas.util.BaseUtil.getCurrentUser().id;
  607. formData.main['creatorName'] = saas.util.BaseUtil.getCurrentUser().realname;
  608. formData.main['createTime'] = Ext.Date.format(new Date(), 'Y-m-d H:i:s');
  609. formData.main['updaterId'] = undefined;
  610. formData.main['updaterName'] = undefined;
  611. formData.main['updateTime'] = undefined;
  612. formData.main[form._auditmanField] = undefined;
  613. formData.main[form._auditdateField] = undefined;
  614. return formData;
  615. },
  616. refresh: function() {
  617. var me = this,
  618. form = me.getView(),
  619. viewModel = me.getViewModel(),
  620. xtype = form.xtype,
  621. _config = {
  622. initId: form.initId,
  623. init_vc_kind: viewModel.get('vc_kind'),
  624. },
  625. currentTab = saas.util.BaseUtil.getCurrentTab();
  626. var view = {
  627. _config: _config,
  628. xtype: xtype
  629. };
  630. Ext.apply(view, _config);
  631. Ext.suspendLayouts();
  632. currentTab.removeAll();
  633. currentTab.add(view);
  634. Ext.resumeLayouts(true);
  635. },
  636. });