
Component({
	data: {
		//默认是2
		active: 2,
		isBazi:false,
		list2: [
			{
				"pagePath": "/pages/carVideo/index",
				"iconPath": "/static/imgs/car.png",
				"selectedIconPath": "/static/imgs/car-active.png",
				"text": "驾考"
			},
			{
				"pagePath": "/pages/teacherVideo/index",
				"iconPath": "/static/imgs/video.png",
				"selectedIconPath": "/static/imgs/video-active.png",
				"text": "教学视频"
			},

			{
				"pagePath": "/pages/user/index",
				"iconPath": "/static/imgs/user.png",
				"selectedIconPath": "/static/imgs/user-active.png",
				"text": "我的"
			}
		],
		list: [{
			"pagePath": "/pages/carVideo/index",
			"iconPath": "/static/imgs/car.png",
			"selectedIconPath": "/static/imgs/car-active.png",
			"text": "驾考"
		},
		{
			"pagePath": "/pages/teacherVideo/index",
			"iconPath": "/static/imgs/video.png",
			"selectedIconPath": "/static/imgs/video-active.png",
			"text": "教学视频"
		},
		{
			"pagePath": "/pages/future/index",
			"iconPath": "/static/imgs/fortune.png",
			"selectedIconPath": "/static/imgs/fortune-active.png",
			"text": "运势"
		},
		{
			"pagePath": "/pages/user/index",
			"iconPath": "/static/imgs/user.png",
			"selectedIconPath": "/static/imgs/user-active.png",
			"text": "我的"
		}]
	},
	attached(){
		let that =this
		// const baseUrl = wx.getSystemInfoSync().platform === 'devtools' ? 'https://nbjk1.zzxcx.net/nbjk-admin/' : 'https://nbjk.zzxcx.net/nbjk-admin/'
		const baseUrl =  wx.getStorageSync("NODE_ENV")==='development'? 'https://nbjk1.zzxcx.net/nbjk-admin/' : 'https://nbjk.zzxcx.net/nbjk-admin/'
		wx.request({
			url:baseUrl+"open-api/system/dict/data/configKey/IS_BAZI",
			method:'GET',
			success(res){
				console.log('八字是否开启',res.data.data)
				if(res.data.data=='1'){
				
					that.setData({
						isBazi:true
					})
				}
				else{
					that.setData({
						isBazi:false
					})
				}
			

			}
		})
	},

	methods: {
		switchTab(e) {
			const data = e.currentTarget.dataset
			const url = data.path
			if(url=='/pages/future/index'){
				wx.navigateTo({
					url:'/pages/future/index'
				})
				return

			}
			wx.switchTab({ url })
			// this.setData({
			// 	active: data.index
			// })

		},
		onChange(event) {
			console.log('触发切换tabbar')
			this.setData({ active: event.detail });
			const list = Object.assign([], this.data.list)
			list[event.detail].icon =
				this.setData({
					list
				})
			wx.switchTab({
				url: this.data.list[event.detail].url
			});
		},

		init() {
			const page = getCurrentPages().pop();
			console.log(this.data.list)
			const active = this.data.list.findIndex(item => item.pagePath === `/${page.route}`)
			console.log(active, page.route)
			this.setData({
				active: active
			});
		}
	}
});
