Commit 4c6155bee39c45e5c427432ca57fcacc64c56392
1 parent
1a8a946d
优化代码
Showing
2 changed files
with
45 additions
and
5 deletions
src/api/report/reportFeeSummaryApi.js
src/views/report/reportFeeSummaryList.vue
| ... | ... | @@ -246,14 +246,52 @@ export default { |
| 246 | 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 | 292 | } catch (error) { |
| 256 | 293 | console.error('Failed to query fee summary:', error) |
| 294 | + this.$message.error(this.$t('reportFeeSummary.queryFailed') || '查询失败,请稍后重试') | |
| 257 | 295 | } |
| 258 | 296 | }, |
| 259 | 297 | async _loadStaffCommunitys() { | ... | ... |