ProdFeature.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.bom.ProdFeature', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. views:[
  8. 'core.form.Panel','pm.bom.ProdFeature','core.grid.Panel2','core.toolbar.Toolbar',
  9. 'core.button.Save','core.button.Add','core.button.Upload','core.form.YnField',
  10. 'core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail',
  11. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.grid.YnColumn','core.trigger.MultiDbfindTrigger'
  12. ],
  13. init:function(){
  14. var me = this;
  15. this.control({
  16. 'erpGridPanel2': {
  17. itemclick: function(selModel, record){
  18. this.onGridItemClick(selModel, record);
  19. },
  20. afterrender:function(grid){
  21. grid.setReadOnly(false);
  22. }
  23. },
  24. 'erpSaveButton': {
  25. afterrender:function(btn){
  26. btn.ownerCt.insert(2,{
  27. text: $I18N.common.button.erpCloseButton,
  28. iconCls: 'x-button-icon-close',
  29. cls: 'x-btn-gray',
  30. width: 60,
  31. style: {
  32. marginLeft: '10px'
  33. },
  34. handler:function(){
  35. var win=Ext.getCmp('win');
  36. if(win) win.close();
  37. }
  38. });
  39. var form=Ext.getCmp('form');
  40. data=form.getValues();
  41. Ext.getCmp('pf_prodcode').setValue(data.pr_code);
  42. Ext.getCmp('pf_prid').setValue(data.pr_id);
  43. },
  44. click:function(btn){
  45. var form=btn.ownerCt.ownerCt;
  46. r=form.getValues();
  47. var params = new Object();
  48. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  49. var me = this;
  50. Ext.Ajax.request({
  51. url : basePath + form.saveUrl,
  52. params : params,
  53. method : 'post',
  54. callback : function(options,success,response){
  55. var localJson = new Ext.decode(response.responseText);
  56. if(localJson.success){
  57. saveSuccess(function(){
  58. var grid=Ext.getCmp('grid');
  59. var param={
  60. caller:caller,
  61. condition:'pf_prid='+r.pf_prid
  62. };
  63. btn.ownerCt.ownerCt.ownerCt.close();
  64. grid.GridUtil.loadNewStore(grid,param);
  65. });
  66. } else if(localJson.exceptionInfo){
  67. var str = localJson.exceptionInfo;
  68. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  69. str = str.replace('AFTERSUCCESS', '');
  70. saveSuccess(function(){
  71. //add成功后刷新页面进入可编辑的页面
  72. var value = r[form.keyField];
  73. var formCondition = form.keyField + "IS" + value ;
  74. var gridCondition = '';
  75. var grid = Ext.getCmp('grid');
  76. if(grid && grid.mainField){
  77. gridCondition = grid.mainField + "IS" + value;
  78. }
  79. if(me.contains(window.location.href, '?', true)){
  80. window.location.href = window.location.href + '&formCondition=' +
  81. formCondition + '&gridCondition=' + gridCondition;
  82. } else {
  83. window.location.href = window.location.href + '?formCondition=' +
  84. formCondition + '&gridCondition=' + gridCondition;
  85. }
  86. });
  87. showError(str);
  88. } else {
  89. showError(str);
  90. return;
  91. }
  92. } else{
  93. saveFailure();//@i18n/i18n.js
  94. }
  95. }
  96. });
  97. }
  98. },
  99. 'erpDeleteButton' : {
  100. afterrender: function(btn){
  101. if(Ext.getCmp('pr_id').value != null && Ext.getCmp('pr_id').value != ''){
  102. btn.show();
  103. } else {
  104. btn.hide();
  105. }
  106. },
  107. click: function(btn){
  108. me.FormUtil.onDelete(Ext.getCmp('pr_id').value);
  109. }
  110. },
  111. 'erpUpdateButton': {
  112. afterrender: function(btn){
  113. if(Ext.getCmp('pr_id').value != null && Ext.getCmp('pr_id').value != ''){
  114. btn.show();
  115. } else {
  116. btn.hide();
  117. }
  118. /*if(Ext.getCmp('pr_statuscode').value!='ENTERING'){
  119. btn.hide();
  120. }*/
  121. },
  122. click: function(btn){
  123. if(Ext.getCmp('pr_statuscode').value!='ENTERING'){
  124. showError('只能修改在录入物料的特征');
  125. return;
  126. }
  127. var grid = Ext.getCmp('grid');
  128. Ext.each(grid.store.data.items, function(item){
  129. if(item.dirty == true){
  130. item.set('pf_prodcode', Ext.getCmp('pr_code').value);
  131. }
  132. });
  133. me.GridUtil.onUpdate(Ext.getCmp('grid'));
  134. }
  135. },
  136. 'erpAddButton': {
  137. click: function(){
  138. me.FormUtil.onAdd('addProdFeature', '新增BOM物料位号', 'jsps/pm/bom/ProdFeature.jsp');
  139. }
  140. },
  141. 'erpCloseButton': {
  142. click: function(btn){
  143. /*me.FormUtil.beforeClose(me);*/
  144. }
  145. },
  146. 'button[id=addFeatrue]':{
  147. click:function(btn){
  148. var value=Ext.getCmp('pr_id').getValue();
  149. if(!value) {
  150. showError('请先选择需要添加的物料');
  151. return;
  152. }
  153. var win=new Ext.window.Window({
  154. id : 'win',
  155. title: "新增特征明细",
  156. height: "50%",
  157. width: "40%",
  158. maximizable : false,
  159. layout: 'anchor',
  160. items: { // Let's put an empty grid in just to illustrate fit layout
  161. xtype:'erpFormPanel',
  162. id:'baseform',
  163. _noc: 1,
  164. params:{
  165. caller:'AddProdFeature',
  166. condition:'',
  167. _noc:1
  168. },
  169. anchor:'100% 100%',
  170. saveUrl:'pm/feature/addProdFeature.action?_noc=1'
  171. }
  172. });
  173. win.show();
  174. }
  175. },
  176. 'dbfindtrigger[name=fe_valuecode]':{
  177. afterrender:function(t){
  178. var value=Ext.getCmp('pf_fecode').getValue();
  179. if(value){
  180. t.dbBaseCondition="fd_code like '%"+value+"'%";
  181. }
  182. }
  183. },
  184. 'multidbfindtrigger[name=fe_valuecode]':{
  185. afterrender:function(t){
  186. var value=Ext.getCmp('pf_fecode').getValue();
  187. if(value){
  188. t.dbBaseCondition="fd_code like '%"+value+"'%";
  189. }
  190. }
  191. },
  192. // 'dbfindtrigger[name=bd_sonid]': {
  193. // afterrender: function(t){
  194. // t.dbKey = "bd_bomid";
  195. // t.mappingKey = "bd_bomid";
  196. // t.dbMessage = "请先选择BOMID!";
  197. // }
  198. // },
  199. 'field[name=pr_id]': {
  200. change: function(f){
  201. if(f.value != null && f.value != ''){
  202. // me.GridUtil.loadNewStore(Ext.getCmp('grid'), {
  203. // caller: caller,
  204. // condition: 'pf_prid=' + f.value
  205. // });
  206. // Ext.getCmp('deletebutton').show();
  207. // Ext.getCmp('updatebutton').show();
  208. // //Ext.getCmp('save').hide();
  209. window.location.href = window.location.href.toString().split('?')[0] + '?formCondition=pr_id='+f.value+'&gridCondition=pf_prid='+f.value;
  210. } else {
  211. Ext.getCmp('deletebutton').hide();
  212. Ext.getCmp('updatebutton').hide();
  213. //Ext.getCmp('save').show();
  214. }
  215. }
  216. }
  217. });
  218. },
  219. onGridItemClick: function(selModel, record){//grid行选择
  220. this.GridUtil.onGridItemClick(selModel, record);
  221. },
  222. getForm: function(btn){
  223. return btn.ownerCt.ownerCt;
  224. }
  225. });