Blame view

src/views/system/information/password-edit.vue 2.83 KB
xiaomiao committed
1
<template>
xiaomiao committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  <div class="informationpassword">
    <el-form
      ref="form"
      label-width="100px"
      :model="form"
      class="form-wrapper"
      :rules="rules">
      <el-form-item label="旧密码:" prop="oldPassword">
        <el-input
          v-model="form.oldPassword"
          clearable
          type="password"
          show-password />
      </el-form-item>
      <el-form-item label="新密码:" prop="newPassword">
        <el-input
          v-model="form.newPassword"
          clearable
          type="password"
          show-password />
      </el-form-item>
      <el-form-item label="确认密码:" prop="confirmPassword">
        <el-input
          v-model="form.confirmPassword"
          clearable
          type="password"
          show-password />
      </el-form-item>
    </el-form>
    <div class="bottom-wrapper">
      <btn nativeType="cx" type="primary" @click="updatePassword">确认修改</btn>
xiaomiao committed
33 34 35 36 37
    </div>
  </div>
</template>

<script>
38 39 40 41 42 43
  import { updateUserPassword } from "@/api/personnelManage";
  export default {
    props: {
      userInfo: {
        type: Object,
        default: null,
44
      },
xiaomiao committed
45
    },
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    data () {
      return {
        form: {},
        sexList: [],
        userId: "",
        rules: {
          oldPassword: [
            { required: true, message: "旧密码不能为空", trigger: "blur" },
          ],
          newPassword: [
            { required: true, message: "新密码不能为空", trigger: "blur" },
          ],
          confirmPassword: [
            { required: true, message: "确认密码不能为空", trigger: "blur" },
            { validator: this.validatorConfirmPassword, trigger: "blur" },
          ],
        },
      };
xiaomiao committed
64
    },
65 66 67 68 69 70 71 72 73 74 75 76 77
    computed: {},
    watch: {
      userInfo: {
        handler: function (val) {
          if (val) {
            this.getid(val);
          }
        },
      },
    },
    mounted () {
      if (this.userInfo) {
        this.getid(this.userInfo);
xiaomiao committed
78
      }
xiaomiao committed
79
    },
80 81 82 83 84 85 86 87 88 89
    methods: {
      getid (val) {
        this.userId = val.id;
      },
      validatorConfirmPassword (rule, value, callback) {
        const { newPassword } = this.form;
        if (value !== newPassword) {
          callback("两次输入密码不一致");
        } else {
          callback();
xiaomiao committed
90
        }
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
      },
      updatePassword () {
        this.$refs.form.validate((valid) => {
          if (valid) {
            const params = Object.assign({}, this.form, { id: this.userId });
            updateUserPassword(params).then((res) => {
              if (res.status === 1) {
                this.$message.success({ message: res.message, showClose: true });
              } else {
                this.$message.error({ message: res.message, showClose: true });
              }
            });
          }
        });
      },
106
    },
107
  };
xiaomiao committed
108 109 110 111
</script>

<style scoped lang="scss">
</style>