|
@@ -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 {
|