<template>
	<view class="content">
		<view class="status_bar"></view>
		<view class="logo">
			<image src="~@/static/logo.png" mode="aspectFit"></image>
		</view>
		<view class="title">
			<text v-if="mine_code == 'ningdongyunying'">E信管理</text>
			<text v-if="mine_code == 'zaoquan'">枣泉煤矿</text>
		</view>
		<view class="change_box">
			<view class="item">
				<view class="name">手机号</view>
				<view class="input">
					<input type="text" value=""  v-model="mobile"/>
				</view>
			</view>
			<view class="send_box">
				<view class="send_code">
					<view class="name">验证码</view>
					<view class="input">
						<input type="text" value="" v-model="vcode"/>
					</view>
				</view>
				
				<view class="send_btn" @click="send_vcode()">
					<text>{{send_text}}</text>
				</view>
			</view>
			<view class="item">
				<view class="name">修改密码</view>
				<view class="input">
					<input type="password" value="" v-model="password"/>
				</view>
			</view>
			<view class="item">
				<view class="name">确认密码</view>
				<view class="input">
					<input type="password" value="" v-model="copypassword"/>
				</view>
			</view>
		</view>

		<view class="tips">
			<text @click="back()">记起来了？请点击这登陆</text>
		</view>

		<view class="change_btn" @click="changeBtn()">
			<text>确认修改</text>
		</view>

	</view>
</template>

<script>
	var testPassword =/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,15}$/
	
	export default {
		data() {
			return {
				mine_code:"",
				mobile:'',
				vcode:'',
				password:'',
				copypassword:'',
				send_text:'发送验证码'
			};
		},
		onLoad() {
			this.mine_code = uni.getStorageSync('mine_code')
		},
		methods: {
			changeBtn() {
				

			},
			back(){
				uni.navigateTo({
					url:"../login/login"
				})
			},
			
			
			send_vcode(){
				if(this.mobile.length < 11){
					uni.showToast({
						icon:'none',
						title:'请填写正确的手机号'
					})
					return
				}
				
				if(this.send_text == "发送验证码"){
					this.$api.sms_send_v_code({
						mobile:this.mobile
					}).then((res)=>{
						
						console.log(res.data)
						
						if(res.data.code == 3001){
							uni.showToast({
								icon:"none",
								title:"电话号码错误"
							})
							this.send_text = "发送验证码"
						}else if(res.data.code == 3002){
							uni.showToast({
								icon:"none",
								title:"发送失败"
							})
							this.send_text = "发送验证码"
						}else if(res.data.code == 3003){
							uni.showToast({
								icon:"none",
								title:"请填写绑定的手机号"
							})
							this.send_text = "发送验证码"
						}else if(res.data.code == 0){
							uni.showToast({
								icon:"none",
								title:"验证码发送成功"
							})
						}
					})
				}
				
				this.send_text = "已发送"
				if(this.send_text = "已发送"){
					uni.showToast({
						icon:"none",
						title:"请勿重复发送"
					})
				}
				
			},
			
			changeBtn(){
				if(this.vcode == ''){
					uni.showToast({
						icon:'none',
						title:'请填写验证码'
					})
					return
				}
				
				if(this.password == '' || this.copypassword == ''){
					uni.showToast({
						icon:'none',
						title:'请填写完整信息'
					})
					return
				}
				
				if(this.password !== this.copypassword){
					uni.showToast({
						icon:'none',
						title:'两次密码输入不一致'
					})
					return
				}
				
				if( !testPassword.test(this.password) ){
					uni.showToast({
						icon:'none',
						title:'密码必须包含大写字母、小写字母、数字和特殊符号且长度在8位至16位之间'
					})
					return
				}
				
				this.$api.user_forget_password({
					mobile:this.mobile,
					vcode:this.vcode,
					password:this.password
				}).then((res)=>{
					console.log(res)
					
					if(res.data.code == 4002){
						uni.showToast({
							icon:'none',
							title:"验证码超时或者错误"
						})
						return
					}else{
						uni.setStorageSync('login_password',this.password)
						
						uni.showToast({
							icon:'none',
							title:'密码修改成功、返回登陆'
						})
						this.send_text = "发送验证码"
					}
					
					
					
					setTimeout(function(){
						uni.navigateTo({
							url:"../login/login"
						})
					},1000)
				})
				
			}

		}

	}
</script>

<style lang="scss">
	page {}

	.content {
		width: 750rpx;
		min-height: 100vh;
		height: 100%;
		background-image: url(~@/static/login.png);
		background-size: cover;
		background-position: center  center;
		background-repeat: no-repeat;
		
		.logo {
			width: 344rpx;
			height: 350rpx;
			margin: 0 auto;
			padding-top: 100rpx;
		
			image {
				width: 100%;
				height: 100%;
			}
		}
		
		.title {
			margin: 0 auto;
			margin-top: 32rpx;
			width: 288rpx;
			height: 47rpx;
			font-size: 36rpx;
			color: #FFFFFF;
			line-height: 47rpx;
			text-align: center;
		}
		
		.change_box {
			padding-top: 40px;

			.item {
				margin: 0 auto;
				margin-bottom: 20px;
				width: 600rpx;
				height: 45px;
				background: #FFFFFF;
				border-radius: 25px;
				box-sizing: border-box;
				padding: 0 20px;
				display: flex;
				align-items: center;

				.name {
					width: 150rpx;
					font-size: 16px;
					color: #009FE8;
					line-height: 45px;
				}

				.input {
					input {
						height: 45px;
						color: #666;
					}
				}

			}
			
			.send_box{
				margin: 0 auto;
				margin-bottom: 20px;
				width: 600rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.send_code{
					background: #FFFFFF;
					border-radius: 25px;
					box-sizing: border-box;
					padding: 0 20px;
					height: 45px;
					
					display: flex;
					justify-content: space-between;
					align-items: center;
					.name{
						width: 120rpx;
						font-size: 16px;
						font-family: MicrosoftYaHei;
						color: #009FE8;
						line-height: 45px;
					}
					.input{
						width: 140rpx;
					}
				}
				.send_btn{
					width: 220rpx;
					height: 50px;
					background: rgba(100, 220, 255, 0.8);
					border-radius: 25px;
					text-align: center;
					line-height: 50px;
					
					text {
						font-size: 34rpx;
						color: #FFFFFF;
					}
				}
			}
		}

		.tips {
			margin: 0 auto;
			margin-top: 25px;
			text-align: center;
			font-size: 14px;
			color: #ECF0F1;
			line-height: 40px;
			text-align: center;

		}

		.change_btn {
			margin: 40px auto;
			width: 200px;
			height: 50px;
			background: rgba(100, 220, 255, 0.8);
			border-radius: 25px;
			text-align: center;
			line-height: 50px;

			text {
				font-size: 18px;
				color: #FFFFFF;
				letter-spacing: 4px;
			}
		}
	}
</style>
