<template>
	<view class="container avstarBack">
		<uni-navbar title="修改密码"></uni-navbar>
		<view class="box commonMt relative">
			<view class="absolute">
				<view class="choose-line-bottom commonBj">
					<u--form :model="form" ref="formRef" :rules="rules" labelWidth="0" class="formStyle">
						<u-form-item ref="form1">
							<view class="redCircle"></view>
							<text class="itemText">账&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</text>
							<u-input disabled disabledColor="rgba(73,91,147,0.2)" class="inputStyle"
								v-model="form.userName" placeholder="请输入账号">
							</u-input>
						</u-form-item>
						<u-form-item prop="oldPassword">
							<view class="redCircle"></view>
							<text class="itemText">原始密码</text>
							<u-input class="inputStyle" v-model="form.oldPassword" placeholder="请输入原始密码	">
							</u-input>
						</u-form-item>
						<u-form-item prop="newPassword">
							<view class="redCircle"></view>
							<text class="itemText">新&nbsp;&nbsp;密&nbsp;&nbsp;码</text>
							<u-input class="inputStyle pasStyle" v-model="form.newPassword" placeholder="大小写字母组合+特殊符号 长度8位">
							</u-input>
						</u-form-item>
						<u-form-item prop="password">
							<view class="redCircle"></view>
							<text class="itemText">确认密码</text>
							<u-input class="inputStyle" v-model="form.password" placeholder="请确认密码" />
						</u-form-item>
					</u--form>
				</view>
				<u-button @click="submit" shape="circle" color="linear-gradient(to top, #F59A02, #FFD334 )"
					class="buttonStyle mt33 commonMb buttonLang">确认修改</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		editPassword
	} from "@/api/company/my.js"
	export default {
		data() {
			return {
				form: {
					userName: '',
					oldPassword: '',
					newPassword: '',
					password: ''
				},
				rules: {
					oldPassword: [{
						required: true,
						message: '请设置登录密码',
						trigger: ['blur', 'change']
					}, ],
					newPassword: [{
						required: true,
						validator: (rule, value, callback) => {
							// let validationStr = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]+$/;
							// 大小写字母+特殊字符组合+八位
							// let validationStr = /^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[!#@*&.])[a-zA-Z!#@*&.]{8,8}.*$/;
							let validationStr = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[`~!@#$%^&*()_+<>?:"{},.\/\\;'[\]])[A-Za-z\d`~!@#$%^&*()_+<>?:"{},.\/\\;'[\]]{8,}$/;
							// console.log(validationStr.test(value), 'validationStr.test(value)');
							if (!validationStr.test(value) || value.length !== 8) {
								return false;
							} else {
								return true;
							}

						},
						message: '请设置大小写字母组合+特殊符号 长度8位',
						trigger: ['blur', 'change']
					}, ],
					password: [{
						required: true,
						validator: (rule, value, callback) => {
							// let validationStr = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]+$/;
							// 大小写字母+特殊字符组合+八位
							// let validationStr = /^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[!#@*&.])[a-zA-Z!#@*&.]{8,8}.*$/;
							let validationStr = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[`~!@#$%^&*()_+<>?:"{},.\/\\;'[\]])[A-Za-z\d`~!@#$%^&*()_+<>?:"{},.\/\\;'[\]]{8,}$/;
							// console.log(validationStr.test(value), 'validationStr.test(value)');
							if (!validationStr.test(value) || value.length !== 8) {
								return false;
							} else {
								return true;
							}

						},
						message: '请设置大小写字母组合+特殊符号 长度8位',
						trigger: ['blur', 'change']
					}, ],
					legal: [{
						required: true,
						message: '请输入企业法人姓名',
						trigger: ['blur', 'change']
					}, ],
				}
			}
		},
		methods: {
			submit() {
				// this.$tab.navigateBack()
				this.$refs.formRef.validate().then(res => {
					if (this.form.newPassword === this.form.password) {
						editPassword(this.form).then(() => {
							uni.showToast({
								title: '修改密码成功',
								icon: 'none'
							});
							this.form.oldPassword = null
							this.form.newPassword = null
							this.form.password = null
							this.$tab.reLaunch('/pages/home/index')
						})
					} else {
						uni.showToast({
							title: '两次输入的密码不一致',
							icon: 'none'
						})
					}

				})
			}
		},
		onLoad() {
			this.form.userName = this.$store.state.user.userName
		}
	}
</script>

<style scoped lang="scss">
	.avstarBack {
		background-image: url(@/static/images/editInfo/editpassword.png);
	}

	.relative {
		position: relative;
	}

	.absolute {
		position: absolute;
		bottom: 46rpx;
		width: 100%;
	}

	.choose-line-bottom {
		overflow: hidden;
		padding: 69rpx 39rpx 177rpx;
		box-sizing: border-box;
		// height: 644rpx;

		.small-box-middle {
			position: relative;
			margin-bottom: 27rpx;

			border: 1rpx solid #EBEBEB;
			border-radius: 20rpx;
			padding: 28rpx;
			box-sizing: border-box;

			.small-box-middle-startAndEnd {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				font-weight: bold;

				uni-text {
					margin-left: 22rpx;
				}
			}

			.small-box-middle-line {
				display: flex;
				justify-content: start;
				align-items: center;
				margin-left: 11rpx;

				.small-box-middle-line-left {
					width: 2rpx;
					height: 26rpx;
					background: #eeeeee;
					border-radius: 1rpx;
					margin: 6rpx 7rpx;
				}

				.small-box-middle-line-right {
					width: 439rpx;
					height: 1rpx;
					background: #eeeeee;
					margin-left: 15rpx;
				}
			}
		}
	}

	.mt33 {
		margin-top: 33rpx;
	}
	.pasStyle .input-placeholder {
		font-size: 24rpx !important;
	}
	
</style>
