<script>
	import Vue from 'vue'
	//app.js
	var config = require("./config");
	export default {
		onLaunch(options) {
			uni.getSystemInfo({
				success: function(e) {
					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					Vue.prototype.windowHeight = e.safeArea.height
					// #endif
					Vue.mixin({
						data() {
							return {
								StatusBar: Vue.prototype.StatusBar,
								CustomBar: Vue.prototype.CustomBar,
								windowHeight: Vue.prototype.windowHeight,
								LOADING: false
							};
						},

						methods: {
							// 时分秒转换为秒
							TIMEEVENT(e) {
								var time = e;
								var len = time.split(':')
								if (len.length == 3) {
									var hour = time.split(':')[0];
									var min = time.split(':')[1];
									var sec = time.split(':')[2];
									return Number(hour * 3600) + Number(min * 60) + Number(sec);
								}
								if (len.length == 2) {
									var min = time.split(':')[0];
									var sec = time.split(':')[1];
									return Number(min * 60) + Number(sec);
								}
								if (len.length == 1) {
									var sec = time.split(':')[0];
									return Number(sec);
								}
							},
							// 目前使用页面为录音页面
							SPEAKERSTYLE(index) {
								let obj = {
									color: '',
								}
								switch (index) {
									case 1:
										obj.color = '#60CBEC';
										break;
									case 2:
										obj.color = '#EC8B47';
										break;
									case 3:
										obj.color = '#4F861E';
										break;
									case 5:
										obj.color = '#4980C8';
										break;
									case 6:
										obj.color = '#60CBEC';
										break;
									case 7:
										obj.color = '#EC8B47';
										break;
									case 8:
										obj.color = '#4F861E';
										break;
									default:
										obj.color = '#9F61C8';
										break;
								}
								return obj
							},
						},

						filters: {
							// ASCII码转换 大写字母A是65 演讲人是从1开始所以num+64
							toCapital(num) {
								let str = ''
								str = String.fromCharCode(Number(num) + 65)
								return str
							},
						}
					});
				}
			});

			if (wx.canIUse('getUpdateManager')) {
				const updateManager = wx.getUpdateManager()
				updateManager.onCheckForUpdate(function(res) {
					if (res.hasUpdate) {
						updateManager.onUpdateReady(function() {
							uni.showModal({
								title: '更新提示',
								cancelColor: "#999999",
								content: '新版本已经准备好，是否重启应用？',
								success: function(res) {
									if (res.confirm) {
										updateManager.applyUpdate()
									}
								}
							})
						})
						updateManager.onUpdateFailed(function() {
							uni.showModal({
								title: '已经有新版本了哟~',
								cancelColor: "#999999",
								content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
							})
						})
					}
				})
			} else {
				uni.showModal({
					title: '提示',
					cancelColor: "#999999",
					content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
				})
			}
			const token = uni.getStorageSync("weapp_session_login_data")
			if (typeof token.token != "string") {
				return
			}
			this.$u.get("/user/getUser").then(data => {
				uni.setStorageSync("weapp_session_userInfo_data", data)
			})
			this.$u.get("/user/getMenu").then(data => {
				uni.setStorageSync("weapp_session_Menu_data", data)
			})


			wx.setInnerAudioOption({
				obeyMuteSwitch: false
			});
		},
		onShow(options) {
			const token = uni.getStorageSync("weapp_session_login_data")
			if (typeof token.token != "string") {
				console.log("没有")
				return
			} else {
				this.infoscoket()
			}
		},
		onHide() {},
		methods: {
			infoscoket() {
				let pushon = uni.getStorageSync('weapp_session_userInfo_data').loginName
				uni.connectSocket({
					url: 'wss://hfju.com/ws?uid=' + pushon + '_applets',
					header: {
						"content-type": "application/json",
						'Access-Token': uni.getStorageSync('weapp_session_login_data').token
					}
				});
				uni.onSocketOpen(function(res) {
					console.log('WebSocket连接已打开！');
				});
				uni.onSocketError(function(res) {
					console.log('WebSocket连接打开失败，请检查！');
				});
				uni.onSocketMessage(function(res) {
					console.log('收到服务器内容：' + res.data);
					let cedata = JSON.stringify(res);
					let data = JSON.parse(cedata);
					let zdata = JSON.parse(data.data)
					if (zdata.to == "recCmd") {
						uni.$emit('update', {
							msg: '页面更新'
						})
						return
					}
					uni.showModal({
						title: '提示',
						content: zdata.to + '的设备电量过低请检查！',
						cancelText: "取消", // 取消按钮的文字  
						confirmText: "查看", // 确认按钮文字  
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: `/pages/main/toviewtherecording/index?jump=` + "jump"
								})

							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				});
			},
			Closewebsocke() {
				uni.closeSocket();
				uni.onSocketClose(function(res) {
					console.log('WebSocket 已关闭！');
				});
			},
		}
	};
