Explorar el Código

应收开票增加合计

@dongkboy hace 2 meses
padre
commit
a1c445966e
Se han modificado 1 ficheros con 51 adiciones y 2 borrados
  1. 51 2
      src/views/receivable/handingFee/ticket.vue

+ 51 - 2
src/views/receivable/handingFee/ticket.vue

@@ -68,7 +68,8 @@
       <p>应收明细</p>
       <el-button type="primary" @click="addTicket">添加应收</el-button>
     </div>
-    <el-table :data="tableData" style="height: calc(100% - 300px)">
+    <el-table :data="tableData" style="height: calc(100% - 300px)" show-summary
+    :summary-method="val => getSummaries(val,['jqPremium','jqSuperviseCostsProportion','syPremium','sySuperviseCostsProportion','receivableAmount','receivableAmount4Car','receivableAmount4Other'])">
       <template #empty>
         <div v-if="noData">暂无应收,点击<el-button link type="primary" @click="batchShow = true">导入应收</el-button></div>
         <div v-else>没有符合的应收单据~</div>
@@ -557,7 +558,55 @@ const handleTicket = (bool) => {
     }
   })
 }
-
+const getSummaries = (param, list) => {
+  console.log(param)
+  const { columns, data } = param
+  const sums: (string | VNode)[] = []
+  // 指定需要计算的字段列表(可根据需求添加字段名)
+  const specifiedFields = list || [] // 替换为您需要的字段名
+
+  columns.forEach((column, index) => {
+    if (index === 0) {
+      sums[index] = h('div', { style: { textDecoration: 'underline' } }, [
+        '',
+      ])
+      return
+    }
+    // 计算数字类型字段和指定字段
+    const values = data.map((item) => {
+      const val = item[column.property]
+      // 排除空值
+      if (val === '' || val === null || val === undefined) {
+        return NaN
+      }
+      // 如果是数字类型,直接参与计算
+      if (typeof val === 'number') {
+        return val
+      }
+      // 如果字段在指定列表中,尝试转换为数字
+      if (specifiedFields.includes(column.property)) {
+        const num = Number(val)
+        return Number.isNaN(num) ? NaN : num
+      }
+      // 其他情况不参与计算
+      return NaN
+    })
+    if (!values.every((value) => Number.isNaN(value))) {
+      const total = values.reduce((prev, curr) => {
+        if (!Number.isNaN(curr)) {
+          return prev + curr
+        } else {
+          return prev
+        }
+      }, 0)
+      // 保留五位小数
+      sums[index] = ` ${total.toFixed(5)}`
+    } else {
+      sums[index] = '-'
+    }
+  })
+  return sums
+}
 const receivableSupervisePremium = ref(0)
 const calBeforeInvoice = async (params: any) => {
   const res = await api.financeApi.calBeforeInvoice(params)