const _Http = getApp().globalData.http;
Page({
    data: {
        detailsData: []
    },
    onLoad(options) {
        _Http.basic({
            "classname": "system.message.Message",
            "method": "readMessage",
            "content": {
                "messageid": options.id
            }
        }).then(res => {
            if (res.msg != '成功') return wx.showToast({
                title: res.msg,
                icon: "none"
            })
            this.setData({
                detailsData: res.data
            })
        })
    },
    async toDetails() {
        const {
            objectname,
            objectid
        } = this.data.detailsData;

        const res = await _Http.basic({
            "classname": "saletool.common.auth",
            "method": "isAuth",
            "content": {
                objectid,
                objectname
            }
        });

        if (res.msg != '成功' || res.data[0].isAuth != 1) return wx.showToast({
            title: '暂无权限进入应用',
            icon: "none"
        });

        switch (objectname) {
            case 'sat_courseware':
                wx.navigateTo({
                    url: `/pages/college/detail?id=${objectid}`,
                })
                break;
            case 'sat_sharematerial':
                wx.navigateTo({
                    url: `/pages/promotional/details?id=${objectid}`,
                })
                break;
            case 'sat_notice':
                wx.navigateTo({
                    url: `/pages/annunciate/details?id=${objectid}`,
                })
                break;
            case 'sat_submitedit':
                wx.navigateTo({
                    url: `/pages/submission/details?id=${objectid}`,
                })
                break;
            case 'sat_orderclue':
                wx.navigateTo({
                    url: `/pages/threadedTree/details/index?id=${objectid}`,
                })
                break;
            case 'sys_attachment':
                let item = {
                    attachmentid: objectid,
                    document: '营销物料'
                }
                wx.navigateTo({
                    url: '/pages/tabbar/smartStore/folder?item=' + JSON.stringify(item),
                })
                break;
            default:
                console.log(objectname)
                wx.showToast({
                    title: '当前应用暂不支持跳转',
                    icon: "none"
                })
                break;
        }
    },
    onShareAppMessage(res) { }
})