Files
suixinkan_ios_uikit/suixinkan_ios/Features/PilotCertification/ViewControllers/PilotCertificationViewController.swift
汉秋 d99a5b1bf8 Advance UIKit rewrite with AMap integration and core UI modules.
Integrate高德 SDK with simulator-safe build flags, add map views for operating area and punch points, refactor main tabs and key feature screens to UIKit with Diffable lists, and document Swift concurrency defaults in AGENTS.md.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 15:16:12 +08:00

121 lines
3.8 KiB
Swift

//
// PilotCertificationViewController.swift
// suixinkan
//
// Created by Codex on 2026/6/26.
//
import SnapKit
import UIKit
///
final class PilotCertificationViewController: ModuleTableViewController {
private let viewModel = PilotCertificationViewModel()
private let statusLabel = UILabel()
/// UI
override func viewDidLoad() {
title = "飞手认证"
navigationItem.rightBarButtonItem = UIBarButtonItem(
title: "提交",
style: .done,
target: self,
action: #selector(submit)
)
super.viewDidLoad()
setupHeader()
wireViewModel(viewModel) { [weak self] in self?.updateHeader() }
}
/// Header UI
private func setupHeader() {
statusLabel.numberOfLines = 0
statusLabel.font = .systemFont(ofSize: 14)
statusLabel.textColor = AppDesign.textSecondary
statusLabel.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: 80)
tableView.tableHeaderView = statusLabel
}
/// section
override func numberOfTableSections() -> Int { 2 }
/// section
override func tableRowCount(in section: Int) -> Int {
section == 0 ? formRows.count : 1
}
/// section
override func tableSectionTitle(for section: Int) -> String? {
section == 0 ? "认证信息" : "操作"
}
/// Cell
override func tableCell(for indexPath: IndexPath, row: ModuleTableRow, in tableView: UITableView) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(
withIdentifier: TitleSubtitleTableViewCell.reuseIdentifier,
for: indexPath
) as! TitleSubtitleTableViewCell
if indexPath.section == 0 {
let row = formRows[indexPath.row]
cell.configure(title: row.title, subtitle: row.value)
} else {
cell.configure(title: "发送验证码", subtitle: viewModel.phone)
}
return cell
}
///
override func didSelectTableRow(at indexPath: IndexPath) {
if indexPath.section == 1 {
Task {
do {
try await viewModel.sendCode(api: services.pilotCertificationAPI)
showToast("验证码已发送")
} catch {
showToast(error.localizedDescription)
}
}
}
}
/// Content
override func reloadContent() async {
await viewModel.load(api: services.pilotCertificationAPI, realNameAPI: services.profileAPI)
updateHeader()
}
///
@objc private func submit() {
Task {
do {
try await viewModel.submit(
api: services.pilotCertificationAPI,
uploader: services.ossUploadService,
scenicId: services.currentScenicId
)
services.toastCenter.show("提交成功")
} catch {
services.toastCenter.show(error.localizedDescription)
}
}
}
private var formRows: [(title: String, value: String)] {
[
("姓名", viewModel.name),
("证件号", viewModel.certNo),
("手机号", viewModel.phone),
("无人机型号", viewModel.droneModel),
("序列号", viewModel.droneSerialNo)
]
}
/// Header
private func updateHeader() {
let status = viewModel.auditStatusText
statusLabel.text = "状态:\(status)\n\(viewModel.statusMessage ?? "")"
}
}
extension PilotCertificationViewModel: ViewModelBindable {}