Browse Source

视图交互 -- to be continued

Chris 6 years ago
parent
commit
82fdee4dd5

+ 11 - 8
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartAccountView.swift

@@ -12,6 +12,9 @@ import RxCocoa
 
 class ShoppingCartAccountView: BaseView {
     
+    typealias AllSelectBlock = (_ isAllSelected: Int) -> Void
+    var allSelectBlock : AllSelectBlock?
+    
     typealias OrderPayBlock = () -> Void
     var orderPayBlock : OrderPayBlock?
     
@@ -30,6 +33,7 @@ class ShoppingCartAccountView: BaseView {
             make.height.equalTo(30)
             make.width.equalTo(54)
         }
+        allSelectBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 4)
 
         accountBtn.snp.makeConstraints { (make) in
             make.right.equalToSuperview().offset(-14)
@@ -56,16 +60,15 @@ class ShoppingCartAccountView: BaseView {
         allSelectBtn.setTitle("全选", for: UIControl.State.normal)
         allSelectBtn.setTitleColor(k333333Color, for: UIControl.State.normal)
         allSelectBtn.setTitleColor(k666666Color, for: UIControl.State.selected)
-        allSelectBtn.setImage(UIImage.imageWithColor(color: kDisabledButtonColor), for: UIControl.State.selected)
-        allSelectBtn.setImage(UIImage.imageWithColor(color: kEnabledButtonColor), for: UIControl.State.normal)
+        allSelectBtn.setImage(kImage(name: "common_uncheck_icon"), for: UIControl.State.normal)
+        allSelectBtn.setImage(kImage(name: "common_check_icon"), for: UIControl.State.selected)
         allSelectBtn.titleLabel?.font = kScaleRegularFont16
         allSelectBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
-            
-//            if let loginBlock = self?.loginBlock {
-//                loginBlock((self?.phoneNumber)!,(self?.password)!)
-//            }
-            print("点击了全选")
-            
+            allSelectBtn.isSelected = !allSelectBtn.isSelected
+            if let allSelectBlock = self?.allSelectBlock {
+                let isAllSel: Int = allSelectBtn.isSelected == true ? 1 : 0
+                allSelectBlock(isAllSel)
+            }
         }).disposed(by: disposeBag)
         return allSelectBtn
     }()

+ 19 - 7
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartList/ShoppingCartListTableViewCell.swift

