Vue3-admin-template的表格合计计算

news/2024/7/24 3:53:45 标签: vue.js, elementui, javascript

直接上代码:

 <el-table
          :data="lists"
          style="width: 100%"
          max-height="500"
          :header-cell-style="{ textAlign: 'center' }"
          :cell-style="{ textAlign: 'center' }"
          show-summary
          :summary-method="getSummaries"
          class="center-table"
        >
          <el-table-column fixed="left" prop="id" label="序号" />
          <el-table-column fixed="left" prop="name" label="姓名" width="90" />
          <el-table-column label="工资所属日期" width="120">
            <span>{{ dates }}</span>
          </el-table-column>
          <el-table-column label="公共性质" width="100">
            <template #default="scope">
              <span>{{
                scope.row.layout == 1 ? '长期派遣' : scope.row.layout == 2 ? '短期派遣' : '学员'
              }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="zw" label="职务" width="100" />
          <el-table-column prop="title" label="薪水等级" width="100" />
          <el-table-column label="薪资待遇标准" width="300">
            <el-table-column prop="money" label="岗位工资" width="100" />
            <el-table-column prop="safe" label="安全质量奖金" width="100" />
            <el-table-column prop="station" label="岗位津贴" width="100" />
            <el-table-column prop="performance" label="绩效奖金" width="100" />
          </el-table-column>
          <el-table-column prop="total_day" label="应出勤天数" width="120" />
          <el-table-column prop="standard" label="实际出勤天数" width="120" />
          <el-table-column prop="money" label="岗位工资" width="100" />
          <el-table-column prop="safe" label="安全质量奖金" width="120" />
          <el-table-column prop="station" label="岗位津贴" width="100" />
          <el-table-column prop="performance" label="绩效奖金" width="100" />
          <el-table-column label="证书补贴" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.crt_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="通讯补贴" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.tel_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="电脑补贴" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.comp_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="夜班补贴" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.night_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="加班补贴" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.overtime_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="误餐补贴" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.delay_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="租房补贴" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.house_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="高温补贴" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.hot_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="取暖补贴" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.toast_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="外出施工补贴" width="120">
            <template #default="scope">
              <input type="number" v-model="scope.row.egress_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="奖金" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.bonus" />
            </template>
          </el-table-column>
          <el-table-column label="其他补助" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.other_allowance" />
            </template>
          </el-table-column>
          <el-table-column label="扣款" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.deduct" />
            </template>
          </el-table-column>
          <el-table-column prop="yf_subtotal" label="应发小计" width="100"></el-table-column>
          <el-table-column label="个人社保" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.gr_security" />
            </template>
          </el-table-column>
          <el-table-column label="个税" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.individual" />
            </template>
          </el-table-column>
          <el-table-column prop="sf_subtotal" label="实发小计" width="100"></el-table-column>
          <el-table-column label="单位社保" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.dw_security" />
            </template>
          </el-table-column>
          <el-table-column label="管理费" width="100">
            <template #default="scope">
              <input type="number" v-model="scope.row.management" />
            </template>
          </el-table-column>
          <el-table-column prop="tel" label="电话" width="140"></el-table-column>
          <el-table-column prop="idcard" label="身份证号" width="180"></el-table-column>
          <el-table-column prop="bank_card" label="银行卡号" width="220"></el-table-column>
          <el-table-column
            fixed="right"
            prop="totalprice"
            label="合计金额"
            width="100"
          ></el-table-column>
        </el-table>

里面用到两个属性:

    show-summary

   :summary-method="getSummaries"

第二步:逻辑部分

javascript">const getSummaries = (param) => {
    const { columns, data } = param;
    const sums = [];
    columns.forEach((column, index) => {
      if (index === 0) {
        sums[index] = '总价';
        return;
      }
      const values = data.map((item) => Number(item[column.property]));
      if ((index >= 6 && index < 10) || (index >= 12 && index <= 34) || index == 38) {
        sums[index] = values.reduce((prev, curr) => {
          const value = Number(curr);
          if (!isNaN(value)) {
            return prev + curr;
          } else {
            return prev;
          }
        }, 0);
        sums[index] = sums[index].toFixed(2);
        // sums[index] += ' 元';
      } else {
        sums[index] = '';
      }
    });

    return sums;
  };

原创作者:吴小糖

创作时间: 2023.11.29 


http://www.niftyadmin.cn/n/5232471.html

相关文章

在FMCW雷达系统使用复基带架构(TI文档)

摘要 本文阐述了复基带架构在调频连续波(FMCW)雷达系统中的优势。典型的雷达前端实现使用带有真实基带和模数转换器(ADC)链的真实混频器。然而&#xff0c;在FMCW雷达的背景下&#xff0c;使用正交混频器和复基带架构可以发挥性能优势。该架构已在德州仪器的76 - 81 GHz全集成互…

数据结构算法-冒泡排序算法

引言 虽然选择排序好用 &#xff0c;但有点问题 也就是频繁找最大值下标 放到 未排序的后面 因为每次需要扫描整个未排序序列&#xff0c;找到最大值或最小值的下标&#xff0c;并将其交换到未排序序列的最后一个位置。这样做的问题在于&#xff0c;在后面的迭代中&#xff0c…

c++ 的几种用法

1. 声明引用&#xff1a;别名 改变ref a 都修改源数据 源地址数值 int a 10; int& ref a; // 声明一个引用变量ref&#xff0c;它引用了变量a 为什么要用别名: 1 给变量起一个更容易理解的名子 2 给函数/方法 传参 取这个参数的地址的值 修改的是源数据值 更高效 不多用…

Postman Post请求上传文件

Postman Post请求上传文件 一、选择post请求方式&#xff0c;输入请求地址 二、填写Headers Key&#xff1a;Content-Type Value&#xff1a;multipart/form-data [{"key":"Content-Type","value":"multipart/form-data","de…

力扣 --- H指数

题目描述&#xff1a; 给你一个整数数组 citations &#xff0c;其中 citations[i] 表示研究者的第 i 篇论文被引用的次数。计算并返回该研究者的 h 指数。 根据维基百科上 h 指数的定义&#xff1a;h 代表“高引用次数” &#xff0c;一名科研人员的 h 指数 是指他&#xff…

ChatGPT一周年,奥特曼官宣 OpenAI 新动作!

大家好&#xff0c;我是二狗。 今天是11月30日&#xff0c;一转眼&#xff0c;ChatGPT 发布已经一周年了&#xff01; 而就在刚刚&#xff0c;ChatGPT一周年之际。 OpenAI 正式宣布Sam Altman回归重任CEO, Mira Murati 重任CTO&#xff0c;Greg Brockman重任总裁&#xff0c;O…

Java开发项目之智能停车场管理系统设计说明介绍

项目背景和介绍 随着网络不断的普及发展&#xff0c;智能停车场管理系统依靠网络技术的支持得到了快速的发展&#xff0c;首先要从用户的实际需求出发&#xff0c;通过了解用户的需求开发出具有针对性的管理系统&#xff0c;利用目前网络给用户带来的方便快捷这一特点对系统进…

数据结构 / 队列 / 循环队列 / 概念

1. 定义 为充分利用向量空间&#xff0c;克服假溢出现象的方法是&#xff1a;将向量空间想象为一个首尾相接的圆环&#xff0c;并称这种向量为循环向量。存储在其中的队列称为循环队列&#xff08;Circular Queue&#xff09;。循环队列是把顺序队列首尾相连&#xff0c;把存储…