Component({
    properties: {
        files: Object,
        deleteFile: Function,
        delete: {
            type: Boolean,
            value: true
        }
    },
    methods: {
        /* 预览媒体 */
        viewMedias(e) {
            const {
                index,
                type
            } = e.currentTarget.dataset;
            wx.previewMedia({
                current: index,
                sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
            })
        },
        /* 预览文档 */
        viewFlies(e) {
            const {
                item
            } = e.currentTarget.dataset;
            wx.showLoading({
                title: '加载中...',
            })
            wx.downloadFile({
                url: item.url,
                complete({
                    statusCode,
                    tempFilePath
                }) {
                    if (statusCode != 200) return;
                    wx.openDocument({
                        filePath: tempFilePath,
                        fileType: item.postfix,
                        showMenu: true,
                        complete({
                            errMsg
                        }) {
                            wx.hideLoading();
                            if (errMsg != "openDocument:ok") wx.showToast({
                                title: '打开失败',
                                icon: "none"
                            })
                        }
                    })
                }
            })
        },
        handleDeleteFile(e) {
            this.triggerEvent("deleteFile", e)
        }
    }
})