MVMineProductController.swift 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // MVMineProductController.swift
  3. // MusicVideoPlus
  4. //
  5. // Created by SanW on 2021/6/22.
  6. //
  7. import BFFramework
  8. import UIKit
  9. class MVMineProductController: PQBaseViewController {
  10. var itemsList: [PQVideoListModel] = Array<PQVideoListModel>.init()
  11. var pageNum: Int = 1
  12. let margin: CGFloat = 14
  13. let headH: CGFloat = cDefaultMargin * 9
  14. lazy var headInfoView: MVMineHeadInfoView = {
  15. let headInfoView = MVMineHeadInfoView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: headH), margin: 0)
  16. return headInfoView
  17. }()
  18. lazy var flowLayout: PQCollectionViewFlowlayout = {
  19. let flowLayout = PQCollectionViewFlowlayout()
  20. flowLayout.columnCount = 2
  21. flowLayout.sectionInset = .zero
  22. flowLayout.minimumLineSpacing = cDefaultMargin / 2
  23. flowLayout.minimumInteritemSpacing = cDefaultMargin / 2
  24. flowLayout.headerH = headH
  25. return flowLayout
  26. }()
  27. lazy var collectionView: UICollectionView = {
  28. let width = (cScreenWidth - 30) / 2
  29. let proCollectView = UICollectionView(frame: CGRect(x: margin, y: cDevice_iPhoneNavBarAndStatusBarHei, width: cScreenWidth - margin * 2, height: view.frame.height - cDevice_iPhoneNavBarAndStatusBarHei - cSafeAreaHeight), collectionViewLayout: flowLayout)
  30. proCollectView.register(MVMineProductCell.self, forCellWithReuseIdentifier: String(describing: MVMineProductCell.self))
  31. proCollectView.showsVerticalScrollIndicator = false
  32. proCollectView.delegate = self
  33. proCollectView.dataSource = self
  34. proCollectView.backgroundColor = UIColor.white
  35. proCollectView.addRefreshView { [weak self] isRefresh in
  36. self?.loadRequestData(isRefresh: isRefresh)
  37. }
  38. return proCollectView
  39. }()
  40. lazy var emptyView: MVProductEmptyView = {
  41. let emptyView = MVProductEmptyView.init(frame: CGRect.init(x: 0, y: headH, width: collectionView.frame.width, height: collectionView.frame.height - headH))
  42. emptyView.btnClickHandle = {[weak self] sender in
  43. let vc = PQStuckPointMaterialController()
  44. self?.navigationController?.pushViewController(vc, animated: true)
  45. }
  46. emptyView.isHidden = true
  47. return emptyView
  48. }()
  49. override func viewDidLoad() {
  50. super.viewDidLoad()
  51. view.addSubview(collectionView)
  52. collectionView.addSubview(emptyView)
  53. collectionView.addSubview(headInfoView)
  54. leftBackButton()
  55. loadRequestData()
  56. setTitle(title: BFLoginUserInfo.shared.nickName, color: UIColor(white: 0, alpha: 0))
  57. MVMineViewModel.userInfoData { [weak self] count, _ in
  58. if count != nil {
  59. BFLoginUserInfo.shared.videos = "\(count ?? 0)"
  60. self?.headInfoView.updateProducts()
  61. }
  62. }
  63. }
  64. /// 请求网络数据
  65. /// - Parameter isRefresh: <#isRefresh description#>
  66. /// - Returns: <#description#>
  67. func loadRequestData(isRefresh: Bool = true) {
  68. if isRefresh {
  69. pageNum = 1
  70. } else {
  71. pageNum = pageNum + 1
  72. }
  73. MVMineViewModel.userVideoListData(pageNum: pageNum) { [weak self] videoList, _ in
  74. if videoList != nil {
  75. if (videoList?.count ?? 0) > 0 {
  76. if isRefresh {
  77. self?.itemsList = videoList!
  78. } else {
  79. self?.itemsList = self!.itemsList + videoList!
  80. }
  81. self?.flowLayout.findList = self?.itemsList as! [PQVideoListModel]
  82. self?.collectionView.reloadData()
  83. self?.emptyView.isHidden = true
  84. } else {
  85. self?.emptyView.isHidden = false
  86. }
  87. } else {
  88. cShowHUB(superView: nil, msg: "没有网络连接")
  89. self?.pageNum = (self?.pageNum ?? 1) - 1
  90. }
  91. if isRefresh {
  92. self?.collectionView.mj_header?.endRefreshing()
  93. self?.collectionView.mj_footer?.resetNoMoreData()
  94. } else {
  95. self?.collectionView.mj_footer?.endRefreshing()
  96. }
  97. if (videoList?.count ?? 0) < 20 {
  98. self?.collectionView.mj_footer?.endRefreshingWithNoMoreData()
  99. }
  100. }
  101. }
  102. }
  103. extension MVMineProductController: UICollectionViewDelegate, UICollectionViewDataSource, UIScrollViewDelegate {
  104. func collectionView(_: UICollectionView, numberOfItemsInSection _: Int) -> Int {
  105. return itemsList.count
  106. }
  107. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  108. let itemData = itemsList[indexPath.item]
  109. let cell = MVMineProductCell.productCell(collectionView: collectionView, indexPath: indexPath)
  110. cell.videoData = itemData
  111. cell.btnClickHandle = { [weak self] sender, videoData in
  112. self?.btnClickHandle(sender: sender, videoData: videoData)
  113. }
  114. return cell
  115. }
  116. func collectionView(_: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  117. if itemsList[indexPath.item].auditStatus != 5 || itemsList[indexPath.item].transcodeStatus != 3 {
  118. return
  119. }
  120. let playVC = MVPlayViewController()
  121. playVC.itemsList = itemsList
  122. playVC.currentIndex = indexPath
  123. playVC.pageNum = pageNum
  124. navigationController?.pushViewController(playVC, animated: true)
  125. }
  126. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  127. BFLog(message: "scrollView.contentOffset.y = \(scrollView.contentOffset.y)")
  128. if scrollView.contentOffset.y <= 0 {
  129. navTitleLabel?.textColor = UIColor(white: 0, alpha: 0)
  130. } else if scrollView.contentOffset.y >= headH {
  131. navTitleLabel?.textColor = UIColor(white: 0, alpha: 1)
  132. } else {
  133. var alpha: CGFloat = (scrollView.contentOffset.y / headH)
  134. if alpha < 0 {
  135. alpha = 0
  136. }
  137. if alpha > 1 {
  138. alpha = 1
  139. }
  140. navTitleLabel?.textColor = UIColor(white: 0, alpha: alpha)
  141. }
  142. }
  143. /// 处理按钮点击事件
  144. /// - Parameters:
  145. /// - sender: <#sender description#>
  146. /// - videoData: <#videoData description#>
  147. func btnClickHandle(sender _: UIButton, videoData: PQVideoListModel?) {
  148. let seleView = PQSelectedOprationView.showSelectedOprationView(itemList: ["删除视频"]) { sender in
  149. if sender.tag == 1 {
  150. PQBaseViewModel.deleteVideo(videoId: Int(videoData?.uniqueId ?? "0") ?? 0) { [weak self] isSuccess, videoId, _ in
  151. if isSuccess {
  152. self?.itemsList.removeAll(where: { tempVideo in
  153. tempVideo.uniqueId == "\(videoId)"
  154. })
  155. self?.flowLayout.findList = self?.itemsList as! [PQVideoListModel]
  156. self?.collectionView.reloadData()
  157. cShowHUB(superView: nil, msg: "删除成功")
  158. if (self?.itemsList.count ?? 0) <= 0 {
  159. self?.loadRequestData()
  160. }
  161. }
  162. }
  163. }
  164. }
  165. seleView.contentView.backgroundColor = UIColor.hexColor(hexadecimal: "#F2F2F2")
  166. seleView.cancelBtn.backgroundColor = UIColor.white
  167. seleView.cancelBtn.setTitleColor(UIColor.black, for: .normal)
  168. seleView.cancelBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .semibold)
  169. let firstBtn: UIButton? = seleView.contentView.subviews[1] as? UIButton
  170. firstBtn?.backgroundColor = UIColor.white
  171. firstBtn?.setTitleColor(UIColor.hexColor(hexadecimal: "#FF0000"), for: .normal)
  172. firstBtn?.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .semibold)
  173. seleView.contentView.subviews[2].backgroundColor = UIColor.hexColor(hexadecimal: "#F2F2F2")
  174. }
  175. @objc func btnClick(sender _: UIButton) {}
  176. }