Selaa lähdekoodia

Merge branch 'develop' into feature/nanxinlin

* develop:
  购物车 -- 数量变更 && 热销商品API
  购物车 -- 删除商品 && 流程跳转
南鑫林 6 vuotta sitten
vanhempi
commit
711159fdda

+ 6 - 4
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartAccountView.swift

@@ -12,6 +12,9 @@ import RxCocoa
 
 class ShoppingCartAccountView: BaseView {
     
+    typealias OrderPayBlock = () -> Void
+    var orderPayBlock : OrderPayBlock?
+    
     override func setupViews() {
         self.backgroundColor = kffffffColor
         addSubview(allSelectBtn)
@@ -76,10 +79,9 @@ class ShoppingCartAccountView: BaseView {
         accountBtn.cornerRadius = 18
         accountBtn.masksToBounds = true
         accountBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
-//            if let forgetPasswordBlock = self?.forgetPasswordBlock {
-//                forgetPasswordBlock()
-//            }
-            print("点击了结算")
+            if let orderPayBlock = self?.orderPayBlock {
+                orderPayBlock()
+            }
         }).disposed(by: disposeBag)
         return accountBtn
     }()

+ 20 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartList/ShoppingCartListTableViewCell.swift

@@ -7,9 +7,16 @@
 //  购物车--商品列表Cell
 
 import UIKit
+import RxSwift
+import RxCocoa
 
 class ShoppingCartListTableViewCell: UITableViewCell {
     
+    let disposeBag = DisposeBag()
+    
+    typealias ChangeProductBlock = (_ id: Int,_ type : Int) -> Void
+    var changeProductBlock : ChangeProductBlock?
+    
     var productMdl : ProductModel? {
         didSet {
             // 商品图片
@@ -21,11 +28,11 @@ class ShoppingCartListTableViewCell: UITableViewCell {
             // 规格
             sellScaleLabel.text = "规格:\(productMdl?.skuName ?? "")"
             // 数量
-            sellNumberLabel.text = "x1"
+            sellNumberLabel.text = "x\(productMdl?.amount ?? 1)"
             // 价格
             sellPriceLabel.text = "¥\(productMdl?.skuPrice ?? 0)"
             // 数量
-            numberLabel.text = "1"
+            numberLabel.text = "\(productMdl?.amount ?? 1)"
         }
     }
     
@@ -196,6 +203,12 @@ class ShoppingCartListTableViewCell: UITableViewCell {
     private lazy var plusButton: UIButton = {
         let plusButton = UIButton(type: UIButton.ButtonType.custom)
         plusButton.setImage(kImage(name: "shopping_mall_plus"), for: UIControl.State.normal)
+        plusButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if let changeProductBlock = self?.changeProductBlock {
+                changeProductBlock((self?.productMdl?.id)!, 1)
+            }
+        }).disposed(by: disposeBag)
+        
         return plusButton
     }()
 
@@ -210,6 +223,11 @@ class ShoppingCartListTableViewCell: UITableViewCell {
     private lazy var reduceButton: UIButton = {
         let reduceButton = UIButton(type: UIButton.ButtonType.custom)
         reduceButton.setImage(kImage(name: "home_btn_buy_subtract"), for: UIControl.State.normal)
+        reduceButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if let changeProductBlock = self?.changeProductBlock {
+                changeProductBlock((self?.productMdl?.id)!, 2)
+            }
+        }).disposed(by: disposeBag)
         return reduceButton
     }()
     

+ 40 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -20,11 +20,14 @@ class ShoppingCartView: BaseView {
     // 热销ModelArr
     var hotSaleModelArr : Array<ProductSearchModel>? {
         didSet {
-            //FIXME:刷新指定section
-            tableView.reloadData()
+            let sectionIdx = cartListModelArr?.count ?? 1
+            self.tableView.reloadSections([sectionIdx], with: UITableView.RowAnimation.none)
         }
     }
     
+    typealias OrderPayTransBlock = () -> Void
+    var orderPayTransBlock : OrderPayTransBlock?
+    
     override func setupViews() {
         self.backgroundColor = kf7f8faColor
         addSubview(accountView)
@@ -48,6 +51,14 @@ class ShoppingCartView: BaseView {
     
     lazy var accountView: ShoppingCartAccountView = {
         let accountView = ShoppingCartAccountView()
+        
+        accountView.orderPayBlock = {
+            [weak self] in
+            if let orderPayTransBlock = self?.orderPayTransBlock {
+                orderPayTransBlock()
+            }
+        }
+        
         return accountView
     }()
     
@@ -107,6 +118,18 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
                 // 购物车列表Item
                 let cell = ShoppingCartListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
                 cell.productMdl = cartListModelArr![indexPath.section].productList![indexPath.row]
+                cell.changeProductBlock = {
+                    (productId, type) in
+                    SwiftMoyaNetWorkServiceProduct.shared().productCartAmountApi(id: productId, type: type, completion: { [weak self] (amountData) -> (Void) in
+                        // 1.更新数据源
+                        let cartAmountMdl = amountData as? CartAmountModel
+                        let amount = cartAmountMdl?.amount
+                        self?.cartListModelArr![indexPath.section].productList![indexPath.row].amount = amount
+                        // 2.刷新cell
+                        let indexPath = IndexPath(item: indexPath.row, section: indexPath.section)
+                        self?.tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
+                    })
+                }
                 return cell
                 
             } else {
@@ -149,4 +172,19 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
         return nil
     }
     
+    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
+        
+        if editingStyle == .delete {
+            // 删除商品
+            let productId = cartListModelArr![indexPath.section].productList?[indexPath.row].id
+            SwiftMoyaNetWorkServiceProduct.shared().productCartDeleteApi(id: productId ?? 0) { [weak self] (data) -> (Void) in
+                self?.cartListModelArr![indexPath.section].productList?.remove(at: indexPath.row)
+                tableView.deleteRows(at: [indexPath], with: .none)
+            }
+        }
+    }
+    
+    func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
+        return "删除"
+    }
 }

