<template>
<view class="">
	<customNav :shownav="true" :title="$t('user.denglu')" tinColor="#006AFF" jiantou="0"></customNav>
	<image class="topimag" src="/static/defimags/zhucetop.png" mode="widthFix"></image>
	<view class="contentV">
		<text class="titlev">{{$t('user.denglu')}}</text>
		<view class="" >
			<view class="contentInRowS duoyuyanctv" @click="duoyuyan">
				<view class="contentInRowL">
					<image class="duoyuyIcon" src="/static/imags/yuyan@3x.png" mode="scaleToFill"></image>
					<text>Ngôn ngữ/语言</text>
				</view>
				<image style="width: 30rpx;" src="/static/imags/youjian@3x.png" mode="widthFix"></image>
			</view>
		</view>
		<view class="yzmctV">
			<input class="noinputVcode" type="nickname" :placeholder="$t('user.qsrzhanghao')"  @input="dengluzhangh">
		</view>
		<view class="yzmctV">
			<input class="noinputVcode" password type="text" :placeholder="$t('user.qingshurmim')" :password="true"  @input="denglumima">
		</view>
	
		<view class="yzmctV">
			<text class="querenBt" @click="loginAC">{{$t('user.denglu')}}</text>
		</view>
		<view class="contentInRowC" style="margin-top: 40rpx;">
			<text class="detealText" style="padding-right: 20rpx;">{{$t('user.meiyouzhanghao')}}</text>
			<text class="zhuceBt" @click="registerAC">{{$t('user.zhuce')}}</text>
		</view>
		<view class="contentColumnC" style="margin-top: 20rpx;" @click="yueduyszc">
			<label class="linktext">{{$t('index.yuedu')}}{{$t('index.yinsizc')}}</label>
		</view>
		
		<view class="contentColumnC" style="margin-top: 30rpx;" @tap="gotogvWebview">
			<netImage style="margin-top: 30rpx;" width="200" height="75"  bradius="0" mysrc="http://online.gov.vn/Content/EndUser/LogoCCDVSaleNoti/logoCCDV.png" mymode="aspectFit"></netImage>
		</view>
		
		<view style="height: 30rpx;"></view>
	</view>
	<uni-popup style="z-index: 999;" ref="popYsxy" type="center" :isMaskClick="false" :safeArea="true">
		<ysxyView v-on:EagrResult="agrResult"></ysxyView>
	</uni-popup>
</view>
</template>

<script>
	import {
		smsCode,
		loginByzhmm
	} from '@/pages/api/login';
	
	import { encrypt,decrypt } from '@/common/jsencrypt.js'
	
	export default {
		
		data() {
			return {// paotui123    123456
				zhanghao:'',
				mima:'',
				cid:'',
				cryptform:''
			}
		},
		onReady() {
			
			var yszche=uni.getStorageSync('yszche');
			if(1!=yszche){
				this.$refs.popYsxy.open('center');
			}
		},
		onShow() {
			var that=this;
			uni.getPushClientId({
			    success: (res) => {
			     that.cid =  res.cid;
			     //console.log('客户端推送标识:',that.cid)
				 uni.setStorageSync("cid",that.cid);
			    },
			    fail(err) {
			     console.log(err)
				 uni.showToast({
				 	title:'获取推送标识失败',
				 	icon: 'none',
				 	duration: 4000
				 })
			    }
			});
			//this.UpdataToken();
		},
		methods: {
			dengluzhangh(event){
				this.zhanghao = event.target.value;
			},
			
			denglumima(event){
				this.mima = event.target.value;
			},
			yueduyszc(){
				uni.navigateTo({
					url:'/pages/index/yinszhengc'
				})
			},
			agrResult(state){//隐私协议
					 console.log(state);
					 if(state==0){
						if (plus.os.name.toLowerCase() === 'android') {
							console.log('ios');
							plus.runtime.quit();
						}
						else{
							console.log('ios');
							 plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
						}
					 }
					 if(state==1){
						 uni.showTabBar(); 
						 this.$refs.popYsxy.close();
						 uni.setStorageSync('yszche',1);
						 var yszche=uni.getStorageSync('yszche');
						 console.log(yszche);
					 }
					 if(state==2){
						uni.navigateTo({
							url:'/pages/index/yinszhengc'
						})	 
					 }
			},
			loginAC(){
				if(this.zhanghao.length<=0){
					uni.showToast({
					    title: this.$t('user.qsrzhanghao'),
					    icon: 'none',
					    duration: 1500
					})
					return
				}
				if(this.mima.length<=0){
					uni.showToast({
					    title: this.$t('user.qingshurmim'),
					    icon: 'none',
					    duration: 1500
					})
					return;
				}
				this.loginUp();
			},
			async loginUp(){
				var that = this;
				await this.$http.post(`${loginByzhmm}`, {
						userName:this.zhanghao,
						password:encrypt(this.mima),
						cid:this.cid
					},false)
				.then(async r => {
					console.log(r)
					if(r.data.code==200){
						plus.nativeUI.toast(this.$t('user.denglucg'), {
							icon : "none",// eg. "/img/add.png"
							duration : "long",// 持续3.5s，short---2s
							align : "center",// 水平居中
							verticalAlign : "bottom"// 垂直底部
						});
						uni.setStorageSync("token",r.data.token);
						getApp().globalData.token=r.data.token;
						uni.setStorageSync('userInfo',r.data.data);
						uni.setStorageSync("userId",r.data.data.userId);
						getApp().globalData.initgoEasy();
						uni.reLaunch({
							url:'/pages/index/index'
						})
						return;
					}
					if(r.data.code==500){
						uni.showToast({
						    title: r.data.msg,
						    icon: 'none',
						    duration: 3500
						})
						return;
					}
					uni.showToast({
					    title: that.$t('user.denglushib'),
					    icon: 'none',
					    duration: 3500
					})
					
					//uni.setStorageSync("token",r.data.token);
					//uni.navigateBack();
				})
				.catch(err => {
					console.log(err)
					uni.showToast({
					    title: that.$t('user.denglushib'),
					    icon: 'none',
					    duration: 2500
					})
				})
			},
			duoyuyan(){
				uni.navigateTo({
					url:'/pages/user/duoyuyan'
				})
			},
			registerAC(){
				uni.navigateTo({
					url:'/pages/user/RegisterView'
				})
			},
			gotogvWebview(){
				uni.navigateTo({
					url:'/pages/index/Openwebview?url=http://online.gov.vn/UngDung/chi-tiet-3269'
				})
			},
		}
	}
