// // PosManangerViewController.swift // xingchuangke // // Created by Virgil on 2019/3/27. // Copyright © 2019 Virgil. All rights reserved. // import UIKit class PosManangerViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var lblOpenAmount: UILabel! @IBOutlet weak var lblAmount: UILabel! @IBOutlet weak var tableView: UITableView! @IBOutlet weak var viewTop: UIView! @IBOutlet weak var viewMenu1: UIView! @IBOutlet weak var viewMenu2: UIView! override func viewDidLoad() { super.viewDidLoad() self.title = "机具管理" let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView) viewNav.initView(title: "机具管理") {[weak self] (index, _) in if index == 0 { self!.handleBack() } } self.view.addSubview(viewNav) viewNav.marginTop(top: 0) viewTop.setSizeWidth(width: ScreenWidth) CommonViewUntils.setViewAverage(arrView: [viewMenu1, viewMenu2]) // tableView.register(UINib(nibName: "PosManangerTableViewCell", bundle:nil) , forCellReuseIdentifier: "PosManangerTableViewCell") tableView.delegate = self tableView.dataSource = self // tableView.separatorStyle = .none tableView.tableFooterView = UIView.init() tableView.showsVerticalScrollIndicator = false tableView.estimatedRowHeight = 100 tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in self!.currentPage = 1 self!.loadData() }) tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell" } // MARK: =============加载数据=============== func loadData() { let url = RequestURL.machineTypeNumList let params = NSMutableDictionary() params.setValue(CommonValue.getUserId(), forKey: "userId") loadDataList(url: url, params: params, tableView: self.tableView, tag: 1001) } override func returnData(tag: Int) { if tag == 1001 { if dataSize != nil { let strAmount = "\(dataSize!["total"] ?? "0")台" lblAmount.attributedText = CommonViewUntils.getAttributedStringForFont(str: strAmount, rangs: [NSRange.init(location: 0, length: strAmount.length() - 1), NSRange.init(location: strAmount.length() - 1, length: 1)], fonts: [UIFont.systemFont(ofSize: 24), UIFont.systemFont(ofSize: 14)]) let bindNum = getIntValue(key: "status1", dic: dataSize!) let activNum = getIntValue(key: "status2", dic: dataSize!) let strOpenAmount = "\(bindNum + activNum)台" lblOpenAmount.attributedText = CommonViewUntils.getAttributedStringForFont(str: strOpenAmount, rangs: [NSRange.init(location: 0, length: strOpenAmount.length() - 1), NSRange.init(location: strOpenAmount.length() - 1, length: 1)], fonts: [UIFont.systemFont(ofSize: 24), UIFont.systemFont(ofSize: 14)]) } // var amount = 0; // var openAmount = 0; // for i in 0 ..< self.arrData.count // { // amount += getIntValue(current: i, key: "total") // openAmount += getIntValue(current: i, key: "activated") // } // let strAmount = "\(amount)台" // let strOpenAmount = "\(openAmount)台" // lblAmount.attributedText = CommonViewUntils.getAttributedStringForFont(str: strAmount, rangs: [NSRange.init(location: 0, length: strAmount.length() - 1),NSRange.init(location: strAmount.length() - 1, length: 1)], fonts: [UIFont.systemFont(ofSize: 24),UIFont.systemFont(ofSize: 14)]) // // lblOpenAmount.attributedText = CommonViewUntils.getAttributedStringForFont(str: strOpenAmount, rangs: [NSRange.init(location: 0, length: strOpenAmount.length() - 1),NSRange.init(location: strOpenAmount.length() - 1, length: 1)], fonts: [UIFont.systemFont(ofSize: 24),UIFont.systemFont(ofSize: 14)]) tableView.reloadData() } } override func returnError(tag: Int, type: String) { } // MARK: TABLEVLEW 实现 // 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 { return 60 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // let cell = tableView.dequeueReusableCell(withIdentifier: "PosManangerTableViewCell", for: indexPath as IndexPath) as! PosManangerTableViewCell // // cell.lblTitle.text = getString(current: indexPath.row, key: "name") // //cell.lblRemark.text = getString(current: indexPath.row, key: "brief"); // cell.img.loadImage(imgUrl: getString(current: indexPath.row, key: "icon"), defaultImage: ""); // cell.lblCount.text = "\(getIntValue(current: indexPath.row, key: "total"))台" // return cell var cell = tableView.dequeueReusableCell(withIdentifier: "posManagerCell") if cell == nil { cell = UITableViewCell.init(style: .value1, reuseIdentifier: "posManagerCell") cell?.detailTextLabel?.textColor = UIColor.red cell?.detailTextLabel?.font = UIFont.systemFont(ofSize: 14) cell?.accessoryType = .disclosureIndicator } cell?.textLabel!.text = getString(current: indexPath.row, key: "name") cell?.detailTextLabel!.text = "\(getIntValue(current: indexPath.row, key: "total"))台" return cell! } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.row >= arrData.count { return } let vc = PosViewController() vc.amount = getIntValue(current: indexPath.row, key: "total") vc.bindAmount = getIntValue(current: indexPath.row, key: "bound") vc.activated = getIntValue(current: indexPath.row, key: "activated") vc.unBindAmount = getIntValue(current: indexPath.row, key: "unbound") vc.machineTypeId = getString(current: indexPath.row, key: "id") vc.titleName = getString(current: indexPath.row, key: "name") toViewController(viewController: vc) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) appDelegate.setNavigationBarHidden(isHidden: true) tableView.mj_header?.beginRefreshing() } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "PosManangerViewController", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }