Procházet zdrojové kódy

Merge branch 'feature/liuxuqing' into develop

南鑫林 před 6 roky
rodič
revize
0c4a781925

+ 2 - 0
RainbowPlanet/RainbowPlanet/Macro/ColorMacro.swift

@@ -109,3 +109,5 @@ let kFFF1EBColor = UIColor(hexString: "FFF1EB")
 let kD2D3D5Color = UIColor(hexString: "D2D3D5")
 
 let kfee5e4Color = UIColor(hexString: "fee5e4")
+
+let kccccccColor = UIColor(hexString: "cccccc")

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

@@ -10,6 +10,13 @@ import UIKit
 
 class ShoppingCartHotSaleTableViewCell: UITableViewCell {
     
+    // 热销ModelArr
+    var hotSaleModelArr : Array<ProductSearchModel>? {
+        didSet {
+            collectionView.reloadData()
+        }
+    }
+    
     override var frame: CGRect {
         get {
             return super.frame
@@ -80,6 +87,27 @@ class ShoppingCartHotSaleTableViewCell: UITableViewCell {
             make.centerX.equalToSuperview()
             make.height.equalTo(23)
         }
+        
+        let leftLineView = UIView()
+        leftLineView.backgroundColor = kccccccColor
+        titleView.addSubview(leftLineView)
+        leftLineView.snp.makeConstraints({ (make) in
+            make.centerY.equalTo(titleLabel)
+            make.right.equalTo(titleLabel.snp_left).offset(-10)
+            make.width.equalTo(63)
+            make.height.equalTo(1)
+        })
+        
+        let rightLineView = UIView()
+        rightLineView.backgroundColor = kccccccColor
+        titleView.addSubview(rightLineView)
+        rightLineView.snp.makeConstraints({ (make) in
+            make.centerY.equalTo(titleLabel)
+            make.left.equalTo(titleLabel.snp_right).offset(10)
+            make.width.equalTo(63)
+            make.height.equalTo(1)
+        })
+        
         return titleView
     }()
     
@@ -123,7 +151,8 @@ extension ShoppingCartHotSaleTableViewCell: UICollectionViewDelegateFlowLayout,U
     }
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return 5
+//        return hotSaleModelArr?.count ?? 0
+        return 3
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

+ 65 - 7
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartList/ShoppingCartListTableViewHeader.swift

@@ -15,6 +15,7 @@ class ShoppingCartListTableViewHeader: BaseView {
     var shopName : String? {
         didSet {
             titleButton.setTitle(shopName, for: UIControl.State.normal)
+            titleButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.right, imageTitleSpace: 4)
         }
     }
     
@@ -31,9 +32,13 @@ class ShoppingCartListTableViewHeader: BaseView {
     }
     
     override func setupViews() {
-        self.backgroundColor = kffffffColor
+        self.backgroundColor = kf7f8faColor
         addSubview(separateView)
-        addSubview(titleButton)
+        addSubview(headerBackView)
+        addSubview(bottomLineView)
+        
+        headerBackView.addSubview(titleButton)
+        headerBackView.addSubview(selectedButton)
     }
     
     override func setupLayouts() {
@@ -42,9 +47,28 @@ class ShoppingCartListTableViewHeader: BaseView {
             make.height.equalTo(10)
         }
         
+        headerBackView.snp.makeConstraints { (make) in
+            make.top.equalTo(separateView.snp_bottom)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(48)
+        }
+        
         titleButton.snp.makeConstraints { (make) in
-            make.left.equalToSuperview().offset(10)
+            make.left.equalToSuperview().offset(36)
+//            make.top.equalTo(separateView.snp_bottom).offset(14)
             make.centerY.equalToSuperview()
+            make.height.equalTo(20)
+        }
+        
+        selectedButton.snp.makeConstraints { (make) in
+            make.left.equalTo(10)
+            make.centerY.equalTo(titleButton)
+            make.size.equalTo(18)
+        }
+        
+        bottomLineView.snp.makeConstraints { (make) in
+            make.left.right.bottom.equalToSuperview()
+            make.height.equalTo(1)
         }
     }
     
@@ -54,22 +78,56 @@ class ShoppingCartListTableViewHeader: BaseView {
         return separateView
     }()
     
+    lazy var headerBackView: UIView = {
+        let headerBackView = UIView()
+        headerBackView.backgroundColor = kffffffColor
+        let shapeLayer = CAShapeLayer()
+        headerBackView.layer.mask = nil
+        let rect = CGRect(x: 0, y: 0, width: kScreenWidth - 14 * kScaleWidth * 2, height: 48)
+        let bezierPath = UIBezierPath(roundedRect: rect,
+                                      byRoundingCorners: [.topLeft,.topRight],
+                                      cornerRadii: CGSize(width: 4,height: 4))
+        shapeLayer.frame = headerBackView.bounds
+        shapeLayer.path = bezierPath.cgPath
+        headerBackView.layer.mask = shapeLayer
+        return headerBackView
+    }()
+    
+    private lazy var selectedButton: UIButton = {
+        let selectedButton = UIButton(type: UIButton.ButtonType.custom)
+        selectedButton.setImage(kImage(name: "common_uncheck_icon"), for: UIControl.State.normal)
+        selectedButton.setImage(kImage(name: "common_check_icon"), for: UIControl.State.selected)
+        selectedButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            
+            //            if let loginBlock = self?.loginBlock {
+            //                loginBlock((self?.phoneNumber)!,(self?.password)!)
+            //            }
+            print("点击了全选当前section")
+            
+        }).disposed(by: disposeBag)
+        return selectedButton
+    }()
+    
     private lazy var titleButton: UIButton = {
         let titleButton = UIButton(type: UIButton.ButtonType.custom)
+        titleButton.setImage(kImage(name: "my_arrows_unfold"), for: UIControl.State.normal)
         titleButton.setTitleColor(k333333Color, for: UIControl.State.normal)
-        titleButton.setTitleColor(k666666Color, for: UIControl.State.selected)
-        titleButton.setImage(UIImage.imageWithColor(color: kDisabledButtonColor), for: UIControl.State.selected)
-        titleButton.setImage(UIImage.imageWithColor(color: kEnabledButtonColor), for: UIControl.State.normal)
         titleButton.titleLabel?.font = kScaleRegularFont14
         titleButton.rx.tap.subscribe(onNext: { [weak self] (data) in
             
             //            if let loginBlock = self?.loginBlock {
             //                loginBlock((self?.phoneNumber)!,(self?.password)!)
             //            }
-            print("点击了全选当前section")
+            print("点击了商店Title")
             
         }).disposed(by: disposeBag)
         return titleButton
     }()
     
