<template>
	<view class="page">
		<view class="list_info">
			<!-- 标题和说明 -->
			<view class="title">原手机号验证</view>
			<view class="subtitle">该账号绑定的原手机号 139****5599，完成手机验证</view>

			<!-- 手机号输入 -->
			<view class="phone_input">
				<text class="area_code">+86</text>
				<input type="text" class="input" placeholder="请输入手机号" v-model="mobile" maxlength="11" />
			</view>

			<!-- 验证码输入 -->
			<view class="code_input">
				<input type="text" class="input" placeholder="请输入验证码" v-model="code" maxlength="6" />
				<view class="btn" v-if="captchaTime === 0" @click="getCode">获取验证码</view>
				<view class="btn disabled" v-else>{{captchaTime}}秒后重试</view>
			</view>

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

		<view class="btn_submit">确定</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				title: '',
				mobile: '',
				code: '',
				captchaTime: 0,
			}
		},
		onLoad() {},
		onShow() {
			// this.loadData();
		},
		methods: {
			onBack() {},
			chkSel() {
				if (this.sel == 1) {
					this.sel = 0;
				} else {
					this.sel = 1;
				}
			},
			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.code == "") {
					uni.showToast({
						title: "请输入验证码",
						icon: 'none'
					});
					return;
				}
				uni.request({
					url: this.$apiHost + '/Member/editMobile',
					data: {
						uuid: getApp().globalData.uuid,
						mobile: this.mobile,
						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>