const _Http = getApp().globalData.http;
Page({
	data: {
		appid: 'wxc1b6ae925ac1d06a',
		detailsData: {}
	},
	onLoad(options) {
		const item = JSON.parse(options.item)
		if (item.isread == 0) _Http.basic({
			"classname": "system.message.Message",
			"method": "readMessage",
			"content": {
				"messageid": item.messageid
			}
		}).then(res => {
			console.log("已读消息", res)


		})
		//判断具体消息归属
		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)
				// sa_order
				break;
		}
		//修改跳转页面
		if (item.path) {
			switch (item.path) {
				case "sa_workorder":
					//工单
					item.path = "/Eservice/workerLeader/editworkOrderDetail/index"
					break;
					/* 				case "sa_serviceorder":
										//申请单
										item.path = "/Eservice/workerLeader/serviceBillDetail/index"
										break; */
				default:
					let arr = item.path.split("/");
					arr[arr.length - 1] = 'detail';
					item.path = arr.join("/");
					break;
			}
		}
		this.setData({
			detailsData: item,
			auth: JSON.stringify(wx.getStorageSync('auth')),
			userMsg: JSON.stringify(wx.getStorageSync('userMsg')),
			site: JSON.stringify(wx.getStorageSync('siteP'))
		})
	},
	saOrder(sa_orderid) {
		_Http.basic({
			"id": 20221108151302,
			"content": {
				nocache: true,
				sa_orderid
			}
		}).then(res => {
			console.log("订单", res)
			if (res.msg != '成功') 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.msg != '成功') return wx.showToast({
				title: res.data,
				icon: "none"
			});
			this.setData({
				"detailsData.name": res.data.isprivate ? '销售线索' : '公海线索',
				"detailsData.path": res.data.isprivate ? '/packageA/saleClue/detail' : '/packageA/publicClue/detail',
			})
		});
	},
	saCustomer(sa_customersid) {
		_Http.basic({
			"id": 20221012164302,
			"content": {
				sa_customersid
			},
		}).then(res => {
			console.log("客户详情", res)
			if (res.msg != '成功') return wx.showToast({
				title: res.data,
				icon: "none"
			});
			this.setData({
				"detailsData.name": res.data.ispublic ? '公海客户' : '我的客户',
				"detailsData.path": res.data.ispublic ? '/packageA/publicCustomer/detail' : '/packageA/setclient/detail',
			})
		});
	}
})