@@ -14,11 +14,19 @@ class ShoppingCartListTableViewCell: UITableViewCell {
     
     let disposeBag = DisposeBag()
     
+    // 选中商品
+    typealias ProductSelBlock = (_ isProductSelected: Int) -> Void
+    var productSelBlock : ProductSelBlock?
+    
+    // 加/减购物车数量
     typealias ChangeProductBlock = (_ id: Int,_ type : Int) -> Void
     var changeProductBlock : ChangeProductBlock?
     
     var productMdl : ProductModel? {
         didSet {
+            // 选中状态
+            let selStatus = productMdl?.isSelect == 1 ? true : false
+            selectedButton.isSelected = selStatus
             // 商品图片
             iconImageView.kf.setImage(with: kURLImage(name: productMdl?.productImg ?? ""), placeholder: kImage(name: "pic_preload"))
             // 商品名称
@@ -75,8 +83,6 @@ class ShoppingCartListTableViewCell: UITableViewCell {
     //MRAK: - 设置View
     private func setupViews() {
         self.selectionStyle = .none
-//        cornerRadius = 4
-//        masksToBounds = true
         
         addSubview(selectedButton)
         addSubview(iconImageView)
@@ -88,15 +94,13 @@ class ShoppingCartListTableViewCell: UITableViewCell {
         addSubview(plusButton)
         addSubview(numberLabel)
         addSubview(reduceButton)
-        
     }
     
     private func setupLayouts() {
         selectedButton.snp.makeConstraints { (make) in
-            make.left.equalTo(10)
-            make.top.equalTo(50)
-            make.bottom.equalTo(-80)
-            make.size.equalTo(18)
+            make.left.top.bottom.equalToSuperview()
+            make.width.equalTo(40)
+            make.height.equalTo(148)
         }
         iconImageView.snp.makeConstraints { (make) in
             make.left.equalToSuperview().offset(40)
@@ -153,6 +157,14 @@ class ShoppingCartListTableViewCell: UITableViewCell {
         let selectedButton = UIButton(type: UIButton.ButtonType.custom)
         selectedButton.setImage(kImage(name: "common_uncheck_icon"), for: UIControl.State.normal)
         selectedButton.setImage(kImage(name: "common_check_icon"), for: UIControl.State.selected)
+        selectedButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            selectedButton.isSelected = !selectedButton.isSelected
+            if let productSelBlock = self?.productSelBlock {
+                let isSel: Int = selectedButton.isSelected == true ? 1 : 0
+                productSelBlock(isSel)
+            }
+        }).disposed(by: disposeBag)
+        
         return selectedButton
     }()
 

+ 8 - 6
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartList/ShoppingCartListTableViewHeader.swift

@@ -12,6 +12,9 @@ import RxCocoa
 
 class ShoppingCartListTableViewHeader: BaseView {
     
+    typealias SecSelectBlock = (_ isSecSelected: Int) -> Void
+    var secSelectBlock : SecSelectBlock?
+    
     var shopName : String? {
         didSet {
             titleButton.setTitle(shopName, for: UIControl.State.normal)
@@ -55,7 +58,6 @@ class ShoppingCartListTableViewHeader: BaseView {
         
         titleButton.snp.makeConstraints { (make) in
             make.left.equalToSuperview().offset(36)
-//            make.top.equalTo(separateView.snp_bottom).offset(14)
             make.centerY.equalToSuperview()
             make.height.equalTo(20)
         }
@@ -99,11 +101,11 @@ class ShoppingCartListTableViewHeader: BaseView {
         selectedButton.setImage(kImage(name: "common_check_icon"), for: UIControl.State.selected)
         selectedButton.rx.tap.subscribe(onNext: { [weak self] (data) in
             
-            //            if let loginBlock = self?.loginBlock {
-            //                loginBlock((self?.phoneNumber)!,(self?.password)!)
-            //            }
-            print("点击了全选当前section")
-            
+            selectedButton.isSelected = !selectedButton.isSelected
+            if let secSelectBlock = self?.secSelectBlock {
+                let isSectionSel: Int = selectedButton.isSelected == true ? 1 : 0
+                secSelectBlock(isSectionSel)
+            }
         }).disposed(by: disposeBag)
         return selectedButton
     }()

+ 12 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -52,6 +52,12 @@ class ShoppingCartView: BaseView {
     lazy var accountView: ShoppingCartAccountView = {
         let accountView = ShoppingCartAccountView()
         
+        accountView.allSelectBlock = {
+            (isAllSelected) in
+            
+            print("选中状态 -- \(isAllSelected)")
+        }
+        
         accountView.orderPayBlock = {
             [weak self] in
             if let orderPayTransBlock = self?.orderPayTransBlock {
@@ -119,6 +125,12 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
                 // 购物车列表Item
                 let cell = ShoppingCartListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
                 cell.productMdl = cartListModelArr![indexPath.section].productList![indexPath.row]
+                
+                cell.productSelBlock = {
+                    (isProductSel) in
+                    print("选中状态 -- \(isProductSel)")
+                }
+                
                 cell.changeProductBlock = {
                     (productId, type) in
                     SwiftMoyaNetWorkServiceProduct.shared().productCartAmountApi(id: productId, type: type, completion: { [weak self] (amountData) -> (Void) in

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/ViewController/ShoppingCartViewController.swift

@@ -49,7 +49,7 @@ class ShoppingCartViewController: BaseViewController {
             self?.productHotSaleApi(page: page)
         }
         
-        shoppingCartView.tableView.addFooterWithWithHeader(withAutomaticallyRefresh: true) { [weak self] (page) in
+        shoppingCartView.tableView.addFooterWithWithHeader(withAutomaticallyRefresh: false) { [weak self] (page) in
             self?.productHotSaleApi(page: page)
         }
     }