南鑫林 5 years ago
parent
commit
8687540537

+ 35 - 4
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchProduct/ViewController/SearchProductListViewController.swift

@@ -11,6 +11,7 @@ import JXSegmentedView
 class SearchProductListViewController: UIViewController {
 
     var keyWord : String = ""
+    var productSearchModelArray = Array<ProductSearchModel>()
     
     override func viewDidLoad() {
         super.viewDidLoad()
@@ -55,20 +56,51 @@ class SearchProductListViewController: UIViewController {
     var addCartClosure : AddCartClosure?
 }
     
+extension SearchProductListViewController {
+    /// 搜索
+    func productSearchApi(page:Int = 1) {
+        SwiftProgressHUD.shared().showWait()
+        SwiftMoyaNetWorkServiceProduct.shared().productListApi(page:page ,keyword: self.keyWord) {
+            [weak self] (productSearchListModel) -> (Void) in
+            let productSearchListModel = productSearchListModel as? ProductSearchListModel
+            if productSearchListModel?.pagination?.currentPage ?? 1  <= productSearchListModel?.pagination?.totalPages ?? 1 {
+                if productSearchListModel?.pagination?.currentPage == 1{
+                    self?.productSearchModelArray.removeAll()
+                }
+                self?.productSearchModelArray = (self?.productSearchModelArray)! + (productSearchListModel?.data!)!
+                self?.tableView.reloadData()
+                if  self?.productSearchModelArray.count ?? 0 >= productSearchListModel?.pagination?.total ?? 0 {
+                    self?.tableView.isHiddenFooter(true)
+                }
+            }else {
+                self?.tableView.endFooterNoMoreData()
+            }
+            SwiftProgressHUD.shared().hide()
+        }
+    }
+}
+
 extension SearchProductListViewController :UITableViewDataSource,UITableViewDelegate  {
     
     
     func numberOfSections(in tableView: UITableView) -> Int {
-        return 1
+        return productSearchModelArray.isEmpty ? 0 : 1
     }
     
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        return 10
+        return productSearchModelArray.isEmpty ? 0 : productSearchModelArray.count
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         let cell = ProductHBigTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
-
+        cell.productSearchModel = productSearchModelArray[indexPath.row]
+        cell.plusClosure = {
+            [weak self] (productSearchModel,indexPath) in
+            
+            if let addCartClosure = self?.addCartClosure {
+                addCartClosure(productSearchModel!,indexPath!)
+            }
+        }
         return cell
     }
     
@@ -79,7 +111,6 @@ extension SearchProductListViewController :UITableViewDataSource,UITableViewDele
     }
     
 }
-    
 
 extension SearchProductListViewController : JXSegmentedListContainerViewListDelegate {
     func listView() -> UIView {

+ 1 - 0
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchResult/ViewController/SearchResultViewController.swift

@@ -177,6 +177,7 @@ extension SearchResultViewController :JXSegmentedListContainerViewDataSource {
         /// 商品
         default:
             let vc = SearchProductListViewController()
+            vc.keyWord = keyWord
             return vc
         }
     }