<template>
    <view>
        <!-- pages/oneselfCenter/page/helppdf/helppdf.wxml -->
        <mp-loading type="circle" tips="正在加载" v-if="loading"></mp-loading>
        <web-view v-if="platform == 'ios'" :src="url"></web-view>
    </view>
</template>

<script>
// pages/oneselfCenter/page/helppdf/helppdf.js
export default {
    components: {},
    data() {
        return {
            platform: '',
            url: '',
            loading: true
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (options.url) {
            this.setData(
                {
                    url: options.url
                },
                () => {
                    let _this = this;
                    uni.getSystemInfo({
                        success: function (res) {
                            _this.setData({
                                platform: res.platform
                            });
                            if (res.platform != 'ios') {
                                uni.downloadFile({
                                    url: options.url,
                                    success: function (res) {
                                        console.log(res);
                                        var Path = res.tempFilePath; //返回的文件临时地址，用于后面打开本地预览所用
                                        uni.openDocument({
                                            filePath: Path,
                                            success: function (res) {
                                                _this.setData({
                                                    loading: false
                                                });
                                            }
                                        });
                                    },
                                    fail: function (res) {
                                        uni.showToast({
                                            title: '文档加载失败',
                                            icon: 'none'
                                        });
                                        _this.setData({
                                            loading: false
                                        });
                                    }
                                });
                            }
                        }
                    });
                }
            );
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {}
};
</script>
<style>
/* pages/oneselfCenter/page/helppdf/helppdf.wxss */
</style>
