<template>
  <div id="navtab">
    <i class="el-icon-arrow-left" @click="tapFirst"></i>
    <div class="list" ref="listNav">
      <div
        class="lis"
        @mouseenter="mouseIn($event, item.id)"
        @mouseleave="mouseLeave()"
        @click="tourl(item)"
        :class="{ showlis: info.supplier_list[tapInd - 1].id == item.id }"
        v-for="(item, index) in listShow(info.supplier_list)"
        :key="index"
      >
        <div>{{ item.store_name == 'null'?item.username.slice(0,5):item.store_name.slice(0,5) }}</div>
        <div>{{ item.store_name == 'null'?item.username.slice(5,7):item.store_name.slice(5,7) }}</div>
      </div>
    </div>
    <i class="el-icon-arrow-right" @click="tapNext"></i>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  props: {
    info: {
      type: Object,
      default: {},
    },
    timeSet: {
      type: Number,
      default: 3000,
    },
  },
  computed: {
    ...mapState(["basicSet", "basic_info"]),
  },
  data() {
    return {
      showListInd: 0,
      tapInd: 1,
      // arr: ["1", "2", "3", "4", "5", "6", "7", "8"],
      // 后端设置的秒数
      settimeOut: null,
      ceilNum: 0,
    };
  },
  mounted() {
    this.$emit("postChildInd", this.tapInd - 1);
    if (this.timeSet != 0) {
      this.settimeOut = setInterval(() => {
        if (this.tapInd < this.info.supplier_list.length) {
          this.tapInd = this.tapInd + 1;
        } else {
          this.tapInd = 1;
        }
        if (this.tapInd <= 9) {
          this.showListInd = 9;
        } else if (
          this.tapInd > this.showListInd &&
          this.showListInd < this.info.supplier_list.length
        ) {
          this.showListInd = this.showListInd + 9;
        }
        this.$emit("postChildInd", this.tapInd - 1);
      }, this.timeSet);
    }
  },
  methods: {
    tourl(item) {
      let supplier_Id = item.id;
      if (this.$baseURL) {
        // 静态部署环境下
        this.$router.push(
          this.fun.getUrl("supplierGoodList", { id: supplier_Id }, {})
        );
      } else {
        this.$router.push(
          this.fun.getUrl("supplierGoodList-id", { id: supplier_Id }, {})
        );
      }
    },
    mouseLeave() {
      if (this.timeSet != 0) {
        if (!this.settimeOut) {
          this.settimeOut = setInterval(() => {
            if (this.tapInd < this.info.supplier_list.length) {
              this.tapInd = this.tapInd + 1;
            } else {
              this.tapInd = 1;
            }
            this.$emit("postChildInd", this.tapInd - 1);
          }, this.timeSet);
        }
      }
    },
    mouseIn(e, id) {
      for (let i = 0; i < this.info.supplier_list.length; i++) {
        if (this.info.supplier_list[i].id == id) {
          this.tapInd = Number(i + 1);
        }
      }
      // this.tapInd = Number(ind + 1);
      if (this.timeSet != 0) {
        if (this.settimeOut) {
          clearInterval(this.settimeOut);
          this.settimeOut = null;
        }
      }
      this.$emit("postChildInd", this.tapInd - 1);
    },
    tapFirst() {
      if (this.showListInd == 9) return;
      if (this.showListInd - 9 <= 9) return (this.showListInd = 9);
      this.showListInd = this.showListInd - 9;
    },
    tapNext() {
      let len = this.info.supplier_list.length;
      if (len <= 9) return;
      if (this.showListInd == len) return;
      if (this.showListInd + 9 > len) {
        this.showListInd = len;
      } else {
        this.showListInd = this.showListInd + 9;
      }
    },
    listShow(arr) {
      if (this.showListInd == 0) {
        this.showListInd = 9;
        let arrinfo = arr.slice(0, this.showListInd);
        return arrinfo;
      } else {
        let arrinfo = arr.slice(this.showListInd - 9, this.showListInd);
        return arrinfo;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.el-icon-arrow-left,
.el-icon-arrow-right {
  font-size: 20px;
  color: #7e7e7e;
  cursor: pointer;
}
#navtab {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 32px;
  overflow: hidden;
}
::-webkit-scrollbar {
  display: none;
}

.list {
  padding: 20px 0;
  width: 100%;
  display: flex;
  justify-content: flex-start;
  overflow: hidden;
  .showlis {
    color: #2973fd;
    font-size: 14px;
  }
  .lis {
    cursor: pointer;
    flex-shrink: 0;
    margin: 0 0 0 42px;
    width: 77px;
    font-size: 14px;
    font-weight: bold;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-align: center;
  }
}
</style>