123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- //
- // MeTraineeSubjectPageViewController.swift
- // JiaPeiManage
- //
- // Created by Ning.ge on 2023/6/15.
- //
- import UIKit
- import RxSwift
- import RxCocoa
- final class MeTraineeSubjectPageViewController: BaseTableViewController {
-
- let cellIdentifier:String = "_MeTraineeSubjectCell"
- // MARK: 服务属性
- private let cocahService: CoachServiceType = CoachService(networking: CoachNetworking())
-
- // MARK: UI属性
-
-
- // MARK: 数据
- var traineeDataModel:TraineeDataModel?
- var rows:[RowInfo] = []
-
- var page:Int = 1
- var pageSize:Int = 10
- var state = "1"
- var schoolId:Int = 0
- var type:TraineeType?
-
- init(type:TraineeType,state:String,schoolId:Int) {
- self.type = type
- super.init()
- self.state = state
- self.schoolId = schoolId
- }
-
- required convenience init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- getCoachInfoList()
- //绑定
- biandView()
-
- }
-
- // MARK: 私有方法
-
- func getCoachInfoList()
- {
- page = 1
- if (self.type == .advancet){ //预报名
- self.cocahService.coachTempListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
- .subscribe(onSuccess: { traineeDataModel in
- self.rows.removeAll()
- self.traineeDataModel = traineeDataModel
- self.rows += traineeDataModel.rows!
- print("coachInfoListRequest成功")
- self.hideLoadAnimation()
- self.tableView.reloadData()
- self.stopRefresh()
- }, onError: { error in
- self.stopRefresh()
- })
- .disposed(by: disposeBag)
-
- return
- }else if(self.type == .biandstu){ //绑定学员
- self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "\(LocalManager.userInfo.id)", coachId: "", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
- .subscribe(onSuccess: { traineeDataModel in
- self.rows.removeAll()
- self.traineeDataModel = traineeDataModel
- self.rows += traineeDataModel.rows!
- print("coachInfoListRequest成功")
- self.hideLoadAnimation()
- self.tableView.reloadData()
- self.stopRefresh()
- NotificationCenter.default.post(name: Notification.updateItemTopTotalNameNotification, object: [traineeDataModel.total,Int(self.state)!-1])
- }, onError: { error in
- self.stopRefresh()
- })
- .disposed(by: disposeBag)
- return
- }
- self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
- .subscribe(onSuccess: { traineeDataModel in
- self.rows.removeAll()
- self.traineeDataModel = traineeDataModel
- self.rows += traineeDataModel.rows!
- print("coachInfoListRequest成功")
- self.hideLoadAnimation()
- self.tableView.reloadData()
- self.stopRefresh()
- NotificationCenter.default.post(name: Notification.updateItemTopTotalNameNotification, object: [traineeDataModel.total,Int(self.state)!-1])
- }, onError: { error in
- self.stopRefresh()
- })
- .disposed(by: disposeBag)
- }
-
- //更多
- func getLoadMore(){
- //计算-页数
- if (traineeDataModel != nil){
- let total = pageSize*self.page
- if(total<(traineeDataModel?.total)!){
- self.page+=1
- }else{
- self.stopLoad()
- return //已经显示完
- }
- }
- if (self.type == .advancet){ //预报名
- self.cocahService.coachTempListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
- .subscribe(onSuccess: { traineeDataModel in
- self.traineeDataModel = traineeDataModel
- if(traineeDataModel.rows!.count>0){
- self.rows += traineeDataModel.rows!
- }
- print("coachInfoListRequest成功")
- self.tableView.reloadData()
- self.stopLoad()
- }, onError: { error in
- self.stopLoad()
- })
- .disposed(by: disposeBag)
- return
- }else if(self.type == .biandstu){ //绑定学员
- self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "\(LocalManager.userInfo.id)", coachId: "", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
- .subscribe(onSuccess: { traineeDataModel in
- self.traineeDataModel = traineeDataModel
- if(traineeDataModel.rows!.count>0){
- self.rows += traineeDataModel.rows!
- }
- print("coachInfoListRequest成功")
- self.tableView.reloadData()
- self.stopLoad()
- }, onError: { error in
- self.stopLoad()
- })
- .disposed(by: disposeBag)
- return
- }
- //请求网络-加载
- self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
- .subscribe(onSuccess: { traineeDataModel in
- self.traineeDataModel = traineeDataModel
- if(traineeDataModel.rows!.count>0){
- self.rows += traineeDataModel.rows!
- }
- print("coachInfoListRequest成功")
- self.tableView.reloadData()
- self.stopLoad()
- }, onError: { error in
- self.stopLoad()
- })
- .disposed(by: disposeBag)
- }
-
- func biandView(){
- 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
- self.getCoachInfoList()
- }
- self.isEmptyDisplay = false
- // 设置上拉加载更多
- tableView.es.addInfiniteScrolling { [weak self] in
- self?.getLoadMore()
- }
- }
-
- }
- //数据源
- extension MeTraineeSubjectPageViewController:UITableViewDataSource {
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.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.rows[indexPath.row]))
- return cell
- }
- }
- //事件
- extension MeTraineeSubjectPageViewController:UITableViewDelegate {
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- tableView.deselectRow(at: indexPath, animated: false)
- let rowInfo = self.rows[indexPath.row]
- if rowInfo != nil {
- let context: Int = rowInfo.id ?? 0
- NYSwRouter.push(NYSwPushType.trainee_info,context: context)
- }
- }
-
- }
|