+    private lazy var bottomLineView: UIView = {
+        let bottomLineView = UIView()
+        bottomLineView.backgroundColor = kf5f5f5Color
+        return bottomLineView
+    }()
+    
 }

+ 23 - 13
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -10,12 +10,21 @@ import UIKit
 
 class ShoppingCartView: BaseView {
     
-    var cartListModelsArr : Array<CartProductListModel>? {
+    // 购物车列表ModelArr
+    var cartListModelArr : Array<CartProductListModel>? {
         didSet {
             tableView.reloadData()
         }
     }
     
+    // 热销ModelArr
+    var hotSaleModelArr : Array<ProductSearchModel>? {
+        didSet {
+            //FIXME:刷新指定section
+            tableView.reloadData()
+        }
+    }
+    
     override func setupViews() {
         self.backgroundColor = kf7f8faColor
         addSubview(accountView)
@@ -59,16 +68,16 @@ class ShoppingCartView: BaseView {
 extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
     func numberOfSections(in tableView: UITableView) -> Int {
         // 购物车列表 + 超值热卖
-        return cartListModelsArr?.isEmpty ?? true ? 2 : cartListModelsArr!.count + 1
+        return cartListModelArr?.isEmpty ?? true ? 2 : cartListModelArr!.count + 1
     }
     
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        if cartListModelsArr?.isEmpty ?? true {
+        if cartListModelArr?.isEmpty ?? true {
             return 1
             
         } else {
-            if  section < cartListModelsArr!.count {
-                return cartListModelsArr![section].productList?.isEmpty ?? true ? 0 : cartListModelsArr![section].productList!.count
+            if  section < cartListModelArr!.count {
+                return cartListModelArr![section].productList?.isEmpty ?? true ? 0 : cartListModelArr![section].productList!.count
             } else {
                 return 1
             }
@@ -76,7 +85,7 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-        if cartListModelsArr?.count == 0 {
+        if cartListModelArr?.count == 0 {
             switch indexPath.section {
             case 0:
                 // 购物车列表为空
@@ -94,13 +103,14 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
             }
             
         } else {
-            if indexPath.section < cartListModelsArr!.count {
+            if indexPath.section < cartListModelArr!.count {
                 // 购物车列表Item
                 let cell = ShoppingCartListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
-                cell.productMdl = cartListModelsArr![indexPath.section].productList![indexPath.row]
+                cell.productMdl = cartListModelArr![indexPath.section].productList![indexPath.row]
                 return cell
                 
             } else {
+                // 超值热卖
                 let cell = ShoppingCartHotSaleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
                 cell.frame = tableView.bounds
                 cell.layoutIfNeeded()
@@ -115,17 +125,17 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
     }
     
     func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
-        if cartListModelsArr?.count ?? 0 > 0 && section < cartListModelsArr!.count {
-            return 48
+        if cartListModelArr?.count ?? 0 > 0 && section < cartListModelArr!.count {
+            return 58
         } else {
             return 10
         }
     }
     
     func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
-        if cartListModelsArr?.count ?? 0 > 0 && section < cartListModelsArr!.count {
-            let headerView = ShoppingCartListTableViewHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 48))
-            headerView.shopName = cartListModelsArr![section].shopName
+        if cartListModelArr?.count ?? 0 > 0 && section < cartListModelArr!.count {
+            let headerView = ShoppingCartListTableViewHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 58))
+            headerView.shopName = cartListModelArr![section].shopName
             return headerView
         } else {
             return nil

+ 38 - 5
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/ViewController/ShoppingCartViewController.swift

@@ -11,6 +11,8 @@ import RxSwift
 
 class ShoppingCartViewController: BaseViewController {
     
+    var productSearchModelArray = Array<ProductSearchModel>()
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         setupViews()
@@ -41,11 +43,14 @@ class ShoppingCartViewController: BaseViewController {
     }
     
     override func setupData() {
-        SwiftMoyaNetWorkServiceProduct.shared().productCartListApi { [weak self] (cartListData) -> (Void) in
-            let cartListData = cartListData as? ProductCartListData
-            self?.setShoppingCartView()
-            self?.shoppingCartView.cartListModelsArr = cartListData?.data
-            
+        
+        shoppingCartView.tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) { [weak self] (page) in
+            self?.productCartListApi()
+            self?.productSearchApi(page: page)
+        }
+        
+        shoppingCartView.tableView.addFooterWithWithHeader(withAutomaticallyRefresh: true) { [weak self] (page) in
+            self?.productSearchApi(page: page)
         }
     }
     
@@ -62,5 +67,33 @@ class ShoppingCartViewController: BaseViewController {
         let shoppingCartView = ShoppingCartView()
         return shoppingCartView
     }()
+    
+    /// 购物车列表
+    func productCartListApi() {
+        SwiftMoyaNetWorkServiceProduct.shared().productCartListApi { [weak self] (cartListData) -> (Void) in
+            let cartListData = cartListData as? ProductCartListData
+            self?.setShoppingCartView()
+            self?.shoppingCartView.cartListModelArr = cartListData?.data
+        }
+    }
+    
+    /// 商品热销
+    func productSearchApi(page:Int = 1) {
+        SwiftMoyaNetWorkServiceProduct.shared().productSearchApi(page:page) {
+            [weak self] (productSearchListModel) -> (Void) in
+            let productSearchListModel = productSearchListModel as? ProductSearchListModel
+            if productSearchListModel?.pagination?.currentPage ?? 1  <= productSearchListModel?.pagination?.totalPages ?? 1 {
+                if productSearchListModel?.pagination?.currentPage == 1{
+                    self?.productSearchModelArray.removeAll()
+                }
+                self?.productSearchModelArray = (self?.productSearchModelArray)! + (productSearchListModel?.data!)!
+                
+                self?.shoppingCartView.hotSaleModelArr = self?.productSearchModelArray
+                
+            } else {
+                self?.shoppingCartView.hotSaleModelArr = self?.productSearchModelArray
+            }
+        }
+    }
 
 }