春风项目四线(合箱线、总装线)
wujian
2024-01-18 b395c6c17048f4862dd07e54fdb2122905402794
提交 | 用户 | 时间
fd2207 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="phonenumber">
7       <el-input v-model="form.phonenumber" 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
25 <script>
26 import { updateUserProfile } from "@/api/system/user";
27
28 export default {
29   props: {
30     user: {
31       type: Object
32     }
33   },
34   data() {
35     return {
36       form: {},
37       // 表单校验
38       rules: {
39         nickName: [
40           { required: true, message: "用户昵称不能为空", trigger: "blur" }
41         ],
42         email: [
43           { required: true, message: "邮箱地址不能为空", trigger: "blur" },
44           {
45             type: "email",
46             message: "请输入正确的邮箱地址",
47             trigger: ["blur", "change"]
48           }
49         ],
50         phonenumber: [
51           { required: true, message: "手机号码不能为空", trigger: "blur" },
52           {
53             pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
54             message: "请输入正确的手机号码",
55             trigger: "blur"
56           }
57         ]
58       }
59     };
60   },
61   watch: {
62     user: {
63       handler(user) {
64         if (user) {
65           this.form = { nickName: user.nickName, phonenumber: user.phonenumber, email: user.email, sex: user.sex };
66         }
67       },
68       immediate: true
69     }
70   },
71   methods: {
72     submit() {
73       this.$refs["form"].validate(valid => {
74         if (valid) {
75           updateUserProfile(this.form).then(response => {
76             this.$modal.msgSuccess("修改成功");
77             this.user.phonenumber = this.form.phonenumber;
78             this.user.email = this.form.email;
79           });
80         }
81       });
82     },
83     close() {
84       this.$tab.closePage();
85     }
86   }
87 };
88 </script>