Browse Source

添加用户

gzb
guozhongbo 9 months ago
parent
commit
de8c7b3017
1 changed files with 238 additions and 3 deletions
  1. 238
    3
      src/views/schoolSection/userManage/userManage.vue

+ 238
- 3
src/views/schoolSection/userManage/userManage.vue View File

@@ -21,6 +21,7 @@
21 21
             :transfer="true"
22 22
             v-model="searchForm.care"
23 23
             style="width: 140px"
24
+            @on-change="searchList()"
24 25
           >
25 26
             <Option v-for="item in care_list" :value="item.id" :key="item.id">{{
26 27
               item.title
@@ -30,6 +31,7 @@
30 31
             :transfer="true"
31 32
             v-model="searchForm.enabled"
32 33
             style="width: 140px; margin: 0 10px"
34
+            @on-change="searchList()"
33 35
           >
34 36
             <Option
35 37
               v-for="item in enabled_list"
@@ -42,6 +44,7 @@
42 44
             :transfer="true"
43 45
             v-model="searchForm.control"
44 46
             style="width: 140px; margin-right: 10px"
47
+            @on-change="searchList()"
45 48
           >
46 49
             <Option
47 50
               v-for="item in control_list"
@@ -59,7 +62,7 @@
59 62
           />
60 63
         </div>
61 64
         <div>
62
-          <Button type="primary" class="primary_btn" @click="toAdd()"
65
+          <Button type="primary" class="primary_btn" @click="userExport()"
63 66
             >用户导入</Button
64 67
           >
65 68
           <Button
@@ -110,20 +113,139 @@
110 113
         ></Page>
111 114
       </div>
112 115
     </div>
116
+    <!-- 新建 -->
117
+    <Modal
118
+      class="modal1"
119
+      :mask-closable="false"
120
+      v-model="addInfo.show"
121
+      title="新建"
122
+    >
123
+      <Form
124
+        v-if="addInfo.show"
125
+        ref="addForm"
126
+        :model="addInfo"
127
+        :rules="rules"
128
+        :label-width="110"
129
+        inline
130
+      >
131
+        <FormItem label="姓名" prop="username" style="width: calc(50% - 10px)">
132
+          <Input v-model="addInfo.username" placeholder="请输入姓名"></Input>
133
+        </FormItem>
134
+        <FormItem label="性别" style="width: calc(50% - 10px)">
135
+          <RadioGroup v-model="addInfo.sex">
136
+            <Radio :label="1">男</Radio>
137
+            <Radio :label="2">女</Radio>
138
+            <Radio :label="0">未知</Radio>
139
+          </RadioGroup>
140
+        </FormItem>
141
+        <FormItem label="密码" prop="loginpwd" style="width: calc(50% - 10px)">
142
+          <Input v-model="addInfo.loginpwd" placeholder="请输入密码"></Input>
143
+        </FormItem>
144
+        <FormItem
145
+          label="确认密码"
146
+          prop="loginpwd1"
147
+          style="width: calc(50% - 10px)"
148
+        >
149
+          <Input
150
+            v-model="addInfo.loginpwd1"
151
+            placeholder="请输入确认密码"
152
+          ></Input>
153
+        </FormItem>
154
+        <FormItem label="登录名" prop="loginname" style="width: 100%">
155
+          <Input v-model="addInfo.loginname" placeholder="请输入登录名"></Input>
156
+        </FormItem>
157
+        <FormItem label="班级" class="require" style="width: 100%">
158
+          <Select
159
+            v-model="addInfo.classid"
160
+            placeholder="请选择班级"
161
+            style="width: 300px"
162
+            @on-change="classChange()"
163
+          >
164
+            <template v-if="schoolInfo.children.length > 0">
165
+              <Option
166
+                v-for="item in schoolInfo.children"
167
+                :value="item.id"
168
+                :key="item.id"
169
+                >{{ item.name }}</Option
170
+              >
171
+            </template>
172
+          </Select>
173
+        </FormItem>
174
+        <FormItem label="状态" style="width: 100%">
175
+          <RadioGroup v-model="addInfo.enabled">
176
+            <Radio :label="1">启用</Radio>
177
+            <Radio :label="2">禁用</Radio>
178
+          </RadioGroup>
179
+        </FormItem>
180
+        <FormItem label="学号" style="width: 100%">
181
+          <Input v-model="addInfo.studentno" placeholder="请输入学号"></Input>
182
+        </FormItem>
183
+        <FormItem label="手机号码" style="width: 100%">
184
+          <Input
185
+            v-model="addInfo.userphone"
186
+            placeholder="请输入手机号码"
187
+          ></Input>
188
+        </FormItem>
189
+        <FormItem label="身份证号码" style="width: 100%">
190
+          <Input
191
+            v-model="addInfo.cardid"
192
+            placeholder="请输入身份证号码"
193
+          ></Input>
194
+        </FormItem>
195
+      </Form>
196
+      <div
197
+        slot="footer"
198
+        style="
199
+          display: flex;
200
+          justify-content: space-between;
201
+          align-items: center;
202
+        "
203
+      >
204
+        <div style="color: #b50000">
205
+          注:密码必须包含大小写字母和数字的组合,长度在8-32之间。
206
+        </div>
207
+        <div>
208
+          <Button @click="addInfo.show = false">取消</Button>
209
+          <Button @click="saveAddInfo()" type="primary">保存</Button>
210
+        </div>
211
+      </div>
212
+    </Modal>
113 213
   </div>
114 214
 </template>
115 215
 
116 216
 <script>
117
-import { app_edit_enable, app_edit_unenable, app_list } from "@/api/appgroup";
118 217
 import {
119 218
   class_list,
120 219
   user_disabled,
121 220
   user_enable,
122 221
   user_list
123 222
 } from "@/api/school";
223
+import {user_add, user_edit} from "@/api/school";
224
+import {generateRandomString} from "@/utils";
124 225
 
125 226
 export default {
126 227
   data() {
228
+    const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,32}$/;
229
+    // 密码验证
230
+    const pwdCheck = (rule, value, callback) => {
231
+      console.log(value)
232
+      if (!reg.test(this.addInfo.loginpwd)) {
233
+        return callback(new Error("密码格式不正确!"));
234
+      }
235
+      console.log(this.addInfo.loginpwd)
236
+    };
237
+    // 重复密码验证
238
+    const pwdAgainCheck = async (rule, value, callback) => {
239
+      if (!reg.test(this.addInfo.loginpwd1)) {
240
+        return callback(new Error("确认密码不能为空!"));
241
+      }
242
+      if (!reg.test(this.addInfo.loginpwd1)) {
243
+        return callback(new Error("密码格式不正确!"));
244
+      }
245
+      if (this.addInfo.loginpwd != this.addInfo.loginpwd1) {
246
+        return callback(new Error("两次输入密码不一致!"));
247
+      }
248
+    };
127 249
     return {
128 250
       userInfo: {},
129 251
       showLoading: false,
@@ -143,6 +265,51 @@ export default {
143 265
         { id: 2, title: "解除管控" }
144 266
       ],
145 267
       curClass: 0,
268
+      addInfo: {
269
+        show: false,
270
+        userid: null,
271
+        username: "",
272
+        loginname: "",
273
+        loginpwd: "",
274
+        classid: "",
275
+        classname: "",
276
+        schoolid: null,
277
+        regionid: null,
278
+        enabled: 1,
279
+        studentno: "",
280
+        userphone: "",
281
+        cardid: ""
282
+      },
283
+      rules: {
284
+        username: [
285
+          {
286
+            required: true,
287
+            message: "请输入姓名",
288
+            trigger: "blur"
289
+          }
290
+        ],
291
+        loginname: [
292
+          {
293
+            required: true,
294
+            message: "请输入请输入登录名",
295
+            trigger: "blur"
296
+          }
297
+        ],
298
+        loginpwd: [
299
+          {
300
+            required: true,
301
+            validator: pwdCheck,
302
+            trigger: "blur"
303
+          }
304
+        ],
305
+        loginpwd1: [
306
+          {
307
+            required: true,
308
+            validator: pwdAgainCheck,
309
+            trigger: "blur"
310
+          }
311
+        ]
312
+      },
146 313
       searchForm: {
147 314
         page: 1,
148 315
         size: 10,
@@ -220,7 +387,75 @@ export default {
220 387
     this.searchList();
221 388
   },
222 389
   methods: {
223
-    toAdd(row) {},
390
+    classChange() {
391
+      if(this.schoolInfo.children.length === 0){
392
+        return;
393
+      }
394
+      let classInfo = this.schoolInfo.children.filter(v=>v.id === this.addInfo.classid)[0];
395
+      this.addInfo.classname = classInfo.name;
396
+    },
397
+    userImport() {},
398
+    userExport() {},
399
+    toAdd() {
400
+      this.addInfo = {
401
+        show: true,
402
+        userid: null,
403
+        sex: 1,
404
+        username: "",
405
+        loginname: "",
406
+        loginpwd: "",
407
+        classid: "",
408
+        classname: "",
409
+        schoolid: null,
410
+        regionid: null,
411
+        enabled: 1,
412
+        studentno: "",
413
+        userphone: "",
414
+        cardid: ""
415
+      };
416
+    },
417
+    saveAddInfo() {
418
+      console.log(this.addInfo);
419
+      this.$refs.addForm.validate((valid) => {
420
+        if (valid) {
421
+          console.log(this.addInfo.classid)
422
+           if(!this.addInfo.classid){
423
+             this.$Message.error("请选择班级!")
424
+             return
425
+           }
426
+          let form = {
427
+            username: this.addInfo.username,
428
+            loginname: this.addInfo.loginname,
429
+            loginpwd: this.addInfo.loginpwd,
430
+            classid: this.addInfo.classid,
431
+            classname: this.addInfo.classname,
432
+            schoolid: this.addInfo.schoolid,
433
+            regionid: this.addInfo.regionid,
434
+            enabled: this.addInfo.enabled,
435
+            studentno: this.addInfo.studentno,
436
+            userphone: this.addInfo.userphone,
437
+            cardid: this.addInfo.cardid
438
+          };
439
+          //编辑
440
+          // if (this.addInfo.appid) {
441
+          //   form.userid = this.addInfo.userid;
442
+          //   form.rversion = this.addInfo.rversion;
443
+          // }
444
+          console.log(form);
445
+          let api = this.addInfo.userid ? user_edit : user_add;
446
+          api(form).then((res) => {
447
+            if (res.code === 0) {
448
+              this.addInfo.show = false;
449
+              console.log(res.obj);
450
+              this.$Message.success(res.msg);
451
+              this.searchList();
452
+            } else {
453
+              this.$Message.error(res.msg);
454
+            }
455
+          });
456
+        }
457
+      });
458
+    },
224 459
     toCare(row) {},
225 460
     toDel(row) {},
226 461
     enabledChange(row) {

Loading…
Cancel
Save