Browse Source

加入购物车

南鑫林 6 years ago
parent
commit
a131d4baea
14 changed files with 307 additions and 73 deletions
  1. 8 4
      RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj
  2. 2 2
      RainbowPlanet/RainbowPlanet/Modules/OrderModule/OrderComment/View/OrderCommentAddImgCollectionCell.swift
  3. 11 4
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/Cell/ProcuctDetailSelectSku/ProcuctDetailSelectSkuTableViewCell.swift
  4. 1 11
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/Cell/ProductDetailProductLabel/ProductDetailProductLabelTableViewCell.swift
  5. 107 13
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/ProductDetailView.swift
  6. 22 26
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/ProductDetailSkuView/ProductDetailSkuView.swift
  7. 35 2
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/ViewController/ProductDetailViewController.swift
  8. 8 2
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallBanner/ShoppingMallBannerTableViewCell.swift
  9. 10 2
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallListView.swift
  10. 27 0
      RainbowPlanet/RainbowPlanet/Service/Model/ProductModel/ProductCartCountModel.swift
  11. 0 2
      RainbowPlanet/RainbowPlanet/Service/Model/ProductModel/ProductCommentListModel.swift
  12. 2 0
      RainbowPlanet/RainbowPlanet/Service/Model/ProductModel/ProductDetailModel.swift
  13. 59 1
      RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaNetWorkServiceProduct.swift
  14. 15 4
      RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaServiceProductApi.swift

+ 8 - 4
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -12,7 +12,6 @@
 		A70B2C072284305400B2449F /* ProductModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B2C062284305400B2449F /* ProductModel.swift */; };
 		A70B2C102286A3BC00B2449F /* ProductDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B2C0F2286A3BC00B2449F /* ProductDetailModel.swift */; };
 		A70B2C1D2286B52400B2449F /* ProductDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B2C1B2286B52400B2449F /* ProductDetailViewController.swift */; };
-		A70B2C202286B54500B2449F /* ProductDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B2C1F2286B54500B2449F /* ProductDetailView.swift */; };
 		A70B2C222286BF5900B2449F /* ProductDetailTableViewHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B2C212286BF5900B2449F /* ProductDetailTableViewHeaderView.swift */; };
 		A70B2C252286C03800B2449F /* NXLPageControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B2C242286C03800B2449F /* NXLPageControl.swift */; };
 		A70B2C272286C5D600B2449F /* ProductDetailFSPagerViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B2C262286C5D600B2449F /* ProductDetailFSPagerViewCell.swift */; };
@@ -41,6 +40,8 @@
 		A70B2C732289019200B2449F /* ProductDetailSkuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B2C722289019200B2449F /* ProductDetailSkuView.swift */; };
 		A70B2C75228920BA00B2449F /* ProductDetailSkuSectionHeaerCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B2C74228920BA00B2449F /* ProductDetailSkuSectionHeaerCollectionReusableView.swift */; };
 		A70B842E228F97EC00882BC5 /* ProcuctDetailSelectSkuTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B842D228F97EC00882BC5 /* ProcuctDetailSelectSkuTableViewCell.swift */; };
+		A70B8430228FF6D400882BC5 /* ProductCartCountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B842F228FF6D400882BC5 /* ProductCartCountModel.swift */; };
+		A70B84322290046D00882BC5 /* ProductDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B84312290046D00882BC5 /* ProductDetailView.swift */; };
 		A70EBBC022561179000AD74F /* Extension+UITableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70EBBBF22561179000AD74F /* Extension+UITableView.swift */; };
 		A7146349228EFCE20066099B /* ORSKUDataFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = A7146347228EFCE20066099B /* ORSKUDataFilter.m */; };
 		A714634E228F020A0066099B /* ORSKUDataFilterSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = A714634D228F020A0066099B /* ORSKUDataFilterSwift.swift */; };
