elment表格总计列进行字段筛选相加

export function getSummaries (param) {
  /* 表格总计行 */
  const { columns, data } = param
  const sums = []
  const columnList = ['boxes', 'purchaseQuantity', 'newboxes', 'newpurchaseQuantity', 'sendQuantity',
    'totalPrice', 'totalPay', 'tobeSend', 'deliveryQuantity', 'newdeliveryQuantity', 'quantity',
    'receiveQuantity', 'checkQuantity', 'instockQuantity', 'planQuantity', 'allAmount', 'payableAmount']
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = '总计'
    } else if (columnList.includes(column.property)) {
      const values = data.map(item => Number(item[column.property]))
      if (!values.every(value => isNaN(value))) {
        sums[index] = values.reduce((prev, curr) => {
          const value = Number(curr)
          if (!isNaN(value)) {
            return accAdd(prev, curr)
          } else {
            return prev
          }
        }, 0)
        sums[index] += ''
      } else {
        sums[index] = ''
      }
    }
  })
  return sums
}

  

上一篇:想学java老师建议学python怎么办?IT培训常见骗局汇总


下一篇:插件——nprogress进度条