</script>

<style>
	@import "./app.css";
</style>
<style lang="scss">
	@import "uview-ui/index.scss";

	/*每个页面公共css */
	//图表样式等
	.single {
		width: 100%;
		background: #FFFFFF;

		.title {
			width: 100%;
			height: 90rpx;
			border-bottom: 1rpx solid #E0E0E0;
			display: flex;

			.title1 {
				flex: 2;
				font-size: 30rpx;
				font-weight: 600;
				color: #333333;
				line-height: 90rpx;
				text-indent: 30rpx;
			}

			.title3 {
				flex: 3;
				height: 90rpx;
				display: flex;
				align-items: center;
				justify-content: flex-end;

				.title3-box {
					display: flex;
					align-items: center;
					width: 25%;
					justify-content: center;

					.activecltab {
						border-bottom: 2px solid #2671E2;
					}
				}
			}

			.title2 {
				flex: 3;
				height: 90rpx;
				display: flex;
				align-items: center;

				.title2-che {
					width: 178rpx;
					height: 48rpx;
					background: #FFFFFF;
					border-radius: 6rpx;
					border: 1px solid #E0E0E0;
					line-height: 48rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: #666666;
					text-indent: 12rpx;
					margin-left: 35rpx;
					position: relative;

					.righttochoose {
						width: 18rpx;
						height: 24rpx;
						position: absolute;
						top: 12rpx;
						right: 12rpx;
					}
				}
			}
		}

		.swiper-box {
			width: 97%;
			margin: 0 auto;
		}

		.hejibox {
			width: 100%;
			height: 80rpx;
			display: flex;

			.heji {
				width: 50%;
				height: 100%;
				font-size: 28rpx;
				font-weight: 400;
				color: #666666;
				line-height: 80rpx;
				text-indent: 30rpx;
			}
		}

		.danwei {
			width: 100%;
			height: 40rpx;
			font-size: 24rpx;
			font-weight: 400;
			color: #999999;
			line-height: 40rpx;
			text-indent: 30rpx;
		}

		.uchaserbox {
			width: 95%;
			height: 470rpx;
		}

		.jindu {
			width: 100%;
			height: 300rpx;

			.jindu-box {
				width: 100%;
				padding-left: 30rpx;
				padding-right: 30rpx;

				.jindu-boxche {
					width: 100%;
					height: 46rpx;
					display: flex;
					align-items: center;
					height: 50rpx;

					.jindu-name {
						width: 120rpx;
						font-size: 28rpx;
						color: #666666;
					}

					.jindu-zxl {
						width: 120rpx;
						font-size: 26rpx;
						margin-left: 16rpx;
						color: #666666;
						text-align: center;
					}
				}
			}
		}
	}

	//时间切换的样式
	.boxtittab {
		width: 100;
		height: 92rpx;
		background: #FFFFFF;
		border: 1px solid #E0E0E0;
		display: flex;
		align-items: center;

		.tabbox {
			flex: 1;
			height: 100%;
			text-align: center;
			line-height: 92rpx;
			color: #666666;
			font-size: 28rpx;
			display: flex;
			justify-content: center;

			.activecllasscet {
				width: 96rpx;
				border-bottom: 2px solid #2671E2;
			}
		}
	}

	//多个格子的样式
	.boxzonglan {
		width: 100%;
		min-height: 496rpx;
		background: #FFFFFF;
		padding: 30rpx 30rpx 30rpx 30rpx;

		.zonglantit {
			font-size: 30rpx;
			color: #333333;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
		}

		.zonglanbox {
			width: 100%;
			display: flex;
			flex-wrap: wrap;
			margin-top: 24rpx;

			.grid {
				width: 50%;
				height: 128rpx;
				border: 1px solid #E0E0E0;

				.audonum {
					color: #666666;
					text-indent: 40rpx;
					font-size: 26rpx;
					margin-top: 20rpx;
				}

				.num {
					color: #333333;
					text-indent: 40rpx;
					font-size: 32rpx;
					font-weight: 600;
					margin-top: 10rpx;
				}
			}
		}
	}
</style>