@@ -388,7 +389,6 @@
 		A70B2C062284305400B2449F /* ProductModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductModel.swift; sourceTree = "<group>"; };
 		A70B2C0F2286A3BC00B2449F /* ProductDetailModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductDetailModel.swift; sourceTree = "<group>"; };
 		A70B2C1B2286B52400B2449F /* ProductDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductDetailViewController.swift; sourceTree = "<group>"; };
-		A70B2C1F2286B54500B2449F /* ProductDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductDetailView.swift; sourceTree = "<group>"; };
 		A70B2C212286BF5900B2449F /* ProductDetailTableViewHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductDetailTableViewHeaderView.swift; sourceTree = "<group>"; };
 		A70B2C242286C03800B2449F /* NXLPageControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NXLPageControl.swift; sourceTree = "<group>"; };
 		A70B2C262286C5D600B2449F /* ProductDetailFSPagerViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductDetailFSPagerViewCell.swift; sourceTree = "<group>"; };
@@ -417,6 +417,8 @@
 		A70B2C722289019200B2449F /* ProductDetailSkuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductDetailSkuView.swift; sourceTree = "<group>"; };
 		A70B2C74228920BA00B2449F /* ProductDetailSkuSectionHeaerCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductDetailSkuSectionHeaerCollectionReusableView.swift; sourceTree = "<group>"; };
 		A70B842D228F97EC00882BC5 /* ProcuctDetailSelectSkuTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProcuctDetailSelectSkuTableViewCell.swift; sourceTree = "<group>"; };
+		A70B842F228FF6D400882BC5 /* ProductCartCountModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCartCountModel.swift; sourceTree = "<group>"; };
+		A70B84312290046D00882BC5 /* ProductDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductDetailView.swift; sourceTree = "<group>"; };
 		A70EBBBF22561179000AD74F /* Extension+UITableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Extension+UITableView.swift"; sourceTree = "<group>"; };
 		A7146347228EFCE20066099B /* ORSKUDataFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORSKUDataFilter.m; sourceTree = "<group>"; };
 		A7146348228EFCE20066099B /* ORSKUDataFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ORSKUDataFilter.h; sourceTree = "<group>"; };
@@ -891,7 +893,6 @@
 			children = (
 				A70B2C702289016600B2449F /* ProductDetailSkuView */,
 				A70B2C39228819CA00B2449F /* Cell */,
-				A70B2C1F2286B54500B2449F /* ProductDetailView.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -932,6 +933,7 @@
 				A70B2C442288408E00B2449F /* ProductDetailHotSell */,
 				A70B2C4A228845B200B2449F /* ProductDetailParameter */,
 				A70B2C4F22884EF100B2449F /* ProductDetailDescription */,
+				A70B84312290046D00882BC5 /* ProductDetailView.swift */,
 			);
 			path = Cell;
 			sourceTree = "<group>";
@@ -2238,6 +2240,7 @@
 				A70B2C0F2286A3BC00B2449F /* ProductDetailModel.swift */,
 				BDE3045C22851E4F001D050F /* ProductCartListModel.swift */,
 				BDE3045E228554CA001D050F /* ProductCartAmountModel.swift */,
+				A70B842F228FF6D400882BC5 /* ProductCartCountModel.swift */,
 				A71738AC228AB7B2000AEA6A /* ProductCommentListModel.swift */,
 				BDDF3B27228EBB72003A7D16 /* ProductRefundReasonModel.swift */,
 			);
@@ -3301,6 +3304,7 @@
 				A70B2C3322880BB700B2449F /* ProductDetailProductLabelTableViewCell.swift in Sources */,
 				BDF45F0D228C00B8004E2682 /* DefaultContactInfoModel.swift in Sources */,
 				A72A72BA22321DE000B21995 /* Extension+String.swift in Sources */,
+				A70B8430228FF6D400882BC5 /* ProductCartCountModel.swift in Sources */,
 				A77F2CA02231FE45001BD3F6 /* BaseWebViewController.swift in Sources */,
 				BD20F1D52283D15500677D8E /* ShoppingCartPayFailureCell.swift in Sources */,
 				A72A72C022321DE000B21995 /* Extension+UIView.swift in Sources */,
@@ -3401,7 +3405,6 @@
 				A71AF0BA226F00F8001730FE /* SearchResultView.swift in Sources */,
 				A77F2CB52232010F001BD3F6 /* ShoppingMallViewController.swift in Sources */,
 				A71AA513227215B5008FF1A5 /* ExpressAddressListView.swift in Sources */,
-				A70B2C202286B54500B2449F /* ProductDetailView.swift in Sources */,
 				A7B4E723228154750012914A /* ProductFloorBannerView.swift in Sources */,
 				A7DC467F22783A47001F3EFC /* EditExpressAddressTableViewCell.swift in Sources */,
 				A7A98E4522804C63005306E9 /* ShoppingMallSepcialCollectionViewCell.swift in Sources */,
@@ -3587,6 +3590,7 @@
 				BD7AB8452284398A0030646A /* OrderPaySelfPickAddInfoCell.swift in Sources */,
 				A72A72D222321E2700B21995 /* Common.swift in Sources */,
 				A70B2C64228875DE00B2449F /* ShopViewShopInfoTableViewCell.swift in Sources */,
+				A70B84322290046D00882BC5 /* ProductDetailView.swift in Sources */,
 				BDEF7791228571DC00ED0AC0 /* CommonPayView.swift in Sources */,
 				A71AF0A6226EDDC8001730FE /* SearchViewController.swift in Sources */,
 				BD20F1CF2283CE2300677D8E /* ShoppingCartFinishPayView.swift in Sources */,

+ 2 - 2
RainbowPlanet/RainbowPlanet/Modules/OrderModule/OrderComment/View/OrderCommentAddImgCollectionCell.swift

