import { Service } from "@/Service/Service"
export class EventHandler {
	//处理事件
	static Events(data : any) {
		var result = JSON.parse(data.data);
		if (result.code == 'msg') {
			this.ChatEnent(result);
		} else if (result.code == 'order') {
			uni.$emit('newOrder', data);
			this.NewOrder()
		}
	}

	static NewOrder() {
		var innerAudioContext = uni.createInnerAudioContext();
		innerAudioContext.autoplay = true;
		innerAudioContext.src = '/static/order.mp3';

		innerAudioContext.onEnded(() => {
			console.log('播放结束');
		})
	}


	static ChatEnent(data : any) {
		console.log(data, 'xxx')
		var eventName = `chat_${data.chanId}`;
		uni.$emit(eventName, data);
	}

	static ChatUserEnent(data : any) {
		var eventUserName = `chatUser_${data.sendId}`;
		uni.$emit('UpdatePrivateMsg', data);
		uni.$emit(eventUserName, data);
		this.plusPush();
	}

	static plusPush() {
	
	  Service.createLocalPush('骑手订单','您有一个新订单','')
	}

	static SystemEnent(data : any) {
		let obj = JSON.parse(data.data);
		if (obj.code == 'Like' || obj.code == 'Aite' || obj.code == 'Comment' || obj.code == 'Notice') {
			uni.$emit('MegEvent', obj);
		} else if (obj.code == 'Off') {
			uni.$emit('ImComOff', 'user');
		} else if (obj.code == 'UpdateUserInfo') {
			uni.$emit('UpdateUserInfo');
		} else if (obj.code == 'Friend') {
			uni.$emit('Friend');
		}
	}

	static ConnectBus() {
		uni.$emit('UpdateChat');
	}
}