SNCheckViewController.swift 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // SNCheckViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/3/26.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. // ZBarReaderDelegate,UIImagePickerControllerDelegate,
  10. class SNCheckViewController: BaseViewController, UITextFieldDelegate, UINavigationControllerDelegate {
  11. @IBOutlet weak var lblRemark: UILabel!
  12. @IBOutlet weak var imgJiJu: UIImageView!
  13. @IBOutlet weak var imgBackgroud: UIImageView!
  14. @IBOutlet weak var txtCode: UITextField!
  15. @IBOutlet weak var viewMenu: UIView!
  16. /// 0:查询 1:开通商户
  17. var type = 1
  18. var shopOpen = ShopOpenEntity()
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView)
  22. viewNav.initView(title: "SN码查询") {[weak self] (index, _) in
  23. if index == 0 {
  24. self!.handleBack()
  25. }
  26. }
  27. self.view.addSubview(viewNav)
  28. viewNav.marginTop(top: 0)
  29. viewMenu.marginTop(top: viewNav.bottom())
  30. txtCode.setCornerRadius(size: 4)
  31. txtCode.setContentMarginLeft(leftWidth: 15)
  32. txtCode.delegate = self
  33. txtCode.returnKeyType = .search
  34. txtCode.setContentMarginRight(rightWidth: 30)
  35. imgBackgroud.setSizeHeight(height: viewMenu.bottom())
  36. imgJiJu.marginTop(top: 51, view: imgBackgroud)
  37. lblRemark.marginTop(top: 28, view: imgJiJu)
  38. lblRemark.setTextLineSpace(lineSpace: 6)
  39. lblRemark.textAlignment = .center
  40. }
  41. func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  42. loadData()
  43. return true
  44. }
  45. @IBAction func btnMenuClick(_ sender: AnyObject) {
  46. switch (sender as! UIButton).tag {
  47. case 1001: // 查询
  48. loadData()
  49. break
  50. case 1002: // 扫码
  51. // let vc = ScannerViewController();
  52. // toViewController(viewController: vc)
  53. barcode()
  54. break
  55. case 1003: //
  56. break
  57. case 1004: //
  58. break
  59. case 1005: //
  60. break
  61. case 1006: //
  62. break
  63. default:
  64. break
  65. }
  66. }
  67. // MARK: =============加载数据===============
  68. func loadData() {
  69. txtCode.resignFirstResponder()
  70. if txtCode.text!.length() < 1 {
  71. SVProgressHUD.showError(withStatus: "请输入SN码")
  72. return
  73. }
  74. let url = RequestURL.getMachineBySM
  75. let params = NSMutableDictionary()
  76. params.setValue(CommonValue.getUserId(), forKey: "userId")
  77. params.setValue(txtCode.text!, forKey: "smCode")
  78. loadDataInfo(url: url, params: params, tag: 1001)
  79. }
  80. override func returnData(tag: Int) {
  81. if tag == 1001 {
  82. let state = dicData.getInt(key: "status")
  83. if state == 0 {
  84. let viewState = CommonViewUntils.getViewForXIB(xibName: "BindCheckView") as! BindCheckView
  85. viewState.initView(state: 1) {[weak self] (_, _) in
  86. appDelegate.navController.hiddenBackgroudViewNoAnimate()
  87. if(self!.type == 1) //可以绑定
  88. {
  89. let vc = SelectBusTypeViewController()
  90. vc.shopOpen = self!.shopOpen
  91. vc.shopOpen.posSN = self!.txtCode.text!
  92. self!.toViewController(viewController: vc)
  93. }
  94. }
  95. appDelegate.navController.showBackgroudView(viewContent: viewState, isCenter: true)
  96. } else {
  97. let viewState = CommonViewUntils.getViewForXIB(xibName: "BindCheckView") as! BindCheckView
  98. viewState.initView(state: 0) {(_, _) in
  99. appDelegate.navController.hiddenBackgroudViewNoAnimate()
  100. }
  101. appDelegate.navController.showBackgroudView(viewContent: viewState, isCenter: true)
  102. }
  103. }
  104. }
  105. override func returnError(tag: Int, type: String) {
  106. isAlertError = false
  107. if tag == 1001 {
  108. let viewState = CommonViewUntils.getViewForXIB(xibName: "BindCheckView") as! BindCheckView
  109. viewState.initView(state: 0) {(_, _) in
  110. appDelegate.navController.hiddenBackgroudViewNoAnimate()
  111. }
  112. appDelegate.navController.showBackgroudView(viewContent: viewState, isCenter: true)
  113. }
  114. }
  115. func barcode() {
  116. // let imagePicker = ZBarReaderController();
  117. // imagePicker.showsHelpOnFail = false;
  118. // imagePicker.sourceType = .camera;
  119. // imagePicker.delegate = self;
  120. // imagePicker.allowsEditing = true;
  121. // self.present(imagePicker, animated: true) {
  122. //
  123. // }
  124. }
  125. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
  126. // self.dismiss(animated: true) {[weak self] in
  127. // var bars = info[ZBarReaderControllerResults] as? [ZBarSymbol]
  128. // if(bars != nil && bars!.count > 0)
  129. // {
  130. //
  131. // }
  132. // else
  133. // {
  134. // SVProgressHUD.showError(withStatus: "二维码识别失败!")
  135. // }
  136. //
  137. // }
  138. }
  139. // func readerControllerDidFail(toRead reader: ZBarReaderController!, withRetry retry: Bool) {
  140. // if(retry)
  141. // {
  142. // self.dismiss(animated: true) {
  143. // SVProgressHUD.showError(withStatus: "二维码识别失败!")
  144. // }
  145. // }
  146. // }
  147. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  148. txtCode.resignFirstResponder()
  149. }
  150. override func viewWillAppear(_ animated: Bool) {
  151. super.viewWillAppear(animated)
  152. setNavLineHidden(hidden: true)
  153. appDelegate.setNavigationBarHidden(isHidden: true)
  154. if mainViewControllerIsGo {
  155. txtCode.text = mainViewControllerIsGoValue
  156. }
  157. mainViewControllerIsGo = false
  158. }
  159. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  160. super.init(nibName: "SNCheckViewController", bundle: nil)
  161. }
  162. required init?(coder aDecoder: NSCoder) {
  163. fatalError("init(coder:) has not been implemented")
  164. }
  165. }