123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- //
- // SNCheckViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/3/26.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- // ZBarReaderDelegate,UIImagePickerControllerDelegate,
- class SNCheckViewController: BaseViewController, UITextFieldDelegate, UINavigationControllerDelegate {
- @IBOutlet weak var lblRemark: UILabel!
- @IBOutlet weak var imgJiJu: UIImageView!
- @IBOutlet weak var imgBackgroud: UIImageView!
- @IBOutlet weak var txtCode: UITextField!
- @IBOutlet weak var viewMenu: UIView!
- /// 0:查询 1:开通商户
- var type = 1
- var shopOpen = ShopOpenEntity()
- override func viewDidLoad() {
- super.viewDidLoad()
- let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView)
- viewNav.initView(title: "SN码查询") {[weak self] (index, _) in
- if index == 0 {
- self!.handleBack()
- }
- }
- self.view.addSubview(viewNav)
- viewNav.marginTop(top: 0)
- viewMenu.marginTop(top: viewNav.bottom())
- txtCode.setCornerRadius(size: 4)
- txtCode.setContentMarginLeft(leftWidth: 15)
- txtCode.delegate = self
- txtCode.returnKeyType = .search
- txtCode.setContentMarginRight(rightWidth: 30)
- imgBackgroud.setSizeHeight(height: viewMenu.bottom())
- imgJiJu.marginTop(top: 51, view: imgBackgroud)
- lblRemark.marginTop(top: 28, view: imgJiJu)
- lblRemark.setTextLineSpace(lineSpace: 6)
- lblRemark.textAlignment = .center
- }
- func textFieldShouldReturn(_ textField: UITextField) -> Bool {
- loadData()
- return true
- }
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- switch (sender as! UIButton).tag {
- case 1001: // 查询
- loadData()
- break
- case 1002: // 扫码
- // let vc = ScannerViewController();
- // toViewController(viewController: vc)
- barcode()
- break
- case 1003: //
- break
- case 1004: //
- break
- case 1005: //
- break
- case 1006: //
- break
- default:
- break
- }
- }
- // MARK: =============加载数据===============
- func loadData() {
- txtCode.resignFirstResponder()
- if txtCode.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入SN码")
- return
- }
- let url = RequestURL.getMachineBySM
- let params = NSMutableDictionary()
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- params.setValue(txtCode.text!, forKey: "smCode")
- loadDataInfo(url: url, params: params, tag: 1001)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- let state = dicData.getInt(key: "status")
- if state == 0 {
- let viewState = CommonViewUntils.getViewForXIB(xibName: "BindCheckView") as! BindCheckView
- viewState.initView(state: 1) {[weak self] (_, _) in
- appDelegate.navController.hiddenBackgroudViewNoAnimate()
- if(self!.type == 1) //可以绑定
- {
- let vc = SelectBusTypeViewController()
- vc.shopOpen = self!.shopOpen
- vc.shopOpen.posSN = self!.txtCode.text!
- self!.toViewController(viewController: vc)
- }
- }
- appDelegate.navController.showBackgroudView(viewContent: viewState, isCenter: true)
- } else {
- let viewState = CommonViewUntils.getViewForXIB(xibName: "BindCheckView") as! BindCheckView
- viewState.initView(state: 0) {(_, _) in
- appDelegate.navController.hiddenBackgroudViewNoAnimate()
- }
- appDelegate.navController.showBackgroudView(viewContent: viewState, isCenter: true)
- }
- }
- }
- override func returnError(tag: Int, type: String) {
- isAlertError = false
- if tag == 1001 {
- let viewState = CommonViewUntils.getViewForXIB(xibName: "BindCheckView") as! BindCheckView
- viewState.initView(state: 0) {(_, _) in
- appDelegate.navController.hiddenBackgroudViewNoAnimate()
- }
- appDelegate.navController.showBackgroudView(viewContent: viewState, isCenter: true)
- }
- }
- func barcode() {
- // let imagePicker = ZBarReaderController();
- // imagePicker.showsHelpOnFail = false;
- // imagePicker.sourceType = .camera;
- // imagePicker.delegate = self;
- // imagePicker.allowsEditing = true;
- // self.present(imagePicker, animated: true) {
- //
- // }
- }
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
- // self.dismiss(animated: true) {[weak self] in
- // var bars = info[ZBarReaderControllerResults] as? [ZBarSymbol]
- // if(bars != nil && bars!.count > 0)
- // {
- //
- // }
- // else
- // {
- // SVProgressHUD.showError(withStatus: "二维码识别失败!")
- // }
- //
- // }
- }
- // func readerControllerDidFail(toRead reader: ZBarReaderController!, withRetry retry: Bool) {
- // if(retry)
- // {
- // self.dismiss(animated: true) {
- // SVProgressHUD.showError(withStatus: "二维码识别失败!")
- // }
- // }
- // }
- override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
- txtCode.resignFirstResponder()
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- setNavLineHidden(hidden: true)
- appDelegate.setNavigationBarHidden(isHidden: true)
- if mainViewControllerIsGo {
- txtCode.text = mainViewControllerIsGoValue
- }
- mainViewControllerIsGo = false
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "SNCheckViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|