odc.xiaohui
2023-02-09 085fa2fb257e9f11f8f6d34bf12e2dc281c36b4d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
<template>
  <div class="createUser">
    <main>
      <div class="mainContent">
        <el-form
          ref="user"
          label-width="140px"
          autoComplete="on"
          :model="depart"
          :rules="createDepartRules"
          label-position="right"
        >
          <!-- 部门名称 -->
          <el-form-item class="optionItem" label="部门名称:" prop="departName">
            <el-input
              v-model="depart.departName"
              placeholder="请输入部门名称"
            ></el-input>
          </el-form-item>
          <!-- 上级部门 -->
          <el-form-item class="optionItems" label="上级部门:" prop="parentId">
            <el-select ref="projectApplicant" v-model="depart.parentId" placeholder="请输入上级部门">
              <el-option  :value="mylabel">
                <el-tree
                  ref="tree"
                  :check-strictly="true"
                  :data="departList"
                  :props="defaultProps"
                  @node-click="handleCheck"
                  @check-change="handleCheck"
                  default-expand-all
                  node-key="id"
                >
                </el-tree>
              </el-option>
            </el-select>
          </el-form-item>
          <!-- 部门类型 -->
          <el-form-item class="optionItem" label="部门类型:" prop="departType">
            <el-select v-model="depart.departType" placeholder="请选择部门类型">
              <el-option
                v-for="item in departTypeList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <!--添加人员  -->
          <el-form-item class="optionItem add" label="添加人员:">
            <ul class="addPerson">
              <li
                v-for="(item, index) in checkedList"
                :key="index"
                @click="setLeader(index)"
              >
                <div class="li-item">
                  <div class="li-icon">
                    <i
                      :class="[
                        'el-icon-user-solid',
                        item.leader ? 'leader' : '',
                      ]"
                    ></i>
                  </div>
                  <label
                    style="font-size: 12px"
                    :class="[item.leader ? 'leader' : '']"
                    >{{ item.username }}</label
                  >
                </div>
              </li>
              <li class="li-btn">
                <i class="el-icon-plus" @click="openUser = true"></i>
              </li>
              <li class="li-btn">
                <el-tooltip class="item" effect="light" content="清除选中人员" placement="top" :enterable="false">
                  <i class="el-icon-minus" @click="clrarUser"></i>
                </el-tooltip>
 
              </li>
            </ul>
            <div class="card" v-if="openUser">
              <el-card class="box-card">
                <div slot="header" class="myclear">
                  <span>工作人员</span>
                  <div class="box-card-sub" @click="addUser">确认</div>
                </div>
                <div class="scrollWrap">
                  <el-checkbox-group v-model="checkedUser">
                    <el-checkbox
                      v-for="user in userList"
                      :label="user.id"
                      :key="user.id"
                    >
                      {{ user.username }}
                    </el-checkbox>
                  </el-checkbox-group>
                </div>
                <div class="hidebar"></div>
              </el-card>
            </div>
          </el-form-item>
          <el-form-item style="margin-top: -40px">
            <label style="color: #ff0000ab"
              >红色代表部门领导,点击头像可设置部门领导</label
            >
          </el-form-item>
          <!-- 部门描述 -->
          <el-form-item class="optionItem" label="部门描述:" prop="departDes">
            <el-input
              type="textarea"
              :rows="4"
              v-model="depart.departDes"
              placeholder="请输入部门描述"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
    </main>
    <footer>
      <div class="optionBtn">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" class="btn submit" @click="handleUser"
          >确定</el-button
        >
      </div>
    </footer>
  </div>
