123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- //
- // 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: 服务属性
- private let cocahService: CoachServiceType = CoachService(networking: CoachNetworking())
- // MARK: UI属性
- // @IBOutlet weak var nav_top_layout: NSLayoutConstraint!
- @IBOutlet weak var searchView: UIView!
- //搜索
- @IBOutlet weak var search_textfield: QMUITextField!
- //搜按钮
- @IBOutlet weak var search_button: UIButton!
-
-
- //search bar
- // let search_bar = QMUISearchBar().then {
- // $0.backgroundColor = UIColor("#26486B")
- // $0.layer.cornerRadius = 15.f
- // $0.layer.masksToBounds = true
- // }
-
- let headerView = MeTraineeSubjectHeaderView.loadFromNib()
- // MARK: 数据
- var traineeDataModel:TraineeDataModel?
- var page:Int = 1
- var pageSize:Int = 100
- var state = ""
- //重置约束
- override func setupConstraints() {
- self.tableView.snp.remakeConstraints { make in
- make.top.equalTo(self.searchView.bottom)
- make.left.right.bottom.equalTo(self.view)
- }
-
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- setupUI()
- biandView()
- }
-
-
- // MARK: 私有方法
- func setupUI(){
- if isIphoneX {self.nav_top_layout.constant = 24.f}
- self.view.backgroundColor = .db_theme
- // self.searchView.addSubview(search_bar)
- self.search_textfield.placeholderColor = .db_place
- tableView.delegate = self
- tableView.dataSource = 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()
- })
- .disposed(by: disposeBag)
-
- }
-
- func searchCoachInfoList()
- {
- print("网络请求")
- self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: search_textfield.text!, pageNum: page, pageSize: pageSize, schoolId: 0, state: state)
- .subscribe(onSuccess: { traineeDataModel in
- self.traineeDataModel = traineeDataModel
- print("coachInfoListRequest成功")
- self.hideLoadAnimation()
- self.tableView.reloadData()
- }, onError: { error in
- })
- .disposed(by: disposeBag)
- }
-
- }
- //数据源
- extension MeTraineeSearchPageViewController:UITableViewDataSource {
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- if traineeDataModel != nil {
- let total = String(format: "%d", 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 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.traineeDataModel?.rows?[indexPath.row])!)
- return cell
- }
- }
- //事件
- extension MeTraineeSearchPageViewController:UITableViewDelegate {
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- tableView.deselectRow(at: indexPath, animated: false)
- let rowInfo:RowInfo = (self.traineeDataModel?.rows![indexPath.row])!
- if rowInfo != nil {
- let context: Int = rowInfo.id!
- NYSwRouter.push(NYSwPushType.trainee_info,context: context)
- }
- }
-
- }
- extension MeTraineeSearchPageViewController:UIScrollViewDelegate {
-
- func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
- self.view.endEditing(true)
- }
- }
|