search.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. }
  13. },
  14. computed: {
  15. },
  16. mounted:function() {
  17. this.getHot();
  18. this.searchKey =(GetRequest().search && decodeURIComponent(GetRequest().search)) || ''
  19. this.initData(this.searchKey);
  20. },
  21. methods: {
  22. getHot:function(){
  23. var vm=this;
  24. bigDataOutApi.hot_words().then(function(res){
  25. vm.hotList=res
  26. }).catch(function(err){
  27. console.err(err)
  28. })
  29. },
  30. initData:function(keyword){
  31. this.searchword=keyword
  32. this.allEventInit =false;
  33. this.outpatientInit =false;
  34. this.hospitalizationInit =false;
  35. var vm=this
  36. this.$nextTick(function () {
  37. switch (vm.type){
  38. case '全部':vm.$refs.allEvent.initData();vm.allEventInit =true;break;
  39. case '门诊':vm.$refs.outpatient.initData();vm.outpatientInit =true;break;
  40. case '住院':vm.$refs.hospitalization.initData();vm.hospitalizationInit =true;break
  41. }
  42. })
  43. },
  44. setIndexPage:function(key){ //前往左边菜单页面
  45. GlobalEventBus.$emit('setleftTabUrl', {
  46. key: key
  47. });
  48. },
  49. search:function(value){
  50. if(!value){
  51. toastr.error("请输入检索词再进行搜索");
  52. return
  53. }
  54. this.searchKey=value
  55. this.initData(value);
  56. }
  57. },
  58. watch: {
  59. type:function(value){
  60. switch (value){
  61. case '全部':if(!this.allEventInit){this.$refs.allEvent.initData();this.allEventInit =true};break;
  62. case '门诊':if(!this.outpatientInit){this.$refs.outpatient.initData();this.outpatientInit =true;}break;
  63. case '住院':if(!this.hospitalizationInit){this.$refs.hospitalization.initData();this.hospitalizationInit =true;}break
  64. }
  65. }
  66. }
  67. })