<template>
    <web-view :src="url" @message="handleGetMessage"/></web-view>
</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/reportDetail?reportId=${this.msgObj.reportId}`
        }
    },
    methods: {
        async init(options){
            console.log('options',options);
            if(options.scene){
                const res=await apiGetSceneToParams({scene_key:options.scene})
                if(res.code==200){
                    console.log(res);
                    const obj=JSON.parse(res.data)
                    console.log(obj);
                    options.reportId=obj.reportId
                    console.log(options);
                }
            }

            let reportId=options.reportId
            const timestamp=new Date().getTime()
            const token=this.$store.state.user.token
            this.url=`${h5BaseUrl}/hzyb/report/detail?reportId=${reportId}&userId=${this.userInfo.user_id}&fromPage=${options.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>