</template>
<script>
import { getTypeList } from "@/utils/helper";
export default {
  data() {
    const validateNickname = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请填写部门名称"));
      } else {
        callback();
      }
    };
    const validatePass = (rule, value, callback) => {
      if (!value) {
        callback();
      } else {
        callback();
      }
    };
    const validatePhone = (rule, value, callback) => {
      if (!value) {
        callback();
      } else {
        callback();
      }
    };
    return {
      depart: {
        departName: "",
        parentId: "",
        departType: "",
        departDes: "",
      },
      createDepartRules: {
        departName: [
          { required: true, trigger: "blur", validator: validateNickname },
        ],
        parentId: [
          { required: false, trigger: "blur", validator: validatePass },
        ],
        departType: [
          { required: false, trigger: "blur", validator: validatePhone },
        ],
        departDes: [{ required: false, trigger: "blur" }],
      },
      userList: [],
      departList: [],
      checkedUser: [],
      checkedList: [],
      openUser: false,
      departTypeList: [],
      selectOrg: {
        orgsid: [],
      },
      mylabel: "",
      defaultProps: {
        children: "children",
        label: "departName",
      },
    };
  },
  created() {
    const that = this;
    // 获取部门树形结构图
    this.getDepartTree();
    // 获取用户列表
    this.getUserList();
    // 获取部门类型列表
    this.getDepartTypeList();
  },
  methods: {
    handleUser() {
      this.$refs.user.validate((valid) => {
        if (valid) {
          const { depart, checkedList, selectOrg } = this;
          const arr = [];
          checkedList.forEach((item) => {
            arr.push({ leader: item.leader, userId: item.id });
          });
          console.log(arr);
          this.$axios({
            method: "post",
            url: "/sccg/depart/create",
            data: {
              departName: depart.departName,
              parentId: selectOrg.orgsid[0],
              departType: depart.departType,
              departDes: depart.departDes,
              departManagerList: arr,
            },
          }).then((res) => {
            if (res.code === 200) {
              this.$message({
                message: res.message,
                type: "success",
              });
              this.refresh();
            } else if (res.code === 2001) {
              this.$message({
                message: res.message,
                type: "error",
              });
              this.refresh();
            }
          });
        } else {
          return false;
        }
      });
    },
    // 获取部门树形结构图
    getDepartTree() {
      this.$axios({
        method: "get",
        url: "sccg/depart/tree",
      }).then((res) => {
        // console.log(res);
        // res.data.unshift({ id: 0, departName: "顶级菜单" });
        this.departList = res.data;
      });
    },
    // 获取所有用户信息
    getUserList() {
      // 获取所有用户信息、用户查询(暂时支持电话号码)
      this.$axios.get(`/sccg/depart/query_surplus_user`).then((res) => {
        if (res.code === 200) {
          this.userList = res.data;
        }
      });
    },
    addUser() {
      console.log(this.checkedUser);
      console.log(this.userList);
      this.checkedList = [];
      this.userList.forEach((item) => {
        this.checkedUser.forEach((child) => {
          if (item.id == child) {
            this.checkedList.push({
              id: item.id,
              username: item.username,
              leader: false,
            });
          }
        });
      });
      if (this.checkedList.length > 0) this.checkedList[0].leader = true;
      this.openUser = false;
    },
    // 清除选中用户
    clrarUser(){
      this.checkedUser=[]
    },
    handleClose() {
      this.$emit("changMyDialog", { flag: false });
    },
    // 获取部门类型
    async getDepartTypeList() {
      this.departTypeList = await getTypeList(1, "08");
    },
    handleCheck(data, checked) {
      if(checked.childNodes.length == 0){
        this.depart.parentId = data.departName;
        let _this = this;
        _this.$refs.projectApplicant.blur();
        this.selectOrg.orgsid = []
        this.selectOrg.orgsid.push(data.id)
      }else {
        return
      }
 
      // this.depart.parentId = data.departName;
      // // 获取当前选择的id在数组中的索引
      // const indexs = this.selectOrg.orgsid.indexOf(data.id);
      // // 如果不存在数组中,并且数组中已经有一个id并且checked为true的时候,代表不能再次选择。
      // if (indexs < 0 && this.selectOrg.orgsid.length === 1 && checked) {
      //   this.$message({
      //     message: "只能选择一个部门!",
      //     type: "warning",
      //     showClose: true,
      //   });
      //   // 设置已选择的节点为false 很重要
      //   this.$refs.tree.setChecked(data, false);
      // } else if (this.selectOrg.orgsid.length === 0 && checked) {
      //   // 发现数组为空 并且是已选择
      //   // 防止数组有值,首先清空,再push
      //   this.selectOrg.orgsid = [];
      //   this.selectOrg.orgsid.push(data.id);
      // } else if (
      //   indexs >= 0 &&
      //   this.selectOrg.orgsid.length === 1 &&
      //   !checked
      // ) {
      //   // 再次直接进行赋值为空操作
      //   this.selectOrg.orgsid = [];
      //   this.depart.parentId = "";
      // }
    },
    // 设置领导
    setLeader(idx) {
      this.checkedList.forEach((item, index) => {
        item.leader = index === idx;
      });
    },
  },
  props: ["refresh", "changMyDialog"],
};
</script>
<style lang="scss" scoped>
.createUser {
  border-radius: 1px;
  // background-color: #09152f;
 
  main {
    text-align: left;
    padding: 0 55px;
    // background-color: #09152f;
    padding-bottom: 50px;
 
    .mainContent {
      display: flex;
      justify-content: center;
      padding-top: 50px;
 
      // &::v-deep .el-form-item__label {
      //   color: #4b9bb7;
      // }
 
      // &::v-deep .el-input__inner {
      //   background-color: #09152f;
      //   border: 1px solid #17324c;
      // }
 
      // &::v-deep .el-textarea__inner {
      //   background-color: #09152f;
      //   border: 1px solid #17324c;
      // }
 
      .addPerson {
        display: flex;
        list-style: none;
        padding: 0;
        flex-wrap: wrap;
        max-width: 280px;
        li {
          color: #fff;
          text-align: center;
          font-size: 30px;
          margin-left: 10px;
        }
      }
      .li-icon {
        background-color: #cccccc;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        margin: 0 auto;
      }
      .li-btn {
        background-color: #cccccc;
        width: 36px;
        height: 36px;
        border-radius: 50%;
       .el-icon-plus{
         cursor: pointer;
       }
        .el-icon-minus{
          cursor: pointer;
        }
      }
      .el-form-item__content {
        width: 400px;
 
        .el-select {
          width: 100%;
        }
      }
 
      .optionHandleSp {
        display: flex;
 
        .areaNumber,
        .moreNumber {
          flex: 1;
        }
 
        .telNumber {
          flex: 2;
        }
      }
    }
 
    .add {
      position: relative;
 
      .card {
        position: absolute;
        z-index: 2000;
        right: 0;
 
        .box-card {
          min-height: 240px;
          max-height: 260px;
          overflow: hidden;
          // background-color: #09152f;
          position: relative;
          max-width: 220px;
 
          .scrollWrap {
            overflow: scroll;
            height: 180px;
            position: relative;
            // color: #4b9bb7;
 
            .el-checkbox-group {
              display: flex;
              flex-direction: column;
 
              .el-checkbox {
                line-height: 20px;
              }
            }
          }
 
          .myclear {
            width: 100%;
            line-height: 20px;
            // color: #4b9bb7;
            display: flex;
            justify-content: space-between;
            .box-card-sub{
              color: #2f54eb;
              margin-left: 5px;
              cursor: pointer;
            }
          }
 
          .hidebar {
            position: absolute;
            top: 77px;
            right: 20px;
            width: 20px;
            height: 180px;
            // background-color: #09152f;
          }
 
          .item {
            line-height: 40px;
          }
        }
      }
    }
  }
 
  .li-item {
    display: flex;
    flex-direction: column;
  }
 
  .leader {
    color: red;
  }
  .el-input {
    width: 280px !important;
  }
  footer {
    border-top: 1px solid #fff;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 20px;
  }
}
</style>