MeTraineeSubjectPageViewController.swift 8.3 KB

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