// // DelegateListForActiveViewController.swift // xingchuangke // // Created by 李晓飞 on 2020/9/4. // Copyright © 2020 Virgil. All rights reserved. // import UIKit typealias SelectDelegateBlock = (NSDictionary) -> Void class DelegateListForActiveViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var imgBgView: UIImageView! @IBOutlet weak var searchView: UIView! @IBOutlet weak var searchTextField: UITextField! @IBOutlet weak var searchBtn: UIButton! @IBOutlet weak var tableView: UITableView! var selectBlock: SelectDelegateBlock? override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) appDelegate.setNavigationBarHidden(isHidden: true) } override func viewDidLoad() { super.viewDidLoad() navInit() tableViewInit() loadData() } // 自定义导航栏 func navInit() { let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView) viewNav.initView(title: "选择代理") {[weak self] (index, _) in if index == 0 { self!.handleBack() } } self.view.addSubview(viewNav) viewNav.marginTop(top: 0) searchView.marginTop(top: viewNav.bottom()) imgBgView.translatesAutoresizingMaskIntoConstraints = false let h: NSLayoutConstraint = NSLayoutConstraint(item: imgBgView as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0.0, constant: searchView.bottom()) imgBgView.addConstraint(h) } func tableViewInit() { tableView.delegate = self tableView.dataSource = self tableView.tableFooterView = UIView.init() tableView.register(UINib(nibName: "DelegateListCell", bundle: nil), forCellReuseIdentifier: "DelegateListCell") 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() }) } // MARK: - request func loadData() { let url = RequestURL.myAgentList let params = NSMutableDictionary() params.setValue(CommonValue.getUserId(), forKey: "userId") params.setValue(searchTextField.text!, forKey: "likeStr") loadDataList(url: url, params: params, tableView: tableView, tag: 1001) } override func returnData(tag: Int) { tableView.reloadData() } override func returnError(tag: Int, type: String) { } // MARK: - action @IBAction func searchBtnClicked(_ sender: Any) { self.view.endEditing(true) self.currentPage = 1 loadData() } // 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: DelegateListCell = tableView.dequeueReusableCell(withIdentifier: "DelegateListCell", for: indexPath) as! DelegateListCell cell.selectionStyle = .none if getString(current: indexPath.row, key: "realName") == "" { cell.titleLabel.text = "未实名" } else { cell.titleLabel.text = "\(getString(current: indexPath.row, key: "realName")) " } let phone = "\(getString(current: indexPath.row, key: "phone"))" if phone.length() > 7 { cell.phoneLabel.text = "\(phone.substringTo(index: 3))****\(phone.substringFrom(index: 7))" } else { cell.phoneLabel.text = "\(phone.substringTo(index: 3))****" } cell.codeLabel.text = "(推荐码:\(getString(current: indexPath.row, key: "recCode")))" return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if selectBlock != nil { selectBlock!(arrData[indexPath.row] as! NSDictionary) self.navigationController?.popViewController(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. } */ }