Browse Source

no message

南鑫林 6 years ago
parent
commit
5684d3ae1c

+ 53 - 1
RainbowPlanet/RainbowPlanet/Macro/Common.swift

@@ -132,7 +132,7 @@ func delay(by delayTime: TimeInterval, qosClass: DispatchQoS.QoSClass? = nil,
 }
 
 func getCurrentVC() -> UIViewController {
-    let keywindow = (UIApplication.shared.delegate as! AppDelegate).window//UIApplication.shared.keyWindow使用此有时会崩溃
+    let keywindow = (UIApplication.shared.delegate as! AppDelegate).window
     let firstView: UIView = (keywindow?.subviews.first)!
     let secondView: UIView = firstView.subviews.first!
     var vc = viewForController(view: secondView)!
@@ -152,6 +152,58 @@ private func viewForController(view:UIView)->UIViewController?{
     return nil
 }
 
+//classType: 当前页面类类型
+func vcResult(classType: UIViewController.Type) -> Bool {
+    return getCurrentVC().isKind(of: classType)
+}
+
+
+///获取当前显示的控制器 UIWindow (Visible)
+func getCurrentVC2() -> UIViewController {
+    let keywindow = (UIApplication.shared.delegate as! AppDelegate).window?.rootViewController//UIApplication.shared.keyWindow
+    let rootVC = keywindow!//UIApplication.shared.keyWindow!.rootViewController!
+    return getVisibleViewControllerFrom(vc: rootVC)
+}
+
+//方法1
+func getVisibleViewControllerFrom(vc: UIViewController) -> UIViewController {
+    
+    if vc.isKind(of: UINavigationController.self) {
+        return getVisibleViewControllerFrom(vc: (vc as! UINavigationController).visibleViewController!)
+    } else if vc.isKind(of: UITabBarController.self) {
+        return getVisibleViewControllerFrom(vc: (vc as! UITabBarController).selectedViewController!)
+    } else {
+        if (vc.presentedViewController != nil) {
+            return getVisibleViewControllerFrom(vc: vc.presentedViewController!)
+        } else {
+            return vc
+        }
+    }
+    
+}
+
+//方法2
+func topViewControllerWithRootViewController(rootVC: UIViewController) -> UIViewController {
+    
+    if rootVC.isKind(of: UITabBarController.self) {
+        let tabVC = rootVC as! UITabBarController
+        return topViewControllerWithRootViewController(rootVC: tabVC.selectedViewController!)
+    } else if rootVC.isKind(of: UINavigationController.self) {
+        let navc = rootVC as! UINavigationController
+        return topViewControllerWithRootViewController(rootVC: navc.visibleViewController!)
+    } else if (rootVC.presentedViewController != nil) {
+        return topViewControllerWithRootViewController(rootVC: rootVC.presentedViewController!)
+    } else {
+        return rootVC
+    }
+    
+}
+
+///验证
+func vcResult2(classType: UIViewController.Type) -> Bool {
+    return getCurrentVC2().isKind(of: classType)
+}
+
 func showSwiftProgressHUDInfo() {
     SwiftProgressHUD.shared().showText("该功能暂未开通,敬请期待!!!")
 }

+ 4 - 4
RainbowPlanet/RainbowPlanet/Modules/CommonModules/SearchModule/SearchResult/ViewController/SearchResultViewController.swift

@@ -60,10 +60,10 @@ class SearchResultViewController: BaseViewController {
         }
         navigationBarView.shoppingCarBlock = {
             [weak self] in
-            self?.dismiss(animated: false, completion: {
-                let tabBarController = kAppDelegate.window?.rootViewController as! BaseTabbarViewController
-                tabBarController.selectedIndex = 1
-            })
+            
+            let vc = ShoppingCartViewController()
+            vc.shoppingCartVCType = .push
+            self?.navigationController?.pushViewController(vc, animated: true)
         }
         
         searchResultView.didSelectRow = {

+ 46 - 6
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -13,6 +13,33 @@ class ShoppingCartView: BaseView {
     typealias ProductDidSelectRowAt = (ProductModel) -> Void
     var productDidSelectRowAt : ProductDidSelectRowAt?
     
+    var shoppingCartVCType : ShoppingCartVCType = .none {
+        didSet{
+            if shoppingCartVCType == .push {
+                accountView.snp.makeConstraints { (make) in
+                    make.left.right.equalToSuperview()
+                    make.height.equalTo(48)
+                    make.bottom.equalTo(-kSafeTabBarHeight)
+                }
+                tableView.snp.makeConstraints { (make) in
+                    make.top.left.right.equalToSuperview()
+                    make.bottom.equalTo(accountView.snp_top).offset(0)
+                }
+            }else {
+                accountView.snp.makeConstraints { (make) in
+                    make.left.right.equalToSuperview()
+                    make.height.equalTo(48)
+                    make.bottom.equalTo(0)
+                }
+                tableView.snp.makeConstraints { (make) in
+                    make.top.left.right.equalToSuperview()
+                    make.bottom.equalTo(accountView.snp_top).offset(0)
+                }
+            }
+        }
+    }
+
+    
     // 购物车列表ModelArr
     var cartListModelArr : Array<CartProductListModel>? {
         didSet {
@@ -74,8 +101,9 @@ class ShoppingCartView: BaseView {
     
     override func setupLayouts() {
         accountView.snp.makeConstraints { (make) in
-            make.left.right.bottom.equalToSuperview()
+            make.left.right.equalToSuperview()
             make.height.equalTo(48)
+            make.bottom.equalTo(0)
         }
         tableView.snp.makeConstraints { (make) in
             make.top.left.right.equalToSuperview()
@@ -85,26 +113,38 @@ class ShoppingCartView: BaseView {
     
     // 处理购物车结算是否显示
     func updateAccountViewCondition() {
+        
         if cartListModelArr?.isEmpty ?? true {
             accountView.isHidden = true
             
             accountView.snp.remakeConstraints { (make) in
-                make.left.right.bottom.equalToSuperview()
+                make.left.right.equalToSuperview()
                 make.height.equalTo(0)
+                if self.shoppingCartVCType == .push {
+                    make.bottom.equalTo(-kSafeTabBarHeight)
+                }else {
+                    make.bottom.equalTo(0)
+                }
             }
             tableView.snp.remakeConstraints { (make) in
-                make.edges.equalToSuperview()
+                make.top.right.left.equalToSuperview()
+                make.bottom.equalTo(accountView.snp_top)
             }
         } else {
             accountView.isHidden = false
             
             accountView.snp.remakeConstraints { (make) in
-                make.left.right.bottom.equalToSuperview()
+                make.left.right.equalToSuperview()
                 make.height.equalTo(48)
+                if self.shoppingCartVCType == .push {
+                    make.bottom.equalTo(-kSafeTabBarHeight)
+                }else {
+                    make.bottom.equalTo(0)
+                }
             }
             tableView.snp.remakeConstraints { (make) in
-                make.top.left.right.equalToSuperview()
-                make.bottom.equalTo(accountView.snp_top).offset(0)
+                make.top.right.left.equalToSuperview()
+                make.bottom.equalTo(accountView.snp_top)
             }
         }
     }

+ 12 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/ViewController/ShoppingCartViewController.swift

@@ -9,6 +9,16 @@
 import UIKit
 import RxSwift
 
+
+/// 跳转方式
+///
+/// - none: 默认
+/// - push: push
+enum ShoppingCartVCType{
+    case none
+    case push
+}
+
 class ShoppingCartViewController: BaseViewController {
     
     weak var observe : NSObjectProtocol?
@@ -17,6 +27,7 @@ class ShoppingCartViewController: BaseViewController {
     }
     
     var productSearchModelArray = Array<ProductSearchModel>()
+    var shoppingCartVCType : ShoppingCartVCType = .none
     
     override func viewDidLoad() {
         super.viewDidLoad()
@@ -48,6 +59,7 @@ class ShoppingCartViewController: BaseViewController {
     
     override func setupData() {
         shoppingCartView.tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) { [weak self] (page) in
+            self?.shoppingCartView.shoppingCartVCType = self?.shoppingCartVCType ?? .none
             self?.productCartListApi()
             self?.productHotSaleApi(page: page)
         }

+ 3 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/Category/ViewController/CategoryViewController.swift

@@ -54,9 +54,10 @@ class CategoryViewController: BaseViewController {
         }).disposed(by: disposeBag)
         categorySearchView.shoppingCarBlock = {
             [weak self] in
-            self?.tabBarController?.selectedIndex = 1
-            self?.navigationController?.popToRootViewController(animated: false)
             
+            let vc = ShoppingCartViewController()
+            vc.shoppingCartVCType = .push
+            self?.navigationController?.pushViewController(vc, animated: true)
         }
         
         categoryView.leftTableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) {

+ 9 - 4
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/ProductDetailView.swift

@@ -21,6 +21,9 @@ class ProductDetailView: BaseView {
     typealias BuyNowClosure = (ProductDetailSkuModel) -> Void
     var buyNowClosure : BuyNowClosure?
     
+    typealias CartButtonClosure = () -> Void
+    var cartButtonClosure : CartButtonClosure?
+    
     var productDetailSkuModel : ProductDetailSkuModel?
     
     var titles = ["","","商品评价","","热销排行","商品参数","商品详情"]
@@ -160,10 +163,12 @@ class ProductDetailView: BaseView {
     
     private lazy var cartButton : UIButton = {
         let cartButton = UIButton()
-        cartButton.rx.tap.subscribe(onNext: { (data) in
-           
-            getCurrentVC().navigationController?.popToRootViewController(animated: false)
-            getCurrentVC().tabBarController?.selectedIndex = 1
+        cartButton.rx.tap.subscribe(onNext: {
+            [weak self] (data) in
+            
+            if let cartButtonClosure = self?.cartButtonClosure {
+                cartButtonClosure()
+            }
 
         }).disposed(by: disposeBag)
         return cartButton

+ 6 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/ViewController/ProductDetailViewController.swift

@@ -117,6 +117,12 @@ class ProductDetailViewController: BaseViewController {
             vc.totalProductPrice = (productDetailSkuModel.price ?? 0) * (productDetailSkuModel.productCount ?? 0)
             self?.navigationController?.pushViewController(vc, animated: true)
         }
+        productDetailView.cartButtonClosure = {
+            [weak self] in
+            let vc = ShoppingCartViewController()
+            vc.shoppingCartVCType = .push
+            self?.navigationController?.pushViewController(vc, animated: true)
+        }
     }
     
     

+ 2 - 81
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductView/CollectionViewCell/ProductMallBarChart/ProductMallBarChartCollectionViewCell.swift

@@ -18,9 +18,7 @@ class ProductMallBarChartCollectionViewCell: UICollectionViewCell {
     
     typealias PlusClosure = (_ productModel: ProductModel?,_ indexPath:IndexPath?) -> Void
     var plusClosure : PlusClosure?
-    
-    typealias ReduceClosure = (_ productModel: ProductModel?,_ indexPath:IndexPath?) -> Void
-    var reduceClosure : ReduceClosure?
+
     
     class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> ProductMallBarChartCollectionViewCell {
         let ID = "ProductMallBarChartCollectionViewCell"
@@ -60,9 +58,6 @@ class ProductMallBarChartCollectionViewCell: UICollectionViewCell {
         addSubview(sellPriceLabel)
         addSubview(markPriceLabel)
         addSubview(plusButton)
-        addSubview(numberLabel)
-        addSubview(reduceButton)
-        addSubview(shopingCarButton)
     }
     
     private func setupLayouts() {
@@ -102,24 +97,6 @@ class ProductMallBarChartCollectionViewCell: UICollectionViewCell {
             make.size.equalTo(25)
         }
         
-        numberLabel.snp.makeConstraints { (make) in
-            make.top.bottom.equalTo(plusButton)
-            make.right.equalTo(plusButton.snp.left)
-            make.width.greaterThanOrEqualTo(50)
-        }
-        
-        reduceButton.snp.makeConstraints { (make) in
-            make.right.equalTo(numberLabel.snp.left)
-            make.top.width.bottom.equalTo(plusButton)
-        }
-        
-        shopingCarButton.snp.makeConstraints { (make) in
-            make.right.equalTo(-10)
-            make.bottom.equalTo(-10)
-            make.width.equalTo(100)
-            make.height.equalTo(31)
-        }
-        
     }
     
     private lazy var iconImagView: UIImageView = {
@@ -199,48 +176,6 @@ class ProductMallBarChartCollectionViewCell: UICollectionViewCell {
         return plusButton
     }()
     
-    private lazy var numberLabel: UILabel = {
-        let numberLabel = UILabel()
-        numberLabel.textAlignment = .center
-        numberLabel.font = kRegularFont14
-        numberLabel.textColor = k333333Color
-        numberLabel.isHidden = true
-        return numberLabel
-    }()
-    
-    private lazy var reduceButton: UIButton = {
-        let reduceButton = UIButton(type: UIButton.ButtonType.custom)
-        reduceButton.setImage(kImage(name: "home_btn_buy_subtract"), for: UIControl.State.normal)
-        reduceButton.isHidden = true
-        reduceButton.rx.tap.subscribe(onNext: {
-            [weak self] (data) in
-            if let reduceClosure = self?.reduceClosure {
-                reduceClosure(self?.productModel, self?.indexPath)
-            }
-        }).disposed(by: disposeBag)
-        return reduceButton
-    }()
-    
-
-    private lazy var shopingCarButton: UIButton = {
-        let shopingCarButton = UIButton(type: UIButton.ButtonType.custom)
-        shopingCarButton.setTitle("加入购物车", for: UIControl.State.normal)
-        shopingCarButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
-        shopingCarButton.titleLabel?.font = kMediumFont14
-        shopingCarButton.backgroundColor = kFFAC33Color
-        shopingCarButton.cornerRadius = 31/2
-        shopingCarButton.masksToBounds = true
-        shopingCarButton.isHidden = true
-        shopingCarButton.rx.tap.subscribe(onNext: {
-            [weak self] (data) in
-            if let shopingCarClosure = self?.shopingCarClosure {
-                shopingCarClosure(self?.productModel, self?.indexPath)
-            }
-        }).disposed(by: disposeBag)
-        return shopingCarButton
-    }()
-    
-    
     var productModel : ProductModel? {
         didSet {
             iconImagView.kf.setImage(with: kURLImage(name: productModel?.img ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
@@ -252,23 +187,9 @@ class ProductMallBarChartCollectionViewCell: UICollectionViewCell {
             attributeString.changeStrikethrough(atAllStyle: NSUnderlineStyle.single, color: kbbbbbbColor)
            
             if productModel?.totalStock == 0 {
-                reduceButton.isHidden = true
-                numberLabel.isHidden = true
                 plusButton.isHidden = true
-                shopingCarButton.isHidden = true
             }else {
-                if productModel?.amount == 0 || productModel?.amount == nil  {
-                    reduceButton.isHidden = true
-                    numberLabel.isHidden = true
-                    plusButton.isHidden = true
-                    shopingCarButton.isHidden = false
-                }else {
-                    reduceButton.isHidden = false
-                    numberLabel.isHidden = false
-                    plusButton.isHidden = false
-                    shopingCarButton.isHidden = true
-                    numberLabel.text =  "\(productModel?.amount ?? 1)"
-                }
+                plusButton.isHidden = false
             }
 
         }

+ 19 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/Shop/ViewController/ShopViewController.swift

@@ -30,8 +30,9 @@ class ShopViewController: BaseViewController {
         navigationBar.wr_setRightButton(image: kImage(name: "navbar_shopping_white")!)
         navigationBar.onClickRightButton = {
             [weak self] in
-            self?.tabBarController?.selectedIndex = 1
-            self?.navigationController?.popToRootViewController(animated: false)
+            let vc = ShoppingCartViewController()
+            vc.shoppingCartVCType = .push
+            self?.navigationController?.pushViewController(vc, animated: true)
         }
         view.addSubview(shopView)
     }
@@ -44,6 +45,9 @@ class ShopViewController: BaseViewController {
     }
     
     override func setupData() {
+        
+        productGetCartCountApi()
+        
         shopView.tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) { [weak self] (page) in
              self?.shopViewApi()
              self?.productListApi(page: page)
@@ -106,5 +110,18 @@ class ShopViewController: BaseViewController {
             }
         }
     }
+    
+    /// 获取购物车数量
+    private func productGetCartCountApi() {
+        SwiftMoyaNetWorkServiceProduct.shared().productGetCartCountApi {
+            [weak self] (productCartCountModel) -> (Void) in
+            let productCartCountModel = productCartCountModel as!  ProductCartCountModel
+            if productCartCountModel.count != 0 {
+                self?.navigationBar.rightButton.pp.addBadge(number: productCartCountModel.count ?? 0)
+            }else {
+                self?.navigationBar.rightButton.pp.badgeView.isHidden = true
+            }
+        }
+    }
 
 }

+ 1 - 9
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallFloor/Floor/ShoppingMallFloorTableViewCell.swift

@@ -194,17 +194,9 @@ extension ShoppingMallFloorTableViewCell: UICollectionViewDelegateFlowLayout,UIC
                 let productModels = productModelsArrays![indexPath.section]
                 cell.productModel = productModels[indexPath.row]
             }
-            cell.shopingCarClosure = {
-                [weak self] (productModel,indexPath) in
-                self?.addCart(productModel: productModel!, indexPath: indexPath!)
-            }
             cell.plusClosure = {
                 [weak self] (productModel,indexPath) in
-                self?.setProductAmount(type: 1, productModel: productModel!, indexPath: indexPath!)
-            }
-            cell.reduceClosure = {
-                [weak self] (productModel,indexPath) in
-                self?.setProductAmount(type: 2, productModel: productModel!, indexPath: indexPath!)
+                self?.addCart(productModel: productModel!, indexPath: indexPath!)
             }
             return cell
         case 2: //  2:左右滑动

+ 0 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/ViewController/ShoppingMallListViewController.swift

@@ -26,7 +26,6 @@ class ShoppingMallListViewController: UIViewController {
                 [weak self] (page) in
             self?.cmsTemplateSetPreviewApi()
         }
-        
     }
     func setupView() {
         view.backgroundColor = kf7f8faColor

+ 1 - 0
RainbowPlanet/RainbowPlanet/Tools/PhotoAndCameraManager/PhotoAndCameraManager.swift

@@ -54,6 +54,7 @@ class PhotoAndCameraManager: NSObject {
                 picker.sourceType = UIImagePickerController.SourceType.camera
                 picker.delegate = strongSelf;
                 picker.allowsEditing = strongSelf.isEditedImage
+                
                 getCurrentVC().present(picker, animated: true, completion: nil)
             } else {
                 LBXPermissions.jumpToSystemPrivacySetting()