Przeglądaj źródła

购物车首页table数据源

Chris 6 lat temu
rodzic
commit
d56bd95da1

+ 2 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartHotSale/ShoppingCartHotSaleTableViewCell.swift

@@ -123,7 +123,7 @@ extension ShoppingCartHotSaleTableViewCell: UICollectionViewDelegateFlowLayout,U
     }
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return 9
+        return 5
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
@@ -136,7 +136,7 @@ extension ShoppingCartHotSaleTableViewCell: UICollectionViewDelegateFlowLayout,U
     }
     
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
-        return UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
+        return UIEdgeInsets(top: 10, left: 0, bottom: 20, right: 0)
     }
     
 }

+ 54 - 51
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -10,6 +10,12 @@ import UIKit
 
 class ShoppingCartView: BaseView {
     
+    var cartListModelsArr : Array<CartProductListModel>? {
+        didSet {
+            tableView.reloadData()
+        }
+    }
+    
     override func setupViews() {
         self.backgroundColor = kf7f8faColor
         addSubview(accountView)
@@ -26,8 +32,8 @@ class ShoppingCartView: BaseView {
             make.height.equalTo(48)
         }
         tableView.snp.makeConstraints { (make) in
-            make.edges.equalToSuperview()
-            make.bottom.equalTo(accountView.snp_top).offset(-20)
+            make.top.left.right.equalToSuperview()
+            make.bottom.equalTo(accountView.snp_top).offset(0)
         }
     }
     
@@ -52,78 +58,75 @@ class ShoppingCartView: BaseView {
 
 extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
     func numberOfSections(in tableView: UITableView) -> Int {
-        return 4
+        // 购物车列表 + 超值热卖
+        return cartListModelsArr?.isEmpty ?? true ? 2 : cartListModelsArr!.count + 1
     }
     
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        switch section {
-        case 0:
-            return 1
-        case 1:
-            return 3
-        case 2:
-            return 2
-        case 3:
-            return 1
-        default:
+        if cartListModelsArr?.isEmpty ?? true {
             return 1
+            
+        } else {
+            if  section < cartListModelsArr!.count {
+                return cartListModelsArr![section].productList?.isEmpty ?? true ? 0 : cartListModelsArr![section].productList!.count
+            } else {
+                return 1
+            }
         }
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-        switch indexPath.section {
-        case 0:
-            let cell = ShoppingCartListNoneItemCell.cellWith(tableView: tableView, indexPath: indexPath)
-            return cell
-        case 1:
-            let cell = ShoppingCartListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
-            return cell
-        case 2:
-            let cell = ShoppingCartListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
-            return cell
-        case 3:
-            let cell = ShoppingCartHotSaleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
-            cell.frame = tableView.bounds
-            cell.layoutIfNeeded()
-            cell.reloadData()
-            return cell
+        if cartListModelsArr?.count == 0 {
+            switch indexPath.section {
+            case 0:
+                // 购物车列表为空
+                let cell = ShoppingCartListNoneItemCell.cellWith(tableView: tableView, indexPath: indexPath)
+                return cell
+            case 1:
+                // 超值热卖
+                let cell = ShoppingCartHotSaleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+                cell.frame = tableView.bounds
+                cell.layoutIfNeeded()
+                cell.reloadData()
+                return cell
+            default:
+                return UITableViewCell()
+            }
             
-        default:
-            return UITableViewCell()
+        } else {
+            if indexPath.section < cartListModelsArr!.count {
+                // 购物车列表Item
+                let cell = ShoppingCartListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+                return cell
+                
+            } else {
+                let cell = ShoppingCartHotSaleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+                cell.frame = tableView.bounds
+                cell.layoutIfNeeded()
+                cell.reloadData()
+                return cell
+            }
         }
-        
     }
     
     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
-        switch indexPath.section {
-        case 0:
-            return  UITableView.automaticDimension
-        case 1:
-            return  UITableView.automaticDimension
-        case 2:
-            return  UITableView.automaticDimension
-        case 3:
-            return  UITableView.automaticDimension
-        default:
-            return 0
-        }
-        
+        return  UITableView.automaticDimension
     }
     
     func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
-        if section == 0 || section == 3 {
-            return 10
-        } else {
+        if cartListModelsArr?.count ?? 0 > 0 && section < cartListModelsArr!.count {
             return 48
+        } else {
+            return 10
         }
     }
     
     func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
-        if section == 3 || section == 0 {
-            return nil
-        } else {
+        if cartListModelsArr?.count ?? 0 > 0 && section < cartListModelsArr!.count {
             let headerView = ShoppingCartListTableViewHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 48))
             return headerView
+        } else {
+            return nil
         }
     }
     

+ 11 - 8
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/ViewController/ShoppingCartViewController.swift

@@ -4,17 +4,20 @@
 //
 //  Created by 南鑫林 on 2019/3/7.
 //  Copyright © 2019 RainbowPlanet. All rights reserved.
-//
+//  购物车首页Vc
 
 import UIKit
 import RxSwift
 
 class ShoppingCartViewController: BaseViewController {
-
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         setupViews()
         setupLayouts()
+    }
+    
+    override func viewWillAppear(_ animated: Bool) {
         setupData()
     }
     
@@ -28,12 +31,12 @@ class ShoppingCartViewController: BaseViewController {
     }
     
     override func setupData() {
-        //TODO:获取购物车列表
-//        SwiftMoyaNetWorkServiceCMS.shared().cmsTemplateSetTemplateNameApi {
-//            [weak self] (data) -> (Void) in
-//            self?.setShoppingCartView()
-        self.setShoppingCartView()
-//        }
+        SwiftMoyaNetWorkServiceProduct.shared().productCartListApi { [weak self] (cartListData) -> (Void) in
+            let cartListData = cartListData as? ProductCartListData
+            self?.setShoppingCartView()
+            self?.shoppingCartView.cartListModelsArr = cartListData?.data
+            
+        }
     }
     
     /// 添加view