添加即时收款流程并对齐 Android

This commit is contained in:
2026-07-07 09:29:03 +08:00
parent 0964ef8b80
commit 16e86c8899
17 changed files with 1548 additions and 1 deletions

View File

@ -0,0 +1,61 @@
//
// PaymentCollectionRecordViewModel.swift
// suixinkan
//
import Foundation
/// ViewModel 7
final class PaymentCollectionRecordViewModel {
private(set) var loading = false
private(set) var groups: [RepaymentCollectionRecordGroup] = []
var onStateChange: (() -> Void)?
private let appStore: AppStore
init(appStore: AppStore = .shared) {
self.appStore = appStore
}
func loadRecord(api: PaymentAPI) async {
guard !loading else { return }
loading = true
notifyStateChange()
defer {
loading = false
notifyStateChange()
}
let scenicId = appStore.currentScenicId
guard scenicId > 0 else {
groups = []
return
}
do {
let response = try await api.collectionRecord(scenicId: scenicId)
groups = PaymentRecordGrouper.group(response: response)
} catch {
groups = []
}
}
private func notifyStateChange() {
onStateChange?()
}
}
/// Android `PaymentCollectionRecordViewModel.getRecord`
enum PaymentRecordGrouper {
static func group(response: RepaymentCollectionRecordResponse) -> [RepaymentCollectionRecordGroup] {
let mapByDate = Dictionary(grouping: response.list, by: \.createDate)
return response.analyse.map { analyseItem in
RepaymentCollectionRecordGroup(
analyse: analyseItem,
items: mapByDate[analyseItem.date] ?? []
)
}
}
}