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

直接上代码:

 <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"

第二步:逻辑部分

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 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小吴吴吴呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值