<template>
  <div class="personal-info">
    <el-form ref="form" label-width="80px">
      <el-form-item label="账号" v-if="userInfo && userInfo.name">
        {{ userInfo.username }}
      </el-form-item>
      <el-form-item label="手机号" v-if="userInfo && userInfo.phone">
        {{ userInfo.phone }}</el-form-item
      >
      <!-- <el-form-item>
        <el-button @click="editInfo">修改个人信息</el-button>
        <el-button @click="editPassword">修改密码</el-button>
      </el-form-item> -->
    </el-form>
    <el-dialog
      title="修改个人信息"
      :visible.sync="dialogFormVisible"
      width="400px"
    >
      <el-form
        :model="infoData"
        v-if="isEditBasicInfo"
        label-position="right"
        label-width="80px"
      >
        <el-form-item label="昵称">
          <el-input v-model="infoData.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="infoData.email" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="infoData.phone" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <el-form
        :model="pwdData"
        v-else
        label-position="right"
        label-width="80px"
      >
        <el-form-item label="旧密码">
          <el-input v-model="pwdData.oldPwd" type="password"></el-input>
        </el-form-item>
        <el-form-item label="新密码">
          <el-input v-model="pwdData.newPwd" type="password"></el-input>
        </el-form-item>
        <el-form-item label="重复密码">
          <el-input v-model="pwdData.repeatPwd" type="password"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "Info",
  data() {
    return {
      dialogFormVisible: false,
      infoData: {
        name: "",
        email: "",
        phone: "",
      },
      pwdData: {
        oldPwd: "",
        newPwd: "",
        repeatPwd: "",
      },
      isEditBasicInfo: true,
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  methods: {
    editInfo() {
      this.dialogFormVisible = true;
      this.isEditBasicInfo = true;
    },
    editPassword() {
      this.dialogFormVisible = true;
      this.isEditBasicInfo = false;
    },
  },
};
</script>
<style lang="scss" scoped>
.el-input {
  width: 80%;
}
</style>