|
@@ -269,22 +269,7 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
|
|
}, confirmBlock: {
|
|
}, confirmBlock: {
|
|
[weak self] (popupView, index, string) in
|
|
[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
|
|
return
|
|
@@ -422,21 +407,7 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
|
|
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
|
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
|
if editingStyle == .delete {
|
|
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
|
|
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)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|