<template>
  <el-form v-loading="saveLoading">
    <el-form-item label="Name">
      <el-input v-model.trim="cuser.lastname" />
    </el-form-item>
    <el-form-item label="Email">
      <el-input v-model.trim="cuser.email" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit">保 存</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import request from "@/core/utils/request";
export default {
  props: {
    user: {
      type: Object
    }
  },
  data() {
    return {
      cuser: JSON.parse(JSON.stringify(this.user)),
      saveLoading: false
    };
  },
  methods: {
    submit() {
      const _self = this;
      _self.saveLoading = true;
      request({
        url: "/sys/user/update",
        method: "post",
        data: this.cuser
      }).then(res => {
        _self.saveLoading = false;
        if (res.data.code === 0) {
          _self.saveLoading = false;
          _self.$message({
            message: "保存成功",
            type: "success"
          });
          _self.$store.dispatch('user/getInfo');
        }
      });
    }
  }
};
</script>
