// // WalletMainViewController.swift // xingchuangke // // Created by 李晓飞 on 2020/8/11. // Copyright © 2020 Virgil. All rights reserved. // import UIKit class WalletMainViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var topView: UIView! @IBOutlet weak var tableView: UITableView! var machineTypeArr: NSArray = [] let headerView: CommonHeaderView = { let headerV = CommonHeaderView.init(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 180)) headerV.isCycle = false headerV.isMoney = true headerV.setupUI() return headerV }() let footer: UIView = { let w = UIScreen.main.bounds.width let view = UIView.init(frame: CGRect.init(x: 0, y: 0, width: w, height: 160)) view.backgroundColor = UIColor.init(white: 245/255.0, alpha: 1.0) return view }() let withdrawBtn: UIButton = { let w = UIScreen.main.bounds.width let btn = UIButton.init(type: .custom) btn.backgroundColor = UIColor.init(red: 42/255.0, green: 146/255.0, blue: 247/255.0, alpha: 1.0) btn.frame = CGRect.init(x: 0, y: 0, width: w - 60, height: 44) btn.setTitle("提现", for: .normal) btn.layer.cornerRadius = 22 return btn }() //10 10 10 10 20 40 80 80 override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // appDelegate.setNavigationBarHidden(isHidden: false) appDelegate.setNavigationBarHidden(isHidden: true) self.tabBarController?.title = "我的钱包" loadData() } override func viewDidLoad() { super.viewDidLoad() navInit() footer.addSubview(withdrawBtn) withdrawBtn.center = footer.center withdrawBtn.addTarget(self, action: #selector(withdrawBtnBlock), for: .touchUpInside) tableView.frame = self.view.bounds tableView.tableFooterView = UIView.init() tableView.delegate = self tableView.dataSource = self self.view.addSubview(tableView) tableView.tableHeaderView = headerView tableView.tableFooterView = footer } // 自定义导航栏 func navInit() { let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView) viewNav.initView(title: "我的钱包") {[weak self] (index, _) in if index == 1 { // self!.handleBack(); // 提现记录 let vc = TiXianRecordListViewController() self?.navigationController?.pushViewController(vc, animated: true) } } self.view.addSubview(viewNav) viewNav.btnLeft.isHidden = true viewNav.initRightBtn(title: "提现记录") topView.translatesAutoresizingMaskIntoConstraints = false let h: NSLayoutConstraint = NSLayoutConstraint(item: topView as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0.0, constant: viewNav.bottom()) topView.addConstraint(h) } // MARK: - action @objc func withdrawBtnBlock() { let vc = TiXianViewController() vc.machineTypeId = "" var all = 0.0 all = getDoubleValue(key: "profitBalance") vc.withdraw = "\(String(format: "%.2f", all))" self.navigationController?.pushViewController(vc, animated: true) } override func btnRightMenuClick() { let vc = TiXianRecordListViewController() vc.machineTypeId = "" self.navigationController?.pushViewController(vc, animated: true) } // MARK: - request func loadData() { let url = RequestURL.findUserById let params = NSMutableDictionary() params.setValue(CommonValue.getUserId(), forKey: "userId") loadDataInfo(url: url, params: params, tag: 1001) let url1 = RequestURL.activityAuth let params1 = NSMutableDictionary() params1.setValue(CommonValue.getUserId(), forKey: "userId") params1.setValue("0001", forKey: "code") loadDataListPost(url: url1, params: params1, tag: 1002) } override func returnData(tag: Int) { if tag == 1001 { var all = 0.0 all = getDoubleValue(key: "profitBalance") var all1 = 0.0 all1 = getDoubleValue(key: "UnallocatedBalance") let all2 = all + all1 headerView.dataView2.earnLbl.text = "¥\(String(format: "%.2f", all2))" headerView.dataView2.rewardLbl.text = "¥\(String(format: "%.2f", all))" headerView.dataView2.dhMoney.text = "¥\(String(format: "%.2f", all1))" } if tag == 1002 { machineTypeArr = arrData } 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) } if machineTypeArr.count != 0 { let machineDic: NSDictionary = machineTypeArr[indexPath.row] as! NSDictionary cell?.textLabel?.text = machineDic["machineTypeName"] as? String } return cell! } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if machineTypeArr.count != 0 { let machineDic: NSDictionary = machineTypeArr[indexPath.row] as! NSDictionary let vc = WalletRecordViewController() vc.type = indexPath.row vc.machineTypeId = (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. } */ }