<template>
  <div class="video-page">
    <div class="content">
      <div class="header">
        <img :src="imgURL.luolacoming" class="text" v-if="nowShow === 3">
        <img :src="imgURL.luolalaila" class="text" v-if="nowShow === 2">
      </div>
      <div class="video-block hp-video" v-if="showObj.video[videoIndex]">
        <video :src="showObj.video[videoIndex].url" @ended="videoEnd" @play="videoPlay()" controls :poster="showObj.video[videoIndex].url+'?vframe/jpg/offset/3'"></video>
      </div>
      <div class="btn-block">
        <div v-if="contentData.content.age" class="age-block" @click="ageShow = !ageShow">
          <div v-if="contentData.age === 1">0-3岁<i class="playImage _154722344142123489"></i></div>
          <div v-if="contentData.age === 2">4-6岁<i class="playImage _154722344142123489"></i></div>
        </div>
        <div v-if="showObj.video.length > 1" class="age-block video" @click="videoShow = !videoShow">
          <div>视频({{videoIndex+1}})<i class="playImage _154722344142123489"></i></div>
        </div>
        <div class="age-change-block video" v-if="showObj.video.length > 1 && videoShow">
          <div @click="videoIndex= index;videoShow=false"  v-for="(item,index) in showObj.video">视频({{index+1}})<i :class="{'playImage _282918034425091245':index === videoIndex}" v-if="contentData.age === 1"></i></div>
        </div>
        <div class="age-change-block" v-show="ageShow" v-if="contentData.content.age && ageShow">
          <div @click="contentData.age = 1;ageShow=false;sendConsole('选择分龄')">0-3岁<i class="playImage _282918034425091245" v-if="contentData.age === 1"></i></div>
          <div @click="contentData.age = 2;ageShow=false;sendConsole('选择分龄')">4-6岁<i class="playImage _282918034425091245" v-if="contentData.age === 2"></i></div>
        </div>
        <div v-if="showObj.change" class="change-block-HP" @click="changeAudio(true)">
          <div class="">
            <img :src="imgURL.tapToAudio"/>
          </div>
        </div>
        <div v-if="showObj.change" class="change-block">
          <div class="active">视频教学</div>
          <div @click="changeAudio(true)">音频教学</div>
        </div>
      </div>
    </div>
    <guide-block/>
  </div>

</template>

<script>
  import luolacoming from '../../assets/newLesson/luoLacoming.png'
  import luolalaila from '../../assets/newLesson/luolalaila.png'
  import guideBlock from '../guide/video'
  import tapToAudio from '../../assets/tapToAudio.png'
  export default {
    name: "play",
    components:{
      guideBlock
    },
    data(){
      return{
        ageShow:false,
        showObj:{
          video:[],
          change:false
        },
        videoShow:false,
        videoIndex:0,
        imgURL:{
          luolacoming:luolacoming,
          luolalaila:luolalaila,
          tapToAudio:tapToAudio
        }
      }
    },
    props:[
      'contentData','nowShow'
    ],
    mounted(){
      this.changeAge(this.contentData.age)
    },
    methods:{
      videoEnd(event){
        event.srcElement.play()
      },
      sendConsole(data){
        this.$sa.track('watchClick',{
          elementName:JSON.parse(localStorage.getItem('lessonDetail')).title,
          themeID:JSON.parse(localStorage.getItem('lessonDetail')).themeID,
          themeName:JSON.parse(localStorage.getItem('lessonDetail')).themeName,
          goodsID:JSON.parse(localStorage.getItem('lessonDetail')).goodsID,
          classID:JSON.parse(localStorage.getItem('lessonDetail')).classID,
          buttonName:data,
          partName:this.contentData.partName,
          elementID:this.$route.query.elementId.toString(),
        });
      },
      changeAudio(flag){
        if(flag){
          this.$sa.track('watchClick',{
            elementName:JSON.parse(localStorage.getItem('lessonDetail')).title,
            themeID:JSON.parse(localStorage.getItem('lessonDetail')).themeID,
            themeName:JSON.parse(localStorage.getItem('lessonDetail')).themeName,
            goodsID:JSON.parse(localStorage.getItem('lessonDetail')).goodsID,
            classID:JSON.parse(localStorage.getItem('lessonDetail')).classID,
            buttonName:'切换音频教学',
            partName:this.contentData.partName,
            elementID:this.$route.query.elementId.toString(),
          });
        }
        this.contentData.type = 'audio'
      },
      videoPlay(){
        // 神策埋点 点击操作
        this.$sa.track('watchClick',{
          elementName:JSON.parse(localStorage.getItem('lessonDetail')).title,
          themeID:JSON.parse(localStorage.getItem('lessonDetail')).themeID,
          themeName:JSON.parse(localStorage.getItem('lessonDetail')).themeName,
          goodsID:JSON.parse(localStorage.getItem('lessonDetail')).goodsID,
          classID:JSON.parse(localStorage.getItem('lessonDetail')).classID,
          buttonName:'播放视频',
          partName:this.contentData.partName,
          elementID:this.$route.query.elementId.toString(),
        });
      },
      changeAge(value){
        if(this.contentData.content.age && value === 2){
          this.showObj = {
            video:this.contentData.content.video2,
            change:this.contentData.content.change2
          }
        }else{
          this.showObj = {
            video:this.contentData.content.video,
            change:this.contentData.content.change
          }
        }
      }
    },
    watch:{
      'contentData':{
        handler:function() {
          this.videoIndex = 0;
          this.changeAge(this.contentData.age)
        },
        deep: true
      },
    }
  }
