MeTraineeSearchPageViewController.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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: 服务属性
  13. private let cocahService: CoachServiceType = CoachService(networking: CoachNetworking())
  14. // MARK: UI属性
  15. @IBOutlet weak var searchView: UIView!
  16. //搜索
  17. @IBOutlet weak var search_textfield: QMUITextField!
  18. //搜按钮
  19. @IBOutlet weak var search_button: UIButton!
  20. //search bar
  21. // let search_bar = QMUISearchBar().then {
  22. // $0.backgroundColor = UIColor("#26486B")
  23. // $0.layer.cornerRadius = 15.f
  24. // $0.layer.masksToBounds = true
  25. // }
  26. let headerView = MeTraineeSubjectHeaderView.loadFromNib()
  27. // MARK: 数据
  28. var traineeDataModel:TraineeDataModel?
  29. var page:Int = 1
  30. var pageSize:Int = 100
  31. var state = ""
  32. //重置约束
  33. override func setupConstraints() {
  34. self.tableView.snp.makeConstraints { make in
  35. make.top.equalTo(self.searchView.bottom)
  36. make.left.right.bottom.equalTo(self.view)
  37. }
  38. }
  39. override func viewDidLoad() {
  40. super.viewDidLoad()
  41. setupUI()
  42. biandView()
  43. }
  44. // MARK: 私有方法
  45. func setupUI(){
  46. self.view.backgroundColor = .db_theme
  47. // self.searchView.addSubview(search_bar)
  48. self.search_textfield.placeholderColor = .db_place
  49. tableView.delegate = self
  50. tableView.dataSource = self
  51. tableView.separatorStyle = .none //去除分割线
  52. tableView.register(UINib(nibName: "MeTraineeSubjectCell", bundle: nil), forCellReuseIdentifier: cellIdentifier)
  53. tableView.rowHeight = 288.f
  54. setupRefreshHeader(tableView) {[unowned self] in
  55. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
  56. // 在延迟 1 秒后执行的代码
  57. self.stopRefresh()
  58. }
  59. NSLog("AAAAAAA")
  60. }
  61. self.isEmptyDisplay = false
  62. //获取第一响应者
  63. }
  64. //绑定-rx
  65. func biandView(){
  66. search_textfield.rx.text.orEmpty
  67. // .filter { !$0.isEmpty } // Filter out empty strings
  68. .subscribe(onNext: { [unowned self] searchText in
  69. // Handle the updated search text here
  70. print("Search text changed: \(searchText)")
  71. self.searchCoachInfoList()
  72. })
  73. .disposed(by: disposeBag)
  74. //Driver
  75. // let result = search_textfield.rx.text.skip(1)
  76. // .flatMap{
  77. // return self.dealWithData(intputText: $0!).observeOn(MainScheduler()).catchErrorJustReturn("监听到错误事件")
  78. // }.share(replay: 1,scope: .whileConnected)
  79. }
  80. // func dealWithData(intputText:String)-> Observable<Any> {
  81. // return Observable<Any>.create({ ob -> Disposable in
  82. // self.searchCoachInfoList()
  83. // return Disposables.create()
  84. // })
  85. // }
  86. func searchCoachInfoList()
  87. {
  88. print("网络请求")
  89. self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: search_textfield.text!, pageNum: page, pageSize: pageSize, schoolId: 0, state: state)
  90. .subscribe(onSuccess: { traineeDataModel in
  91. self.traineeDataModel = traineeDataModel
  92. print("coachInfoListRequest成功")
  93. self.hideLoadAnimation()
  94. self.tableView.reloadData()
  95. }, onError: { error in
  96. })
  97. .disposed(by: disposeBag)
  98. }
  99. }
  100. //数据源
  101. extension MeTraineeSearchPageViewController:UITableViewDataSource {
  102. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  103. if traineeDataModel != nil {
  104. let total = String(format: "%d", traineeDataModel?.total ?? 0)
  105. headerView.total_label.text = "总数:"+total
  106. }
  107. return headerView
  108. }
  109. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  110. return 55.f
  111. }
  112. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  113. return traineeDataModel?.rows!.count ?? 0
  114. }
  115. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  116. let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MeTraineeSubjectCell
  117. cell.index_button.setTitle("\(indexPath.row+1)", for: .normal)
  118. cell.setRowInfo(rowInfo: (self.traineeDataModel?.rows?[indexPath.row])!)
  119. return cell
  120. }
  121. }
  122. //事件
  123. extension MeTraineeSearchPageViewController:UITableViewDelegate {
  124. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  125. tableView.deselectRow(at: indexPath, animated: false)
  126. let rowInfo:RowInfo = (self.traineeDataModel?.rows![indexPath.row])!
  127. if rowInfo != nil {
  128. let context: Int = rowInfo.id!
  129. NYSwRouter.push(NYSwPushType.trainee_info,context: context)
  130. }
  131. }
  132. }
  133. extension MeTraineeSearchPageViewController:UIScrollViewDelegate {
  134. func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
  135. self.view.endEditing(true)
  136. }
  137. }