<template>
  <div class="components-add">
    <div class="add-api-box">
      <div class="add-head">
        <span>添加API</span>
        <i class="el-icon-close" @click="onClose"></i>
      </div>

      <div class="tab-content">
        <div class="tab-box" ref="tabItem">
          <div @click="changeTab(0, $event)">全部</div>
          <div @click="changeTab(1, $event)">基础工具API</div>
          <div @click="changeTab(2, $event)">搜索相关API</div>
          <div @click="changeTab(3, $event)">特色栏目API</div>
          <div @click="changeTab(4, $event)">入库更新API</div>
          <div ref="tabLine" class="tab-line"></div>
        </div>
        <div class="content-box">
          <div
            class="content-item"
            v-for="(item, index) in 20"
            :key="index"
          >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      setWidth: 0,
    };
  },
  created() {
    document.body.style.overflow = "hidden";
  },

  destroyed() {
    document.body.style.overflow = "auto";
  },

  mounted() {
    this.setWidth = this.$refs.tabItem.children[0].offsetWidth;
    this.$refs.tabLine.style.width = this.setWidth + "px";
    this.$refs.tabLine.style.transform = `translateX(${this.offSet}px)`;
    this.$refs.tabLine.style.transition = "transform  .5s ,width .5s ";
  },

  methods: {
    changeTab: function (value, e) {
      let offSet = 0;
      for (let i = 0; i < value; i++) {
        offSet = offSet + this.$refs.tabItem.children[i].offsetWidth + 50;
      }
      let width = e.target.offsetWidth; // 当前元素的宽
      this.$refs.tabLine.style.transform = `translateX(${offSet}px)`;
      this.$refs.tabLine.style.width = width + "px";
      this.$refs.tabLine.style.transition = "transform  .5s , width .5s ";
    },

    onClose(){
        this.$emit('onClose')
    }
  },
};
</script>


<style lang="scss" scoped>
.components-add {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  min-height: 100vh;
  overflow-x: hidden;
  background: rgba($color: #000000, $alpha: 0.3);
  z-index: 99;
  display: flex;
  justify-content: center;
  align-items: center;

  .add-api-box {
    width: 1080px;
    height: 690px;
    background: #ffffff;
    border-radius: 14px;
    box-sizing: border-box;
    overflow: hidden;
    .add-head {
      width: 100%;
      height: 64px;
      background: #fafafa;

      padding: 0 20px;
      box-sizing: border-box;
      display: flex;
      flex-flow: row nowrap;
      justify-content: space-between;
      align-items: center;
      span {
        padding-left: 15px;
        border-left: 4px solid #1890ff;
        display: inline-block;
        line-height: 19px;
        height: 19px;
        font-size: 19px;
      }
      .el-icon-close {
        font-size: 16px;
        width: 30px;
        cursor: pointer;
        text-align: center;
        height: 30px;
        line-height: 30px;
      }
    }
    .tab-content {
      height: 546px;
      width: 100%;
      overflow-y: auto;
      padding-bottom: 20px;
      box-sizing: border-box;
      border-bottom: 1px solid #eeeeee;

      .tab-box {
        height: 96px;
        background: #fff;
        padding: 0 20px;
        box-sizing: border-box;
        display: flex;
        position: relative;
        align-items: center;
        div {
          margin-right: 50px;
          color: #333333;
          font-size: 20px;
          position: relative;
          cursor: pointer;
        }

        .tab-line {
          position: absolute;
          width: 0;
          height: 4px;
          bottom: 25px;
          left: 21px;
          background-color: #1890ff;
          transform: translateX(0);
        }
      }
      .content-box {
        display: flex;
        flex-flow: wrap;
        width: 100%;
        padding: 0 20px 0 20px;
        box-sizing: border-box;
        justify-content: space-between; /* 横向中间自动空间 */

        .content-item {
          width: 330px;
          height: 130px;
          background: #ffffff;
          border-radius: 14px;
          border: 1px solid #dddddd;
          margin-bottom: 20px;
        }
      }
    }

    .tab-content::-webkit-scrollbar {
      //   width: 6px;
      //   height: 60px;
      //   background: #d8d8d8;
      //   border-radius: 3px;
      background: #fff;
      width: 6px;
    }
    .tab-content::-webkit-scrollbar-thumb {
      width: 6px;
      height: 60px;
      background: #d8d8d8;
      border-radius: 3px;
    }
  }
}
</style>