ProdFeature.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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','core.button.LoadFeature',
  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. 'erpFormPanel' : {
  17. afterload : function(form) {
  18. form.getForm().getFields().each(function() {
  19. var val = getUrlParam(this.name);
  20. if(!Ext.isEmpty(val) && Ext.isEmpty(this.getValue())) {
  21. this.setValue(val);
  22. }
  23. });
  24. }
  25. },
  26. 'erpGridPanel2': {
  27. itemclick: function(selModel, record){
  28. this.onGridItemClick(selModel, record);
  29. },
  30. afterrender:function(grid){
  31. grid.setReadOnly(false);
  32. }
  33. },
  34. 'erpLoadFeatureButton': {
  35. afterrender: function(btn){
  36. var status = Ext.getCmp('pr_statuscode');
  37. if(status && status.value != 'ENTERING'){
  38. btn.hide();
  39. }
  40. },
  41. click: function(btn){
  42. if(getUrlParam('formCondition') != null && Ext.getCmp('grid').getStore().getCount() != 0){
  43. showError('载入前请删除明细,以免数据重复');return;
  44. }
  45. var refno = Ext.getCmp('pr_refno').value;
  46. if(refno == null || refno == ''){
  47. showError('没有模板编号');return;
  48. } else {
  49. me.loadFeature(refno);
  50. }
  51. }
  52. },
  53. 'erpSaveButton': {
  54. afterrender:function(btn){
  55. var status = Ext.getCmp('pr_statuscode');
  56. if(status && status.value != 'ENTERING'){
  57. btn.hide();
  58. }
  59. btn.ownerCt.insert(2,{
  60. text: $I18N.common.button.erpCloseButton,
  61. iconCls: 'x-button-icon-close',
  62. cls: 'x-btn-gray',
  63. width: 60,
  64. style: {
  65. marginLeft: '10px'
  66. },
  67. handler:function(){
  68. var win=Ext.getCmp('win');
  69. if(win) win.close();
  70. }
  71. });
  72. var form=Ext.getCmp('form');
  73. data=form.getValues();
  74. Ext.getCmp('pf_prodcode').setValue(data.pr_code);
  75. Ext.getCmp('pf_prid').setValue(data.pr_id);
  76. },
  77. click:function(btn){
  78. var form=btn.ownerCt.ownerCt;
  79. r=form.getValues();
  80. var params = new Object();
  81. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  82. var me = this;
  83. Ext.Ajax.request({
  84. url : basePath + form.saveUrl,
  85. params : params,
  86. method : 'post',
  87. callback : function(options,success,response){
  88. var localJson = new Ext.decode(response.responseText);
  89. if(localJson.success){
  90. saveSuccess(function(){
  91. var grid=Ext.getCmp('grid');
  92. var param={
  93. caller:caller,
  94. condition:'pf_prid='+r.pf_prid
  95. };
  96. btn.ownerCt.ownerCt.ownerCt.close();
  97. grid.GridUtil.loadNewStore(grid,param);
  98. });
  99. } else if(localJson.exceptionInfo){
  100. var str = localJson.exceptionInfo;
  101. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  102. str = str.replace('AFTERSUCCESS', '');
  103. saveSuccess(function(){
  104. //add成功后刷新页面进入可编辑的页面
  105. var value = r[form.keyField];
  106. var formCondition = form.keyField + "IS" + value ;
  107. var gridCondition = '';
  108. var grid = Ext.getCmp('grid');
  109. if(grid && grid.mainField){
  110. gridCondition = grid.mainField + "IS" + value;
  111. }
  112. if(me.contains(window.location.href, '?', true)){
  113. window.location.href = window.location.href + '&formCondition=' +
  114. formCondition + '&gridCondition=' + gridCondition;
  115. } else {
  116. window.location.href = window.location.href + '?formCondition=' +
  117. formCondition + '&gridCondition=' + gridCondition;
  118. }
  119. });
  120. showError(str);
  121. } else {
  122. showError(str);
  123. return;
  124. }
  125. } else{
  126. saveFailure();//@i18n/i18n.js
  127. }
  128. }
  129. });
  130. }
  131. },
  132. 'erpDeleteButton' : {
  133. afterrender: function(btn){
  134. if(Ext.getCmp('pr_id').value != null && Ext.getCmp('pr_id').value != ''){
  135. var status = Ext.getCmp('pr_statuscode');
  136. if(status && status.value != 'ENTERING'){
  137. btn.hide();
  138. } else {
  139. btn.show();
  140. }
  141. } else {
  142. btn.hide();
  143. }
  144. },
  145. click: function(btn){
  146. me.FormUtil.onDelete(Ext.getCmp('pr_id').value);
  147. }
  148. },
  149. 'erpUpdateButton': {
  150. afterrender: function(btn){
  151. if(Ext.getCmp('pr_id').value != null && Ext.getCmp('pr_id').value != ''){
  152. var status = Ext.getCmp('pr_statuscode');
  153. if(status && status.value != 'ENTERING'){
  154. btn.hide();
  155. } else {
  156. btn.show();
  157. }
  158. } else {
  159. btn.hide();
  160. }
  161. },
  162. click: function(btn){
  163. if(Ext.getCmp('pr_statuscode').value!='ENTERING'){
  164. showError('只能修改在录入物料的特征');
  165. return;
  166. }
  167. var grid = Ext.getCmp('grid');
  168. Ext.each(grid.store.data.items, function(item){
  169. if(item.dirty == true){
  170. item.set('pf_prodcode', Ext.getCmp('pr_code').value);
  171. }
  172. });
  173. me.GridUtil.onUpdate(Ext.getCmp('grid'));
  174. }
  175. },
  176. 'erpAddButton': {
  177. afterrender: function(btn){
  178. var status = Ext.getCmp('pr_statuscode');
  179. if(status && status.value != 'ENTERING'){
  180. btn.hide();
  181. }
  182. },
  183. click: function(){
  184. me.FormUtil.onAdd('addProdFeature', '新增BOM物料位号', 'jsps/pm/bom/ProdFeature.jsp');
  185. }
  186. },
  187. 'erpCloseButton': {
  188. click: function(btn){
  189. /*me.FormUtil.beforeClose(me);*/
  190. }
  191. },
  192. 'button[id=addFeatrue]':{
  193. click:function(btn){
  194. var value=Ext.getCmp('pr_id').getValue();
  195. if(!value) {
  196. showError('请先选择需要添加的物料');
  197. return;
  198. }
  199. var win=new Ext.window.Window({
  200. id : 'win',
  201. title: "新增特征明细",
  202. height: "50%",
  203. width: "40%",
  204. maximizable : false,
  205. layout: 'anchor',
  206. items: { // Let's put an empty grid in just to illustrate fit layout
  207. xtype:'erpFormPanel',
  208. id:'baseform',
  209. _noc: 1,
  210. params:{
  211. caller:'AddProdFeature',
  212. condition:'',
  213. _noc:1
  214. },
  215. anchor:'100% 100%',
  216. saveUrl:'pm/feature/addProdFeature.action?_noc=1'
  217. }
  218. });
  219. win.show();
  220. }
  221. },
  222. 'dbfindtrigger[name=fe_valuecode]':{
  223. afterrender:function(t){
  224. var value=Ext.getCmp('pf_fecode').getValue();
  225. if(value){
  226. t.dbBaseCondition="fd_code like '%"+value+"'%";
  227. }
  228. }
  229. },
  230. 'multidbfindtrigger[name=fe_valuecode]':{
  231. afterrender:function(t){
  232. var value=Ext.getCmp('pf_fecode').getValue();
  233. if(value){
  234. t.dbBaseCondition="fd_code like '%"+value+"'%";
  235. }
  236. }
  237. },
  238. 'field[name=pr_id]': {
  239. change: function(f){
  240. if(f.value != null && f.value != ''){
  241. me.GridUtil.loadNewStore(Ext.getCmp('grid'), {
  242. caller: caller,
  243. condition: 'pf_prid=' + f.value
  244. });
  245. } else {
  246. Ext.getCmp('deletebutton').hide();
  247. Ext.getCmp('updatebutton').hide();
  248. }
  249. }
  250. }
  251. });
  252. },
  253. onGridItemClick: function(selModel, record){//grid行选择
  254. this.GridUtil.onGridItemClick(selModel, record);
  255. },
  256. getForm: function(btn){
  257. return btn.ownerCt.ownerCt;
  258. },
  259. loadFeature: function(num){
  260. Ext.Ajax.request({//拿到grid的columns
  261. url : basePath + "common/loadNewGridStore.action",
  262. params: {
  263. caller: 'FeatureTemplet',
  264. condition: "fd_code='" + num + "'"
  265. },
  266. method : 'post',
  267. callback : function(options,success,response){
  268. var res = new Ext.decode(response.responseText);
  269. if(res.exceptionInfo){
  270. showError(res.exceptionInfo);return;
  271. }
  272. var data = res.data;
  273. var fpd = [];
  274. if(data != null && data.length > 0){
  275. Ext.each(data, function(d, index){
  276. var da = {
  277. pf_prodcode :Ext.getCmp('pr_code').value,
  278. pf_prid : Ext.getCmp('pr_id').value,
  279. pf_detno : d.fd_detno,
  280. pf_fecode : d.fd_fecode,
  281. pf_fename : d.fd_fename
  282. };
  283. fpd[index] = da;
  284. });
  285. Ext.getCmp('grid').store.loadData(fpd);
  286. } else {
  287. showError('没有可载入的特征');return;
  288. }
  289. }
  290. });
  291. }
  292. });