<template>
	<view>
		<view class="logo">
			<view class="img">
				<image mode="widthFix" src="../../../static/img/logo2.jpg">
				</image>
			</view>
		</view>
		<!-- 账号密码输入框 -->
		<view class="form re">
			<view class="username">
				<view class="get-code" style="color: #676767;" @click.stop="getCode()">{{getCodeText}}</view>
				<input placeholder="请输入手机号" disabled="true" v-model="phoneNumber" placeholder-style="color: #676767;" />
			</view>
			<view class="code">
				<input placeholder="请输入验证码" v-model="code" placeholder-style="color: #676767;" />
			</view>
			<!-- <view class="password">
				<image src="../../../static/img/pas.png" style="width: 40rpx;height: 40rpx;"></image>
				<input placeholder="请输入旧密码" type="number" maxlength="6" v-model="jpasswd" password=true
					placeholder-style="color: #333333;" />
			</view> -->
			<view class="password">
				<!-- <image src="../../../static/img/pas.png" style="width: 40rpx;height: 40rpx;"></image> -->
				<input placeholder="请输入新密码" type="number" maxlength="6" v-model="xpasswd" password=true
					placeholder-style="color: #676767;" />
			</view>
			<view class="btn mart50" @tap="updateUserPayPwd">确 认</view>
		</view>
	</view>
</template>

<script>
	import {
		updateUserPayPwd,
		sendSmsCodeByHw
	} from "../../../Utils/Api.js";
	let app = getApp();
	export default {
		data() {
			return {
				phoneNumber: "",
				code: '',
				getCodeText: '获取验证码',
				getCodeisWaiting: false,
				jpasswd: '',
				xpasswd: '',
			}
		},
		onLoad() {
			this.phoneNumber = app.globalData.userInfo.phone;
		},
		methods: {
			//发送短信
			getCode() {
				uni.hideKeyboard()
				if (this.getCodeisWaiting) {
					return;
				}
				uni.showLoading({
					title: '发送中...'
				})
				let params = {
					phone: this.phoneNumber,
					HWMSG: 6
				}
				sendSmsCodeByHw(params).then(res => {
					if (res.return_code == '000000') {
						this.getCodeisWaiting = true;
						uni.showToast({
							title: '验证码已发送',
							icon: "none"
						});
						this.setTimer();
					} else {
						uni.showToast({
							title: res.return_msg,
							duration: 2000,
							icon: "none"
						})
						uni.hideLoading()
					}
				})
			},
			//发送验证码
			setTimer() {
				let holdTime = 60;
				this.getCodeText = "重新获取(60)"
				this.Timer = setInterval(() => {
					if (holdTime <= 0) {
						this.getCodeisWaiting = false;
						this.getCodeBtnColor = "#ffffff";
						this.getCodeText = "获取验证码"
						clearInterval(this.Timer);
						return;
					}
					this.getCodeText = "重新获取(" + holdTime + ")"
					holdTime--;

				}, 1000)
			},
			//修改密码
			updateUserPayPwd() {
				uni.hideKeyboard();
				if (this.code == '') {
					uni.showToast({
						title: '请填写验证码',
						icon: "none",
						duration: 2000
					});
					return false;
				}

				if (this.xpasswd == '') {
					uni.showToast({
						title: '请填写新的积分支付密码',
						icon: "none",
						duration: 2000
					});
					return false;
				}
				uni.showLoading({
					title: '设置中...'
				})
				let datas = {
					"code": this.code,
					"newPassword": this.xpasswd
				}
				updateUserPayPwd(datas).then(res => {
					if (res.return_code == '000000') {
						uni.hideLoading();
						uni.showToast({
							title: '修改成功',
							icon: "none",
							duration: 2000
						});
						uni.navigateBack({})
					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.return_msg,
							icon: "none",
							duration: 2000
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import '../../../static/css/login.scss';

	.form {
		.res {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 100upx;
			color: rgba($color: #ffffff, $alpha: 0.8);
		}
	}
</style>
