<script>
	let socketID;
	import amapFile from './libs/amap-wx.js'
	export default {
		data(){
			return {
				// 地图
				amapPlugin: null,
				key: 'bb6f4ed802756f963b37c184ce4e9766',
				timer:null
			}
		},
		onLaunch: function() {
			console.log('App Launch')
			// 定位
			this.amapPlugin = new amapFile.AMapWX({
				key: this.key
			});
			this.connect()
			this.$store.commit('getCity', '')
			let tabList = []
			this.$http('/addons/ddrive/banner/market_setting').then(data => {
				if (data.dj_status == 1) {
					tabList.push({
						name: '代驾',
						id: 0
					})
				}
				if (data.sf_status == 1) {
					tabList.push({
						name: '顺风车',
						id: 1
					})
				}
				if (data.dc_status == 1) {
					tabList.push({
						name: '货运',
						id: 2
					})
				}
				this.$store.commit('getTab', tabList)
			})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		beforeDestroy() {
			clearInterval(this.timer)
			this.timer = null
		},
		methods: {
			connect() {
				socketID = uni.connectSocket({
					url: 'ws://47.115.43.235:2340', //仅为示例，并非真实接口地址。
					success: () => {
						//console.log('连接成功');
					}
				});
				socketID.onOpen(() => {
					let _this = this
					this.timer=setInterval(()=>{
						this.amapPlugin.getRegeo({
							success: (data) => {
								_this.$
								if(_this.$store.state.token&&_this.$store.state.userInfo.real_verified==1&&_this.$store.state.userInfo.driver_verified==1){
									let addr = [_this.$store.state.userInfo.user_id,_this.$store.state.userInfo.truename,data[0].latitude,data[0].longitude,_this.$store.state.userInfo.driver_status]
									console.log(addr);
									socketID.send({
										data:addr.join(',')
									})	
								}
							}
						});
					},4000)
				});

				socketID.onClose(() => {
					//this.connect()
				});
				socketID.onError(() => {
					//this.connect()
				});

			},
		
		}
	}
</script>

<style lang="scss">
	uni-page-body {
		color: $gray !important;
		font-size: 30rpx !important;
	}

	// 自定义头部，状态栏盒子样式
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
		background-color: #fff;
	}

	// tab切换选中加下边框
	.active-bb {
		&::after {
			content: '';
			position: absolute;
			width: 90%;
			height: 5rpx;
			background-color: $blue;
			left: 5%;
			bottom: -25rpx;
		}
	}

	// filed
	.u-field {
		padding: 26rpx 34rpx !important;

		.u-label-text {
			font-weight: 700 !important;
		}
	}

	// 提交按钮
	.u-btn--primary {
		background: $blue !important;
	}

	.u-size-default {
		width: 682rpx !important;
		height: 88rpx !important;
		font-weight: 700 !important;
	}

	// cell组件右边箭头对其文字
	.u-cell_title {
		font-weight: 700 !important;
		color: #333 !important;
	}

	.u-cell__right-icon-wrap {
		height: 55rpx !important;
	}

	/*每个页面公共css */
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	@import './common/common.scss'
</style>
