<template>
	<view class="all">
		<ujp-navbar title="修改手机号"></ujp-navbar>
		<view class="login-form">
			<view class="login-form-item">
				<view class="input">
					<u-input :customStyle="customStyle" :placeholderStyle="placeholderStyle" v-model="form.telephone" type="number" placeholder="请输入手机号" placeholder-style="font-size:16px;color:#ccc;"/>
				</view>
			</view>
			<view class="login-form-item">
				<view class="input">
					<u-input :customStyle="customStyle" :placeholderStyle="placeholderStyle" v-model="form.verifyCode" type="number" placeholder="请输入验证码" placeholder-style="font-size:16px;color:#ccc;"/>
					<view class="code" @click="getCode">{{codeTips}}</view>
				</view>
			</view>
		</view>
		
		<u-button class="login-btn" type="success" shape="circle" @click="sure">确定修改</u-button>
		
		<u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" change-text="已发送(Xs)">
		</u-verification-code>
	</view>
</template>

<script>
	import * as userApi from '@/apis/user.js'
	import * as loginApi from '@/apis/login.js'
	import {
		checkPhone
	} from '@/utils'
	
	export default {
		data() {
			return {
				elderMode:false,
				customStyle:{
					'font-size':'28rpx'
				},
				placeholderStyle:"font-size:28rpx",
				form: {
					telephone: '',
					verifyCode: '',
				},
				isSendMsgIng: false,
				sendMsgSecond: 60,
				codeTips: '',
				jpcode: 'toLogin',
			}
		},
		methods: {
			codeChange(text) {
				this.codeTips = text;
			},
			start() {
				if (!this.isSendMsgIng) {
					uni.showLoading({
						title: "加载中",
						mask: true,
					})
					loginApi.getVerifyCode(this.form.telephone).then((response) => {
						uni.hideLoading();
						this.carhelp.set("getvcodetime", new Date().getTime());
			
						if (!"") {
							//倒计时
							uni.showToast({
								title: "发送成功"
							})
						} else {
							uni.showToast({
								title: "您的验证码已经发送[5分钟有效]，请勿重复点击"
							})
						}
					}).catch(error => {
						uni.showToast({
							title: error,
							icon: "none"
						})
					})
				}
			},
			//倒计时
			end() {
				this.sendMsgSecond = 60;
				this.isSendMsgIng = false;
			},
			// 获取验证码
			getCode() {
				if (this.$refs.uCode.canGetCode) {} else {
					uni.showToast({
						title: '倒计时结束后再发送',
						icon: "none"
					})
					return
				}
			
				var checkPhoneResult = checkPhone(this.form.telephone);
			
				if (checkPhoneResult !== true) {
					uni.showToast({
						title: checkPhoneResult,
					})
					return;
				}
				this.$refs.uCode.start();
			},
			sure() {
				var checkPhoneResult = checkPhone(this.form.telephone);
				
				if(!this.form.telephone || checkPhoneResult != true) {
					uni.showToast({
						title: checkPhoneResult,
						icon: "none"
					})
					return;
				}
				if(!this.form.verifyCode) {
					uni.showToast({
						title: "请输入验证码",
						icon: "none"
					})
					return
				}
				
				uni.showLoading({
					title: "加载中",
					mask: true,
				})		
				userApi.changePhone(this.form).then((response) => {
					uni.hideLoading();
					
					uni.reLaunch({
						url: '/pages/index/index?jpcode=' + this.jpcode
					})
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
			theme(type) {
				
			  if(type == 'elder')	
			  {
				document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
				 let data = {
				 	"font-size":'32rpx', 
				 	};
				 this.customStyle = data;
				 this.placeholderStyle = "font-size:32rpx";//data;
			  }
			  else
			  {
				document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
				 let data = {
				 	"font-size":'28rpx'
				 	};
				this.customStyle = data;
				this.placeholderStyle = "font-size:28rpx";//data;
			  } 
			}
		}, 
		onReady(){
			this.elderMode = this.carhelp.get('getElderModeClass')  == '长辈模式';
			if(this.elderMode)
				this.theme('elder')
			else
				this.theme('standard')
		}
	}
</script>
<style>
	page{
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	@import "@/_theme.scss";
	.all{
		@include themeify{
			font-size: themed('font-size2');
		}
	}
	
	.login-form{
		background-color: #fff;
		padding: 12px 28px;
		
	}
	.login-form-item{
		
		.title{
			margin-bottom: 8px;
		}
		.input {
			padding: 4px 0;
			border-bottom: 1px solid #f7f7f7;
			position: relative;
		}
		.code{
			position: absolute;
			right: 0;
			top:12px;
			color:#1677FF;
		}
		.tips {
			color: $u-type-info;
			margin-top: 12px;
			@include themeify{
				font-size: themed('font-size1');
			}
/*			font-size: 12px;*/
			span{
				color:#3fbd70;
			}
		}
	}
		
	.login-btn {
		margin: 28px ;
		background-color:#00B962!important;
		border-color: #00B962!important;
		color:#fff!important;
	}
</style>
