<template>
  <el-form>
    <el-form-item label="原密码">
      <el-input v-model.trim="dataForm.oldPassword" type="password" />
    </el-form-item>
    <el-form-item label="新密码">
      <el-input v-model.trim="dataForm.newPassword" type="password" />
    </el-form-item>
    <el-form-item label="确认密码">
      <el-input v-model.trim="dataForm.confirmPassword"  type="password"/>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submit">修改密码</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import {changeUserPassword} from "@/api/admin"
export default {
  data(){
    return{
      dataForm:{
        oldPassword:'',
        newPassword:'',
        confirmPassword:'',
      }
    }
  },
  methods: {
    submit() {
       let _this=this;
       if(_this.dataForm.oldPassword==''){
         _this.$alert("请填写原密码");
         return;
       }
       if(_this.dataForm.newPassword==''){
         _this.$alert("请填写新密码");
         return;
       }
       if(_this.dataForm.confirmPassword==''){
         _this.$alert("请填写确认密码");
         return;
       }
       if(_this.dataForm.newPassword!=_this.dataForm.confirmPassword){
         _this.$alert("两次填写的密码不相同");
         return;
       }
       changeUserPassword(this.dataForm).then(res=>{
         if(res.status!=200){
           _this.$message(res.message);return;
         }
         _this.$message("用户密码修改成功")
       })
    }
  }
}
</script>
