LNJoinUsViewController.swift 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. //
  2. // LNJoinUsViewController.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/1/19.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. extension UIView {
  11. func pushToJoinUs() {
  12. let vc = LNJoinUsViewController()
  13. let fromWeb = navigationController?.viewControllers.last is LNWebViewController
  14. if fromWeb, var viewControllers = navigationController?.viewControllers {
  15. viewControllers.removeLast()
  16. viewControllers.append(vc)
  17. navigationController?.setViewControllers(viewControllers, animated: true)
  18. } else {
  19. navigationController?.pushViewController(vc, animated: true)
  20. }
  21. }
  22. }
  23. enum LNJoinUsStep: Int, CaseIterable {
  24. case none
  25. case inputPhone
  26. case inputCaptcha
  27. case inputInfo
  28. case selectSkill
  29. case skillInfoInput
  30. var backStep: LNJoinUsStep? {
  31. switch self {
  32. case .none: nil
  33. case .inputPhone: nil
  34. case .inputCaptcha: .inputPhone
  35. case .inputInfo: nil
  36. case .selectSkill: nil
  37. case .skillInfoInput: .selectSkill
  38. }
  39. }
  40. }
  41. class LNJoinUsViewController: LNViewController {
  42. private var curStep: LNJoinUsStep = .inputPhone {
  43. didSet {
  44. view.endEditing(true)
  45. inputPhoneView.isHidden = true
  46. inputCaptchaView.isHidden = true
  47. inputInfoView.isHidden = true
  48. selectSkillView.isHidden = true
  49. inputSkillView.isHidden = true
  50. switch curStep {
  51. case .none: break
  52. case .inputPhone:
  53. inputPhoneView.isHidden = false
  54. headerView.update(1)
  55. case .inputCaptcha:
  56. inputCaptchaView.isHidden = false
  57. case .inputInfo:
  58. inputInfoView.isHidden = false
  59. headerView.update(2)
  60. case .selectSkill:
  61. selectSkillView.isHidden = false
  62. headerView.update(3)
  63. case .skillInfoInput:
  64. inputSkillView.isHidden = false
  65. }
  66. }
  67. }
  68. private let headerView = LNJoinUsHeaderView()
  69. private let inputPhoneView = LNJoinUsInputPhoneView()
  70. private let inputCaptchaView = LNJoinUsInputCaptchaView()
  71. private let inputInfoView = LNJoinUsInputInfoView()
  72. private let selectSkillView = LNJoinUsSelectSkillView()
  73. private let inputSkillView = LNJoinUsSkillFieldsEditView()
  74. override func viewDidLoad() {
  75. super.viewDidLoad()
  76. setupViews()
  77. curStep = .none
  78. loadInfos()
  79. }
  80. }
  81. extension LNJoinUsViewController {
  82. private func loadInfos() {
  83. showLoading()
  84. LNGameMateManager.shared.getJoinGameMateInfo { [weak self] res in
  85. dismissLoading()
  86. guard let self else { return }
  87. guard let res else { return }
  88. if res.step3Complete || res.underReview {
  89. view.pushToJoinUsReview(false)
  90. return
  91. }
  92. if res.step2Complete {
  93. if let step3 = res.setp3, let code = step3.bizCategoryCode, !code.isEmpty,
  94. let skill = LNGameMateManager.shared.gameCategory(for: code) {
  95. curStep = .skillInfoInput
  96. inputSkillView.update(skill, info: step3)
  97. } else {
  98. curStep = .selectSkill
  99. }
  100. } else if res.step1Complete {
  101. curStep = .inputInfo
  102. if let info = res.setp2 {
  103. inputInfoView.update(info)
  104. }
  105. } else {
  106. curStep = .inputPhone
  107. if let info = res.setp2 {
  108. inputInfoView.update(info)
  109. }
  110. }
  111. }
  112. }
  113. }
  114. extension LNJoinUsViewController:
  115. LNJoinUsInputPhoneViewDelegate,
  116. LNJoinUsInputCaptchaViewDelegate,
  117. LNJoinUsInputInfoViewDelegate,
  118. LNJoinUsSelectSkillViewDelegate {
  119. func joinUsSelectSkillView(view: LNJoinUsSelectSkillView, didSelect skill: LNGameCategoryItemVO) {
  120. showLoading()
  121. LNGameMateManager.shared.getCreateSkillFields(id: skill.code) { [weak self] info in
  122. dismissLoading()
  123. guard let self else { return }
  124. guard let info else { return }
  125. curStep = .skillInfoInput
  126. inputSkillView.update(skill, info: info)
  127. }
  128. }
  129. func joinUsInputInfoViewDidFinish(view: LNJoinUsInputInfoView) {
  130. curStep = .selectSkill
  131. }
  132. func joinUsInputCaptchaViewDidFinish(view: LNJoinUsInputCaptchaView) {
  133. curStep = .inputInfo
  134. }
  135. func joinUsInputPhoneView(view: LNJoinUsInputPhoneView, didFinished code: String, phone: String) {
  136. curStep = .inputCaptcha
  137. inputCaptchaView.update(code, phone: phone)
  138. }
  139. }
  140. extension LNJoinUsViewController {
  141. private func setupViews() {
  142. navigationBarColor = .clear
  143. view.backgroundColor = .primary_1
  144. customBack = { [weak self] in
  145. guard let self else { return }
  146. if let back = curStep.backStep {
  147. curStep = back
  148. } else {
  149. navigationController?.popViewController(animated: true)
  150. }
  151. }
  152. title = .init(key: "B00031")
  153. view.addSubview(headerView)
  154. headerView.snp.makeConstraints { make in
  155. make.horizontalEdges.equalToSuperview()
  156. make.top.equalTo(fakeNaviBgView)
  157. }
  158. let container = UIView()
  159. container.layer.cornerRadius = 20
  160. container.backgroundColor = .fill
  161. view.addSubview(container)
  162. container.snp.makeConstraints { make in
  163. make.horizontalEdges.bottom.equalToSuperview()
  164. make.top.equalTo(headerView.snp.bottom).offset(-56)
  165. }
  166. inputPhoneView.delegate = self
  167. container.addSubview(inputPhoneView)
  168. inputPhoneView.snp.makeConstraints { make in
  169. make.edges.equalToSuperview()
  170. }
  171. inputCaptchaView.delegate = self
  172. container.addSubview(inputCaptchaView)
  173. inputCaptchaView.snp.makeConstraints { make in
  174. make.edges.equalToSuperview()
  175. }
  176. inputInfoView.delegate = self
  177. container.addSubview(inputInfoView)
  178. inputInfoView.snp.makeConstraints { make in
  179. make.edges.equalToSuperview()
  180. }
  181. selectSkillView.delegate = self
  182. container.addSubview(selectSkillView)
  183. selectSkillView.snp.makeConstraints { make in
  184. make.edges.equalToSuperview()
  185. }
  186. container.addSubview(inputSkillView)
  187. inputSkillView.snp.makeConstraints { make in
  188. make.edges.equalToSuperview()
  189. }
  190. }
  191. }
  192. #if DEBUG
  193. import SwiftUI
  194. struct LNJoinUsViewControllerPreview: UIViewControllerRepresentable {
  195. func makeUIViewController(context: Context) -> some UIViewController {
  196. LNJoinUsViewController()
  197. }
  198. func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
  199. }
  200. #Preview(body: {
  201. LNJoinUsViewControllerPreview()
  202. })
  203. #endif