</script>

<style scoped lang="less">
  @import "../../util/public";
  .playImage{background:url('https://static-cdn.changchangenglish.com/new-sing/static/images/playImage.png')  no-repeat;background-size:40*@toVw 189*@toVw;display: inline-block}
  ._154722344142123489{height:5*@toVw;width:9*@toVw;background-position:0 0;}
  ._282918034425091245{height:8*@toVw;width:9*@toVw;background-position:0 -4*@toVw;vertical-align: bottom}
  .video-page{
    .content{
      background: white;
      width: 315*@toVw;
      position: absolute;
      top: 80*@toVw;
      left: 20*@toVw;
      right: 20*@toVw;
      bottom: 20*@toVw;
      overflow: auto;
      margin: auto;
      display: block;
      border-radius: 8*@toVw;
      padding: 10*@toVw;
      .header{
        padding-top: 8*@toVw;
        .text{
          width:100% ;
        }
      }
      .video-block{
        margin-bottom: 16*@toVw;
        border: 1*@toVw solid #666;
        border-radius: 12*@toVw;
        padding: 8*@toVw;
        video{
          width: 100%;
          margin: 0;
          display: block;
          padding: 0;
          background:rgba(0,0,0,0.4);
          border-radius:8*@toVw;
        }
      }
      .btn-block{
        position: relative;
        text-align: center;
        .age-block{
          height: 28*@toVw;
          line-height: 28*@toVw;
          border: 1*@toVw solid #666;
          position: absolute;
          padding: 0 13*@toVw;
          border-radius: 100*@toVw;
          font-size:12*@toVw;
          font-family:PingFang-SC-Medium;
          font-weight:500;
          color:rgba(102,102,102,1);
          &.video{
            right: 0;
          }
        }
        .age-change-block{
          &.video{
            right: 0;
            left: auto;
            width: 80*@toVw;
          }
          display: block;
          position: absolute;
          top: 37*@toVw;
          left: 0;
          width: 66*@toVw;
          border-radius: 8*@toVw;
          border: 1*@toVw solid #666666;
          font-size:12px;
          font-family:PingFang-SC-Medium;
          font-weight:500;
          color:rgba(102,102,102,1);
          &>div{
            padding: 6*@toVw 11*@toVw;
            text-align: left;
            &:first-child{
              border-bottom: 1*@toVw solid #eee;
            }
          }
        }
        .change-block{
          border-radius: 1000*@toVw;
          width: 144*@toVw;
          border:1*@toVw solid #40A9FF;
          &:after{
            content: '';
            display: block;
            clear: both;
          }
          div{
            float: left;
            width: 50%;
            border-radius: 100*@toVw;
            font-size:12*@toVw;
            height: 28*@toVw;
            line-height: 28*@toVw;
            font-family:PingFang-SC-Medium;
            font-weight:500;
            color:rgba(204,204,204,1);
            &.active{
              background: #40A9FF;
              color: white;
            }
          }
        }
      }
    }
  }
  .change-block-HP{
    display: none;
  }
  @media screen and (orientation: landscape) {
    @toVw:100/667vw;
    .video-page{
      position: absolute;
      top: 5*@toVw;
      bottom: 5*@toVw;
      left: 5*@toVw;
      right: 5*@toVw;
      background:rgba(255,255,255,1);
      overflow: auto;
      border-radius:8*@toVw;
      .content{
        position: static;
        height: 100%;
        width: 100%;
        display: flex;
        border-radius: 8px;
        padding: 0;
        .header{
          display: none;
        }
        .video-block{
          display: none;
          &.hp-video{
            display: inline-block;
            margin: 0 10*@toVw 0 0;
            border: none;
            height: 100%;
            border-radius: 12*@toVw;
            padding: 0;
          }
          video{
            height: 100%;
            margin: auto;
            width: auto;
            display: block;
            background:rgba(0,0,0,0.4);
            border-radius:8*@toVw;
          }
        }
        .btn-block{
          position:relative;
          min-width: 90*@toVw;
          display: block;
          height: 100%;
          .age-block{
            display: block;
            position: static;
            padding: 0;
            height: 28*@toVw;
            width: 88*@toVw;
            line-height: 28*@toVw;
            border: 1*@toVw solid #666;
            border-radius: 100*@toVw;
            font-size:12*@toVw;
            font-family:PingFang-SC-Medium;
            font-weight:500;
            color:rgba(102,102,102,1);
            &.video{
              display: block;
            }
          }
          .age-change-block{
            &.video{
              right: 0;
              left: auto;
              width: 80*@toVw;
            }
            position: static;
            display: block;
            width: 80*@toVw;
            margin-top: 10*@toVw;
            border-radius: 8*@toVw;
            border: 1*@toVw solid #666666;
            font-size:12*@toVw;
            font-family:PingFang-SC-Medium;
            font-weight:500;
            color:rgba(102,102,102,1);
            &>div{
              padding: 6*@toVw 11*@toVw;
              text-align: left;
              &:first-child{
                border-bottom: 1*@toVw solid #eee;
              }
            }
          }
          .change-block-HP{
            position: absolute;
            top: ~"calc(100vh - 12.5vw)";
            display: block;
            width: 78*@toVw;
            img{
              width: 100%;
            }
          }
          .change-block{
            display: none;
          }
        }
      }
    }
  }

  @media screen and (min-aspect-ratio: ~"20/8"){
    @toVw:100/900vw;
    .video-page{
      position: absolute;
      top: 5*@toVw;
      bottom: 5*@toVw;
      left: 5*@toVw;
      right: 5*@toVw;
      background:rgba(255,255,255,1);
      overflow: auto;
      border-radius:8*@toVw;
      .content{
        position: static;
        height: 100%;
        width: 100%;
        display: flex;
        border-radius: 8px;
        padding: 0;
        .header{
          display: none;
        }
        .video-block{
          display: none;
          &.hp-video{
            display: inline-block;
            margin: 0 10*@toVw 0 0;
            border: none;
            height: 100%;
            border-radius: 12*@toVw;
            padding: 0;
          }
          video{
            height: 100%;
            margin: auto;
            width: auto;
            display: block;
            background:rgba(0,0,0,0.4);
            border-radius:8*@toVw;
          }
        }
        .btn-block{
          position:relative;
          min-width: 90*@toVw;
          display: block;
          height: 100%;
          .age-block{
            display: block;
            position: static;
            padding: 0;
            height: 28*@toVw;
            width: 88*@toVw;
            line-height: 28*@toVw;
            border: 1*@toVw solid #666;
            border-radius: 100*@toVw;
            font-size:12*@toVw;
            font-family:PingFang-SC-Medium;
            font-weight:500;
            color:rgba(102,102,102,1);
            &.video{
              display: block;
            }
          }
          .age-change-block{
            position: static;
            width: 80*@toVw;
            margin-top: 10*@toVw;
            border-radius: 8*@toVw;
            border: 1*@toVw solid #666666;
            font-size:12*@toVw;
            font-family:PingFang-SC-Medium;
            font-weight:500;
            color:rgba(102,102,102,1);
            &>div{
              padding: 6*@toVw 11*@toVw;
              text-align: left;
              &:first-child{
                border-bottom: 1*@toVw solid #eee;
              }
            }
          }
          .change-block-HP{
            position: absolute;
            top: ~"calc(100vh - 12.5vw)";
            display: block;
            width: 78*@toVw;
            img{
              width: 100%;
            }
          }
          .change-block{
            display: none;
          }
        }
      }
    }
  }
</style>
