// // BaseViewController.swift // SparkEducation // // Created by virgil on 16/3/14. // Copyright © 2016年 virgil. All rights reserved. // import UIKit class BaseViewController: BaseMainViewController, CLLocationManagerDelegate { var dataSize: NSDictionary? var dicBackDataAnyObject: AnyObject! var dicBackData = NSMutableDictionary() var dicBackLoData: NSDictionary? var isAlertError = true; // 请求错误时,是否弹浮窗提示 override func viewDidLoad() { super.viewDidLoad() //解决MJRefresh在IOS11以后 顶部显示问题 if #available(iOS 11.0, *) { for viewT in self.view.subviews { if viewT.isKind(of: UITableView.classForCoder()) { (viewT as! UITableView).contentInsetAdjustmentBehavior = .never } else if viewT.isKind(of: UICollectionView.classForCoder()) { (viewT as! UICollectionView).contentInsetAdjustmentBehavior = .never } } } else { self.automaticallyAdjustsScrollViewInsets = false //低于 iOS 9.0 } } // MARK: 数据请求方法类 // https 配置证书 func customSecurityPolicy() -> AFSecurityPolicy { let cerPath = Bundle.main.path(forResource: "app", ofType: "cer") ?? "" let cerData = NSData(contentsOfFile: cerPath) let cerSet = NSSet(object: cerData as Any) let securityPolicy = AFSecurityPolicy(pinningMode: .certificate, withPinnedCertificates: cerSet as! Set) securityPolicy.allowInvalidCertificates = true securityPolicy.validatesDomainName = false return securityPolicy } // 请求列表数据 func loadDataList(url: String, params: NSMutableDictionary, tag: Int) { isAlertError = true if self.currentPage == 1 { self.arrData.removeAllObjects() } params.setValue(self.currentPage, forKey: "pageNumber") params.setValue(self.pageSize, forKey: "pageSize") let http = CommonValue.getHttp() http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "succeed") as! String if succeed == "000" { if self.currentPage == 1 { self.arrData.removeAllObjects() } let dataInfo = json["dataInfo"] as? NSDictionary if dataInfo != nil { let array = dataInfo!["dataList"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrData.add(dicNew) } } } else { let array = json["dataInfo"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrData.add(dicNew) } } } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: succeed) if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } }, failure: { (_, err) -> Void in CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func loadDataInfoPost(url: String, params: NSMutableDictionary, tag: Int) { isAlertError = true let http = CommonValue.getHttp() http.securityPolicy = customSecurityPolicy() MBProgressHUD.showAdded(to: self.view, animated: true) // http.get(url, parameters: params ,progress:nil , success: { (operation, json1) -> Void in http.post(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "success") as! Bool let success = "\(json.object(forKey: "statusCode") ?? "000")" if succeed == true { if success == "200" { let dataInfo = json["data"] as? NSDictionary if dataInfo != nil { self.dicData.setDictionary(dataInfo as! [AnyHashable: Any]) } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: success) if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "message") as? String) } } }else { self.returnError(tag: tag, type: success) if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "message") as? String) } } MBProgressHUD.hide(for: self.view, animated: true) }, failure: { (_, err) -> Void in MBProgressHUD.hide(for: self.view, animated: true) CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func loadDataInfoPostRZ(url: String, params: NSMutableDictionary, tag: Int) { isAlertError = true let http = CommonValue.getHttp() http.securityPolicy = customSecurityPolicy() MBProgressHUD.showAdded(to: self.view, animated: true) // http.get(url, parameters: params ,progress:nil , success: { (operation, json1) -> Void in http.post(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "success") as! Bool let statusCode = json.object(forKey: "statusCode") as! Int if succeed && statusCode == 400{ let dataInfo = json["message"] as? NSString if dataInfo != nil { self.dicData.setDictionary(json as! [AnyHashable: Any]) } self.returnData(tag: tag) }else if succeed && statusCode == 200 { SVProgressHUD.showSuccess(withStatus: json.object(forKey: "message") as? String) }else { self.returnError(tag: tag, type: "") if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "message") as? String) } } MBProgressHUD.hide(for: self.view, animated: true) }, failure: { (_, err) -> Void in MBProgressHUD.hide(for: self.view, animated: true) CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func loadDataListPost(url: String, params: NSMutableDictionary, tag: Int) { isAlertError = true if self.currentPage == 1 { self.arrData.removeAllObjects() } // params.setValue(self.currentPage, forKey: "pageNumber") // params.setValue(self.pageSize, forKey: "pageSize") let http = CommonValue.getHttp() http.securityPolicy = customSecurityPolicy() http.responseSerializer = AFJSONResponseSerializer() // http.requestSerializer = AFHTTPRequestSerializer(); http.requestSerializer.setValue("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0", forHTTPHeaderField: "User-Agent") http.requestSerializer.setValue("application/json, text/javascript, */*; q=0.01", forHTTPHeaderField: "Accept") http.requestSerializer.setValue("topbarnewsshow=1; _ntes_nnid=8f33b5fed9dec9409bd4dc4994c7d59d,1525239051198; _ntes_nuid=8f33b5fed9dec9409bd4dc4994c7d59d; vjuids=3392fcda9.16339cc603e.0.6df8017661491; vjlast=1525683085.1526450258.11; vinfo_n_f_l_n3=63f469d9bed36f43.1.2.1525683085404.1525745136234.1526450292170; P_INFO=xiao77isgood@163.com|1526315502|0|mail163|10&17|shd&1526200230&mail163#shd&371300#10#0#0|&0|mail163|xiao77isgood@163.com; nts_mail_user=xiao77isgood@163.com:-1:1; mail_psc_fingerprint=9a1ed88d5a722fc9f1f216b7e86d50bc; topbarnewsshow=1", forHTTPHeaderField: "Cookie") // http.requestSerializer.setValue("text/json; charset=gbk", forHTTPHeaderField: "Content-Type") http.post(url, parameters: params, progress: nil, success: { (_, json1) -> Void in // print(String(NSString(data: json1 as! Data, encoding: String.Encoding.utf8.rawValue)!)) let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "success") as! Bool if succeed { if self.currentPage == 1 { self.arrData.removeAllObjects() } let dataInfo = json["data"] as? NSDictionary if dataInfo != nil { let array = dataInfo!["dataList"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrData.add(dicNew) } } } else { let array = json["data"] as? NSArray let dic: NSDictionary = array![0] as! NSDictionary var dataArr = dic["activityModelList"] as? NSArray if dic["machineTypeModelList"] != nil { dataArr = dic["machineTypeModelList"] as? NSArray } if dataArr != nil { for dic in dataArr! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrData.add(dicNew) } } } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: "") if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } }, failure: { (_, err) -> Void in CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func loadDataListPostMerchants(url: String, params: NSMutableDictionary, tag: Int) { isAlertError = true if self.currentPage == 1 { self.arrDataMj.removeAllObjects() } // params.setValue(self.currentPage, forKey: "pageNumber") // params.setValue(self.pageSize, forKey: "pageSize") let http = CommonValue.getHttp() http.securityPolicy = customSecurityPolicy() http.responseSerializer = AFJSONResponseSerializer() // http.requestSerializer = AFHTTPRequestSerializer(); http.requestSerializer.setValue("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0", forHTTPHeaderField: "User-Agent") http.requestSerializer.setValue("application/json, text/javascript, */*; q=0.01", forHTTPHeaderField: "Accept") http.requestSerializer.setValue("topbarnewsshow=1; _ntes_nnid=8f33b5fed9dec9409bd4dc4994c7d59d,1525239051198; _ntes_nuid=8f33b5fed9dec9409bd4dc4994c7d59d; vjuids=3392fcda9.16339cc603e.0.6df8017661491; vjlast=1525683085.1526450258.11; vinfo_n_f_l_n3=63f469d9bed36f43.1.2.1525683085404.1525745136234.1526450292170; P_INFO=xiao77isgood@163.com|1526315502|0|mail163|10&17|shd&1526200230&mail163#shd&371300#10#0#0|&0|mail163|xiao77isgood@163.com; nts_mail_user=xiao77isgood@163.com:-1:1; mail_psc_fingerprint=9a1ed88d5a722fc9f1f216b7e86d50bc; topbarnewsshow=1", forHTTPHeaderField: "Cookie") // http.requestSerializer.setValue("text/json; charset=gbk", forHTTPHeaderField: "Content-Type") http.post(url, parameters: params, progress: nil, success: { (_, json1) -> Void in // print(String(NSString(data: json1 as! Data, encoding: String.Encoding.utf8.rawValue)!)) let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "success") as! Bool if succeed { if self.currentPage == 1 { self.arrDataMj.removeAllObjects() } let dataInfo = json["data"] as? NSDictionary if dataInfo != nil { let array = dataInfo!["dataList"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrDataMj.add(dicNew) } } } else { let array = json["data"] as? NSArray let dic: NSDictionary = array![0] as! NSDictionary var dataArr = dic["activityModelList"] as? NSArray if dic["machineTypeModelList"] != nil { dataArr = dic["machineTypeModelList"] as? NSArray } if dataArr != nil { for dic in dataArr! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrDataMj.add(dicNew) } } } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: "") if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } }, failure: { (_, err) -> Void in CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func loadDataList(url: String, params: NSMutableDictionary, tag: Int, array: NSMutableArray) { isAlertError = true params.setValue(self.currentPage, forKey: "pageNumber") params.setValue(self.pageSize, forKey: "pageSize") let http = CommonValue.getHttp() http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "succeed") as! String if succeed == "000" { let dataInfo = json["dataInfo"] as? NSDictionary if dataInfo != nil { let arrayTemp = dataInfo!["dataList"] as? NSArray if arrayTemp != nil { for dic in arrayTemp! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) array.add(dicNew) } } } else { let arrayTemp = json["dataInfo"] as? NSArray if arrayTemp != nil { for dic in arrayTemp! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) array.add(dicNew) } } } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: succeed) if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } }, failure: { (_, err) -> Void in CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func TloadDataList(url: String, params: NSMutableDictionary, tag: Int, array: NSMutableArray) { isAlertError = true params.setValue(self.currentPage, forKey: "pageNumber") params.setValue(self.pageSize, forKey: "pageSize") params.setValue(CommonValue.getUserId(), forKey: "userId") let http = CommonValue.getHttp() print(params) http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "statusCode") as! Int if succeed == 200 { let dataInfo = json["dataInfo"] as? NSDictionary if dataInfo != nil { let arrayTemp = dataInfo!["dataList"] as? NSArray if arrayTemp != nil { for dic in arrayTemp! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) array.add(dicNew) } } } else { let dicn = ["name":"全部","id":"FFFFFF"] // array.add(dicn) let arrayTemp = json["data"] as? NSArray if arrayTemp != nil { for dic in arrayTemp! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) array.add(dicNew) } } } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: "\(succeed)") if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "message") as? String) } } }, failure: { (_, err) -> Void in CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } let dicDataList = NSMutableDictionary() func loadDataList(url: String, params: NSMutableDictionary, tableView: UITableView, tag: Int) { isAlertError = true if self.currentPage == 1 { self.arrData.removeAllObjects() } params.setValue(self.currentPage, forKey: "pageNumber") params.setValue(self.pageSize, forKey: "pageSize") MBProgressHUD.showAdded(to: self.view, animated: true) let http = CommonValue.getHttp() http.get(url, parameters: params, progress: nil, success: {[weak self] (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "succeed") as! String if succeed == "000" { if self!.currentPage == 1 { self!.arrData.removeAllObjects() } let dataInfo = json["dataInfo"] as? NSDictionary if dataInfo != nil { self!.dicDataList.setDic(dic: dataInfo!) self!.dicData.setDictionary(dataInfo as! [AnyHashable: Any]) let array = dataInfo!["dataList"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self!.arrData.add(dicNew) } }else{ let array1 = dataInfo!["agents"] as? NSArray for dic in array1 ?? [] { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self!.arrData.add(dicNew) } } } else { let array = json["dataInfo"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self!.arrData.add(dicNew) } } } let dataS = json["dataSize"] as? NSDictionary if dataS != nil { self?.dataSize = dataS } self!.returnData(tag: tag) } else { self!.returnError(tag: tag, type: succeed) if self!.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } if self!.arrData.count > 0 { self!.hiddenNoDataViewForTableView(tableView: tableView) } else { self!.showNoDataViewForTableView(tableView: tableView) } if tableView.mj_header != nil { tableView.mj_header?.endRefreshing() } if tableView.mj_footer != nil { tableView.mj_footer?.endRefreshing() } MBProgressHUD.hide(for: self?.view ?? UIView.init(), animated: true) }, failure: { (_, err) -> Void in MBProgressHUD.hide(for: self.view, animated: true) if tableView.mj_header != nil { tableView.mj_header?.endRefreshing() } if tableView.mj_footer != nil { tableView.mj_footer?.endRefreshing() } CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func TloadDataList(url: String, params: NSMutableDictionary, tableView: UITableView, tag: Int) { isAlertError = true if self.currentPage == 1 { self.arrData.removeAllObjects() } params.setValue(self.currentPage, forKey: "currentPage") params.setValue(self.pageSize, forKey: "showCount") params.setValue(CommonValue.getUserId(), forKey: "userId") let http = CommonValue.getHttp() http.get(url, parameters: params, progress: nil, success: {[weak self] (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "statusCode") as! Int if succeed == 200 { if self!.currentPage == 1 { self!.arrData.removeAllObjects() } let dataInfo = json["data"] as? NSDictionary if dataInfo != nil { self!.dicDataList.setDic(dic: dataInfo!) let array = dataInfo!["resultList"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self!.arrData.add(dicNew) } } } else { let array = json["data"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self!.arrData.add(dicNew) } } } let dataS = json["dataSize"] as? NSDictionary if dataS != nil { self?.dataSize = dataS } self!.returnData(tag: tag) } else { self!.returnError(tag: tag, type: "\(succeed)") if self!.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "message") as? String) } } if self!.arrData.count > 0 { self!.hiddenNoDataViewForTableView(tableView: tableView) } else { self!.showNoDataViewForTableView(tableView: tableView) } if tableView.mj_header != nil { tableView.mj_header?.endRefreshing() } if tableView.mj_footer != nil { tableView.mj_footer?.endRefreshing() } }, failure: { (_, err) -> Void in if tableView.mj_header != nil { tableView.mj_header?.endRefreshing() } if tableView.mj_footer != nil { tableView.mj_footer?.endRefreshing() } CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func loadDataListForCollectionView(url: String, params: NSMutableDictionary, collectionView: UICollectionView, tag: Int) { isAlertError = true if self.currentPage == 1 { self.arrData.removeAllObjects() } params.setValue(self.currentPage, forKey: "pageNumber") params.setValue(self.pageSize, forKey: "pageSize") print(params) let http = CommonValue.getHttp() http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "succeed") as! String if succeed == "000" { if self.currentPage == 1 { self.arrData.removeAllObjects() } let dataInfo = json["dataInfo"] as? NSDictionary if dataInfo != nil { let array = dataInfo!["dataList"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrData.add(dicNew) } } } else { let array = json["dataInfo"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrData.add(dicNew) } } } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: succeed) if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } // if(self.arrData.count > 0) // { // self.hiddenNoDataViewForTableView(tableView: tableView) // } // else // { // self.showNoDataViewForTableView(tableView: tableView) // } if collectionView.mj_header != nil { collectionView.mj_header?.endRefreshing() } if collectionView.mj_footer != nil { collectionView.mj_footer?.endRefreshing() } }, failure: { (_, err) -> Void in if collectionView.mj_header != nil { collectionView.mj_header?.endRefreshing() } if collectionView.mj_footer != nil { collectionView.mj_footer?.endRefreshing() } CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func TloadDataListForCollectionView(url: String, params: NSMutableDictionary, collectionView: UICollectionView, tag: Int) { isAlertError = true if self.currentPage == 1 { self.arrData.removeAllObjects() } params.setValue(self.currentPage, forKey: "currentPage") params.setValue(self.pageSize, forKey: "showCount") print(params) let http = CommonValue.getHttp() http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "statusCode") as! Int if succeed == 200 { if self.currentPage == 1 { self.arrData.removeAllObjects() } let dataInfo = json["data"] as? NSDictionary if dataInfo != nil { let array = dataInfo!["resultList"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrData.add(dicNew) } } } else { let array = json["dataInfo"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrData.add(dicNew) } } } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: "\(succeed)") if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "message") as? String) } } // if(self.arrData.count > 0) // { // self.hiddenNoDataViewForTableView(tableView: tableView) // } // else // { // self.showNoDataViewForTableView(tableView: tableView) // } if collectionView.mj_header != nil { collectionView.mj_header?.endRefreshing() } if collectionView.mj_footer != nil { collectionView.mj_footer?.endRefreshing() } }, failure: { (_, err) -> Void in if collectionView.mj_header != nil { collectionView.mj_header?.endRefreshing() } if collectionView.mj_footer != nil { collectionView.mj_footer?.endRefreshing() } CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func loadDataInfo(url: String, params: NSMutableDictionary, tag: Int, reDic: NSMutableDictionary) { isAlertError = true let http = CommonValue.getHttp() MBProgressHUD.showAdded(to: self.view, animated: true) http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "succeed") as! String if succeed == "000" { self.dicBackDataAnyObject = json["dataInfo"] as AnyObject let dataInfo = json["dataInfo"] as? NSDictionary if dataInfo != nil { reDic.setDictionary(dataInfo as! [AnyHashable: Any]) } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: succeed) if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } MBProgressHUD.hide(for: self.view, animated: true) }, failure: { (_, err) -> Void in MBProgressHUD.hide(for: self.view, animated: true) CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func loadDataInfo(url: String, params: NSMutableDictionary, tag: Int) { isAlertError = true let http = CommonValue.getHttp() MBProgressHUD.showAdded(to: self.view, animated: true) http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "succeed") as! String if succeed == "000"||succeed == "0000" { let dataInfo = json["dataInfo"] as? NSDictionary if dataInfo != nil { self.dicData.setDictionary(dataInfo as! [AnyHashable: Any]) } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: succeed) if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } MBProgressHUD.hide(for: self.view, animated: true) }, failure: { (_, err) -> Void in MBProgressHUD.hide(for: self.view, animated: true) CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func TloadDataInfo(url: String, params: NSMutableDictionary, tag: Int) { isAlertError = true let http = CommonValue.getHttp() MBProgressHUD.showAdded(to: self.view, animated: true) http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "statusCode") as! Int if succeed == 200 { let dataInfo = json["data"] as? NSDictionary if dataInfo != nil { self.dicData.setDictionary(dataInfo as! [AnyHashable: Any]) } self.returnData(tag: tag) } else { if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "message") as? String) } } MBProgressHUD.hide(for: self.view, animated: true) }, failure: { (_, err) -> Void in MBProgressHUD.hide(for: self.view, animated: true) CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func submitData(url: String, params: NSMutableDictionary, tag: Int) { isAlertError = true let http = CommonValue.getHttp() MBProgressHUD.showAdded(to: self.view, animated: true) http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "succeed") as! String if succeed == "000" { self.dicBackDataAnyObject = json["dataInfo"] as AnyObject let dataInfo = json["dataInfo"] as? NSDictionary if dataInfo != nil { self.dicBackData.setDictionary(dataInfo as! [AnyHashable: Any]) self.dicBackLoData = dataInfo } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: succeed) if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } MBProgressHUD.hide(for: self.view, animated: true) }, failure: { (_, err) -> Void in MBProgressHUD.hide(for: self.view, animated: true) CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func submitDatMachineInforList(url: String, params: NSMutableDictionary, tableView: UITableView, tag: Int) { isAlertError = true if self.currentPage == 1 { self.arrData.removeAllObjects() } params.setValue(self.currentPage, forKey: "currentPage") params.setValue(self.pageSize, forKey: "showCount") let http = CommonValue.getHttp() http.get(url, parameters: params, progress: nil, success: {[weak self] (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "success") as! Bool if succeed { if self!.currentPage == 1 { self!.arrData.removeAllObjects() } let dataInfo = json["data"] as? NSDictionary if dataInfo != nil { self!.dicDataList.setDic(dic: dataInfo!) let array = dataInfo!["machineInforList"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self!.arrData.add(dicNew) } } } else { let array = json["data"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self!.arrData.add(dicNew) } } } let dataS = json["dataSize"] as? NSDictionary if dataS != nil { self?.dataSize = dataS } self!.returnData(tag: tag) } else { self!.returnError(tag: tag, type: "") if self!.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } if self!.arrData.count > 0 { self!.hiddenNoDataViewForTableView(tableView: tableView) } else { self!.showNoDataViewForTableView(tableView: tableView) } if tableView.mj_header != nil { tableView.mj_header?.endRefreshing() } if tableView.mj_footer != nil { tableView.mj_footer?.endRefreshing() } }, failure: { (_, err) -> Void in if tableView.mj_header != nil { tableView.mj_header?.endRefreshing() } if tableView.mj_footer != nil { tableView.mj_footer?.endRefreshing() } CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func submitDatMachineInforNumdic(url: String, params: NSMutableDictionary, tag: Int) { isAlertError = true let http = CommonValue.getHttp() MBProgressHUD.showAdded(to: self.view, animated: true) http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in let json = json1 as! NSDictionary print(json) let succeed = json.object(forKey: "success") as! Bool if succeed { if self.currentPage == 1 { self.arrDataMj.removeAllObjects() } let dataInfo = json["data"] as? NSDictionary if dataInfo != nil { let array = dataInfo!["dataList"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrDataMj.add(dicNew) } } } else { let array = json["data"] as? NSArray if array != nil { for dic in array! { let dicNew = NSMutableDictionary(dictionary: dic as! NSDictionary) self.arrDataMj.add(dicNew) } } } self.returnData(tag: tag) } else { self.returnError(tag: tag, type: "") if self.isAlertError { SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String) } } MBProgressHUD.hide(for: self.view, animated: true) }, failure: { (_, err) -> Void in MBProgressHUD.hide(for: self.view, animated: true) CommonUntils.alertError(error: err as NSError) self.returnError(tag: tag, type: "9999") }) } func returnData(tag: Int) { } /// type:9999是异常 其他是后台返回的状态如 001 002 func returnError(tag: Int, type: String) { } // MARK: =========定位模块 ========= start ====== var updateLocationCount = 0 var locationManager: CLLocationManager! /// 开始定位 成功回调:returnLocationData func startLocation() { if locationManager == nil { locationManager = CLLocationManager() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest // kCLLocationAccuracyBest 精确度最佳 // kCLLocationAccuracynearestTenMeters 精确度10m以内 // kCLLocationAccuracyHundredMeters 精确度100m以内 // kCLLocationAccuracyKilometer 精确度1000m以内 // kCLLocationAccuracyThreeKilometers 精确度3000m以内 } locationManager.requestWhenInUseAuthorization() updateLocationCount = 0 locationManager.startUpdatingLocation() } /// 返回定位成功的坐标 latitude:纬度 longitude:经度 location:用作取详情地址信息 func returnLocationData(latitude: Double, coordinate: Double, location: CLLocation) { } /// 定位失败返回 func returnLocationError(error: Error) { } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let location = locations.last if location != nil && location!.coordinate.latitude > 0 && location!.coordinate.longitude > 0 { let coordinate = location!.coordinate print("纬度:\(coordinate.latitude) 经度:\(coordinate.longitude)") returnLocationData(latitude: coordinate.longitude, coordinate: coordinate.longitude, location: location!) locationManager.stopUpdatingLocation() } else { if updateLocationCount > 20 { locationManager.stopUpdatingLocation() } updateLocationCount += 1 } } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { returnLocationError(error: error) locationManager.stopUpdatingLocation() } ///根据位置信息获取详情的街道地址 成功返回:returnLoctionDetailInfo func getLoationDetailInfo(location: CLLocation) { let clGeocoder = CLGeocoder() clGeocoder.reverseGeocodeLocation(location, completionHandler: { ( placemarks, _) in var isWin = false if placemarks != nil { for dic in placemarks! { let addressDic = dic.addressDictionary //print(addressDic); if addressDic != nil { print(addressDic!) if addressDic!["State"] as? String != nil && addressDic!["City"] as? String != nil && addressDic!["SubLocality"] as? String != nil && addressDic!["Name"] as? String != nil { isWin = true self.returnLoctionDetailInfo(dic: addressDic! as NSDictionary, ad1: addressDic!["State"] as! String, ad2: addressDic!["City"] as! String, ad3: addressDic!["SubLocality"] as! String, ad4: addressDic!["Name"] as! String) } break } } } if !isWin { self.returnLoctionDetailError() } }) } /// 获取详细信息出错回调 func returnLoctionDetailInfo(dic: NSDictionary, ad1: String, ad2: String, ad3: String, ad4: String) { } func returnLoctionDetailError() { } func printLog(_ dic: Any) { if isPrintLog { print(dic) } } deinit { if isPrintLog { print("=====deinit==\(self.classForCoder)==") } } ///设置导航栏透明,且不占空间 func setNavTranslucent(isTran: Bool) { if isTran { self.automaticallyAdjustsScrollViewInsets = false self.navigationController?.navigationBar.isTranslucent = true self.navigationController?.navigationBar.backgroundColor = UIColor.clear self.navigationController?.navigationBar.tintColor = UIColor.clear self.navigationController?.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) } else { self.navigationController?.navigationBar.isTranslucent = false // if(CommonUntils.isX()) // { // self.navigationController?.navigationBar.setBackgroundImage(UIImage(named:"a_titleX"), for: .default) // } // else // { self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: "a_title"), for: .default) // } } } /// 重新加载后更新用户信息 @objc func notiReloadUser(noti: NSNotification) { } func initCusServiceBackButton(viewController: UIViewController) { let backBtn = UIButton(type: UIButton.ButtonType.custom) backBtn.frame = CGRect(x: 0, y: 0, width: 45, height: 50) backBtn.setImage(UIImage(named: "ion_return-arrow"), for: .normal) backBtn.contentHorizontalAlignment = .left backBtn.addTarget(self, action: #selector(self.handleBack), for: UIControl.Event.touchUpInside) let backBarBtnItem=UIBarButtonItem(customView: backBtn) viewController.navigationItem.leftBarButtonItem = backBarBtnItem viewController.navigationItem.rightBarButtonItem = UIBarButtonItem() } // MARK: =========定位模块 ============ end ====== override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) appDelegate.setNavigationBarHidden(isHidden: false) NotificationCenter.default.addObserver(self, selector: #selector(self.notiReloadUser(noti:)), name: NSNotification.Name(rawValue: "noti_reload_user"), object: nil) appDelegate.initSystem() } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: "noti_reload_user"), object: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // required init?(coder aDecoder: NSCoder) { // fatalError("init(coder:) has not been implemented") // } // // override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { // let className = String(describing: type(of:self )); // if(Bundle.main.path(forResource: className, ofType: "xib") == nil) // { // super.init(nibName: nil, bundle: nil); // } // else // { // super.init(nibName:className , bundle: nil) // } // // } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ }