<template>
	<view class="flex topBox">
		<view class="userInfo flex_item">
			<view class="flex_item user">
				<image class="userIcon" src="/static/img/img01.png"></image>
				<view class="userId">{{address}}</view>
			</view>
			<view class="ch" @click="selectLang">{{value}}</view>
		</view>
		<view class="navTab flex">
			<view class="navItem flex_item" v-for="item,index in list" :key="index" 
			:class="{ atcive: currTab == index }" @click="navTo(item.url,index)">
				<!-- <image class="icon" :src="item.icon" mode="widthFix"></image> -->
				<view class="name">{{item.name}}</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex";
	export default {
		props:["currTab","address"],
		data() {
			return {
				show: false,
				list:[]
			}
		},
		mounted() {
			this.init()
		},
		computed: {
			...mapState({
				langList: "langList",
				lang: "lang",
			}),
			...mapState('user', ['userInfo']),
			value() {
				const value = this.langList.find((item) => {
					console.log(this.lang, item.value);
					return item.value == this.lang
				}).value;
				return value
			}
		},
		methods: {
			...mapActions({
				setLang: "setLang",
			}),
			init(){
				this.list = [{
					name:'Home',
					icon:'/static/img/img14.png',
					url:'/pages/pc/index'
				},{
					name:'BF swap',
					icon:'/static/img/img15.png',
					url:'/pages/pc/404'
				},{
					name:this.$t('indexs.i2'),
					icon:'/static/img/img16.png',
					url:'/pages/pc/supermarket'
				},{
					name:this.$t('indexs.i3'),
					icon:'/static/img/img17.png',
					url:'/pages/pc/404'
				},{
					name:this.$t('indexs.i4'),
					icon:'/static/img/img19.png',
					url:'/pages/pc/diagram'
				},{
					name:this.$t('indexs.i7'),
					icon:'/static/img/img25.png',
					url:'/pages/pc/404'
				},
				{
					name:this.$t('indexs.i5'),
					icon:'/static/img/img18.png',
					url:'https://t.me/Benfolds_cn'
				}]
			},
			//切换语言
			selectLang() {
				let value = ''
				if(this.value == 'cn'){
					value = 0
				}else{
					value = 1
				}
				this.setLang(this.langList[value].value);
				this.init();
			},
			navTo(url,index){
				if(index == 6){
					window.open(url)
				}else{
					if (url == "/pages/pc/404") {
						let url = '/pages/pc/404?index='+ index
						uni.navigateTo({
							url,
							fail() {
								uni.switchTab({
									url,
								});
							},
						});
					} else {
						uni.navigateTo({
							url,
							fail() {
								uni.switchTab({
									url,
								});
							},
						});
					}
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		min-width: 1800px;
	}
	.topBox{
		border-bottom: 1rpx solid #4F5256;
		padding: 10px 30px;
		position: fixed;
		width: 100%;
		background: #080401;
		z-index: 99;
		.userInfo{
			color: #FFD515;
			min-width: 400px;
			.ch{
				border: 4rpx solid #FFD515;
				border-radius: 7rpx;
				font-size: 21rpx;
				padding: 4rpx 4rpx;
				margin-left: 30rpx;
				cursor: pointer;
			}
			.user{
				width: 83%;
				background: #2B2929;
				border-radius: 10rpx;
				padding: 12rpx 15rpx;
				.userIcon{
					width: 34rpx;
					height: 34rpx;
					margin-right: 10rpx;
				}
				.userId{
					width: calc(100% - 34rpx);
					font-size: 25rpx;
				}
			}
		}
		.navTab{
			min-width: 1000px;
			.navItem{
				font-size: 32rpx;
				color: #FFFFFF;
				padding: 25rpx 30rpx;
				margin-bottom: 20rpx;
				cursor: pointer;
				.icon{
					width: 44rpx;
					height: 43rpx;
				}
				.name{
					padding-left: 29rpx;
				}
			}
			.atcive{
				box-shadow: -4rpx -4rpx 13rpx 0rpx rgba(168,168,206,0.13), 4rpx 4rpx 7rpx 3rpx rgba(0,0,0,0.4);
				border-radius: 10rpx;
				color: #FFCC12 !important;
			}
		}
	}
</style>
