Files
suixinkan_uikit/suixinkan/UI/DroneDock/DroneDockCompactOrderCell.swift
T

119 lines
5.8 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.
import SnapKit
import UIKit
/// 工作台沿用紧凑订单卡;当前任务只改变按钮标题及右上角状态。
final class DroneDockCompactOrderCell: UICollectionViewCell {
/// 返回该订单的拍摄或当前任务入口。
var onShootingTap: (() -> Void)?
/// 返回该订单原素材入口。
var onMaterialsTap: (() -> Void)?
private let customerLabel = DroneDockStyle.label(size: 16, weight: .bold)
private let statusLabel = DroneDockStatusLabel()
private let packageLabel = DroneDockStyle.label(size: 13, color: UIColor(hex: 0x666E7C))
private let countsLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
private let actionButton = UIButton(type: .system)
private let materialButton = UIButton(type: .system)
private let footer = UIView()
/// 创建紧凑卡片及可选素材栏。
override init(frame: CGRect) {
super.init(frame: frame)
DroneDockStyle.applyCard(to: contentView)
setupUI()
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 应用数据,不展示具体点位或航线,也不在卡片自行扣次。
func apply(order: DroneShootingOrder) {
customerLabel.text = order.customerName
statusLabel.apply(title: order.statusTitle, tone: order.statusTone)
packageLabel.text = order.packageSummary
countsLabel.text = "已拍摄 \(order.successfulShootingCount)/\(order.totalShootingCount) 次 · 剩余 \(order.remainingShootingCount) 次"
actionButton.setTitle(order.primaryAction.title, for: .normal)
actionButton.isEnabled = order.primaryActionEnabled
actionButton.accessibilityIdentifier = "drone.home.\(order.id).primary"
footer.isHidden = !order.hasMaterials
var configuration = UIButton.Configuration.plain()
configuration.image = UIImage(systemName: order.materialState.systemImageName)
configuration.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 15)
configuration.imagePadding = 6
configuration.title = order.materialState.title
configuration.baseForegroundColor = DroneDockStyle.color(for: order.materialState.tone)
configuration.contentInsets = .zero
configuration.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
var attributes = attributes
attributes.font = .systemFont(ofSize: 11)
return attributes
}
materialButton.configuration = configuration
materialButton.accessibilityLabel = "查看素材,\(order.materialState.title)"
accessibilityIdentifier = "drone.home.\(order.id)"
}
override func prepareForReuse() {
super.prepareForReuse()
onShootingTap = nil
onMaterialsTap = nil
}
private func setupUI() {
customerLabel.adjustsFontSizeToFitWidth = true
customerLabel.minimumScaleFactor = 0.75
customerLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
let titleRow = UIStackView(arrangedSubviews: [customerLabel, statusLabel])
titleRow.alignment = .center
titleRow.spacing = 8
let labels = UIStackView(arrangedSubviews: [packageLabel, countsLabel])
labels.axis = .vertical
labels.spacing = 9
packageLabel.adjustsFontSizeToFitWidth = true
packageLabel.minimumScaleFactor = 0.8
labels.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
actionButton.backgroundColor = DroneDockStyle.primary
actionButton.setTitleColor(.white, for: .normal)
actionButton.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
actionButton.titleLabel?.adjustsFontSizeToFitWidth = true
actionButton.titleLabel?.minimumScaleFactor = 0.8
actionButton.layer.cornerRadius = 8
actionButton.addTarget(self, action: #selector(shootingTapped), for: .touchUpInside)
actionButton.snp.makeConstraints { make in make.width.equalTo(106); make.height.equalTo(42) }
let body = UIStackView(arrangedSubviews: [labels, actionButton])
body.spacing = 10
body.alignment = .center
let divider = UIView()
divider.backgroundColor = DroneDockStyle.border
footer.addSubview(divider)
footer.addSubview(materialButton)
materialButton.contentHorizontalAlignment = .leading
materialButton.addTarget(self, action: #selector(materialsTapped), for: .touchUpInside)
let viewButton = UIButton(type: .system)
viewButton.setTitle("查看素材 ›", for: .normal)
viewButton.titleLabel?.font = .systemFont(ofSize: 11)
viewButton.tintColor = DroneDockStyle.primary
viewButton.addTarget(self, action: #selector(materialsTapped), for: .touchUpInside)
footer.addSubview(viewButton)
divider.snp.makeConstraints { make in make.leading.trailing.top.equalToSuperview(); make.height.equalTo(0.5) }
materialButton.snp.makeConstraints { make in
make.leading.equalToSuperview()
make.bottom.equalToSuperview().priority(999)
make.top.equalTo(divider.snp.bottom).offset(7)
make.height.equalTo(26)
make.trailing.lessThanOrEqualTo(viewButton.snp.leading).offset(-8)
}
viewButton.snp.makeConstraints { make in make.centerY.equalTo(materialButton); make.trailing.equalToSuperview() }
let stack = UIStackView(arrangedSubviews: [titleRow, body, footer])
stack.axis = .vertical
stack.spacing = 12
contentView.addSubview(stack)
stack.snp.makeConstraints { make in make.edges.equalToSuperview().inset(16) }
}
@objc private func shootingTapped() { onShootingTap?() }
@objc private func materialsTapped() { onMaterialsTap?() }
}