|
@@ -8,20 +8,156 @@ import UIKit
|
|
|
import RxSwift
|
|
|
import RxCocoa
|
|
|
|
|
|
-final class MeTraineeSearchPageViewController: BaseViewController {
|
|
|
+final class MeTraineeSearchPageViewController: BaseTableViewController {
|
|
|
|
|
|
+ let cellIdentifier:String = "_MeTraineeSubjectCellSearch"
|
|
|
+ // MARK: 服务属性
|
|
|
+ private let cocahService: CoachServiceType = CoachService(networking: CoachNetworking())
|
|
|
// MARK: UI属性
|
|
|
|
|
|
+ @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 = 10
|
|
|
+ var state = ""
|
|
|
+ //重置约束
|
|
|
+ override func setupConstraints() {
|
|
|
+ self.tableView.snp.makeConstraints { 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(){
|
|
|
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)
|
|
|
+
|
|
|
+ //Driver
|
|
|
+// let result = search_textfield.rx.text.skip(1)
|
|
|
+// .flatMap{
|
|
|
+// return self.dealWithData(intputText: $0!).observeOn(MainScheduler()).catchErrorJustReturn("监听到错误事件")
|
|
|
+// }.share(replay: 1,scope: .whileConnected)
|
|
|
}
|
|
|
|
|
|
+// func dealWithData(intputText:String)-> Observable<Any> {
|
|
|
+// return Observable<Any>.create({ ob -> Disposable in
|
|
|
+// self.searchCoachInfoList()
|
|
|
+// return Disposables.create()
|
|
|
+// })
|
|
|
+// }
|
|
|
+
|
|
|
+ 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: true)
|
|
|
+ let rowInfo = self.traineeDataModel?.rows![indexPath.row]
|
|
|
+ if rowInfo != nil {
|
|
|
+ NYSwRouter.push(NYSwPushType.trainee_info.path)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+extension MeTraineeSearchPageViewController:UIScrollViewDelegate {
|
|
|
+
|
|
|
+ func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
|
|
+ self.view.endEditing(true)
|
|
|
+ }
|
|
|
}
|