<template>
  <div>
    <div class="view">
      <div class="img-box">
        <div class="show-box" :style="{
            transform: 'translateX(' + translate + 'px)',
            transition: tsion ? 'all 0.5s' : 'none',
          }" ref="swip">
          <img src="https://img1.baidu.com/it/u=1966616150,2146512490&fm=253&fmt=auto&app=138&f=JPEG?w=751&h=500" alt="" />
          <img v-for="(item, i) in src" :key="i" :src="item.img" alt="" class="imgg" />
          <img src="https://img1.baidu.com/it/u=1966616150,2146512490&fm=253&fmt=auto&app=138&f=JPEG?w=751&h=500" alt="" />
        </div>
      </div>
      <div class="arrowhead-box">
        <span @click="last"><img src="../../assets/OIP-C.jpg" alt="" style="height: 40px; width: 40px" /></span>
        <span @click="next"><img src="../../assets/OIP-C.jpg" alt="" style="height: 40px; width: 40px" /></span>
      </div>
      <div class="swiper-boxs" ref="swiper">
        <span v-for="(item, i) in src" :key="i" @click="swiper(i)"></span>
      </div>
    </div>
    <button @click="change3">多图轮播</button>
    <button @click="change2">圆角</button>
    <button @click="change1">颜色直角</button>
    <button @click="change5">删除分页</button>
    <button @click="change4">图片直圆角</button>
    <button @click="tabChange4">改变tab图片</button>
    <button @click="tabChange5">改变tab标题</button>
    <button @click="tabChange3">改变tab</button>

    <div class="tab" ref="tabs">
      <div class="tab_item" v-for="(item, index) in tabBarImg" :key="index" @click="switchToTab(item.path)">
        <img :src="item.normal" alt="" />
        <span :class="$route.path === item.path ? 'active' : ''">{{
        item.title
      }}</span>
      </div>
    </div>

  </div>
</template>

