<template>
    <block>
        <web-view :src="url" />
    </block>
</template>

<script>
import util from '../util.js';
let plugin = requirePlugin('loginPlugin');
export default {
    data() {
        return {
            h5_url: '',
            url: ''
        };
    },
    onLoad: function (options = {}) {
        let { h5_url = '' } = options;
        util.h5Init(options);
		this.h5_url = h5_url
        util.setCustomNavigation();

        this._genToken();
    },
    onShareAppMessage: function () {
        let { h5_url } = this;
        return {
            title: '京东',
            path: `/pages/login/wv-common/wv-common?h5_url=${h5_url}`
        };
    },
    methods: {
        _genToken() {
            let { h5_url } = this;
            plugin
                .genToken({
                    h5_url
                })
                .then((res) => {
                    let { isSuccess, err_code, url, tokenkey, err_msg } = res;

                    if (isSuccess && !err_code) {
						this.url = `${url}?to=${h5_url}&tokenkey=${tokenkey}`
                    } else {
                        uni.showModal({
                            title: '提示',
                            content: err_msg || '页面跳转失败，请重试',
                            success: (res) => {
                                if (res.confirm) {
                                    this._genToken();
                                }
                            }
                        });
                    }
                })
                .catch((res) => console.jdLoginLog(res));
        }
    }
};
</script>
<style>
/* pages/login/wv-common/wv-common.wxss */
</style>
