<template>
	<view class="page">
		<view class="list_info">
			<view class="name">手机号码：</view>
			<view class="item">
				<input type="text" class="input" placeholder="请输入手机号码" v-model="mobile" maxlength="11"
					disabled="true" />
			</view>
			<view class="name">验证码：</view>
			<view class="item">
				<input type="text" class="input" placeholder="请输入验证码" v-model="code" maxlength="6" />
				<view class="btn">获取验证码</view>
			</view>
			<view class="name">设置新密码：</view>
			<view class="item">
				<input type="password" class="input" placeholder="请输入新登录密码" v-model="password1" maxlength="32" />
			</view>
			<view class="name">确认新密码：</view>
			<view class="item">
				<input type="password" class="input" placeholder="请再次输入新登录密码" v-model="password2" maxlength="32" />
			</view>

			<view class="blankHeight"></view>
		</view>

		<view class="btn_submit" @click="submitData">提交修改</view>


		<!-- 提示框 -->
		<DialogBox ref="DialogBox"></DialogBox>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				title: '',
				sel: 1,
				mobile: '188****6699',
				password1: '',
				password2: '',
				code: '',
				captchaTime: 0,

			}
		},
		onLoad() {},
		onShow() {
			// this.loadData();
		},
		methods: {
			onBack() {},
			getCodeTime() {
				this.captchaTime = 60;
				let timer = setInterval(() => {
					this.captchaTime--;
					// console.log(this.captchaTime)
					if (this.captchaTime < 1) {
						clearInterval(timer);
						this.captchaTime = 0
					}
				}, 1000)
			},
			getCode() {
				if (this.mobile.length != 11) {
					uni.showToast({
						title: '请输入新手机号',
						icon: 'none'
					});
					return;
				}
				if (this.captchaTime > 0) {
					uni.showToast({
						title: '不能重复获取',
						icon: 'none'
					});
					return;
				}
				this.captchaTime = 60;

				uni.request({
					url: this.$apiHost + '/Web/getcode', //仅为示例，并非真实接口地址。
					data: {
						skey: this.skey,
						mobile: this.mobile,
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					success: (res) => {
						console.log("----", res.data)
						uni.showToast({
							title: res.data.str,
							icon: 'none'
						})
						if (res.data.success == 'yes') {
							this.getCodeTime();
						} else {
							this.captchaTime = 0;
						}
					}
				});

			},
			submitData() {
				if (this.mobile == "") {
					uni.showToast({
						title: "请输入手机号码",
						icon: 'none'
					});
					return;
				}
				if (this.password1 == "" || this.password1 != this.password2) {
					uni.showToast({
						title: "请输入密码并确保两次密码一致",
						icon: 'none'
					});
					return;
				}
				if (this.code == "") {
					uni.showToast({
						title: "请输入验证码",
						icon: 'none'
					});
					return;
				}
				uni.request({
					url: this.$apiHost + '/Member/editPass',
					data: {
						uuid: getApp().globalData.uuid,
						type: 'forget',
						password: this.password1,
						code: this.code,
					},
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						console.log("----", res.data);
						uni.showToast({
							title: res.data.str,
							icon: 'none'
						});
						if (res.data.success == "yes") {

						}
					}
				});

			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'normal.scss';
</style>