|
@@ -88,6 +88,47 @@ class ShoppingMallFloorTableViewCell: UITableViewCell {
|
|
|
}
|
|
|
self.collectionView.collectionViewLayout.invalidateLayout()
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /// 添加购物车
|
|
|
+ ///
|
|
|
+ /// - Returns:
|
|
|
+ func addCart(productModel:ProductModel,indexPath:IndexPath) {
|
|
|
+ productModel.isSelect = 1
|
|
|
+ productModel.amount = 1
|
|
|
+ SwiftMoyaNetWorkServiceProduct.shared().productCartAddApi(productMdl: productModel) {
|
|
|
+ [weak self] (cartAmountModel) -> (Void) in
|
|
|
+ let cartAmountModel = cartAmountModel as? CartAmountModel
|
|
|
+ let productModels = self?.productModelsArrays![indexPath.section]
|
|
|
+ let productModel = productModels![indexPath.row]
|
|
|
+ productModel.cartId = cartAmountModel?.id ?? 0
|
|
|
+ productModel.amount = 1
|
|
|
+ self!.collectionView.reloadItems(at: [indexPath])
|
|
|
+ SwiftProgressHUD.shared().showText("已加入购物车")
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 添加数量
|
|
|
+ func setProductAmount(type:Int,productModel:ProductModel,indexPath:IndexPath){
|
|
|
+ SwiftMoyaNetWorkServiceProduct.shared().productCartAmountApi(id: productModel.cartId ?? 0, type: type) {
|
|
|
+ [weak self] (cartAmountModel) -> (Void) in
|
|
|
+ let cartAmountModel = cartAmountModel as? CartAmountModel
|
|
|
+ let productModels = self?.productModelsArrays![indexPath.section]
|
|
|
+ let productModel = productModels![indexPath.row]
|
|
|
+ productModel.cartId = cartAmountModel?.id ?? 0
|
|
|
+ productModel.amount = cartAmountModel?.amount
|
|
|
+ self!.collectionView.reloadItems(at: [indexPath])
|
|
|
+ if type == 1{
|
|
|
+ SwiftProgressHUD.shared().showText("已加入购物车")
|
|
|
+ }else {
|
|
|
+ SwiftProgressHUD.shared().showText("已移出购物车")
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
extension ShoppingMallFloorTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
|
|
@@ -139,6 +180,11 @@ extension ShoppingMallFloorTableViewCell: UICollectionViewDelegateFlowLayout,UIC
|
|
|
cell.layer.mask = shapeLayer
|
|
|
}
|
|
|
}
|
|
|
+ cell.plusClosure = {
|
|
|
+ [weak self] (productModel,indexPath) in
|
|
|
+ self?.addCart(productModel: productModel!, indexPath: indexPath!)
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
return cell
|
|
|
case 1: // 1:通栏大图
|
|
@@ -148,6 +194,18 @@ extension ShoppingMallFloorTableViewCell: UICollectionViewDelegateFlowLayout,UIC
|
|
|
let productModels = productModelsArrays![indexPath.section]
|
|
|
cell.productModel = productModels[indexPath.row]
|
|
|
}
|
|
|
+ cell.shopingCarClosure = {
|
|
|
+ [weak self] (productModel,indexPath) in
|
|
|
+ self?.addCart(productModel: productModel!, indexPath: indexPath!)
|
|
|
+ }
|
|
|
+ cell.plusClosure = {
|
|
|
+ [weak self] (productModel,indexPath) in
|
|
|
+ self?.setProductAmount(type: 1, productModel: productModel!, indexPath: indexPath!)
|
|
|
+ }
|
|
|
+ cell.reduceClosure = {
|
|
|
+ [weak self] (productModel,indexPath) in
|
|
|
+ self?.setProductAmount(type: 2, productModel: productModel!, indexPath: indexPath!)
|
|
|
+ }
|
|
|
return cell
|
|
|
case 2: // 2:左右滑动
|
|
|
let cell = ShoppingMallSlidingLeftRightBgCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
@@ -245,29 +303,29 @@ extension ShoppingMallFloorTableViewCell: UICollectionViewDelegateFlowLayout,UIC
|
|
|
|
|
|
return CGSize(width:347 * kScaleWidth, height: 50 + kScaleWidth * 90)
|
|
|
case 1: // 1:通栏大图
|
|
|
- if cmsRuleModel?.rule?.title?.isEmpty ?? true {
|
|
|
+ if cmsRuleModel?.rule?.title == "" {
|
|
|
return CGSize(width:347 * kScaleWidth, height: 73 + (kScaleWidth * 90))
|
|
|
}
|
|
|
|
|
|
- if cmsRuleModel?.rule?.url?.isEmpty ?? true {
|
|
|
+ if cmsRuleModel?.rule?.url == "" {
|
|
|
return CGSize(width:347 * kScaleWidth, height: 10 + (kScaleWidth * 90))
|
|
|
}
|
|
|
|
|
|
- if cmsRuleModel?.rule?.title?.isEmpty ?? true && cmsRuleModel?.rule?.url?.isEmpty ?? true {
|
|
|
+ if cmsRuleModel?.rule?.title == "" && cmsRuleModel?.rule?.url == "" {
|
|
|
return CGSize(width:0, height:0)
|
|
|
}
|
|
|
|
|
|
return CGSize(width:347 * kScaleWidth, height: 73 + (kScaleWidth * 90))
|
|
|
case 2: // 2:左右滑动
|
|
|
- if cmsRuleModel?.rule?.title?.isEmpty ?? true {
|
|
|
+ if cmsRuleModel?.rule?.title == "" {
|
|
|
return CGSize(width:347 * kScaleWidth, height:kScaleWidth * 90)
|
|
|
}
|
|
|
|
|
|
- if cmsRuleModel?.rule?.url?.isEmpty ?? true {
|
|
|
+ if cmsRuleModel?.rule?.url == ""{
|
|
|
return CGSize(width:347 * kScaleWidth, height:50)
|
|
|
}
|
|
|
|
|
|
- if cmsRuleModel?.rule?.title?.isEmpty ?? true && cmsRuleModel?.rule?.url?.isEmpty ?? true {
|
|
|
+ if cmsRuleModel?.rule?.title == "" && cmsRuleModel?.rule?.url == "" {
|
|
|
return CGSize(width:0, height:0)
|
|
|
}
|
|
|
|