<template>
  <div class="bottom-tab">
    <div :class="{actived:$route.name === 'index'}" @click="toUrl('index')">
      <div class="index img">
        <img :src="imgurl.indexBottom" alt>
      </div>
      启蒙
    </div>
    <div v-if="userCourse2.start_periods_id!=null||userCourse2.automation_id" :class="{actived:$route.name === 'map'||$route.name === 'secMap'||$route.name === 'hasaccount'}" @click="toUrl('map')">
      <div class="map img">
        <img :src="imgurl.indexBottom" alt>
      </div>
      上课
    </div>
    <div :class="{actived:$route.name === 'mine'}" @click="toUrl('mine')">
      <div class="mine img">
        <img :src="imgurl.indexBottom" alt>
      </div>
      我的
    </div>
  </div>
</template>

<script>
import { IndexImage } from "../../util/imgUrl";
export default {
  name: "bottomTab",
  data() {
    return {
      imgurl: IndexImage,
      userCourse2:{
      },
      ownDetail:{}
    };
  },
  mounted() {
    // debugger
    let userCourse2 = JSON.parse(localStorage.getItem("userCourse"));
    this.ownDetail = JSON.parse(localStorage.getItem("userDesc"));
    if(userCourse2){
      this.userCourse2 = userCourse2
    }
    console.log(this.userCourse2)
  },
  methods: {
    toUrl(data) {
      // console.log(this.$route.name)
      // debugger
      if (data == "map") {
        this.$sa.track("buttonClick", {
        tabTitle: "底部导航",
        moduleTitle: "功能按钮",
        buttonType: "切换按钮",
        buttonName: "切换到上课"
        });
       
        console.log(this.userCourse2)
        if(this.ownDetail.family_user!=1){
            if(this.userCourse2.start_periods_id!=null&&this.userCourse2.start_periods_course_type!=null){
            //  debugger
            this.$router.push({
            name: "map",
            query: {
              course_type: this.userCourse2.start_periods_course_type
            }
            });
          }else{
            this.$router.push({
            name: "secMap",
            query: {
              periods_id: this.userCourse2.start_periods_id,
              course_type: this.userCourse2.start_periods_course_type
            }
            });
          }
        }else{
          this.$router.push({
          name: "hasaccount"
         });
        }
        
        // this.$router.push({
        //   name: "secMap",
        //   query: {
        //     periods_id: this.userCourse2.start_periods_id,
        //     course_type: this.userCourse2.start_periods_course_type
        //   }
        // });
      } else {
        this.$sa.track("buttonClick", {
        tabTitle: "底部导航",
        moduleTitle: "功能按钮",
        buttonType: "切换按钮",
        buttonName: data === "index" ? "切换到首页" : "切换到我的"
        });
        this.$router.push({ name: data });
      }
    },
    setBtn(){
      let userCourse2 = JSON.parse(localStorage.getItem("userCourse"));
      this.userCourse2 = userCourse2
      // console.log(this.userCourse2)
    }
  }
};
</script>

<style scoped lang="less">
@import "../../util/public";
.bottom-tab {
  width: 375rem;
  height: 48rem;
  position: fixed;
  left: 0;
  bottom: 0;
  box-shadow: 0px -1px 2px 0px rgba(204, 204, 204, 0.5);
  padding: 0 24rem;
  box-sizing: border-box;
  display: flex;
  display: -webkit-flex;
  font-size: 10rem;
  font-family: PingFang-SC-Medium;
  text-align: center;
  font-weight: normal;
  color: #666666;
  line-height: 14rem;
  z-index: 30;
  background: white;
  & > div {
    width: 50%;
  }
  .left {
    // border-right: 1px solid #eeeeee;
  }
  .img {
    width: 28rem;
    height: 28rem;
    overflow: hidden;
    position: relative;
    img {
      width: 28rem;
      position: absolute;
      left: 0;
    }
  }
  .index {
    img {
      top: -28rem;
    }
  }
  .map {
    img {
      top: -56rem;
    }
  }
  .mine {
    img {
      top: -84rem;
    }
  }
  .actived {
    .index {
      img {
        top: -140rem;
      }
    }
    .map {
      img {
        top: -112rem;
      }
    }
    .mine {
      img {
        top: 0;
      }
    }
  }
}

@media screen and (min-width: 600px) {
  @toVw: 100/1024vw;
  .bottom-tab {
    width:100%;
    height: 66rem;
    position: fixed;
    left: 0;
    bottom: 0;
    box-shadow: 0px -1px 2px 0px rgba(204, 204, 204, 0.5);
    padding: 0 6rem;
    display: flex;
    display: -webkit-flex;
    font-size: 10rem;
    font-family: PingFang-SC-Medium;
    text-align: center;
    font-weight: normal;
    color: #ccc;
    line-height: 14rem;
    z-index: 30;
    background: white;
    & > div {
      width: 50%;
    }
    .actived {
      color: #6eb1ff;
    }
    .img {
    width: 30rem;
    height: 30rem;
    overflow: hidden;
    position: relative;
    img {
      width: 30rem;
      position: absolute;
      left: 0;
    }
   }
   .index {
    img {
      top: -30rem;
    }
  }
  .map {
    img {
      top: -60rem;
    }
  }
  .mine {
    img {
      top: -91rem;
    }
  }
  .actived {
    .index {
      img {
        top: -151rem;
      }
    }
    .map {
      img {
        top: -119rem;
      }
    }
    .mine {
      img {
        top: 0;
      }
    }
  }
  }
}
</style>
