EstuLogPhotoListViewController.swift 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. //
  2. // EstuLogPhotoListViewController.swift
  3. // JiaPeiManage
  4. //
  5. // Created by Ning.ge on 2023/8/30.
  6. //
  7. import UIKit
  8. import RxSwift
  9. import RxCocoa
  10. import ReusableKit
  11. import Dollar
  12. import JXPhotoBrowser
  13. import Kingfisher
  14. final class EstuLogPhotoListViewController: BaseCollectionViewController {
  15. let cellIdentifier:String = "_EstuLogListCell"
  16. // MARK: 服务属性
  17. private let elogCoachService: ElogCoachServiceType = ElogCoachService(networking: ElogCoachNetworking())
  18. private struct Reusable {
  19. static let ephotoCell = ReusableCell<EstuLogPhotoCell>()
  20. static let headerView = ReusableView<EstuLogPhotoHeaderView>()
  21. }
  22. // MARK: UI let
  23. let statusBar = UIView().then {
  24. $0.backgroundColor = UIColor.db_theme
  25. }
  26. let navBar = MeTraineeNavBar.loadFromNib().then {
  27. $0.search_button.isHidden = true
  28. }
  29. let estuLogHeaderView = EstuLogHeaderView.loadFromNib()
  30. //学员ID
  31. var stuId:Int = 0
  32. var classId:String = ""
  33. var eteachLogPhotoDataModel:ETeachLogPhotoDataModel?
  34. var rows : [ETeachLogPhotoInfo] = []
  35. private var datasources: [EstuLogPhotoCellReactor] = []
  36. var page:Int = 1
  37. var pageSize:Int = 10
  38. override func setupConstraints() {
  39. statusBar.snp.makeConstraints { (make) in
  40. make.left.right.top.equalToSuperview()
  41. make.height.equalTo(Metric.statusBarHeight)
  42. }
  43. navBar.snp.remakeConstraints { (make) in
  44. make.left.right.equalToSuperview()
  45. make.height.equalTo(Metric.navBarHeight)
  46. make.top.equalTo(statusBar.snp.bottom)
  47. }
  48. collectionView.snp.remakeConstraints { make in
  49. make.top.equalTo(self.navBar.snp.bottom)
  50. make.left.right.bottom.equalTo(self.view)
  51. }
  52. self.loadViewIfNeeded()
  53. }
  54. // MARK: StatusBar
  55. override func viewWillAppear(_ animated: Bool) {
  56. super.viewWillAppear(animated)
  57. self.navigationController?.setNavigationBarHidden(true, animated: true)
  58. }
  59. required convenience init?(coder aDecoder: NSCoder) {
  60. fatalError("init(coder:) has not been implemented")
  61. }
  62. override func viewDidLoad() {
  63. super.viewDidLoad()
  64. configureMagicController()
  65. setupUI()
  66. biandView()
  67. }
  68. // MARK: 私有方法
  69. func setupUI(){
  70. self.navBar.title_label.text = "电子教学日志"
  71. self.navBar.back_button.addTarget(self, action: #selector(actionBackdo), for: .touchUpInside)
  72. }
  73. func configureMagicController(){
  74. self.view.addSubview(navBar)
  75. self.view.addSubview(statusBar)
  76. }
  77. func biandView(){
  78. collectionView.backgroundColor = UIColor.db_theme
  79. // collectionView.frame = self.view.bounds
  80. collectionView.register(Reusable.ephotoCell)
  81. collectionView.register(Reusable.headerView, kind: UICollectionView.elementKindSectionHeader)
  82. collectionView.delegate = self
  83. collectionView.dataSource = self
  84. self.isEmptyDisplay = false
  85. self.hideLoadAnimation()
  86. setupRefreshHeader(collectionView,.rabbit) {[unowned self] in
  87. self.getStudentTeachLogPhotoList(isLoading: false)
  88. }
  89. // 设置上拉加载更多
  90. collectionView.es.addInfiniteScrolling { [weak self] in
  91. self?.getLoadMore()
  92. }
  93. getStudentTeachLogPhotoList(isLoading: true)
  94. // collectionView点击事件
  95. collectionView.rx.itemSelected.throttle(.seconds(1), scheduler: MainScheduler.instance)
  96. .subscribe(onNext: { [weak self]indexPath in
  97. print("点击\(indexPath)行")
  98. self?.openPhotoBrowser(with: self!.collectionView, indexPath: indexPath)
  99. }).disposed(by: disposeBag)
  100. }
  101. func getStudentTeachLogPhotoList(isLoading:Bool){
  102. page = 1
  103. if isLoading {NYTips.show()}
  104. self.elogCoachService.elogTmsStudentPhotoByIdRequest(city: LocalManager.userInfo.city!, classId: classId, id: stuId, pageNum: page, pageSize: pageSize).subscribe(onSuccess: {[unowned self] eteachLogPhotoDataModel in
  105. self.rows.removeAll()
  106. self.eteachLogPhotoDataModel = eteachLogPhotoDataModel
  107. self.rows += eteachLogPhotoDataModel.rows!
  108. print("elogTmsStudentPhotoByIdRequest成功")
  109. self.isEmptyDisplay = true
  110. self.hideLoadAnimation()
  111. self.stopRefresh()
  112. self.collectionView.reloadData()
  113. NYTips.hide()
  114. }, onError: { error in
  115. self.stopRefresh()
  116. NYTips.hide()
  117. })
  118. .disposed(by: disposeBag)
  119. }
  120. //更多
  121. func getLoadMore(){
  122. //计算-页数
  123. if (eteachLogPhotoDataModel != nil){
  124. let total = pageSize*self.page
  125. if(total<(eteachLogPhotoDataModel?.total)!){
  126. self.page+=1
  127. }else{
  128. self.stopLoad()
  129. return //已经显示完
  130. }
  131. }
  132. //请求网络-加载
  133. self.elogCoachService.elogTmsStudentPhotoByIdRequest(city: LocalManager.userInfo.city!, classId: classId, id: stuId, pageNum: page, pageSize: pageSize).subscribe(onSuccess: {[unowned self] eteachLogPhotoDataModel in
  134. self.eteachLogPhotoDataModel = eteachLogPhotoDataModel
  135. self.rows += eteachLogPhotoDataModel.rows!
  136. print("resultInfoModel成功")
  137. self.collectionView.reloadData()
  138. self.stopLoad()
  139. }, onError: { error in
  140. self.stopLoad()
  141. })
  142. .disposed(by: disposeBag)
  143. }
  144. func openPhotoBrowser(with collectionView: UICollectionView, indexPath: IndexPath) {
  145. let browser = JXPhotoBrowser()
  146. browser.numberOfItems = {
  147. self.rows.count
  148. }
  149. browser.reloadCellAtIndex = { context in
  150. let url = self.rows[context.index].filepath.flatMap { URL(string: $0) }
  151. let browserCell = context.cell as? JXPhotoBrowserImageCell
  152. let collectionPath = IndexPath(item: context.index, section: indexPath.section)
  153. let collectionCell = collectionView.cellForItem(at: collectionPath) as? EstuLogPhotoCell
  154. let placeholder = collectionCell?.coverImageView.image
  155. // 用 Kingfisher 加载
  156. browserCell?.imageView.kf.setImage(with: url, placeholder: placeholder)
  157. }
  158. browser.transitionAnimator = JXPhotoBrowserZoomAnimator(previousView: { index -> UIView? in
  159. let path = IndexPath(item: index, section: indexPath.section)
  160. let cell = collectionView.cellForItem(at: path) as? EstuLogPhotoCell
  161. return cell?.coverImageView
  162. })
  163. browser.pageIndex = indexPath.item
  164. browser.show()
  165. }
  166. }
  167. extension EstuLogPhotoListViewController: UICollectionViewDataSource {
  168. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  169. return self.rows.count
  170. }
  171. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  172. let cell = collectionView.dequeue(Reusable.ephotoCell, for: indexPath)
  173. // cell.reactor = datasources[indexPath.item]
  174. cell.setRowInfo(rowInfo: self.rows[indexPath.row])
  175. return cell
  176. }
  177. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  178. collectionView.deselectItem(at: indexPath, animated: true)
  179. }
  180. // Provide header view for each section
  181. func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
  182. let headerView = collectionView.dequeue(Reusable.headerView, kind: kind, for: indexPath)
  183. // (ofKind: kind, withReuseIdentifier: Reusable.headerView, for: indexPath)
  184. return headerView
  185. }
  186. }
  187. extension EstuLogPhotoListViewController: UICollectionViewDelegateFlowLayout {
  188. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  189. // let cellReactor = datasources[indexPath.item]
  190. return CGSize(width: NYFitReal.screenWidth*0.5, height: 174) //Reusable.rcmdCell.class.cellSize(reactor: cellReactor)
  191. }
  192. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  193. return UIEdgeInsets.zero
  194. }
  195. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  196. return 0.f
  197. }
  198. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
  199. return 0.f
  200. }
  201. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
  202. return CGSize(width: NYFitReal.screenWidth, height: 99.f) //branchSectionDelegate.headerSize(collectionView: collectionView,section: dataSource[section])
  203. }
  204. }