<template>
	<view :style="'background-color: '+theme.bg+';color: '+theme.text" style="height: 100vh;">
		<myNav title=""></myNav>

		<radio-group class="padding-w-30" @change="radioChange">
			<label v-for="(item, index) in dataList" :key="index" class="lang-list"
				:style="'background-color: '+theme.fu_bg+';color: '+theme.text">
				<view class="option">
					<view class="margin-r-18">
						<!-- <image :src="item.imgUrl" mode="widthFix"></image> -->
					</view>
					<text class="font-28">{{ item.value }}</text>
				</view>
				<radio :value="item.value" :checked="item.checked" color="#06C38D"></radio>
			</label>
		</radio-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				dataList: [{
						imgUrl: '/static/logo/en.png',
						value: 'English',
						checked: false,
						language: 'en-us'
					},
					{
						imgUrl: '/static/logo/jp.png',
						value: '日本語', //日语
						checked: false,
						language: 'jp'
					},
					{
						imgUrl: '/static/logo/cn.png',
						value: '繁体中文',
						checked: false,
						language: 'zh-cn'
					},

					{
						imgUrl: '/static/logo/mn.png',
						value: 'Монгол', //蒙古
						checked: false,
						language: 'mn'
					},
					{
						imgUrl: '/static/logo/ms.png',
						value: 'Malaysia', //马来语
						checked: false,
						language: 'ms'
					},
					{
						imgUrl: '/static/logo/kr.png',
						value: '한국어', //韩文
						checked: false,
						language: 'kr'
					},
					{
						imgUrl: '/static/logo/fre.png',
						value: 'français', //法语
						checked: false,
						language: 'fre'
					},
					{
						imgUrl: '/static/logo/ger.png',
						value: 'Deutsch', //德语
						checked: false,
						language: 'ger'
					},
					{
						imgUrl: '/static/logo/ily.png',
						value: 'Italiano', //意大利语
						checked: false,
						language: 'ily'
					},
				],
				theme: '',
			};
		},
		computed: {
			i18n() {
				return this.$t('message');
			}
		},
		onShow() {
			if (uni.getStorageSync("theme") == "dark") {
				this.theme = this.$store.state.darkTheme
			} else {
				this.theme = this.$store.state.lightTheme
			}
			let items = this.dataList;
			let ind = 0
			let lang = 'en-us'
			if (uni.getStorageSync('index')) {
				ind = uni.getStorageSync('index')
				lang = uni.getStorageSync('Language');
			}
			if (lang) {
				items[ind].checked = true;
				this.$i18n.locale = lang;
			}
		},
		methods: {
			radioChange(e) {
				let _this = this;
				let items = _this.dataList;
				for (let i = 0; i < items.length; i++) {
					if (items[i].value == e.target.value) {
						items[i].checked = true;
						// 存储选择的下标
						uni.setStorageSync('index', i);
						// 存储选择的语言
						uni.setStorageSync('Language', items[i].language);
						_this.$i18n.locale = items[i].language;
					}
				}
				setTimeout(function() {
					uni.navigateBack();
				}, 300);
			}
		}
	};
</script>

<style lang="scss">
	.lang-list {
		width: 690rpx;
		height: 96rpx;
		padding: 0 15rpx;
		margin: 24rpx auto;
		// background: #FFFFFF;
		border: 1rpx solid rgba(103, 114, 148, 0.1);
		border-radius: 12rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.lang-list .option {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.lang-list .option .img image {
		width: 100%;
	}

	.lang-list radio {
		transform: scale(0.7);
	}
</style>
