<template>
  <div  class="refueling2" :style="{backgroundImage:`url(${imgUrl.refueling1.bg})`}">
    <div class="bg-block">
      <img :src="imgUrl.refueling1.title" class="title" v-if="nowLesson.content.title === 0">
      <img :src="imgUrl.refueling2.title2" class="title" v-if="nowLesson.content.title === 1"/>
      <audio v-if="nowLesson.content.radio.length" :src="nowLesson.content.radio[0].url" autoplay ref="jiayouAudio"></audio>
      <div class="content-img">
        <img :src="nowLesson.content.banner[0].url" class="img" v-if="nowLesson.content.banner[0]">
        <img :src="imgUrl.refueling2.radio" class="radio-icon" @click="playJiayou()">
        <div class="changPage-block">
          <img :src="imgUrl.refueling2.back" class="left-icon" @click="goNext(nowLesson.content.lastIndex)"/>
          <img :src="imgUrl.refueling2.next" class="right-icon" @click="goNext(nowLesson.content.nextIndex,true)"/>
        </div>
        <span class="pageNo">-{{nowLesson.content.mouldIndex}}-</span>
      </div>
    </div>
    <div class="bottom-block">
    </div>
  </div>
</template>

<script>
  import {refueling1,refueling2} from "../../util/imgUrl";

  export default {
    name: "refueling2",
    props:[
      'nowLesson'
    ],
    data(){
      return{
        imgUrl:{
          refueling1:refueling1,
          refueling2:refueling2
        }
      }
    },
    mounted(){
      this.autoPlayAudio();
      console.log(this.nowLesson)
    },
    methods:{
      goNext(i,next){
        this.$emit('goNext',{i:i,next:!!next})
      },
      // 播放加油包音频
      playJiayou(){
        if(this.$refs.jiayouAudio.paused){
          this.$refs.jiayouAudio.play()
        }else{
          this.$refs.jiayouAudio.pause()
        }
      },
      autoPlayAudio(){
        let voice = this.$refs.jiayouAudio;
        let that = this;
        wx.ready(function () {
          that.$nextTick(()=> {
            wx.ready(function () {
              that.$nextTick(()=>{
                if (typeof WeixinJSBridge === "object" && typeof WeixinJSBridge.invoke === "function") {
                  voice.play();
                } else {
                  //監聽客户端抛出事件"WeixinJSBridgeReady"
                  if (document.addEventListener) {
                    document.addEventListener("WeixinJSBridgeReady", function(){
                      voice.play();
                    }, false);
                  } else if (document.attachEvent) {
                    document.attachEvent("WeixinJSBridgeReady", function(){
                      voice.play();
                    });
                    document.attachEvent("onWeixinJSBridgeReady", function(){
                      voice.play();
                    });
                  }
                }
                wx.ready(()=>{
                  that.$refs.jiayouAudio.play()
                })
              })
            })
          })
        })
      }
    },
    watch:{
      'nowLesson'(){
        this.autoPlayAudio()
      }
    }
  }
</script>

<style scoped lang="less">
@import "../../util/public";
.refueling2{
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  background-size: 100% 100%;
  .bg-block{
    width: 1154/2 * @toVw;
    height: 690/2 * @toVw;
    transform-origin: 355/2 * @toVw 370/2 * @toVw;
    transform: rotate(90deg);
    background: white;
    text-align: center;
    .title{
      position: relative;
      top: -30/2 * @toVw;
      width: 560 / 2 * @toVw;
    }
    .content-img{
      width: 1078/2 * @toVw;
      height: 550/2 * @toVw;
      margin: -40/2 * @toVw auto 0 auto;
      position: relative;
      border-radius: 8/2 * @toVw;
      background-size: 100% 100%;
      .img{
        width: 100%;
        border-radius: 4 * @toVw;
      }
      .pageNo{
        color: white;
        position: absolute;
        bottom: 0;
        right: 20 * @toVw;
      }
      .radio-icon{
        width: 40 * @toVw;
        position: absolute;
        bottom: 20/2 * @toVw;
        left: 20/2 * @toVw;
      }
      .changPage-block{
        position: absolute;
        bottom: 0;
        left: 50%;
        text-align: center;
        margin-left: -25 * @toVw;
        img{
          width: 35 * @toVw;
          &:first-child{
            margin-right: 15 * @toVw;
          }
        }
      }

    }
  }
}

@media screen and (orientation: landscape) {
  .refueling2{
    height: 100%;
    overflow: hidden;
    width: 100%;
    background-size: 100% 100%;
    .bg-block{
      width: 300 * @toVw;
      height: 160 * @toVw;
      transform: rotate(0);
      background: white;
      text-align: center;
      border-radius: 8 * @toVw;
      margin-top: 10 * @toVw ;
      .title{
        position: relative;
        top: -10 * @toVw;
        width: 120* @toVw;
      }
      .content-img{
        width: 270 * @toVw;
        height: 270 * 275 /539  * @toVw;
        margin: 0 * @toVw auto 0 auto;
        background: black;
        position: relative;
        top: -22 *@toVw;
        border-radius: 8 * @toVw;
        background-size: 100% 100%;
        .img{
          width: 100%;
        }
        .pageNo{
          color: white;
          position: absolute;
          bottom: 0;
          right: 10 * @toVw;
        }
        .radio-icon{
          width: 22 * @toVw;
          position: absolute;
          bottom: 5 * @toVw;
          left: 5 * @toVw;
        }
        .changPage-block{
          position: absolute;
          left: 50%;
          bottom: 0;
          text-align: center;

          img{
            width: 18 * @toVw;
            &:first-child{
              margin-right: 15 * @toVw;
            }
          }
        }
      }
    }
  }
}
</style>
