FormPanelController.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. Ext.define('make.view.make.makeBase.FormPanelController', {
  2. extend: 'saas.view.core.form.FormPanelController',
  3. alias: 'controller.make-makebase-formpanel',
  4. init: function (form) {
  5. var me = this;
  6. this.control({
  7. 'dbfindtrigger[name=ma_prodcode]':{
  8. beforerender:function(f){
  9. Ext.apply(f,{
  10. //放大镜赋值设置
  11. dbfinds:[{
  12. from:'id',to:'ma_prodid',ignore:true
  13. },{
  14. from:'pr_code',to:'ma_prodcode'
  15. },{
  16. from:'pr_detail',to:'pr_detail'
  17. },{
  18. from:'pr_spec',to:'pr_spec'
  19. },{
  20. from: 'pr_brand', to: 'pr_brand'
  21. },{
  22. from: 'pr_orispeccode', to: 'pr_orispeccode'
  23. },{
  24. from: 'pr_unit', to: 'pr_unit'
  25. }],
  26. });
  27. }
  28. },
  29. 'saledetailDbfindTrigger[name=ma_salecode]':{
  30. beforerender:function(f){
  31. Ext.apply(f,{
  32. //放大镜赋值设置
  33. dbfinds:[{
  34. from:'sa_id',to:'ma_saleid',ignore:true
  35. },{
  36. from:'sa_code',to:'ma_salecode'
  37. },{
  38. from:'sa_custname',to:'ma_custname'
  39. },{
  40. from:'sa_custid',to:'ma_custid'
  41. },{
  42. from: 'sa_custcode', to: 'ma_custcode'
  43. },{
  44. from: 'sd_delivery', to: 'ma_delivery'
  45. },{
  46. from: 'sd_prodcode', to: 'ma_prodcode'
  47. },{
  48. from: 'pr_detail', to: 'pr_detail'
  49. },{
  50. from: 'pr_spec', to: 'pr_spec'
  51. },{
  52. from: 'pr_orispeccode', to: 'pr_orispeccode'
  53. },{
  54. from:'sd_prodid',to:'ma_prodid'
  55. },{
  56. from: 'pr_brand', to: 'pr_brand'
  57. },],
  58. });
  59. }
  60. },
  61. //从表多选放大镜赋值关系 以及 tpl模板
  62. 'multidbfindtrigger[name=mm_prodcode]':{
  63. beforerender:function(f){
  64. Ext.apply(f,{
  65. //放大镜赋值设置
  66. dbfinds:[{
  67. from:'id',to:'mm_prodid',ignore:true
  68. },{
  69. from:'pr_code',to:'mm_prodcode'
  70. },{
  71. from:'pr_detail',to:'pr_detail'
  72. },{
  73. from:'pr_spec',to:'pr_spec'
  74. },{
  75. from: 'pr_brand', to: 'pr_brand'
  76. },{
  77. from: 'pr_orispeccode', to: 'pr_orispeccode'
  78. },{
  79. from: 'pr_unit', to: 'pr_unit'
  80. },{
  81. from: 'pu_decimal', to: 'pu_decimal'
  82. }],
  83. });
  84. }
  85. },
  86. 'multidbfindtrigger[name=pr_detail]': {
  87. beforerender: function (f) {
  88. Ext.apply(f, {
  89. dbfinds:[{
  90. from:'id',to:'mm_prodid',ignore:true
  91. },{
  92. from:'pr_code',to:'mm_prodcode'
  93. },{
  94. from:'pr_detail',to:'pr_detail'
  95. },{
  96. from:'pr_spec',to:'pr_spec'
  97. },{
  98. from: 'pr_brand', to: 'pr_brand'
  99. },{
  100. from: 'pr_orispeccode', to: 'pr_orispeccode'
  101. },{
  102. from: 'pr_unit', to: 'pr_unit'
  103. },{
  104. from: 'pu_decimal', to: 'pu_decimal'
  105. }],
  106. });
  107. }
  108. }
  109. });
  110. },
  111. /**
  112. * 单位用量改变改变,级联事件
  113. * @param {*} field
  114. */
  115. onOneUseChange: function (field) {
  116. if (field.value) {
  117. var me = this,
  118. view = me.getView(),
  119. vm = view.getViewModel(),
  120. oneuseqty = field.value || 0,
  121. ma_qty = vm.get('ma_qty') || 0,
  122. record = view.down('detailGridField').selModel.getLastSelected(),
  123. decimal = record.get('pu_decimal')||(record.get('productDTO')?record.get('productDTO')['pu_decimal']:0);
  124. if(ma_qty>0){
  125. qty = Number(Math.ceil(oneuseqty * ma_qty*Math.pow(10,decimal))/Math.pow(10,decimal));
  126. if(record.data['mm_qty'] != qty){
  127. record.set('mm_qty', qty);
  128. }
  129. }
  130. }
  131. },
  132. /**
  133. * 用料表计算
  134. */
  135. calMaterial: function(){
  136. var me = this,
  137. form = me.getView(),
  138. id = form.getForm().findField(form._idField);
  139. form.setLoading(true);
  140. saas.util.BaseUtil.request({
  141. url: form._calMaterial + '/' + id.value,
  142. method: 'POST',
  143. })
  144. .then(function (localJson) {
  145. form.setLoading(false);
  146. if (localJson.success) {
  147. saas.util.BaseUtil.showSuccessToast('用料计算成功');
  148. saas.util.FormUtil.loadData(form);
  149. }
  150. })
  151. .catch(function (e) {
  152. form.setLoading(false);
  153. saas.util.BaseUtil.showErrorToast('用料计算失败: ' + e.message);
  154. });
  155. },
  156. /**
  157. * 生成领料单
  158. */
  159. turnPick: function(){
  160. var me = this,
  161. form = me.getView(),
  162. id = form.getForm().findField(form._idField);
  163. form.setLoading(true);
  164. saas.util.BaseUtil.request({
  165. url: form._turnPick + '/' + id.value,
  166. method: 'POST',
  167. })
  168. .then(function (localJson) {
  169. form.setLoading(false);
  170. if (localJson.success) {
  171. var intValue = localJson.data.id,
  172. codeValue = localJson.data.code,
  173. name = '生产领料';
  174. saas.util.BaseUtil.openTab('make-makepick-formpanel', name + "(" + codeValue + ")", codeValue + intValue, {
  175. initId: intValue
  176. });
  177. saas.util.BaseUtil.showSuccessToast('转单成功');
  178. saas.util.FormUtil.loadData(form);
  179. }
  180. })
  181. .catch(function (e) {
  182. form.setLoading(false);
  183. saas.util.BaseUtil.showErrorToast('转单失败: ' + e.message);
  184. });
  185. },
  186. /**
  187. * 生成退料单
  188. */
  189. turnBack: function(){
  190. var me = this,
  191. form = me.getView(),
  192. id = form.getForm().findField(form._idField);
  193. form.setLoading(true);
  194. saas.util.BaseUtil.request({
  195. url: form._turnBack + '/' + id.value,
  196. method: 'POST',
  197. })
  198. .then(function (localJson) {
  199. form.setLoading(false);
  200. if (localJson.success) {
  201. var intValue = localJson.data.id,
  202. codeValue = localJson.data.code,
  203. name = '生产退料';
  204. saas.util.BaseUtil.openTab('make-makereturn-formpanel', name + "(" + codeValue + ")", codeValue + intValue, {
  205. initId: intValue
  206. });
  207. saas.util.BaseUtil.showSuccessToast('转单成功');
  208. saas.util.FormUtil.loadData(form);
  209. }
  210. })
  211. .catch(function (e) {
  212. form.setLoading(false);
  213. saas.util.BaseUtil.showErrorToast('转单失败: ' + e.message);
  214. });
  215. },
  216. /**
  217. * 生成报废单
  218. */
  219. turnScrap: function(){
  220. var me = this,
  221. form = me.getView(),
  222. id = form.getForm().findField(form._idField);
  223. form.setLoading(true);
  224. saas.util.BaseUtil.request({
  225. url: form._turnScrap + '/' + id.value,
  226. method: 'POST',
  227. })
  228. .then(function (localJson) {
  229. form.setLoading(false);
  230. if (localJson.success) {
  231. var intValue = localJson.data.id,
  232. codeValue = localJson.data.code,
  233. name = '生产报废';
  234. saas.util.BaseUtil.openTab('make-makescrap-formpanel', name + "(" + codeValue + ")", codeValue + intValue, {
  235. initId: intValue
  236. });
  237. saas.util.BaseUtil.showSuccessToast('转单成功');
  238. saas.util.FormUtil.loadData(form);
  239. }
  240. })
  241. .catch(function (e) {
  242. form.setLoading(false);
  243. saas.util.BaseUtil.showErrorToast('转单失败: ' + e.message);
  244. });
  245. },
  246. /**
  247. * 生成完工入库单
  248. */
  249. turnIn: function(){
  250. var me = this,
  251. form = me.getView(),
  252. id = form.getForm().findField(form._idField);
  253. form.setLoading(true);
  254. saas.util.BaseUtil.request({
  255. url: form._turnIn + '/' + id.value,
  256. method: 'POST',
  257. })
  258. .then(function (localJson) {
  259. form.setLoading(false);
  260. if (localJson.success) {
  261. var intValue = localJson.data.id,
  262. codeValue = localJson.data.code,
  263. name ='完工入库';
  264. saas.util.BaseUtil.openTab('make-makein-formpanel', name + "(" + codeValue + ")", codeValue + intValue, {
  265. initId: intValue
  266. });
  267. saas.util.BaseUtil.showSuccessToast('转单成功');
  268. saas.util.FormUtil.loadData(form);
  269. }
  270. })
  271. .catch(function (e) {
  272. form.setLoading(false);
  273. saas.util.BaseUtil.showErrorToast('转单失败: ' + e.message);
  274. });
  275. },
  276. /**
  277. * 结案
  278. */
  279. end: function(){
  280. var me = this,
  281. form = me.getView(),
  282. id = form.getForm().findField(form._idField);
  283. form.setLoading(true);
  284. saas.util.BaseUtil.request({
  285. url: form._end + '/' + id.value,
  286. method: 'POST',
  287. })
  288. .then(function (localJson) {
  289. form.setLoading(false);
  290. if (localJson.success) {
  291. if(localJson.data){
  292. //弹出结案检测的结果,弹出window
  293. me.showEndCheckDataWin(localJson.data);
  294. }else{
  295. saas.util.BaseUtil.showSuccessToast('结案成功');
  296. saas.util.FormUtil.loadData(form);
  297. }
  298. }
  299. })
  300. .catch(function (e) {
  301. form.setLoading(false);
  302. saas.util.BaseUtil.showErrorToast('结案失败: ' + e.message);
  303. });
  304. },
  305. /**
  306. * 反结案
  307. */
  308. resEnd: function(){
  309. var me = this,
  310. form = me.getView(),
  311. id = form.getForm().findField(form._idField);
  312. form.setLoading(true);
  313. saas.util.BaseUtil.request({
  314. url: form._resEnd + '/' + id.value,
  315. method: 'POST',
  316. })
  317. .then(function (localJson) {
  318. form.setLoading(false);
  319. if (localJson.success) {
  320. saas.util.BaseUtil.showSuccessToast('反结案成功');
  321. saas.util.FormUtil.loadData(form);
  322. }
  323. })
  324. .catch(function (e) {
  325. form.setLoading(false);
  326. saas.util.BaseUtil.showErrorToast('反结案失败: ' + e.message);
  327. });
  328. },
  329. /**
  330. * 修改用料
  331. */
  332. modifyMaterial: function(button){
  333. //需要先选中行
  334. var me = this,
  335. form = me.getView(),
  336. grid = form.down('detailGridField'),
  337. record = grid.selModel.getLastSelected(),
  338. vm = form.getViewModel();
  339. if(null == record || record.get('mm_id')){
  340. saas.util.BaseUtil.showErrorToast('请先选择明细行');
  341. }else{
  342. me.materialDialog = form.add({
  343. xtype: 'make-makebase-modifymaterialwin',
  344. _parent:form,
  345. });
  346. me.materialDialog.getViewModel().set('form',{
  347. id:record.get('id'),
  348. mm_detno:record.get('mm_detno'),
  349. mm_prodid:record.get('mm_prodid'),
  350. mm_prodcode:record.get('mm_prodcode'),
  351. mm_oneuseqty:record.get('mm_oneuseqty'),
  352. mm_qty:record.get('mm_qty'),
  353. mm_remark:record.get('mm_remark'),
  354. pr_detail:record.get('pr_detail'),
  355. pr_spec:record.get('pr_spec'),
  356. pr_brand:record.get('pr_brand'),
  357. pr_orispeccode:record.get('pr_orispeccode'),
  358. pu_decimal: record.get('pu_decimal')||record.get('productDTO')['pu_decimal']});
  359. me.materialDialog.getViewModel().set('ma_qty',vm.get('ma_qty'));
  360. me.materialDialog.getViewModel().set('ma_id',vm.get('id'));
  361. me.materialDialog.show();
  362. }
  363. },
  364. /**
  365. * 工单变更
  366. */
  367. modifyMake: function(){
  368. var me = this,
  369. base = me.getView(),
  370. vm = base.getViewModel();
  371. var win = base.add(Ext.create('Ext.window.Window', {
  372. cls: 'x-window-dbfind',
  373. modal: true,
  374. minHeight: 150,
  375. width: 800,
  376. title: '工单变更',
  377. bodyPadding: 10,
  378. constrain: true,
  379. closable: true,
  380. layout: 'anchor',
  381. renderTo: base.getEl(),
  382. viewModel: {
  383. data: {
  384. make:{
  385. id:vm.get('id'),
  386. ma_code:vm.get('ma_code'),
  387. ma_prodcode:vm.get('ma_prodcode'),
  388. ma_qty:0,
  389. ma_turnmadeqty:vm.get('ma_turnmadeqty')
  390. },
  391. oldmake:{
  392. ma_oldqty:vm.get('ma_qty'),
  393. }
  394. }
  395. },
  396. items: [{
  397. xtype: 'form',
  398. layout: 'column',
  399. autoScroll: true,
  400. buttonAlign : 'center',
  401. _saveUrl:'/api/make/make/modifyMake',
  402. defaults:{
  403. columnWidth:0.33 ,
  404. margin: '0 0 10 0',
  405. labelAlign: 'right',
  406. labelWidth: 90,
  407. },
  408. bodyPadding: '8 12 8 12',
  409. items:[{
  410. xtype: 'hidden',
  411. fieldLabel: 'ID',
  412. allowBlank: false,
  413. bind:'{make.id}',
  414. },{
  415. xtype: 'textfield',
  416. name: 'ma_code',
  417. fieldLabel: '制造单号',
  418. allowBlank: false,
  419. readOnly: true,
  420. bind:'{make.ma_code}',
  421. },{
  422. xtype: 'textfield',
  423. name: 'ma_prodcode',
  424. fieldLabel: '产品编号',
  425. allowBlank: false,
  426. readOnly: true,
  427. bind:'{make.ma_prodcode}',
  428. },{
  429. xtype: 'textfield',
  430. name: 'ma_oldqty',
  431. fieldLabel: '原数量',
  432. readOnly: true,
  433. bind:'{oldmake.ma_oldqty}',
  434. },{
  435. xtype: 'numberfield',
  436. name: 'ma_qty',
  437. fieldLabel: '新数量',
  438. allowBlank: false,
  439. bind:'{make.ma_qty}',
  440. decimalPrecision: 6,
  441. },{
  442. xtype: 'numberfield',
  443. name: 'ma_turnmadeqty',
  444. fieldLabel: '已转完工数',
  445. readOnly: true,
  446. bind:'{make.ma_turnmadeqty}',
  447. }],
  448. buttons: [{
  449. text:'保存',
  450. disabled: true,
  451. formBind: true,
  452. handler:'onWinMSave'
  453. },{
  454. text: '关闭',
  455. handler:'onWinMClose'
  456. }]
  457. }],
  458. }));
  459. win.show();
  460. },
  461. //工单变更修改
  462. onWinMSave:function(btn){
  463. var me = this;
  464. view = btn.ownerCt.ownerCt.ownerCt,
  465. vm = view.getViewModel(),
  466. form = view.down('form'),
  467. params = Ext.clone(vm.get('make')),
  468. oldmake = Ext.clone(vm.get('oldmake'));
  469. if(Ext.isEmpty(params.ma_qty)){
  470. saas.util.BaseUtil.showErrorToast('新数量不能为空!');
  471. return false;
  472. }
  473. if(params.ma_qty<=0){
  474. saas.util.BaseUtil.showErrorToast('新数量不能小于等于0,如需关闭工单,请使用结案功能!');
  475. return false;
  476. }
  477. if(params.ma_qty == oldmake.ma_oldqty){
  478. saas.util.BaseUtil.showErrorToast('新数量等于旧数量无须变更!');
  479. return false;
  480. }
  481. view.setLoading(true);
  482. saas.util.BaseUtil.request({
  483. url: form._saveUrl,
  484. params: JSON.stringify(params),
  485. method: 'POST',
  486. })
  487. .then(function(localJson) {
  488. view.setLoading(false);
  489. if(localJson.success){
  490. saas.util.BaseUtil.showSuccessToast('修改成功');
  491. me.onWinMClose(btn);
  492. //刷新工单页面
  493. saas.util.FormUtil.loadData(me.getView());
  494. }
  495. })
  496. .catch(function(e) {
  497. view.setLoading(false);
  498. saas.util.BaseUtil.showErrorToast('修改失败: ' + e.message);
  499. });
  500. },
  501. onWinMClose:function(btn){
  502. btn.ownerCt.ownerCt.ownerCt.close();
  503. },
  504. /**
  505. * 显示结案检测结果弹框
  506. */
  507. showEndCheckDataWin: function(data){
  508. var me = this,
  509. base = me.getView(),
  510. vm = base.getViewModel();
  511. tab = saas.util.BaseUtil.getCurrentTab(),
  512. win = tab.add({
  513. xtype: 'make-makebase-endcheck-window',
  514. modal: true,
  515. onConfirm: function () {
  516. win.close();
  517. }
  518. });
  519. win.show();
  520. win.loadData(data);
  521. },
  522. });