<template>
	<view class="page">
		<u-navbar :leftText="i18n.return" :title="title" :safeAreaInsetTop="true" :placeholder='true'>
			<view class="u-nav-slot" slot="left" @click="retur">
				<!-- <u-icon name="arrow-left" size="19"></u-icon> -->
				<!-- <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line> -->
				<u-icon name="close" size="22"></u-icon>
			</view>
		</u-navbar>
		<view class="btn-list">
			<view class="language" data-lang="zh-CN" @tap="langChange"> <text>简体中文</text>
				<image v-if="languageSelect=='zh-CN'" class="selected" src="../static/mine/326.png" mode=""></image>
			</view>
			<view class="language" data-lang="en-US" @tap="langChange"> <text>English</text>
				<image v-if="languageSelect=='en-US'" class="selected" src="../static/mine/326.png" mode=""></image>
			</view>
			<view class="language" data-lang="es-ES" @tap="langChange"> <text>Español</text>
				<image v-if="languageSelect=='es-ES'" class="selected" src="../static/mine/326.png" mode=""></image>
			</view>
			<view class="language" data-lang="it-IT" @tap="langChange"> <text>Italiano</text>
				<image v-if="languageSelect=='it-IT'" class="selected" src="../static/mine/326.png" mode=""></image>
			</view>
		</view>
		<view class="bottom u-flex u-row-between"
			style="position: fixed;bottom:80rpx;width: 750rpx;padding: 20rpx 24rpx 24rpx 0;box-sizing: border-box;">
			<view class="btnleft" @click="toindex">{{i18n.skip}}</view>
			<view class="btnright" style="margin-right: 24rpx;" @click="enter">{{i18n.enter}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				languageSelect: 'zh-CN',
				title: ''
			}
		},

		computed: {
			i18n() {
				return this.$t('index')
			}
		},
		methods: {
			retur() {
				uni.navigateBack()
			},
			langChange(e) {
				const {
					lang
				} = e.currentTarget.dataset
				this._i18n.locale = lang
				this.languageSelect = lang
				uni.setNavigationBarTitle({
					title: this.i18n.switchLanguage
				})
				this.title = this.i18n.switchLanguage
			},
			enter() {
				uni.setStorageSync("language", this.languageSelect)
				this.$u.toast(this.i18n.Login)
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}, 800)
			},
			toindex() {
				this.$u.toast(this.i18n.Login)
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}, 800)
			}
		},
		created() {
			this.languageSelect = this._i18n.locale
			this.title = this.i18n.switchLanguage
			uni.setNavigationBarTitle({
				title: this.i18n.switchLanguage
			})
		},
	}
</script>

<style scoped lang="scss">
	.page {
		padding: 20rpx 24rpx;
		background-color: #fff !important;
		height: calc(100vh - 40rpx);

		.btnleft {
			width: 280rpx;
			height: 88rpx;
			border-radius: 48rpx;
			border: 2rpx solid rgba(151, 151, 151, 0.4);
			line-height: 88rpx;
			text-align: center;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #333333;
		}

		.btnright {
			width: 380rpx;
			height: 88rpx;
			background: #F83224;
			border-radius: 48rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 88rpx;
			text-align: center;
			font-style: normal;
		}

		.btn-list {
			background-color: #fff;
			border-radius: 16rpx;
			padding: 0 20rpx;

			.language {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 110rpx;
				border-bottom: 2rpx solid rgba(151, 151, 151, 0.2);

				.selected {
					width: 36rpx;
					height: 36rpx;
				}
			}
		}
	}
</style>