<template>
	<web-view :src="pdf"/>
</template>

<script>
export default {
    data() {
        return {
            fileSrc:[],
            pdf:'',
        }
    },
    onLoad(e) {
        if(e.previews){
            this.getPreviews(e.previews);
        } else if(e.preview){
            this.toPreview(decodeURIComponent(e.preview));
        }
    },
    methods: {
        findImage(processId){
            var that =this;
            that.http.request("/app/previewExcel", {
                processId: processId,
            }).then(res => {
                if(res.datas != null){
                    that.fileSrc = res.datas;
                } else {
                    that.$prompt.none("暂无数据");
                }
            })
        },
        getPreviews(previews){
            var that = this;
            that.http.request("/app/showOutViewOfSubmit", {
                list: previews,
                storeName: uni.getStorageSync("storeName")
            }).then(res => {
                if(res.data){
                    var encode = encodeURIComponent(res.data);
                    that.pdf = `/hybrid/html/web/viewer.html?file=${encode}`;
                }else{
                    that.$prompt.none("暂无数据");
                }
            })
        },
        toPreview(url){
            var encode = encodeURIComponent(url);
            this.pdf = `/hybrid/html/web/viewer.html?file=${encode}`;
        },
        download(){
            uni.showLoading({
                title: '下载中'
            });
            uni.saveImageToPhotosAlbum({
                filePath: this.fileSrc,
                success: function() {
                    uni.hideLoading();
                    uni.showToast({
                        title: '已保存到相册',
                        icon: 'none',
                        duration: 2200
                    });
                }
            });
        }
    }
}
</script>
