agreeButton.js 8.26 KB
//同意审批按钮时用户任务加签
const ADD_SIGN_ACTION_MAP = {
  oppose: 'opposeTrans',
  agree: 'agreeTrans',
}
//任务状态
const TASK_STATUS_ARRAY = [
  'APPROVELINEING',
  'APPROVELINEED',
  'SIGNSEQUENCEING',
  'SIGNSEQUENCEED',
  'SIGNLINEING',
  'SIGNLINEED',
]

import {
  getAfterJumpNodesByDefId,
  getNextExecutor,
} from '@/api/process'

import { validObject } from '@/utils'
import { mapMutations, mapState } from 'vuex'
export default {
  data() {
    return {
      jumpNodes: {},
      selectConfig: {},
      isShowSelectPath: false,
      jumpType: ''
    }
  },
  computed: {
    ...mapState('signature', ['signatureStatus']),
    //自动签章字段
    signatureField() {
      return this.getNodeProperties()?.signatureField
    },
    // 签章是否免密
    secretFree() {
      return this.getNodeProperties()?.secretFree
    },
    //是否显示签章密码输入框
    isShowSignature() {
      if (this.signatureField) {
        return !this.secretFree && this.currentAlias === 'agree'
      } else {
        return false
      }
    },
    isFree() {
      return this.$route.query.type === 'free'
    },
    excludeStatus() {
      return !TASK_STATUS_ARRAY.includes(this.bpmTask.status)
    },
  },
  methods: {
    ...mapMutations('signature', [
      'setSignatureConfig',
      'setSignatureStatus',
      'initSignatureConfig',
    ]),
    //配置了签章
    handleSignature() {
      //修改签章配置前先初始化配置信息
      this.initSignatureConfig()
      const { signatureCover, secretFree } = this.getNodeProperties()
      const signatureConfig = {
        field: this.signatureField, //自动签章字段
        isCover: signatureCover, //自动签章时是否覆盖
        secretFree: secretFree, //自动签章时是否免密
        password: this.form.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.curNodeDef.type === 'USERTASK' && this.bpmTask.parentId !== '0') {
        this.addSignAction = ADD_SIGN_ACTION_MAP[this.currentAlias]
      }
    },
    //选择路径跳转
    selectPathJumpDialogBefore() {
      this.getApprovalOpinionByInstIdAndTaskId()
      this.setAddSignAction()
      const { choiceExcutor, jumpType } = this.getNodeProperties()
      this.jumpType = jumpType
      if ((choiceExcutor || jumpType || this.isFree) && this.excludeStatus) {
        const params = {
          defId: this.bpmTask.procDefId,
          instId: this.instId,
          type: jumpType || '',
        }
        this.getAfterJumpNodes(params)
      } else {
        const isGetNextExecutor =
          this.currentAlias === 'agree' && this.bpmTask.status === 'SIGNSEQUENCEED'
        isGetNextExecutor
          ? this.getSequenceSignNextExecutor() : this.showApprovalAction = true

      }
    },

    openCurrentDialogByJumpNodes() {
      this.showApprovalAction = true
      if (this.isFree) {
        this.jumpType = 'free'
      }
      this.setSelectConfigVal()
      if (this.jumpType === 'free' && this.selectConfig.choiceExcutor === 'free') {
        const data = {
          selectNodeId: '',
          selectNodeName: '',
          nodeUsers: this.getNodeUserList() || []
        }
        this.getCurrentSelected(data)
      }
    },
    //获取顺序签署下一步执行人
    getSequenceSignNextExecutor() {
      getNextExecutor(this.taskId, (res) => {
        if (!res.data) return
        if (res.data.state && res.data.value) {
          this.$dialog.confirm(
            `下一步执行人为:${res.data?.value?.name},您确定要继续?`,
            '提示',
            {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            }
          )
            .then(() => {
              this.showApprovalAction = true
            })
            .catch(() => {
              this.showApprovalAction = false
            })
        }
      })
    },
    //获取跳转节点
    getAfterJumpNodes(params) {
      const requestParams = {
        taskId: this.taskId || '',
        alias: this.currentAlias,
        data: Base64.encode(JSON.stringify(this.data)),
        ...params,
      }
      getAfterJumpNodesByDefId(requestParams).then((res) => {
        this.jumpNodes = res
        this.selectConfig = res
        this.nodeList = res?.afterNodes
        this.openCurrentDialogByJumpNodes()
      })
    },
    setSelectConfigVal() {
      if (this.isFree) {
        this.selectConfig = {
          ...this.selectConfig,
          jumpType: this.jumpType,
          choiceExcutor: this.jumpType,
        }
        this.nodeList = this.selectConfig.afterNodes
      }
      const { afterNodes } = this.selectConfig
      if (afterNodes?.length === 1) {
        this.form.selectNodeId = afterNodes[0].nodeId
        this.selectNodeName = afterNodes[0].nodeName
      }
      // 如果是自由选择,默认带出候选人,然后在再基于候选人进行调整(删减或增加)
      if (
        afterNodes?.length > 0 &&
        this.selectConfig.choiceExcutor &&
        this.selectConfig.choiceExcutor != 'candidate'
      ) {
        this.selectConfig.afterNodes = afterNodes.map((item) => {
          return {
            ...item,
            selectUsers: this.getValueByKey(item.excutorList, 'name'),
            id: this.getValueByKey(item.excutorList, 'id'),
          }
        })

        this.nodeList = this.selectConfig.afterNodes
      }
    },
    getValueByKey(array, key) {
      let value = ''
      if (array && array.length > 0) {
        value = array.map((it) => it[key]).join(',')
      }
      return value
    },
    //审批同意,选择路径跳转 自由跳转,提交参数
    getSubmitData() {
      let data = {
        formType: this.data?.businessKey ? 'frame' : 'inner',
        defId: this.bpmTask.procDefId || this.startParams.defId,
        proInstId: this.instId || '',
        agentLeaderId: this.leaderId || 0,
        isSendNodeUsers: '1',
        destination: this.form.selectNodeId || '',
        ...this.getEffectiveValue(),

      }
      if (this.jumpType) {
        data.jumpType = this.jumpType === 'select' ? 'select' : 'free'
      }
      return data
    },
    getEffectiveValue() {
      const data = {
        urgentStateValue: this.$storage.get('urgentStateValue'),
        nodeUsers: JSON.stringify(this.getNodeUserList()) || this.selectedNodeAndUser?.nodeUsers,
        startOrgId: '',//TODO:获取组织id
      }
      return validObject(data)
    },
    getNodeUserList() {
      let nodeUsers = []
      if (this.selectConfig?.choiceExcutor === 'candidate') {
        nodeUsers = this.getCandidateList()
      } else {
        nodeUsers = this.getNodeUsers()
      }
      return nodeUsers.length > 0 ? nodeUsers : []
    },
    getCandidateList() {
      let candidateList = []
      this.selectConfig?.afterNodes?.map((item) => {
        if (item.selectUserIds?.length > 0) {
          const excutorList = item.excutorList
          const selectUsers = excutorList?.filter((it) => {
            return item.selectUserIds.includes(it.id)
          })
          candidateList.push({ nodeId: item.nodeId, executors: selectUsers })
        }
      })
      return candidateList
    },
    getNodeUsers() {
      let nodeUsers = []
      this.selectConfig?.afterNodes?.map((node) => {
        const currentSelectedUserList = node.selectUsers?.split(',')
        const selectedUserIds = node.id?.split(',')
        if (currentSelectedUserList?.length > 0) {
          const selectUsers = currentSelectedUserList?.map((user, index) => {
            return {
              id: selectedUserIds[index],
              name: user,
              type: 'user',
            }
          })?.filter(it => it.id)
          if (selectUsers && selectUsers.length) {
            nodeUsers.push({ nodeId: node.nodeId, executors: selectUsers })
          }
        }
      })
      return nodeUsers
    },
  }
}