南鑫林 5 年 前
コミット
6c19bfb03e

+ 0 - 4
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductAllComment/View/ProductAllCommentView.swift

@@ -113,10 +113,6 @@ class ProductAllCommentView: BaseView {
         buyButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
         buyButton.backgroundColor = kFFA42FColor
         buyButton.titleLabel?.font = kRegularFont16
-        buyButton.rx.tap.subscribe(onNext: {
-            [weak self](data) in
-//            self?.productDetailSkuView()
-        }).disposed(by: disposeBag)
         return buyButton
     }()
 

+ 25 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/ProductDetailSkuView/ProductDetailSkuView.swift

@@ -352,7 +352,11 @@ class ProductDetailSkuView: FWPopupView {
     var productDetailModel : ProductDetailModel? {
         didSet {
             filter = ORSKUDataFilter.init(dataSource: self)
-            filter!.needDefaultValue = true
+            if productDetailSkuModel != nil {
+                selected()
+            }else {
+                defaultMainSelected()
+            }
             self.collectionView.reloadData()
             actionComplete()
             productImageView.kf.setImage(with: kURLImage(name: productDetailModel?.img ?? "pic_preload")
@@ -365,6 +369,25 @@ class ProductDetailSkuView: FWPopupView {
         }
     }
     
+    func defaultMainSelected() {
+        if !(self.productDetailModel?.sku?.isEmpty ?? true) { //skus是否为空
+            for (index,sku) in (self.productDetailModel?.sku)!.enumerated() {//便利skus
+                if sku.isMain == 1 {//sku是否是主规格
+                    filter?.defaultIndex = Int32(index)
+                }
+            }
+        }
+    }
+    func selected() {
+        if !(self.productDetailModel?.sku?.isEmpty ?? true) { //skus是否为空
+            for (index,sku) in (self.productDetailModel?.sku)!.enumerated() {//便利skus
+                if sku.id == productDetailSkuModel?.id {//sku是否是主规格
+                    filter?.defaultIndex = Int32(index)
+                }
+            }
+        }
+    }
+    
     func actionComplete() {
          let  productDetailSkuModel = filter?.currentResult as? ProductDetailSkuModel
         if productDetailSkuModel != nil {
@@ -384,6 +407,7 @@ class ProductDetailSkuView: FWPopupView {
         }
        
     }
+    
 
 }
 

+ 7 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/ProductDetailView.swift

@@ -441,12 +441,19 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
             if !(productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
                 if indexPath.row == 0 {
                     self.view.productDetailSkuViewType = ProductDetailSkuViewType.selectSku
+                    if self.productDetailSkuModel != nil {
+                        self.view.productDetailSkuModel = self.productDetailSkuModel
+                    }
                     self.view.productDetailModel = self.productDetailModel
+
                     self.view.show()
                 }
             }
             if !(productDetailModel?.spec?.isEmpty ?? true) && (productDetailModel?.label?.isEmpty ?? true) {
                 self.view.productDetailSkuViewType = ProductDetailSkuViewType.selectSku
+                if self.productDetailSkuModel != nil {
+                    self.view.productDetailSkuModel = self.productDetailSkuModel
+                }
                 self.view.productDetailModel = self.productDetailModel
                 self.view.show()
             }

+ 7 - 1
RainbowPlanet/RainbowPlanet/Tools/SKUDataFilter/ORSKUDataFilter.h

@@ -51,6 +51,8 @@
 
 @class ORSKUDataFilter;
 @class ORSKUProperty;
+@class ORSKUCondition;
+
 
 @protocol ORSKUDataFilterDataSource <NSObject>
 
@@ -79,7 +81,9 @@
 
 @end
 
-@interface ORSKUDataFilter : NSObject
+@interface ORSKUDataFilter : NSObject  {
+    ORSKUCondition *_defaultSku;
+}
 
 @property (nonatomic, assign) id<ORSKUDataFilterDataSource> dataSource;
 
@@ -92,6 +96,8 @@
 
 @property (nonatomic, assign) BOOL needDefaultValue;
 
+@property (nonatomic, assign) int defaultIndex;
+
 //init
 - (instancetype)initWithDataSource:(id<ORSKUDataFilterDataSource>)dataSource;
 

+ 10 - 3
RainbowPlanet/RainbowPlanet/Tools/SKUDataFilter/ORSKUDataFilter.m

@@ -8,9 +8,7 @@
 
 #import "ORSKUDataFilter.h"
 
-@interface ORSKUDataFilter() {
-    ORSKUCondition *_defaultSku;
-}
+@interface ORSKUDataFilter()
 
 @property (nonatomic, strong) NSSet <ORSKUCondition *> *conditions;
 
@@ -129,6 +127,10 @@
             _defaultSku = model;
         }
         
+        if (self.defaultIndex == i && !_defaultSku) {
+            _defaultSku = model;
+        }
+        
         [modelSet addObject:model];
     }
     _conditions = [modelSet copy];
@@ -342,6 +344,11 @@
     [self reloadData];
 }
 
+- (void)setDefaultIndex:(int)defaultIndex {
+    _defaultIndex = defaultIndex;
+    [self reloadData];
+}
+
 @end
 
 @implementation ORSKUCondition