<template>
	<view class="p-root-person-pwdForget g_w_all g_h_all g_bg_f_5 g_kuaishou">
		<view class="g_pt_10 g_mb_24">
			<g-panel-form-slot
				:list="[
					{
						icon: '',
						label: '手机号',
						result: tel,
						path: '',
						tip: 'mobile',
						type: 'slot',
					},
					{
						icon: '',
						label: '验证码',
						result: '',
						path: '',
						tip: 'slot-code',
						value: code,
						type: 'slot',
						placeholder: '输入验证码',
						pColumn: 12,
					},
				]"
				@changeCode="getCode"
			>
			</g-panel-form-slot>
		</view>
		<view class="">
			<g-panel-form-slot
				:list="[
					{
						icon: '',
						label: '新密码',
						result: '',
						path: '',
						tip: 'slot-new-pwd',
						value: newPwd,
						type: 'slot',
						placeholder: '请输入新密码',
						pColumn: 12,
					},
					{
						icon: '',
						label: '确认密码',
						result: '',
						path: '',
						tip: 'slot-confirm-pwd',
						value: confirmPwd,
						type: 'slot',
						placeholder: '再次输入新密码',
						pColumn: 12,
					},
				]"
				@changeNewPwd="getNewPwd"
				@changeConfirmPwd="getConfirmPwd"
			>
			</g-panel-form-slot>
		</view>
		<view class="g_pt_90 g_flex_row_center">
			<rh-button  btnText="修改密码" type="primary" @clickBtn="submitForm" />
		</view>
	</view>
</template>

<script>
export default {
	onReady() {},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	components: {
	},
	data() {
		return {
			tel: uni.getStorageSync("apply-tel"),
			code: "",
			newPwd: "",
			confirmPwd: "",
		};
	},
	methods: {
		getCode(e) {
			this.code = e;
		},
		getNewPwd(e) {
			this.newPwd = e;
		},
		getConfirmPwd(e) {
			this.confirmPwd = e;
		},
		submitForm() {
			let that = this;
			if (that.code == "") {
				uni.showToast({
					title: "请输入验证码",
					icon: "none",
				});
				return false;
			}
			if (that.newPwd == "") {
				uni.showToast({
					title: "请输入新密码",
					icon: "none",
				});
				return false;
			}
			if (that.confirmPwd == "") {
				uni.showToast({
					title: "请再次输入新密码",
					icon: "none",
				});
				return false;
			}
			if (that.confirmPwd != that.newPwd) {
				uni.showToast({
					title: "前后密码不一致",
					icon: "none",
				});
				return false;
			}
			that.G.Get(
				that.api.user_changeForgetPwd,
				{
					tel: uni.getStorageSync("apply-tel"),
					code: that.code,
					password: that.newPwd,
				},
				() => {
					uni.showToast({
						title: "修改成功",
						icon: "success",
					});
					setTimeout(() => {
						that.G.Get(that.api.login_out, {}, () => {
							that.G.clearLocalStorage();
							let params = {
								path: "",
								level: "",
							};
							uni.reLaunch({
								url: "/root/login/index?" + that.G.objToStr(params),
							});
						});
					}, 1500);
				}
			);
		},
		goPage() {
			uni.navigateTo({
				url: "/root/person/pwdForget",
			});
		},
	},
};
</script>

<style></style>
