export function getTaskResult(task) {
	if(task.isFuture) return {text: '等待中...', type: 'info'}
	if (task.taskResult === 'agree') {
		return {
			text: '已同意',
			type: 'success'
		}
	} else if (task.taskResult === 'refuse') {
		return {
			text: '已拒绝',
			type: 'error'
		}
	} else if (task.taskResult === 'transfer') {
		return {
			text: '已转交',
			type: 'primary'
		}
	} else if (task.taskResult === 'recall') {
		return {
			text: '已退回',
			type: 'warning'
		}
	} else if (!task.taskResult && task.finishTime) {
		return {
			text: '已取消',
			type: 'default'
		}
	} else {
		return {
			text: '处理中',
			type: 'primary'
		}
	}
}

export function getProcTag(result) {
	switch (result) {
		case 'RUNNING':
			return {
				text: '进行中', type: 'primary'
			}
		case 'COMPLETE':
			return {
				text: '已结束', type: 'primary'
			}
		case 'PASS':
			return {
				text: '审批通过', type: 'success'
			}
		case 'CANCEL':
			return {
				text: '已撤销', type: 'default'
			}
		case 'REFUSE':
			return {
				text: '审批驳回', type: 'error'
			}
		default: 
			return {
				text: '未知状态', type: 'default'
			}

	}
}


//判断是否为主要业务节点
export function isPrimaryNode(node){
  return node && node.type && !(isBranchNode(node) || isEmptyNode(node));
}
export function isBranchNode(node){
  return node && (node.type === 'CONDITIONS' || node.type === 'CONCURRENTS' || node.type === 'INCLUSIVES');
}
export function isEmptyNode(node){
  return node && (node.type === 'EMPTY')
}
//是分支节点
export function isConditionNode(node){
  return node.type === 'CONDITIONS';
}
//是分支节点
export function isBranchSubNode(node){
  return node && (node.type === 'CONDITION' || node.type === 'CONCURRENT' || node.type === 'INCLUSIVE');
}
export function isConcurrentNode(node){
  return node.type === 'CONCURRENTS'
}

export function isInclusiveNode(node){
  return node.type === 'INCLUSIVES'
}

export function forEachNode(node, callback){
  if (isBranchNode(node)){
    if (callback(node)){return}
    node.branchs.map(branchNode => {
      if (callback(branchNode)){return}
      forEachNode(branchNode.children, callback)
    })
    forEachNode(node.children, callback)
  }else if (isPrimaryNode(node) || isEmptyNode(node) || isBranchSubNode(node)){
    if (callback(node)){return}
    forEachNode(node.children, callback)
  }
}