SearchField.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Ext.define('erp.view.core.trigger.SearchField', {
  2. extend : 'Ext.form.field.Trigger',
  3. alias : 'widget.searchfield',
  4. triggerCls: 'x-form-search-trigger',
  5. hasSearch : false,
  6. paramName : 'query',
  7. fieldStyle: 'color:#777;background: #f1f2f5;border-color: #d9d9d9; -moz-border-radius:3px 0 0 3px; -webkit-border-radius:3px 0 0 3px; border-radius:3px 0 0 3px;',
  8. focusCls: 'x-form-field-cir',
  9. emptyText: $I18N.common.main.quickSearch,
  10. enableKeyEvents : true,
  11. listeners : {
  12. specialkey : function(field, e){
  13. if(e.getKey() == Ext.EventObject.ENTER){
  14. this.onTriggerClick();
  15. }
  16. }
  17. },
  18. autoShow:true,
  19. initComponent : function() {
  20. this.callParent(arguments);
  21. },
  22. onTriggerClick: function(){
  23. var f = this, tree = Ext.getCmp('tree-panel')!=null?Ext.getCmp('tree-panel'):Ext.getCmp('powertree');
  24. if(f.value == '' || f.value == null){
  25. tree.getTreeRootNode(0);
  26. return;
  27. }
  28. tree.setLoading(true, tree.body);
  29. Ext.Ajax.request({//拿到tree数据
  30. url : basePath + 'common/searchTree.action',
  31. params: {
  32. search: f.value,
  33. isPower:Ext.getCmp('tree-panel')!=null?0:1,
  34. isPDA: f.isPDA || false
  35. },
  36. callback : function(options,success,response){
  37. tree.setLoading(false);
  38. var res = new Ext.decode(response.responseText);
  39. if(res.tree){
  40. var searchKeys = Ext.util.Cookies.get('searchKeys');
  41. if(searchKeys == null || searchKeys.length == 0){
  42. //searchKeys = new Array();//cookie存放数组很麻烦,就用字符串,中间用||隔开
  43. searchKeys = f.value;
  44. } else {
  45. var bool = true;
  46. Ext.Array.each(searchKeys.split('||'), function(k){
  47. if(k == f.value){//已存在
  48. bool = false;
  49. }
  50. });
  51. if(bool){
  52. searchKeys = searchKeys + "||" + f.value;
  53. }
  54. }
  55. //Ext.util.Cookies.set('searchKeys', searchKeys);//把用户的搜索条件作为关键字存入cookie
  56. var root = tree.getRootNode();
  57. root.removeAll();
  58. var fn = function(node, ch) {
  59. for(var i in ch) {
  60. var n = ch[i], chs = n.children;
  61. n.children = [];
  62. n.expanded = true;
  63. var d = node.appendChild(n);
  64. if(d && chs && chs.length > 0 && String(chs) != '[]') {
  65. fn(d, chs);
  66. }
  67. }
  68. };
  69. fn(root, res.tree);
  70. } else if(res.redirectUrl){
  71. window.location.href = res.redirectUrl;
  72. } else if(res.exceptionInfo){
  73. Ext.Msg.alert("ERROR:" + res.exceptionInfo);
  74. }
  75. }
  76. });
  77. }
  78. });