Files
suixinkan_uikit/suixinkan/UI/Payment/PaymentCollectionRecordViewController.swift

111 lines
3.4 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// PaymentCollectionRecordViewController.swift
// suixinkan
//
import SnapKit
import UIKit
/// 7
final class PaymentCollectionRecordViewController: BaseViewController {
private let viewModel = PaymentCollectionRecordViewModel()
private let paymentAPI = NetworkServices.shared.paymentAPI
private let scrollView = UIScrollView()
private let contentStack = UIStackView()
private let emptyLabel = UILabel()
private let recordCardView = UIView()
private let groupsStack = UIStackView()
private let footerLabel = UILabel()
override func setupNavigationBar() {
title = "收款记录"
}
override func setupUI() {
view.backgroundColor = AppColor.pageBackground
contentStack.axis = .vertical
contentStack.spacing = AppSpacing.md
emptyLabel.text = "暂无收款记录"
emptyLabel.font = .systemFont(ofSize: 14)
emptyLabel.textColor = AppColor.textTertiary
emptyLabel.textAlignment = .center
emptyLabel.isHidden = true
recordCardView.backgroundColor = .white
recordCardView.layer.cornerRadius = AppRadius.lg
recordCardView.isHidden = true
groupsStack.axis = .vertical
groupsStack.spacing = AppSpacing.md
footerLabel.text = "仅支持查看7天的数据"
footerLabel.font = .systemFont(ofSize: 12)
footerLabel.textColor = UIColor(hex: 0xB6BECA)
footerLabel.textAlignment = .center
footerLabel.isHidden = true
view.addSubview(scrollView)
scrollView.addSubview(contentStack)
contentStack.addArrangedSubview(emptyLabel)
contentStack.addArrangedSubview(recordCardView)
contentStack.addArrangedSubview(footerLabel)
recordCardView.addSubview(groupsStack)
}
override func setupConstraints() {
scrollView.snp.makeConstraints { make in
make.edges.equalTo(view.safeAreaLayoutGuide)
}
contentStack.snp.makeConstraints { make in
make.edges.equalToSuperview().inset(AppSpacing.screenHorizontalInset)
make.width.equalTo(scrollView.snp.width).offset(-AppSpacing.screenHorizontalInset * 2)
}
emptyLabel.snp.makeConstraints { make in
make.height.greaterThanOrEqualTo(240)
}
groupsStack.snp.makeConstraints { make in
make.edges.equalToSuperview().inset(AppSpacing.md)
}
}
override func bindActions() {
viewModel.onStateChange = { [weak self] in
Task { @MainActor in self?.applyViewModel() }
}
}
override func viewDidLoad() {
super.viewDidLoad()
Task { await loadData() }
}
private func loadData() async {
showLoading()
await viewModel.loadRecord(api: paymentAPI)
hideLoading()
}
@MainActor
private func applyViewModel() {
let hasData = !viewModel.groups.isEmpty
emptyLabel.isHidden = hasData
recordCardView.isHidden = !hasData
footerLabel.isHidden = !hasData
groupsStack.arrangedSubviews.forEach {
groupsStack.removeArrangedSubview($0)
$0.removeFromSuperview()
}
viewModel.groups.forEach { group in
let groupView = PaymentRecordGroupView()
groupView.apply(group: group)
groupsStack.addArrangedSubview(groupView)
}
}
}