PRController.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. Ext.define('erp.controller.sys.step.PRController', {
  2. extend: 'Ext.app.Controller',
  3. id:'PRController',
  4. BaseUtil: Ext.create('erp.util.BaseUtil'),
  5. FormUtil: Ext.create('erp.util.FormUtil'),
  6. views:['sys.pr.ProductPortal','sys.pr.ProductKindTree'],
  7. init:function(){
  8. var me=this;
  9. this.flag = true;
  10. this.control({
  11. 'menuitem[itemId=topProductKind]':{
  12. click:me.handleTopProductKindClick
  13. },
  14. 'menuitem[itemId=addProductKind]':{
  15. click:me.handleAddProductKindClick
  16. },
  17. 'productkindtree': {
  18. /*itemmousedown: function(selModel, record){
  19. if(!this.flag){
  20. return;
  21. }
  22. this.flag = false;
  23. var treegrid = Ext.getCmp('productkindtree');
  24. treegrid.selModel.select(record);
  25. setTimeout(function(){
  26. me.flag = true;
  27. me.loadNode(selModel, record);
  28. },20);
  29. },*/
  30. itemmouseenter: me.showActions,
  31. itemmouseleave: me.hideActions,
  32. beforeitemmouseenter:me.showActions,
  33. removeclick:me.handleRemoveClick,
  34. speexpandclick:me.handleSpeExpandClick
  35. },
  36. });
  37. var app=erp.getApplication();
  38. var productportal = activeItem.child('productportal');
  39. if(!productportal){
  40. productportal = Ext.widget('productportal',{desc:'物料管理'});
  41. activeItem.add(productportal);
  42. Ext.getCmp('syspanel').setTitle(productportal.desc);
  43. }
  44. },
  45. handleAddKindClick: function(component, e) {
  46. this.addKind(true,component);
  47. },
  48. handleTopProductKindClick:function(c,e){
  49. this.addKind(true,c,'top');
  50. },
  51. handleAddProductKindClick:function(c,e){
  52. this.addKind(true,c);
  53. },
  54. addKind:function(leaf,btn,type){
  55. var me = this,
  56. productkindtree= Ext.getCmp('productkindtree'),
  57. cellEditingPlugin = productkindtree.cellEditingPlugin,
  58. selectionModel = productkindtree.getSelectionModel(),
  59. selectedList = selectionModel.getSelection()[0];
  60. var parentId=selectedList && !type?selectedList.get('pk_id'):0;
  61. selectedList=parentId==0?productkindtree.getRootNode():selectedList;
  62. var pkind =this.getNewProductKind(parentId,btn);
  63. expandAndEdit = function() {
  64. if(selectedList.isExpanded()) {
  65. selectionModel.select(pkind);
  66. me.addedNode = pkind;
  67. cellEditingPlugin.startEdit(pkind, 0);
  68. } else {
  69. productkindtree.on('afteritemexpand', function startEdit(list) {
  70. if(list === selectedList) {
  71. selectionModel.select(newList);
  72. me.addedNode = newList;
  73. cellEditingPlugin.startEdit(pkind, 0);
  74. // remove the afterexpand event listener
  75. productkindtree.un('afteritemexpand', startEdit);
  76. }
  77. });
  78. selectedList.expand();
  79. }
  80. };
  81. selectedList.appendChild(pkind);
  82. productkindtree.getStore().sync();
  83. if(productkindtree.getView().isVisible(true)) {
  84. expandAndEdit();
  85. } else {
  86. productkindtree.on('expand', function onExpand() {
  87. expandAndEdit();
  88. listTree.un('expand', onExpand);
  89. });
  90. productkindtree.expand();
  91. }
  92. },
  93. getNewProductKind:function(parentId,btn){
  94. var pkind=new Object();
  95. parentId=parentId?parentId:0;
  96. Ext.Ajax.request({//拿到tree数据
  97. url : basePath + 'scm/sale/addProductKindByParent.action',
  98. params: {
  99. parentId: parentId
  100. },
  101. async:false,
  102. callback : function(options,success,response){
  103. var res = new Ext.decode(response.responseText);
  104. if(res.pkind){
  105. pkind=res.pkind;
  106. pkind.loaded=true;
  107. pkind.id=pkind.pk_id;
  108. }
  109. }
  110. });
  111. return pkind;
  112. },
  113. showActions: function(view, list, node, rowIndex, e) {
  114. var icons = Ext.DomQuery.select('.x-action-col-icon', node),record=view.getRecord(node);
  115. Ext.each(icons, function(icon){
  116. Ext.get(icon).removeCls('x-hidden');
  117. });
  118. },
  119. hideActions: function(view, list, node, rowIndex, e) {
  120. var icons = Ext.DomQuery.select('.x-action-col-icon', node),record=view.getRecord(node);
  121. Ext.each(icons, function(icon){
  122. Ext.get(icon).addCls('x-hidden');
  123. });
  124. },
  125. handleRemoveClick: function(view, rowIndex, colIndex, column, e) {
  126. var record=view.getRecord(view.findTargetByEvent(e)),title=record.get('pk_code'), kindTree = Ext.getCmp('productkindtree'),
  127. selModel = kindTree.getSelectionModel();
  128. Ext.Msg.confirm('删除数据?', '确定要删除当前选中种类 ('+title+')?',
  129. function(choice) {
  130. if(choice === 'yes') {
  131. Ext.Ajax.request({//拿到tree数据
  132. url : basePath + 'scm/sale/deleteProductKind.action',
  133. params: {
  134. id: record.get('id')
  135. },
  136. async:false,
  137. callback : function(options,success,response){
  138. var res = new Ext.decode(response.responseText);
  139. if(res.success){
  140. showResult('提示','删除种类('+title+') 成功!');
  141. record.parentNode.removeChild(record);
  142. if (!selModel.hasSelection()) {
  143. selModel.select(0);
  144. }
  145. }
  146. }
  147. });
  148. }
  149. });
  150. },
  151. handleSpeExpandClick:function(record){
  152. this.loadNode(record);
  153. var treegrid = Ext.getCmp('productkindtree');
  154. treegrid.selModel.select(record);
  155. },
  156. loadNode: function(record){
  157. var me = this;
  158. if ( record.data['pk_id']) {
  159. if(record.isExpanded() && record.childNodes.length > 0){
  160. me.flag = true;
  161. } else {
  162. if(record.childNodes.length == 0){
  163. Ext.Ajax.request({//拿到tree数据
  164. url : basePath + 'scm/product/getProductKindTree.action',
  165. params: {
  166. parentid: record.data['id']
  167. },
  168. callback : function(options,success,response){
  169. var res = new Ext.decode(response.responseText);
  170. if(res.tree && res.tree.length>0){
  171. var tree = res.tree;
  172. Ext.each(tree, function(t){
  173. t.pk_id = t.id;
  174. t.pk_code=t.data.pk_code;
  175. t.pk_name=t.data.pk_name;
  176. t.leaf=false;
  177. t.data = null;
  178. });
  179. me.flag=true;
  180. record.appendChild(tree);
  181. Ext.each(record.childNodes, function(){
  182. this.dirty = false;
  183. });
  184. } else if(res.exceptionInfo){
  185. showError(res.exceptionInfo);
  186. }
  187. }
  188. });
  189. } else {
  190. me.flag=true;
  191. }
  192. }
  193. }
  194. }
  195. });