<template>
  <el-dialog
      title="修改密码"
      :visible.sync="editor.showChangePwd"
      width="35%">

    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
      <el-form-item label="原密码" prop="password">
        <el-input show-password style="width: 80%" v-model="ruleForm.password" placeholder="请输入原密码"></el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="passwordNew">
        <el-input show-password style="width: 80%" v-model="ruleForm.passwordNew" placeholder="请输入新密码" ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
      </el-form-item>
    </el-form>

  </el-dialog>
</template>

<script>
import {mapActions, mapState} from "vuex";

export default {
  name: "FpChangePwd",
  computed: {
    ...mapState({
      'editor': state => state.editor
    })
  },
  data() {
    return {
      ruleForm: {
        password: '',
        passwordNew: ''
      },
      rules: {
        password: [
          {required: true, message: '请输入原密码', trigger: 'blur'},
          { min: 3, max: 32, message: '长度在 3 到 32 个字符', trigger: 'blur' }
        ],
        passwordNew: [
          {required: true, message: '请输入新密码', trigger: 'blur'},
          { min: 3, max: 32, message: '长度在 3 到 32 个字符', trigger: 'blur' }
        ],
      }
    }
  },
  methods: {
    ...mapActions({
      'changepwd': 'editor/changepwd',
    }),
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.changepwd(this.ruleForm).then(r => {
            this.$message.success('操作成功')
            this.editor.showChangePwd = false
          })
        }
      });
      return false;
    }
  }
}
</script>

<style scoped>

</style>