zhiyong.zhou
2024-02-26 60d911172b1dbebe0ab952ce10366b327d5744f1
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
<template>
  <div>
    <div class="el-row" style="margin-left: -10px; margin-right: -10px">
      <div
        class="el-col el-col-15"
        style="
          padding-left: 10px;
          padding-right: 10px;
          border-right: 1px solid rgb(232, 232, 232);
        "
      >
        <form-render
          class="process-form"
          ref="form"
          :forms="forms"
          v-model="formData"
        />
      </div>
      <div
        class="el-col el-col-9"
        style="padding-left: 10px; padding-right: 10px"
      >
        <div>
          <el-timeline>
            <el-timeline-item
              v-for="(activity, index) in cc"
              :key="index"
              :icon="activity.icon"
              size="large"
              class="task"
            >
              <div
                class="process-node-render"
                v-if="!activity.hasOwnProperty('options')"
              >
                <div>
                  <div style="font-size: 16px">{{ activity.title }}</div>
                  <span style="color: rgb(168, 173, 175)">{{
                    activity.desc
                  }}</span>
                </div>
                <div style="display: flex">
                  <div
                    class="avatar show-y"
                    v-for="(user, index) in activity.users"
                    :key="index"
                  >
                    <div class="a-img">
                      <el-avatar
                        style="height: 38px; width: 38px; line-height: 38px"
                        :src="user.avatar"
                      ></el-avatar>
                      <i
                        class="close el-icon-close"
                        v-if="activity.isEdit"
                        @click="delUser(activity.users, user)"
                      ></i>
                      <i class="status" style="display: none"></i>
                    </div>
                    <span class="name line">{{ user.name }}</span>
                  </div>
                  <span
                    class="add-user"
                    v-if="
                      activity.isEdit &&
                      (activity.multiple || 0 === activity.users.length)
                    "
                    @click="addUser(activity)"
                    ><i class="el-icon-plus"></i>
                    <div>添加</div></span
                  >
                </div>
              </div>
              <el-radio-group v-model="activity.id" size="mini" v-else>
                <el-radio-button
                  :label="d.title"
                  :value="d.id"
                  v-for="(d, index) in activity.options"
                  :key="index"
                ></el-radio-button>
              </el-radio-group>
            </el-timeline-item>
          </el-timeline>
        </div>
        <org-picker
          :type="this.selectedNode.type || 'user'"
          :multiple="this.selectedNode.multiple || !1"
          ref="orgPicker"
          :selected="this.selectedNode.users || []"
          @ok="selected"
        ></org-picker>
      </div>
    </div>
    <div></div>
  </div>
</template>
 
<script>
import FormRender from "@/views/common/form/FormRender";
import { getFormDetailV2 } from "@/api/design";
import OrgPicker from "@/components/common/OrgPicker";
import {flatFormItem} from "@/views/workspace/form";
 
