BindDeviceViewController.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // BindDeviceViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/4/11.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class BindDeviceViewController: BaseViewController {
  10. @IBOutlet weak var btnOpen: UIButton!
  11. @IBOutlet weak var btnScan: UIButton!
  12. @IBOutlet weak var txtCode: UITextField!
  13. var merchantsId = ""
  14. ///0:返回上一层 1:返回首页
  15. var fromType = 0
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. self.title = "绑定设备"
  19. initNavLeftBackButton()
  20. txtCode.setCornerRadius(size: 4)
  21. txtCode.setContentMarginLeft(leftWidth: 20)
  22. }
  23. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  24. txtCode.resignFirstResponder()
  25. }
  26. func cusHandleBack() {
  27. if !CommonUntils.reBackView(controller: self, aclass: ShopManagerViewController.classForCoder()) {
  28. self.navigationController?.popToRootViewController(animated: true)
  29. }
  30. }
  31. @IBAction func btnMenuClick(_ sender: AnyObject) {
  32. switch (sender as! UIButton).tag {
  33. case 1001: // 扫码
  34. //取值在viewWillApper里 根据appDelegate.mainViewControllerIsGo mainViewControllerIsGoType mainViewControllerIsGoValue 取值
  35. let view = ScannerViewController()
  36. self.navigationController?.pushViewController(view, animated: true)
  37. break
  38. case 1002: // 开通
  39. loadData()
  40. break
  41. case 1003: //
  42. break
  43. case 1004: //
  44. break
  45. case 1005: //
  46. break
  47. case 1006: //
  48. break
  49. default:
  50. break
  51. }
  52. }
  53. // MARK: =============加载数据===============
  54. func loadData() {
  55. txtCode.resignFirstResponder()
  56. if txtCode.text!.length() < 1 {
  57. SVProgressHUD.showError(withStatus: "请输入SN码")
  58. return
  59. }
  60. let url = RequestURL.bandMachine
  61. let params = NSMutableDictionary()
  62. params.setValue(CommonValue.getUserId(), forKey: "userId")
  63. params.setValue(merchantsId, forKey: "merchantsId")
  64. params.setValue(txtCode.text!, forKey: "machineSnCode")
  65. loadDataInfo(url: url, params: params, tag: 1001)
  66. }
  67. override func returnData(tag: Int) {
  68. if tag == 1001 {
  69. let viewState = CommonViewUntils.getViewForXIB(xibName: "BindCheckView") as! BindCheckView
  70. viewState.initView(state: 1) {[weak self] (_, _) in
  71. appDelegate.navController.hiddenBackgroudViewNoAnimate()
  72. if self!.fromType == 0 {
  73. self!.handleBack()
  74. } else {
  75. self!.cusHandleBack()
  76. }
  77. }
  78. appDelegate.navController.showBackgroudView(viewContent: viewState, isCenter: true, clickOtherIsClose: false)
  79. }
  80. }
  81. override func returnError(tag: Int, type: String) {
  82. isAlertError = false
  83. if tag == 1001 {
  84. let viewState = CommonViewUntils.getViewForXIB(xibName: "BindCheckView") as! BindCheckView
  85. viewState.initView(state: 0) {(_, _) in
  86. appDelegate.navController.hiddenBackgroudViewNoAnimate()
  87. }
  88. appDelegate.navController.showBackgroudView(viewContent: viewState, isCenter: true)
  89. }
  90. }
  91. override func viewWillAppear(_ animated: Bool) {
  92. super.viewWillAppear(animated)
  93. if mainViewControllerIsGo {
  94. txtCode.text = mainViewControllerIsGoValue
  95. }
  96. mainViewControllerIsGo = false
  97. }
  98. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  99. super.init(nibName: "BindDeviceViewController", bundle: nil)
  100. }
  101. required init?(coder aDecoder: NSCoder) {
  102. fatalError("init(coder:) has not been implemented")
  103. }
  104. }