Explorar el Código

购物车,异常状态商品全选处理fix

Chris hace 6 años
padre
commit
5ba1ec958f

+ 21 - 12
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartList/ShoppingCartListTableViewCell.swift

@@ -26,11 +26,11 @@ class ShoppingCartListTableViewCell: UITableViewCell {
         didSet {
             // 已下架
             if productMdl?.upStatus == 0 {
-                self.resetButtonWithTitle("已下架")
+                self.resetDisableWithTitle("已下架")
             }
             // 已售罄
             if productMdl?.stock == 0 {
-                self.resetButtonWithTitle("已售罄")
+                self.resetDisableWithTitle("已售罄")
             }
             
             // 选中状态
@@ -82,6 +82,7 @@ class ShoppingCartListTableViewCell: UITableViewCell {
         self.selectionStyle = .none
         backgroundColor = kf7f8faColor
         addSubview(bgView)
+        bgView.addSubview(disableLabel)
         bgView.addSubview(selectedButton)
         bgView.addSubview(iconImageView)
         bgView.addSubview(titleLabel)
@@ -101,12 +102,15 @@ class ShoppingCartListTableViewCell: UITableViewCell {
             make.right.equalTo(-14 * kScaleWidth)
             make.height.equalTo(148)
         }
-        selectedButton.snp.makeConstraints { (make) in
+        disableLabel.snp.makeConstraints { (make) in
             make.left.equalToSuperview()
             make.top.equalTo(50)
             make.width.equalTo(36)
             make.height.equalTo(20)
         }
+        selectedButton.snp.makeConstraints { (make) in
+            make.edges.equalTo(disableLabel.snp_edges)
+        }
         iconImageView.snp.makeConstraints { (make) in
             make.left.equalToSuperview().offset(40)
             make.centerY.equalToSuperview()
@@ -158,20 +162,15 @@ class ShoppingCartListTableViewCell: UITableViewCell {
         
     }
     
-    private func resetButtonWithTitle(_ title: String) {
+    private func resetDisableWithTitle(_ title: String) {
         deliveryTime.isHidden = true
         plusButton.isHidden = true
         numberLabel.isHidden = true
         reduceButton.isHidden = true
         
-        selectedButton.setImage(kImage(name: ""), for: UIControl.State.normal)
-        selectedButton.setTitle(title, for: .normal)
-        selectedButton.setTitleColor(k333333Color, for: .normal)
-        selectedButton.titleLabel?.font = kRegularFont10
-        selectedButton.backgroundColor = kf5f5f5Color
-        selectedButton.cornerRadius = 10
-        selectedButton.masksToBounds = true
-        selectedButton.isUserInteractionEnabled = false
+        disableLabel.text = title
+        disableLabel.isHidden = false
+        selectedButton.isHidden = true
     }
     
     private lazy var selectedButton: UIButton = {
@@ -188,6 +187,16 @@ class ShoppingCartListTableViewCell: UITableViewCell {
         
         return selectedButton
     }()
+    
+    private lazy var disableLabel: UILabel = {
+        let disableLabel = UILabel()
+        disableLabel.textColor = k333333Color
+        disableLabel.font = kRegularFont10
+        disableLabel.backgroundColor = kf5f5f5Color
+        disableLabel.cornerRadius = 10
+        disableLabel.masksToBounds = true
+        return disableLabel
+    }()
 
     private lazy var iconImageView: UIImageView = {
         let iconImageView = UIImageView()

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

@@ -378,7 +378,10 @@ extension ShoppingCartView {
     func allSelectedAction(_ isSelected: Int) {
         for cartProListMdl in cartListModelArr ?? [] {
             for productMdl in cartProListMdl.productList! {
-                productMdl.isSelect = isSelected
+                // 已售罄/下架商品不改变选中状态
+                if productMdl.upStatus != 0 && productMdl.stock != 0 {
+                    productMdl.isSelect = isSelected
+                }
             }
         }
         tableView.reloadData()
@@ -388,7 +391,10 @@ extension ShoppingCartView {
     func shopSelectedAction(_ isSelected: Int, section: Int) {
         let cartProListMdl: CartProductListModel = cartListModelArr![section]
         for productMdl in cartProListMdl.productList! {
-            productMdl.isSelect = isSelected
+            // 已售罄/下架商品不改变选中状态
+            if productMdl.upStatus != 0 && productMdl.stock != 0 {
+                productMdl.isSelect = isSelected
+            }
         }
         self.tableView.reloadSections([section], with: UITableView.RowAnimation.none)
         self.judgeAllSelectedStatus()