export default {
  name: "SponsorProcess",
  components: { FormRender, OrgPicker },
  props: {
    code: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      loading: false,
      formData: {},
      select: [],
      selectedNode: {},
      processUsers: {},
      form: {
        formId: "",
        formName: "",
        logo: {},
        formItems: [],
        process: {},
        remark: "",
      },
      loginUser: {},
      conditionFormItem: new Set(),
      activities: [],
      cc: [],
    };
  },
  mounted() {
    this.loadLoginUser();
    this.loadFormInfo(this.code);
  },
  watch: {
    // 被侦听的变量count
    formData: {
      // 对对象进行深度监听
      handler(nv) {
        this.startProcess(nv, (this.cc = []));
      },
      immediate: true,
      deep: true,
    },
  },
  computed: {
    forms() {
      return this.$store.state.design.formItems;
    },
    _value: {
      get: function () {
        return this.value;
      },
      set: function (e) {
        this.$emit("input", e);
      },
    },
  },
  methods: {
    loadLoginUser() {
      this.loginUser = JSON.parse(sessionStorage.getItem("user"));
    },
    loadFormInfo(formId) {
      this.loading = true;
      getFormDetailV2(formId)
        .then((rsp) => {
          this.loading = false;
          let form = rsp.data.result;
          form.logo = JSON.parse(form.logo);
          form.settings = JSON.parse(form.settings);
          form.process = JSON.parse(form.process);
          const perms = form.process.props.formPerms || [];
          // 表单项 从json转换为数组 用于渲染表单 扁平化处理 去除了spanLayout
          const formItems = flatFormItem(JSON.parse(form.formItems));
          // item显示状态映射关系
          const itemStatusMap = new Map(perms.map((it) => [it.id, it.perm]));
          const items = formItems
              .map((item) => {
                // perm说明 只读R  编辑E  隐藏H
                const perm = itemStatusMap.get(item.id);
                if (perm === "E") {
                  return item;
                } else if (perm === "R") {
                  item.props.readerMode = true;
                  return item;
                } else if (perm === "H") {
                  return undefined;
                }
              })
              .filter(Boolean);
          form.formItems = items;
 
          this.form = form;
          //构建表单及校验规则
          this.$store.state.design = form;
          this.startProcess(form.process, this.formData);
        })
        .catch((err) => {
          this.loading = false;
          this.$message.error(err);
        });
    },
    validate(call) {
      this.$refs.form.validate(call);
    },
    getFormData() {
      return this.formData;
    },
    getProcessUser() {
      return this.processUsers;
    },
    getForm() {
      return this.form;
    },
    addUser(e) {
      (this.selectedNode = e), this.$refs.orgPicker.show();
    },
    delUser(e, t) {
      e.splice(t, 1);
      this.processUsers = e;
    },
    startProcess() {
      this.cc = [];
      this.getProcess(this.form.process, this.activities, this.cc);
 
      this.cc.push({
        title: "结束",
        name: "END",
        icon: "el-icon-success",
        isEdit: false,
      });
    },
    selected(e) {
      var t = this;
      t.processUsers[t.selectedNode.id] = [];
 
      e.forEach((user) => {
        var ddd = t.selectedNode.users.findIndex((t) => {
          return t.id === user.id;
        });
        if (ddd === -1) {
          t.selectedNode.users.push(user);
          t.processUsers[t.selectedNode.id].push(user);
          t.$set(e, "isEdit", true);
        }
      });
    },
    getProcess(process, data, cc) {
      if (null != process && undefined != process) {
        if ("ROOT" === process.type) {
          //发起人节点
          this.getRootNode(cc, process);
        } else if ("APPROVAL" === process.type) {
          //审批节点
          this.getApprovalNode(cc, process);
        } else if ("CC" === process.type) {
          this.getCcNode(cc, process);
        } else if ("CONDITIONS" === process.type) {
          //判断是否符合条件符合走条件分支,否则继续递归子分支
          if (null != process.branchs && undefined != process.branchs) {
            this.getConditionNode(cc, process);
          }
        } else if ("CONCURRENTS" === process.type) {
          this.getConcurrentNode(cc, process);
        }
        if (null != process.children && undefined != process.children) {
          this.getProcess(process.children, data, cc);
        }
      }
    },
    //封装开始节点
    getRootNode(cc, process) {
      cc.push({
        id: process.id,
        title: process.name,
        name: "发起人",
        icon: "el-icon-user-solid",
        isEdit: false,
        users: [this.loginUser],
      });
    },
    //封装审批节点
    getApprovalNode(cc, process) {
      var data = {
        id: process.id,
        title: process.name,
        name: "审批人",
        icon: "el-icon-s-check",
        isEdit: false,
        multiple: false,
        mode: process.props.mode,
        users: [],
        desc: "",
      };
      //判断审批人类型
      switch (process.props.assignedType) {
        case "ASSIGN_USER":
          data.users = this.$deepCopy(process.props.assignedUser);
          data.desc = "指定审批人";
          break;
        case "ASSIGN_LEADER":
          data.desc = "指定部门的领导";
          break;
        case "SELF":
          data.users = [this.loginUser];
          data.desc = "发起人自己审批";
          break;
        case "SELF_SELECT":
          data.isEdit = true;
          data.multiple = process.props.selfSelect.multiple || false;
          data.desc = "自选审批人";
          break;
        case "LEADER_TOP":
          data.desc = "连续多级主管审批";
          break;
        case "LEADER":
          data.desc =
            1 === process.props.leader.level
              ? "直接主管审批"
              : "第".concat(process.props.leader.level, "级主管审批");
          break;
        case "ROLE":
          data.desc = "由角色[".concat(
            (process.props.role || []).map(function (e) {
              return e.name;
            }),
            "]审批"
          );
          break;
        case "REFUSE":
          data.desc = "流程此处将被自动驳回";
          break;
      }
      cc.push(data);
    },
    getCcNode(cc, process) {
      var data = {
        id: process.id,
        title: process.name,
        icon: "el-icon-s-promotion",
        name: "抄送人",
        isEdit: process.props.shouldAdd,
        type: "org",
        multiple: true,
        desc: process.props.shouldAdd ? "可添加抄送人" : "",
        users: this.$deepCopy(process.props.assignedUser),
      };
      cc.push(data);
    },
    getConditionNode(cc, process) {
      for (var r = null, s = 0; s < process.branchs.length; s++) {
        for (
          var a = process.branchs[s], n = false, o = 0, i = 0;
          i < a.props.groups.length;
          i++
        ) {
          if (
            ((n = this.getConditionResultByGroup(a.props.groups[i])),
            "OR" === a.props.groupsType && n)
          ) {
            r = a;
            break;
          }
          "AND" === a.props.groupsType && n && o++;
        }
 
        if (r) {
          break;
        }
        if (o === a.props.groups.length) {
          r = a;
          break;
        }
      }
      var d = [];
      console.log(
        "符合分支条件,继续执行递归,获取符合条件下节点下的子节点!" +
          JSON.stringify(r)
      );
      r
        ? this.getProcess(r, d, cc)
        : console.log(
            "条件节点 "
              .concat(process.id, " => ")
              .concat(process.name, " 均不满足,无法继续"),
            process
          );
    },
    getConcurrentNode(cc, process) {
      var data = {
        id: process.id,
        title: process.name,
        name: "并行分支",
        icon: "el-icon-s-operation",
        isEdit: false,
        active: process.branchs[0].id,
        options: [],
        desc: "切换分支可显示对应执行流程",
        branchs: {},
      };
      cc.push(data);
      process.branchs.forEach((b) => {
        data.options.push({ id: b.id, title: b.name });
        this.$set(data.branchs, b.id, []);
        var d = [];
        this.getProcess(b.children, d, data.branchs[b.id]);
      });
    },
    getConditionResultByGroup: function (e) {
      var t = this,
        r = !1,
        s = 0;
      e.conditions.forEach(function (e) {
        return t.conditionFormItem.add(e.id);
      });
 
      for (var a = 0; a < e.conditions.length; a++) {
        var n = e.conditions[a];
        switch (n.valueType) {
          case "Number":
            console.log("这是number类型判断");
            r = this.numberCompare(n);
            break;
          case "String":
            console.log("这是string类型判断");
            break;
          case "Date":
            console.log("这是data类型判断");
 
            break;
          case "User":
            console.log("这是user类型判断");
 
            break;
          case "Array":
            console.log("这是array类型判断");
 
            break;
        }
        if (r && "OR" === e.groupType) break;
        r && "AND" === e.groupType && s++;
      }
      return "AND" === e.groupType && (r = s === e.conditions.length), r;
    },
    numberCompare: function (e) {
      var t = this.formData[e.id];
      switch (e.compare) {
        case ">":
          return t > parseFloat(e.value[0]);
        case "<":
          return t < parseFloat(e.value[0]);
        case "=":
          return t === parseFloat(e.value[0]);
        case ">=":
          return t >= parseFloat(e.value[0]);
        case "<=":
          return t <= parseFloat(e.value[0]);
        case "B":
          return t > parseFloat(e.value[0]) && t < parseFloat(e.value[1]);
        case "AB":
          return t >= parseFloat(e.value[0]) && t < parseFloat(e.value[1]);
        case "BA":
          return t > parseFloat(e.value[0]) && t <= parseFloat(e.value[1]);
        case "ABA":
          return t >= parseFloat(e.value[0]) && t <= parseFloat(e.value[1]);
        case "IN":
          return e.value.indexOf(String(t)) > -1;
        default:
          return !1;
      }
    },
  },
};
</script>
 
