<template>
  <div class="search">
    <div class="tab">
      <div
        :class="['tab-item', activeTab == item ? 'active' : '']"
        @click="handleClickTab(item)"
        v-for="(item, index) in tabs"
        :key="index"
      >
        {{ item }}
      </div>
    </div>
    <div class="search-input">
      <el-input
        placeholder="输入关键词搜索，马上在线阅读"
        v-model="keyword"
        clearable
      ></el-input>
      <el-button icon="el-icon-search" type="primary" @click="handleSearch"
        >搜索
      </el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tabs: ["期刊", "论文", "会议", "报纸"],
      activeTab: "期刊",
      keyword: "",
    };
  },
  methods: {
    handleClickTab(item) {
      this.activeTab = item;
    },
    handleSearch() {
      this.$emit("search");
    },
  },
};
</script>

<style lang="scss" scoped>
.search {
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;

  .tab {
    display: flex;
    margin-bottom: 20px;
    .tab-item {
      margin-right: 20px;
      padding: 4px 20px;
      cursor: pointer;
      &:hover {
        color: $theme-blue;
        font-weight: bold;
      }
    }
    .active {
      background-color: rgba($color: $theme-blue, $alpha: 0.1);
      border-radius: 4px;
      color: $theme-blue;
      font-weight: bold;
      position: relative;
      &::after {
        position: absolute;
        width: 0;
        height: 0;
        content: "";
        border: 8px solid rgba($color: $theme-blue, $alpha: 0.1);
        border-left: 8px solid transparent;
        border-right: 8px solid transparent;
        border-bottom: 8px solid transparent;
        bottom: -16px;
        left: 50%;
        transform: translateX(-50%);
      }
    }
  }
  .search-input {
    display: flex;
    .el-button {
      margin-left: 20px;
    }
    ::v-deep .el-input {
      input {
        background-color: #f7f8fa;
        border: none;
      }
    }
  }
}
</style>