</script>

<style lang="scss">
	@import '@/common/common.scss';
	page{
		background-color:white;
	}
.topimag{
	width: 100%;
}

.contentVB{
	position: fixed;
	flex-direction: row;
	justify-content: center;
	align-items: center;
	bottom: 30rpx;
	width: 100%;
}
.contentV{
	display: flex;
	width: 92%;
	margin-left: 4%;
	flex-direction: column;
	justify-content: flex-start;
}
.titlev{
	width: 100%;
	height: 60rpx;
	line-height: 60rpx;
	font-size: 40rpx;
	font-weight: bold;
	text-align: left;
}
.yzmctV{
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content:flex-start;
	margin-top: 30rpx;
	width: 100%;
}
.yzmctVS{
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content:space-between;
	margin-top: 30rpx;
	width: 100%;
}
.noinputV{
	width: 73%;
	height: 80rpx;
	line-height: 80rpx;
	border-radius: 10rpx;
	border: 2rpx solid #F2F3F7;
	background-color: #F2F3F7;
}

.noinputVcode{
	width: 100%;
	height: 80rpx;
	line-height: 80rpx;
	border-radius: 10rpx;
	border: 2rpx solid #F2F3F7;
	background-color: #F2F3F7;
}


.yzmbt{
	color: white;
	font-size: 26rpx;
	width: 170rpx;
	height: 60rpx;
	line-height: 60rpx;
	text-align: center;
	margin-left: -190rpx;
	border-radius: 2rpx;
	background-color:#006AFF;
}

.yzmdl{
	color: white;
	font-size: 26rpx;
	width: 170rpx;
	height: 60rpx;
	line-height: 60rpx;
	text-align: center;
	margin-top: 26rpx;
	border-radius: 2rpx;
	background-color:#006AFF;
}

.querenBt{
	margin-top: 30rpx;
	width: 100%;
	height: 60rpx;
	line-height: 60rpx;
	padding: 10rpx;
	border-radius: 20rpx;
	text-align: center;
	justify-content: center;
	background-color: #006AFF;
	color: white;
	box-shadow: 0px 0rpx 10rpx 0rpx #006AFF;
}

.zhuceBt{
	width: 40%;
	height: 60rpx;
	line-height: 60rpx;
	padding: 10rpx;
	border-radius: 20rpx;
	text-align: center;
	justify-content: center;
	background-color: darkgray;
	color: white;
	box-shadow: 0px 0rpx 10rpx 0rpx darkgray;
}

.linktext{
	font-size: 24rpx;
	color:skyblue;
	text-decoration:underline;
}

.notetext{
	color: darkgray;
	font-size: 24rpx;
	text-align: center;
}
	
.xialakuangct{
	
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content:space-between;
	
	padding-left: 16rpx;
	margin-right: 20rpx;
	width: 140rpx;
	height: 80rpx;
	line-height: 80rpx;
	border-radius: 10rpx;
	border: 2rpx solid #F2F3F7;
	background-color: #F2F3F7;
}

.xialakuang{
	width: 100%;
}


.lineview{
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: center;
	background-color: whitesmoke;
	border: solid darkgray;
	border-width: 0px 0px 1rpx 0px;
	width: 80%;
	margin-bottom: 12rpx;
}

.picker-view {
	width: 750rpx;
	height: 300rpx;
	margin-top: 10rpx;
}
.item {
	line-height: 90rpx;
	text-align: center;
}
.duoyuyanctv{
		margin-top: 20rpx;
		padding: 30rpx;
		border: solid lavender;
		border-width: 0px 0px 1rpx 0px;
}
.duoyuyIcon{
	width: 40rpx;
	height: 40rpx;
}
</style>
