<template>
  <el-form ref="pwdRef" :model="user" :rules="rules" label-width="80px" style="width: 400px;height: 260px;">
    <el-form-item label="账号昵称" prop="nickname">
      <el-input v-model="user.nickname" placeholder="请输入账号昵称" type="text"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit">保存</el-button>
      <!--      <el-button type="danger" @click="close">关闭</el-button>-->
    </el-form-item>
  </el-form>
</template>

<script setup>
import {updateUserProfile} from "@/api/system/user";

const {proxy} = getCurrentInstance();

const user = reactive({
  nickname: undefined,
});

const rules = ref({
  nickname: [{required: true, message: "账号昵称不能为空", trigger: "blur"}],
});

/** 提交按钮 */
function submit() {
  proxy.$refs.pwdRef.validate(valid => {
    if (valid) {
      updateUserProfile({nickname: user.nickname}).then(response => {
        proxy.$modal.msgSuccess("修改成功");
      });
    }
  });
};

/** 关闭按钮 */
function close() {
  proxy.$tab.closePage();
};
</script>
