|
@@ -28,13 +28,11 @@ final class BindingViewController: BaseViewController {
|
|
|
@IBOutlet weak var location_button_btn: UIButton!
|
|
|
//区域
|
|
|
@IBOutlet weak var userlocation_textField: QMUITextField!
|
|
|
- //登录按钮
|
|
|
+ //绑定按钮
|
|
|
@IBOutlet weak var login_button: UIButton!
|
|
|
- //已同意
|
|
|
- @IBOutlet weak var agree_button: QMUIButton!
|
|
|
|
|
|
|
|
|
-
|
|
|
+ var openid:String = ""
|
|
|
var city:String = ""
|
|
|
var cityPower:String = "" //地区权限
|
|
|
var cityItems:[CityItem] = []
|
|
@@ -57,119 +55,91 @@ final class BindingViewController: BaseViewController {
|
|
|
// MARK: 私有方法
|
|
|
func setupUI(){
|
|
|
self.view.backgroundColor = .db_theme
|
|
|
-// self.username_textField.placeholderColor = .db_place
|
|
|
-// self.userpassword_textField.placeholderColor = .db_place
|
|
|
-// self.userlocation_textField.placeholderColor = .db_place
|
|
|
+ self.username_textField.placeholderColor = .db_place
|
|
|
+ self.userpassword_textField.placeholderColor = .db_place
|
|
|
+ self.userlocation_textField.placeholderColor = .db_place
|
|
|
}
|
|
|
func biandView(){
|
|
|
-// //判断账号的输入是否可用
|
|
|
-// let accountValid = username_textField.rx.text.orEmpty.map{ value in
|
|
|
-// return value.count >= 18
|
|
|
-// }
|
|
|
-// //判断密码的输入是否可用
|
|
|
-// let passwordValid = userpassword_textField.rx.text.orEmpty.map{ value in
|
|
|
-// return value.count >= 6
|
|
|
-// }
|
|
|
-//
|
|
|
-// //判断同意
|
|
|
-// let agreeValid = agree_button.rx.tap.map { [unowned self] in
|
|
|
-// NSLog("agreeValid")
|
|
|
-// return self.agree_button.isSelected
|
|
|
-// }
|
|
|
-// //同意
|
|
|
-// agree_button.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
-// NSLog("tap.subscribe")
|
|
|
-// self.agree_button.isSelected = !self.agree_button.isSelected
|
|
|
-// }).disposed(by: disposeBag)
|
|
|
-// //登录按钮的可用与否
|
|
|
-// let loginObserver = Observable.combineLatest(accountValid,passwordValid,agreeValid){(account,password,agree) in
|
|
|
-// account && password && agree
|
|
|
-// }
|
|
|
-//
|
|
|
-// //绑定按钮
|
|
|
-// loginObserver.bind(to: login_button.rx.isEnabled).disposed(by: disposeBag)
|
|
|
-// loginObserver.subscribe(onNext: { [unowned self] valid in
|
|
|
-// NSLog("loginObserver")
|
|
|
-// self.login_button.alpha = valid ? 1 : 0.5
|
|
|
-// }).disposed(by: disposeBag)
|
|
|
-//
|
|
|
-// //用户协议
|
|
|
-// userprotocol_button.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
-// //跳web
|
|
|
-// navigator.push("https://ys.zzxcx.net/xy_jlgj.html")
|
|
|
-// }).disposed(by: disposeBag)
|
|
|
-// //隐私
|
|
|
-// userprivacy_button.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
-// //跳web
|
|
|
-// navigator.push("https://ys.zzxcx.net/xy_jlgj.html")
|
|
|
-// }).disposed(by: disposeBag)
|
|
|
-// //显示密码
|
|
|
-// pwdshow_button.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
-// self.pwdshow_button.isSelected = !self.pwdshow_button.isSelected;
|
|
|
-// self.userpassword_textField.isSecureTextEntry = !self.pwdshow_button.isSelected
|
|
|
-// }).disposed(by: disposeBag)
|
|
|
-// //选择区域
|
|
|
-// location_button.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
-// NSLog("点击了:选择区域- \(Thread.isMainThread)")
|
|
|
-// self.showDialog()
|
|
|
-// }).disposed(by: disposeBag)
|
|
|
-// location_button_btn.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
-// self.showDialog()
|
|
|
-// }).disposed(by: disposeBag)
|
|
|
-// //wxin_button
|
|
|
-// wxin_button.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
-//
|
|
|
-// }).disposed(by: disposeBag)
|
|
|
-// //登录
|
|
|
-// login_button.rx.tap
|
|
|
-// .asObservable()
|
|
|
-// .withLatestFrom(loginObserver)
|
|
|
-// .do(onNext: {
|
|
|
-// [unowned self]_ in
|
|
|
-// self.login_button.isEnabled = false
|
|
|
-// self.view.endEditing(true)
|
|
|
-// })
|
|
|
-// .subscribe(onNext: {[unowned self]isLogin in
|
|
|
-// NSLog("登录 - 登录: login %@","123")
|
|
|
-// self.login_button.isEnabled = true
|
|
|
-// //保存用户信息
|
|
|
-// var account:String = self.username_textField.text!
|
|
|
-// var password:String = self.userpassword_textField.text!
|
|
|
-// if city=="" {
|
|
|
-// NYTips.showMsg(txt: "请选择地区!")
|
|
|
-// return
|
|
|
-// }
|
|
|
-// LocalManager.userInfo.userAccount = account
|
|
|
-// LocalManager.userInfo.password = password
|
|
|
-// LocalManager.userInfo.city = city
|
|
|
-// LocalManager.userInfo.cityPower = cityPower
|
|
|
-// //登录api RX 订阅 观察 销毁 三部曲
|
|
|
-// NYTips.show()
|
|
|
-// self.loginService.loginRequest(user_name: account, user_password: password,city: city)
|
|
|
-// .subscribe(onSuccess: { userinfo in
|
|
|
-// NYTips.hide()
|
|
|
-// LocalManager.userInfo = userinfo
|
|
|
-// LocalManager.userInfo.isLogin = true //设置已经登录
|
|
|
-// NYAccountManager.shared.addUserinfo(user: userinfo)//添加用户信息
|
|
|
-// print("登录成功:%@", userinfo)
|
|
|
-// self.dismiss(animated: true)
|
|
|
-// }, onError: { error in
|
|
|
-// NYTips.hide()
|
|
|
-// NYTips.showErr(txt: (error as! RequestError).errorDescription)
|
|
|
-// print("%@",error)
|
|
|
-// })
|
|
|
-// .disposed(by: disposeBag)
|
|
|
-//
|
|
|
-// })
|
|
|
-// .disposed(by: disposeBag)
|
|
|
-// //添加手势
|
|
|
-// let tapBackground = UITapGestureRecognizer()
|
|
|
-// tapBackground.rx.event
|
|
|
-// .subscribe(onNext: { [weak self] _ in
|
|
|
-// self?.view.endEditing(true)
|
|
|
-// })
|
|
|
-// .disposed(by: disposeBag)
|
|
|
-// view.addGestureRecognizer(tapBackground)
|
|
|
+ //判断账号的输入是否可用
|
|
|
+ let accountValid = username_textField.rx.text.orEmpty.map{ value in
|
|
|
+ return value.count >= 18
|
|
|
+ }
|
|
|
+ //判断密码的输入是否可用
|
|
|
+ let passwordValid = userpassword_textField.rx.text.orEmpty.map{ value in
|
|
|
+ return value.count >= 6
|
|
|
+ }
|
|
|
+ //登录按钮的可用与否
|
|
|
+ let loginObserver = Observable.combineLatest(accountValid,passwordValid){(account,password) in
|
|
|
+ account && password
|
|
|
+ }
|
|
|
+ //绑定按钮
|
|
|
+ loginObserver.bind(to: login_button.rx.isEnabled).disposed(by: disposeBag)
|
|
|
+ loginObserver.subscribe(onNext: { [unowned self] valid in
|
|
|
+ NSLog("loginObserver")
|
|
|
+ self.login_button.alpha = valid ? 1 : 0.5
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ //显示密码
|
|
|
+ pwdshow_button.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
+ self.pwdshow_button.isSelected = !self.pwdshow_button.isSelected;
|
|
|
+ self.userpassword_textField.isSecureTextEntry = !self.pwdshow_button.isSelected
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ //选择区域
|
|
|
+ location_button.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
+ NSLog("点击了:选择区域- \(Thread.isMainThread)")
|
|
|
+ self.showDialog()
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ location_button_btn.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
+ self.showDialog()
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ //登录
|
|
|
+ login_button.rx.tap
|
|
|
+ .asObservable()
|
|
|
+ .withLatestFrom(loginObserver)
|
|
|
+ .do(onNext: {
|
|
|
+ [unowned self]_ in
|
|
|
+ self.login_button.isEnabled = false
|
|
|
+ self.view.endEditing(true)
|
|
|
+ })
|
|
|
+ .subscribe(onNext: {[unowned self]isLogin in
|
|
|
+ self.login_button.isEnabled = true
|
|
|
+ //保存用户信息
|
|
|
+ var account:String = self.username_textField.text!
|
|
|
+ var password:String = self.userpassword_textField.text!
|
|
|
+ if city=="" {
|
|
|
+ NYTips.showMsg(txt: "请选择地区!")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ LocalManager.userInfo.userAccount = account
|
|
|
+ LocalManager.userInfo.password = password
|
|
|
+ LocalManager.userInfo.city = city
|
|
|
+ LocalManager.userInfo.cityPower = cityPower
|
|
|
+ //登录api RX 订阅 观察 销毁 三部曲
|
|
|
+ NYTips.show()
|
|
|
+ self.loginService.biandUserRequest(idcard: account, user_password: password,openid: self.openid,city: city)
|
|
|
+ .subscribe(onSuccess: {[unowned self] userinfo in
|
|
|
+ NYTips.hide()
|
|
|
+ LocalManager.userInfo = userinfo
|
|
|
+ LocalManager.userInfo.isLogin = true //设置已经登录
|
|
|
+ NYAccountManager.shared.addUserinfo(user: userinfo)//添加用户信息
|
|
|
+ print("登录成功:%@", userinfo)
|
|
|
+ self.dismiss(animated: true)
|
|
|
+ }, onError: { error in
|
|
|
+ NYTips.hide()
|
|
|
+ NYTips.showErr(txt: (error as! RequestError).errorDescription)
|
|
|
+ print("%@",error)
|
|
|
+ })
|
|
|
+ .disposed(by: self.disposeBag)
|
|
|
+
|
|
|
+ })
|
|
|
+ .disposed(by: disposeBag)
|
|
|
+ //添加手势
|
|
|
+ let tapBackground = UITapGestureRecognizer()
|
|
|
+ tapBackground.rx.event
|
|
|
+ .subscribe(onNext: { [weak self] _ in
|
|
|
+ self?.view.endEditing(true)
|
|
|
+ })
|
|
|
+ .disposed(by: disposeBag)
|
|
|
+ view.addGestureRecognizer(tapBackground)
|
|
|
}
|
|
|
|
|
|
|
|
@@ -180,31 +150,28 @@ final class BindingViewController: BaseViewController {
|
|
|
dialogViewController.items = Array(citys.keys)
|
|
|
dialogViewController.selectedItemIndex = selectedItemIndex
|
|
|
dialogViewController.addCancelButton(withText: "取消", block: nil)
|
|
|
- dialogViewController.addSubmitButton(withText: "确定") { [weak self] dialogViewController in
|
|
|
+ dialogViewController.addSubmitButton(withText: "确定") { [unowned self] dialogViewController in
|
|
|
guard let dialogViewController:QMUIDialogSelectionViewController = dialogViewController as? QMUIDialogSelectionViewController else { return }
|
|
|
if dialogViewController.selectedItemIndex == QMUIDialogSelectionViewControllerSelectedItemIndexNone {
|
|
|
NYTips.showErr(txt: "请至少选一个")
|
|
|
return
|
|
|
}
|
|
|
- self?.selectedItemIndex = dialogViewController.selectedItemIndex
|
|
|
- let keyname = dialogViewController.items![self!.selectedItemIndex]
|
|
|
+ self.selectedItemIndex = dialogViewController.selectedItemIndex
|
|
|
+ let keyname = dialogViewController.items![self.selectedItemIndex]
|
|
|
// self.citys[cityItem.dictLabel] = cityItem.dictValue
|
|
|
var item:CityItem?
|
|
|
- for cityItem in self!.cityItems {
|
|
|
+ for cityItem in self.cityItems {
|
|
|
if cityItem.dictLabel == keyname {
|
|
|
item = cityItem
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
- self?.city = item!.dictValue //编码
|
|
|
- self?.cityPower = item!.remark //地区权重
|
|
|
- self?.userlocation_textField.text = item?.dictLabel
|
|
|
+ self.city = item!.dictValue //编码
|
|
|
+ self.cityPower = item!.remark //地区权重
|
|
|
+ self.userlocation_textField.text = item?.dictLabel
|
|
|
dialogViewController.hide()
|
|
|
}
|
|
|
dialogViewController.show()
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
|
|
|
}
|