<template>
	<view class="updata-psw">
		<custom-nav noback="noback" transparent="transparent" ref="ltm" title=" " />
		<view class="content">
			<view style="width: 100%; padding-left: 24px;">设置密码：</view>
			<view style="height: 12px;"></view>
			<input type="text" maxlength="16" v-model="psw1" placeholder="请输入密码" />
			<view style="height: 24px;"></view>
			<view style="width: 100%; padding-left: 24px;">确认密码：</view>
			<view style="height: 12px;"></view>
			<input type="text" maxlength="16" v-model="psw2" placeholder="请再次输入密码" />
			<view class="big-btn bg" @tap="updata">修改密码</view>
			<view style="height: 12x;"></view>
			<view class="basecolor">* 密码为6至16位任意数字字母组合</view>
		</view>
	</view>
</template>

<script>
	import { _API_UpdataPsw } from '@/apis/verify.js'
	import { _API_Logout } from "@/apis/verify.js"
 	export default {
		data() {
			return {
				psw1: '',
				psw2: '',
			};
		},
		methods: {
			updata() {
				if (this.psw1.trim().length != this.psw2.trim().length) { uni.toast('两次输入的密码不一致，请确认'); return }
				console.log(this.psw1.trim()  === this.$store.state.userinfo.mobile.toString())
				if (this.psw1.trim()  === this.$store.state.userinfo.mobile.toString()) { uni.toast('新密码不能与原密码一致'); return }
				if (this.psw1.length >= 6 && this.psw1.length <= 16) {
					uni.showLoading({ mask: true })
					let _this = this
					_API_UpdataPsw({ password: this.psw1 }).then(res => {
						_API_Logout().then(() => {
							_this.$store.commit('app/LOGOUT')
							_this.toWxchatLogin("/pages/login-reg/login-reg", null)
						})
					})
				} else {
					uni.toast('密码格式错误')
				}
			},
			toWxchatLogin(url, state) {
				url = url || "/pages/index/index"
				state = state || "cli"
				const redirect_uri = encodeURIComponent(`${this.$config.redirect_uri}/api/gzh#${url}`)
				const auth = () => window.location.href = `${this.$config.wxURL}?appid=${this.$config.appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`
				auth()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.updata-psw {
		@include page();
		.content {
			@include flex(column);
			justify-content: flex-start;
			padding-top: 98rpx;
			input {
				width: 666rpx;
				height: 98rpx;
				font-size: 45rpx;
				text-align: center;
				background: #FFFFFF;
				border-radius: 24rpx;
			}
		}
	}
</style>
