// // MyOrderViewController.swift // CommonFrame // // Created by Virgil on 2019/4/19. // Copyright © 2019 Virgil. All rights reserved. // import UIKit class MyOrderViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var tableView: UITableView! ///0:正常返回 1:返回到商城页 var fromType = 0 override func viewDidLoad() { super.viewDidLoad() self.title = "我的订单" initNavLeftBackButton() tableView.register(UINib(nibName: "MyOrderListTableViewCell", bundle: nil), forCellReuseIdentifier: "MyOrderListTableViewCell") 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 = "MyOrderListTableViewCell" tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in self!.currentPage += 1 self!.loadData() }) tableView.mj_header?.beginRefreshing() // Do any additional setup after loading the view. } override func handleBack() { if fromType == 0 { super.handleBack() } else { if !CommonUntils.reBackView(controller: self, aclass: ShoppingMallViewController.classForCoder()) { self.navigationController?.popToRootViewController(animated: true) } } } // MARK: =============加载数据=============== func loadData() { let url = RequestURL.getProductOrderMainList let params = NSMutableDictionary() TloadDataList(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 100 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "MyOrderListTableViewCell", for: indexPath as IndexPath) as! MyOrderListTableViewCell cell.selectionStyle = .none //cell.lblTitle.text = getString(indexPath.row, key: "Name") let dic = self.arrData[indexPath.row]as!NSDictionary cell.initCell(rowIndex: indexPath.row, dic: dic) cell.btn1.addTarget(self, action: #selector(btnTouc(sender:)), for: .touchUpInside) cell.btn2.addTarget(self, action: #selector(btnTouc(sender:)), for: .touchUpInside) cell.btn3.addTarget(self, action: #selector(btnTouc(sender:)), for: .touchUpInside) cell.btn1.tag = indexPath.row cell.btn2.tag = indexPath.row cell.btn3.tag = indexPath.row return cell } @objc func btnTouc(sender: UIButton) { let index = sender.tag let lin = Int(sender.titleLabel!.text!) let dic = self.arrData[index]as!NSDictionary let array = dic["productOrderlist"]as!NSArray let goodsDic = array[lin!]as!NSDictionary let view = ShoppingMallDetailViewController() view.id = goodsDic.getString(key: "product_id") self.navigationController?.pushViewController(view, animated: true) } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) let dic = self.arrData[indexPath.row]as!NSDictionary let vc = MyOrderDtialViewController() //let dicProduct = (self.arrData[indexPath.row] as! NSDictionary)["product"] as! NSDictionary; vc.orderId = dic.getString(key: "id") //vc.dicData.setDictionary((self.arrData[indexPath.row] as! NSDictionary) as! [AnyHashable : Any]) toViewController(viewController: vc) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if common_back_is_reload { loadData() common_back_is_reload = false } } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "MyOrderViewController", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }