xiangpei
2025-04-03 121761d95c65b31e27253f72c3f0d07987069015
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
<template>
  <div>
    <el-form label-width="80px" size="small">
      <el-form-item label="异步">
        <el-switch v-model="bpmnFormData.async" active-text="是" inactive-text="否" @change="updateElementTask('async')"/>
      </el-form-item>
      <el-form-item label="用户类型">
        <el-select v-model="bpmnFormData.userType" placeholder="用户类型" @change="updateUserType">
          <el-option
            v-for="item in userTypeOption"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
 
      <el-form-item label="指定人员" v-if="bpmnFormData.userType === 'assignee'">
        <el-input-tag v-model="bpmnFormData.assignee" :value="bpmnFormData.assignee"/>
        <el-button-group class="ml-4" style="margin-top: 4px">
          <!--指定人员-->
          <el-tooltip class="box-item" effect="dark" content="指定人员" placement="bottom">
            <el-button size="mini" type="primary" icon="el-icon-user" @click="singleUserCheck"/>
          </el-tooltip>
          <!--选择表达式-->
          <el-tooltip class="box-item" effect="dark" content="选择表达式" placement="bottom">
            <el-button size="mini" type="warning" icon="el-icon-postcard" @click="singleExpCheck"/>
          </el-tooltip>
        </el-button-group>
      </el-form-item>
 
      <el-form-item label="候选人员" v-else-if="bpmnFormData.userType === 'candidateUsers'">
        <el-input-tag v-model="bpmnFormData.candidateUsers" :value="bpmnFormData.candidateUsers"/>
        <el-button-group class="ml-4" style="margin-top: 4px">
          <!--候选人员-->
          <el-tooltip class="box-item" effect="dark" content="候选人员" placement="bottom">
            <el-button size="mini" type="primary" icon="el-icon-user" @click="multipleUserCheck"/>
          </el-tooltip>
          <!--选择表达式-->
          <el-tooltip class="box-item" effect="dark" content="选择表达式" placement="bottom">
            <el-button size="mini" type="warning" icon="el-icon-postcard" @click="singleExpCheck"/>
          </el-tooltip>
        </el-button-group>
      </el-form-item>
 
      <el-form-item label="候选角色" v-else-if="bpmnFormData.userType === 'candidateGroups'">
        <el-input-tag v-model="bpmnFormData.candidateGroups" :value="bpmnFormData.candidateGroups"/>
        <el-button-group class="ml-4" style="margin-top: 4px">
          <!--候选角色-->
          <el-tooltip class="box-item" effect="dark" content="候选角色" placement="bottom">
            <el-button size="mini" type="primary" icon="el-icon-user"  @click="multipleRoleCheck"/>
          </el-tooltip>
          <!--选择表达式-->
          <el-tooltip class="box-item" effect="dark" content="选择表达式" placement="bottom">
            <el-button size="mini" type="warning" icon="el-icon-postcard" @click="singleExpCheck"/>
          </el-tooltip>
        </el-button-group>
      </el-form-item>
 
      <el-form-item label="候选部门" v-else>
        <el-input-tag v-model="bpmnFormData.candidateGroups" :value="bpmnFormData.candidateGroups"/>
        <el-button-group class="ml-4" style="margin-top: 4px">
          <!--候选部门-->
          <el-tooltip class="box-item" effect="dark" content="候选部门" placement="bottom">
            <el-button size="mini" type="primary" icon="el-icon-user"  @click="deptVisible = true"/>
          </el-tooltip>
          <!--选择表达式-->
          <el-tooltip class="box-item" effect="dark" content="选择表达式" placement="bottom">
            <el-button size="mini" type="warning" icon="el-icon-postcard" @click="singleExpCheck"/>
          </el-tooltip>
        </el-button-group>
      </el-form-item>
 
      <el-form-item label="优先级">
        <el-input v-model="bpmnFormData.priority" @change="updateElementTask('priority')"/>
      </el-form-item>
      <el-form-item label="到期时间">
        <el-input v-model="bpmnFormData.dueDate" @change="updateElementTask('dueDate')"/>
      </el-form-item>
    </el-form>
 
    <!--选择人员-->
    <el-dialog
      title="选择人员"
      :visible.sync="userVisible"
      width="60%"
      :close-on-press-escape="false"
      :show-close="false"
    >
      <flow-user v-show="userVisible" ref="user" :checkType="checkType" :num="num" :selectValues="selectData.assignee || selectData.candidateUsers" @handleUserSelect="userSelect"></flow-user>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="userVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="checkUserComplete">确 定</el-button>
      </div>
    </el-dialog>
 
    <!--选择角色-->
    <el-dialog
      title="选择候选角色"
      :visible.sync="roleVisible"
      width="60%"
      :close-on-press-escape="false"
      :show-close="false"
    >
      <flow-role v-if="roleVisible" :selectValues="selectData.candidateGroups" @handleRoleSelect="roleSelect"></flow-role>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="roleVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="checkRoleComplete">确 定</el-button>
      </div>
    </el-dialog>
 
    <!--  选择部门  -->
    <flow-dept  ref="dept" :checkeds="selectData.candidateGroups" :show="deptVisible" @close="closeDept" @submit="submitDept"/>
 
    <!--选择表达式-->
    <el-dialog
      title="选择表达式"
      :visible.sync="expVisible"
      width="60%"
      :close-on-press-escape="false"
      :show-close="false"
    >
      <flow-exp :selectValues="selectData.exp" @handleSingleExpSelect="expSelect"></flow-exp>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="expVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="checkExpComplete">确 定</el-button>
      </div>
    </el-dialog>
 
 
  </div>
