<template>
  <div class="index">
    <div class="banner-block">
    <swiper :options="swiperOption" class="banner" ref="mySwiper">
      <swiper-slide v-for="(data,index) in bannerList" :key="index">
        <img class="banner" :src="data.url">
      </swiper-slide>
    </swiper>
    </div>
    <div class="btn-block">
      <div class="btn">
        <img :src="imgUrl.record"/>
      </div>
      <div class="btn">
        <img :src="imgUrl.money"/>
      </div>
      <div class="btn">
        <img :src="imgUrl.listen"/>
      </div>
      <div class="btn">
        <img :src="imgUrl.more"/>
      </div>
    </div>
    <div class="class-block">
      <div class="title" @click="toGoodsList()">
        我的课程
        <img class="more" :src="imgUrl.indexMore"/>
      </div>
      <div class="lesson-block">
        <swiper :options="swiperOption2">
          <swiper-slide v-for="(data,index) in lessonList" :key="index">
            <div class="goods-block" @click="toMap(data)">
              <span class="tips">
                开课时间：{{data.periods_info.start_at}}
              </span>
              <img :src="data.goods_info.goods_desc.img[0].url">
            </div>
          </swiper-slide>
          <swiper-slide>
            <div class="goods-block" @click="toMap(data)">
              <img :src="imgUrl.noMore">
            </div>
          </swiper-slide>
        </swiper>
      </div>
    </div>
    <mt-popup v-model="teacherQ2">
      <div class="teacher-block">
        <img :src="imgUrl.teacherBg" class="teacher-bg"/>
        <div class="closeBtn" @click="teacherQ2 = false"></div>
      </div>
    </mt-popup>
    <bottom-tab></bottom-tab>
  </div>
</template>

<script>
  import 'swiper/dist/css/swiper.css'
  import { swiper, swiperSlide } from 'vue-awesome-swiper'
  import {getBannerListApi,getUserLessonApi} from "../service/api";
  import {IndexImage} from "../util/imgUrl";
  import bottomTab from './public/bottomTab';
  export default {
    name: "index",
    components:{
      swiper,
      swiperSlide,
      bottomTab
    },
    data(){
      return {
        bannerList:[],
        teacherQ2:true,
        imgUrl: IndexImage,
        swiperOption: {
          pagination: {
            el: '.swiper-pagination'
          }
        },
        swiperOption2:{
          width: window.innerWidth*0.95,
        },
        lessonList:[]
      }
    },
    methods:{
      initPage(){
        getBannerListApi().then(res=>{
          this.bannerList = res.list
        });
        getUserLessonApi().then(res=>{
          res.forEach(i=>{
            i.goods_info.desc = JSON.parse(i.goods_info.desc);
            i.goods_info.share_desc = JSON.parse(i.goods_info.share_desc);
            i.goods_info.goods_desc = JSON.parse(i.goods_info.goods_desc)
          });
          this.lessonList = res
        })
      },
      toGoodsList(){
        this.$router.push({name:'myGoodsList'})
      },
      toMap(data){
        this.$router.push({
          name:'map',
          query:
            {
              periods_id:data.periods_id,
              parent_category_id:data.periods_info.parent_category_id
            }
        })
      }
    },
    mounted(){
      this.initPage()
    }
  }
</script>

<style scoped lang="less">
@import "../util/public";
  .index{
    background: #eee;
    padding-bottom: 80px;
  }
  .banner-block{
    width: 375*@toVw;
    height: 200*@toVw;
    .banner{
      width: 375*@toVw;
      height: 200*@toVw;
    }
  }
  .teacher-block{
    position: relative;
    .teacher-bg{
      width: 280*@toVw;
    }
    .closeBtn{
      position: absolute;
      width: 30*@toVw;
      height: 30*@toVw;
      right: 8*@toVw;
      top: 8*@toVw;
    }
  }

  .btn-block{
    display: flex;
    padding: 12*@toVw 8*@toVw;
    background: white;
    justify-content: space-around;
    .btn{
      width: 68*@toVw;
      height: 68*@toVw;
      img{
        width: 100%;
      }
    }
  }
  .lesson-block{
    padding-bottom: 20px;
    .goods-block{
      position: relative;
      width: 335*@toVw;
      .tips{
        display: inline-block;
        font-size:12px;
        font-family:PingFang-SC-Bold;
        font-weight:normal;
        color:rgba(255,255,255,1);
        line-height:17px;
        padding: 2px 5px;
        position: absolute;
        right: 10px;
        top: 12px;
        background:rgba(245,166,35,1);
        border-radius:10px;
      }
      img{
        width: 335*@toVw;
        height: 236*@toVw;
        border-radius: 8px;
      }
    }

  }
  .class-block{
    margin-top: 10px;
    font-family: PingFang-SC-Medium;
    font-size: 18px;
    color: #333333;
    text-align: center;
    background: white;
    .title{
      padding: 8*@toVw;
      position: relative;
      .more{
        position: absolute;
        width: 30*@toVw;
        bottom: 10px;
        right: 20px;
      }
    }
  }
</style>
