123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- //
- // ShopView.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/5/12.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- class ShopView: BaseView {
-
- typealias DidSelectItemBlock = (_ indexPath: IndexPath) -> Void
- var didSelectItemBlock : DidSelectItemBlock?
-
- typealias PlusCloSure = () -> Void
- var plusCloSure : PlusCloSure?
-
- var shopModel : ShopModel? {
- didSet {
- tableView.reloadData()
- }
- }
-
- var paginationModel: PaginationModel? {
- didSet {
- tableView.reloadData()
- }
- }
-
- var productSearchModelArray : Array<ProductSearchModel>? {
- didSet {
- if productSearchModelArray?.isEmpty ?? true {
- tableView.isHiddenFooter(true)
- }else {
- tableView.isHiddenFooter(false)
- }
- tableView.reloadData()
- }
- }
-
- var shopSectionHeaderModel : ShopSectionHeaderModel? {
- didSet {
- tableView.reloadData()
- }
- }
-
- override func setupViews() {
- addSubview(tableView)
- }
-
- override func setupLayouts() {
- tableView.snp.makeConstraints { (make) in
- make.edges.equalToSuperview()
- }
- }
-
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.plain)
- tableView.separatorStyle = .none
- tableView.backgroundColor = kf7f8faColor
- tableView.dataSource = self
- tableView.delegate = self
- tableView.estimatedRowHeight = 82
- tableView.estimatedSectionFooterHeight = 0.000001
- tableView.estimatedSectionHeaderHeight = 0.000001
- return tableView
- }()
-
-
- }
- extension ShopView : UITableViewDelegate, UITableViewDataSource {
- func numberOfSections(in tableView: UITableView) -> Int {
- return 2
- }
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 1
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- switch indexPath.section {
- case 0:
- let cell = ShopViewShopInfoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.shopModel = shopModel
- cell.paginationModel = paginationModel
- cell.lookButtonClosure = {
- [weak self] isSelected in
- self?.shopModel?.isOpen = isSelected
- tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
- }
- return cell
- case 1:
- let cell = ShopViewTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.productSearchModelArray = productSearchModelArray
- cell.frame = tableView.bounds
- cell.layoutIfNeeded()
- cell.reloadData()
- cell.didSelectItemBlock = {
- [weak self] indexPath in
- if let didSelectItemBlock = self?.didSelectItemBlock {
- didSelectItemBlock(indexPath)
- }
- }
- cell.plusCloSure = {
- if let plusCloSure = self.plusCloSure {
- plusCloSure()
- }
- }
- return cell
- default:
- return UITableViewCell()
- }
- }
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return UITableView.automaticDimension
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- switch section {
- case 0:
- return 0.000001
- case 1:
- return 44
- default:
- return 0
- }
-
- }
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- switch section {
- case 0:
- return nil
- case 1:
- let view = ShopSectionHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 44))
- view.shopSectionHeaderModel = self.shopSectionHeaderModel
- return view
- default:
- return nil
- }
-
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- return 0.000001
- }
-
- func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
- return nil
- }
-
- }
|