userInfo.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  3. <el-form-item label="用户昵称" prop="nickName">
  4. <el-input v-model="form.nickName" maxlength="30" />
  5. </el-form-item>
  6. <el-form-item label="手机号码" prop="mobile">
  7. <el-input v-model="form.mobile" maxlength="11" />
  8. </el-form-item>
  9. <el-form-item label="邮箱" prop="email">
  10. <el-input v-model="form.email" maxlength="50" />
  11. </el-form-item>
  12. <el-form-item label="性别">
  13. <el-radio-group v-model="form.sex">
  14. <el-radio label="0">男</el-radio>
  15. <el-radio label="1">女</el-radio>
  16. </el-radio-group>
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  20. <el-button type="danger" size="mini" @click="close">关闭</el-button>
  21. </el-form-item>
  22. </el-form>
  23. </template>
  24. <script>
  25. import { updateUserProfile } from "@/api/system/user";
  26. export default {
  27. props: {
  28. user: {
  29. type: Object
  30. }
  31. },
  32. data() {
  33. return {
  34. form: {},
  35. // 表单校验
  36. rules: {
  37. nickName: [
  38. { required: true, message: "用户昵称不能为空", trigger: "blur" }
  39. ],
  40. email: [
  41. { required: true, message: "邮箱地址不能为空", trigger: "blur" },
  42. {
  43. type: "email",
  44. message: "请输入正确的邮箱地址",
  45. trigger: ["blur", "change"]
  46. }
  47. ],
  48. mobile: [
  49. { required: true, message: "手机号码不能为空", trigger: "blur" },
  50. {
  51. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  52. message: "请输入正确的手机号码",
  53. trigger: "blur"
  54. }
  55. ]
  56. }
  57. };
  58. },
  59. watch: {
  60. user: {
  61. handler(user) {
  62. if (user) {
  63. this.form = { id:user.id, nickName: user.nickName, mobile: user.mobile, email: user.email, sex: user.sex };
  64. }
  65. },
  66. immediate: true
  67. }
  68. },
  69. methods: {
  70. submit() {
  71. this.$refs["form"].validate(valid => {
  72. if (valid) {
  73. updateUserProfile(this.form).then(response => {
  74. this.$modal.msgSuccess("修改成功");
  75. this.user.mobile = this.form.mobile;
  76. this.user.email = this.form.email;
  77. });
  78. }
  79. });
  80. },
  81. close() {
  82. this.$tab.closePage();
  83. }
  84. }
  85. };
  86. </script>