<!-- 修改密码 -->
<template>
	<div class='passwordChange'>
		<el-dialog title="" :show-close="false" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true" :visible.sync="dialogPasswordVisible">
			<div slot="title" class="header-title">
				<span class="dialogHeader">修改密码</span>
				<img @click="closeDialog('passwordForm')" class="dialogHeaderClose" src="../assets/images/modal-gb.png" />
			</div>
			<div>
				<el-row>
					<el-col :span="12">
						<div style="text-align: center;">
							<img height="354" src="../assets/images/imgs/big-lock.png"/>
						</div>
					</el-col>
					<el-col :span="12">
						<div style="margin-top: 50px;">
							<el-form :hide-required-asterisk="true" :model="passwordForm" :rules="rules" ref="passwordForm" label-width="100px" class="demo-ruleForm">
								<el-form-item label="当前密码" prop="old">
									<el-input v-model="passwordForm.old" placeholder="请输入当前密码"></el-input>
								</el-form-item>
								<el-form-item label="新密码" prop="new">
									<el-input v-model="passwordForm.new" placeholder="请输入新密码"></el-input>
								</el-form-item>
								<el-form-item label="确认密码" prop="confirm">
									<el-input v-model="passwordForm.confirm" placeholder="请输入确认密码"></el-input>
								</el-form-item>
							</el-form>
						</div>
					</el-col>
				</el-row>
			</div>
			<div style="text-align: center;margin-top: 40px;">
				<el-button type="primary" @click="passwordSubmit('passwordForm')">确定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
	//例如：import 《组件名称》 from '《组件路径》';

	export default {
		name: "passwordChange",
//import引入的组件需要注入到对象中才能使用
		components: {},
		data () {
//这里存放数据
			return {
				dialogPasswordVisible: false,
				passwordForm:{
					new: '',
					old: '',
					confirm: ''
				},
				rules: {
					new: [
						{ required: true, message: '请输入新密码', trigger: 'blur' },
					],
					old: [
						{ required: true, message: '请输入当前密码', trigger: 'blur' },
					],
					confirm: [
						{ required: true, message: '请输入确认密码', trigger: 'blur' },
					],
				},
				closeDialog(val) {
					console.log(val)
					this.$refs[val].resetFields();
					this.$emit('close', false);
				},
			};
		},
		props: {
			showPasswordDialog: { type: Boolean, default: false },
		},
//监听属性 类似于data概念
		computed: {},
//监控data中的数据变化
		watch: {
			showPasswordDialog:{
				immediate: true,
				handler(showPasswordDialog) {
					// console.log(showPasswordDialog)
					this.dialogPasswordVisible = showPasswordDialog;
				}
			},
		},
//方法集合
		methods: {
			passwordSubmit(val) {
				this.$refs[val].validate((valid) => {
					if (valid) {
						alert('submit!');
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			}
		},
//生命周期 - 创建完成（可以访问当前this实例）
		created () {

		},
//生命周期 - 挂载完成（可以访问DOM元素）
		mounted () {

		},
		beforeCreate () {
		}, //生命周期 - 创建之前
		beforeMount () {
		}, //生命周期 - 挂载之前
		beforeUpdate () {
		}, //生命周期 - 更新之前
		updated () {
		}, //生命周期 - 更新之后
		beforeDestroy () {
		}, //生命周期 - 销毁之前
		destroyed () {
		}, //生命周期 - 销毁完成
		activated () {
		}, //如果页面有keep-alive缓存功能，这个函数会触发
	}
</script>
<style scoped>
	.header-title{
		text-align: center;
		font-size: 26px;
		position: relative;
		height: 30px;
	}
	.dialogHeaderClose{
		position: absolute;
		top: -10px;
		right: 0px;
		cursor: pointer;
	}
</style>
