|
@@ -17,6 +17,7 @@ class SearchProductListViewController: UIViewController {
|
|
|
super.viewDidLoad()
|
|
|
setupViews()
|
|
|
setupLayouts()
|
|
|
+ setupData()
|
|
|
}
|
|
|
|
|
|
func setupViews() {
|
|
@@ -36,6 +37,17 @@ class SearchProductListViewController: UIViewController {
|
|
|
make.bottom.equalTo(-kSafeTabBarHeight - 10)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ func setupData() {
|
|
|
+ tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) {
|
|
|
+ [weak self] (page) in
|
|
|
+ self?.productSearchApi(page:page)
|
|
|
+ }
|
|
|
+ tableView.addFooterWithWithHeader(withAutomaticallyRefresh: true) {
|
|
|
+ [weak self] (page) in
|
|
|
+ self?.productSearchApi(page:page)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
lazy var tableView: UITableView = {
|
|
|
let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.plain)
|
|
@@ -78,6 +90,18 @@ extension SearchProductListViewController {
|
|
|
SwiftProgressHUD.shared().hide()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// 添加购物车
|
|
|
+ ///
|
|
|
+ /// - Returns:
|
|
|
+ func addCart(productSearchModel:ProductSearchModel,indexPath:IndexPath) {
|
|
|
+ productSearchModel.isSelect = 1
|
|
|
+ SwiftMoyaNetWorkServiceProduct.shared().productCartListAddApi(productSearchModel: productSearchModel, completion: {
|
|
|
+ [weak self] (cartAmountModel) -> (Void) in
|
|
|
+ self?.tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
|
|
|
+ SwiftProgressHUD.shared().showText("已加入购物车")
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension SearchProductListViewController :UITableViewDataSource,UITableViewDelegate {
|
|
@@ -96,10 +120,7 @@ extension SearchProductListViewController :UITableViewDataSource,UITableViewDele
|
|
|
cell.productSearchModel = productSearchModelArray[indexPath.row]
|
|
|
cell.plusClosure = {
|
|
|
[weak self] (productSearchModel,indexPath) in
|
|
|
-
|
|
|
- if let addCartClosure = self?.addCartClosure {
|
|
|
- addCartClosure(productSearchModel!,indexPath!)
|
|
|
- }
|
|
|
+ self?.addCart(productSearchModel: productSearchModel!, indexPath: indexPath!)
|
|
|
}
|
|
|
return cell
|
|
|
}
|