<template>
  <div id="audioDetail" class="app" ref="elementAsconten">
    <van-sticky>
      <div class="head">
        <audio-player
          ref="audioEle"
          color="#e42417"
          @playing="playing"
          :show-prev-button="false"
          :show-next-button="false"
          :audio-list="[item.videoUrl]"
          :before-play="onBeforePlay"
        ></audio-player>
      </div>
    </van-sticky>
    <div v-if="item.id">
      <van-cell-group>
        <van-cell title="" :value="item.publishTime" />
        <div
          @click="showIntrodu = !showIntrodu"
          :class="{ introduction: true, 'van-ellipsis': !showIntrodu }"
          v-text="item.normalizedContent"
          v-if="item.normalizedContent"
        ></div>
      </van-cell-group>
    </div>
    <van-empty v-else description="内容没找到" />
  </div>
</template>

<script>
// import { articleDetail } from "@/api/article/article.js";
import { currentUrlToParams } from "@/utils/common.js";
import {
  Cell as vanCell,
  CellGroup as vanCellGroup,
  Sticky as vanSticky,
  Empty as vanEmpty
} from "vant";
import "video.js/dist/video-js.css";
import "vant/lib/cell-group/style";
import "vant/lib/nav-bar/style";
import "vant/lib/sticky/style";
import "vant/lib/empty/style";
import "vant/lib/cell/style";
import "vant/lib/toast/style";
import "@liripeng/vue-audio-player/lib/vue-audio-player.css";
import AudioPlayer from "@liripeng/vue-audio-player";
import Config from "@/config/index.js";
export default {
  name: "app",
  maxPro: 0,
  props: {
    item: {
      type: Object,
      default: () => {
        return {};
      }
    },
    id: {
      type: String,
      default: ""
    }
  },
  data: function() {
    return {
      chosenAddressId: "1",
      showIntrodu: true,
      value: "",
      more: false,
      audioList: []
    };
  },
  timeout: null,
  methods: {
    goBack() {
      history.go(-1);
    },
    // 播放前做的事
    onBeforePlay(next) {
      this.playing();
      next(); // 开始播放
    },
    playing() {
      const duration = (this.$refs.audioEle.duration * 1000).toFixed(0) - 0;
      const currentTime =
        (this.$refs.audioEle.currentTime * 1000).toFixed(0) - 0;
      let timeout = new Date() - 0;
      let pro = (currentTime / duration).toFixed(2);
      if (timeout - this.timeout < Config.proTimeout || pro <= this.maxPro)
        return;
      this.timeout = timeout;
      this.maxPro = pro;
      // progress({
      //   articleId: this.$pageParams.id,
      //   progress: pro
      // });
      window.Progress.progress = pro;
    }
  },
  mounted() {
    window.webkit &&
      window.webkit.messageHandlers.setWebviewHeight.postMessage({
        height: this.$refs.elementAsconten.offsetHeight
      });
    window.H5Listener &&
      window.H5Listener.setWebviewHeight(
        this.$refs.elementAsconten.offsetHeight
      );
    this.$pageParams = currentUrlToParams();
    this.timeout = new Date();
  },
  beforeDestroy: function() {},
  components: {
    vanCellGroup,
    AudioPlayer,
    vanSticky,
    vanEmpty,
    vanCell
  }
};
</script>
<style lang="scss" scoped>
#audioDetail {
  .van-button {
    border: none;
  }
  .video-js {
    .vjs-big-play-button {
      top: 50%;
      left: 50%;
    }
  }
  .introduction {
    padding: 0.5em;
    font-size: 0.14rem;
    color: #969799;
    text-indent: 2em;
  }
  .head {
    padding: 10em 2em 2em 2em;
  }

  .selectText {
    color: #ee0a24;
  }
}
</style>
