import { mapMutations, mapState } from 'vuex' import ApprovalComments from '@/views/matter/components/ApprovalComments' import LeaderDialog from '@/views/matter/components/LeaderDialog' import { getNextTaskByDefId, savaTaskComplete, canLock, getAfterJumpNodesByDefId, getNextExecutor, } from '@/api/process' import { getBpmSaveOpinionByTeam } from '@/api/flow' import request from '@/utils/request' import { ACTION_MAP, ADD_SIGN_ACTION_MAP, TASK_STATUS_ARRAY, CAN_LOCK_STATUS, TASK_STATUS_MESSAGE, } from '@/views/matter/components/const' import { Base64 } from 'js-base64' import { validObject } from '@/utils' import { getValueByPath, setValueByPath } from '@/utils/value.js' export default { components: { ApprovalComments, LeaderDialog, }, props: { name: { type: String, default: '', }, alias: { type: String, default: '', }, nodeType: { type: String, default: '', }, data: { type: Object, default: () => { return {} }, }, formKey: { type: String, default: '', }, formType: { type: String, default: '', }, disabled: { type: Boolean, default: false, }, btnSize: { type: String, default: 'small', }, opinionField: { type: String, default: '', }, appendOpinion: { type: Boolean, default: false, }, beforeClick: { type: Function, default: null, }, dialogBeforeClick: { type: Function, default: null, }, dialogAfterClick: { type: Function, default: null, }, approvalButtonList: { type: Array, default: () => [], }, isGetApprovalBtn: { type: Boolean, default: false, }, }, data() { return { approvalOpinion: '', //审批意见 opinionValue: '', //意见输入框中的值 dialogVisible: false, taskStatus: '', //任务是否锁定状态 isNewProcess: false, //是否新建流程 loading: false, fileList: '', addSignAction: '', signaturePassword: '', //签章密码 jumpNodes: {}, requestParams: {}, //启动或处理待办时发送到后台的参数 oldOpinion: {}, isDialog: false, } }, computed: { ...mapState('user', ['userId', 'username', 'account']), ...mapState('process', ['bpmTask', 'curNodeDef']), ...mapState('signature', ['signatureStatus']), ...mapState('routes', ['fullScreenState']), ...mapState('matter', [ 'currentShowDialogAlias', 'isFromApplicationModule', ]), ...mapState('settings', ['layout']), taskId() { return this.$route.query.taskId || this.bpmTask.id }, doneTaskId() { return this.$route.query.doneTaskId }, instId() { return this.$route.query.instId || this.bpmTask.procInstId }, leaderId() { return this.$route.query.leaderId || 0 }, isFree() { return this.$route.query.type === 'free' }, excludeStatus() { return !TASK_STATUS_ARRAY.includes(this.bpmTask.status) }, //自动签章字段 signatureField() { return this.getNodeProperties()?.signatureField }, // 签章是否免密 secretFree() { return this.getNodeProperties()?.secretFree }, //是否显示签章密码输入框 isShowSignature() { if (this.signatureField) { return !this.secretFree && this.alias === 'agree' } else { return false } // return this.signatureField && this.secretFree && this.alias === 'agree' }, isFromTaskManager() { return this.$route.query.isDefAuthorize }, }, watch: { dialogVisible(val) { if (val) { this.setCurrentShowDialogAlias(this.alias) } }, currentShowDialogAlias(val) { if (val && val !== this.alias) { this.handleClose('autoClose') } }, }, created() { this.$on('update:params', (params) => { Object.assign(this.requestParams, params || {}) }) this.isDialog = JSON.parse(localStorage.getItem('isDialog')) }, methods: { ...mapMutations('signature', [ 'setSignatureConfig', 'setSignatureStatus', 'initSignatureConfig', ]), ...mapMutations('matter', ['setCurrentShowDialogAlias']), //获取任务是否能锁定状态 getTaskIsLock(type) { this.$emit('update:disabled', true) const query = { taskId: this.taskId, leaderId: this.leaderId, } canLock(query, (res) => { if (res || res == '0') { this.taskStatus = CAN_LOCK_STATUS[res] if (['LockedBySomeone', 'hasHandle'].includes(CAN_LOCK_STATUS[res])) { this.$message.warning(TASK_STATUS_MESSAGE[CAN_LOCK_STATUS[res]]) if (this.isDialog) { this.$emit('close-dialog') } else { this.$tabs.close() } } else { if (type === 'agree') { this.openAgreeOrSelectPathJumpDialogBefore() } else if (type === 'savaDraft') { this.dialogVisible = true } } } else { this.$emit('update:disabled', false) } }) }, //7.设置审批意见 setApprovalOpinion(opinion) { this.approvalOpinion = opinion }, //获取意见输入框中的值 getOpinion(val) { this.opinionValue = val }, //10.配置了签章 handleSignature() { //修改签章配置前先初始化配置信息 this.initSignatureConfig() const { signatureCover, secretFree } = this.getNodeProperties() const signatureConfig = { field: this.signatureField, //自动签章字段 isCover: signatureCover, //自动签章时是否覆盖 secretFree: secretFree, //自动签章时是否免密 password: this.signaturePassword, } this.setSignatureConfig(signatureConfig) this.setSignatureStatus('start') }, getNodeProperties() { let currentNodeProperties = {} const nodeProperties = (this.curNodeDef || {}).nodeProperties if (nodeProperties && nodeProperties.length) { const { nodeProperties, localProperties } = this.curNodeDef currentNodeProperties = nodeProperties[0] || localProperties } return currentNodeProperties }, //用户任务加签设置action setAddSignAction() { if (this.nodeType === 'USERTASK' && this.bpmTask.parentId !== '0') { this.addSignAction = ADD_SIGN_ACTION_MAP[this.alias] } }, //判断打开同意审批弹窗或选择路径跳转弹窗 openAgreeOrSelectPathJumpDialogBefore() { if (this.taskStatus === 'LockedBySomeone') { return this.$message.warning(TASK_STATUS_MESSAGE[this.taskStatus]) } this.setAddSignAction() const { choiceExcutor, jumpType } = this.getNodeProperties() if ((choiceExcutor || jumpType || this.isFree) && this.excludeStatus) { const params = { defId: '', instId: '', type: this.$route.query.type || jumpType, } this.getAfterJumpNodes(params, this.openCurrentDialogByJumpNodes) } else { const isGetNextExecutor = this.alias === 'agree' && this.bpmTask.status === 'SIGNSEQUENCEED' isGetNextExecutor ? this.getSequenceSignNextExecutor() : this.openAgreeDialog() } }, openCurrentDialogByJumpNodes() { const onlyOneExecutor = this.jumpNodes.length === 1 && this.jumpNodes[0]?.excutorList?.length === 1 if (this.jumpNodes.length === 0 || onlyOneExecutor) { this.openAgreeDialog() } else { this.$refs.selectPathJump.openSelectPathJumpDialog(this.data) } }, //获取顺序签署下一步执行人 getSequenceSignNextExecutor() { getNextExecutor(this.taskId, (res) => { if (!res.data) return if (res.data.state && res.data.value) { this.$confirm( `下一步执行人为:${res.data?.value?.name},您确定要继续?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', } ) .then(() => { this.openAgreeDialog() }) .catch(() => {}) } }) }, //获取跳转节点 getAfterJumpNodes(params, callback) { const requestParams = { taskId: this.taskId || '', data: Base64.encode(JSON.stringify(this.data)), alias: this.alias, ...params, } getAfterJumpNodesByDefId(requestParams).then((res) => { this.jumpNodes = res this.selectConfig = res callback() }) }, //通过实例id和任务id获取审批意见 getApprovalOpinionByInstIdAndTaskId() { getBpmSaveOpinionByTeam(this.instId, this.taskId, ({ state, value }) => { const opinion = state && value ? value : ACTION_MAP[this.alias] this.setApprovalOpinion(opinion) }) }, // 审批意见前缀 添加节点名称和当前操作名称 getOpinionPre() { return `${this.bpmTask.name}:${this.name} ` }, //审批意见的后缀 getOpinionTail() { return ` 审核人:${this.username} 审核日期:${new Date().format( 'yyyy-MM-dd HH:mm:ss' )}` }, //设置审批意见回填 setOpinionWrap() { if (this.opinionField && this.opinionValue) { let opinion4Fill = null //是否覆盖审批意见 if (this.appendOpinion) { opinion4Fill = `${this.getOpinionPre()}审核意见:${ this.opinionValue }${this.getOpinionTail()}\n` } else { const oldVal = getValueByPath(this.data, this.opinionField) this.oldOpinion[this.opinionField] = oldVal let preVal = '' if (oldVal && oldVal.trim() != '