RedemptionAreaFloorTableViewCell.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // RedemptionAreaFloorTableViewCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/7/16.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyMediator
  10. class RedemptionAreaFloorTableViewCell: UITableViewCell {
  11. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> RedemptionAreaFloorTableViewCell {
  12. let ID = "RedemptionAreaFloorTableViewCell"
  13. tableView.register(RedemptionAreaFloorTableViewCell.self, forCellReuseIdentifier: ID)
  14. let cell : RedemptionAreaFloorTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! RedemptionAreaFloorTableViewCell
  15. cell.indexPath = indexPath
  16. return cell
  17. }
  18. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  19. super.init(style: style, reuseIdentifier: reuseIdentifier)
  20. setupViews()
  21. setupLayouts()
  22. }
  23. required init?(coder aDecoder: NSCoder) {
  24. fatalError("init(coder:) has not been implemented")
  25. }
  26. var indexPath: IndexPath? {
  27. didSet {
  28. }
  29. }
  30. //MARK: - 设置view
  31. private func setupViews() {
  32. self.selectionStyle = .none
  33. addSubview(collectionView)
  34. }
  35. private func setupLayouts() {
  36. collectionView.snp.makeConstraints { (make) in
  37. make.edges.equalToSuperview()
  38. }
  39. }
  40. private lazy var collectionView: UICollectionView = {
  41. let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
  42. collectionView.delegate = self;
  43. collectionView.dataSource = self;
  44. collectionView.showsVerticalScrollIndicator = false
  45. collectionView.showsHorizontalScrollIndicator = false
  46. collectionView.backgroundColor = UIColor.white
  47. collectionView.contentInset = UIEdgeInsets(top: 0, left: 5, bottom: 5, right: 5)
  48. return collectionView
  49. }()
  50. private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
  51. let collectionViewLayout = UICollectionViewFlowLayout.init()
  52. collectionViewLayout.minimumLineSpacing = 5
  53. collectionViewLayout.minimumInteritemSpacing = 5
  54. return collectionViewLayout
  55. }()
  56. var cmsRedemptionAreaContent: CMSRedemptionAreaContent? {
  57. didSet{
  58. collectionView.reloadData()
  59. }
  60. }
  61. }
  62. extension RedemptionAreaFloorTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
  63. func numberOfSections(in collectionView: UICollectionView) -> Int {
  64. if !(cmsRedemptionAreaContent?.rule?.isEmpty ?? true) {
  65. return 1
  66. }else {
  67. return 0
  68. }
  69. }
  70. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  71. if !(cmsRedemptionAreaContent?.rule?.isEmpty ?? true) {
  72. return cmsRedemptionAreaContent?.rule?.count ?? 0
  73. }else {
  74. return 0
  75. }
  76. }
  77. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  78. let cmsRedemptionAreaRule = cmsRedemptionAreaContent?.rule?[indexPath.row]
  79. let cell = RedemptionAreaProductCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
  80. cell.cmsRedemptionAreaRule = cmsRedemptionAreaRule
  81. return cell
  82. }
  83. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  84. let cmsRedemptionAreaRule = cmsRedemptionAreaContent?.rule?[indexPath.row]
  85. Mediator.push(H5RouterModuleType.pushDetail(id: "\(cmsRedemptionAreaRule?.id ?? 0)"))
  86. }
  87. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  88. return CGSize(width:(kScreenWidth-15)/2, height: (kScreenWidth-15)/2 + 116)
  89. }
  90. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  91. return UIEdgeInsets(top:0, left: 0, bottom: 0, right: 0)
  92. }
  93. }