当前位置: 首页 > article >正文

VUE3中Element table表头动态展示合计信息(不是表尾合计)

一、背景 

原型上需要对两个字段动态合计,输出摘要信息

原先想到是的Element的 :summary-method,发现不是动态,所以换监听来实现

二、vue代码

   <el-table v-model="loading" :data="itemList">
          <el-table-column label="药品名称" prop="drugName" fixed min-width="100px" :show-overflow-tooltip="true"/>
          <el-table-column label="规格" prop="drugSpec" :show-overflow-tooltip="true"/>
          <el-table-column label="批号" prop="batchNo" :show-overflow-tooltip="true"/>
          <el-table-column label="账面数" prop="batchStockDesc" min-width="90px"/>
          <el-table-column label="盘存数" align="center">
            <el-table-column prop="stocktakeQty" min-width="150px">
              <template v-slot="scope">
                <el-input-number :disabled="!canEdit"
                                 v-model="scope.row.stocktakeQty"
                                 :min="0"
                                 controls-position="right"
                                 size="small"/>
              </template>
            </el-table-column>
            <el-table-column label="单位" prop="unit" min-width="90px">
              <template #default="scope">
                <dict-tag :options="bd_plat_drug_unit" :value="scope.row.unit" :showValue="false"/>
              </template>
            </el-table-column>
            <el-table-column prop="stocktakeTinyqty" min-width="150px">
              <template v-slot="scope">
                <el-input-number :disabled="!canEdit"
                                 v-model="scope.row.stocktakeTinyqty"
                                 :min="0"
                                 controls-position="right"
                                 size="small"/>
              </template>
            </el-table-column>
            <el-table-column label="小单位" prop="tinyUnit" min-width="90px">
              <template #default="scope">
                <dict-tag :options="bd_plat_drug_unit" :value="scope.row.tinyUnit" :showValue="false"/>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="零售" align="center">
            <el-table-column label="零售价" prop="retailPrice" min-width="100px" :show-overflow-tooltip="true"
                             align="right"/>
            <el-table-column label="盘前金额" prop="totalRetail" min-width="100px" :show-overflow-tooltip="true"
                             align="right"/>
            <el-table-column label="盘后金额" prop="afterTotalRetail" min-width="100px" :show-overflow-tooltip="true"
                             align="right">
              <template v-slot="scope">
                {{
                  scope.row.afterTotalRetail = computeTotalMoney(scope.row.stocktakeQty, scope.row.stocktakeTinyqty, scope.row.packageQty, scope.row.retailPrice)
                }}
              </template>
            </el-table-column>
            <el-table-column label="成本损溢金额" prop="totalLossoverRetail" min-width="120px" align="right">
              <template v-slot="scope">
                {{
                  scope.row.totalLossoverRetail = computeDifferenceMoney(scope.row.stocktakeQty, scope.row.stocktakeTinyqty, scope.row.packageQty, scope.row.retailPrice, scope.row.totalRetail)
                }}
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="成本" align="center">
            <el-table-column label="采购价" prop="purchasePrice" min-width="100px" :show-overflow-tooltip="true"
                             align="right"/>
            <el-table-column label="盘前金额" prop="totalPurchase" min-width="100px" :show-overflow-tooltip="true"
                             align="right"/>
            <el-table-column label="盘后金额" prop="afterTotalPurchase" min-width="100px" :show-overflow-tooltip="true"
                             align="right">
              <template v-slot="scope">
                {{
                  scope.row.afterTotalPurchase = computeTotalMoney(scope.row.stocktakeQty, scope.row.stocktakeTinyqty, scope.row.packageQty, scope.row.purchasePrice)
                }}
              </template>
            </el-table-column>
            <el-table-column label="成本损溢金额" prop="totalLossoverPurchase" min-width="120px"
                             :show-overflow-tooltip="true" align="right">
              <template v-slot="scope">
                {{
                  scope.row.totalLossoverPurchase = computeDifferenceMoney(scope.row.stocktakeQty, scope.row.stocktakeTinyqty, scope.row.packageQty, scope.row.purchasePrice, scope.row.totalPurchase)
                }}
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="生产企业" prop="firmName" min-width="80px" :show-overflow-tooltip="true"/>
          <el-table-column label="产地" prop="producerName" min-width="80px" :show-overflow-tooltip="true"/>
          <el-table-column label="库位码" prop="locationCode" min-width="100px" :show-overflow-tooltip="true"/>
          <el-table-column label="操作" fixed="right" min-width="60px" align="center" v-if="canEdit"
                           class-name="small-padding fixed-width">
            <template #default="scope">
              <el-button link type="primary" icon="Delete" title="删除" @click="handleDelete(scope.row)"/>
            </template>
          </el-table-column>
        </el-table>

  其中代码,赋值给totalLossoverRetail 才能保证,后期监听时数据有发生变化

                {{
                  scope.row.totalLossoverRetail = computeDifferenceMoney(scope.row.stocktakeQty, scope.row.stocktakeTinyqty, scope.row.packageQty, scope.row.retailPrice, scope.row.totalRetail)
                }}

三、方法代码

watch(itemList, () => {
  console.log(itemList.value, 'itemList')
  let totalLossoverRetail = 0
  let totalLossoverPurchase = 0
  itemList.value.forEach(item => {
    totalLossoverRetail = Number(totalLossoverRetail) + Number(item.totalLossoverRetail);
    totalLossoverPurchase = Number(totalLossoverPurchase) + Number(item.totalLossoverPurchase);
  })
  sumDescription.value = '成本损溢金额 ' + totalLossoverPurchase + ' 零售损溢金额  ' + totalLossoverRetail
}, {deep: true});

其中开启深度监听

四、效果


http://www.kler.cn/a/395221.html

相关文章:

  • nacos配置中心入门
  • 基于微信小程序的平安驾校预约平台的设计与实现(源码+LW++远程调试+代码讲解等)
  • 在 CentOS 系统中,您可以使用多种工具来查看网络速度和流量
  • 【C++】string类(附题)
  • Javaweb—Ajax与jQuery请求
  • Jetpack 之 Ink API初探
  • 【C#/C++】C++/CL中String^的含义和举例,C++层需要调用C#层对象时...
  • 数据结构--数组
  • 算法|牛客网华为机试41-52C++
  • LeetCode-222.完全二叉树的节点个数
  • DVWA靶场通关——SQL Injection篇
  • c++ shared_ptr 常见构造函数
  • GIT:如何查找已删除的文件的历史记录
  • caozha-pinyin(中文转拼音源码)
  • 【ubuntu18.04】vm虚拟机复制粘贴键不能用-最后无奈换版本
  • 数据结构---详解双向链表
  • Leecode刷题C语言之统计好节点的数目
  • uniapp luch-request 使用教程+响应对象创建
  • 异步处理之async/await使用技巧分享
  • 【广西-柳州】《柳州市本级信息化建设项目预算支出标准(试行)》(柳财审〔2020〕16号 )-省市费用标准解读系列11
  • Windows搭建流媒体服务并使用ffmpeg推流播放rtsp和rtmp流
  • 【redis】redis
  • c# 在10万条数据中判断是否存在很慢问题
  • 【金猿案例展】科技日报——大数据科技资讯服务平台
  • DB-GPT系列(五):DB-GPT六大基础应用场景part2
  • pyinstaller+upx给python GUI程序添加自定义图标