<template>
	<view class="web_box vflex acenter jbetween">
		<view style="width: 100%;">
			<!-- <u-navbar height="44" leftIcon="arrow-left" leftIconColor="#000" leftText="修改密码" @leftClick="leftClick" :autoBack="true" bgColor="#fff">
			</u-navbar> -->
			<view class="form">
				<u--form labelPosition="left" ref="form1" labelWidth="100">
					<u-form-item label="手机号">
						<view class="text">{{tele}}</view>
					</u-form-item>
					<u-form-item label="验证码">
						<u-input v-model="code" border="none" placeholder="请输入验证码">
							<template slot="suffix">
								<u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
								<view class="code" @tap="getCode">{{tips}}</view>
							</template>
						</u-input>
					</u-form-item>
					<u-form-item label="密码">
						<u--input type="password" v-model="password" border="none" placeholder="请输入新密码"></u--input>
					</u-form-item>
					<u-form-item label="确定密码">
						<u--input type="password" v-model="password2" border="none" placeholder="请重新输入新密码"></u--input>
					</u-form-item>
				</u--form>
			</view>	
		</view>
		<view class="bottom hflex acenter jcenter">
			<u-button @click="edit">确定修改</u-button>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js';
	export default {
		data() {
			return {
				tele: '',
				code: '',
				password: '',
				password2: '',
				tips: ''
			}
		},
		onLoad() {
			this.getTele()
			var login = uni.getStorageSync('token')
			if (!login) {
				$api.info("请先登录")
				$api.jump(-1)
			}
		},
		methods: {
			leftClick() {
				
			},
			// 确定修改
			edit() {
				var that = this
				if ($api.formCheck(that.code,"code6") && $api.formCheck(that.password,"required") && $api.formCheck(that.password2,"required")) {
					$api.req({
						url: '/api/User/updatePass',
						data: {
							ver_code: that.code,
							password: that.password,
							confirmpassword: that.password2
						}
					}, function(res) {
						if(res.code == 1) {
							$api.jump('/pages/mine/password/success')
						}
					}) 
				}
				
			},
			// 获取手机号
			getTele() {
				var that = this
				$api.req({
					url: '/api/User/userinfo'
				}, function(res) {
					if(res.code ==1) {
						that.tele = res.data.phone
					}
				})
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				var that = this
				if (this.$refs.uCode.canGetCode) {
				  uni.showLoading({
					title: '正在获取验证码'
				  })
				  
				  setTimeout(() => {
					uni.hideLoading();
					uni.$u.toast('验证码已发送');
					$api.req({
						url: '/api/Sms/send',
						data: {
							phone: that.tele,
						}
					},function(res) {
						if (res.code == 1) {
							// $api.info("发送成功")
						}
					})
					this.$refs.uCode.start();
				  }, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.web_box::v-deep {
		
		.u-navbar {
			width: 100%;
			box-sizing: border-box;
			padding: 36px 16px 58rpx 0;
		}
		.form {
			margin: 20rpx 0;
			width: 100%;
			box-sizing: border-box;
			padding: 0 54rpx;
			background: #FFFFFF;
		}
		.u-form-item__body {
			padding: 27rpx 0;
		}
		.u-input {
			background: #EEEEEE;
			box-shadow: 1px 1px 2px 0px rgba(189,189,189,0.5);
			border-radius: 38rpx;
			box-sizing: border-box;
			padding: 10rpx 34rpx !important;
		}
		.text {
			box-sizing: border-box;
			padding: 10rpx 34rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: #333333;
		}
		.code {
			font-size: 28rpx;
			font-weight: 400;
			color: #3E93FD;
		}
		.bottom {
			width: 100%;
			box-sizing: border-box;
			padding: 20rpx 86rpx;
			background: #FFFFFF;
		}
		.u-button {
			width: 578rpx;
			margin: 0;
			height: 80rpx;
			background: linear-gradient(135deg, #53BDFF 0%, #2988FE 100%);
			border-radius: 40rpx;
			font-size: 36rpx;
			font-weight: 500;
			color: #FFFFFF;
		}
		
	}
</style>