// // ShoppingMallViewController.swift // CommonFrame // // Created by Virgil on 2019/4/18. // Copyright © 2019 Virgil. All rights reserved. // import UIKit class ShoppingMallViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var tableViewMarginBottom: NSLayoutConstraint! @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() initNavLeftBackButton() tableView.register(UINib(nibName: "ShoppingMallTableViewCell", bundle: nil), forCellReuseIdentifier: "ShoppingMallTableViewCell") 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() }) if #available(iOS 11.0, *) { } else { tableViewMarginBottom.constant = 48 } tableView.mj_header?.beginRefreshing() initNavRightButtonForTitle(title: "我的订单", color: UIColor.white) } override func btnRightMenuClick() { toViewController(viewController: MyOrderViewController()) } // MARK: =============加载数据=============== func loadData() { let url = RequestURL.productPageList let params = NSMutableDictionary() loadDataList(url: url, params: params, tableView: self.tableView, tag: 1001) } override func returnData(tag: Int) { if tag == 1001 { tableView.reloadData() } } override func returnError(tag: Int, type: String) { } // 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 140 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ShoppingMallTableViewCell", for: indexPath as IndexPath) as! ShoppingMallTableViewCell cell.lblName.text = getString(current: indexPath.row, key: "name") cell.lblDesc.text = "数量:\(getIntValue(current: indexPath.row, key: "num")) | 销量:\(getIntValue(current: indexPath.row, key: "sales_num"))" let strPrice = "¥\(getDoubleValue(current: indexPath.row, key: "price", defaultValue: 0.0))" cell.lblMoney.attributedText = CommonViewUntils.getAttributedStringForFont(str: strPrice, rangs: [NSRange.init(location: 0, length: 1), NSRange.init(location: 1, length: strPrice.length() - 1)], fonts: [UIFont.systemFont(ofSize: 10), UIFont.systemFont(ofSize: 14)]) cell.imgShow.loadImage(imgUrl: getString(current: indexPath.row, key: "image"), defaultImage: "") return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let view = ShoppingMallDetailViewController() view.id = getString(current: indexPath.row, key: "id") self.navigationController?.pushViewController(view, animated: true) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.title = "优惠商城" } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "ShoppingMallViewController", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }