// // PosListViewController.swift // xingchuangke // // Created by Virgil on 2019/4/3. // Copyright © 2019 Virgil. All rights reserved. // import UIKit class PosListViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate { @IBOutlet weak var lblTitle: UILabel! @IBOutlet weak var tableView: UITableView! var machineTypeId = "" var amount = 0 var bindAmount = 0 var activated = 0 var unBindAmount = 0 var strTitle = "" @IBOutlet weak var imgBackgroud: UIImageView! @IBOutlet weak var txtCode: UITextField! @IBOutlet weak var viewMenu: UIView! @IBOutlet weak var viewRemark: UIView! override func viewDidLoad() { super.viewDidLoad() let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView) viewNav.initView(title: "\(strTitle)") {[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.setContentMarginRight(rightWidth: 30) txtCode.delegate = self imgBackgroud.setSizeHeight(height: viewMenu.bottom()) viewRemark.marginTop(top: 0, view: imgBackgroud) tableView.marginTop(top: 1, view: viewRemark) tableView.setSizeHeight(height: ScreenHeight - imgBackgroud.height() - 44) tableView.register(UINib(nibName: "PosListTableViewCell", bundle: nil), forCellReuseIdentifier: "PosListTableViewCell") tableView.delegate = self tableView.dataSource = self tableView.separatorStyle = .none tableView.showsVerticalScrollIndicator = false tableView.estimatedRowHeight = 100 tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in self!.currentPage = 1 self!.loadData() }) tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell" tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in self!.currentPage += 1 self!.loadData() }) tableView.mj_header?.beginRefreshing() } override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) { txtCode.resignFirstResponder() } func textFieldShouldReturn(_ textField: UITextField) -> Bool { txtCode.resignFirstResponder() self.currentPage = 1 loadData() return true } // MARK: =============加载数据=============== func loadData() { let url = RequestURL.machineList let params = NSMutableDictionary() params.setValue(CommonValue.getUserId(), forKey: "userId") params.setValue(machineTypeId, forKey: "machineTypeId") params.setValue(txtCode.text!, forKey: "snCode") loadDataList(url: url, params: params, tableView: self.tableView, tag: 1001) //tableView.reloadData(); } override func returnData(tag: Int) { if tag == 1001 { tableView.reloadData() } } override func returnError(tag: Int, type: String) { } //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick)) @IBAction func btnMenuClick(_ sender: AnyObject) { switch (sender as! UIButton).tag { case 1001: // 查询 txtCode.resignFirstResponder() self.currentPage = 1 self.loadData() break case 1002: // break case 1003: // break case 1004: // break case 1005: // break case 1006: // break default: break } } // MARK: TABLEVLEW 实现 func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.arrData.count } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { let state = getIntValue(current: indexPath.row, key: "status") if state == 0 { return 220; //177 } else { return 177; //177 } } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "PosListTableViewCell", for: indexPath as IndexPath) as! PosListTableViewCell cell.btnBottom.isHidden = true let state = getIntValue(current: indexPath.row, key: "status") if state == 2 { cell.lblState.text = "已激活" cell.lblState.textColor = UIColor.red } else if state == 1 { cell.lblState.text = "已绑定" cell.lblState.textColor = UIColor.red } else if state == 0 { cell.lblState.text = "未绑定" cell.btnBottom.isHidden = false cell.lblState.textColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x0cab1f, alpha: 1.0) } else { cell.lblState.text = "已激活" cell.lblState.textColor = UIColor.red } cell.lblNo.text = "编号:\(getString(current: indexPath.row, key: "sn_code"))" cell.lblName.text = "\(getString(current: indexPath.row, key: "superior_user_name"))" cell.lblDate.text = "\(getString(current: indexPath.row, key: "allocation_time"))" cell.lblShopName.text = "\(getString(current: indexPath.row, key: "bind_merchant_name"))" cell.lblBindDate.text = "\(getString(current: indexPath.row, key: "bind_time"))" cell.btnBottom.tag = indexPath.row cell.btnBottom.addTarget(self, action: #selector(btnBottomClick(btn:)), for: .touchUpInside) return cell } @objc func btnBottomClick(btn: UIButton) { let vc = SplitDeviceViewController() vc.mid = getString(current: btn.tag, key: "id") toViewController(viewController: vc) } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { // let view = UIViewController() // view.oneGoId = self.arrData[indexPath.row]["ItemId"] as! Int // self.navigationController?.pushViewController(view, animated: true) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) appDelegate.setNavigationBarHidden(isHidden: true) let strAmount = "\(amount)" let strBindAmount = "\(bindAmount)" let strUnBindAmount = "\(unBindAmount)" let strActivated = "\(activated)" let str = "共\(strAmount)台 未绑定\(strUnBindAmount)台 已绑定\(strBindAmount)台 激活\(strActivated)台" lblTitle.attributedText = CommonViewUntils.getAttributedStringForFontAndColor(str: str, rangs: [NSRange.init(location: 0, length: 1), NSRange.init(location: 1, length: strAmount.length()), NSRange.init(location: strAmount.length() + 1, length: 5), NSRange.init(location: strAmount.length() + 6, length: strUnBindAmount.length()), NSRange.init(location: strAmount.length() + 6 + strUnBindAmount.length(), length: 4), NSRange.init(location: strAmount.length() + 6 + strUnBindAmount.length() + 5, length: strBindAmount.length()), NSRange.init(location: strAmount.length() + 6 + strUnBindAmount.length() + 5 + strBindAmount.length(), length: 4), NSRange.init(location: strAmount.length() + 6 + strUnBindAmount.length() + 5 + strBindAmount.length() + 4, length: strActivated.length()), NSRange.init(location: strAmount.length() + 6 + strUnBindAmount.length() + 5 + strBindAmount.length() + 4 + strActivated.length(), length: 1)], fonts: [UIFont.systemFont(ofSize: 13), UIFont.systemFont(ofSize: 13), UIFont.systemFont(ofSize: 13), UIFont.systemFont(ofSize: 13), UIFont.systemFont(ofSize: 13), UIFont.systemFont(ofSize: 13), UIFont.systemFont(ofSize: 13), UIFont.systemFont(ofSize: 13), UIFont.systemFont(ofSize: 13)], colors: [CommonUntils.getUIColorFromRGB(rgbValue: 0x333333, alpha: 1.0), UIColor.red, CommonUntils.getUIColorFromRGB(rgbValue: 0x333333, alpha: 1.0), UIColor.red, CommonUntils.getUIColorFromRGB(rgbValue: 0x333333, alpha: 1.0), UIColor.red, CommonUntils.getUIColorFromRGB(rgbValue: 0x333333, alpha: 1.0), UIColor.red, CommonUntils.getUIColorFromRGB(rgbValue: 0x333333, alpha: 1.0)]) } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "PosListViewController", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }