<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:{},
						options: {}
        }
    },
    onLoad(options) {
			this.options = options;
        
    },
	 onShow() {
			this.init(this.options)
	 },
      onHide() {
         this.options = {}
     },
    onShareAppMessage() {
        return {
            title:this.msgObj.title,
            path:`/pages/pricedriven/pricedriven?default_classify_first=${this.msgObj.default_classify_first}&default_classify_sub=${this.msgObj.default_classify_sub}`
        }
    },
    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.default_classify_first=obj.default_classify_first
						  options.default_classify_sub = obj.default_classify_sub
                    console.log(options);
                }
            }

            let default_classify_first=options.default_classify_first || ''
						let default_classify_sub=options.default_classify_sub || ''
						let timestamp = new Date().getTime();
            const token=this.$store.state.user.token
            this.url=`${h5BaseUrl}/hzyb/pricedriven/detail?default_classify_first=${default_classify_first}&default_classify_sub=${default_classify_sub}&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>