Quellcode durchsuchen

购物车 -- 删除商品 && 流程跳转

Chris vor 6 Jahren
Ursprung
Commit
b6cade5f30

+ 6 - 4
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartAccountView.swift

@@ -12,6 +12,9 @@ import RxCocoa
 
 
 class ShoppingCartAccountView: BaseView {
 class ShoppingCartAccountView: BaseView {
     
     
+    typealias OrderPayBlock = () -> Void
+    var orderPayBlock : OrderPayBlock?
+    
     override func setupViews() {
     override func setupViews() {
         self.backgroundColor = kffffffColor
         self.backgroundColor = kffffffColor
         addSubview(allSelectBtn)
         addSubview(allSelectBtn)
@@ -76,10 +79,9 @@ class ShoppingCartAccountView: BaseView {
         accountBtn.cornerRadius = 18
         accountBtn.cornerRadius = 18
         accountBtn.masksToBounds = true
         accountBtn.masksToBounds = true
         accountBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
         accountBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
-//            if let forgetPasswordBlock = self?.forgetPasswordBlock {
-//                forgetPasswordBlock()
-//            }
-            print("点击了结算")
+            if let orderPayBlock = self?.orderPayBlock {
+                orderPayBlock()
+            }
         }).disposed(by: disposeBag)
         }).disposed(by: disposeBag)
         return accountBtn
         return accountBtn
     }()
     }()

+ 28 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -20,11 +20,14 @@ class ShoppingCartView: BaseView {
     // 热销ModelArr
     // 热销ModelArr
     var hotSaleModelArr : Array<ProductSearchModel>? {
     var hotSaleModelArr : Array<ProductSearchModel>? {
         didSet {
         didSet {
-            //FIXME:刷新指定section
-            tableView.reloadData()
+            let sectionIdx = cartListModelArr?.count ?? 1
+            self.tableView.reloadSections([sectionIdx], with: UITableView.RowAnimation.none)
         }
         }
     }
     }
     
     
+    typealias OrderPayTransBlock = () -> Void
+    var orderPayTransBlock : OrderPayTransBlock?
+    
     override func setupViews() {
     override func setupViews() {
         self.backgroundColor = kf7f8faColor
         self.backgroundColor = kf7f8faColor
         addSubview(accountView)
         addSubview(accountView)
@@ -48,6 +51,14 @@ class ShoppingCartView: BaseView {
     
     
     lazy var accountView: ShoppingCartAccountView = {
     lazy var accountView: ShoppingCartAccountView = {
         let accountView = ShoppingCartAccountView()
         let accountView = ShoppingCartAccountView()
+        
+        accountView.orderPayBlock = {
+            [weak self] in
+            if let orderPayTransBlock = self?.orderPayTransBlock {
+                orderPayTransBlock()
+            }
+        }
+        
         return accountView
         return accountView
     }()
     }()
     
     
@@ -149,4 +160,19 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
         return nil
         return nil
     }
     }
     
     
+    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
+        
+        if editingStyle == .delete {
+            // 删除商品
+            let productId = 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)
+            }
+        }
+    }
+    
+    func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
+        return "删除"
+    }
 }
 }

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

@@ -65,6 +65,11 @@ class ShoppingCartViewController: BaseViewController {
     
     
     private lazy var shoppingCartView: ShoppingCartView = {
     private lazy var shoppingCartView: ShoppingCartView = {
         let shoppingCartView = ShoppingCartView()
         let shoppingCartView = ShoppingCartView()
+        shoppingCartView.orderPayTransBlock = {
+            [weak self] in
+            let vc = ShoppingCartPayOrderController()
+            self?.navigationController?.pushViewController(vc, animated: true)
+        }
         return shoppingCartView
         return shoppingCartView
     }()
     }()
     
     

+ 6 - 4
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/View/OrderPayAcountView.swift

@@ -12,6 +12,9 @@ import RxCocoa
 
 
 class OrderPayAcountView: BaseView {
 class OrderPayAcountView: BaseView {
     
     
+    typealias CommitOrderBlock = () -> Void
+    var commitOrderBlock : CommitOrderBlock?
+    
     override func setupViews() {
     override func setupViews() {
         self.backgroundColor = kffffffColor
         self.backgroundColor = kffffffColor
         addSubview(accountBtn)
         addSubview(accountBtn)
@@ -49,10 +52,9 @@ class OrderPayAcountView: BaseView {
         accountBtn.cornerRadius = 18
         accountBtn.cornerRadius = 18
         accountBtn.masksToBounds = true
         accountBtn.masksToBounds = true
         accountBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
         accountBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
-            //            if let forgetPasswordBlock = self?.forgetPasswordBlock {
-            //                forgetPasswordBlock()
-            //            }
-            print("点击了提交订单")
+            if let commitOrderBlock = self?.commitOrderBlock {
+                commitOrderBlock()
+            }
         }).disposed(by: disposeBag)
         }).disposed(by: disposeBag)
         return accountBtn
         return accountBtn
     }()
     }()

+ 9 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/View/ShoppingCartOrderPayView.swift

@@ -10,6 +10,9 @@ import UIKit
 
 
 class ShoppingCartOrderPayView: BaseView {
 class ShoppingCartOrderPayView: BaseView {
     
     
+    typealias CommitOrderTransBlock = () -> Void
+    var commitOrderTransBlock : CommitOrderTransBlock?
+    
     override func setupViews() {
     override func setupViews() {
         self.backgroundColor = kf7f8faColor
         self.backgroundColor = kf7f8faColor
         addSubview(accountView)
         addSubview(accountView)
@@ -34,6 +37,12 @@ class ShoppingCartOrderPayView: BaseView {
     
     
     lazy var accountView: OrderPayAcountView = {
     lazy var accountView: OrderPayAcountView = {
         let accountView = OrderPayAcountView()
         let accountView = OrderPayAcountView()
+        accountView.commitOrderBlock = {
+            [weak self] in
+            if let commitOrderTransBlock = self?.commitOrderTransBlock {
+                commitOrderTransBlock()
+            }
+        }
         return accountView
         return accountView
     }()
     }()
     
     

+ 7 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/ViewController/ShoppingCartPayOrderController.swift

@@ -47,6 +47,13 @@ class ShoppingCartPayOrderController: BaseViewController {
     
     
     private lazy var orderPayView: ShoppingCartOrderPayView = {
     private lazy var orderPayView: ShoppingCartOrderPayView = {
         let orderPayView = ShoppingCartOrderPayView()
         let orderPayView = ShoppingCartOrderPayView()
+        orderPayView.commitOrderTransBlock = {
+            [weak self] in
+            // 支付弹窗调用
+            AlertSheetView.payAlertSheetView {
+                
+            }
+        }
         return orderPayView
         return orderPayView
     }()
     }()