<!--
  <open-doc-header :currentTab="currentTab" @changeTab="changeTab" @searchMenu="searchMenu"></open-doc-header>
  import openDocHeader from '@/components/open-doc-header.vue';
-->
<template>
  <div class="open-header">
    <div class="open-header-wrap border-box flex ">
      <div class="open-header-left" @click="toHome"><img src="../assets/document/logo.png" alt="" /></div>
      <div class="open-header-right border-box">
        <div class="open-header-right_wrap flex flex-space-between">
          <ul class="flex">
            <li v-for="(item, index) in openMenuData" :key="index + 'menu'" :class="['menu-li border-box', currentMenuTab == item.menuId ? 'active-tab' : '']" @click.stop.prevent="toRedirect(item)">
              <span>{{ item.menuName }}</span>
            </li>
          </ul>
          <div class="search-wrap">
            <el-input clearable placeholder="请输入搜索内容" prefix-icon="el-icon-search" v-model="searchValue" @keyup.native="value => searchData(value)" @clear="clearInput"> </el-input>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { _debounce } from '@/assets/js/public';
export default {
  name: 'vue-open-header',
  props: {
    currentTab: {
      type: [String, Number],
      default() {
        return '2';
      }
    }
  },
  data() {
    return {
      currentMenuTab: this.currentTab,
      openMenuData: [
        {
          menuId: '2',
          menuName: '开发者接入',
          menuUrl: ''
        },
        {
          menuId: '1',
          menuName: '解决方案',
          menuUrl: ''
        }
      ],
      searchValue: ''
    };
  },

  methods: {
    toRedirect(item) {
      const that = this;
      that.currentMenuTab = item.menuId;
      that.$emit('changeTab', item.menuId);
    },
    toHome() {
      const that = this;
      that.$router.push('/home');
    },
    /**
     *  搜索
     */
    searchData: _debounce(function(value) {
      const that = this;
      that.$emit('searchMenu', that.searchValue, that.currentMenuTab);
    }, 500),

    /**
     *  搜索清除
     */
    clearInput() {
      const that = this;
      that.$emit('searchMenu', that.searchValue, that.currentMenuTab);
    }
  },
  watch: {
    $route: {
      handler: function(val, oldVal) {
        // console.log('获取当前路由:', val);
      },
      // 深度观察监听
      deep: true
    },
    currentTab(newData, oldData) {
      const that = this;
      that.currentMenuTab = newData;
    }
  },
  /* 接收数据 */
  mounted() {
    const that = this;
    that.currentMenuTab = that.$route.query.currentTab || '2';
  }
};
</script>

<style lang="less" scoped>
.open-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 58px;
  line-height: 58px;
  background: #fff;
  border-bottom: 1px solid #e1e6f0;
  box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.03);
  z-index: 3;
  &-wrap {
    width: 100%;
    margin: 0 auto;
    height: 58px;
    line-height: 58px;
    .open-header-left {
      position: relative;
      width: 300px;
      text-align: center;
      cursor: pointer;
      &::after {
        content: '';
        position: absolute;
        right: 0;
        top: 50%;
        -webkit-transform: translateY(-50%);
        -moz-transform: translateY(-50%);
        transform: translateY(-50%);
        width: 0;
        height: 21px;
        border-right: 1px solid #e1e6ef;
      }
      img {
        display: inline-block;
        vertical-align: middle;
      }
      span {
        font-size: 17px;
      }
    }
    .open-header-right {
      width: calc(100% - 300px);
      padding: 0 40px 0 32px;
      .open-header-right_wrap {
        height: 58px;
      }
      ul {
        .menu-li {
          position: relative;
          margin-right: 32px;
          height: 58px;
          line-height: 58px;
          font-size: 14px;
          color: #16214a;
          cursor: pointer;
          &.active-tab {
            color: #4c70e8;
            border-bottom: 2px solid #4c70e8;
          }
          .icon-arrow_right {
            display: inline-block;
            padding: 0 4px;
            font-size: 12px;
            -webkit-transition: 0.3s all;
            -moz-transition: 0.3s all;
            -o-transition: 0.3s all;
            -ms-transition: 0.3s all;
            transition: 0.3s all;
          }
          &:hover {
            color: #4c70e8;
            border-bottom: 2px solid #4c70e8;
            .icon-arrow_right {
              color: #4c70e8;
              -webkit-transform: rotate(180deg);
              -moz-transform: rotate(180deg);
              -o-transform: rotate(180deg);
              -ms-transform: rotate(180deg);
              transform: rotate(180deg);
            }
            .menu-child {
              display: block;
            }
          }
          .menu-child {
            display: none;
            position: absolute;
            top: 58px;
            left: -30px;
            width: 140px;
            // border: 1px solid #ebeef5;
            border-radius: 0px;
            background: #ffffff;
            box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.08);
            z-index: 1;
            .child-menu-ul {
              padding: 20px 0 20px 32px;
            }
            .child-item-menu {
              line-height: 40px;
              margin: 0;
              cursor: pointer;
              outline: none;
              font-size: 14px;
              color: #16214a;
              &:hover {
                color: #4c70e8;
              }
            }
          }
        }
      }
      .search-wrap {
        position: relative;
        &::after {
          content: '';
          position: absolute;
          left: -12px;
          top: 50%;
          -webkit-transform: translateY(-50%);
          -moz-transform: translateY(-50%);
          transform: translateY(-50%);
          width: 0;
          height: 21px;
          border-left: 1px solid #e1e6ef;
        }
        .el-input {
          /deep/ .el-input__inner {
            border: none;
            padding-left: 33px;
          }
          /deep/ .el-input__prefix {
            color: #34495e;
            font-size: 16px;
            .child-item-menu {
              color: #34495e;
            }
          }
        }
      }
    }
  }
}
</style>
