|
@@ -41,6 +41,9 @@ class CategoryViewController: BaseViewController {
|
|
|
}
|
|
|
|
|
|
override func setupData() {
|
|
|
+
|
|
|
+ productGetCartCountApi()
|
|
|
+
|
|
|
categorySearchView.searchbgView.rx.tap.subscribe(onNext: {
|
|
|
[weak self] in
|
|
|
let vc = SearchViewController()
|
|
@@ -49,6 +52,10 @@ class CategoryViewController: BaseViewController {
|
|
|
|
|
|
})
|
|
|
}).disposed(by: disposeBag)
|
|
|
+ categorySearchView.shoppingCarBlock = {
|
|
|
+ [weak self] in
|
|
|
+ self?.tabBarController?.selectedIndex = 1
|
|
|
+ }
|
|
|
|
|
|
categoryView.leftTableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) {
|
|
|
[weak self] (page) in
|
|
@@ -72,9 +79,20 @@ class CategoryViewController: BaseViewController {
|
|
|
self?.productSearchApi(page: page)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
categoryView.rightDidSelectRow = {
|
|
|
[weak self] indexPath in
|
|
|
+ let vc = ProductDetailViewController()
|
|
|
+ let productSearch = self?.productSearchModelArray[indexPath.row]
|
|
|
+ vc.productSearchModel = productSearch
|
|
|
+ self?.navigationController?.pushViewController(vc, animated: true)
|
|
|
+
|
|
|
+ }
|
|
|
+ categoryView.addCartClosure = {
|
|
|
+ [weak self] (productSearchModel,indexPath) in
|
|
|
+ self?.addCart(productSearchModel: productSearchModel, indexPath: indexPath)
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private lazy var categorySearchView: CategorySearchView = {
|
|
@@ -129,4 +147,27 @@ class CategoryViewController: BaseViewController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// 获取购物车数量
|
|
|
+ func productGetCartCountApi() {
|
|
|
+ SwiftMoyaNetWorkServiceProduct.shared().productGetCartCountApi {
|
|
|
+ [weak self] (productCartCountModel) -> (Void) in
|
|
|
+ self?.categorySearchView.productCartCountModel = productCartCountModel as? ProductCartCountModel
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 添加购物车
|
|
|
+ ///
|
|
|
+ /// - Returns:
|
|
|
+ func addCart(productSearchModel:ProductSearchModel,indexPath:IndexPath) {
|
|
|
+
|
|
|
+
|
|
|
+ productSearchModel.isSelect = 1
|
|
|
+ SwiftMoyaNetWorkServiceProduct.shared().productCartListAddApi(productSearchModel: productSearchModel, completion: {
|
|
|
+ [weak self] (cartAmountModel) -> (Void) in
|
|
|
+ self?.categoryView.rightTableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
|
|
|
+ SwiftProgressHUD.shared().showText("已加入购物车", view: (self?.categoryView.rightTableView)!, textAlignment: .center)
|
|
|
+ self?.productGetCartCountApi()
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|