</template>
 
<script>
import FlowUser from '@/components/flow/User'
import FlowRole from '@/components/flow/Role'
import FlowExp from '@/components/flow/Expression'
import ElInputTag from '@/components/flow/ElInputTag'
import FlowDept from '@/components/flow/Dept'
import {StrUtil} from '@/utils/StrUtil'
 
 
 
export default {
  name: "TaskPanel",
  components: {
    FlowUser,
    FlowRole,
    FlowExp,
    ElInputTag,
    FlowDept
  },
  /** 组件传值  */
  props : {
    id: {
      type: String,
      required: true
    },
  },
  data() {
    return {
      num: 0, // 用于触发用户选择更新
      userVisible: false,
      roleVisible: false,
      expVisible: false,
      deptVisible: false,
      isIndeterminate: true,
      checkType: 'single', // 选类
      userType: '',
      userTypeOption: [
        {label: '指定人员', value: 'assignee'},
        {label: '候选人员', value: 'candidateUsers'},
        {label: '候选角色', value: 'candidateGroups'},
        {label: '候选部门', value: 'candidateDeptGroups'},
      ],
      checkAll: false,
      bpmnFormData: {
        userType: "candidateDeptGroups",
        assignee: "",
        candidateUsers: "",
        candidateGroups: "",
        dueDate: "",
        priority: "",
        dataType: "",
        expId: "",
      },
      // 数据回显
      selectData: {
        assignee: null,
        candidateUsers: null,
        candidateGroups: [],  // 角色
        candidateDeptGroups: [], // 部门
        exp: null,
      },
      otherExtensionList:[],
    }
  },
 
  /** 传值监听 */
  watch: {
    id: {
      handler(newVal) {
        if (StrUtil.isNotBlank(newVal)) {
          this.resetTaskForm();
        }
      },
      immediate: true, // 立即生效
    },
  },
  created() {
 
  },
  methods: {
    closeDept() {
      this.deptVisible = false
      this.selectData.candidateGroups = null
    },
 
    // 初始化表单
    resetTaskForm() {
      // 初始化设为空值
      this.bpmnFormData = {
        userType: "candidateDeptGroups",
        assignee: "",
        candidateUsers: "",
        candidateGroups: "",
        dueDate: "",
        priority: "",
        dataType: "",
        expId: "",
      }
      this.selectData = {
        assignee: null,
        candidateUsers: null,
        candidateGroups: null,
        exp: null,
      }
      // 流程节点信息上取值
      for (let key in this.bpmnFormData) {
        const value = this.modelerStore.element?.businessObject[key] || this.bpmnFormData[key];
        this.$set(this.bpmnFormData, key, value);
      }
      // 人员、角色、部门信息回显
      this.checkValuesEcho(this.bpmnFormData);
    },
 
    // 更新节点信息
    updateElementTask(key) {
      const taskAttr = Object.create(null);
      taskAttr[key] = this.bpmnFormData[key] || "";
      this.modelerStore.modeling.updateProperties(this.modelerStore.element, taskAttr);
    },
 
    // 更新自定义流程节点/参数信息
    updateCustomElement(key, value) {
      const taskAttr = Object.create(null);
      taskAttr[key] = value;
      this.modelerStore.modeling.updateProperties(this.modelerStore.element, taskAttr);
    },
 
    // 更新人员类型
    updateUserType(val) {
      console.log("worinim", val)
      // 删除xml中已选择数据类型节点
      this.deleteFlowAttar();
      // 清除已选人员数据
      if (val === "candidateDeptGroups") {
        this.bpmnFormData["candidateGroups"] = null;
      } else {
        this.bpmnFormData[val] = null;
      }
      this.selectData = {
        assignee: null,
        candidateUsers: null,
        candidateGroups: null,
        exp: null,
      }
      // 写入userType节点信息到xml
      this.updateCustomElement('userType', val);
    },
 
    // 设计器右侧表单数据回显
    checkValuesEcho(formData) {
      if (StrUtil.isNotBlank(formData.expId)) {
        this.getExpList(formData.expId, formData.userType);
      } else {
        console.log("我去", formData.userType)
        if ("candidateGroups" === formData.userType || "candidateDeptGroups" === formData.userType) {
          this.getRoleList(formData["candidateGroups"], "candidateGroups");
        } else {
          this.getUserList(formData[formData.userType], formData.userType);
        }
      }
    },
 
    // 获取表达式信息
    getExpList(val, key) {
      if (StrUtil.isNotBlank(val)) {
        this.bpmnFormData[key] = this.modelerStore.expList?.find(item => item.id.toString() === val).name;
        this.selectData.exp = this.modelerStore.expList?.find(item => item.id.toString() === val).id;
      }
    },
 
    // 获取人员信息
    getUserList(val, key) {
      if (StrUtil.isNotBlank(val)) {
 
 
        if ('assignee' === key) {
          console.log("这里开始报错,", this.modelerStore.userList)
          const uList = this.modelerStore.userList.filter(item => item.userId == val);
          this.bpmnFormData[key] = uList && uList.length > 0 ? uList[0].nickName : "人员不存在";
          this.selectData[key] = val;
        } else {
          const newArr = this.modelerStore.userList?.filter(i => val.split(',').includes(i.userId.toString()))
          console.log("指定人员", newArr)
          this.bpmnFormData[key] = newArr.map(item => item.nickName).join(',');
          this.selectData[key] = newArr.map(item => item.userId);
        }
        // if (this.$refs.user) {
        //   this.$refs.user.setChecked(this.selectData[key])
        // }
 
      }
    },
 
    // 获取角色信息
    getRoleList(val, key) {
      if (StrUtil.isNotBlank(val)) {
        // 根据id筛选出是角色还是部门
        const roleAndDeptIds = val.split(",");
        const deptIds = roleAndDeptIds.filter(item => item.includes("dept") || item === '${data_launch}');
        const roleIds = roleAndDeptIds.filter(item => !item.includes("dept"));
        // 谁有值就是谁
        if (roleIds && roleIds.length > 0) {
          const newArr = this.modelerStore.roleList?.filter(i => roleIds.includes(i.roleId.toString()))
          this.bpmnFormData[key] = newArr.map(item => item.roleName).join(',');
          if ('assignee' === key) {
            console.log("不会吧?")
            this.selectData[key] = newArr.find(item => item.roleId.toString() === val).roleId;
          } else {
            this.selectData[key] = newArr.map(item => item.roleId);
          }
        } else {
          console.log(deptIds, "部门IDs")
          const newArr = this.modelerStore.deptList?.filter(i => deptIds.includes(i.id))
          this.bpmnFormData[key] = newArr.map(item => item.label).join(',');
          if ('assignee' === key) {
            console.log("不会吧???")
            this.selectData[key] = newArr.find(item => item.id === val).id;
          } else {
            this.selectData[key] = newArr.map(item => item.id);
          }
          // this.$refs.dept.setCheckList(this.selectData[key])
        }
 
 
      }
    },
 
    // ------ 流程审批人员信息弹出框 start---------
 
    /*单选人员*/
    singleUserCheck() {
      this.num+=1
      this.userVisible = true;
      this.checkType = "single";
      // this.$nextTick(() => {
      //   console.log(typeof this.selectData.assignee, "类型")
      //   this.$refs.user.setChecked(this.selectData.assignee);
      // });
 
    },
 
    /*多选人员*/
    multipleUserCheck() {
      this.num = this.num + 1
      this.userVisible = true;
      this.checkType = "multiple";
    },
 
    /*单选角色*/
    singleRoleCheck() {
      this.roleVisible = true;
      this.checkType = "single";
    },
 
    /*多选角色*/
    multipleRoleCheck() {
      this.roleVisible = true;
    },
 
    /*单选表达式*/
    singleExpCheck() {
      this.expVisible = true;
    },
 
    // 表达式选中数据
    expSelect(selection) {
      if (selection) {
        this.deleteFlowAttar();
        this.bpmnFormData[this.bpmnFormData.userType] = selection.name;
        this.updateCustomElement('dataType', selection.dataType);
        this.updateCustomElement('expId', selection.id.toString());
        this.updateCustomElement(this.bpmnFormData.userType, selection.expression);
        this.handleSelectData("exp", selection.id);
      }
    },
 
    // 用户选中数据 TODO: 后面更改为 点击确认按钮再赋值人员信息
    userSelect(selection) {
      if (selection) {
        this.deleteFlowAttar();
        this.updateCustomElement('dataType', 'fixed');
        if (this.checkType === 'multiple') {
          const userIds = selection.map(item => item.userId);
          const nickName = selection.map(item => item.nickName);
          // userType = candidateUsers
          this.bpmnFormData[this.bpmnFormData.userType] = nickName.join(',');
          this.updateCustomElement(this.bpmnFormData.userType, userIds.join(','));
          this.handleSelectData(this.bpmnFormData.userType, userIds);
        } else {
          console.log(selection, "返回值")
          // userType = assignee
          this.bpmnFormData[this.bpmnFormData.userType] = selection.nickName;
          this.updateCustomElement(this.bpmnFormData.userType, selection.userId);
          this.handleSelectData(this.bpmnFormData.userType, selection.userId);
        }
      }
    },
 
    // 角色选中数据
    roleSelect(selection, name) {
      if (selection && name) {
        this.deleteFlowAttar();
        this.bpmnFormData[this.bpmnFormData.userType] = name;
        this.updateCustomElement('dataType', 'fixed');
        // userType = candidateGroups
        this.updateCustomElement(this.bpmnFormData.userType, selection);
        this.handleSelectData(this.bpmnFormData.userType, selection);
      }
    },
 
    // 部门选中数据
    submitDept(checkList, names) {
      this.deptVisible = false
      if (checkList && names) {
        this.deleteFlowAttar();
        this.bpmnFormData["candidateGroups"] = names;
        this.updateCustomElement('dataType', 'fixed');
        // userType = candidateGroups
        // 这里只能写死为:candidateGroups,因为flowable用户组的关键字就是它
        // this.updateCustomElement("candidateGroups", null); // 先清空再赋值,因为是一次性提交的部门数据,所以需要去重,直接赋值为null
        this.updateCustomElement("candidateGroups", checkList);
        this.handleSelectData("candidateGroups", checkList);
        console.log(checkList, "部门值")
      }
    },
 
    // 处理人员回显
    handleSelectData(key, value) {
      for (let oldKey in this.selectData) {
        if (key !== oldKey) {
          this.$set(this.selectData, oldKey, null);
        } else {
          this.$set(this.selectData, oldKey, value);
        }
      }
    },
 
    /*用户选中赋值*/
    checkUserComplete() {
      this.userVisible = false;
      this.checkType = "single";
    },
 
    /*候选角色选中赋值*/
    checkRoleComplete() {
      this.roleVisible = false;
    },
 
    /*表达式选中赋值*/
    checkExpComplete() {
      this.expVisible = false;
    },
 
    // 删除节点
    deleteFlowAttar() {
      delete this.modelerStore.element.businessObject[`dataType`]
      delete this.modelerStore.element.businessObject[`expId`]
      delete this.modelerStore.element.businessObject[`assignee`]
      delete this.modelerStore.element.businessObject[`candidateUsers`]
      delete this.modelerStore.element.businessObject[`candidateGroups`]
    },
 
    // 去重数据
    unique(arr, code) {
      const res = new Map();
      return arr.filter((item) => !res.has(item[code]) && res.set(item[code], 1));
    },
 
    // 更新扩展属性信息
    updateElementExtensions(properties) {
      const extensions = this.modelerStore.moddle.create("bpmn:ExtensionElements", {
        values: this.otherExtensionList.concat([properties])
      });
 
      this.modelerStore.modeling.updateProperties(this.modelerStore.element, {
        extensionElements: extensions
      });
    }
  }
}
</script>