<template>
  <div class="reportContainer">
    <div v-if="data_length>=15">
      <web-view :src="webUrl" @load="webLoading"></web-view>
    </div>
    <div v-else style="padding:400rpx 20rpx 0 20rpx;">
      本次训练有效数据不足，无法分析并生成有效报告，请确保训练时脑机佩戴正确，网络状况良好，且训练时长不能太短。
    </div>
    <van-toast id="van-toast"/>
  </div>
</template>
<script>
import store from '@/store/index';
import game_store from "@/store/game";

var $this;
export default {
  name: "reportContainer",
  data() {
    return {
      report_id: 0,
      data_length: 15,
      webUrl: ""
    }
  },
  methods: {
    webLoading(params) {
      console.log("报告页面web-view加载完成")
      wx.hideLoading();
    }
  },
  created() {
    $this = this;
  },
  onLoad(options) {
    wx.showLoading({
      title: "加载中",
      mask: true,
      duration: 5000
    })
    $this.report_id = options.id
      ? options.id
      : game_store.getters.getGameRecordId();
    if (options.size && options.size > 0) {
      $this.data_length = options.size;
    }
    if($this.data_length < 15){
      wx.hideLoading();
    } else {
      let mode = options.mode ? options.mode : wx.getStorageSync('report_mode')
      let $userinfo = wx.getStorageSync("userinfo")
      $this.webUrl = `${process.env.REPORT_URI}?mode=${mode}&token=${store.getters.get_token()}&record_id=${options.id}&nickName=${$userinfo.user_name}&mp=1`
      console.log($this.webUrl);
    }
  },
  onUnload(){
    wx.removeStorageSync("mode")
  }
}
</script>
