Просмотр исходного кода

Merge branch 'feature/liuxuqing' into develop

# Conflicts:
#	彩虹星球1期遗留问题.xmind
Chris лет назад: 6
Родитель
Сommit
74d7e1769c

+ 6 - 5
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartList/ShoppingCartListTableViewHeader.swift

@@ -15,6 +15,9 @@ class ShoppingCartListTableViewHeader: BaseView {
     typealias SecSelectBlock = (_ isSecSelected: Int) -> Void
     var secSelectBlock : SecSelectBlock?
     
+    typealias ShopClickedBlock = () -> Void
+    var shopClickedBlock : ShopClickedBlock?
+    
     var shopName : String? {
         didSet {
             titleButton.setTitle(shopName, for: UIControl.State.normal)
@@ -123,11 +126,9 @@ class ShoppingCartListTableViewHeader: BaseView {
         titleButton.setTitleColor(k333333Color, 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("点击了商店Title")
+            if let shopClickedBlock = self?.shopClickedBlock {
+                shopClickedBlock()
+            }
             
         }).disposed(by: disposeBag)
         return titleButton

+ 35 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -45,6 +45,10 @@ class ShoppingCartView: BaseView {
     typealias RefreshTransBlock = () -> Void
     var refreshTransBlock : RefreshTransBlock?
     
+    // 点击店铺跳转--次级block
+    typealias ShopClickedTransBlock = (_ shopId: Int) -> Void
+    var shopClickedTransBlock : ShopClickedTransBlock?
+    
     override func setupViews() {
         self.backgroundColor = kf7f8faColor
         addSubview(accountView)
@@ -80,7 +84,6 @@ class ShoppingCartView: BaseView {
             }
             tableView.snp.remakeConstraints { (make) in
                 make.edges.equalToSuperview()
-//                make.bottom.equalTo(accountView.snp_top).offset(0)
             }
         } else {
             accountView.isHidden = false
@@ -186,6 +189,31 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
                 
                 cell.changeProductBlock = { [weak self]
                     (productId, type) in
+                    // 最少只能减到1件商品
+                    let curAmount = self?.cartListModelArr![indexPath.section].productList![indexPath.row].amount
+                    if type == 2 && curAmount == 1 {
+                        AlertSheetView.alert(title: "确认删除商品", cancelTitle: "取消", sureTitle: "确认", cancelBlock: { (popupView, index, string) in
+                            
+                        }, confirmBlock: {
+                            [weak self] (popupView, index, string) in
+                            // 删除商品
+                            let productId = self?.cartListModelArr![indexPath.section].productList?[indexPath.row].id
+                            SwiftMoyaNetWorkServiceProduct.shared().productCartDeleteApi(id: productId ?? 0) { [weak self] (data) -> (Void) in
+                                self?.cartListModelArr![indexPath.section].productList?.remove(at: indexPath.row)
+                                tableView.deleteRows(at: [indexPath], with: .none)
+                                
+                                // 删除后商店为空,刷新table
+                                if self?.cartListModelArr![indexPath.section].productList?.isEmpty ?? true {
+                                    self?.cartListModelArr?.remove(at: indexPath.section)
+                                    tableView.reloadData()
+                                }
+                            }
+                        })
+                        
+                        return
+                    }
+                   
+                    // 更改数量Api
                     SwiftMoyaNetWorkServiceProduct.shared().productCartAmountApi(id: productId, type: type, completion: { [weak self] (amountData) -> (Void) in
                         // 1.更新数据源
                         let cartAmountMdl = amountData as? CartAmountModel
@@ -259,6 +287,12 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
 //                self?.judgeAllSelectedStatus()
 //                self?.refreshAccountView()
             }
+            headerView.shopClickedBlock = {
+                [weak self] in
+                if let shopClickedTransBlock = self?.shopClickedTransBlock {
+                    shopClickedTransBlock(self!.cartListModelArr![section].shopId ?? 0)
+                }
+            }
             return headerView
             
         } else {

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

@@ -74,6 +74,12 @@ class ShoppingCartViewController: BaseViewController {
             vc.shopId = productModel.shopId
             self?.navigationController?.pushViewController(vc, animated: true)
         }
+        shoppingCartView.shopClickedTransBlock = {
+            [weak self] (shopId) in
+            let vc = ShopViewController()
+            vc.shopId = shopId
+            self?.navigationController?.pushViewController(vc, animated: true)
+        }
     }
     
     private lazy var shoppingCartView: ShoppingCartView = {