MeTraineeSearchPageViewController.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // MeTraineeSearchPageViewController.swift
  3. // JiaPeiManage
  4. //
  5. // Created by Ning.ge on 2023/6/15.
  6. //
  7. import UIKit
  8. import RxSwift
  9. import RxCocoa
  10. final class MeTraineeSearchPageViewController: BaseTableViewController {
  11. let cellIdentifier:String = "_MeTraineeSubjectCellSearch"
  12. // MARK: UI属性
  13. @IBOutlet weak var searchView: UIView!
  14. //搜索
  15. @IBOutlet weak var search_textfield: QMUITextField!
  16. //搜按钮
  17. @IBOutlet weak var search_button: UIButton!
  18. let meTraineeSearchViewModel = MeTraineeSearchViewModel()
  19. let headerView = MeTraineeSubjectHeaderView.loadFromNib()
  20. //重置约束
  21. override func setupConstraints() {
  22. self.tableView.snp.remakeConstraints { make in
  23. make.top.equalTo(self.searchView.snp.bottom)
  24. make.left.right.bottom.equalTo(self.view)
  25. }
  26. self.loadViewIfNeeded()
  27. }
  28. override func viewDidLoad() {
  29. super.viewDidLoad()
  30. setupUI()
  31. biandView()
  32. }
  33. // MARK: 私有方法
  34. func setupUI(){
  35. if isIphoneX {self.nav_topH_layout.constant = 64.f+24.f}
  36. self.view.backgroundColor = .db_theme
  37. // self.searchView.addSubview(search_bar)
  38. self.search_textfield.placeholderColor = .db_place
  39. tableView.dataSource = self
  40. tableView.delegate = self
  41. tableView.separatorStyle = .none //去除分割线
  42. tableView.register(UINib(nibName: "MeTraineeSubjectCell", bundle: nil), forCellReuseIdentifier: cellIdentifier)
  43. tableView.rowHeight = 288.f
  44. setupRefreshHeader(tableView) {[unowned self] in
  45. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
  46. // 在延迟 1 秒后执行的代码
  47. self.stopRefresh()
  48. }
  49. NSLog("AAAAAAA")
  50. }
  51. self.isEmptyDisplay = false
  52. }
  53. //绑定-rx
  54. func biandView(){
  55. search_textfield.rx.text.orEmpty
  56. // .filter { !$0.isEmpty } // Filter out empty strings
  57. .subscribe(onNext: { [unowned self] searchText in
  58. // Handle the updated search text here
  59. print("Search text changed: \(searchText)")
  60. // self.searchCoachInfoList()
  61. self.meTraineeSearchViewModel.searchCoachInfoList(searchPageVC: self)
  62. })
  63. .disposed(by: disposeBag)
  64. //RX 绑定
  65. // self.meTraineeSearchViewModel.items
  66. // .bind(to: tableView.rx.items(cellIdentifier: cellIdentifier,cellType:MeTraineeSubjectCell.self)) { (row, model, cell) in
  67. // cell.index_button.setTitle("\(row+1)", for: .normal)
  68. // cell.setRowInfo(rowInfo:model as! RowInfo)
  69. // }
  70. // .disposed(by: disposeBag)
  71. // tableView点击事件
  72. tableView.rx.itemSelected.subscribe(onNext: { [weak self]indexPath in
  73. print("点击\(indexPath)行")
  74. let rowInfo:RowInfo = (self!.meTraineeSearchViewModel.traineeDataModel?.rows![indexPath.row])!
  75. if rowInfo != nil {
  76. let context: Int = rowInfo.id!
  77. NYSwRouter.push(NYSwPushType.trainee_info,context: context)
  78. }
  79. self?.tableView.deselectRow(at: indexPath, animated: false)
  80. }).disposed(by: disposeBag)
  81. }
  82. }
  83. //数据源
  84. extension MeTraineeSearchPageViewController:UITableViewDataSource {
  85. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  86. if self.meTraineeSearchViewModel.traineeDataModel != nil {
  87. let total = String(format: "%d", self.meTraineeSearchViewModel.traineeDataModel?.total ?? 0)
  88. headerView.total_label.text = "总数:"+total
  89. }
  90. return headerView
  91. }
  92. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  93. return 55.f
  94. }
  95. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  96. return self.meTraineeSearchViewModel.traineeDataModel?.rows!.count ?? 0
  97. }
  98. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  99. let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MeTraineeSubjectCell
  100. cell.index_button.setTitle("\(indexPath.row+1)", for: .normal)
  101. cell.setRowInfo(rowInfo: (self.meTraineeSearchViewModel.traineeDataModel?.rows?[indexPath.row])!)
  102. return cell
  103. }
  104. }
  105. //事件
  106. extension MeTraineeSearchPageViewController:UITableViewDelegate {
  107. }