search.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. new Vue({
  2. el: '#app',
  3. data: function () {
  4. return {
  5. searchKey:'',//input的值
  6. searchword:'',//搜索时传给子组件的值(可能input改变了未按搜索 所以分成两个)
  7. hotList:[],
  8. type:'全部',
  9. allEventInit:false, //判断是否需要重新加载数据
  10. outpatientInit:false,
  11. hospitalizationInit:false,
  12. showBtn:true
  13. }
  14. },
  15. computed: {
  16. },
  17. mounted:function() {
  18. this.getHot();
  19. this.searchKey =(GetRequest().search && decodeURIComponent(GetRequest().search)) || ''
  20. this.initData(this.searchKey);
  21. var vm=this;
  22. GlobalEventBus.$on('getSearchData',function(val){
  23. if(val.data && val.data.length>0){
  24. vm.showBtn =true
  25. }
  26. else{
  27. vm.showBtn =false
  28. }
  29. })
  30. },
  31. methods: {
  32. getHot:function(){
  33. var vm=this;
  34. bigDataOutApi.hot_words().then(function(res){
  35. vm.hotList=res
  36. }).catch(function(err){
  37. console.err(err)
  38. })
  39. },
  40. initData:function(keyword){
  41. this.searchword=keyword
  42. this.allEventInit =false;
  43. this.outpatientInit =false;
  44. this.hospitalizationInit =false;
  45. var vm=this
  46. this.$nextTick(function () {
  47. switch (vm.type){
  48. case '全部':vm.$refs.allEvent.initData();vm.allEventInit =true;break;
  49. case '门诊':vm.$refs.outpatient.initData();vm.outpatientInit =true;break;
  50. case '住院':vm.$refs.hospitalization.initData();vm.hospitalizationInit =true;break
  51. }
  52. })
  53. },
  54. setIndexPage:function(key){ //前往左边菜单页面
  55. GlobalEventBus.$emit('setleftTabUrl', {
  56. key: key
  57. });
  58. },
  59. search:function(value){
  60. if(!value){
  61. toastr.error("请输入检索词再进行搜索");
  62. return
  63. }
  64. this.searchKey=value
  65. this.initData(value);
  66. },
  67. reseviceData:function(val){
  68. debugger
  69. }
  70. },
  71. watch: {
  72. type:function(value){
  73. switch (value){
  74. case '全部':if(!this.allEventInit){this.$refs.allEvent.initData();this.allEventInit =true};break;
  75. case '门诊':if(!this.outpatientInit){this.$refs.outpatient.initData();this.outpatientInit =true;}break;
  76. case '住院':if(!this.hospitalizationInit){this.$refs.hospitalization.initData();this.hospitalizationInit =true;}break
  77. }
  78. }
  79. }
  80. })