<template>
  <div>
    <div class="title">修改基本信息</div>
    <el-form ref="form" :model="form" label-width="130px" :rules="rules">
      <el-form-item label="用户名:" prop="userName">
        <el-input v-model="form.userName" disabled />
      </el-form-item>
      <el-form-item label="电话号码:" prop="phone">
        <el-input v-model="form.phone" />
      </el-form-item>
      <el-form-item label="邮箱:">
        <el-input v-model="form.email" />
      </el-form-item>
    </el-form>
    <div class="btn">
      <el-button type="primary" @click="confirm">确认修改</el-button>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { rules } from '../../const'
import { updateInfo } from '../../api'
export default {
  data() {
    let { deptId, email, phone, userId, userName } = this.$store.state.user.userBaseInfo
    return {
      form: {
        deptId: deptId,
        email: email,
        phone:  phone,
        userId: userId,
        userName: userName
      },
      rules
    }
  },
  computed: {
    ...mapGetters('depart', ['departList']),
  },
  methods: {
    confirm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          updateInfo(this.form).then(res => {
            this.$message.success('操作成功');
          })
        } else {
          return false;
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.btn {
  margin-top: 50px;
  text-align: center;
}
.title {
  width: 100%;
  height: 60px;
  background: rgba(226, 235, 255, 0.39);
  line-height: 60px;
  font-size: 18px;
  color: #333;
  font-weight: 500;
  text-align: center;
  margin-bottom: 30px;
}
.el-form {
  width: 500px;
  margin: 0 auto;
}
</style>
