<template>
	<view style="background-color: $color-white !important;">
		<u-navbar :back-text="i18n('Back')" :back-text-style="backStyle" back-icon-color="#fff" title-color="#fff" :background="background" title-width="300" :title="i18n('AccountSecurity')"></u-navbar>
		<!-- 手机号 -->
		<!-- <list-cell iconColor="#333" title="手机号" @eventClick="navTo('/pages/profile/profileSetUp/changeMobileNumber')"></list-cell> -->
		<list-cell iconColor="#333" :title="i18n('phonenumber')" @eventClick="toSetPhone"></list-cell>
		<!-- 修改密码 -->
		<list-cell iconColor="#333" :title="i18n('ChangePassword')" @eventClick="navTo('/pages/profile/profileSetUp/changePassword')"></list-cell>
		<!-- 绑定邮箱 -->
		<list-cell iconColor="#333" :title="$i18n.locale=='zh'?'绑定邮箱':'BindEmail'" @eventClick="navTo('/pages/profile/profileSetUp/changeMailbox')"></list-cell>
		<!-- 设置语言 -->
		<!-- <list-cell iconColor="#333" :title="$i18n.locale=='zh'?'设置语言':'SetLanguage'"  @eventClick="setLanguage" :tips="$i18n.locale=='zh'?i18n('Chinese'):i18n('English')"></list-cell> -->
		
		<!-- 注销账户 -->
		<!-- <list-cell iconColor="#333" title="注销账户" @eventClick="navTo('/pages/profile/profileSetUp/cancellationOfAccount')"></list-cell> -->
		<u-toast ref="uToast" />
		<uni-popup ref="popup" type="center">
			<uni-popup-dialog type="input" :content="$i18n.locale=='zh'?'确认切换为英文？':'Confirm to switch to Chinese?'" :duration="2000"
			 :before-close="true" @close="close" @confirm="confirm">
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import listCell from '@/components/JumpBox';
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
	import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
	export default {
		components: {
			listCell,
			uniPopup,
			uniPopupMessage,
			uniPopupDialog
		},
		data() {
			return {
				isMobilePass: '',
				phone: '',
				salfPhone: '',
				isEmailPass: '',
				background: {
					backgroundImage: 'linear-gradient(270deg, #4BC0E2 0%, #538BE7 100%)',
				},
				backStyle: {
					color: '#FFFFFF',
				},
			};
		},
		onShow() {
			this.getUserInfoById();
		},

		methods: {
			async getUserInfoById() {
				const result = await this.$myRequest({
					url: '/uc/securitySetting/getUserInfoById',
				});
				if (result) {
					var phone = result.data.userPreferredMobile;
					if (phone) {
						this.salfPhone = phone.substr(0, 3) + '****' + phone.substr(7);
					}
					this.isMobilePass = result.data.userMobileStatus;
					this.isEmailPass = result.data.userEmailStatus;
				}
			},
			toSetPhone() {
				if (this.isMobilePass == '0') {
					this.$mRouter.push({
						route: '/pages/profile/profileSetUp/changeMobileNumber'
					});
				} else {
					this.$mRouter.push({
						route: '/pages/profile/profileSetUp/BindMobileNumber'
					});
				}
			},
			navTo(route) {
				this.$mRouter.push({
					route
				});
			},
			i18n(data) {
				return this.$t('common.' + data);
			},
			async confirm(done) {
				let res = await this.$myRequest({
					url:'/uc/userCenter/settingLanguage',
					data:{language:this._i18n.locale=='zh'?'en':'zh'},
				})
				if(res.status==200){
					if (this.$i18n.locale == 'zh') {
						uni.setStorageSync("language", 'en')
						this._i18n.locale = 'en';
					} else {
						uni.setStorageSync("language", 'zh')
						this._i18n.locale = 'zh';
					}
					this.$refs.uToast.show({
						title: this._i18n.locale == 'zh'?'设置成功':'set language success',
						type: 'success',
						icon: false
					})
				}else{
					this.$refs.uToast.show({
						title: this._i18n.locale == 'zh'?'设置失败':'set language fail',
						type: 'error',
						icon: false
					})
				}
				done();
			},
			close(done) {
				done();
			},
			setLanguage(){
				this.$refs.popup.open();
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	page,
	body.pages-profile-profileSetUp-setUp uni-page-body {
		background-color: #fff !important;
	}
</style>
