<template>
  <header-md class="middle_before textR">
    <div slot="center" class="search-wrapper middle">
      <i class="iconfont">&#xe60a;</i>
      <div class="search-input h100 ">
        <input ref="input" class="inputTxt h100 w100  " type="text" name="" value="" placeholder="搜索教程"
               @keydown.13="searchHandle" v-model.trim="searchVal"/>
        <button>搜索</button>
      </div>
    </div>
  </header-md>
</template>

<script>
  export default {
    data () {
      return {
        searchVal: this.$route.query.searchval ? this.$route.query.searchval : ''
      }
    },
    methods: {
      searchHandle () {
        if (!this.searchVal) {
          this.$alertMsg.alert('搜索不能为空！', 1000)
          return
        }
        this.$refs.input.blur()
        this.$emit('searchHandle', this.searchVal)
      }
    }
  }
</script>

<style lang="less" scoped>
  @import url("../assets/config.less");

  .search-wrapper {
    @h: 56;
    .m-h(@h);
    .m-lh(@h);
    .m-pdL(30);
    .m-pdR(30);
    width: 90%;
    /*margin: 13px auto;*/
    position: relative;
    font-size: 14px;
    .iconfont {
      position: absolute;
      left: 20px;
      top: 0;
      display: block;
      color: #333;
      .m-w(@h);
      text-align: center;
    }
    @btnH: 74;
    .search-input {
      .m-mgR(@btnH);
      .m-pdL(@h+5px);
      border: 1px solid #fff;
      background: #fff;
      border-radius: @h/2px;
      input {
        float: left;
        color: #333;
      }
      ::-webkit-input-placeholder {
        color: #a3beb0;
      }
    }
    button {
      position: absolute;
      right: 15px;
      top: 0;
      display: block;
      .m-w(@btnH);
      .m-h(@h);
      color: #fff;
      text-align: right;
    }
  }
</style>
