// // BrandForWithdrawViewController.swift // xingchuangke // // Created by 李晓飞 on 2020/9/7. // Copyright © 2020 Virgil. All rights reserved. // import UIKit typealias BrandForWithdrawBlock = (NSArray, Float) -> Void class BrandForWithdrawViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var tableView: UITableView! var withdrawBlock: BrandForWithdrawBlock? override func viewDidLoad() { super.viewDidLoad() self.title = "提现金额设置" initNavLeftBackButton() initNavRightButtonForTitle(title: "确定", color: UIColor.white) tableView.delegate = self tableView.dataSource = self tableView.tableFooterView = UIView.init() tableView.register(UINib(nibName: "BrandForWithdrawCell", bundle: nil), forCellReuseIdentifier: "BrandForWithdrawCell") loadData() } // MARK: - action override func btnRightMenuClick() { let tempArr = NSMutableArray() var totalEarn: Float = 0.0 for i in 0...(arrData.count - 1) { let indexPath = IndexPath.init(row: i, section: 0) let cell: BrandForWithdrawCell = tableView.cellForRow(at: indexPath) as! BrandForWithdrawCell let earn: NSString = (cell.earnTextField.text ?? "0") as NSString let sourceDic: NSDictionary = arrData[i] as! NSDictionary let balanceDouble = getDoubleValue(key: "profitBalance", dic: sourceDic) let balance = balanceDouble > 0 ? balanceDouble : 0 let dic = ["machineTypeId": sourceDic["id"] as! String, "money": cell.earnTextField.text as Any] as [String: Any] tempArr.add(dic) let earnF: Float = earn.floatValue totalEarn += earnF if earn.floatValue > Float(balance) { let show = "\(sourceDic["name"] ?? "")提现金额不得大于\(balance)" SVProgressHUD.showError(withStatus: show) return } } if withdrawBlock != nil { withdrawBlock!(tempArr, totalEarn) } self.navigationController?.popViewController(animated: true) } // MARK: - request func loadData() { let url = RequestURL.machineTypeListWhithCash let params = NSMutableDictionary() loadDataList(url: url, params: params, tag: 1001) } override func returnData(tag: Int) { tableView.reloadData() } override func returnError(tag: Int, type: String) { } // MARK: - delegate func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return arrData.count } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 60 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: BrandForWithdrawCell = tableView.dequeueReusableCell(withIdentifier: "BrandForWithdrawCell", for: indexPath) as! BrandForWithdrawCell cell.selectionStyle = .none let dic: NSDictionary = arrData[indexPath.row] as! NSDictionary cell.dataDic = dic cell.brandLabel.text = getString(key: "name", dic: dic) if getDoubleValue(key: "profitBalance", dic: dic) != 0{ cell.earnTextField.placeholder = "填写金额≤\(getDoubleValue(key: "profitBalance", dic: dic))" } else { cell.earnTextField.placeholder = "填写金额≤0.0" } cell.totalBlock = { } return cell } /* // 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. } */ }