refueling1.vue 3.85 KB
<template>
  <div class="refueling1" :style="{backgroundImage:`url(${imgUrl.bg})`}">
    <div class="bg-block">
      <img :src="imgUrl.title" class="title" >
      <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" v-if="nowLesson.content.banner[0]" class="bg">
        <img :src="imgUrl.radio" class="radio-icon" @click="playJiayou()">
      </div>
    </div>
    <div class="bottom-block">
      <img :src="imgUrl.backBtn" @click="goNext(nowLesson.content.lastIndex)"/>
      <img :src="imgUrl.next" @click="goNext(nowLesson.content.nextIndex,true)"/>
    </div>
  </div>
</template>

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

  export default {
    name: "refueling1",
    props:[
      'nowLesson'
    ],
    data(){
      return{
        imgUrl:refueling1
      }
    },
    mounted(){
      this.autoPlayAudio();
      window._hmt.push(['_trackPageview', '/#/PV/card']);
    },
    methods:{
      goNext(i,next){
        this.$refs.jiayouAudio.pause()
        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";
  .refueling1{
    position: absolute;
    overflow: auto;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-size: 100% 100%;
    height: 100%;
    .bg-block{
      width: 325 * @toVw;
      background: white;
      border-radius: 8 * @toVw;
      padding: 10 * @toVw;
      position: relative;
      margin-top: 10 * @toVw;
      text-align: center;
    }
    .title{
      width: 280 * @toVw ;
    }
    .bottom-block{
      margin-top: 10 * @toVw;
      width: 100%;
      text-align: center;
      img{
        width: 127 * @toVw;
        &:first-child{
          margin-right: 10*@toVw;
        }
      }
    }
    .pageNo{
      position: absolute;
      width: 100%;
      color: #888888;
      font-size: 12px;
      left: 0;
      display: inline-block;
      text-align: center;
      bottom:0;
    }
    .content-img{
      position: relative;
      background-repeat: no-repeat;
      background-size: 100% 100%;
      margin: 20/ 2 * @toVw;
      border-radius: 8/ 2 * @toVw;
      .bg{
        width: 100%;
      }
      .radio-icon{
        position: absolute;
        width: 40 * @toVw;
        right: 20/ 2 * @toVw;
        top: 20/ 2 * @toVw;
      }
    }
  }
</style>