feat(drone-dock): 对接我的拍摄订单筛选与分页
This commit is contained in:
@@ -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