feat(drone-dock): 对接我的拍摄订单筛选与分页
This commit is contained in:
@@ -190,6 +190,7 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
let header = collection.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: path) as! DroneDockHomeHeader
|
||||
let isOrders = Section(rawValue: path.section) == .orders
|
||||
let orderTitle = self.viewModel.orderTotal.map { "我的拍摄订单(\($0))" } ?? "我的拍摄订单"
|
||||
header.onViewAll = isOrders ? { [weak self] in self?.openAllOrders() } : nil
|
||||
header.apply(title: isOrders ? orderTitle : "今日统计", isOrders: isOrders)
|
||||
return header
|
||||
}
|
||||
@@ -289,6 +290,23 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
showAlert(title: feature, message: "该功能暂未开放")
|
||||
}
|
||||
|
||||
private func openAllOrders() {
|
||||
let controller = DroneDockOrdersViewController(
|
||||
viewModel: viewModel.makeOrdersViewModel(), preparationControllerFactory: preparationFactory)
|
||||
navigationController?.pushViewController(controller, animated: true)
|
||||
}
|
||||
|
||||
/// 首页和全部订单页沿用同一真实拍摄准备入口。
|
||||
private var preparationFactory: (DroneDockHomeOrder, DroneDockHomeContext) -> UIViewController {
|
||||
preparationControllerFactory ?? { order, context in
|
||||
DroneDockRemotePreparationViewController(viewModel: DroneDockPreparationViewModel(
|
||||
context: context, order: order,
|
||||
service: DroneDockPreparationAPI(client: NetworkServices.shared.apiClient),
|
||||
currentContext: { Self.currentContext() }
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
private func openPreparation(orderID: String) {
|
||||
guard !isRefreshing, let order = viewModel.orders.first(where: { $0.orderID == orderID }) else { return }
|
||||
guard order.primaryAction == "start_shoot" else {
|
||||
@@ -300,12 +318,7 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
return
|
||||
}
|
||||
let context = viewModel.context
|
||||
let controller = preparationControllerFactory?(order, context) ?? DroneDockRemotePreparationViewController(
|
||||
viewModel: DroneDockPreparationViewModel(
|
||||
context: context, order: order,
|
||||
service: DroneDockPreparationAPI(client: NetworkServices.shared.apiClient),
|
||||
currentContext: { Self.currentContext() }
|
||||
))
|
||||
let controller = preparationFactory(order, context)
|
||||
navigationController?.pushViewController(controller, animated: true)
|
||||
}
|
||||
|
||||
@@ -467,12 +480,31 @@ private final class DroneDockHomeContentCell: UICollectionViewCell {
|
||||
|
||||
/// 首页分区标题,订单数量使用接口 total,不使用当前页条数。
|
||||
private final class DroneDockHomeHeader: UICollectionReusableView {
|
||||
/// 用户请求打开当前景区的全部真实拍摄订单。
|
||||
var onViewAll: (() -> Void)?
|
||||
private let label = DroneDockStyle.label(size: 17, weight: .semibold)
|
||||
private let viewAllButton = UIButton(type: .system)
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
addSubview(label)
|
||||
label.snp.makeConstraints { $0.leading.trailing.centerY.equalToSuperview() }
|
||||
viewAllButton.setTitle("查看全部 ›", for: .normal)
|
||||
viewAllButton.titleLabel?.font = .systemFont(ofSize: 13)
|
||||
viewAllButton.tintColor = DroneDockStyle.primary
|
||||
viewAllButton.accessibilityIdentifier = "drone.home.allOrders"
|
||||
viewAllButton.addTarget(self, action: #selector(viewAllTapped), for: .touchUpInside)
|
||||
addSubview(viewAllButton)
|
||||
viewAllButton.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
label.adjustsFontSizeToFitWidth = true
|
||||
label.minimumScaleFactor = 0.75
|
||||
label.snp.makeConstraints { make in
|
||||
make.leading.centerY.equalToSuperview()
|
||||
make.trailing.lessThanOrEqualTo(viewAllButton.snp.leading).offset(-8)
|
||||
}
|
||||
viewAllButton.snp.makeConstraints { make in
|
||||
make.trailing.centerY.equalToSuperview()
|
||||
make.height.equalTo(44)
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
@@ -482,5 +514,13 @@ private final class DroneDockHomeHeader: UICollectionReusableView {
|
||||
func apply(title: String, isOrders: Bool) {
|
||||
label.text = title
|
||||
label.accessibilityIdentifier = isOrders ? "drone.home.orderCount" : nil
|
||||
viewAllButton.isHidden = !isOrders
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
onViewAll = nil
|
||||
}
|
||||
|
||||
@objc private func viewAllTapped() { onViewAll?() }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 当前账号在景区内的真实拍摄订单,支持履约状态筛选与分页。
|
||||
@MainActor
|
||||
final class DroneDockOrdersViewController: BaseViewController {
|
||||
/// 与首页共享接口及身份范围、独立维护分页的列表状态。
|
||||
let viewModel: DroneDockOrdersViewModel
|
||||
private let preparationControllerFactory: (DroneDockHomeOrder, DroneDockHomeContext) -> UIViewController
|
||||
private let countLabel = DroneDockStyle.label(size: 17, weight: .semibold)
|
||||
private let descriptionLabel = DroneDockStyle.label("分配给我的全部订单,含已完成订单", size: 12, color: DroneDockStyle.secondary)
|
||||
private let filterView = DroneShootingOrderFilterView()
|
||||
private lazy var collectionView = UICollectionView(frame: .zero, collectionViewLayout: makeLayout())
|
||||
private var dataSource: UICollectionViewDiffableDataSource<Int, Item>!
|
||||
private var loadTask: Task<Void, Never>?
|
||||
private var operation: LoadAction?
|
||||
|
||||
/// 使用订单号更新同一张卡片,空态和分页入口也纳入快照。
|
||||
private enum Item: Hashable { case order(String), message, more }
|
||||
/// 刷新替换整页,翻页保留已加载订单。
|
||||
private enum LoadAction: Equatable { case refresh, more, filter(DroneShootingOrderFilter) }
|
||||
|
||||
/// 注入真实订单服务及与首页一致的拍摄准备入口。
|
||||
init(viewModel: DroneDockOrdersViewModel,
|
||||
preparationControllerFactory: @escaping (DroneDockHomeOrder, DroneDockHomeContext) -> UIViewController) {
|
||||
self.viewModel = viewModel
|
||||
self.preparationControllerFactory = preparationControllerFactory
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
hidesBottomBarWhenPushed = true
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
deinit { loadTask?.cancel() }
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = "我的拍摄订单"
|
||||
navigationItem.backButtonDisplayMode = .minimal
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
view.backgroundColor = DroneDockStyle.background
|
||||
countLabel.accessibilityIdentifier = "drone.orders.count"
|
||||
descriptionLabel.numberOfLines = 0
|
||||
collectionView.backgroundColor = .clear
|
||||
collectionView.alwaysBounceVertical = true
|
||||
collectionView.accessibilityIdentifier = "drone.orders.remote.list"
|
||||
collectionView.register(DroneShootingOrderCell.self, forCellWithReuseIdentifier: "order")
|
||||
collectionView.register(DroneDockOrdersStateCell.self, forCellWithReuseIdentifier: "state")
|
||||
let refresh = UIRefreshControl()
|
||||
refresh.tintColor = DroneDockStyle.primary
|
||||
refresh.addTarget(self, action: #selector(refreshTriggered), for: .valueChanged)
|
||||
collectionView.refreshControl = refresh
|
||||
[countLabel, descriptionLabel, filterView, collectionView].forEach(view.addSubview)
|
||||
configureDataSource()
|
||||
applySnapshot(animated: false)
|
||||
}
|
||||
|
||||
override func setupConstraints() {
|
||||
descriptionLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(view.safeAreaLayoutGuide).offset(12)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
}
|
||||
filterView.snp.makeConstraints { make in
|
||||
make.top.equalTo(descriptionLabel.snp.bottom).offset(12)
|
||||
make.leading.trailing.equalToSuperview()
|
||||
make.height.equalTo(50)
|
||||
}
|
||||
countLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(filterView.snp.bottom).offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
}
|
||||
collectionView.snp.makeConstraints { make in
|
||||
make.top.equalTo(countLabel.snp.bottom).offset(16)
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
override func bindActions() {
|
||||
filterView.onFilterSelected = { [weak self] filter in
|
||||
guard let self, filter != self.viewModel.selectedFilter else { return }
|
||||
self.load(.filter(filter))
|
||||
}
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
load(.refresh)
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
loadTask?.cancel()
|
||||
operation = nil
|
||||
collectionView.refreshControl?.endRefreshing()
|
||||
viewModel.invalidate()
|
||||
}
|
||||
|
||||
private func configureDataSource() {
|
||||
dataSource = UICollectionViewDiffableDataSource<Int, Item>(collectionView: collectionView) { [weak self] collection, path, item in
|
||||
guard let self else { return nil }
|
||||
if case .order(let id) = item {
|
||||
let cell = collection.dequeueReusableCell(withReuseIdentifier: "order", for: path) as! DroneShootingOrderCell
|
||||
if let order = self.viewModel.orders.first(where: { $0.orderID == id }) {
|
||||
cell.accessibilityIdentifier = "drone.orders.order.\(id)"
|
||||
cell.cardView.apply(homeOrder: order)
|
||||
cell.cardView.onShootingTap = { [weak self] in self?.openPreparation(orderID: id) }
|
||||
cell.cardView.onMaterialsTap = { [weak self] in self?.showUnavailable("订单素材") }
|
||||
cell.cardView.onDeliveryTap = { [weak self] in self?.showUnavailable("交付成片") }
|
||||
cell.cardView.onConfirmationTap = { [weak self] in self?.showUnavailable("交付确认") }
|
||||
}
|
||||
return cell
|
||||
}
|
||||
let cell = collection.dequeueReusableCell(withReuseIdentifier: "state", for: path) as! DroneDockOrdersStateCell
|
||||
if item == .more {
|
||||
cell.apply(message: self.viewModel.loadMoreErrorMessage,
|
||||
buttonTitle: self.operation == .more ? "加载中…" : self.viewModel.loadMoreErrorMessage == nil ? "加载更多订单" : "重试加载更多",
|
||||
identifier: "drone.orders.loadMore", enabled: self.operation == nil) { [weak self] in self?.load(.more) }
|
||||
} else if self.operation != nil || self.viewModel.isLoading {
|
||||
cell.apply(message: "正在加载拍摄订单")
|
||||
} else if let error = self.viewModel.errorMessage {
|
||||
cell.apply(message: "订单加载失败\n\(error)", buttonTitle: "重试", identifier: "drone.orders.retry") { [weak self] in self?.load(.refresh) }
|
||||
} else {
|
||||
let title = self.viewModel.selectedFilter == .all ? "暂无拍摄订单" : "暂无\(self.viewModel.selectedFilter.title)订单"
|
||||
cell.apply(message: "\(title)\n请下拉刷新或切换其他分类查看")
|
||||
}
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
||||
private func makeLayout() -> UICollectionViewLayout {
|
||||
let size = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(320))
|
||||
let item = NSCollectionLayoutItem(layoutSize: size)
|
||||
let group = NSCollectionLayoutGroup.vertical(layoutSize: size, subitems: [item])
|
||||
let section = NSCollectionLayoutSection(group: group)
|
||||
section.interGroupSpacing = 12
|
||||
section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: 24, trailing: 16)
|
||||
return UICollectionViewCompositionalLayout(section: section)
|
||||
}
|
||||
|
||||
private func applySnapshot(animated: Bool) {
|
||||
guard dataSource != nil else { return }
|
||||
let isSwitching: Bool
|
||||
let filter: DroneShootingOrderFilter
|
||||
if case .filter(let selected) = operation { filter = selected; isSwitching = true }
|
||||
else { filter = viewModel.selectedFilter; isSwitching = false }
|
||||
filterView.apply(selectedFilter: filter)
|
||||
countLabel.text = !isSwitching ? viewModel.total.map { "\(filter.listTitle)(\($0))" } ?? filter.listTitle : filter.listTitle
|
||||
var snapshot = NSDiffableDataSourceSnapshot<Int, Item>()
|
||||
snapshot.appendSections([0])
|
||||
snapshot.appendItems(isSwitching || viewModel.orders.isEmpty ? [.message] : viewModel.orders.map { .order($0.orderID) })
|
||||
if !isSwitching && (viewModel.hasMore || viewModel.loadMoreErrorMessage != nil || operation == .more) {
|
||||
snapshot.appendItems([.more])
|
||||
}
|
||||
let previous = Set(dataSource.snapshot().itemIdentifiers)
|
||||
snapshot.reconfigureItems(snapshot.itemIdentifiers.filter { previous.contains($0) })
|
||||
dataSource.apply(snapshot, animatingDifferences: animated)
|
||||
}
|
||||
|
||||
private func load(_ action: LoadAction) {
|
||||
if action == .more {
|
||||
guard operation == nil, viewModel.hasMore else { return }
|
||||
}
|
||||
loadTask?.cancel()
|
||||
operation = action
|
||||
applySnapshot(animated: false)
|
||||
loadTask = Task { @MainActor [weak self] in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .refresh: await self.viewModel.refresh()
|
||||
case .more: await self.viewModel.loadMore()
|
||||
case .filter(let filter): await self.viewModel.selectFilter(filter)
|
||||
}
|
||||
guard !Task.isCancelled else { return }
|
||||
self.operation = nil
|
||||
self.collectionView.refreshControl?.endRefreshing()
|
||||
self.applySnapshot(animated: true)
|
||||
if case .filter = action {
|
||||
self.collectionView.setContentOffset(CGPoint(x: 0, y: -self.collectionView.adjustedContentInset.top), animated: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func openPreparation(orderID: String) {
|
||||
guard operation == nil, let order = viewModel.orders.first(where: { $0.orderID == orderID }) else { return }
|
||||
guard order.primaryAction == "start_shoot" else {
|
||||
showUnavailable(order.actionTitle ?? "拍摄订单")
|
||||
return
|
||||
}
|
||||
guard DroneDockHomeMetric.usableText(order.orderNumber) != nil else {
|
||||
showAlert(title: "拍摄准备", message: "缺少订单号,请刷新拍摄订单后重试")
|
||||
return
|
||||
}
|
||||
let controller = preparationControllerFactory(order, viewModel.context)
|
||||
navigationController?.pushViewController(controller, animated: true)
|
||||
}
|
||||
|
||||
private func showUnavailable(_ feature: String) { showAlert(title: feature, message: "该功能暂未开放") }
|
||||
|
||||
@objc private func refreshTriggered() { load(.refresh) }
|
||||
}
|
||||
|
||||
/// 真实订单列表的加载、空态、错误重试及分页入口。
|
||||
private final class DroneDockOrdersStateCell: UICollectionViewCell {
|
||||
private let messageLabel = DroneDockStyle.label(size: 13, color: DroneDockStyle.secondary)
|
||||
private let button = UIButton(type: .system)
|
||||
private var onTap: (() -> Void)?
|
||||
|
||||
/// 消息与操作按钮共同撑开自适应列表行。
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
messageLabel.numberOfLines = 0
|
||||
messageLabel.textAlignment = .center
|
||||
button.tintColor = DroneDockStyle.primary
|
||||
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
|
||||
button.snp.makeConstraints { $0.height.equalTo(44).priority(999) }
|
||||
let stack = UIStackView(arrangedSubviews: [messageLabel, button])
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 12
|
||||
contentView.addSubview(stack)
|
||||
stack.snp.makeConstraints { $0.edges.equalToSuperview().inset(UIEdgeInsets(top: 20, left: 16, bottom: 20, right: 16)) }
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
/// 复用时完整替换消息和操作,纯提示不占按钮空间。
|
||||
func apply(message: String?, buttonTitle: String? = nil, identifier: String? = nil,
|
||||
enabled: Bool = true, onTap: (() -> Void)? = nil) {
|
||||
messageLabel.text = message
|
||||
messageLabel.isHidden = message == nil
|
||||
button.setTitle(buttonTitle, for: .normal)
|
||||
button.isHidden = buttonTitle == nil
|
||||
button.isEnabled = enabled
|
||||
button.accessibilityIdentifier = identifier
|
||||
self.onTap = onTap
|
||||
}
|
||||
|
||||
@objc private func buttonTapped() { onTap?() }
|
||||
}
|
||||
@@ -35,6 +35,7 @@ final class DroneShootingOrderCardView: UIView {
|
||||
private let secondaryButton = UIButton(type: .system)
|
||||
private let primaryButton = UIButton(type: .system)
|
||||
private var displayedOrder: DroneShootingOrder?
|
||||
private var displayedHomeOrder: DroneDockHomeOrder?
|
||||
|
||||
/// 创建可以按内容自行撑高的白色圆角订单卡。
|
||||
override init(frame: CGRect) {
|
||||
@@ -50,6 +51,17 @@ final class DroneShootingOrderCardView: UIView {
|
||||
/// 应用完整订单快照;卡片不推断或修改订单及任务状态。
|
||||
func apply(order: DroneShootingOrder) {
|
||||
displayedOrder = order
|
||||
displayedHomeOrder = nil
|
||||
materialControl.isEnabled = true
|
||||
materialControl.accessibilityIdentifier = nil
|
||||
deliveryControl.isEnabled = true
|
||||
deliveryChevron.isHidden = false
|
||||
actionStack.isHidden = false
|
||||
primaryButton.isHidden = false
|
||||
primaryButton.isEnabled = true
|
||||
primaryButton.backgroundColor = DroneDockStyle.primary
|
||||
secondaryButton.isHidden = false
|
||||
secondaryButton.isEnabled = true
|
||||
customerLabel.text = order.customerName
|
||||
metadataLabel.text = "\(order.orderNumber) · \(order.createdAtText)"
|
||||
packageLabel.text = order.packageSummary
|
||||
@@ -58,12 +70,57 @@ final class DroneShootingOrderCardView: UIView {
|
||||
remainingLabel.attributedText = remainingText(order: order)
|
||||
progressView.setProgress(Float(order.progress), animated: false)
|
||||
progressView.accessibilityLabel = "已拍摄 \(order.successfulShootingCount) 次,共 \(order.totalShootingCount) 次"
|
||||
applyStatusAppearance(order: order)
|
||||
applyStatusAppearance(tone: order.statusTone)
|
||||
applyMaterialSummary(order: order)
|
||||
applyActions(order: order)
|
||||
accessibilityIdentifier = "drone.order.\(order.id)"
|
||||
}
|
||||
|
||||
/// 展示张工订单摘要中的真实字段和操作权限,不推导飞行任务或交付完成。
|
||||
func apply(homeOrder order: DroneDockHomeOrder) {
|
||||
displayedOrder = nil
|
||||
displayedHomeOrder = order
|
||||
let identifier = "drone.orders.order.\(order.orderID)"
|
||||
customerLabel.text = order.touristTitle
|
||||
let createdAt = DroneDockHomeMetric.usableText(order.createdAt) ?? "创建时间待确认"
|
||||
metadataLabel.text = "订单号 \(order.orderNumberText) · \(createdAt)"
|
||||
packageLabel.text = order.packageTitle
|
||||
statusLabel.text = order.statusTitle
|
||||
let tone: DroneDockStatusTone = switch order.shootStatus {
|
||||
case "pending": .blue
|
||||
case "processing": .orange
|
||||
case "completed": .green
|
||||
default: .gray
|
||||
}
|
||||
applyStatusAppearance(tone: tone)
|
||||
|
||||
let used = order.shotUsed.map(String.init) ?? "—"
|
||||
let total = order.shotTotal.map(String.init) ?? "—"
|
||||
let remaining = order.shotRemain.map(String.init) ?? "—"
|
||||
countsLabel.attributedText = countText(prefix: "已拍摄 ", value: used, suffix: " / \(total) 次")
|
||||
remainingLabel.attributedText = countText(prefix: "剩余 ", value: remaining, suffix: " 次")
|
||||
if let used = order.shotUsed, let total = order.shotTotal, total > 0 {
|
||||
progressView.setProgress(Float(min(Double(used) / Double(total), 1)), animated: false)
|
||||
progressView.accessibilityLabel = "已拍摄 \(used) 次,共 \(total) 次"
|
||||
} else {
|
||||
progressView.setProgress(0, animated: false)
|
||||
progressView.accessibilityLabel = "拍摄进度待确认"
|
||||
}
|
||||
applyRemoteSummary(order: order, identifier: identifier)
|
||||
applyRemoteActions(order: order, identifier: identifier)
|
||||
accessibilityIdentifier = identifier
|
||||
}
|
||||
|
||||
/// 清除复用卡片中的订单及所有动作,避免点击到上一笔订单。
|
||||
func resetForReuse() {
|
||||
displayedOrder = nil
|
||||
displayedHomeOrder = nil
|
||||
onShootingTap = nil
|
||||
onMaterialsTap = nil
|
||||
onDeliveryTap = nil
|
||||
onConfirmationTap = nil
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
DroneDockStyle.applyCard(to: self)
|
||||
|
||||
@@ -157,7 +214,7 @@ final class DroneShootingOrderCardView: UIView {
|
||||
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .semibold)
|
||||
button.titleLabel?.adjustsFontSizeToFitWidth = true
|
||||
button.titleLabel?.minimumScaleFactor = 0.85
|
||||
button.snp.makeConstraints { make in make.height.equalTo(44) }
|
||||
button.snp.makeConstraints { make in make.height.equalTo(44).priority(999) }
|
||||
}
|
||||
secondaryButton.backgroundColor = UIColor(hex: 0xECF3FF)
|
||||
secondaryButton.setTitleColor(DroneDockStyle.primary, for: .normal)
|
||||
@@ -204,10 +261,10 @@ final class DroneShootingOrderCardView: UIView {
|
||||
control.accessibilityTraits = .button
|
||||
}
|
||||
|
||||
private func applyStatusAppearance(order: DroneShootingOrder) {
|
||||
private func applyStatusAppearance(tone: DroneDockStatusTone) {
|
||||
let foreground: UIColor
|
||||
let background: UIColor
|
||||
switch order.statusTone {
|
||||
switch tone {
|
||||
case .blue:
|
||||
foreground = DroneDockStyle.primary
|
||||
background = UIColor(hex: 0xECF3FF)
|
||||
@@ -228,6 +285,48 @@ final class DroneShootingOrderCardView: UIView {
|
||||
statusContainer.backgroundColor = background
|
||||
}
|
||||
|
||||
private func applyRemoteSummary(order: DroneDockHomeOrder, identifier: String) {
|
||||
materialRow.isHidden = false
|
||||
materialControl.isHidden = false
|
||||
materialControl.isEnabled = true
|
||||
materialTitleLabel.text = "查看素材"
|
||||
materialStateLabel.text = order.mediaStatusTitle ?? "素材状态待确认"
|
||||
materialStateLabel.textColor = order.materialStatus == 3 ? UIColor(hex: 0xC26962) : UIColor(hex: 0x8992A3)
|
||||
materialChevron.isHidden = false
|
||||
materialControl.accessibilityIdentifier = identifier + ".materials"
|
||||
materialControl.accessibilityLabel = "查看素材,\(materialStateLabel.text ?? "")"
|
||||
|
||||
deliveryControl.isHidden = false
|
||||
deliveryControl.isEnabled = order.canConfirm == true || order.confirmStatus == 2
|
||||
deliveryChevron.isHidden = !deliveryControl.isEnabled
|
||||
let confirmation: String = switch order.confirmStatus {
|
||||
case 0: "未发起确认"
|
||||
case 1: "待游客确认"
|
||||
case 2: "已确认完成"
|
||||
default: "确认状态待确认"
|
||||
}
|
||||
deliveryTitleLabel.text = order.canConfirm == true ? "邀请确认" : order.confirmStatus == 2 ? "查看记录" : confirmation
|
||||
deliveryStateLabel.text = "已交付 \(order.filmCount.map(String.init) ?? "—") 个视频"
|
||||
deliveryControl.accessibilityIdentifier = identifier + ".confirmation"
|
||||
deliveryControl.accessibilityLabel = "\(deliveryTitleLabel.text ?? ""),\(deliveryStateLabel.text ?? ""),\(confirmation)"
|
||||
}
|
||||
|
||||
private func applyRemoteActions(order: DroneDockHomeOrder, identifier: String) {
|
||||
let canShoot = order.canCreateTask == true
|
||||
let canConfirm = order.canConfirm == true
|
||||
let canDeliver = order.canUploadFilm == true
|
||||
primaryButton.isHidden = !canShoot && !canConfirm && !canDeliver
|
||||
primaryButton.isEnabled = !primaryButton.isHidden
|
||||
primaryButton.backgroundColor = DroneDockStyle.primary
|
||||
primaryButton.setTitle(canShoot ? "开始拍摄" : canConfirm ? "邀请确认" : "交付成片", for: .normal)
|
||||
primaryButton.accessibilityIdentifier = identifier + ".primary"
|
||||
secondaryButton.isHidden = !canDeliver || (!canShoot && !canConfirm)
|
||||
secondaryButton.isEnabled = !secondaryButton.isHidden
|
||||
secondaryButton.setTitle("交付成片", for: .normal)
|
||||
secondaryButton.accessibilityIdentifier = identifier + ".delivery"
|
||||
actionStack.isHidden = primaryButton.isHidden && secondaryButton.isHidden
|
||||
}
|
||||
|
||||
private func applyMaterialSummary(order: DroneShootingOrder) {
|
||||
materialRow.isHidden = !order.hasMaterials && order.deliveredVideoCount == 0
|
||||
materialControl.isHidden = !order.hasMaterials
|
||||
@@ -285,7 +384,23 @@ final class DroneShootingOrderCardView: UIView {
|
||||
return text
|
||||
}
|
||||
|
||||
private func countText(prefix: String, value: String, suffix: String) -> NSAttributedString {
|
||||
let attributes: [NSAttributedString.Key: Any] = [.foregroundColor: UIColor(hex: 0x69717F)]
|
||||
let text = NSMutableAttributedString(string: prefix, attributes: attributes)
|
||||
text.append(NSAttributedString(string: value, attributes: [
|
||||
.foregroundColor: DroneDockStyle.primary,
|
||||
.font: UIFont.systemFont(ofSize: 12, weight: .medium)
|
||||
]))
|
||||
text.append(NSAttributedString(string: suffix, attributes: attributes))
|
||||
return text
|
||||
}
|
||||
|
||||
@objc private func secondaryTapped() {
|
||||
if let order = displayedHomeOrder {
|
||||
guard !secondaryButton.isHidden, secondaryButton.isEnabled, order.canUploadFilm == true else { return }
|
||||
onDeliveryTap?()
|
||||
return
|
||||
}
|
||||
guard let displayedOrder else { return }
|
||||
if displayedOrder.primaryAction == .none {
|
||||
onMaterialsTap?()
|
||||
@@ -295,6 +410,13 @@ final class DroneShootingOrderCardView: UIView {
|
||||
}
|
||||
|
||||
@objc private func primaryTapped() {
|
||||
if let order = displayedHomeOrder {
|
||||
guard !primaryButton.isHidden, primaryButton.isEnabled else { return }
|
||||
if order.canCreateTask == true { onShootingTap?() }
|
||||
else if order.canConfirm == true { onConfirmationTap?() }
|
||||
else if order.canUploadFilm == true { onDeliveryTap?() }
|
||||
return
|
||||
}
|
||||
guard let displayedOrder else { return }
|
||||
if displayedOrder.primaryAction == .none {
|
||||
onDeliveryTap?()
|
||||
@@ -303,8 +425,15 @@ final class DroneShootingOrderCardView: UIView {
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func materialsTapped() { onMaterialsTap?() }
|
||||
@objc private func confirmationTapped() { onConfirmationTap?() }
|
||||
@objc private func materialsTapped() {
|
||||
guard displayedOrder != nil || displayedHomeOrder != nil else { return }
|
||||
onMaterialsTap?()
|
||||
}
|
||||
@objc private func confirmationTapped() {
|
||||
if displayedHomeOrder != nil, !deliveryControl.isEnabled { return }
|
||||
guard displayedOrder != nil || displayedHomeOrder != nil else { return }
|
||||
onConfirmationTap?()
|
||||
}
|
||||
}
|
||||
|
||||
/// Diffable 订单列表使用的自适应高度容器。
|
||||
@@ -329,8 +458,6 @@ final class DroneShootingOrderCell: UICollectionViewCell {
|
||||
/// 清除上一订单动作,避免复用时调用旧订单。
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
cardView.onShootingTap = nil
|
||||
cardView.onMaterialsTap = nil
|
||||
cardView.onDeliveryTap = nil
|
||||
cardView.resetForReuse()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user