// // MeTraineeSearchPageViewController.swift // JiaPeiManage // // Created by Ning.ge on 2023/6/15. // import UIKit import RxSwift import RxCocoa final class MeTraineeSearchPageViewController: BaseTableViewController { let cellIdentifier:String = "_MeTraineeSubjectCellSearch" // MARK: UI属性 @IBOutlet weak var searchView: UIView! //搜索 @IBOutlet weak var search_textfield: QMUITextField! //搜按钮 @IBOutlet weak var search_button: UIButton! let meTraineeSearchViewModel = MeTraineeSearchViewModel() let headerView = MeTraineeSubjectHeaderView.loadFromNib() //重置约束 override func setupConstraints() { self.tableView.snp.remakeConstraints { make in make.top.equalTo(self.searchView.snp.bottom) make.left.right.bottom.equalTo(self.view) } self.loadViewIfNeeded() } override func viewDidLoad() { super.viewDidLoad() setupUI() biandView() } // MARK: 私有方法 func setupUI(){ if isIphoneX {self.nav_topH_layout.constant = 64.f+24.f} self.view.backgroundColor = .db_theme // self.searchView.addSubview(search_bar) self.search_textfield.placeholderColor = .db_place tableView.dataSource = self tableView.delegate = self tableView.separatorStyle = .none //去除分割线 tableView.register(UINib(nibName: "MeTraineeSubjectCell", bundle: nil), forCellReuseIdentifier: cellIdentifier) tableView.rowHeight = 288.f setupRefreshHeader(tableView) {[unowned self] in DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { // 在延迟 1 秒后执行的代码 self.stopRefresh() } NSLog("AAAAAAA") } self.isEmptyDisplay = false } //绑定-rx func biandView(){ search_textfield.rx.text.orEmpty // .filter { !$0.isEmpty } // Filter out empty strings .subscribe(onNext: { [unowned self] searchText in // Handle the updated search text here print("Search text changed: \(searchText)") // self.searchCoachInfoList() self.meTraineeSearchViewModel.searchCoachInfoList(searchPageVC: self) }) .disposed(by: disposeBag) //RX 绑定 // self.meTraineeSearchViewModel.items // .bind(to: tableView.rx.items(cellIdentifier: cellIdentifier,cellType:MeTraineeSubjectCell.self)) { (row, model, cell) in // cell.index_button.setTitle("\(row+1)", for: .normal) // cell.setRowInfo(rowInfo:model as! RowInfo) // } // .disposed(by: disposeBag) // tableView点击事件 tableView.rx.itemSelected.subscribe(onNext: { [weak self]indexPath in print("点击\(indexPath)行") let rowInfo:RowInfo = (self!.meTraineeSearchViewModel.traineeDataModel?.rows![indexPath.row])! if rowInfo != nil { let context: Int = rowInfo.id! NYSwRouter.push(NYSwPushType.trainee_info,context: context) } self?.tableView.deselectRow(at: indexPath, animated: false) }).disposed(by: disposeBag) } } //数据源 extension MeTraineeSearchPageViewController:UITableViewDataSource { func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { if self.meTraineeSearchViewModel.traineeDataModel != nil { let total = String(format: "%d", self.meTraineeSearchViewModel.traineeDataModel?.total ?? 0) headerView.total_label.text = "总数:"+total } return headerView } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 55.f } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.meTraineeSearchViewModel.traineeDataModel?.rows!.count ?? 0 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MeTraineeSubjectCell cell.index_button.setTitle("\(indexPath.row+1)", for: .normal) cell.setRowInfo(rowInfo: (self.meTraineeSearchViewModel.traineeDataModel?.rows?[indexPath.row])!) return cell } } //事件 extension MeTraineeSearchPageViewController:UITableViewDelegate { }