CustomerProduct.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.product.CustomerProduct', {
  3. extend : 'Ext.app.Controller',
  4. FormUtil : Ext.create('erp.util.FormUtil'),
  5. GridUtil : Ext.create('erp.util.GridUtil'),
  6. views : [ 'core.form.Panel', 'core.grid.Panel2', 'scm.product.CustomerProduct', 'core.trigger.DbfindTrigger',
  7. 'core.button.Save', 'core.button.Update', 'core.button.Close', 'core.button.Sync', 'core.button.Add' ],
  8. refs : [ {
  9. ref : 'form',
  10. selector : '#form'
  11. },{
  12. ref : 'grid',
  13. selector : '#grid'
  14. } ],
  15. init : function() {
  16. var me = this;
  17. me.control({
  18. 'erpGridPanel2': {
  19. itemclick: function(sel, item) {
  20. me.GridUtil.onGridItemClick(sel, item);
  21. },
  22. reconfigure: function() {
  23. me.setSyncdatas();
  24. },
  25. storeloaded: function() {
  26. me.setSyncdatas();
  27. }
  28. },
  29. 'field[name=cp_custcode]': {
  30. afterrender: function(t) {
  31. var v = getUrlParam('cp_custcode');
  32. if(!Ext.isEmpty(v)) {
  33. t.setValue(v);
  34. (typeof t.autoDbfind === 'function')
  35. && t.autoDbfind('form', caller, 'cp_custcode', 'cu_code=\'' + v + '\'');
  36. me.loadData(v);
  37. }
  38. },
  39. aftertrigger: function(t) {
  40. if(t.isDirty())
  41. me.loadData(t.getValue());
  42. }
  43. },
  44. 'erpAddButton': {
  45. click: function() {
  46. me.FormUtil.onAdd(null, '客户物料对照', 'jsps/scm/product/custprod.jsp');
  47. }
  48. },
  49. 'erpCloseButton': {
  50. click: function(btn){
  51. me.FormUtil.beforeClose(me);
  52. }
  53. },
  54. 'erpSaveButton': {
  55. click: function(btn) {
  56. if(me.getForm().getForm().isValid()) {
  57. me.onSave();
  58. }
  59. }
  60. }
  61. });
  62. },
  63. loadData : function(cust) {
  64. if (!Ext.isEmpty(cust)) {
  65. var grid = this.getGrid();
  66. grid.GridUtil.loadNewStore(grid, {
  67. caller : caller,
  68. condition : 'cp_custcode=\'' + cust + '\''
  69. });
  70. }
  71. },
  72. onSave: function() {
  73. var me = this, arr = new Array(), cust = me.getForm().down('#cp_custcode').getValue();
  74. me.getGrid().store.each(function(i){
  75. if(i.dirty) {
  76. var d = i.data;
  77. if(!Ext.isEmpty(d.cp_prcode) && !Ext.isEmpty(d.cp_custprcode)) {
  78. delete d.pr_detail;
  79. delete d.pr_spec;
  80. d.cp_custcode = cust;
  81. arr.push(d);
  82. }
  83. }
  84. });
  85. if(arr.length > 0) {
  86. me.FormUtil.setLoading(true);
  87. Ext.Ajax.request({
  88. url: basePath + me.getForm().saveUrl,
  89. params: {
  90. param: Ext.encode(arr),
  91. caller: caller
  92. },
  93. callback: function(opt, s, res) {
  94. me.FormUtil.setLoading(false);
  95. var r = Ext.decode(res.responseText);
  96. if(r.success) {
  97. showMessage('提示', '保存成功', 1500);
  98. window.location.href = basePath + 'jsps/scm/product/custprod.jsp?cp_custcode=' + cust;
  99. } else if(r.exceptionInfo) {
  100. showError(r.exceptionInfo);
  101. }
  102. }
  103. });
  104. }
  105. },
  106. setSyncdatas: function() {
  107. var btn = this.getForm().down('erpSyncButton');
  108. if(btn) {
  109. var arr = [], i;
  110. this.getGrid().store.each(function(){
  111. i = this.get('cp_id');
  112. if(!Ext.isEmpty(i) && Number(i) > 0) {
  113. arr.push(i);
  114. }
  115. });
  116. btn.syncdatas = arr.join(',');
  117. }
  118. }
  119. });