瀏覽代碼

no message

南鑫林 6 年之前
父節點
當前提交
10101570fb

+ 28 - 8
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallFloor/Floor/ShoppingMallFloorTableViewCell.swift

@@ -39,6 +39,11 @@ class ShoppingMallFloorTableViewCell: UITableViewCell {
             collectionView.reloadData()
             collectionView.reloadData()
         }
         }
     }
     }
+    var productModelsArrays : Array<[ProductModel]>? {
+        didSet {
+            collectionView.reloadData()
+        }
+    }
     //MRAK: - 设置View
     //MRAK: - 设置View
     private func setupViews() {
     private func setupViews() {
         self.selectionStyle = .none
         self.selectionStyle = .none
@@ -92,11 +97,20 @@ extension ShoppingMallFloorTableViewCell: UICollectionViewDelegateFlowLayout,UIC
     
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
         let cmsRuleModel = cmsRuleModels?[section]
         let cmsRuleModel = cmsRuleModels?[section]
+        
         switch cmsRuleModel?.showType {
         switch cmsRuleModel?.showType {
         case 0: // 0:左图右字;
         case 0: // 0:左图右字;
-            return cmsRuleModel?.rule?.showNum ?? 0
+            if !(productModelsArrays?.isEmpty ?? true) {
+                let productModels = productModelsArrays![section]
+                return productModels.count 
+            }
+            return 0
         case 1: // 1:通栏大图
         case 1: // 1:通栏大图
-            return cmsRuleModel?.rule?.showNum ?? 0
+            if !(productModelsArrays?.isEmpty ?? true) {
+                let productModels = productModelsArrays![section]
+                return productModels.count 
+            }
+            return 0
         case 2: //  2:左右滑动
         case 2: //  2:左右滑动
             return 1
             return 1
         default:
         default:
@@ -107,12 +121,16 @@ extension ShoppingMallFloorTableViewCell: UICollectionViewDelegateFlowLayout,UIC
     
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         let cmsRuleModel = cmsRuleModels?[(indexPath.section)]
         let cmsRuleModel = cmsRuleModels?[(indexPath.section)]
-        
+
         switch cmsRuleModel?.showType {
         switch cmsRuleModel?.showType {
         case 0: // 0:左图右字;
         case 0: // 0:左图右字;
             let cell = ShoppingMallRightSideleftPictureCollectionViewCell.cellWith(
             let cell = ShoppingMallRightSideleftPictureCollectionViewCell.cellWith(
                 collectionView: collectionView, indexPath: indexPath)
                 collectionView: collectionView, indexPath: indexPath)
-            if indexPath.row == 9 {
+            if !(productModelsArrays?.isEmpty ?? true) {
+                let productModels = productModelsArrays![indexPath.section]
+                cell.productModel = productModels[indexPath.row]
+            }
+            if indexPath.row == (cmsRuleModel?.rule!.showNum)! - 1 {
                 let shapeLayer = CAShapeLayer()
                 let shapeLayer = CAShapeLayer()
                 cell.layer.mask = nil
                 cell.layer.mask = nil
                 let bezierPath = UIBezierPath(roundedRect: cell.bounds,
                 let bezierPath = UIBezierPath(roundedRect: cell.bounds,
@@ -125,9 +143,14 @@ extension ShoppingMallFloorTableViewCell: UICollectionViewDelegateFlowLayout,UIC
         case 1: // 1:通栏大图
         case 1: // 1:通栏大图
             let cell = ShoppingMallBarChartCollectionViewCell.cellWith(
             let cell = ShoppingMallBarChartCollectionViewCell.cellWith(
                 collectionView: collectionView, indexPath: indexPath)
                 collectionView: collectionView, indexPath: indexPath)
+            if !(productModelsArrays?.isEmpty ?? true) {
+                let productModels = productModelsArrays![indexPath.section]
+                cell.productModel = productModels[indexPath.row]
+            }
             return cell
             return cell
         case 2: //  2:左右滑动
         case 2: //  2:左右滑动
             let cell = ShoppingMallSlidingLeftRightBgCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
             let cell = ShoppingMallSlidingLeftRightBgCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
+//            cell.productModels = productModels
             return cell
             return cell
         default:
         default:
             return UICollectionViewCell()
             return UICollectionViewCell()
@@ -217,9 +240,6 @@ extension ShoppingMallFloorTableViewCell: UICollectionViewDelegateFlowLayout,UIC
         }
         }
     }
     }
     
     
-    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
-        return 7
-    }
-    
+
 }
 }
 
 

+ 6 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallFloor/FloorCell/ShoppingMallBarChart/ShoppingMallBarChartCollectionViewCell.swift

@@ -207,6 +207,12 @@ class ShoppingMallBarChartCollectionViewCell: UICollectionViewCell {
         return shopingCarButton
         return shopingCarButton
     }()
     }()
     
     
+    var productModel : ProductModel? {
+        didSet {
+            
+        }
+    }
+    
     //    var productSearchModel: ProductSearchModel? {
     //    var productSearchModel: ProductSearchModel? {
     //        didSet {
     //        didSet {
     //            iconImagView.kf.setImage(with: kURLImage(name: productSearchModel?.img ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
     //            iconImagView.kf.setImage(with: kURLImage(name: productSearchModel?.img ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))

+ 6 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallFloor/FloorCell/ShoppingMallRightSideleftPicture/ShoppingMallRightSideleftPictureCollectionViewCell.swift

@@ -138,6 +138,12 @@ class ShoppingMallRightSideleftPictureCollectionViewCell: UICollectionViewCell {
         return plusButton
         return plusButton
     }()
     }()
     
     
+    var productModel : ProductModel? {
+        didSet {
+            
+        }
+    }
+    
 //    var productSearchModel: ProductSearchModel? {
 //    var productSearchModel: ProductSearchModel? {
 //        didSet {
 //        didSet {
 //            iconImagView.kf.setImage(with: kURLImage(name: productSearchModel?.img ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
 //            iconImagView.kf.setImage(with: kURLImage(name: productSearchModel?.img ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))

+ 7 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallFloor/FloorCell/ShoppingMallSlidingLeftRight/ShoppingMallSlidingLeftRightBgCollectionViewCell.swift

@@ -9,6 +9,13 @@
 import UIKit
 import UIKit
 
 
 class ShoppingMallSlidingLeftRightBgCollectionViewCell: UICollectionViewCell {
 class ShoppingMallSlidingLeftRightBgCollectionViewCell: UICollectionViewCell {
+    
+    var productModels : [ProductModel]? {
+        didSet {
+            
+        }
+    }
+    
     class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> ShoppingMallSlidingLeftRightBgCollectionViewCell {
     class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> ShoppingMallSlidingLeftRightBgCollectionViewCell {
         let ID = "ShoppingMallSlidingLeftRightBgCollectionViewCell"
         let ID = "ShoppingMallSlidingLeftRightBgCollectionViewCell"
         collectionView.register(ShoppingMallSlidingLeftRightBgCollectionViewCell.self, forCellWithReuseIdentifier: ID)
         collectionView.register(ShoppingMallSlidingLeftRightBgCollectionViewCell.self, forCellWithReuseIdentifier: ID)

+ 7 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallListView.swift

@@ -16,6 +16,12 @@ class ShoppingMallListView: BaseView {
         }
         }
     }
     }
     
     
+    var productModelsArrays : Array<[ProductModel]>? {
+        didSet {
+            tableView.reloadData()
+        }
+    }
+    
     override func setupViews() {
     override func setupViews() {
         addSubview(tableView)
         addSubview(tableView)
         let emptyView =  EmptyView.shared.diyCustomEmptyViewStyle2(iconStr: "page04", titleStr: "当前暂无数据")
         let emptyView =  EmptyView.shared.diyCustomEmptyViewStyle2(iconStr: "page04", titleStr: "当前暂无数据")
@@ -76,6 +82,7 @@ extension ShoppingMallListView : UITableViewDelegate, UITableViewDataSource {
         case "floor":
         case "floor":
             let cell = ShoppingMallFloorTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
             let cell = ShoppingMallFloorTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
             cell.cmsRuleModels = cmsSectionModel?.rule
             cell.cmsRuleModels = cmsSectionModel?.rule
+            cell.productModelsArrays = productModelsArrays
             cell.frame = tableView.bounds
             cell.frame = tableView.bounds
             cell.layoutIfNeeded()
             cell.layoutIfNeeded()
             cell.reloadData()
             cell.reloadData()

+ 30 - 9
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/ViewController/ShoppingMallListViewController.swift

@@ -51,28 +51,49 @@ class ShoppingMallListViewController: UIViewController {
             [weak self] (cmsModel) -> (Void) in
             [weak self] (cmsModel) -> (Void) in
             let cmsModel = cmsModel as! CMSModel
             let cmsModel = cmsModel as! CMSModel
             self?.shoppingMallListView.cmsSectionModels = cmsModel.content
             self?.shoppingMallListView.cmsSectionModels = cmsModel.content
-            self?.productHomeProductApi(cmsModel: cmsModel)
+            
+            //任务队列
+            let queue = DispatchQueue(label: "requestHandler")
+            //分组
+            let group = DispatchGroup()
+            
+            queue.async(group: group) {
+                self?.productHomeProductApi(cmsModel: cmsModel)
+            }
             
             
         }
         }
     }
     }
     
     
+    var productModelsArrays = Array<[ProductModel]>()
     
     
     func productHomeProductApi(cmsModel:CMSModel?) {
     func productHomeProductApi(cmsModel:CMSModel?) {
-        var productModelsArray = Array<[ProductModel]>()
-        
+
         if let model = cmsModel {
         if let model = cmsModel {
             if !(model.content?.isEmpty ?? true) {
             if !(model.content?.isEmpty ?? true) {
                 for cmsSectionModel in model.content! {
                 for cmsSectionModel in model.content! {
                     if  cmsSectionModel.areaType == "floor" {
                     if  cmsSectionModel.areaType == "floor" {
 
 
-                        
                         if !(cmsSectionModel.rule?.isEmpty ?? true) {
                         if !(cmsSectionModel.rule?.isEmpty ?? true) {
-                            for cmsRuleModel in cmsSectionModel.rule! {
-                                SwiftMoyaNetWorkServiceProduct.shared().productHomeProductApi(ids: cmsRuleModel.productId ?? "", completion: { (productModels) -> (Void) in
-                                    productModelsArray.append(productModels as! [ProductModel])
-                                })
+                            var productModelsArray = Array<[ProductModel]>.init(repeating: [], count: cmsSectionModel.rule!.count)
+                            for  (index, cmsRuleModel) in cmsSectionModel.rule!.enumerated()  {
+                                
+
+                                    let sema = DispatchSemaphore(value: 0)
+                                    SwiftMoyaNetWorkServiceProduct.shared().productHomeProductApi(ids: cmsRuleModel.productId ?? "", completion: {[weak self] (productModels) -> (Void) in
+                                        productModelsArray[index] = productModels as! [ProductModel]
+                                        self?.productModelsArrays = productModelsArray
+                                        NXLLog("signal\(index)")
+                                        sema.signal()
+                                    })
+                                    //异步调用返回前,就会一直阻塞在这
+                                    sema.wait()
+                                    NXLLog("wait\(index)")
+                                    
+                                }
+                            DispatchQueue.main.sync {
+                                self.shoppingMallListView.productModelsArrays = self.productModelsArrays
                             }
                             }
-                           
+
                         }
                         }
                     }
                     }
                 }
                 }

+ 1 - 1
RainbowPlanet/RainbowPlanet/Service/Model/ProductModel/ProductModel.swift

@@ -58,7 +58,7 @@ class ProductModel : NSObject, NSCoding, Mappable{
 		return ProductModel()
 		return ProductModel()
 	}
 	}
 	required init?(map: Map){}
 	required init?(map: Map){}
-	private override init(){}
+	override init(){}
 
 
 	func mapping(map: Map)
 	func mapping(map: Map)
 	{
 	{

+ 10 - 3
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaNetWorkServiceProduct.swift

@@ -72,9 +72,16 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
     func productHomeProductApi(ids:String = "",completion: @escaping apiCallBack) {
     func productHomeProductApi(ids:String = "",completion: @escaping apiCallBack) {
         var parameters = Dictionary<String,Any>()
         var parameters = Dictionary<String,Any>()
         parameters.updateValue(ids, forKey: "ids")
         parameters.updateValue(ids, forKey: "ids")
-                SwiftMoyaNetWorkManager.shared()
-            .requestArray(ProductModel.self,target: MultiTarget(SwiftMoyaServiceProductApi.productHomeProduct(parameters: parameters))) {(productModels) in
-                completion(productModels)
+        SwiftMoyaNetWorkManager.shared().request(target: MultiTarget(SwiftMoyaServiceProductApi.productHomeProduct(parameters: parameters))) { (rootModel) in
+            let rootModel = rootModel as! RootModel
+            SwiftProgressHUD.shared().hide()
+            if rootModel.code == 0 {
+                let productModels = Mapper<ProductModel>().mapArray(JSONString: rootModel.data!)
+                completion(productModels as Any)
+
+            }else if rootModel.code == 1 {
+                completion("")
+            }
         }
         }
     }
     }
 }
 }