MeTraineeSubjectPageViewController.swift 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // MeTraineeSubjectPageViewController.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 MeTraineeSubjectPageViewController: BaseTableViewController {
  11. let cellIdentifier:String = "_MeTraineeSubjectCell"
  12. // MARK: 服务属性
  13. private let cocahService: CoachServiceType = CoachService(networking: CoachNetworking())
  14. // MARK: UI属性
  15. // MARK: 数据
  16. var traineeDataModel:TraineeDataModel?
  17. var rows:[RowInfo] = []
  18. var page:Int = 1
  19. var pageSize:Int = 10
  20. var state = "1"
  21. var schoolId:Int = 0
  22. var type:TraineeType?
  23. init(type:TraineeType,state:String,schoolId:Int) {
  24. self.type = type
  25. super.init()
  26. self.state = state
  27. self.schoolId = schoolId
  28. }
  29. required convenience init?(coder aDecoder: NSCoder) {
  30. fatalError("init(coder:) has not been implemented")
  31. }
  32. override func viewDidLoad() {
  33. super.viewDidLoad()
  34. getCoachInfoList()
  35. //绑定
  36. biandView()
  37. }
  38. // MARK: 私有方法
  39. func getCoachInfoList()
  40. {
  41. page = 1
  42. if (self.type == .advancet){ //预报名
  43. self.cocahService.coachTempListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
  44. .subscribe(onSuccess: { traineeDataModel in
  45. self.rows.removeAll()
  46. self.traineeDataModel = traineeDataModel
  47. self.rows += traineeDataModel.rows!
  48. print("coachInfoListRequest成功")
  49. self.hideLoadAnimation()
  50. self.tableView.reloadData()
  51. self.stopRefresh()
  52. }, onError: { error in
  53. self.stopRefresh()
  54. })
  55. .disposed(by: disposeBag)
  56. return
  57. }else if(self.type == .biandstu){ //绑定学员
  58. self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "\(LocalManager.userInfo.id)", coachId: "", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
  59. .subscribe(onSuccess: { traineeDataModel in
  60. self.rows.removeAll()
  61. self.traineeDataModel = traineeDataModel
  62. self.rows += traineeDataModel.rows!
  63. print("coachInfoListRequest成功")
  64. self.hideLoadAnimation()
  65. self.tableView.reloadData()
  66. self.stopRefresh()
  67. }, onError: { error in
  68. self.stopRefresh()
  69. })
  70. .disposed(by: disposeBag)
  71. return
  72. }
  73. self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
  74. .subscribe(onSuccess: { traineeDataModel in
  75. self.rows.removeAll()
  76. self.traineeDataModel = traineeDataModel
  77. self.rows += traineeDataModel.rows!
  78. print("coachInfoListRequest成功")
  79. self.hideLoadAnimation()
  80. self.tableView.reloadData()
  81. self.stopRefresh()
  82. NotificationCenter.default.post(name: Notification.updateItemTopTotalNameNotification, object: [traineeDataModel.total,Int(self.state)!-1])
  83. }, onError: { error in
  84. self.stopRefresh()
  85. })
  86. .disposed(by: disposeBag)
  87. }
  88. //更多
  89. func getLoadMore(){
  90. //计算-页数
  91. if (traineeDataModel != nil){
  92. let total = pageSize*self.page
  93. if(total<(traineeDataModel?.total)!){
  94. self.page+=1
  95. }else{
  96. self.stopLoad()
  97. return //已经显示完
  98. }
  99. }
  100. if (self.type == .advancet){ //预报名
  101. self.cocahService.coachTempListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
  102. .subscribe(onSuccess: { traineeDataModel in
  103. self.traineeDataModel = traineeDataModel
  104. if(traineeDataModel.rows!.count>0){
  105. self.rows += traineeDataModel.rows!
  106. }
  107. print("coachInfoListRequest成功")
  108. self.tableView.reloadData()
  109. self.stopLoad()
  110. }, onError: { error in
  111. self.stopLoad()
  112. })
  113. .disposed(by: disposeBag)
  114. return
  115. }else if(self.type == .biandstu){ //绑定学员
  116. self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "\(LocalManager.userInfo.id)", coachId: "", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
  117. .subscribe(onSuccess: { traineeDataModel in
  118. self.traineeDataModel = traineeDataModel
  119. if(traineeDataModel.rows!.count>0){
  120. self.rows += traineeDataModel.rows!
  121. }
  122. print("coachInfoListRequest成功")
  123. self.tableView.reloadData()
  124. self.stopLoad()
  125. }, onError: { error in
  126. self.stopLoad()
  127. })
  128. .disposed(by: disposeBag)
  129. return
  130. }
  131. //请求网络-加载
  132. self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
  133. .subscribe(onSuccess: { traineeDataModel in
  134. self.traineeDataModel = traineeDataModel
  135. if(traineeDataModel.rows!.count>0){
  136. self.rows += traineeDataModel.rows!
  137. }
  138. print("coachInfoListRequest成功")
  139. self.tableView.reloadData()
  140. self.stopLoad()
  141. }, onError: { error in
  142. self.stopLoad()
  143. })
  144. .disposed(by: disposeBag)
  145. }
  146. func biandView(){
  147. tableView.delegate = self
  148. tableView.dataSource = self
  149. tableView.separatorStyle = .none //去除分割线
  150. tableView.register(UINib(nibName: "MeTraineeSubjectCell", bundle: nil), forCellReuseIdentifier: cellIdentifier)
  151. tableView.rowHeight = 288.f
  152. setupRefreshHeader(tableView) {[unowned self] in
  153. self.getCoachInfoList()
  154. }
  155. self.isEmptyDisplay = false
  156. // 设置上拉加载更多
  157. tableView.es.addInfiniteScrolling { [weak self] in
  158. self?.getLoadMore()
  159. }
  160. }
  161. }
  162. //数据源
  163. extension MeTraineeSubjectPageViewController:UITableViewDataSource {
  164. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  165. return self.rows.count ?? 0
  166. }
  167. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  168. let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MeTraineeSubjectCell
  169. cell.index_button.setTitle("\(indexPath.row+1)", for: .normal)
  170. cell.setRowInfo(rowInfo: (self.rows[indexPath.row]))
  171. return cell
  172. }
  173. }
  174. //事件
  175. extension MeTraineeSubjectPageViewController:UITableViewDelegate {
  176. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  177. tableView.deselectRow(at: indexPath, animated: false)
  178. let rowInfo = self.rows[indexPath.row]
  179. if rowInfo != nil {
  180. let context: Int = rowInfo.id ?? 0
  181. NYSwRouter.push(NYSwPushType.trainee_info,context: context)
  182. }
  183. }
  184. }