<script>
export default {
  data () {
    return {
      translateX: 0,
      tsion: true,
      src: [
        {
          img: "https://img1.baidu.com/it/u=1966616150,2146512490&fm=253&fmt=auto&app=138&f=JPEG?w=751&h=500",
        },
        {
          img: "https://ts3.cn.mm.bing.net/th?id=OIP-C.4TuOo-Fd0Q9Xt2PhrZwdnQHaE8&w=306&h=204&c=8&rs=1&qlt=90&o=6&dpr=1.15&pid=3.1&rm=2",
        },
        {
          img: "https://img1.baidu.com/it/u=1966616150,2146512490&fm=253&fmt=auto&app=138&f=JPEG?w=751&h=500",
        },

      ],
      tabBarImg: [
        {
          path: '/home',
          normal: require('../../assets/首页.png'),
          // icon: require('./../assets/images/ahome.png'),
          title: '首页'
        },
        {
          path: '/chat',
          normal: require('../../assets/列表.png'),
          // icon: require('./../assets/images/ahead.png'),
          title: '列表'
        },

        {
          path: '/login',
          normal: require('../../assets/我的.png'),
          // icon: require('./../assets/images/ahead.png'),
          title: '我的'
        },
      ]
    };
  },
  methods: {
    //改变tab底色，文字颜色
    tabChange3 () {
      let a = this.$refs.tabs.querySelectorAll("div");
      a.forEach((element) => {
        element.style.background = "hotpink";
        element.style.color = "white";
      });
    },
    //改变tab图片
    tabChange4 () {
      this.tabBarImg = [
        {
          path: '/home',
          normal: require('../../assets/蝴蝶结.png'),
          // icon: require('./../assets/images/ahome.png'),
          title: '首页'
        },
        {
          path: '/chat',
          normal: require('../../assets/列表.png'),
          // icon: require('./../assets/images/ahead.png'),
          title: '列表'
        },

        {
          path: '/login',
          normal: require('../../assets/蝴蝶结.png'),
          // icon: require('./../assets/images/ahead.png'),
          title: '我的'
        },
        {
          path: '/login',
          normal: require('../../assets/我的.png'),
          // icon: require('./../assets/images/ahead.png'),
          title: '我的'
        },

      ]

    },
    //改变tab标题
    tabChange5 () {
      this.tabBarImg = [
        {
          path: '/home',
          normal: require('../../assets/首页.png'),
          // icon: require('./../assets/images/ahome.png'),
          title: '啦啦啦啦啦'
        },
        {
          path: '/chat',
          normal: require('../../assets/列表.png'),
          // icon: require('./../assets/images/ahead.png'),
          title: '啦啦啦啦啦'
        },
        {
          path: '/login',
          normal: require('../../assets/我的.png'),
          // icon: require('./../assets/images/ahead.png'),
          title: '啦啦啦啦啦'
        },

      ]
    },
    //轮播五图
    change3 () {

      this.src = [
        {
          img: "https://img1.baidu.com/it/u=1966616150,2146512490&fm=253&fmt=auto&app=138&f=JPEG?w=751&h=500",
        },
        {
          img: "https://ts3.cn.mm.bing.net/th?id=OIP-C.4TuOo-Fd0Q9Xt2PhrZwdnQHaE8&w=306&h=204&c=8&rs=1&qlt=90&o=6&dpr=1.15&pid=3.1&rm=2",
        },
        {
          img: "https://img1.baidu.com/it/u=1966616150,2146512490&fm=253&fmt=auto&app=138&f=JPEG?w=751&h=500",
        },
        {
          img: "https://ts3.cn.mm.bing.net/th?id=OIP-C.4TuOo-Fd0Q9Xt2PhrZwdnQHaE8&w=306&h=204&c=8&rs=1&qlt=90&o=6&dpr=1.15&pid=3.1&rm=2",
        },
        {
          img: "https://img1.baidu.com/it/u=1966616150,2146512490&fm=253&fmt=auto&app=138&f=JPEG?w=751&h=500",
        },

      ]
    },
    //改变轮播图分页器颜色圆角
    change1 () {
      let a = this.$refs.swiper.querySelectorAll("span");
      a.forEach((element) => {

        element.style.width = "12px";
        element.style.background = "hotpink";
        element.style.borderRadius = "1px";
      });
    },

    change5 () {
      // let a = this.$refs.swiper
      // console.log(a)
      // let b = this.$refs.swiper.querySelectorAll("span");
      // b.forEach((element) => {
      //   a.removeChild(element)
      // });
      let a = this.$refs.swiper.querySelectorAll("span");
      a.forEach((element) => {
        element.style.display = "none"
      });

    },
    change2 () {
      let a = this.$refs.swiper.querySelectorAll("span");
      a.forEach((element) => {


        element.style.borderRadius = "50px";
      });
    },
    change4 () {
      let a = this.$refs.swip.querySelectorAll("img");
      a.forEach((element) => {


        element.style.borderRadius = "12px";
      });
    },
    last () {
      this.translateX--;
      this.tsion = true;
      if (this.translateX < 0) {
        setTimeout(() => {
          this.tsion = false;
          this.translateX = this.src.length - 1;
        }, 500);
      }
    },
    next () {
      this.translateX++;
      this.tsion = true;
      if (this.translateX > this.src.length - 1) {
        setTimeout(() => {
          this.tsion = false;
          this.translateX = 0;
        }, 500);
      }
    },
    switchToTab (path) {

      // this.$router.replace(path);
    },
    swiper (i) {
      this.translateX = i;
    },
  },
  mounted () {
    setInterval(() => {
      this.next();
    }, 3000);
  },
  computed: {
    translate () {
      return -(this.translateX + 1) * 425;
    },
  },
  watch: {
    translateX: {
      handler (val) {
        let a = this.$refs.swiper.querySelectorAll("span");
        a.forEach((element) => {
          element.style.width = "12px";
        });
        if (this.translateX < 0) {
          val = this.src.length - 1;
        }
        if (this.translateX > this.src.length - 1) {
          val = 0;
        }
        a[val].style.width = "30px";
      },
    },
  },
};
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
}
.tab {
  width: 100%;
  height: 10vh;
  display: flex;
  border-top: 1px solid #ccc;
  position: fixed;
  bottom: 0;
  background: #fff;
  z-index: 999;
  /* color: midnightblue; */
}
.tab_item {
  /* background: white; */
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex-direction: column;
}
.tab_item img {
  margin-top: 5px;
  width: 30px;
  height: 30px;
}
.tab_item span {
  margin-top: -10px;
}
.active {
  color: blue;
}

body {
  margin: 0;
  padding: 0;
  background-image: linear-gradient(to top, #37ecba 0%, #72afd3 100%);
}
button {
  width: 90px;
  height: 85px;
  margin-top: 10px;
}
.view {
  width: 380px;
  /* height: 160px; */
  margin-top: 10px;
}
span {
  margin: 0;
  padding: 0;
}
.big-box {
  width: 100%;
  background-color: #999;
  margin: 10px auto;
  /* position: fixed; */
  position: absolute;
  margin-top: 2%;
  margin-left: 2%;
}

.show-box {
  display: flex;
  transition: all 0.5s;
}
.show-box img {
  float: left;
  min-width: 394px;
  height: 200px;
}
.arrowhead-box {
  position: fixed;
  top: 160px;
  float: left;
  width: 100%;
  height: 50px;
}
.arrowhead-box span {
  float: left;
  display: block;
  /* height: 60px; */
  border-radius: 50px;
  background-position: 6px 14px;
  cursor: pointer;
  opacity: 0.5;
}
.arrowhead-box span img {
  border-radius: 50px;
}
.arrowhead-box span:nth-child(2) {
  float: right;
  transform: rotate(180deg);
}
.arrowhead-box span:hover {
  opacity: 1;
}
.swiper-boxs {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  top: 230px;
}
.swiper-boxs span {
  float: left;
  width: 12px;
  height: 12px;
  background-color: rgb(250, 177, 177);
  border-radius: 50px;
  margin-left: 10px;
  cursor: pointer;
  transition: all 0.5s;
}
.swiper-boxs span:nth-child(1) {
  width: 30px;
}
</style>
