<template>
    <div>
        <!-- <SearchHeader @search="search" :searchText="searchText"/> -->
        <form @submit.prevent="search">
          <mt-search v-model="searchText" ></mt-search>
          <button v-show="false" type="submit" />
        </form>

        <!-- <SplitLine /> -->
        <div class="mt-100"></div>
        <HistoryLabels/>
        <HotLabels/>
        <img src="https://test1-file.yunqueyi.com/image/HJ_B001_YD_002_A.jpg" @click="gotoPage">
    </div>
</template>

<script>
import {mapState, mapMutations} from 'vuex'

import SearchHeader from '../components/business/search-header';
import SplitLine from '../components/business/split-line';
import HistoryLabels from '../components/business/history-labels';
import HotLabels from '../components/business/hot-labels';

export default {
  data() {
    return {
      searchText: '',
      token: ''
    }
  },
  components: {
    SearchHeader,
    SplitLine,
    HistoryLabels,
    HotLabels
  },
  created(){
    
  },
  computed:{
    ...mapState([
        'sousuo'
    ])
  },
  mounted(){
    let _self = this;
    // window.__getUserInfo = function(params){
    //     _self.token = params.userToken
    //     // _self.SET_USER_INFO(params)
    //     _self.getData()
    // }
    // window.__refresh = function(){
    //   _self.getUserInfo()
    // }
    // window.__getStatusBarHeight = function(params){
    //   _self.SET_NAVBAR_HEIGHT(params)
    // }

    // window.__getStatusBarHeight = function(parm){
    //   //lert(parm.statusBarHeight)
    //   if(window.__isAndroid){
    //     _this.popHeight = parseInt(parm.statusBarHeight)/2.5
    //   }else{
    //     _this.popHeight = parm.statusBarHeight
    //   }
    //   _this.ptop = _this.popHeight+'px';
    //   _this.menuptop = _this.popHeight+'px'
    //  // alert(parm.statusBarHeight);
    // }

      _self.getData()

    // if(window.__isWeb) {
    //   _self.getData()
    // }
    // _self.getUserInfo()
    // _self.getStatusBarHeight()
  },
  methods: {
    ...mapMutations([
        'SET_USER_INFO', 'SET_NAVBAR_HEIGHT'
    ]),
    // 跳转到结果页面，并
    search() {
      // if(!this.searchText) return;
      this.$router.push({
        path: '/result',
        query: {
          searchText: this.searchText
        }
      })
    },
    // 获取历史搜索
    getData() {
      let _this = this,
          para = {
              type: 1,
              token: _this.token,
              setEntry: 'headers'
          }
      let url = '/contents/searchKeyword/listKeywords'
      this.GET(url, para).then(res => {
          if (res.code == '000000') {
            if (res.data && res.data.length) {
              let index = Math.floor(Math.random() * res.data.length)
              this.searchText = res.data[index].keyword
            }
          }
      })
    },
    getUserInfo: function () {
      rocNative.getUserInfo({'__funcName': '__getUserInfo'})
    }, 
    getStatusBarHeight: function () {
      rocNative.getStatusBarHeight({'__funcName': '__getStatusBarHeight'})
    },
    gotoPage(item) {
      let obj = {

      }
      console.log(item);
      // let url = pageJumpUrl();
      //  console.log(url.pageListUrl);
      let itemData = {
          "imageUrl": "",
          "appModuleInfo": {
              "code": "M300",
              "type": 4,
              "name": "课程介绍页",
              "paramFlag": 1,
              "paramList": []
          }
      };
      obj = {
          menuLevel: 1,
          menuCode: 'm_home',
          functionCode: 'f_five_minutes',
          actionCode: 'c_content',
          labelId: item.id,
          labelValue: item.title,
      }
      itemData.title = item.name;
      itemData.appModuleInfo["paramList"] = [{
              "key": "pageUrl",
              "value": 'http://10.177.11.253:8019/#/search',
              // "value": 'com.picahealth.yunque.activitys.music.WebMusicListActivity###FiveMinutesMedicalSchoolWebViewController',
              "type": 4,
              "seqNo": 1
          }
      ]
      
      // this.pageBurialPoin(obj)

      let paramList = this.setEventByModuleCode(itemData);
      // alert(itemData.appModuleInfo.code)
      // alert(JSON.stringify(paramList))
      rocNative.dispatchEventByModuleCode({
          modeCode: itemData.appModuleInfo.code,
          jsonString: paramList
      })
    },

  },
}
</script>
<style >
  .mint-search {
    position: fixed;
    top: 0px;
    z-index: 2;
    height: 66px;
    width: 100%;
    /* margin: 0 20px; */
    border-bottom: 1px solid #E7E7E7 !important;
    background-color: #fff;
  }
 .mint-searchbar {
    position: relative;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    background: #fff;
    box-sizing: border-box;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    margin: 0 10px;
    padding: 30px 10px 8px;
    z-index: 1;
  }
  .mint-searchbar-cancel {
    margin-left: 10px;
    font-size: 14px ;
    color: #999;
    text-decoration: none;
  }
  .mint-searchbar-inner {
    background: #F5F6F6;
  }
  .mint-searchbar-core {
    color: #555555;
    background: #F5F6F6;
  }
</style>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
@import '../style/mixin.scss';
@import '../style/global.scss';
.mt-100 {
  padding-top: px2rem(63px) !important;
}
</style>
