ProductKindTree.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. Ext.define('erp.view.sys.pr.ProductKindTree', {
  2. extend: 'Ext.tree.Panel',
  3. alias: 'widget.productkindtree',
  4. id:'productkindtree',
  5. useArrows: true,
  6. rootVisible: false,
  7. multiSelect: true,
  8. columnLines: true,
  9. viewConfig: {stripeRows:true},
  10. //forceFit:true,
  11. dockedItems: [/*{
  12. xtype: 'toolbar',
  13. dock: 'bottom',
  14. ui: 'footer',
  15. layout: {
  16. pack: 'center'
  17. },
  18. items: [{
  19. minWidth: 80,
  20. text: 'Save'
  21. },{
  22. minWidth: 80,
  23. text: 'Cancel'
  24. }]
  25. }, */{
  26. xtype: 'toolbar',
  27. ui: 'footer',
  28. items: [{
  29. text:'添加',
  30. tooltip:'添加新记录',
  31. iconCls:'btn-add',
  32. menu: {
  33. items: [{
  34. text: '顶层种类',
  35. iconCls:'btn-add',
  36. itemId:'topProductKind'
  37. },{
  38. text: '添加种类',
  39. iconCls: 'btn-add',
  40. itemId: 'addProductKind'
  41. }]
  42. }
  43. },/* '-', {
  44. text:'修改',
  45. itemId: 'sa_updateButton',
  46. tooltip:'修改选中行',
  47. iconCls:'btn-edit',
  48. disabled: true
  49. },'-',{
  50. itemId: 'sa_removeButton',
  51. text:'删除',
  52. tooltip:'删除选中行',
  53. iconCls:'btn-delete',
  54. disabled: true
  55. }, */'-', {
  56. text:'帮助',
  57. iconCls:'btn-help',
  58. tooltip:'帮助简介'
  59. }]
  60. }],
  61. initComponent: function(config) {
  62. var me=this;
  63. me.columns=[{
  64. xtype: 'treecolumn',
  65. text: '种类编号',
  66. width: 200,
  67. sortable: true,
  68. dataIndex: 'pk_code',
  69. editor: {
  70. xtype: 'textfield',
  71. selectOnFocus: true,
  72. allowOnlyWhitespace: false
  73. }
  74. },{
  75. text: '种类名称',
  76. width: 150,
  77. dataIndex: 'pk_name',
  78. sortable: true,
  79. editor: {
  80. xtype: 'textfield',
  81. selectOnFocus: true,
  82. allowOnlyWhitespace: false
  83. }
  84. },{text:'ID',width:0,dataIndex:'pk_id'},{
  85. xtype: 'actioncolumn',
  86. width: 40,
  87. icon:basePath+'jsps/sys/images/deletetree.png',
  88. iconCls: 'x-hidden',
  89. renderer :function(val, meta, record){
  90. meta.tdCls = record.get('cls');
  91. meta.tdAttr = record.get('leaf')?'data-qtip="新增'+record.get('text')+'"':'data-qtip="删除种类"';
  92. },
  93. handler: Ext.bind(me.handleRemoveClick, me)
  94. }];
  95. me.store=Ext.create('Ext.data.TreeStore', {
  96. storeId: 'hrorgstore',
  97. fields: [{"name":"pk_id","type":"number"},
  98. {"name":"pk_code","type":"string"},
  99. {"name":"pk_name","type":"string"}],
  100. root : {
  101. text: 'root',
  102. id: 'root',
  103. expanded: true
  104. },
  105. listeners:{
  106. beforeexpand:Ext.bind(me.handleSpeExpandClick, me)
  107. }
  108. });
  109. me.plugins = [me.cellEditingPlugin = Ext.create('Ext.grid.plugin.CellEditing',{
  110. clicksToEdit:1,
  111. listeners:{
  112. 'edit':function(editor,e,Opts){
  113. var record=e.record,update={
  114. pk_id:record.data.pk_id,
  115. pk_code:record.data.pk_code,
  116. pk_name:record.data.pk_name
  117. };
  118. if(e.originalValue!=e.value && e.value){
  119. Ext.Ajax.request({
  120. url:basePath+'scm/sale/updateProductKind.action',
  121. params: {
  122. formStore:unescape(escape(Ext.JSON.encode(update)))
  123. },
  124. method : 'post',
  125. callback : function(options,success,response){
  126. var local=Ext.decode(response.responseText);
  127. if(local.success) {
  128. showResult('提示','修改成功!');
  129. record.commit();
  130. }else {
  131. showResult('提示',local.exceptionInfo);
  132. }
  133. }
  134. });
  135. }
  136. }
  137. }
  138. })];
  139. this.callParent(arguments);
  140. this.getTreeGridNode({parentid: 0});
  141. },
  142. getTreeGridNode: function(param){
  143. var me = this;
  144. Ext.Ajax.request({//拿到tree数据
  145. url : basePath + 'scm/product/getProductKindTree.action',
  146. params: param,
  147. callback : function(options,success,response){
  148. var res = new Ext.decode(response.responseText);
  149. if(res.tree){
  150. var tree = res.tree;
  151. Ext.each(tree, function(t){
  152. t.pk_id = t.data.pk_id;
  153. t.pk_code=t.data.pk_code;
  154. t.pk_name=t.data.pk_name;
  155. t.leaf=false;
  156. t.data = null;
  157. });
  158. me.store.setRootNode({
  159. text: 'root',
  160. id: 'root',
  161. expanded: true,
  162. children: tree
  163. });
  164. Ext.each(me.store.tree.root.childNodes, function(){
  165. this.dirty = false;
  166. });
  167. } else if(res.exceptionInfo){
  168. showError(res.exceptionInfo);
  169. }
  170. }
  171. });
  172. },
  173. handleRemoveClick: function(gridView, rowIndex, colIndex, column, e) {
  174. this.fireEvent('removeclick', gridView, rowIndex, colIndex, column, e);
  175. },
  176. handleSpeExpandClick: function(record) {
  177. if(record.get('id')!='root'){
  178. this.fireEvent('speexpandclick', record);
  179. }
  180. }
  181. });