approvalOpinion.js
2.87 KB
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
import { getBpmSaveOpinionByTeam } from '@/api/flow'
import { mapState } from 'vuex'
const ALIAS_MAP = {
agree: '同意',
agreeTrans: '同意',
oppose: '反对',
opposeTrans: '反对',
}
import { getValueByPath, setValueByPath } from '@/utils/value.js'
export default {
data() {
return {
oldOpinion: {},
}
},
computed: {
...mapState('login', ['currentUser']),
userName() {
return this.currentUser.username
},
allButtonMap() {
return this.approvalButtonList?.reduce((pre, cur) => {
pre[cur.alias] = cur.name
return pre
}, {}) || {}
},
nodeProps() {
const { nodeProperties, localProperties } = this.curNodeDef
if (nodeProperties && nodeProperties.length) {
return nodeProperties[0] || localProperties || {}
}
return {}
},
opinionField() {
return this.nodeProps.opinionField || ''
},
appendOpinion() {
return this.nodeProps.appendOpinion || false
}
},
methods: {
//通过实例id和任务id获取审批意见
getApprovalOpinionByInstIdAndTaskId() {
getBpmSaveOpinionByTeam(this.instId, this.taskId, ({ state, value }) => {
const opinion = state && value ? value : ALIAS_MAP[this.alias]
this.setApprovalOpinion(opinion)
})
},
//设置审批意见
setApprovalOpinion(opinion) {
if (opinion) {
this.form.opinion = opinion
}
},
// 审批意见前缀 添加节点名称和当前操作名称
getOpinionPre() {
return `${this.bpmTask.name}:${this.allButtonMap[this.currentAlias]} `
},
//审批意见的后缀
getOpinionTail() {
return ` 审核人:${this.userName} 审核日期:${new Date().format(
'yyyy-MM-dd HH:mm:ss'
)}`
},
//设置审批意见回填
setOpinionWrap() {
if (this.opinionField && this.approvalDialogData.opinion) {
let opinion4Fill = null
//是否覆盖审批意见
if (this.appendOpinion) {
opinion4Fill = `${this.getOpinionPre()}审核意见:${this.approvalDialogData.opinion
}${this.getOpinionTail()}\n`
} else {
const oldVal = getValueByPath(this.data, this.opinionField)
this.oldOpinion[this.opinionField] = oldVal
let preVal = ''
if (oldVal && oldVal.trim() != '<p><br/></p>') {
preVal = `${oldVal}\n `
}
if (preVal && preVal.indexOf('\n') == -1) {
opinion4Fill = `${this.getOpinionPre()}审核意见:${preVal}${this.approvalDialogData.opinion
}${this.getOpinionTail()}\n`
} else {
opinion4Fill = `${preVal} ${this.getOpinionPre()}审核意见:${this.approvalDialogData.opinion
}${this.getOpinionTail()}\n`
}
}
setValueByPath(this.data, this.opinionField, opinion4Fill)
}
},
},
}