+ 12 - 8
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/ViewController/ShoppingCartViewController.swift

@@ -46,11 +46,11 @@ class ShoppingCartViewController: BaseViewController {
         
         shoppingCartView.tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) { [weak self] (page) in
             self?.productCartListApi()
-            self?.productSearchApi(page: page)
+            self?.productHotSaleApi(page: page)
         }
         
         shoppingCartView.tableView.addFooterWithWithHeader(withAutomaticallyRefresh: true) { [weak self] (page) in
-            self?.productSearchApi(page: page)
+            self?.productHotSaleApi(page: page)
         }
     }
     
@@ -65,6 +65,11 @@ class ShoppingCartViewController: BaseViewController {
     
     private lazy var shoppingCartView: ShoppingCartView = {
         let shoppingCartView = ShoppingCartView()
+        shoppingCartView.orderPayTransBlock = {
+            [weak self] in
+            let vc = ShoppingCartPayOrderController()
+            self?.navigationController?.pushViewController(vc, animated: true)
+        }
         return shoppingCartView
     }()
     
@@ -78,22 +83,21 @@ class ShoppingCartViewController: BaseViewController {
     }
     
     /// 商品热销
-    func productSearchApi(page:Int = 1) {
-        SwiftMoyaNetWorkServiceProduct.shared().productSearchApi(page:page) {
-            [weak self] (productSearchListModel) -> (Void) in
+    func productHotSaleApi(page:Int = 1) {
+        SwiftMoyaNetWorkServiceProduct.shared().productHotSaleApi(page: page) { [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?.shoppingCartView.hotSaleModelArr = self?.productSearchModelArray
-                
+
             } else {
                 self?.shoppingCartView.hotSaleModelArr = self?.productSearchModelArray
             }
         }
     }
-
+    
 }

+ 6 - 4
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/View/OrderPayAcountView.swift

@@ -12,6 +12,9 @@ import RxCocoa
 
 class OrderPayAcountView: BaseView {
     
+    typealias CommitOrderBlock = () -> Void
+    var commitOrderBlock : CommitOrderBlock?
+    
     override func setupViews() {
         self.backgroundColor = kffffffColor
         addSubview(accountBtn)
@@ -49,10 +52,9 @@ class OrderPayAcountView: BaseView {
         accountBtn.cornerRadius = 18
         accountBtn.masksToBounds = true
         accountBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
-            //            if let forgetPasswordBlock = self?.forgetPasswordBlock {
-            //                forgetPasswordBlock()
-            //            }
-            print("点击了提交订单")
+            if let commitOrderBlock = self?.commitOrderBlock {
+                commitOrderBlock()
+            }
         }).disposed(by: disposeBag)
         return accountBtn
     }()

+ 9 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/View/ShoppingCartOrderPayView.swift

@@ -10,6 +10,9 @@ import UIKit
 
 class ShoppingCartOrderPayView: BaseView {
     
+    typealias CommitOrderTransBlock = () -> Void
+    var commitOrderTransBlock : CommitOrderTransBlock?
+    
     override func setupViews() {
         self.backgroundColor = kf7f8faColor
         addSubview(accountView)
@@ -34,6 +37,12 @@ class ShoppingCartOrderPayView: BaseView {
     
     lazy var accountView: OrderPayAcountView = {
         let accountView = OrderPayAcountView()
+        accountView.commitOrderBlock = {
+            [weak self] in
+            if let commitOrderTransBlock = self?.commitOrderTransBlock {
+                commitOrderTransBlock()
+            }
+        }
         return accountView
     }()
     

+ 7 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/ViewController/ShoppingCartPayOrderController.swift

@@ -47,6 +47,13 @@ class ShoppingCartPayOrderController: BaseViewController {
     
     private lazy var orderPayView: ShoppingCartOrderPayView = {
         let orderPayView = ShoppingCartOrderPayView()
+        orderPayView.commitOrderTransBlock = {
+            [weak self] in
+            // 支付弹窗调用
+            AlertSheetView.payAlertSheetView {
+                
+            }
+        }
         return orderPayView
     }()
     

+ 24 - 0
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaNetWorkServiceProduct.swift

@@ -100,6 +100,30 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
         }
     }
     
+    // MARK: - 热销商品
+    /// 热销商品
+    ///
+    /// - Parameters:
+    ///   - completion: 回调
+    func productHotSaleApi(page:Int = 1, completion: @escaping apiCallBack) {
+        var parameters = Dictionary<String,Any>()
+        parameters.updateValue(page, forKey: "page")
+        // 本地获取city_id
+        let loacationModel = LocationModel.shared().getLocationModel()
+        let baiduToCityModel = BaiduToCityFactory.shared.query(bjcityId: loacationModel!.cityCode)
+        parameters.updateValue(baiduToCityModel.areaCode, forKey: "city_id")
+        
+        // 本地获取deliver_type
+        let deliver_type = DeliveryMethodTypeModel.shared().getModel()?.deliveryMethodType
+        parameters.updateValue(deliver_type ?? "0", forKey: "deliver_type")
+        
+        SwiftProgressHUD.shared().showWait()
+        SwiftMoyaNetWorkManager.shared().request(ProductCartListData.self, target: MultiTarget(SwiftMoyaServiceProductApi.productHotSale(parameters: parameters))) { (productCartListData) in
+            SwiftProgressHUD.shared().hide()
+            completion(productCartListData)
+        }
+    }
+    
     // MARK: - 购物车列表
     /// 购物车列表
     ///

+ 12 - 0
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaServiceProductApi.swift

@@ -25,6 +25,10 @@ public let kProductHomeProductApi = "/product/homeProduct"
 /// 商品详情
 public let kProductDetailApi = "/product/detail"
 
+// MARK: - 热销商品
+/// 热销商品
+public let kProductHotSaleApi = "/product/hotSales"
+
 // MARK: - 购物车列表
 /// 购物车列表
 public let kProductCartListApi = "/product/cartList"
@@ -56,6 +60,7 @@ public let kProductCartAllSelApi = "/cart/isSelectAll"
 /// - productCategory: 商品分类
 /// - productHomeProduct: 首页商品
 /// - productDetail: 商品详情
+/// - productHotSale: 热销商品
 /// - productCartList: 购物车列表
 /// - productCartAdd: 购物车-添加
 /// - productCartDelete: 购物车-删除
@@ -67,6 +72,7 @@ public enum SwiftMoyaServiceProductApi {
     case productCategory(parameters:Dictionary<String, Any>)
     case productHomeProduct(parameters:Dictionary<String, Any>)
     case productDetail(parameters:Dictionary<String, Any>)
+    case productHotSale(parameters:Dictionary<String, Any>)
     case productCartList(parameters:Dictionary<String, Any>)
     case productCartAdd(parameters:Dictionary<String, Any>)
     case productCartDelete(parameters:Dictionary<String, Any>)
@@ -83,6 +89,7 @@ extension SwiftMoyaServiceProductApi: TargetType {
              .productCategory,
              .productHomeProduct,
              .productDetail,
+             .productHotSale,
              .productCartList,
              .productCartAdd,
              .productCartDelete,
@@ -104,6 +111,8 @@ extension SwiftMoyaServiceProductApi: TargetType {
             return kProductHomeProductApi
         case .productDetail:
             return kProductDetailApi
+        case .productHotSale:
+            return kProductHotSaleApi
         case .productCartList:
             return kProductCartListApi
         case .productCartAdd:
@@ -124,6 +133,7 @@ extension SwiftMoyaServiceProductApi: TargetType {
         case .productSearch,
              .productCategory,
              .productHomeProduct,
+             .productHotSale,
              .productCartList,
              .productDetail
             :
@@ -149,6 +159,7 @@ extension SwiftMoyaServiceProductApi: TargetType {
              .productCategory(var parameters),
              .productHomeProduct(var parameters),
              .productDetail(var parameters),
+             .productHotSale(var parameters),
              .productCartList(var parameters),
              .productCartAdd(var parameters),
              .productCartDelete(var parameters),
@@ -181,6 +192,7 @@ extension SwiftMoyaServiceProductApi: TargetType {
              .productCategory,
              .productHomeProduct,
              .productDetail,
+             .productHotSale,
              .productCartList,
              .productCartAdd,
              .productCartDelete,