实现订单 Tab 并接入扫码核销流程
This commit is contained in:
@ -12,6 +12,8 @@ final class MainTabBarController: UITabBarController {
|
||||
private var tabNavigationControllers: [AppTab: TabNavigationController] = [:]
|
||||
private var isSyncingTabSelection = false
|
||||
|
||||
private let scanHandler = MainTabScanHandler(api: NetworkServices.shared.orderAPI)
|
||||
|
||||
/// 测试时可注入扫码点击处理。
|
||||
var onScanTabSelected: (() -> Void)?
|
||||
|
||||
@ -47,6 +49,7 @@ final class MainTabBarController: UITabBarController {
|
||||
configureTabBarAppearance()
|
||||
configureTabs()
|
||||
bindBadgeViewModel()
|
||||
bindScanHandler()
|
||||
badgeViewModel.refreshPendingWriteOffCount()
|
||||
}
|
||||
|
||||
@ -118,10 +121,50 @@ final class MainTabBarController: UITabBarController {
|
||||
tabNavigationControllers[.orders]?.tabBarItem.badgeValue = badgeValue
|
||||
}
|
||||
|
||||
private func bindScanHandler() {
|
||||
scanHandler.onShowMessage = { [weak self] message in
|
||||
self?.showScanToast(message)
|
||||
}
|
||||
scanHandler.onShowSignIn = { [weak self] response in
|
||||
guard let self else { return }
|
||||
OrderSignInAlertController.present(from: self, response: response)
|
||||
}
|
||||
scanHandler.onShowWriteOff = { [weak self] response in
|
||||
guard let self else { return }
|
||||
WriteOffResultAlertController.present(from: self, response: response)
|
||||
}
|
||||
scanHandler.onShowMultiVerifySheet = { [weak self] spots, selected in
|
||||
self?.presentMultiVerifySheet(spots: spots, selected: selected)
|
||||
}
|
||||
}
|
||||
|
||||
private func showScanToast(_ message: String) {
|
||||
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
|
||||
present(alert, animated: true)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
|
||||
alert.dismiss(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
private func presentMultiVerifySheet(spots: [MultiTravelScenicSpotEntity], selected: MultiTravelScenicSpotEntity?) {
|
||||
let controller = MultiVerifyScenicSpotViewController(spots: spots, selected: selected)
|
||||
controller.onConfirm = { [weak self] spot in
|
||||
guard let self, let pending = self.scanHandler.pendingMultiVerify else { return }
|
||||
Task { await self.scanHandler.confirmMultiVerify(pending: pending, spot: spot) }
|
||||
}
|
||||
let nav = UINavigationController(rootViewController: controller)
|
||||
nav.modalPresentationStyle = .pageSheet
|
||||
present(nav, animated: true)
|
||||
}
|
||||
|
||||
private func presentGlobalScanner() {
|
||||
guard presentedViewController == nil else { return }
|
||||
|
||||
let scanner = ScanPlaceholderViewController()
|
||||
let scanner = QRCodeScannerViewController()
|
||||
scanner.onScanResult = { [weak self] result in
|
||||
guard let self else { return }
|
||||
Task { await self.scanHandler.handleScanResult(result) }
|
||||
}
|
||||
let navigationController = UINavigationController(rootViewController: scanner)
|
||||
navigationController.modalPresentationStyle = .fullScreen
|
||||
present(navigationController, animated: true)
|
||||
|
||||
Reference in New Issue
Block a user