ComboxTree.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. Ext.define('erp.view.common.JProcess.ComboxTree',{
  2. extend: 'Ext.form.field.ComboBox',
  3. alias: 'widget.treeCombox',
  4. store : new Ext.data.ArrayStore({fields:[],data:[[]]}),
  5. editable : false,
  6. /* resizable:true,*/
  7. /*minWidth:100,
  8. maxWidth:350,*/
  9. width:350,
  10. labelAlign:'right',
  11. readOnly:false,
  12. editable:false,
  13. _idValue : null,
  14. _txtValue : null,
  15. fieldLabel: '选择办理人',
  16. queryMode: 'local',
  17. emptyText :'下拉并双击选择',
  18. fieldStyle:'background:#FFFAFA;color:#515151;',
  19. initComponent : function(){
  20. var combo = this;
  21. this.callParent(arguments);
  22. this.treeRenderId = Ext.id();
  23. //必须要用这个定义tpl
  24. this.tpl = new Ext.XTemplate('<tpl for="."><div style="height:100' + 'px;"><div id="' + this.treeRenderId+ '"></div></div></tpl>');
  25. var treeObj = new Ext.tree.Panel({
  26. border : false,
  27. id:'tree',
  28. autoScroll : true,
  29. rootVisible: false,
  30. listeners: {
  31. itemclick: {
  32. fn: function(){}
  33. }
  34. },
  35. });
  36. /*treeObj.on('itemclick',function(view,rec){*/
  37. treeObj.on('itemdblclick',function(view,record,item,index,e){
  38. /*treeObj.fireEvent('itemclick',null);*/
  39. /*console.log(Ext.getCmp('tree').getSelectionModel())
  40. console.log(e);
  41. console.log(record);*/
  42. if(record){
  43. combo.setValue(this._txtValue = record.get('text'));
  44. combo._idValue = record.get('text');
  45. combo.collapse();
  46. }
  47. });
  48. this.on({
  49. 'expand' : function(){
  50. if(!treeObj.rendered&&treeObj&&!this.readOnly){
  51. var me = this;
  52. Ext.Ajax.request({//拿到tree数据
  53. /*url : basePath + 'comboxTree.action',*/
  54. url : basePath + 'common/getOrgAssignees.action',
  55. callback : function(options,success,response){
  56. var res1 = response.responseText;
  57. var res =Ext.decode(res1);
  58. if(res.tree){
  59. var tree = Ext.decode(res.tree);
  60. for(x in tree){
  61. delete tree[x].id;
  62. if(tree[x].children){
  63. var children = tree[x].children;
  64. for( y in children){
  65. delete children[y].id;
  66. }
  67. }
  68. }
  69. Ext.getCmp('tree').getStore().setRootNode({
  70. text: 'root',
  71. id: 'root',
  72. expanded: true,
  73. children: tree
  74. });
  75. } else if(res.exceptionInfo){
  76. showError(res.exceptionInfo);
  77. }
  78. Ext.defer(function(){
  79. /*console.log(me.xtype);*/
  80. treeObj.render(me.treeRenderId);
  81. },300,me);
  82. }
  83. });
  84. }
  85. }
  86. });
  87. },
  88. getValue : function(){//获取id值
  89. return this._idValue;
  90. },
  91. getTextValue : function(){//获取text值
  92. return this._txtValue;
  93. },
  94. setLocalValue : function(txt,id){//设值
  95. this._idValue = id;
  96. this.setValue(this._txtValue = txt);
  97. }
  98. });