From 40c1138a3fc7ea11536a661f543a55c30be24382 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期一, 02 十一月 2026 16:51:25 +0800
Subject: [PATCH] feat(costStatistics): - 新增全局汇总信息,展示筛选结果条数与全部费用合计 - 保存费用后自动刷新数据并同步已勾选行状态
---
src/views/business/costStatistics/index.vue | 127 ++++++++++++++++++++++++++++++------------
1 files changed, 91 insertions(+), 36 deletions(-)
diff --git a/src/views/business/costStatistics/index.vue b/src/views/business/costStatistics/index.vue
index fac168e..ed405aa 100644
--- a/src/views/business/costStatistics/index.vue
+++ b/src/views/business/costStatistics/index.vue
@@ -1,6 +1,6 @@
<template>
<!-- 璐圭敤缁熻椤甸潰-->
- <div class="capacity-scope">
+ <div class="capacity-scope" v-loading="feeSaving">
<div class="search">
<div>
<el-form :model="entity" ref="entity" size="small" :inline="true">
@@ -34,9 +34,10 @@
</div>
</div>
<div>
- <lims-table :tableData="tableData" :column="column"
+ <lims-table ref="ratesTable" :tableData="tableData" :column="column"
:height="'calc(100vh - 300px)'" @pagination="pagination"
:isSelection="true" :handleSelectionChange="handleSelectionChange"
+ rowKey="id" :reserveSelection="true"
:page="page" :tableLoading="tableLoading">
<template #isDiscount="{ row }">
<el-select v-model="row.isDiscount" size="small" style="width: 80px"
@@ -57,9 +58,14 @@
</template>
</lims-table>
</div>
- <div class="sum-bar">
+ <div class="sum-bar" v-loading="tableLoading">
+ <span class="all-summary">绛涢�夌粨鏋� <b class="sum-count">{{ summary ? summary.count : '鈥�' }}</b> 鏉★紝
+ 鍏ㄩ儴璐圭敤锛�<b class="sum-amount">楼{{ summary ? formatAmount(summary.totalAmount) : '鈥�' }}</b>
+ <small>锛堝寘鍚墍鏈夊垎椤碉級</small>
+ </span>
<span>宸插嬀閫� <b class="sum-count">{{ selectedRows.length }}</b> 鏉�</span>
- <span>鎬婚噾棰濓細<b class="sum-amount">楼{{ selectedTotal }}</b></span>
+ <span>鍕鹃�夊悎璁★細<b class="sum-amount">楼{{ selectedTotal }}</b></span>
+ <el-button link type="primary" :disabled="!selectedRows.length" @click="clearSelection">娓呯┖鍕鹃��</el-button>
</div>
<viewInfoDia ref="viewInfoDia" v-if="viewInfoDia"></viewInfoDia>
</div>
@@ -68,7 +74,9 @@
<script>
import limsTable from "@/components/Table/lims-table.vue";
import viewInfoDia from "./components/viewInfoDia.vue";
-import {selectRatesPage, updateOrderFee} from "@/api/business/insOrderRates";
+import {selectRatesPage, selectRatesSummary, updateOrderFee} from "@/api/business/insOrderRates";
+import {sumOrderAmounts} from "@/utils/orderRates";
+import Big from 'big.js';
import {selectCustomPageList} from "@/api/system/customer";
import { ElMessage } from "element-plus";
@@ -77,10 +85,16 @@
data() {
return {
entity: {
+ entrustCode: null,
sample: null,
company: null,
},
monthRange: [],
+ appliedFilters: {},
+ summary: null,
+ savedRows: {},
+ requestVersion: 0,
+ feeSaving: false,
tableData: [],
tableLoading: false,
column: [
@@ -165,12 +179,7 @@
computed: {
// 鍕鹃�夊悎璁★細鏈変紭鎯犱笖濉簡浼樻儬鍚庨噾棰濈殑鎸変紭鎯犲悗閲戦绠楋紝鍚﹀垯鎸夋�讳环绠�
selectedTotal() {
- const total = this.selectedRows.reduce((sum, row) => {
- const useDiscount = row.isDiscount === 1 && row.discountAmount !== null && row.discountAmount !== undefined
- const amount = Number(useDiscount ? row.discountAmount : row.totalPrice)
- return sum + (isFinite(amount) ? amount : 0)
- }, 0)
- return total.toFixed(2)
+ return sumOrderAmounts(this.selectedRows)
}
},
mounted() {
@@ -179,19 +188,45 @@
},
methods :{
refreshTable() {
- this.tableLoading = true
const [startMonth, endMonth] = this.monthRange || []
- selectRatesPage({ ...this.page, ...this.entity, startMonth, endMonth }).then(res => {
- this.tableLoading = false
- this.tableData = (res.data.records || []).map(item => {
- item.isDiscount = item.isDiscount === 1 ? 1 : 0
- return item
- })
+ this.appliedFilters = { ...this.entity, startMonth, endMonth }
+ this.page.current = 1
+ this.clearSelection()
+ this.savedRows = {}
+ this.tableData = []
+ return this.loadTable()
+ },
+ async loadTable() {
+ const version = ++this.requestVersion
+ this.tableLoading = true
+ this.summary = null
+ try {
+ const [res, summary] = await Promise.all([
+ selectRatesPage({ current: this.page.current, size: this.page.size, ...this.appliedFilters }),
+ selectRatesSummary(this.appliedFilters),
+ ])
+ if (version !== this.requestVersion) return
+ this.tableData = (res.data.records || []).map(row => ({ ...row, isDiscount: Number(row.isDiscount || 0) }))
+ // 淇濈暀鏈嶅姟绔揩鐓э紝杈撳叆妗嗕腑灏氭湭淇濆瓨鐨勯噾棰濅笉杩涘叆鍚堣銆�
+ this.tableData.forEach(row => { this.savedRows[row.id] = { ...row } })
+ this.selectedRows = this.selectedRows.map(row => this.savedRows[row.id] || row)
this.page.total = res.data.total
- this.selectedRows = []
- }).catch(err => {
- this.tableLoading = false
- })
+ this.summary = summary.data
+ } catch (err) {
+ if (version !== this.requestVersion) return
+ this.tableData = []
+ this.page.total = 0
+ this.clearSelection()
+ } finally {
+ if (version === this.requestVersion) this.tableLoading = false
+ }
+ },
+ clearSelection() {
+ this.$refs.ratesTable?.clearSelection()
+ this.selectedRows = []
+ },
+ formatAmount(value) {
+ return new Big(value || 0).toFixed(2)
},
// 閲嶇疆
refresh() {
@@ -218,12 +253,13 @@
},
// 鍒嗛〉鍒囨崲
pagination(page) {
+ this.page.current = page.page
this.page.size = page.limit
- this.refreshTable()
+ return this.loadTable()
},
// 鍕鹃�夎鍙樺寲
handleSelectionChange(selection) {
- this.selectedRows = selection
+ this.selectedRows = selection.map(row => this.savedRows[row.id] || { ...row })
},
// 鍒囨崲鏄惁浼樻儬
handleDiscountChange(row) {
@@ -235,7 +271,7 @@
} else {
row.discountAmount = null
}
- this.saveFee(row)
+ return this.saveFee(row)
},
// 浼樻儬鍚庨噾棰濇敼瀹屼繚瀛�
handleAmountChange(row) {
@@ -247,26 +283,39 @@
ElMessage.warning('鏈変紭鎯犳椂璇峰~鍐欎紭鎯犲悗閲戦')
return
}
- this.saveFee(row)
+ return this.saveFee(row)
},
// 澶囨敞鏀瑰畬淇濆瓨
handleFeeRemarkChange(row) {
- this.saveFee(row)
+ return this.saveFee(row)
},
amountOf(value) {
const num = Number(value)
if (!isFinite(num)) return 0
return Math.round(num * 100) / 100
},
- saveFee(row) {
- updateOrderFee({
- id: row.id,
- isDiscount: row.isDiscount,
- discountAmount: row.isDiscount === 1 ? row.discountAmount : null,
- feeRemark: row.feeRemark || null
- }).catch(() => {
- this.refreshTable()
- })
+ async saveFee(row) {
+ if (this.feeSaving) return
+ if (row.isDiscount === 1 && (row.discountAmount == null || row.discountAmount === '')) {
+ ElMessage.warning('鏈変紭鎯犳椂璇峰~鍐欎紭鎯犲悗閲戦')
+ return
+ }
+ this.feeSaving = true
+ // 浣夸慨鏀瑰墠浠嶅湪閫旂殑鏌ヨ澶辨晥锛岄伩鍏嶆棫閲戦瑕嗙洊淇濆瓨鍚庣殑鐘舵�併��
+ ++this.requestVersion
+ try {
+ await updateOrderFee({
+ id: row.id,
+ isDiscount: row.isDiscount,
+ discountAmount: row.isDiscount === 1 ? row.discountAmount : null,
+ feeRemark: row.feeRemark || null
+ })
+ } catch (err) {
+ // 璇锋眰鎷︽埅鍣ㄦ彁绀哄け璐ュ師鍥狅紱涓嬮潰閲嶆柊璇诲彇瀹為檯淇濆瓨鐨勯噾棰濄��
+ } finally {
+ await this.loadTable()
+ this.feeSaving = false
+ }
},
// 鏌ョ湅璇︽儏
openDia (row) {
@@ -282,6 +331,8 @@
.search {
min-height: 46px;
display: flex;
+ align-items: center;
+ flex-wrap: wrap;
justify-content: space-between;
}
.sum-bar {
@@ -289,6 +340,8 @@
bottom: 0;
z-index: 10;
display: flex;
+ align-items: center;
+ flex-wrap: wrap;
justify-content: flex-end;
gap: 24px;
margin-top: 8px;
@@ -300,6 +353,8 @@
.sum-count {
color: var(--el-color-primary);
}
+.all-summary { margin-right: auto; }
+.all-summary small { color: var(--el-text-color-secondary); }
.sum-amount {
color: var(--el-color-danger);
font-size: 16px;
--
Gitblit v1.9.3