<template>
    <nav-bar :navbar-data="navbarData" />
    <view :style="{ marginTop: 'calc('+ height +'px + 18rpx)', marginBottom: '20rpx' }" class="detail">
        <view v-if="loading" class="loading">加载中...</view>
        <web-view v-if="platform == 'ios'" :src="url" />
    </view>
</template>

<script>
import httpConfig from '@/utils/httpConfig'
import navBar from '@/components/navBar/index'
const app = getApp()
export default {
    components: {
        'nav-bar': navBar
    },
    data() {
        return {
            imgHost: httpConfig && httpConfig.imgHost,
            height: app.globalData.height,
            navbarData: {
                isGoHome: true,
                homePath: '../../../pages/tabBar/index/index',
                isGoBack: true,
                title: "帮助详情",
            },
            list: '',
            loading: true,
            platform: '',
            url: httpConfig.imgHost + '/images/icon/doctor/test.pdf',
        }
    },
    onLoad: function (options) {
        this.url = options.url
    },
    onReady: function () {
        let self = this;
        const eventChannel = this.getOpenerEventChannel();
        eventChannel.on('data', (val) => {
            console.log('传过来的', val)
            this.list = val.dataList
        });
        if (this.list) {
            self.url = this.list
            uni.getSystemInfo({
                success: function (res) {
                    self.platform = res.platform
                    if (res.platform != 'ios') {
                        uni.downloadFile({
                            url: self.list,
                            success: function (res) {
                                var Path = res.tempFilePath //返回的文件临时地址，用于后面打开本地预览所用
                                uni.openDocument({
                                    filePath: Path,
                                    success: function (res) {
                                        self.loading = false
                                    }
                                })
                            },
                            fail: function (res) {
                                uni.showToast({
                                    title: '文档加载失败',
                                    icon: false,
                                })
                                self.loading = false

                            }
                        })
                    }
                }
            })
        }
    },
}
</script>

<style></style>