<template>
	<view class="tabbar align-center" >
		<view v-for="(item, index) in tabbarList" :key="index" @click="switchTabs(item)" 
		class="tablist" v-if="item.isshowed">
			<view class=" tabbar-list"  >
				<image :src="actindex==index?item.selectedIconPath:item.iconPath"></image>
				<text class="fs24 base-textcol"
				 :class="actindex==index?'actcolor':'morecolor'">{{item.Text}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {getUserInfo} from '@/api/user'
	export default {
		name: "tabbar",
		props: {
			actindex: {
				type: Number,
				default: 0,
			}
		},
		data() {
			return {
				tabbarList: [],
				userinfoa:[],
				isuser:false
			};
		},
		mounted() {
			this.themeicon()
			this.$nextTick(()=>{
				if(uni.getStorageSync('AppToken')){
					this.getUserInfos()
				}else{
					this.isuser=true
					this.tabbarList[2].isshowed=true
				}
			})
		},
		methods: {
			getUserInfos(){
				getUserInfo().then(
					res => {
						if(res.code==200){
							if(res.user!=null){
								this.userinfoa=res.user
								if(this.userinfoa.isShow==0&&this.isuser==false){
									this.tabbarList[3].isshowed=false
									this.tabbarList[2].isshowed=true
								}else if(this.userinfoa.isShow==1){
									this.tabbarList[3].isshowed=true
									this.tabbarList[2].isshowed=false
								}
							}
						}else{
							uni.showToast({
								icon:'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
			switchTabs(item) {
				uni.switchTab({
					url: item.url
				})
			},
			themeicon() {
				this.tabbarList = [{
						iconPath: "https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/home.png",
						selectedIconPath: "https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/home_sel.png",
						Text: '首页',
						url: '/pages/home/index',
						isshowed:true
					},
					{
						iconPath: "https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/health.png",
						selectedIconPath: "https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/health_sel.png",
						Text: '健康百科',
						url: '/pages/healthy/index',
						isshowed:true
					},
					{
						iconPath: "https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/archive.png",
						selectedIconPath: "https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/archive_sel.png",
						Text: '健康档案',
						url: '/pages/healthy/idea',
						isshowed:false
					},
					{
						iconPath: "https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/shop_mall.png",
						selectedIconPath: "https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/shop_mall_sel.png",
						Text: '健康产品',
						url: '/pages/shopping/index',
						isshowed:false
					},
					{
						iconPath: "https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/my.png",
						selectedIconPath: "https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/my_sel.png",
						Text: '我的',
						url: '/pages/user/index',
						isshowed:true
					},
				]
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tabbar {
		display: flex;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		background-color: #fff;
		z-index: 1000;
		height: 100rpx;
		padding: 20rpx 0rpx;
		image{
			margin-bottom: 4rpx;
			width: 48rpx;
			height: 48rpx;
		}
	}

	.tablist {
		width: 25%;
	}
	.morecolor{
		color: #626468;
	}
	.actcolor{
		color: #2BC7B9;
	}
	.tabbar-list{
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 24rpx
	}
</style>