<style lang="less" scoped>
.process-form {
  /deep/ .el-form-item__label {
    padding: 0 0;
  }
}
 
.task {
  height: 60px;
}
 
.el-timeline-item .el-timeline-item__content .process-node-render > div {
  position: absolute;
  display: inline-block;
}
 
.el-timeline-item
  .el-timeline-item__content
  .process-node-render
  > div:last-child {
  right: 0;
  top: -10px;
}
 
.avatar {
  display: flex;
  flex-direction: row;
  position: relative;
  align-items: center;
}
 
.show-y {
  justify-content: center;
  flex-direction: column !important;
}
 
.show-y,
.w-h-center {
  display: flex;
  align-items: center;
}
 
.avatar .a-img {
  display: flex;
  border-radius: 50%;
  flex-direction: column;
  justify-content: center;
  background: #fff;
  position: relative;
}
 
.close {
  position: absolute;
  top: 0;
  right: 0;
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  background: #000;
}
 
.status {
  position: absolute;
  bottom: -4px;
  right: -8px;
  border-radius: 50%;
  font-size: 15px;
  background: #fff;
  border: 2px solid #fff;
}
 
.avatar .name {
  text-align: center;
  color: #19191a;
  font-size: 14px;
  margin-left: 10px;
}
 
.show-y .name {
  margin-left: 0 !important;
}
 
.line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
 
.add-user {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
 
.add-user i {
  padding: 10px;
  font-size: 1.1rem;
  border-radius: 50%;
  border: 1px dashed #8c8c8c;
  cursor: pointer;
}
 
.el-timeline-item .el-timeline-item__icon {
  color: #babcc1;
  font-size: 16px;
}
 
.border .el-dialog__header {
  border-bottom: 1px solid #e8e8e8;
}
</style>