<template>
	<view class="container">
		<image class="bg-image" src="../../../static/loginBg.png"></image>
		<view class="up">
			<!-- 自定义导航栏 -->
			<uni-nav-bar id="nav-bar" status-bar='true' :border='false' backgroundColor="rgba(164, 136, 220, 0)" @clickLeft="showClickEvent()"
			 :title="title" color="#FFFFFF" fixed="true">
				<view slot="left">
					<view class=" flex align-center margin-left" @tap="onBack">
						<image class="png-more" src="../../../static/m-icon/leftBack.png"></image>
					</view>
				</view>

				<view slot="right">

				</view>
			</uni-nav-bar>
			<!-- 手机端登录 -->
			<view class="text-26px text-white" style="margin: 105px 0 0 56rpx;">输入验证码</view>
			<view class="text-16px text-white" style="margin: 40px 0 0 56rpx;">已发送4位验证码至 +86 {{phoneNumber}}</view>
			<!-- <view class="flex" style="margin: 71px 0 0 46rpx;">
				<view class="grid col-4 grid-square flex-sub ">
					<view v-for="(item,index) in 4" :key="index">
						<input class='iptbox' type="number" disabled :value="Value.length>=index+1?Value[index]:''" :password="false"
						 @tap="onTap"></input>
					</view>
				</view>
			</view> -->
			<view class="code-input-main">
				<view class="inputLine">
					<input class="input-item" maxlength="1" :value="code[0]"></input>
					<input class="input-item" maxlength="1" :value="code[1]"></input>
					<input class="input-item" maxlength="1" :value="code[2]"></input>
					<input class="input-item" maxlength="1" :value="code[3]"></input>
				</view>
				<!-- <view class="inputLine">

					<input class="input-item" maxlength="1" :value="code[3]"></input>
					<input class="input-item" maxlength="1" :value="code[4]"></input>
					<input class="input-item" maxlength="1" :value="code[5]"></input>
				</view> -->
				<input @input="inputEvent" class="code-input-input" v-model="code" maxlength="4" type="number" />
			</view>

			<view class="btn-row" style="margin-top: 46px;">
				<button type="primary" class="primary btn-confirm" :disabled="code.length<4" @tap="onConfirm">确认</button>
			</view>


			<view v-if="bCodeDisabled" class="action-row">
				<view class="action-child text-gray">重新获取({{count}})</view>
				<!-- <text style="color: #FFFFFF;">|</text>
				<navigator url="../pwd/pwd">忘记密码</navigator> -->
			</view>
			<view v-else class="action-row">
				<view class="action-child" @tap="onGetCode">重新发送验证码</view>
				<!-- <text style="color: #FFFFFF;">|</text>
				<navigator url="../pwd/pwd">忘记密码</navigator> -->
			</view>


			<input class='ipt' type="number" :maxlength="Length" :focus="bFocus" @input="onInputFocus" @focus="onFocus"></input>


		</view>

	</view>
</template>

<script>
	import service from '../../../util/util-js/service.js';
	import mInput from '../../../components/m-input.vue';
	import reqUtil from "@/util/util-js/requstUtil.js";
	import config from '../../../common/config.js';
	import verify from '../../../util/util-js/verify.js';
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue";
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		components: {
			mInput,
			uniNavBar
		},
		data() {
			return {
				//输入框参数
				Length: 4, //输入框个数
				bFocus: false, //聚焦
				Value: "", //输入的内容
				code: '',
			}
		},
		computed: mapState(['phoneNumber', 'bCodeDisabled', 'count']),
		onLoad() {
			// console.log("初始化onLoad");
			this.onGetCode();
		},
		methods: {
			...mapMutations(['countDown', 'accountLogin']),
			//注册
			onConfirm() {

				reqUtil.requestData(config.URL.SMSLOGIN, {
					"phoneNumber": this.phoneNumber,
					"code": this.code
				}).then(res => {
						console.log('requestData GETCODE =====', res);
						if (res.code == 0) {
							uni.showToast({
								title: "注册成功",
								mask: true,
								duration: 1000
							})
							//登录成功
							uni.setStorageSync('token', res.data.token);
							// this.$store.state.hasLogin = true;
							this.accountLogin();
							uni.navigateTo({
								url: "../../personal-page/personal/personal"
							})
						} else {
							uni.showToast({
								title: "验证码错误",
								mask: true,
								icon: 'none',
								duration: 1000
							})
						}


					},
					e => {
						console.log(e)
					});
			},
			onGetCode() {
				//置灰状态
				if (this.bCodeDisabled) return;


				//调用store 倒计时
				this.countDown();

			},
			onTap() {
				this.bFocus = true;
				console.log(this.bFocus);
			},
			onFocus(e) {

				console.log(e);
				setTimeout(() => {
					// this.bFocus = false;
				}, 1000)
			},
			onInputFocus(e) {
				console.log(e.detail.value);
				this.Value = e.detail.value;

			},
			onBack() {
				uni.navigateBack();
			},
			inputEvent(res) {
				console.log("input 1 input code  components : ", res.detail.value);
				/* this.$emit('vueMsg',res.detail.value); */

			}
		}
	}
</script>

<style>
	.action-row {
		margin-top: 25px;
		display: flex;
		flex-direction: row;
		justify-content: center;
	}

	.action-child {
		color: #FFFFFF;
		padding: 0 20upx;
	}

	.iptbox {
		width: 102rpx;
		height: 102rpx;
		border: 1rpx solid #ddd;
		border-radius: 8rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		text-align: center;
		background-color: rgba(255, 255, 255, 0.2);
		color: #FFFFFF;
		font-size: 20px;
	}

	.ipt {
		width: 0;
		height: 0;
	}

	.btn-confirm {
		width: 636rpx;
		height: 102rpx;
		background-color: rgba(75, 208, 200, 1);
		border-radius: 25px;
		opacity: 0.84;
	}

	.container {
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		background-color: #000000;
	}

	.bg-image {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		opacity: 0.55;
	}

	.up {
		position: absolute;
		z-index: 1;
		width: 100%;
		/* display: flex; */
		/* align-items: flex-start; */
		/* flex-direction: column; */
	}

	.png-more {
		width: 10px;
		height: 19px;
	}

	.code-input-input {
		height: 150px;
		position: absolute;
		width: 100%;
		outline: none;
		color: transparent;
		text-shadow: 0 0 0 transparent;
		width: 300%;
		margin-left: -100%;
		background: #00000000;
		/* border: 1rpx solid #007AFF; */
	}

	.code-input-main {
		display: flex;
		flex-direction: column;
		width: 100%;
		margin-bottom: 46px;
		/* border: 1rpx solid #000000; */
		height: 150px;
	}

	.input-item {
		width: 102rpx;
		height: 102rpx;
		font-size: 20px;
		background-color: rgba(255, 255, 255, 0.2);
		border: 1rpx solid #ddd;
		text-align: center;
		border-radius: 8px;
		margin-left: 40upx;
		margin-right: 40upx;
		color: #FFFFFF;
	}

	.inputLine {
		display: flex;
		justify-content: center;
		width: 100%;
		margin-top: 80upx;
	}
</style>
