<template>
	<view class="body">
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>

		<view class="form">
			<view class="password">
				<view class="icon iconfont icon-icon-mima"></view>
				<input  type="text" placeholder="请输入旧密码" v-model="oepwd"  :password="isHidePassword"
					placeholder-style="color: #C5C5C5;font-size:26upx" />
					<view class=" position-absolute top-0 right-0 d-flex a-center j-center"
							style="padding-right: 10px;height: 100%;">
							<image
								:src="isHidePassword?'../../static/image/login/biyan.png':'../../static/image/login/zhengyan.png'"
								@tap="isHidePassword = !isHidePassword" mode="" style="width: 18px;height: 18px;">
						</view>
			</view>
			<view class="password">
				<view class="icon iconfont icon-icon-mima"></view>
				<input type="text" placeholder="请设置新密码(6-15位数字与字母组合)" v-model="pwd" :password="isHidePassword1"
					placeholder-style="color: #C5C5C5;font-size:26upx" />
					<view class=" position-absolute top-0 right-0 d-flex a-center j-center"
							style="padding-right: 10px;height: 100%;">
							<image
								:src="isHidePassword1?'../../static/image/login/biyan.png':'../../static/image/login/zhengyan.png'"
								@tap="isHidePassword1 = !isHidePassword1" mode="" style="width: 18px;height: 18px;">
						</view>
			</view>
			<view class="password">
				<view class="icon iconfont icon-icon-mima"></view>
				<input type="text" placeholder="再次输入新密码" v-model="repwd"  :password="isHidePassword2"
					placeholder-style="color: #C5C5C5;font-size:26upx" />
					<view class=" position-absolute top-0 right-0 d-flex a-center j-center"
							style="padding-right: 10px;height: 100%;">
							<image
								:src="isHidePassword2?'../../static/image/login/biyan.png':'../../static/image/login/zhengyan.png'"
								@tap="isHidePassword2 = !isHidePassword2" mode="" style="width: 18px;height: 18px;">
						</view>
			</view>
			<button class="user-set-btn d-flex a-center j-center main-bg-color" :loading="loading"
				:class="{'main-bf-hover-color':disabled}" :disabled="disabled" type="primary" @tap="submit">完成</button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,mapMutations
	} from "vuex"
	export default {
		data() {
			return {
				oepwd:'',
				pwd: "",
				repwd: "",
				loading: false,
				disabled: true,
				isHidePassword: true, //是否隐藏密码
				isHidePassword1: true, //是否隐藏密码
				isHidePassword2: true, //是否隐藏密码

			}
		},
		watch: {
			pwd(val) {
				this.OnBtnChange();
			},
			repwd(val) {
				this.OnBtnChange();
			},

		},
		computed: {
			...mapState(['userInfo'])
		},
		methods: {
			...mapMutations(['emptyUserInfo']),
			// 改变按钮状态
			OnBtnChange() {
				if (this.pwd && this.repwd) {
					this.disabled = false;
					return;
				}
				this.disabled = true;
			},
			async submit() {
				if (!this.$base.passwordRegular.test(this.pwd)) {
					return uni.showToast({
						title: '密码须6-15位数字与字母组合',
						icon: 'none'
					});
				}
				if (this.pwd != this.repwd) {
					return uni.showToast({
						title: '两次密码输入不一致',
						icon: "none"
					});
				}

				let res = await this.$http.post('/user/updatePartnerPwd?id=' + this.userInfo.sysUser.userId + '&password=' + this
					.pwd+'&oldPassword=' + this.oepwd);
				if (res.code == 200) {
					this.pwd = "";
					this.repwd = "";
					this.oepwd = "";
					uni.showToast({ title:  res.msg, icon:"none",duration:2000 });
					setTimeout(() => {
						this.emptyUserInfo();
							uni.reLaunch({
								url:"/pages/login/login"
							})
							return true;
					}, 2000);
					}
					else{
						return uni.showToast({
							title: res.msg,
							icon: "none"
						});
					}

			}
		}
	}
</script>

<style>
	.body {
		position: absolute;
		width: 100%;
		height: 100vh;
		background-color: #F5F5F5;
	}

	.form {
		width: 100%;
		padding: 20upx 5%;
		font-size: 30upx;
	}

	.form .password {
		position: relative;
		width: 100%;
		height: 90upx;
		display: flex;
		align-items: center;
		border-radius: 5upx;
		background-color: #FFFFFF;
		padding: 0 0 0 100upx;
		margin: 30rpx 0rpx 50rpx;
	}

	.form .password input {
		width: 100%;
		height: 50rpx;
		color: rgba($color: #ffffff, $alpha: 0.8);
		font-weight: 200;
	}

	.icon {
		color: #999;
		height: 70upx;
		font-size: 40upx;
		z-index: 10;
		position: absolute;
		top: 10upx;
		left: 10upx;
		padding: 0 15upx;
		border-right: 2px solid #F5F5F5;
	}
</style>