ShopView.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // ShopView.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/5/12.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. class ShopView: BaseView {
  10. typealias DidSelectItemBlock = (_ indexPath: IndexPath) -> Void
  11. var didSelectItemBlock : DidSelectItemBlock?
  12. var shopModel : ShopModel? {
  13. didSet {
  14. tableView.reloadSections([0], with: UITableView.RowAnimation.none)
  15. }
  16. }
  17. var paginationModel: PaginationModel? {
  18. didSet {
  19. tableView.reloadData()
  20. }
  21. }
  22. var productSearchModelArray : Array<ProductSearchModel>? {
  23. didSet {
  24. if productSearchModelArray?.isEmpty ?? true {
  25. tableView.isHiddenFooter(true)
  26. }else {
  27. tableView.isHiddenFooter(false)
  28. }
  29. tableView.reloadData()
  30. }
  31. }
  32. override func setupViews() {
  33. addSubview(tableView)
  34. }
  35. override func setupLayouts() {
  36. tableView.snp.makeConstraints { (make) in
  37. make.edges.equalToSuperview()
  38. }
  39. }
  40. lazy var tableView: UITableView = {
  41. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.plain)
  42. tableView.separatorStyle = .none
  43. tableView.backgroundColor = kf7f8faColor
  44. tableView.dataSource = self
  45. tableView.delegate = self
  46. tableView.estimatedRowHeight = 82
  47. tableView.estimatedSectionFooterHeight = 0.000001
  48. tableView.estimatedSectionHeaderHeight = 0.000001
  49. return tableView
  50. }()
  51. }
  52. extension ShopView : UITableViewDelegate, UITableViewDataSource {
  53. func numberOfSections(in tableView: UITableView) -> Int {
  54. return 2
  55. }
  56. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  57. return 1
  58. }
  59. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  60. switch indexPath.section {
  61. case 0:
  62. let cell = ShopViewShopInfoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  63. cell.shopModel = shopModel
  64. cell.paginationModel = paginationModel
  65. cell.lookButtonClosure = {
  66. [weak self] isSelected in
  67. self?.shopModel?.isOpen = isSelected
  68. tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
  69. }
  70. return cell
  71. case 1:
  72. let cell = ShopViewTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  73. cell.productSearchModelArray = productSearchModelArray
  74. cell.frame = tableView.bounds
  75. cell.layoutIfNeeded()
  76. cell.reloadData()
  77. cell.didSelectItemBlock = {
  78. [weak self] indexPath in
  79. if let didSelectItemBlock = self?.didSelectItemBlock {
  80. didSelectItemBlock(indexPath)
  81. }
  82. }
  83. return cell
  84. default:
  85. return UITableViewCell()
  86. }
  87. }
  88. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  89. return UITableView.automaticDimension
  90. }
  91. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  92. switch section {
  93. case 0:
  94. return 0.000001
  95. case 1:
  96. return 44
  97. default:
  98. return 0
  99. }
  100. }
  101. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  102. switch section {
  103. case 0:
  104. return nil
  105. case 1:
  106. let view = ShopSectionHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 44))
  107. return view
  108. default:
  109. return nil
  110. }
  111. }
  112. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  113. return 0.000001
  114. }
  115. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  116. return nil
  117. }
  118. }