MeTraineeSubjectPageViewController.swift 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. NotificationCenter.default.post(name: Notification.updateItemTopTotalNameNotification, object: [traineeDataModel.total,Int(self.state)!-1])
  68. }, onError: { error in
  69. self.stopRefresh()
  70. })
  71. .disposed(by: disposeBag)
  72. return
  73. }
  74. self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
  75. .subscribe(onSuccess: { traineeDataModel in
  76. self.rows.removeAll()
  77. self.traineeDataModel = traineeDataModel
  78. self.rows += traineeDataModel.rows!
  79. print("coachInfoListRequest成功")
  80. self.hideLoadAnimation()
  81. self.tableView.reloadData()
  82. self.stopRefresh()
  83. NotificationCenter.default.post(name: Notification.updateItemTopTotalNameNotification, object: [traineeDataModel.total,Int(self.state)!-1])
  84. }, onError: { error in
  85. self.stopRefresh()
  86. })
  87. .disposed(by: disposeBag)
  88. }
  89. //更多
  90. func getLoadMore(){
  91. //计算-页数
  92. if (traineeDataModel != nil){
  93. let total = pageSize*self.page
  94. if(total<(traineeDataModel?.total)!){
  95. self.page+=1
  96. }else{
  97. self.stopLoad()
  98. return //已经显示完
  99. }
  100. }
  101. if (self.type == .advancet){ //预报名
  102. self.cocahService.coachTempListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
  103. .subscribe(onSuccess: { traineeDataModel in
  104. self.traineeDataModel = traineeDataModel
  105. if(traineeDataModel.rows!.count>0){
  106. self.rows += traineeDataModel.rows!
  107. }
  108. print("coachInfoListRequest成功")
  109. self.tableView.reloadData()
  110. self.stopLoad()
  111. }, onError: { error in
  112. self.stopLoad()
  113. })
  114. .disposed(by: disposeBag)
  115. return
  116. }else if(self.type == .biandstu){ //绑定学员
  117. self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "\(LocalManager.userInfo.id)", coachId: "", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
  118. .subscribe(onSuccess: { traineeDataModel in
  119. self.traineeDataModel = traineeDataModel
  120. if(traineeDataModel.rows!.count>0){
  121. self.rows += traineeDataModel.rows!
  122. }
  123. print("coachInfoListRequest成功")
  124. self.tableView.reloadData()
  125. self.stopLoad()
  126. }, onError: { error in
  127. self.stopLoad()
  128. })
  129. .disposed(by: disposeBag)
  130. return
  131. }
  132. //请求网络-加载
  133. self.cocahService.coachInfoListRequest(city: LocalManager.userInfo.city!, appCoachId: "", coachId: "\(LocalManager.userInfo.id)", field: "", pageNum: page, pageSize: pageSize, schoolId: schoolId, state: state)
  134. .subscribe(onSuccess: { traineeDataModel in
  135. self.traineeDataModel = traineeDataModel
  136. if(traineeDataModel.rows!.count>0){
  137. self.rows += traineeDataModel.rows!
  138. }
  139. print("coachInfoListRequest成功")
  140. self.tableView.reloadData()
  141. self.stopLoad()
  142. }, onError: { error in
  143. self.stopLoad()
  144. })
  145. .disposed(by: disposeBag)
  146. }
  147. func biandView(){
  148. tableView.delegate = self
  149. tableView.dataSource = self
  150. tableView.separatorStyle = .none //去除分割线
  151. tableView.register(UINib(nibName: "MeTraineeSubjectCell", bundle: nil), forCellReuseIdentifier: cellIdentifier)
  152. tableView.rowHeight = 288.f
  153. setupRefreshHeader(tableView) {[unowned self] in
  154. self.getCoachInfoList()
  155. }
  156. self.isEmptyDisplay = false
  157. // 设置上拉加载更多
  158. tableView.es.addInfiniteScrolling { [weak self] in
  159. self?.getLoadMore()
  160. }
  161. }
  162. }
  163. //数据源
  164. extension MeTraineeSubjectPageViewController:UITableViewDataSource {
  165. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  166. return self.rows.count ?? 0
  167. }
  168. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  169. let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MeTraineeSubjectCell
  170. cell.index_button.setTitle("\(indexPath.row+1)", for: .normal)
  171. cell.setRowInfo(rowInfo: (self.rows[indexPath.row]))
  172. return cell
  173. }
  174. }
  175. //事件
  176. extension MeTraineeSubjectPageViewController:UITableViewDelegate {
  177. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  178. tableView.deselectRow(at: indexPath, animated: false)
  179. let rowInfo = self.rows[indexPath.row]
  180. if rowInfo != nil {
  181. let context: Int = rowInfo.id ?? 0
  182. NYSwRouter.push(NYSwPushType.trainee_info,context: context)
  183. }
  184. }
  185. }