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

<script>
import {h5BaseUrl} from '@/utils/config'
import {apiGetSceneToParams} from '@/api/common'
export default {
  data() {
    return {
      url:'',
      msgObj:{},
	    options:{}
    };
  },
  onLoad(options) {
	  this.options=options
    wx.setVisualEffectOnCapture({visualEffect:'hidden'})
  },
  onShow(){
	 this.init(this.options) 
  },
  onUnload(){
    wx.setVisualEffectOnCapture({visualEffect:'none'})
  },
  onShareAppMessage() {
    return {
      title:this.msgObj.title,
      path:`/pages-report/chapterDetail?chapterId=${this.msgObj.chapterId}`,
      imageUrl:this.msgObj.shareImg||''
    }
  },
  methods: {
    async init(options){
	    this.url=''
      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
      setTimeout(()=>{
		    this.url=`${h5BaseUrl}/hzyb/report/chapterdetail?chapterId=${chapterId}&userId=${this.userInfo.user_id}&fromPage=${fromPage}&token=${token}&timestamp=${timestamp}#wechat_redirect`
	    },100)
    },

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

