Files
suixinkan_uikit/suixinkan/UI/Orders/OrderListView.swift
汉秋 31d2b6094b Implement orders tab aligned with Android, including scan verify flows.
Add role-based order/deposit lists, AVFoundation QR scanning, verify dialogs, and ViewModel tests so photographers, scenic admins, and store admins match Android behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 16:59:53 +08:00

74 lines
2.2 KiB
Swift
Raw 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.

//
// OrderListView.swift
// suixinkan
//
import SnapKit
import UIKit
///
final class OrderListView: UIView {
enum Mode {
case photographer
case store
}
var onRefresh: (() -> Void)?
var onLoadMore: ((Int) -> Void)?
let tableView = UITableView(frame: .zero, style: .plain)
private let refreshControl = UIRefreshControl()
private let footerLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor(hex: 0xF5F5F5)
tableView.backgroundColor = .clear
tableView.separatorStyle = .none
tableView.keyboardDismissMode = .onDrag
tableView.refreshControl = refreshControl
refreshControl.addTarget(self, action: #selector(refreshTriggered), for: .valueChanged)
footerLabel.font = .systemFont(ofSize: 12)
footerLabel.textColor = UIColor(hex: 0x9CA3AF)
footerLabel.textAlignment = .center
footerLabel.text = "没有更多"
addSubview(tableView)
tableView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func apply(isRefreshing: Bool, canLoadMore: Bool, isEmpty: Bool) {
if isRefreshing {
if !refreshControl.isRefreshing { refreshControl.beginRefreshing() }
} else {
refreshControl.endRefreshing()
}
footerLabel.text = isEmpty ? "暂无订单" : (canLoadMore ? "" : "没有更多")
tableView.tableFooterView = footerLabelFrame(isEmpty: isEmpty, canLoadMore: canLoadMore)
}
private func footerLabelFrame(isEmpty: Bool, canLoadMore: Bool) -> UIView? {
guard !canLoadMore || isEmpty else { return nil }
footerLabel.frame = CGRect(x: 0, y: 0, width: bounds.width, height: 44)
return footerLabel
}
@objc private func refreshTriggered() {
onRefresh?()
}
func notifyLoadMoreIfNeeded(at index: Int, shouldLoad: Bool) {
guard shouldLoad else { return }
onLoadMore?(index)
}
}