Commit 4c6155bee39c45e5c427432ca57fcacc64c56392

Authored by wuxw
1 parent 1a8a946d

优化代码

src/api/report/reportFeeSummaryApi.js
@@ -19,6 +19,8 @@ export function queryReportFeeSummary(params) { @@ -19,6 +19,8 @@ export function queryReportFeeSummary(params) {
19 }) 19 })
20 } 20 }
21 21
  22 +
  23 +
22 /** 24 /**
23 * 查询楼栋费用汇总数据 25 * 查询楼栋费用汇总数据
24 * @param {Object} params 查询参数 26 * @param {Object} params 查询参数
src/views/report/reportFeeSummaryList.vue
@@ -246,14 +246,52 @@ export default { @@ -246,14 +246,52 @@ export default {
246 params.configIds = this.reportFeeSummaryInfo.configIds.join(','); 246 params.configIds = this.reportFeeSummaryInfo.configIds.join(',');
247 } 247 }
248 248
249 - const { data } = await queryReportFeeSummary(params)  
250 - this.reportFeeSummaryInfo.fees = data 249 + // 定义需要查询的字段类型
  250 + const queryTypes = [
  251 + 'roomCount',
  252 + 'feeRoomCount',
  253 + 'oweRoomCount',
  254 + 'hisOweFee',
  255 + 'curOweFee',
  256 + 'curReceivableFee',
  257 + 'hisReceivedFee',
  258 + 'preReceivedFee',
  259 + 'receivedFee'
  260 + ]
251 261
252 - // Notify child components  
253 - this.$refs.floorFeeSummary.notify(params)  
254 - this.$refs.configFeeSummary.notify(params) 262 + // 合并结果的对象
  263 + const mergedResult = {}
  264 +
  265 + // 串行查询每个字段
  266 + for (const queryType of queryTypes) {
  267 + try {
  268 + const queryParams = { ...params, queryType }
  269 + const { data } = await queryReportFeeSummary(queryParams)
  270 + if (data && data.length > 0 && data[0]) {
  271 + // 将返回的数据合并到结果对象中
  272 + Object.assign(mergedResult, data[0])
  273 + }
  274 + } catch (error) {
  275 + console.error(`Failed to query ${queryType}:`, error)
  276 + // 如果某个字段查询失败,设置为默认值
  277 + const fieldName = queryType === 'roomCount' || queryType === 'feeRoomCount' || queryType === 'oweRoomCount' ? queryType : queryType
  278 + mergedResult[fieldName] = queryType.includes('Count') ? 0 : 0.00
  279 + }
  280 + }
  281 +
  282 + // 将合并后的结果放入数组中(因为表格期望数组格式)
  283 + this.reportFeeSummaryInfo.fees = [mergedResult]
  284 +
  285 + // 通知子组件查询(子组件内部自己查询)
  286 + if (this.$refs.floorFeeSummary) {
  287 + this.$refs.floorFeeSummary.notify(params)
  288 + }
  289 + if (this.$refs.configFeeSummary) {
  290 + this.$refs.configFeeSummary.notify(params)
  291 + }
255 } catch (error) { 292 } catch (error) {
256 console.error('Failed to query fee summary:', error) 293 console.error('Failed to query fee summary:', error)
  294 + this.$message.error(this.$t('reportFeeSummary.queryFailed') || '查询失败,请稍后重试')
257 } 295 }
258 }, 296 },
259 async _loadStaffCommunitys() { 297 async _loadStaffCommunitys() {