vue3 elementplus table表格多行合计

表格底部如何多行合计
在这里插入图片描述

1.先在标签上定义合计方法

 <el-table
            :data="data"
            :summary-method="getSummaries"
            :show-summary="true"
            @selection-change="handleSelectionChange"
          >

2.文件头部引入h函数渲染多行div,BigNumber 防止精度丢失。

import { reactive, onMounted, toRefs, ref, h } from 'vue';
import BigNumber from 'bignumber.js';

// 计算求和
function countTotal(arr, keyName) {
  let $total = 0;
  $total = arr.reduce(function (total, currentValue, currentIndex, arr) {
    return currentValue[keyName]
      ? new BigNumber(total).plus(currentValue[keyName]).toString()
      : total;
  }, 0);
  return $total;
}

function getSummaries(param: any) {
  const { columns, data } = param;
  const sums: string[] = [];
  const tit: string[] = [];

  let CNYObj = {
    waers: 'CNY'
  };
  let USDObj = {
    waers: 'USD'
  };
  const CNYArr = data.filter(item => item.waers === 'CNY');
  const USDArr = data.filter(item => item.waers === 'USD');
  CNYObj.docmt_ttl_amt = countTotal(CNYArr, 'docmt_ttl_amt');
  CNYObj.paid_ttl_amt = countTotal(CNYArr, 'paid_ttl_amt');
  CNYObj.app_ttl_amt = countTotal(CNYArr, 'app_ttl_amt');
  CNYObj.acnt_lmt = countTotal(CNYArr, 'acnt_lmt');
  CNYObj.acnt_sm_lmt = countTotal(CNYArr, 'acnt_sm_lmt');
  CNYObj.num_lmt = countTotal(CNYArr, 'num_lmt');
  CNYObj.bank_lmt = countTotal(CNYArr, 'bank_lmt');
  CNYObj.notesr_lmt = countTotal(CNYArr, 'notesr_lmt');
  CNYObj.comm_notesp_lmt = countTotal(CNYArr, 'comm_notesp_lmt');
  CNYObj.bank_notesp_lmt = countTotal(CNYArr, 'bank_notesp_lmt');
  CNYObj.oth_pymt_term_lmt = countTotal(CNYArr, 'oth_pymt_term_lmt');

  USDObj.docmt_ttl_amt = countTotal(USDArr, 'docmt_ttl_amt');
  USDObj.paid_ttl_amt = countTotal(USDArr, 'paid_ttl_amt');
  USDObj.app_ttl_amt = countTotal(USDArr, 'app_ttl_amt');
  USDObj.acnt_lmt = countTotal(USDArr, 'acnt_lmt');
  USDObj.acnt_sm_lmt = countTotal(USDArr, 'acnt_sm_lmt');
  USDObj.num_lmt = countTotal(USDArr, 'num_lmt');
  USDObj.bank_lmt = countTotal(USDArr, 'bank_lmt');
  USDObj.notesr_lmt = countTotal(USDArr, 'notesr_lmt');
  USDObj.comm_notesp_lmt = countTotal(USDArr, 'comm_notesp_lmt');
  USDObj.bank_notesp_lmt = countTotal(USDArr, 'bank_notesp_lmt');
  USDObj.oth_pymt_term_lmt = countTotal(USDArr, 'oth_pymt_term_lmt');

  tit.push(CNYObj);
  tit.push(USDObj);
  titData.value = tit;

  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = h('div', { class: '' }, [
        h('div', '金额合计'),
        h('br', '')
      ]);
      return;
    }
    if (index === 1) {
      sums[index] = h('div', { class: '' }, [h('div', 'CNY'), h('div', 'USD')]);
      return;
    }
    if (index === 2) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
    if (index === 3) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
    if (index === 4) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
    if (index === 5) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
    if (index === 6) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
    if (index === 7) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
    if (index === 8) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
    if (index === 9) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
    if (index === 10) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
    if (index === 11) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
    if (index === 12) {
      sums[index] = h('div', { class: '' }, [
        h('div', toThousandFilter(countTotal(CNYArr, column.property))),
        h('div', toThousandFilter(countTotal(USDArr, column.property)))
      ]);
      return;
    }
  });
  return sums;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值