|
@@ -41,9 +41,14 @@ class ShoppingCartView: BaseView {
|
|
|
// 已选商品ModelArr
|
|
|
private var selModelArr: Array<CartProductListModel> = []
|
|
|
|
|
|
+ // 订单支付--次级block
|
|
|
typealias OrderPayTransBlock = (_ selMdlArr: Array<CartProductListModel>, _ totalPrice: Int) -> Void
|
|
|
var orderPayTransBlock : OrderPayTransBlock?
|
|
|
|
|
|
+ // 刷新列表(数据)--次级block
|
|
|
+ typealias RefreshTransBlock = () -> Void
|
|
|
+ var refreshTransBlock : RefreshTransBlock?
|
|
|
+
|
|
|
override func setupViews() {
|
|
|
self.backgroundColor = kf7f8faColor
|
|
|
addSubview(accountView)
|
|
@@ -77,8 +82,7 @@ class ShoppingCartView: BaseView {
|
|
|
|
|
|
accountView.allSelectBlock = { [weak self]
|
|
|
(isAllSelected) in
|
|
|
- self?.allSelectedAction(isAllSelected)
|
|
|
- self?.refreshAccountView()
|
|
|
+ self?.productCartAllSelApi(isSel: isAllSelected)
|
|
|
}
|
|
|
|
|
|
accountView.orderPayBlock = {
|
|
@@ -139,6 +143,12 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
|
|
|
hotSaleCell.hotSaleModelArr = hotSaleModelArr
|
|
|
hotSaleCell.layoutIfNeeded()
|
|
|
hotSaleCell.reloadData()
|
|
|
+ hotSaleCell.refreshBlock = {
|
|
|
+ [weak self] in
|
|
|
+ if let refreshTransBlock = self?.refreshTransBlock {
|
|
|
+ refreshTransBlock()
|
|
|
+ }
|
|
|
+ }
|
|
|
return hotSaleCell
|
|
|
default:
|
|
|
return UITableViewCell()
|
|
@@ -152,11 +162,8 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
|
|
|
|
|
|
cell.productSelBlock = { [weak self]
|
|
|
(isProductSel) in
|
|
|
- self?.cartListModelArr![indexPath.section].productList![indexPath.row].isSelect = isProductSel
|
|
|
-
|
|
|
- self?.tableView.reloadSections([indexPath.section], with: UITableView.RowAnimation.none)
|
|
|
- self?.judgeAllSelectedStatus()
|
|
|
- self?.refreshAccountView()
|
|
|
+ let productMdl: ProductModel = (self?.cartListModelArr![indexPath.section].productList![indexPath.row])!
|
|
|
+ self?.productCartIsSelApi(pro_id: productMdl.id!, isSel: isProductSel, indexPath: indexPath)
|
|
|
}
|
|
|
|
|
|
cell.changeProductBlock = { [weak self]
|
|
@@ -181,6 +188,12 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
|
|
|
hotSaleCell.hotSaleModelArr = hotSaleModelArr
|
|
|
hotSaleCell.layoutIfNeeded()
|
|
|
hotSaleCell.reloadData()
|
|
|
+ hotSaleCell.refreshBlock = {
|
|
|
+ [weak self] in
|
|
|
+ if let refreshTransBlock = self?.refreshTransBlock {
|
|
|
+ refreshTransBlock()
|
|
|
+ }
|
|
|
+ }
|
|
|
return hotSaleCell
|
|
|
}
|
|
|
}
|
|
@@ -205,9 +218,12 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
|
|
|
headerView.isSectionSelected = self.judgeSectionSelectedStatus(section)
|
|
|
headerView.secSelectBlock = { [weak self]
|
|
|
(isSectionSel) in
|
|
|
- self?.shopSelectedAction(isSectionSel, section: section)
|
|
|
- self?.judgeAllSelectedStatus()
|
|
|
- self?.refreshAccountView()
|
|
|
+ let proListMdl: CartProductListModel = (self?.cartListModelArr![section])!
|
|
|
+ self?.productCartIsSelApi(shop_id: proListMdl.shopId!, isSel: isSectionSel, section: section)
|
|
|
+
|
|
|
+// self?.shopSelectedAction(isSectionSel, section: section)
|
|
|
+// self?.judgeAllSelectedStatus()
|
|
|
+// self?.refreshAccountView()
|
|
|
}
|
|
|
return headerView
|
|
|
|
|
@@ -223,8 +239,19 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
|
|
+ func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
|
|
+ // 非商品Item拦截滑动删除
|
|
|
+ if cartListModelArr?.isEmpty ?? true {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if indexPath.section == cartListModelArr!.count {
|
|
|
+ return false
|
|
|
+ }
|
|
|
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
|
|
if editingStyle == .delete {
|
|
|
// 删除商品
|
|
|
let productId = cartListModelArr![indexPath.section].productList?[indexPath.row].id
|
|
@@ -319,4 +346,32 @@ extension ShoppingCartView {
|
|
|
self.accountView.tNumber = totalNum
|
|
|
}
|
|
|
|
|
|
+ // 选中单个商品
|
|
|
+ func productCartIsSelApi(pro_id:Int = 0, isSel:Int, indexPath:IndexPath) {
|
|
|
+ SwiftMoyaNetWorkServiceProduct.shared().productCartIsSelApi(id: pro_id, shop_id: 0, isSelect: isSel) { (data) -> (Void) in
|
|
|
+ self.cartListModelArr![indexPath.section].productList![indexPath.row].isSelect = isSel
|
|
|
+
|
|
|
+ self.tableView.reloadSections([indexPath.section], with: UITableView.RowAnimation.none)
|
|
|
+ self.judgeAllSelectedStatus()
|
|
|
+ self.refreshAccountView()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 选中section内商品
|
|
|
+ func productCartIsSelApi(shop_id:Int = 0, isSel:Int, section:Int) {
|
|
|
+ SwiftMoyaNetWorkServiceProduct.shared().productCartIsSelApi(id: 0, shop_id: shop_id, isSelect: isSel) { (data) -> (Void) in
|
|
|
+ self.shopSelectedAction(isSel, section: section)
|
|
|
+ self.judgeAllSelectedStatus()
|
|
|
+ self.refreshAccountView()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 全选商品
|
|
|
+ func productCartAllSelApi(isSel:Int) {
|
|
|
+ SwiftMoyaNetWorkServiceProduct.shared().productCartAllSelApi(isSelect: isSel) { (data) -> (Void) in
|
|
|
+ self.allSelectedAction(isSel)
|
|
|
+ self.refreshAccountView()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|