<template>
  <el-dialog v-model="visible" width="400" title="修改密码" class="password-dialog"
    @closed="emit('update:modelValue', false)">
    <el-form :model="formData" status-icon :rules="rules" ref="ruleFormRef" class="demo-ruleForm">
      <!-- <el-form-item label="" prop="username">
      <el-input type="username" v-model.trim="formData.username" autocomplete="off" placeholder="请输入账号">
        <template #prefix>
          <i class="icon-username"></i>
        </template>
</el-input>
</el-form-item> -->
      <el-form-item label="旧密码" prop="oldPassword">
        <el-input type="text" v-model.trim="formData.oldPassword" placeholder="请输入旧密码">
          <template #prefix><el-icon>
              <Lock />
            </el-icon></template>
        </el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="newPassword">
        <el-input type="password" v-model.trim="formData.newPassword" placeholder="请输入新密码">
          <template #prefix><el-icon>
              <Lock />
            </el-icon></template>
        </el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="reNewPassword">
        <el-input type="password" v-model.trim="formData.reNewPassword" placeholder="请再次输入新密码">
          <template #prefix><el-icon>
              <Lock />
            </el-icon></template>
        </el-input>
      </el-form-item>

      <!-- <el-form-item label="" prop="captcha" class="captcha">
      <el-input class="input-captcha" v-model.trim="formData.captcha" placeholder="请输入验证码"></el-input>
      <img src="@/assets/images/组11拷贝2x.png" alt="验证码" />
    </el-form-item> -->
      <el-form-item>
        <footer class="form-footer">
          <el-button @click="onCancel"><span>取消</span></el-button>
          <el-button type="primary" @click="onSubmit" class="submit"><span>提交</span></el-button>
        </footer>
        <!-- <div class="other clearfix">
        <span class="forgot-password">忘记密码？</span>
        <span class="sign-up">立即注册</span>
        <span class="no-account">还没账号？</span>
      </div> -->
      </el-form-item>
    </el-form>
  </el-dialog>

</template>


<script setup>
import { ref, watch } from 'vue'

let visible = ref(true)
const ruleFormRef = ref()
let formData = ref({
  oldPassword: "",
  newPassword: "",
  reNewPassword: ""
})
const props = defineProps({ show: Boolean })
const emit = defineEmits(['update:modelValue'])
const validatePass = (rule, value, callback) => {
  if (value !== formData.value.newPassword) {
    callback(new Error('输入的密码不同'))
  } else {
    callback()
  }
}
const rules = {
  username: [{ required: true, message: "账号是必填", trigger: ["change", "blur"] }],
  oldPassword: [{ required: true, message: "必填", trigger: ["change", "blur"] }],
  newPassword: [{ required: true, message: "必填", trigger: ["change", "blur"] }],
  reNewPassword: [{ required: true, message: "必填", trigger: ["change", "blur"] },
  { validator: validatePass, trigger: ["blur", "change"] }
  ],
};
watch(() => props.show, (newVal) => {
  visible.value = newVal
})
function onCancel() {
  emit('update:modelValue', false)
}
function onSubmit() {
  ruleFormRef.value.validate((valid) => {
    if (valid) {

    }
  })
}
</script>


<style scoped lang="less">
.form-footer {
  text-align: right;
  margin-left: auto;
}
</style>