<template>
  <div class="app-container">
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="80px"
      class="user-address"
    >
      <el-form-item label="姓名" prop="nickName">
        <el-input v-model="form.nickName"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="phonenumber">
        <el-input v-model="form.phonenumber"></el-input>
      </el-form-item>
      <el-form-item label="详细地址" prop="address">
        <el-input v-model="form.address" type="textarea" :rows="3"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSubmit()">提 交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getUserProfile, updateUserProfile } from "@/api/system/user.js";
export default {
  data() {
    return {
      form: {},
      rules: {
        nickName: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        phonenumber: [
          { required: true, message: "请输入手机号", trigger: "blur" },
        ],
        address: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    getUserInfo() {
      getUserProfile().then((res) => {
        this.form = res.data;
        console.log(this.form, res);
      });
    },
    handleSubmit() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          updateUserProfile(this.form).then(() => {
            this.$modal.msgSuccess("提交成功");
          });
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-address {
  padding: 30px 15px 0 15px;
  width: 500px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
</style>