@@ -95,9 +95,9 @@ class OrderCommentAddImgCollectionCell: UICollectionViewCell {
         delButton.setImage(kImage(name: "common_sku_cancel"), for: UIControl.State.normal)
         delButton.rx.tap.subscribe(onNext: {
             [weak self] (data) in
-            let idxPath = self?.indexPath as! IndexPath
+            let idxPath = self?.indexPath
             if let delPicBlock = self?.delPicBlock {
-                delPicBlock(idxPath.row)
+                delPicBlock(idxPath?.row)
             }
         }).disposed(by: disposeBag)
         return delButton

+ 11 - 4
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/Cell/ProcuctDetailSelectSku/ProcuctDetailSelectSkuTableViewCell.swift

@@ -10,7 +10,7 @@ import UIKit
 
 class ProcuctDetailSelectSkuTableViewCell: UITableViewCell {
     
-    class func cellWith(tableView:UITableView,indexPath:IndexPath) -> UITableViewCell {
+    class func cellWith(tableView:UITableView,indexPath:IndexPath) -> ProcuctDetailSelectSkuTableViewCell {
         let ID = "ProcuctDetailSelectSkuTableViewCell"
         tableView.register(ProcuctDetailSelectSkuTableViewCell.self, forCellReuseIdentifier: ID)
         let cell : ProcuctDetailSelectSkuTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! ProcuctDetailSelectSkuTableViewCell
@@ -50,17 +50,17 @@ class ProcuctDetailSelectSkuTableViewCell: UITableViewCell {
             make.height.equalTo(20)
         }
         
-        goImageView.snp.makeConstraints { (make) in
+        goImageView.snp.remakeConstraints { (make) in
             make.centerY.equalToSuperview()
             make.right.equalTo(-14)
             make.width.equalTo(6)
             make.height.equalTo(11)
         }
         
-        skuLabel.snp.makeConstraints { (make) in
+        skuLabel.snp.remakeConstraints { (make) in
             make.top.equalTo(13)
             make.left.equalTo(selectedLabel.snp.right).offset(27)
-            make.right.equalTo(-14)
+            make.right.equalTo(goImageView.snp.left).offset(-10)
             make.bottom.equalTo(-13)
         }
     }
@@ -86,5 +86,12 @@ class ProcuctDetailSelectSkuTableViewCell: UITableViewCell {
         goImageView.image = kImage(name: "my_arrows_unfold")
         return goImageView
     }()
+    
+    var productDetailSkuModel: ProductDetailSkuModel? {
+        didSet {
+            selectedLabel.text = "已选中"
+            skuLabel.text = productDetailSkuModel?.skuName
+        }
+    }
 
 }

+ 1 - 11
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/Cell/ProductDetailProductLabel/ProductDetailProductLabelTableViewCell.swift

@@ -46,12 +46,6 @@ class ProductDetailProductLabelTableViewCell: UITableViewCell {
     }
     
     private func setupLayouts() {
-//        bgView.snp.makeConstraints { (make) in
-//            make.top.left.right.equalToSuperview()
-//            make.bottom.equalTo(iconCollectionView.snp.top)
-//        }
-
-        
         iconCollectionView.snp.makeConstraints { (make) in
             make.top.equalToSuperview()
             make.height.equalTo(65 * kScaleWidth)
@@ -60,7 +54,7 @@ class ProductDetailProductLabelTableViewCell: UITableViewCell {
         }
         bgView.snp.makeConstraints { (make) in
             make.top.equalTo(10)
-            make.bottom.equalTo(10)
+            make.bottom.equalTo(-10)
             make.right.equalToSuperview()
             make.width.equalTo(kScreenWidth/5)
         }
@@ -77,13 +71,9 @@ class ProductDetailProductLabelTableViewCell: UITableViewCell {
     
     lazy var bgView : UIView = {
         let bgView = UIView()
-        bgView.addTapGesture(1, target: self, action: #selector(tapSku))
         return bgView
     }()
     
-    @objc func tapSku() {
-        ProductDetailSkuView.productDetailSkuView(productDetailModel: productDetailModel!)
-    }
     
     
     private lazy var iconCollectionView: UICollectionView = {

+ 107 - 13
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/ProductDetailView.swift

@@ -1,4 +1,4 @@
-//
+
 //  ProductDetailView.swift
 //  RainbowPlanet
 //
@@ -15,6 +15,13 @@ class ProductDetailView: BaseView {
     typealias LookAllCommentClosure = () -> Void
     var lookAllCommentClosure : LookAllCommentClosure?
     
+    typealias AddCartClosure = (ProductDetailSkuModel) -> Void
+    var addCartClosure : AddCartClosure?
+    
+    typealias BuyNowClosure = (ProductDetailSkuModel) -> Void
+    var buyNowClosure : BuyNowClosure?
+    
+    var productDetailSkuModel : ProductDetailSkuModel?
     
     var titles = ["","","商品评价","","热销排行","商品参数","商品详情"]
     
@@ -27,7 +34,7 @@ class ProductDetailView: BaseView {
                 let rect = tableView.rect(forSection: reloadSection)
                 tableView.setContentOffset(CGPoint(x: 0, y: rect.origin.y - kNavBarTotalHeight), animated: true)
             }
-           
+            
         }
     }
     
@@ -39,7 +46,7 @@ class ProductDetailView: BaseView {
                 
                 if productDetailModel?.commentNumber != 0 && productDetailModel?.commentNumber != nil {
                     titles[2] = "商品评价" + "(" + "\(productDetailModel?.commentNumber ?? 0)" + ")"
-
+                    
                 }
                 if productDetailModel?.imgs?.isEmpty ?? true {
                     tableView.tableHeaderView = nil
@@ -64,7 +71,7 @@ class ProductDetailView: BaseView {
         }
     }
     
-
+    
     override func setupViews() {
         addSubview(bottomBgView)
         bottomBgView.addSubview(cartButton)
@@ -145,9 +152,6 @@ class ProductDetailView: BaseView {
     private lazy var cartImageView: UIImageView = {
         let cartImageView = UIImageView()
         cartImageView.image = kImage(name: "tabbar_shopping")
-        cartImageView.pp.addBadge(number: 2)
-        //        shoppingCarButton.pp.setBadge(height: 14)
-        //        shoppingCarButton.pp.badgeView.font = kRegularFont10
         cartImageView.pp.badgeView.backgroundColor = kfe352bColor
         cartImageView.pp.moveBadge(x: -2, y: 2)
         return cartImageView
@@ -159,6 +163,12 @@ class ProductDetailView: BaseView {
         addCartButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
         addCartButton.backgroundColor = k404040Color
         addCartButton.titleLabel?.font = kRegularFont16
+        addCartButton.rx.tap.subscribe(onNext: {
+            [weak self] (data) in
+            self?.view.productDetailSkuViewType = ProductDetailSkuViewType.addCart
+            self?.view.productDetailModel = self?.productDetailModel
+            self?.view.show()
+        }).disposed(by: disposeBag)
         return addCartButton
     }()
     
@@ -170,7 +180,9 @@ class ProductDetailView: BaseView {
         buyButton.titleLabel?.font = kRegularFont16
         buyButton.rx.tap.subscribe(onNext: {
             [weak self] (data) in
-            ProductDetailSkuView.productDetailSkuView(productDetailModel: (self?.productDetailModel!)!)
+            self?.view.productDetailSkuViewType = ProductDetailSkuViewType.buyNow
+            self?.view.productDetailModel = self?.productDetailModel
+            self?.view.show()
         }).disposed(by: disposeBag)
         return buyButton
     }()
@@ -184,6 +196,61 @@ class ProductDetailView: BaseView {
         return topButton
     }()
     
+    
+    lazy var view: ProductDetailSkuView = {
+        let view = ProductDetailSkuView(frame: CGRect(x: 0, y: 0, width: kScreenWidth , height: kScreenHeight - 76 - kNavBarTotalHeight))
+        let vProperty1 = FWPopupViewProperty()
+        vProperty1.popupCustomAlignment = .bottomCenter
+        vProperty1.popupAnimationType = .frame
+        vProperty1.maskViewColor = UIColor(white: 0, alpha: 0.5)
+        vProperty1.touchWildToHide = "0"
+        vProperty1.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
+        vProperty1.animationDuration = 0.1
+        view.vProperty = vProperty1
+        view.sureClosure = {
+            [weak self] (productDetailSkuViewType,productDetailSkuModel) in
+            self?.productDetailSkuModel = productDetailSkuModel
+            switch productDetailSkuViewType {
+            case .selectSku:
+                self?.tableView.reloadRows(at: [IndexPath(row: 0, section: 1)], with: UITableView.RowAnimation.none)
+                view.hide()
+                break
+            case .buyNow:
+                view.hide(popupDidDisappearBlock: { (FWPopupView) in
+
+                })
+                break
+            case .addCart:
+
+                if let addCartClosure = self?.addCartClosure {
+                    addCartClosure((self?.productDetailSkuModel)!)
+                }
+                break
+            }
+        }
+        return view
+    }()
+    
+    var cartAmountModel : CartAmountModel? {
+        didSet {
+            if cartAmountModel != nil {
+                self.tableView.reloadRows(at: [IndexPath(row: 0, section: 1)], with: UITableView.RowAnimation.none)
+                cartImageView.pp.addBadge(number: cartAmountModel?.amount ?? 0)
+                self.view.hide()
+            }
+            
+        }
+    }
+    var productCartCountModel : ProductCartCountModel? {
+        didSet {
+            if productCartCountModel != nil {
+                cartImageView.pp.addBadge(number: productCartCountModel?.count ?? 0)
+//                self.view.hide()
+            }
+            
+        }
+    }
+    
 }
 
 extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
@@ -225,7 +292,7 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-       
+        
         
         switch indexPath.section {
         case 0:
@@ -236,6 +303,9 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
             if !(productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
                 if indexPath.row == 0 {
                     let cell = ProcuctDetailSelectSkuTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+                    if self.productDetailSkuModel != nil {
+                        cell.productDetailSkuModel = self.productDetailSkuModel
+                    }
                     return cell
                 }else {
                     let cell = ProductDetailProductLabelTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
@@ -258,6 +328,9 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
             
             if !(productDetailModel?.spec?.isEmpty ?? true) && (productDetailModel?.label?.isEmpty ?? true) {
                 let cell = ProcuctDetailSelectSkuTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+                if self.productDetailSkuModel != nil {
+                    cell.productDetailSkuModel = self.productDetailSkuModel
+                }
                 return cell
             }
             return UITableViewCell()
@@ -283,12 +356,29 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
             return cell
             
         default:
-           
+            
             return UITableViewCell()
         }
         
     }
     
+    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        if indexPath.section == 1 {
+            if !(productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
+                if indexPath.row == 0 {
+                    self.view.productDetailSkuViewType = ProductDetailSkuViewType.selectSku
+                    self.view.productDetailModel = self.productDetailModel
+                    self.view.show()
+                }
+            }
+            if !(productDetailModel?.spec?.isEmpty ?? true) && (productDetailModel?.label?.isEmpty ?? true) {
+                self.view.productDetailSkuViewType = ProductDetailSkuViewType.selectSku
+                self.view.productDetailModel = self.productDetailModel
+                self.view.show()
+            }
+        }
+    }
+    
     
     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
         switch indexPath.section {
@@ -357,25 +447,29 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
         var offset = scrollView.contentOffset
         NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ProductDetailView"), object: offset)
-
+        
         if (!(scrollView.isTracking || scrollView.isDecelerating)) {
             //不是用户滚动的,比如setContentOffset等方法,引起的滚动不需要处理。
             return;
         }
         offset.y =  offset.y + kNavBarTotalHeight
-       
+        
         if  offset.y > 251 + kSafeTabBarHeight {
             
             let indexPath = tableView.indexPathForRow(at: offset)
             if indexPath != nil {
                 var rect = tableView.rect(forSection: (indexPath?.section)!)
+                
                 if rect.size.height + kNavBarTotalHeight - tableView.frame.size.height < 0 {
+                    
                     rect.size.height = tableView.frame.size.height - kNavBarTotalHeight - rect.size.height
+                    
                     tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: rect.size.height, right: 0)
                 }
+                
                 if indexPath!.section % 2 == 0  {
                     NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ProductDetailViewSection"), object: indexPath!.section)
-
+                    
                 }
             }
         }

+ 22 - 26
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/ProductDetailSkuView/ProductDetailSkuView.swift

@@ -11,16 +11,29 @@ import FWPopupView
 import RxSwift
 import RxCocoa
 
+enum ProductDetailSkuViewType {
+    case selectSku
+    case addCart
+    case buyNow
+}
+
 class ProductDetailSkuView: FWPopupView {
-   
+    
     let disposeBag = DisposeBag()
+    
+    typealias SureClosure = (ProductDetailSkuViewType,ProductDetailSkuModel) -> Void
+    var sureClosure: SureClosure?
+    
     override init(frame: CGRect) {
         super.init(frame: frame)
+        setupViews()
+        setupLayouts()
     }
     
     required init?(coder aDecoder: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
+
     
     private func setupViews() {
        
@@ -315,23 +328,26 @@ class ProductDetailSkuView: FWPopupView {
         sureButton.setTitle("确  认", for: UIControl.State.normal)
         sureButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
         sureButton.setTitleColor(k666666Color, for: UIControl.State.disabled)
-
         sureButton.titleLabel?.font = kRegularFont16
+        sureButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if let sureClosure = self?.sureClosure {
+               self?.productDetailSkuModel?.productCount = self?.productCount
+                sureClosure((self?.productDetailSkuViewType)!,(self?.productDetailSkuModel)!)
+            }
+        }).disposed(by: disposeBag)
         return sureButton
     }()
     
     var skuModelMainkey = ""
     var skuIdArray : Array<String>?
     var productCount : Int = 1
+    var filter : ORSKUDataFilter?
     var productDetailSkuModel : ProductDetailSkuModel?
-    let first = PublishSubject<Int>()
-    let second = PublishSubject<Int>()
+    var productDetailSkuViewType:ProductDetailSkuViewType?
     
     var productDetailModel : ProductDetailModel? {
         didSet {
             filter = ORSKUDataFilter.init(dataSource: self)
-            setupViews()
-            setupLayouts()
             filter!.needDefaultValue = true
             self.collectionView.reloadData()
             actionComplete()
@@ -364,26 +380,6 @@ class ProductDetailSkuView: FWPopupView {
         }
        
     }
-    
-    var selectedIndexPaths = Array<Any>()
-    
-    var filter : ORSKUDataFilter?
-    
-    
-    static func productDetailSkuView(productDetailModel : ProductDetailModel) {
-        let view = ProductDetailSkuView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: kScreenHeight - 76 - kNavBarTotalHeight))
-        view.productDetailModel = productDetailModel
-        let vProperty1 = FWPopupViewProperty()
-        vProperty1.popupCustomAlignment = .bottomCenter
-        vProperty1.popupAnimationType = .frame
-        vProperty1.maskViewColor = UIColor(white: 0, alpha: 0.5)
-        vProperty1.touchWildToHide = "1"
-        vProperty1.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
-        vProperty1.animationDuration = 0.2
-        view.vProperty = vProperty1
-        view.show()
-    }
-    
 
 }
 

+ 35 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/ViewController/ProductDetailViewController.swift

@@ -12,13 +12,17 @@ import JXSegmentedView
 class ProductDetailViewController: BaseViewController {
     
     deinit {
-        NotificationCenter.default.removeObserver(observe!)
+        if observe != nil {
+            NotificationCenter.default.removeObserver(observe!)
+        }
     }
     weak var observe : NSObjectProtocol?
     
     var productModel : ProductModel?
     
     var productSearchModel : ProductSearchModel?
+    
+    var productDetailModel : ProductDetailModel?
 
     override func viewDidLoad() {
         super.viewDidLoad()
@@ -51,6 +55,7 @@ class ProductDetailViewController: BaseViewController {
             self?.productDetailApi()
             self?.productListApi()
             self?.productCommentListApi()
+            self?.productGetCartCountApi()
         }
         
         observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ProductDetailView"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
@@ -63,6 +68,7 @@ class ProductDetailViewController: BaseViewController {
                 self?.navigationBar.wr_setBackgroundAlpha(alpha: 1)
             }
         }
+        
         observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ProductDetailViewSection"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
             let item = notification.object as! Int
             if item == 0 {
@@ -83,12 +89,19 @@ class ProductDetailViewController: BaseViewController {
             }
             self?.navigationController?.pushViewController(vc, animated: true)
         }
+        productDetailView.addCartClosure = {
+            [weak self] (productDetailSkuModel) in
+            self?.productDetailAddCartApi(productDetailSkuModel: productDetailSkuModel)
+        }
     }
     
+    
+    /// 获取商品详情
     private func productDetailApi() {
         if self.productModel != nil {
             SwiftMoyaNetWorkServiceProduct.shared().productDetailApi(id: self.productModel?.id ?? 0) {
                 [weak self] (productDetailModel) -> (Void) in
+                self?.productDetailModel = productDetailModel as? ProductDetailModel
                 self?.productDetailView.productDetailModel = productDetailModel as? ProductDetailModel
             }
         }
@@ -96,10 +109,10 @@ class ProductDetailViewController: BaseViewController {
         if self.productSearchModel != nil {
             SwiftMoyaNetWorkServiceProduct.shared().productDetailApi(id: self.productSearchModel?.id ?? 0) {
                 [weak self] (productDetailModel) -> (Void) in
+                self?.productDetailModel = productDetailModel as? ProductDetailModel
                 self?.productDetailView.productDetailModel = productDetailModel as? ProductDetailModel
             }
         }
-        
     }
     
     /// 获取商家商品列表
@@ -124,6 +137,8 @@ class ProductDetailViewController: BaseViewController {
        
     }
     
+    
+    /// 获取评价列表
     func productCommentListApi() {
         if self.productModel != nil {
             SwiftMoyaNetWorkServiceProduct.shared().productCommentListApi(productId: productModel?.id ?? 0) {
@@ -144,6 +159,24 @@ class ProductDetailViewController: BaseViewController {
     }
     
     
+    /// 加入购物车
+    ///
+    /// - Parameter productDetailSkuModel: 选中的sku
+    func productDetailAddCartApi(productDetailSkuModel:ProductDetailSkuModel) {
+        SwiftMoyaNetWorkServiceProduct.shared().productDetailAddCartApi(productDetailModel: self.productDetailModel!, productDetailSkuModel: productDetailSkuModel) {
+            [weak self] (cartAmountModel) -> (Void) in
+            self?.productGetCartCountApi()
+        }
+    }
+    
+    /// 获取购物车数量
+    func productGetCartCountApi() {
+        SwiftMoyaNetWorkServiceProduct.shared().productGetCartCountApi {
+            [weak self] (productCartCountModel) -> (Void) in
+            self?.productDetailView.productCartCountModel = productCartCountModel as? ProductCartCountModel
+        }
+    }
+    
     lazy var productDetailView: ProductDetailView = {
         let productDetailView = ProductDetailView()
         return productDetailView

+ 8 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallBanner/ShoppingMallBannerTableViewCell.swift

@@ -25,7 +25,9 @@ class ShoppingMallBannerTableViewCell: UITableViewCell {
     
     var cmsRuleModels : Array<CMSRuleModel>? {
         didSet {
-            pagerView.reloadData()
+            if !(cmsRuleModels?.isEmpty ?? true) {
+                pagerView.reloadData()
+            }
         }
     }
     
@@ -81,7 +83,11 @@ class ShoppingMallBannerTableViewCell: UITableViewCell {
 
 extension ShoppingMallBannerTableViewCell:FSPagerViewDataSource,FSPagerViewDelegate {
     func numberOfItems(in pagerView: FSPagerView) -> Int {
-        return 1
+        if !(cmsRuleModels?.isEmpty ?? true) {
+            return 1
+        }else {
+            return 0
+        }
     }
     func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
         let cell  = ShoppingMallBannerFSPagerViewCell.cellWith(collectionView: pagerView, index: index)

+ 10 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallListView.swift

@@ -98,11 +98,19 @@ extension ShoppingMallListView : UITableViewDelegate, UITableViewDataSource {
         
         switch cmsSectionModel?.areaType {
         case "banner":
-           return (160 * kScaleWidth)
+            if !(cmsSectionModel?.rule?.isEmpty ?? true) {
+                return (160 * kScaleWidth)
+            }else {
+                return 0
+            }
         case "category":
             return  UITableView.automaticDimension
         case "special":
-            return  (193 * kScaleWidth)
+            if !(cmsSectionModel?.rule?.isEmpty ?? true) {
+                return  (193 * kScaleWidth)
+            }else {
+                return 0
+            }
         case "floor":
             return  UITableView.automaticDimension
         default:

+ 27 - 0
RainbowPlanet/RainbowPlanet/Service/Model/ProductModel/ProductCartCountModel.swift

@@ -0,0 +1,27 @@
+//
+//  ProductCartCountModel.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/5/18.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+import ObjectMapper
+
+
+class ProductCartCountModel : NSObject, Mappable{
+    
+    var count : Int?
+    
+    class func newInstance(map: Map) -> Mappable?{
+        return ProductCartCountModel()
+    }
+    required init?(map: Map){}
+    private override init(){}
+    
+    func mapping(map: Map)
+    {
+        count <- map["count"]
+    }
+}

+ 0 - 2
RainbowPlanet/RainbowPlanet/Service/Model/ProductModel/ProductCommentListModel.swift

@@ -69,8 +69,6 @@ class ProductCommentModel : NSObject, Mappable{
         skuName <- map["sku_name"]
         star <- map["star"]
         username <- map["username"]
-        
     }
-    
 }
 

+ 2 - 0
RainbowPlanet/RainbowPlanet/Service/Model/ProductModel/ProductDetailModel.swift

@@ -153,6 +153,8 @@ class ProductDetailSkuModel : NSObject, Mappable{
     var price : Int?
     var skuName : String?
     var stock : Int?
+    var productCount : Int?
+    
     
     
     class func newInstance(map: Map) -> Mappable?{

+ 59 - 1
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaNetWorkServiceProduct.swift

@@ -268,6 +268,43 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
         }
     }
     
+    // MARK: - 商品详情-添加购物车
+    /// 购物车店铺-添加
+    ///
+    /// - Parameters:
+    ///   - productMdl: 商品Model
+    ///   - completion: 回调
+    func productDetailAddCartApi(productDetailModel:ProductDetailModel,productDetailSkuModel:ProductDetailSkuModel, completion: @escaping apiCallBack) {
+        var parameters = Dictionary<String,Any>()
+        
+        parameters.updateValue(productDetailModel.shopId ?? "", forKey: "shop_id")
+        parameters.updateValue(productDetailModel.shopName ?? "", forKey: "shop_name")
+        parameters.updateValue(productDetailModel.id ?? "", forKey: "product_id")
+        parameters.updateValue(productDetailSkuModel.price ?? "", forKey: "product_price")
+        parameters.updateValue(productDetailSkuModel.id ?? "", forKey: "sku_id")
+        parameters.updateValue(productDetailModel.totalCount ?? "", forKey: "amount")
+        parameters.updateValue(1, forKey: "is_select")
+        parameters.updateValue(productDetailModel.name ?? "", forKey: "product_name")
+        parameters.updateValue(productDetailModel.img  ?? "", forKey: "product_img")
+        parameters.updateValue(productDetailSkuModel.skuName  ?? "", forKey: "sku_name")
+        
+        // 本地获取city_id/city_name
+        let loacationModel = LocationModel.shared().getLocationModel()
+        let baiduToCityModel = BaiduToCityFactory.shared.query(bjcityId: loacationModel!.cityCode)
+        parameters.updateValue(baiduToCityModel.areaCode, forKey: "city_id")
+        parameters.updateValue(baiduToCityModel.areaName, forKey: "city_name")
+        
+        // 本地获取deliver_type
+        let deliver_type = DeliveryMethodTypeModel.shared().getModel()?.deliveryMethodType
+        parameters.updateValue(deliver_type ?? 0, forKey: "deliver_type")
+        
+        SwiftProgressHUD.shared().showWait()
+        SwiftMoyaNetWorkManager.shared().request(CartAmountModel.self,target: MultiTarget(SwiftMoyaServiceProductApi.productCartAdd(parameters: parameters))) { (cartAmountModel) in
+            SwiftProgressHUD.shared().hide()
+            completion(cartAmountModel)
+        }
+    }
+    
     
     // MARK: - 购物车-删除
     /// 购物车-删除
@@ -363,7 +400,7 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
     /// - Parameters:    
     ///   - completion: 回调
     func productRefundReasonApi(completion: @escaping apiCallBack) {
-        var parameters = Dictionary<String,Any>()                        
+        let parameters = Dictionary<String,Any>()
         SwiftProgressHUD.shared().showWait()
         SwiftMoyaNetWorkManager.shared().request(ProductRefundReasonModel.self, target: MultiTarget(SwiftMoyaServiceProductApi.productRefundReason(parameters: parameters))) { (refundReasonModel) in
             SwiftProgressHUD.shared().hide()
@@ -371,4 +408,25 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
         }
     }
     
+    // MARK: - 获取购物车商品个数
+    /// 获取购物车商品个数
+    ///
+    /// - Parameters:
+    ///   - completion: 回调
+    func productGetCartCountApi(completion: @escaping apiCallBack) {
+        var parameters = Dictionary<String,Any>()
+        SwiftProgressHUD.shared().showWait()
+        // 本地获取city_id
+        let loacationModel = LocationModel.shared().getLocationModel()
+        let baiduToCityModel = BaiduToCityFactory.shared.query(bjcityId: loacationModel!.cityCode)
+        parameters.updateValue(baiduToCityModel.areaCode, forKey: "city_id")
+        // 本地获取deliver_type
+        let deliver_type = DeliveryMethodTypeModel.shared().getModel()?.deliveryMethodType
+        parameters.updateValue(deliver_type ?? "2", forKey: "deliver_type")
+        SwiftMoyaNetWorkManager.shared().request(ProductCartCountModel.self, target: MultiTarget(SwiftMoyaServiceProductApi.productGetCartCount(parameters: parameters))) { (productCartCountModel) in
+            SwiftProgressHUD.shared().hide()
+            completion(productCartCountModel)
+        }
+    }
+    
 }

+ 15 - 4
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaServiceProductApi.swift

@@ -65,6 +65,9 @@ public let kProductRefundReasonApi = "/product/config"
 /// 新增商品评价
 public let kProductAddCommentApi = "/product/commentCreate"
 
+// MARK: - 获取购物车商品个数
+/// 获取购物车商品个数
+public let kProductGetCartCountApi = "/product/getCartCount"
 
 /// 商品
 ///
@@ -82,6 +85,7 @@ public let kProductAddCommentApi = "/product/commentCreate"
 /// - productCartAllSel: 购物车-全选
 /// - productRefundReason: 退款原因
 /// - productAddComment: 新增商品评价
+/// - productGetCartCount: 获取购物车商品个数
 public enum SwiftMoyaServiceProductApi {
     case productSearch(parameters:Dictionary<String, Any>)
     case productCategory(parameters:Dictionary<String, Any>)
@@ -97,6 +101,7 @@ public enum SwiftMoyaServiceProductApi {
     case productCartAllSel(parameters:Dictionary<String, Any>)
     case productRefundReason(parameters:Dictionary<String, Any>)
     case productAddComment(parameters:Dictionary<String, Any>)
+    case productGetCartCount(parameters:Dictionary<String, Any>)
 }
 
 extension SwiftMoyaServiceProductApi: TargetType {
@@ -116,7 +121,8 @@ extension SwiftMoyaServiceProductApi: TargetType {
              .productCartIsSel,
              .productCartAllSel,
              .productRefundReason,
-             .productAddComment
+             .productAddComment,
+             .productGetCartCount
             :
             return URL(string: kApiDataPrefix())!
         }
@@ -152,6 +158,8 @@ extension SwiftMoyaServiceProductApi: TargetType {
             return kProductRefundReasonApi
         case .productAddComment:
             return kProductAddCommentApi
+        case .productGetCartCount:
+            return kProductGetCartCountApi
         }
     }
     
@@ -173,7 +181,8 @@ extension SwiftMoyaServiceProductApi: TargetType {
              .productDetail,
              .productCommentList,
              .productHotSale,
-             .productRefundReason
+             .productRefundReason,
+             .productGetCartCount
             :
             return .get
         case .productCartDelete
@@ -198,7 +207,8 @@ extension SwiftMoyaServiceProductApi: TargetType {
              .productCartIsSel(var parameters),
              .productCartAllSel(var parameters),
              .productRefundReason(var parameters),
-             .productAddComment(var parameters)
+             .productAddComment(var parameters),
+             .productGetCartCount(var parameters)
             :
             let sign = SwiftSign.shared().sign(signType:.AccessToken, parameters: parameters)
             parameters.updateValue(sign, forKey: "sign")
@@ -234,7 +244,8 @@ extension SwiftMoyaServiceProductApi: TargetType {
              .productCartIsSel,
              .productCartAllSel,
              .productRefundReason,
-             .productAddComment
+             .productAddComment,
+             .productGetCartCount
             :
             return (headerParameters(headerType: .tokenHeader) as! [String : String])
         }