Newer
Older
smart-metering-front / src / plugins / preload.ts
function All() {}
All.prototype = {
  // 将负责人的姓名挑出来做成字符串
  arrToStr(arr: any) {
    if (arr) {
      return arr.map((item: any) => { return item.name }).toString()
    }
  },
  toggleClass(arr: any, elem: any, key = 'id') {
    return arr.some((item: any) => { return item[key] == elem[key] })
  },
  toChecked(arr: any, elem: any, key = 'id') {
    console.log('toChecked')
    var isIncludes = this.toggleClass(arr, elem, key)
    !isIncludes ? arr.push(elem) : this.removeEle(arr, elem, key)
  },
  removeEle(arr: any, elem: any, key = 'id') {
    var includesIndex
    arr.map((item: any, index: any) => {
      if (item[key] == elem[key]) {
        includesIndex = index
      }
    })
    arr.splice(includesIndex, 1)
  },
  // 设置审批节点的文字
  setApproverStr(nodeConfig: any) {
    if (nodeConfig.settype == 1 || nodeConfig.settype == 11) {
      if (nodeConfig.nodeUserList.length == 1) {
        return nodeConfig.nodeUserList[0].name
      }
      else if (nodeConfig.nodeUserList.length > 1) {
        if (nodeConfig.examineMode == 1) {
          return `由${this.arrToStr(nodeConfig.nodeUserList)}负责(依次审批)`
        }
        else if (nodeConfig.examineMode == 2) {
          return `由${this.arrToStr(nodeConfig.nodeUserList)}负责(会签)`
        }
        else if (nodeConfig.examineMode == 3) {
          return `由${this.arrToStr(nodeConfig.nodeUserList)}负责(或签)`
        }
      }
    }
    else if (nodeConfig.settype == 2) {
      const level = nodeConfig.directorLevel == 1 ? '直接主管' : `第${nodeConfig.directorLevel}级主管`
      if (nodeConfig.examineMode == 1) {
        return level
      }
      else if (nodeConfig.examineMode == 2) {
        return `${level}会签`
      }
    }
    else if (nodeConfig.settype == 7) {
      return `从直接主管到通讯录中级别最高的第${nodeConfig.examineEndDirectorLevel}个层级主管`
    }
    else if (nodeConfig.settype == 4) {
      return '审批人自选'
    }
  },
  dealStr(str: any, obj: any) {
    const arr = [] as any
    const list = str.split(',')
    for (var elem in obj) {
      list.map((item: any) => {
        if (item == elem) {
          arr.push(obj[elem].value)
        }
      })
    }
    return arr.join('或')
  },
  // 设置条件节点的文字
  conditionStr(nodeConfig: any, index: any) {
    var { conditionList, nodeUserList } = nodeConfig.conditionNodes[index]
    if (conditionList.length == 0) {
      return (index == nodeConfig.conditionNodes.length - 1) && nodeConfig.conditionNodes[0].conditionList.length != 0 ? '其他条件进入此流程' : '请设置条件'
    }
    else {
      let str = ''
      for (var i = 0; i < conditionList.length; i++) {
        var { columnId } = conditionList[i]
        if (columnId == 0) {
          if (nodeUserList.length != 0) {
            str += '发起人属于:'
            str += `${nodeUserList.map((item: any) => { return item.name }).join('、')} `
          }
        }
      }
      // return str ? str.substring(0, str.length - 4) : '请设置条件'
      return str || '请设置条件'
    }
  },
  // 设置抄送人节点文字
  copyerStr(nodeConfig: any) {
    if (nodeConfig.nodeUserList && nodeConfig.nodeUserList.length != 0) {
      console.log(this.arrToStr(nodeConfig.nodeUserList))
      return this.arrToStr(nodeConfig.nodeUserList)
    }
  },
  toggleStrClass(item: any, key: any) {
    const a = item.zdy1 ? item.zdy1.split(',') : []
    return a.some((item: any) => { return item == key })
  },
}

export default new (All as any)()