112 lines
3.6 KiB
Swift
112 lines
3.6 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()
|
|
|
|
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() }
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
override func numberOfSections(in tableView: UITableView) -> Int { 2 }
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
section == 0 ? formRows.count : 1
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
|
section == 0 ? "认证信息" : "操作"
|
|
}
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> 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 tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
if indexPath.section == 1 {
|
|
Task {
|
|
do {
|
|
try await viewModel.sendCode(api: services.pilotCertificationAPI)
|
|
showToast("验证码已发送")
|
|
} catch {
|
|
showToast(error.localizedDescription)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
]
|
|
}
|
|
|
|
private func updateHeader() {
|
|
let status = viewModel.auditStatusText
|
|
statusLabel.text = "状态:\(status)\n\(viewModel.statusMessage ?? "")"
|
|
}
|
|
}
|
|
|
|
extension PilotCertificationViewModel: ViewModelBindable {}
|