BindingViewController.swift 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // BindingViewController.swift
  3. // JiaPeiManage
  4. //
  5. // Created by Ning.ge on 2023/8/3.
  6. //
  7. import UIKit
  8. import RxSwift
  9. import RxCocoa
  10. import SwiftyUserDefaults
  11. final class BindingViewController: BaseViewController {
  12. // MARK: 服务属性
  13. private let loginService: LoginServiceType = LoginService(networking: LoginNetworking())
  14. // MARK: UI属性
  15. // 账号
  16. @IBOutlet weak var username_textField: QMUITextField!
  17. //密码
  18. @IBOutlet weak var userpassword_textField: QMUITextField!
  19. //显示密码
  20. @IBOutlet weak var pwdshow_button: QMUIButton!
  21. //定位arrow
  22. @IBOutlet weak var location_button: QMUIButton!
  23. @IBOutlet weak var location_button_btn: UIButton!
  24. //区域
  25. @IBOutlet weak var userlocation_textField: QMUITextField!
  26. //登录按钮
  27. @IBOutlet weak var login_button: UIButton!
  28. //已同意
  29. @IBOutlet weak var agree_button: QMUIButton!
  30. var city:String = ""
  31. var cityPower:String = "" //地区权限
  32. var cityItems:[CityItem] = []
  33. var citys: [String:String] = [:]
  34. var selectedItemIndex = 0
  35. override func viewDidLoad() {
  36. super.viewDidLoad()
  37. setupUI()
  38. //biand绑定
  39. biandView()
  40. //获取字典数据
  41. loginService.dictRequest(dictType: "coach_city").subscribe(onSuccess: { [unowned self] cityItems in
  42. self.cityItems = cityItems
  43. for cityItem in cityItems {
  44. self.citys[cityItem.dictLabel] = cityItem.dictValue
  45. }
  46. },onError: { Error in
  47. }).disposed(by: disposeBag)
  48. }
  49. // MARK: 私有方法
  50. func setupUI(){
  51. self.view.backgroundColor = .db_theme
  52. // self.username_textField.placeholderColor = .db_place
  53. // self.userpassword_textField.placeholderColor = .db_place
  54. // self.userlocation_textField.placeholderColor = .db_place
  55. }
  56. func biandView(){
  57. // //判断账号的输入是否可用
  58. // let accountValid = username_textField.rx.text.orEmpty.map{ value in
  59. // return value.count >= 18
  60. // }
  61. // //判断密码的输入是否可用
  62. // let passwordValid = userpassword_textField.rx.text.orEmpty.map{ value in
  63. // return value.count >= 6
  64. // }
  65. //
  66. // //判断同意
  67. // let agreeValid = agree_button.rx.tap.map { [unowned self] in
  68. // NSLog("agreeValid")
  69. // return self.agree_button.isSelected
  70. // }
  71. // //同意
  72. // agree_button.rx.tap.subscribe ({ [unowned self] (_) in
  73. // NSLog("tap.subscribe")
  74. // self.agree_button.isSelected = !self.agree_button.isSelected
  75. // }).disposed(by: disposeBag)
  76. // //登录按钮的可用与否
  77. // let loginObserver = Observable.combineLatest(accountValid,passwordValid,agreeValid){(account,password,agree) in
  78. // account && password && agree
  79. // }
  80. //
  81. // //绑定按钮
  82. // loginObserver.bind(to: login_button.rx.isEnabled).disposed(by: disposeBag)
  83. // loginObserver.subscribe(onNext: { [unowned self] valid in
  84. // NSLog("loginObserver")
  85. // self.login_button.alpha = valid ? 1 : 0.5
  86. // }).disposed(by: disposeBag)
  87. //
  88. // //用户协议
  89. // userprotocol_button.rx.tap.subscribe ({ [unowned self] (_) in
  90. // //跳web
  91. // navigator.push("https://ys.zzxcx.net/xy_jlgj.html")
  92. // }).disposed(by: disposeBag)
  93. // //隐私
  94. // userprivacy_button.rx.tap.subscribe ({ [unowned self] (_) in
  95. // //跳web
  96. // navigator.push("https://ys.zzxcx.net/xy_jlgj.html")
  97. // }).disposed(by: disposeBag)
  98. // //显示密码
  99. // pwdshow_button.rx.tap.subscribe ({ [unowned self] (_) in
  100. // self.pwdshow_button.isSelected = !self.pwdshow_button.isSelected;
  101. // self.userpassword_textField.isSecureTextEntry = !self.pwdshow_button.isSelected
  102. // }).disposed(by: disposeBag)
  103. // //选择区域
  104. // location_button.rx.tap.subscribe ({ [unowned self] (_) in
  105. // NSLog("点击了:选择区域- \(Thread.isMainThread)")
  106. // self.showDialog()
  107. // }).disposed(by: disposeBag)
  108. // location_button_btn.rx.tap.subscribe ({ [unowned self] (_) in
  109. // self.showDialog()
  110. // }).disposed(by: disposeBag)
  111. // //wxin_button
  112. // wxin_button.rx.tap.subscribe ({ [unowned self] (_) in
  113. //
  114. // }).disposed(by: disposeBag)
  115. // //登录
  116. // login_button.rx.tap
  117. // .asObservable()
  118. // .withLatestFrom(loginObserver)
  119. // .do(onNext: {
  120. // [unowned self]_ in
  121. // self.login_button.isEnabled = false
  122. // self.view.endEditing(true)
  123. // })
  124. // .subscribe(onNext: {[unowned self]isLogin in
  125. // NSLog("登录 - 登录: login %@","123")
  126. // self.login_button.isEnabled = true
  127. // //保存用户信息
  128. // var account:String = self.username_textField.text!
  129. // var password:String = self.userpassword_textField.text!
  130. // if city=="" {
  131. // NYTips.showMsg(txt: "请选择地区!")
  132. // return
  133. // }
  134. // LocalManager.userInfo.userAccount = account
  135. // LocalManager.userInfo.password = password
  136. // LocalManager.userInfo.city = city
  137. // LocalManager.userInfo.cityPower = cityPower
  138. // //登录api RX 订阅 观察 销毁 三部曲
  139. // NYTips.show()
  140. // self.loginService.loginRequest(user_name: account, user_password: password,city: city)
  141. // .subscribe(onSuccess: { userinfo in
  142. // NYTips.hide()
  143. // LocalManager.userInfo = userinfo
  144. // LocalManager.userInfo.isLogin = true //设置已经登录
  145. // NYAccountManager.shared.addUserinfo(user: userinfo)//添加用户信息
  146. // print("登录成功:%@", userinfo)
  147. // self.dismiss(animated: true)
  148. // }, onError: { error in
  149. // NYTips.hide()
  150. // NYTips.showErr(txt: (error as! RequestError).errorDescription)
  151. // print("%@",error)
  152. // })
  153. // .disposed(by: disposeBag)
  154. //
  155. // })
  156. // .disposed(by: disposeBag)
  157. // //添加手势
  158. // let tapBackground = UITapGestureRecognizer()
  159. // tapBackground.rx.event
  160. // .subscribe(onNext: { [weak self] _ in
  161. // self?.view.endEditing(true)
  162. // })
  163. // .disposed(by: disposeBag)
  164. // view.addGestureRecognizer(tapBackground)
  165. }
  166. func showDialog(){
  167. let dialogViewController = QMUIDialogSelectionViewController()
  168. dialogViewController.title = "请选择地区"
  169. dialogViewController.items = Array(citys.keys)
  170. dialogViewController.selectedItemIndex = selectedItemIndex
  171. dialogViewController.addCancelButton(withText: "取消", block: nil)
  172. dialogViewController.addSubmitButton(withText: "确定") { [weak self] dialogViewController in
  173. guard let dialogViewController:QMUIDialogSelectionViewController = dialogViewController as? QMUIDialogSelectionViewController else { return }
  174. if dialogViewController.selectedItemIndex == QMUIDialogSelectionViewControllerSelectedItemIndexNone {
  175. NYTips.showErr(txt: "请至少选一个")
  176. return
  177. }
  178. self?.selectedItemIndex = dialogViewController.selectedItemIndex
  179. let keyname = dialogViewController.items![self!.selectedItemIndex]
  180. // self.citys[cityItem.dictLabel] = cityItem.dictValue
  181. var item:CityItem?
  182. for cityItem in self!.cityItems {
  183. if cityItem.dictLabel == keyname {
  184. item = cityItem
  185. break
  186. }
  187. }
  188. self?.city = item!.dictValue //编码
  189. self?.cityPower = item!.remark //地区权重
  190. self?.userlocation_textField.text = item?.dictLabel
  191. dialogViewController.hide()
  192. }
  193. dialogViewController.show()
  194. }
  195. }