fix: 优化点位展示、选择滚动和收款信息

This commit is contained in:
2026-11-04 11:13:12 +08:00
parent 7a63ea3432
commit 1c766ff12f
7 changed files with 116 additions and 38 deletions
@@ -153,7 +153,7 @@ final class DroneDockDeliveryViewController: BaseViewController {
if case .point(let id) = item {
let cell = list.dequeueReusableCell(withReuseIdentifier: "point", for: path) as! DroneMaterialFilterCell
let title = self.viewModel.spots.first { $0.id == id }.map { Self.text($0.name, fallback: "点位 \(id)") } ?? "点位 \(id)"
cell.apply(title: title, id: String(id), selected: self.viewModel.selectedSpotID == id, locked: self.locked)
cell.apply(title: title, id: String(id), selected: self.viewModel.selectedSpotID == id, locked: self.locked, wrapsTitle: true)
cell.accessibilityIdentifier = "drone.delivery.point.\(id)"
return cell
}
@@ -207,11 +207,30 @@ final class DroneDockDeliveryViewController: BaseViewController {
private var locked: Bool { isRefreshing || isPicking || isStartingSubmission || viewModel.isLoading || viewModel.isSubmitting }
private func makeLayout() -> UICollectionViewLayout {
UICollectionViewCompositionalLayout { [weak self] index, _ in
UICollectionViewCompositionalLayout { [weak self] index, environment in
guard let self, let source = self.dataSource else { return nil }
let sections = source.snapshot().sectionIdentifiers
guard sections.indices.contains(index) else { return nil }
let points = sections[index] == .points
if points, !self.viewModel.spots.isEmpty {
let maximumWidth = min(200, max(1, environment.container.effectiveContentSize.width - 32))
let sizes = self.viewModel.spots.map {
DroneMaterialFilterCell.wrappedSize(title: Self.text($0.name, fallback: "点位 \($0.id)"), maximumWidth: maximumWidth)
}
let width = sizes.reduce(0) { $0 + $1.width } + CGFloat(sizes.count - 1) * 10
let height = sizes.map(\.height).max() ?? 40
let group = NSCollectionLayoutGroup.custom(layoutSize: .init(widthDimension: .absolute(width), heightDimension: .absolute(height))) { _ in
var x: CGFloat = 0
return sizes.map { size in
defer { x += size.width + 10 }
return NSCollectionLayoutGroupCustomItem(frame: CGRect(x: x, y: 0, width: size.width, height: size.height))
}
}
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = .init(top: 0, leading: 16, bottom: 12, trailing: 16)
section.orthogonalScrollingBehavior = .continuous
return section
}
let size = NSCollectionLayoutSize(widthDimension: points ? .estimated(112) : .fractionalWidth(1), heightDimension: points ? .absolute(40) : .estimated(100))
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: points ? .fractionalHeight(1) : .estimated(100)))
let group = NSCollectionLayoutGroup.vertical(layoutSize: size, subitems: [item])
@@ -242,6 +261,7 @@ final class DroneDockDeliveryViewController: BaseViewController {
snapshot.appendItems([.state], toSection: .state)
let previous = Set(dataSource.snapshot().itemIdentifiers)
snapshot.reconfigureItems(snapshot.itemIdentifiers.filter { previous.contains($0) })
collectionView.collectionViewLayout.invalidateLayout()
dataSource.apply(snapshot, animatingDifferences: animated)
updateFooter()
}
@@ -38,15 +38,14 @@ final class DroneDockPaymentViewController: BaseViewController {
private let placeholderDetail = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
private let retryButton = UIButton(type: .system)
private let reloadImageButton = UIButton(type: .system)
private let regenerateButton = UIButton(type: .system)
private let retryProjectsButton = UIButton(type: .system)
private let spinner = UIActivityIndicatorView(style: .medium)
private let paymentHint = DroneDockStyle.label("请游客使用微信扫码,到账后核对收款记录\n付款码有效 7 天,失效时请重新生成", size: 11, color: DroneDockStyle.secondary)
private let setAmountButton = UIButton(type: .system)
private let saveButton = UIButton(type: .system)
private let checkReceiptsButton = UIButton(type: .system)
private let recordsButton = UIButton(type: .system)
private let staffValue = DroneDockStyle.label(size: 13)
private let merchantValue = DroneDockStyle.label(size: 13)
private let scenicValue = DroneDockStyle.label(size: 13)
private let voiceSwitch = UISwitch()
@@ -246,11 +245,6 @@ final class DroneDockPaymentViewController: BaseViewController {
paymentHint.numberOfLines = 0
paymentHint.textAlignment = .center
stack.addArrangedSubview(paymentHint)
configureButton(checkReceiptsButton, title: "刷新收款记录", identifier: "drone.payment.refreshReceipts", action: #selector(checkReceipts))
configureButton(regenerateButton, title: "重新生成", identifier: "drone.payment.regenerateCode", action: #selector(regenerateCode))
let codeActions = UIStackView(arrangedSubviews: [checkReceiptsButton, regenerateButton])
codeActions.distribution = .fillEqually
stack.addArrangedSubview(codeActions)
configureButton(setAmountButton, title: "设置金额", identifier: "drone.payment.setAmount", action: #selector(setAmountTapped))
configureButton(saveButton, title: "保存二维码", identifier: "drone.payment.saveQR", action: #selector(saveTapped))
let actions = UIStackView(arrangedSubviews: [setAmountButton, saveButton])
@@ -266,7 +260,9 @@ final class DroneDockPaymentViewController: BaseViewController {
stack.spacing = 14
stack.addArrangedSubview(infoRow("景区名称", value: scenicValue))
stack.addArrangedSubview(line())
stack.addArrangedSubview(infoRow("收款方", value: DroneDockStyle.label("—", size: 13)))
merchantValue.accessibilityIdentifier = "drone.payment.merchant"
staffValue.accessibilityIdentifier = "drone.payment.staff"
stack.addArrangedSubview(infoRow("收款方", value: merchantValue))
stack.addArrangedSubview(line())
stack.addArrangedSubview(infoRow("员工 ID", value: staffValue))
return card(stack, insets: 16)
@@ -330,7 +326,8 @@ final class DroneDockPaymentViewController: BaseViewController {
projectButton.isEnabled = !isLoadingProjectRequest && !viewModel.isLoadingProjects && !isUpdatingCode
amountLabel.isHidden = code == nil
amountLabel.text = code.map { "本次收款 ¥\(Self.money($0.price))" }
staffValue.text = code.map { String($0.storeUserID) } ?? "—"
merchantValue.text = PaymentMerchantInfo.defaultInfo.company
staffValue.text = hasCurrentContext ? DroneDockHomeMetric.usableText(viewModel.context.userID) ?? "—" : "—"
let showingProgress = busy || isLoadingImage
if showingProgress { spinner.startAnimating() } else { spinner.stopAnimating() }
spinner.isHidden = !showingProgress
@@ -365,9 +362,6 @@ final class DroneDockPaymentViewController: BaseViewController {
qrImageView.isHidden = !hasImage
placeholder.isHidden = hasImage
paymentHint.isHidden = code == nil
checkReceiptsButton.isHidden = code == nil
regenerateButton.isHidden = code == nil
regenerateButton.isEnabled = code != nil
setAmountButton.isEnabled = code != nil
saveButton.isEnabled = hasImage
setAmountButton.alpha = code != nil ? 1 : 0.4
@@ -506,11 +500,6 @@ final class DroneDockPaymentViewController: BaseViewController {
applyState()
}
@objc private func regenerateCode() {
guard let code = viewModel.payCode, !isUpdatingCode, !isLoadingProjectRequest else { return }
generateCode(projectID: code.projectID, price: Self.money(code.price))
}
@objc private func setAmountTapped() {
guard let code = viewModel.payCode, !isUpdatingCode else { return }
guard viewModel.context.hasSameIdentity(as: currentContext()) else {
@@ -557,7 +546,6 @@ final class DroneDockPaymentViewController: BaseViewController {
}
@objc private func recordsTapped() { navigationController?.pushViewController(makeReceiptsController(), animated: true) }
@objc private func checkReceipts() { navigationController?.pushViewController(makeReceiptsController(projectID: viewModel.payCode?.projectID), animated: true) }
@objc private func voiceChanged() { AppStore.shared.payment.isOpenReceiveVoice = voiceSwitch.isOn }
@objc private func offlineTapped() { navigationController?.pushViewController(OfflineCollectionRegistrationViewController(), animated: true) }
@@ -485,7 +485,16 @@ extension DroneDockRemotePreparationViewController: UICollectionViewDelegate {
viewModel.createdTask == nil, !viewModel.taskCreationOutcomeUnknown,
let item = dataSource.itemIdentifier(for: indexPath) else { return }
switch item {
case .point(let id): viewModel.selectSpot(id: id)
case .point(let id):
viewModel.selectSpot(id: id)
applySnapshot(animated: true) { [weak self] in
guard let self, self.viewModel.selectedSpotID == id,
let path = self.dataSource.indexPath(for: .point(id)) else { return }
let pointsWidth = CGFloat(self.viewModel.spots.count) * 200 + CGFloat(max(0, self.viewModel.spots.count - 1)) * 8 + 32
guard pointsWidth > collectionView.bounds.width else { return }
collectionView.scrollToItem(at: path, at: .centeredHorizontally, animated: true)
}
return
case .route(let id): viewModel.selectRoute(id: id)
default: return
}
@@ -69,7 +69,9 @@ final class DroneMaterialFilterCell: UICollectionViewCell {
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 映射筛选名称、选中态与交互许可。
func apply(title: String, id: String?, selected: Bool, locked: Bool) {
func apply(title: String, id: String?, selected: Bool, locked: Bool, wrapsTitle: Bool = false) {
titleLabel.numberOfLines = wrapsTitle ? 0 : 1
titleLabel.lineBreakMode = wrapsTitle ? .byWordWrapping : .byTruncatingTail
titleLabel.text = title
titleLabel.textColor = selected ? DroneDockStyle.primary : UIColor(hex: 0x677183)
contentView.backgroundColor = selected ? DroneDockStyle.primary.withAlphaComponent(0.09) : .white
@@ -82,6 +84,15 @@ final class DroneMaterialFilterCell: UICollectionViewCell {
if locked { traits.insert(.notEnabled) }
accessibilityTraits = traits
}
/// 云端交付点位在限定宽度内完整换行,短名称保留紧凑卡片。
static func wrappedSize(title: String, maximumWidth: CGFloat) -> CGSize {
let font = UIFont.systemFont(ofSize: 13, weight: .medium)
let width = min(maximumWidth, ceil((title as NSString).size(withAttributes: [.font: font]).width) + 10)
let bounds = (title as NSString).boundingRect(with: CGSize(width: max(1, width - 10), height: .greatestFiniteMagnitude),
options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font: font], context: nil)
return CGSize(width: width, height: max(40, ceil(bounds.height) + 10))
}
}
/// 点位限定入口的只读提示,不将当前任务点位伪装成可切换筛选。