<template>
  <web-view :src="url" @message="handleGetMessage"/>
</template>

<script>
import {h5BaseUrl} from '@/utils/config'
import {apiGetSceneToParams} from '@/api/common'
export default {
  data() {
    return {
      url:'',
      msgObj:{}
    };
  },
  onLoad(options) {
    this.init(options)
  },
  onShareAppMessage() {
    return {
      title:this.msgObj.title,
      path:`/pages-report/chapterDetail?chapterId=${this.msgObj.chapterId}`
    }
  },
  methods: {
    async init(options){
      if(options.scene){
        const res=await apiGetSceneToParams({scene_key:options.scene})
        if(res.code==200){
          const obj=JSON.parse(res.data)
          options.chapterId=obj.chapterId
        }
      }

      let chapterId=options.chapterId
      let fromPage=options.fromPage||''
      const timestamp=new Date().getTime()
      const token=this.$store.state.user.token
      this.url=`${h5BaseUrl}/hzyb/report/chapterdetail?chapterId=${chapterId}&userId=${this.userInfo.user_id}&fromPage=${fromPage}&token=${token}&timestamp=${timestamp}#wechat_redirect`
    },

    handleGetMessage(e){
      const data=e.detail.data[e.detail.data.length-1]
      console.log('h5传来的数据',data);
      this.msgObj=data
    }
  }
};
</script>

