Chris преди 5 години
родител
ревизия
afcea9ee65
променени са 1 файла, в които са добавени 21 реда и са изтрити 31 реда
  1. 21 31
      RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

+ 21 - 31
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -269,22 +269,7 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
                         }, 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)
-                                self?.refreshAccountView()
-                                
-                                // 删除后商店为空,刷新table
-                                if self?.cartListModelArr![indexPath.section].productList?.isEmpty ?? true {
-                                    // 删除后商店为空,刷新table
-                                    self?.cartListModelArr?.remove(at: indexPath.section)
-                                    tableView.reloadData()
-                                } else {
-                                    // 刷新删除行所在的section(防止索引越界)
-                                    self?.tableView.reloadSections([indexPath.section], with: UITableView.RowAnimation.none)
-                                }
-                            }
+                            self?.deleteProduct(indexPath)
                         })
                         
                         return
@@ -422,21 +407,7 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
     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)
-                self?.refreshAccountView()
-                
-                if self?.cartListModelArr![indexPath.section].productList?.isEmpty ?? true {
-                    // 删除后商店为空,刷新table
-                    self?.cartListModelArr?.remove(at: indexPath.section)
-                    tableView.reloadData()
-                } else {
-                    // 刷新删除行所在的section(防止索引越界)
-                    self?.tableView.reloadSections([indexPath.section], with: UITableView.RowAnimation.none)
-                }
-            }
+            self.deleteProduct(indexPath)
         }
     }
     
@@ -577,4 +548,23 @@ extension ShoppingCartView {
         return true
     }
     
+    // 删除商品条目
+    func deleteProduct(_ indexPath: IndexPath) {
+        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)
+            self?.tableView.deleteRows(at: [indexPath], with: .none)
+            self?.refreshAccountView()
+            
+            if self?.cartListModelArr![indexPath.section].productList?.isEmpty ?? true {
+                // 删除后商店为空,刷新table
+                self?.cartListModelArr?.remove(at: indexPath.section)
+                self?.tableView.reloadData()
+            } else {
+                // 刷新删除行所在的section(防止索引越界)
+                self?.tableView.reloadSections([indexPath.section], with: UITableView.RowAnimation.none)
+            }
+        }
+    }
+    
 }