reject.js 7.5 KB
import { getRejectTaskParams } from '@/api/process'
import {
  REJECT_METHOD_OPTIONS,
} from '@/views/matter/components/const'
const REJECT_TYPE_MAP = {
  backToStart: 'isShowRejectSponsor',
  rejectPre: 'isShowRejectPreStep',
  reject: 'isShowRejectNode',
}
const OPTIONS = [
  { key: 'normal', value: '重新审批' },
  { key: 'direct', value: '回到本节点' },
]
export default {
  data() {
    return {
      rejectInfo: {},
      parentTaskId: '',//用户加签后的父任务id
      isSameNode: true,
      canRejectNode: [],
      rejectMethodName: '',
      nodeName: '',
      isSelectNode: false,
      rejectMethodOptions: REJECT_METHOD_OPTIONS
    }
  },
  computed: {
    isShowSelect() {
      return (
        this.rejectInfo.canRejectToAnyNode && this.form.rejectMethod === 'reject'
      )
    },
    isShowRejectSponsor() {
      const { canRejectToStart, inSubProcess } = this.rejectInfo
      return (
        canRejectToStart &&
        (this.form.rejectRecallMode === 'normal' || !inSubProcess)
      )
    },
    isShowRejectPreStep() {
      const { afterGateway, inGateway, canRejectPreAct, inSubProcess } =
        this.rejectInfo
      return canRejectPreAct && !afterGateway && !inGateway && !inSubProcess
    },
    isShowRejectNode() {
      const { canRejectToAnyNode, inSubProcess } = this.rejectInfo
      return (
        canRejectToAnyNode &&
        (!inSubProcess || this.form.rejectRecallMode !== 'normal')
      )
    },
    backNode() {
      const { nodeProperties } = this.curNodeDef
      return nodeProperties.length > 0 ? nodeProperties[0].backNode : ''
    },
    // 允许的驳回重提模式
    permitRejectRecallMode() {
      return this.rejectInfo.rejectRecallMode?.split(',') || []
    },
    // 驳回重提模式选项
    rejectRecallModeOptions() {
      return OPTIONS.filter(
        (m) => this.permitRejectRecallMode.indexOf(m.key) > -1
      )
    },
    rejectPreName() {
      if (
        this.form.rejectRecallMode == 'normal' &&
        this.rejectInfo.allowNormalNode.length > 0
      ) {
        return this.rejectInfo.allowNormalNode[0].name
      }
      if (
        this.form.rejectRecallMode == 'direct' &&
        this.rejectInfo.allowDirectNode.length > 0
      ) {
        return this.rejectInfo.allowDirectNode[0].name
      }
      return '不支持'
    },
    rejectMethodMap() {
      return REJECT_METHOD_OPTIONS.reduce((pre, cur) => {
        pre[cur.key] = cur.name
        return pre
      }, {})
    },
    destinationNodeId() {
      //根据用户所选的驳回策略,计算目标节点id。从而判断目标节点是不是会签,需不需要显示选择驳回会签处理人的下拉
      let nodeId = ''
      // 驳回发起人时的节点id, 取可驳回节点的最后一个
      if (
        this.form.rejectMethod == 'backToStart' &&
        this.canRejectNode.length > 0
      ) {
        nodeId = this.canRejectNode[this.canRejectNode.length - 1].nodeId
        // 驳回上一步的节点id, 取可驳回节点的第一个
      } else if (
        this.form.rejectMethod == 'rejectPre' &&
        this.canRejectNode.length > 0
      ) {
        nodeId = this.canRejectNode[0].nodeId
        // 驳回指定节点的驳回节点id,就是用户所选的
      } else if (this.form.rejectMethod == 'reject') {
        nodeId = this.form.nodeId
      }
      return nodeId
    },
  },
  methods: {
    //驳回重提模式值改变
    changeRejectRecallMode(val) {
      const { inSubProcess, allowNormalNode, allowDirectNode } =
        this.rejectInfo
      if (inSubProcess) {
        this.form.rejectMethod = val === 'normal' ? 'backToStart' : 'reject'
        this.rejectMethodName = this.rejectMethodMap[this.form.rejectMethod]
      }
      if (!this.isSameNode) {
        this.canRejectNode =
          val === 'normal' ? allowNormalNode : allowDirectNode
        this.canRejectNode.map((item) => {
          if (item.nodeId !== this.form.nodeId) {
            this.form.nodeId = ''
          }
        })
        this.filterRejectNode()
      }
      this.filterRejectMethod()
    },
    //过滤指定驳回节点
    filterRejectNode() {
      if (this.backNode && this.canRejectNode?.length > 0) {
        this.canRejectNode = this.canRejectNode.filter((item) =>
          this.backNode.includes(item.nodeId)
        )
      }
    },
    //打开弹窗时获取驳回页面参数
    getRejectTaskParamsByTaskId(show) {
      const query = {
        taskId: this.taskId,
        backModel: 'reject',
      }
      getRejectTaskParams(query, (res) => {
        this.rejectInfo = res
        const {
          allowNormalNode,
          allowDirectNode,
          inGateway,
          defaultRejectRecallMode,
        } = res
        const nodeIds = allowNormalNode?.map((item) => item.nodeId)
        this.form.rejectRecallMode =
          defaultRejectRecallMode || this.permitRejectRecallMode[0]
        allowDirectNode?.map((it) => {
          if (!nodeIds.includes(it.nodeId)) {
            this.isSameNode = false
          }
          this.canRejectNode =
            this.form.rejectRecallMode === 'normal'
              ? allowNormalNode
              : allowDirectNode
          this.filterRejectNode()
          //只有驳回发起人的情况
          this.rejectSponsor(show)
          this.rejectPreStep(show)
          this.rejectSpecifiedNode(show)
          this.setRejectMethod()
        })
        this.showApprovalAction = show
        this.filterRejectMethod()
      })
    },
    filterRejectMethod() {
      this.rejectMethodOptions = REJECT_METHOD_OPTIONS.map((item) => {
        if (item.key == 'rejectPre') {
          item.value = '驳回上一步(' + this.rejectPreName + ')'
        }
        return {
          ...item,
          isShow: this[REJECT_TYPE_MAP[item.key]],
        }
      }).filter((it) => it.isShow)
    },
    //驳回发起人情况
    rejectSponsor(show) {
      const { canRejectToStart, canRejectPreAct, canRejectToAnyNode } =
        this.rejectInfo
      if (canRejectToStart && !canRejectPreAct && !canRejectToAnyNode) {
        this.form.rejectMethod = 'backToStart'
        this.rejectMethodName = this.rejectMethodMap[this.form.rejectMethod]
        this.showApprovalAction = show
        return
      }
    },
    //只有驳回上一步的情况
    rejectPreStep(show) {
      const { canRejectToStart, canRejectPreAct, canRejectToAnyNode } =
        this.rejectInfo
      if (!canRejectToStart && canRejectPreAct && !canRejectToAnyNode) {
        this.form.rejectMethod = 'rejectPre'
        this.rejectMethodName = this.rejectMethodMap[this.form.rejectMethod]
        this.showApprovalAction = show
        return
      }
    },
    // 只有驳回指定节点的情况并且指定节点只有一个
    rejectSpecifiedNode(show) {
      const { canRejectToStart, canRejectPreAct, canRejectToAnyNode } =
        this.rejectInfo
      if (
        !canRejectToStart &&
        !canRejectPreAct &&
        canRejectToAnyNode &&
        this.canRejectNode.length === 1
      ) {
        this.nodeId = this.canRejectNode?.[0]?.nodeId
        this.form.rejectMethod = 'reject'
        this.rejectMethodName = this.rejectMethodMap[this.form.rejectMethod]
        this.showApprovalAction = show
        return
      }
    },
    setRejectMethod() {
      if (this.isShowRejectSponsor) {
        this.form.rejectMethod = 'backToStart'
      } else if (this.isShowRejectPreStep) {
        this.form.rejectMethod = 'rejectPre'
      } else if (this.isShowRejectNode) {
        this.form.rejectMethod = 'reject'
      }
      this.rejectMethodName = this.rejectMethodMap[this.form.rejectMethod]
    },
  }
}