let sys_workreportid = null;
const _Http = getApp().globalData.http;

Page({
    data: {
        activeName: '汇报内容'
    },
    onLoad(options) {
        getApp().globalData.Language.getLanguagePackage(this, '汇报详情')
        sys_workreportid = options.id;
        _Http.basic({
            "id": "20230524092002",
            "content": {
                sys_workreportid
            },
        }).then(res => {
            console.log("汇报详情", res)
            if (res.code != '1') {
                wx.showToast({
                    title: res.msg,
                    icon: "none",
                    mask: true
                })
                setTimeout(() => {
                    wx.navigateBack()
                }, 500)
            } else {
                if (res.data.attinfos.length != 0) this.selectComponent("#Yl_Files").handleFiles(res.data.attinfos)
                this.setData({
                    detail: res.data,
                    type: res.data.userid == wx.getStorageSync('userMsg').userid ? '我发出的' : '我收到的'
                })
            }
        })
    },
    onDetele() {
        let that = this;
        wx.showModal({
            title: getApp().globalData.Language.getMapText('提示'),
            content: getApp().globalData.Language.getMapText('是否确认删除本次汇报') + '?',
            cancelText: getApp().globalData.Language.getMapText('取消'),
            confirmText: getApp().globalData.Language.getMapText('确定'),
            complete: ({
                confirm
            }) => {
                if (confirm) _Http.basic({
                    "id": "20230602105902",
                    "content": {
                        "sys_workreportid": that.data.detail.sys_workreportid
                    }
                }).then(res => {
                    console.log("删除汇报", res)
                    wx.showToast({
                        title: res.code != '1' ? res.msg : getApp().globalData.Language.getMapText('删除成功'),
                        icon: "none",
                        mask: true
                    });
                    if (res.code == '1') return setTimeout(() => {
                        wx.navigateBack();
                    }, 500)
                })
            }
        })
    },
    onUnload() {
        const page = getCurrentPages().find(v => v.__route__ == 'packageA/report/index');
        if (!page) return;
        page.updateList();
    },
    onChange(e) {
        this.setData({
            activeName: e.detail.name
        })

        if (e.detail.name == '评论记录') this.updateList();
    },
    updateList() {
        let Component = this.selectComponent('#Discuss'),
            {
                total,
                pageNumber,
                pageTotal
            } = Component.data.content,
            id = this.data.detail.sys_workreportid;
        if (total == null) {
            Component.getList(id, true);
        } else if (pageNumber <= pageTotal) {
            Component.getList(id, false);
        }
    },
    onReachBottom() {
        this.updateList()
    },
})