const _Http = getApp().globalData.http;
Page({
    data: {
        appid: 'wx197f219a82a89d7b',
        detailsData: {}
    },
    onLoad(options) {
        getApp().globalData.Language.getLanguagePackage(this, '消息详情')
        const item = JSON.parse(options.item)
        if (item.isread == 0) _Http.basic({
            "classname": "system.message.Message",
            "method": "readMessage",
            "content": {
                "messageid": item.messageid
            }
        })
        //判断具体消息归属
        switch (item.objectname) {
            case "sa_customers":
                //客户
                item.name = '';
                this.saCustomer(item.objectid);
                break;
            case "sat_orderclue":
                item.name = '';
                this.satOrderclue(item.objectid);
                //线索
                break;
            case "sa_order":
                item.name = '';
                this.saOrder(item.objectid)
                break;
            case "sa_salesforecastbill":
                item.name = '';
                this.salesforecastbill(item.objectid)
                break;
            case "sys_phonebook":
                item.name = '联系人';
                item.path = '/packageA/contacts/detail'
                break;
            case "sys_enterprise_contacts":
                item.name = '客户联系人';
                item.path = '/packageA/contacts/detail'
                break;
            case "sa_project_contacts":
                item.name = '项目联系人';
                item.path = '/packageA/contacts/detail'
                break;
        }
        //修改跳转页面
        if (item.path) {
            let arr = item.path.split("/");
            arr[arr.length - 1] = ["sat_submiteditmodel", "sat_noticeids", "sat_sharematerial"].includes(item.objectname) ? 'details' : ["sys_attachment"].includes(item.objectname) ? 'index' : 'detail';
            item.path = arr.join("/");
        }
        this.setData({
            detailsData: item,
            auth: JSON.stringify(wx.getStorageSync('auth')),
            userMsg: JSON.stringify(wx.getStorageSync('userMsg')),
            site: JSON.stringify(wx.getStorageSync('siteP'))
        })
        console.log("消息详情", item)
    },
    saOrder(sa_orderid) {
        _Http.basic({
            "id": 20221108151302,
            "content": {
                nocache: true,
                sa_orderid
            }
        }).then(res => {
            console.log("订单", res)
            if (res.code != '1') return wx.showToast({
                title: res.data,
                icon: "none"
            });
            let path = '';
            switch (res.data.type) {
                case '工具借用单':
                    path = '/packageA/borrow/detail'
                    break;
                case '借用归还单':
                    path = '/packageA/toolBill/detail'
                    break;
                default:
                    path = '/packageA/orderForm/detail'
                    break;
            }
            this.setData({
                "detailsData.name": res.data.type,
                "detailsData.path": path
            })
        });
    },
    satOrderclue(sat_orderclueid) {
        _Http.basic({
            "classname": "saletool.orderclue.web.orderclue",
            "method": "selectDetail",
            "version": 1,
            "content": {
                "nocache": true,
                sat_orderclueid
            },
        }).then(res => {
            console.log("线索详情", res)
            if (res.code != '1') return wx.showToast({
                title: res.data,
                icon: "none"
            });
            if (res.data.isprivate == 1) {
                this.setData({
                    "detailsData.name": '销售线索',
                    "detailsData.path": '/packageA/saleClue/detail',
                })
            } else {
                this.setData({
                    "detailsData.name": res.data.allocationstatus == '已分配' ? '销售线索' : '公海线索',
                    "detailsData.path": res.data.allocationstatus == '已分配' ? '/packageA/saleClue/detail' : '/packageA/publicClue/detail',
                })
            }
        });
    },
    salesforecastbill(sa_salesforecastbillid) {
        _Http.basic({
            "id": 20230705144704,
            "content": {
                sa_salesforecastbillid
            }
        }).then(res => {
            console.log("预测详情", res)
            if (res.code != '1') return wx.showToast({
                title: res.data,
                icon: "none"
            });
            this.setData({
                "detailsData.name": res.data.baseonproject ? '项目成交预测' : '出货开票预测',
                "detailsData.path": res.data.baseonproject ? '/packageA/finishforecast/detail' : '/packageA/invoiceforecast/detail',
            })
        });
    },
    saCustomer(sa_customersid) {
        _Http.basic({
            "id": 20221012164302,
            "content": {
                sa_customersid
            },
        }).then(res => {
            console.log("医院详情", res)
            if (res.code != '1') return wx.showToast({
                title: res.data,
                icon: "none"
            });
            this.setData({
                "detailsData.name": res.data.sa_customerpoolid ? '公海客户' : '医院管理',
                "detailsData.path": res.data.sa_customerpoolid ? '/packageA/publicCustomer/detail' : '/packageA/setclient/detail',
            })
        });
    }
})