<template>
	<view>
		<u-tabbar v-model="myCurrent" :list="tabbarList" :before-switch="beforeSwitch" mid-button-size="72" :mid-button="true" inactive-color="#ADB8C2" active-color="#5098FF">
		</u-tabbar>

	</view>
</template>

<script>
	var img1=require('@/assets/img/tabbarImg/item1a.svg')
	var img2=require('@/assets/img/tabbarImg/item1b.svg')

	var img7=require('@/assets/img/tabbarImg/item4a.svg')
	var img8=require('@/assets/img/tabbarImg/item4b.svg')
	
	var img0=require('@/assets/img/tabbarImg/item0.png')
	
	import * as WxJsApi from '@/apis/utils/wxJsApi.js'
	
	export default {
		name: "Tabbar",
		props: {
			current: 0,
			elderStatus: false
		},
		data() {
			return {
				oldindex: this.current,
				myCurrent: this.current,
				tabbarList: [{

						iconPath: img2,
						selectedIconPath: img1,
						text: '主页 ',
						pagePath: "/pages/index/index",
					},
					 {
					 	iconPath: img0,
					 	selectedIconPath: img0,
					 	text: '',
						midButton: true,
					 	pagePath2: "",
					 	
					 },
					// {
					// 	iconPath: img6,
					// 	selectedIconPath: img5,
					// 	text: '用户',
					// 	pagePath: "/pages/userTab/index",
						
					// },
					
					{
						iconPath: img8,
						selectedIconPath: img7,

						text: '我的',
						pagePath: "/pages/myTab/index",
					}
				],
			};

		},
		methods: {
			beforeSwitch(index){
				var item=this.tabbarList[index]
				if(item.pagePath){
						return true;
				}else{
					if(process.jphelp.NODE_ENV=='dev'){
						//this.findStationByGun("YQ202207150011001")
						this.findStationByGun("E5011")
						
					}else{
						this.getScanCode()
					}
					
					return false;
				}
				
			},
			
			findStationByGun(id){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				
				WxJsApi.findStationByNo({
					no:id,
				
				
				}).then((response) => {
					uni.hideLoading();
					var chargingStation=response.data.chargingStation
					if(chargingStation){
						uni.navigateTo({
							url:"/pages/inspection/add?back=1&stationId="+chargingStation.id
						})
					}else{
						uni.showToast({
							title: "未查询到充电站",
							icon: "none"
						})
					}
					
				
				}).catch(error => {
					uni.showToast({
						title: "查询失败,"+error,
						icon: "none"
					})
					uni.hideLoading();
					
				})
			},
			
			//微信扫二维码
			getScanCode() {
				WxJsApi.scanQRCode(1).then(res => {
					var url=res;
					
					var gunId="";
					if(url&&url.indexOf("#/?jpcode=")>-1){
						gunId=url.split("#/?jpcode=")[1]
					}
					if(url&&url.indexOf("#/?gunId=")>-1){
						 gunId=url.split("#/?gunId=")[1].trim()
						
					}
					if(url&&url.indexOf("&gunId=")>-1){
						gunId=url.split("&gunId=")[1].trim()
					}
					
					if(gunId){
						
					}else{
						gunId=res
					}
					
					if(url&&url.indexOf("stationId=")>-1){
						var stationId=url.split("stationId=")[1]
						
						uni.navigateTo({
							url:"/pages/inspection/add?back=1&stationId="+stationId
						})
						
					}else{
						this.findStationByGun(gunId)
					}
					
					
				}).catch(error => {
							
				})
			},
			

		},
		mounted() {
			console.log(111+"mounted")
			WxJsApi.getWxConfig(['scanQRCode']).then((res) => {
				// //(res)
			}).catch(error => {
				//(res)
			})
			
		},
		destroyed() {

		}


	}
</script>

<style>

</style>
