// // BrandListViewController.swift // xingchuangke // // Created by 李晓飞 on 2020/8/8. // Copyright © 2020 Virgil. All rights reserved. // import UIKit @objcMembers class BrandListViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource { var targetStr: String? var strTitle: String? var machineTypeArr: NSArray = [] let tableView: UITableView = { let tab = UITableView.init(frame: CGRect.zero, style: .plain) tab.tableFooterView = UIView.init() return tab }() let headerView: CommonHeaderView = { let headerV = CommonHeaderView.init(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 180)) headerV.isCycle = false headerV.dataView.earnTitLbl.text = "本月总交易(元)" headerV.dataView.rewardTitLbl.text = "本日总交易(元)" return headerV }() let headerViewSH: CommonHeaderView = { let headerV = CommonHeaderView.init(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 180)) headerV.isCycle = true headerV.dataView.earnTitLbl.text = "本月新增商户(个)" headerV.dataView.rewardTitLbl.text = "本日新增商户(个)" headerV.dataView1.earnTitLbl.text = "交易已达标" headerV.dataView1.rewardTitLbl.text = "交易未达标" headerV.dataView1.rewardControl.addTarget(self, action: #selector(rewardClick), for: .touchUpInside) return headerV }() @objc func rewardClick( ) { let vc = MerchantsStateVC() appDelegate.navController.pushViewController(vc, animated: true) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) appDelegate.setNavigationBarHidden(isHidden: false) } override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.init(white: 246/255.0, alpha: 1.0) self.title = strTitle initNavLeftBackButton() tableView.frame = self.view.bounds tableView.delegate = self tableView.dataSource = self if strTitle == "商户管理" { tableView.tableHeaderView = headerViewSH } if strTitle == "交易管理" { tableView.tableHeaderView = headerView } // tableView.marginTop(top: viewNav.bottom()) self.view.addSubview(tableView) loadData() } // MARK: - request func loadData() { let url1 = RequestURL.machineInforNum let params1 = NSMutableDictionary() params1.setValue(CommonValue.getUserId(), forKey: "userId") params1.setValue("", forKey: "machineTypeId") submitDatMachineInforNumdic(url: url1, params: params1, tag: 1001) let url = RequestURL.activityAuth let params = NSMutableDictionary() params.setValue(CommonValue.getUserId(), forKey: "userId") params.setValue("0001", forKey: "code") loadDataListPost(url: url, params: params, tag: 1001) let url2 = RequestURL.sumCountByMonthByDay let param = NSMutableDictionary() param.setValue(CommonValue.getUserId(), forKey: "userId") loadDataInfo(url: url2, params: param, tag: 1002) } override func returnData(tag: Int) { machineTypeArr = arrData for dic in arrDataMj { let succeed = (dic as! NSDictionary).object(forKey: "name") as! String if succeed == "交易达标" { headerViewSH.dataView1.earnLbl.text = "\((dic as! NSDictionary)["num"] as! Int)" }else if succeed == "交易未达标" { headerViewSH.dataView1.rewardLbl.text = "\((dic as! NSDictionary)["num"] as! Int)" } } NSLog("\(dicData)") if (tag==1002){ // if strTitle == "交易管理" { // headerView.dataView.earnLbl.text = "\(getString(key: "momthTransaction"))" // headerView.dataView.rewardLbl.text = "\(getString(key: "dayTransaction"))" // }else{ headerViewSH.dataView.earnLbl.text = "\(getIntValue(key: "momthCount"))" headerViewSH.dataView.rewardLbl.text = "\(getIntValue(key: "dayCount"))" headerView.dataView.earnLbl.text = "\(getDoubleValue(key: "momthTransaction"))" headerView.dataView.rewardLbl.text = "\(getDoubleValue(key: "dayTransaction"))" // } tableView.reloadData() } } override func returnError(tag: Int, type: String) { } // MARK: - tableviewdelegate func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return machineTypeArr.count } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 60 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cellId = "brandCellId" var cell = tableView.dequeueReusableCell(withIdentifier: cellId) if cell == nil { cell = UITableViewCell.init(style: .default, reuseIdentifier: cellId) let imgV = UIImageView.init(image: UIImage.init(named: "ion_arrow_right_gray")) cell?.accessoryView = imgV cell?.selectionStyle = .none cell?.textLabel?.font = UIFont.systemFont(ofSize: 15) } let machineDic: NSDictionary = machineTypeArr[indexPath.row] as! NSDictionary cell?.textLabel?.text = machineDic["machineTypeName"] as? String return cell! } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let machineDic: NSDictionary = machineTypeArr[indexPath.row] as! NSDictionary if strTitle == "交易管理" { let vc = TradeViewController() vc.machineTypeId = (machineDic["machineTypeId"] as! String) vc.titleStr = (machineDic["machineTypeName"] as! String) appDelegate.navController.pushViewController(vc, animated: true) } else if strTitle == "商户管理" { let vc = MyShopListViewController() vc.machineType = machineDic["machineTypeId"] as! String vc.strTitle = (machineDic["machineTypeName"] as! String) appDelegate.navController.pushViewController(vc, animated: true) } else if strTitle == "我的政策" { let vc = PolicyViewController() vc.index = indexPath.row vc.machineType = (machineDic["machineTypeId"] as! String) vc.title = (machineDic["machineTypeName"] as! String) appDelegate.navController.pushViewController(vc, animated: true) } } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ }