<template>
  <div class="info-page">
    <div class="title">个人信息管理</div>
    <el-form
      ref="form"
      class="form-box"
      :model="form"
      label-width="80px"
      placeholder="请输入名称"
    >
      <el-form-item label="名称">
        <el-input v-model="form.name" placeholder="请输入名称"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input
          type="password"
          placeholder="请输入密码"
          v-model="form.password"
        ></el-input>
      </el-form-item>
      <el-form-item label="性别">
        <el-select v-model="form.sex" placeholder="请选择性别">
          <el-option label="保密" value="other"></el-option>
          <el-option label="男" value="man"></el-option>
          <el-option label="女" value="woman"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="form.mobile" placeholder="请输入电话"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button>取消</el-button>
        <el-button type="primary" @click="onSubmit">立即更新</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { updateUserInfo } from "../../../../api/index";
export default {
  name: "info",
  props: {
    userInfo: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      form: {
        name: "",
        sex: "",
        mobile: "",
      },
    };
  },
  mounted() {
    this.pageInit();
  },
  methods: {
    pageInit() {
      if (this.userInfo?.id) {
        this.form.name = this.userInfo.name;
        this.form.sex = this.userInfo.sex;
        this.form.mobile = this.userInfo.mobile;
      }
    },
    async onSubmit() {
      const res = await updateUserInfo({
        userId: this.userInfo?.id,
        ...this.form,
      });
      console.log(res);
    },
  },
};
</script>
<style lang="less" scoped>
.info-page {
  //margin-left: 0;
  //width: 100vw;
  background-color: #f8f9fb;
  padding: 24px;
  .title {
    text-align: left;
    margin-bottom: 24px;
  }
  //margin-top: 350px;
  .form-box {
    //margin-left: 24px;
    width: 500px;
  }
}
</style>
