Browse Source

feat:推荐商品数据联调、逻辑处理

“wangdongchao” 1 năm trước cách đây
mục cha
commit
9522510f5b
23 tập tin đã thay đổi với 351 bổ sung85 xóa
  1. 19 2
      Asteria/Fuction/Cart/Cart_CheckoutC.m
  2. 4 1
      Asteria/Fuction/Cart/Cart_MyCartC.m
  3. 4 0
      Asteria/Fuction/Cart/M/ASCheckoutModel.h
  4. 2 0
      Asteria/Fuction/Cart/VM/CartVM.h
  5. 12 1
      Asteria/Fuction/Goods/Revies/V/ReviewsTableHearV.m
  6. 2 0
      Asteria/Fuction/Goods/V/ASGoodsDetailsSizeCell.h
  7. 10 8
      Asteria/Fuction/Goods/V/ASGoodsDetailsSizeCell.m
  8. 17 10
      Asteria/Fuction/Goods/V/ASGoodsDetailsTableView.m
  9. 83 14
      Asteria/Fuction/Goods/VC/ASGoodsDetailsViewController.m
  10. 9 1
      Asteria/Fuction/Goods/VC/AS_GoodsSizeC.m
  11. 2 0
      Asteria/Fuction/Goods/VM/ASGoodsDetailsVM.h
  12. 3 0
      Asteria/Fuction/Goods/VM/ASGoodsDetailsVM.m
  13. 2 2
      Asteria/Fuction/Login/VC/AS_LoginC.m
  14. 34 11
      Asteria/Fuction/UserCenter/UserCenterHome/ASUserCenterViewController.m
  15. 4 0
      Asteria/Fuction/UserCenter/UserCenterHome/ASUserCenterViewModel.h
  16. 13 0
      Asteria/Fuction/UserCenter/UserCenterHome/ASUserCenterViewModel.m
  17. 1 1
      Asteria/Fuction/UserCenter/UserCenterHome/models/HomeFilterModel.h
  18. 7 6
      Asteria/Fuction/UserCenter/UserCenterHome/models/HomeFilterModel.m
  19. 2 0
      Asteria/Fuction/UserCenter/UserCenterHome/models/KWMineMoreProductModel.h
  20. 8 1
      Asteria/Fuction/UserCenter/UserCenterHome/models/KWMineMoreProductModel.m
  21. 11 2
      Asteria/Fuction/UserCenter/UserCenterHome/views/KWMineMoreProductsCell.h
  22. 97 25
      Asteria/Fuction/UserCenter/UserCenterHome/views/KWMineMoreProductsCell.m
  23. 5 0
      Asteria/NetTools/ASNetApis.h

+ 19 - 2
Asteria/Fuction/Cart/Cart_CheckoutC.m

@@ -218,7 +218,7 @@
             [self reqNet_Cart_cartsMineTotals];
         }
         
-    } else if ([mark isEqualToString:Chectout_getShipMethod]) {
+    } else if ([mark isEqualToString:Chectout_getShipMethod] || [mark isEqualToString:Chectout_addBillingAddress]) {
         
         if(sucessOrFail){
             NSArray *shipMethodArr = (NSArray *)data;
@@ -235,6 +235,8 @@
                     [self requestSetShipMethodByAddress];
                 }
             }
+        }else{
+            [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
         }
         [self updateData];
         
@@ -386,6 +388,7 @@
             self.addressCellM.addressModel = addressM;
             
             [self requestAddShipAddress];
+//            [self requestAddBillingAddress];
         };
         [self.navigationController pushViewController:vc animated:true];
     }
@@ -401,6 +404,20 @@
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
     [self.VM ry_requestPostApi:Chectout_addShipAddress_id param:@{@"addressId":self.addressCellM.addressModel.Id}];
 }
+//添加账单地址
+- (void)requestAddBillingAddress {
+    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
+    
+    NSDictionary *addressDic1 = (NSDictionary *)[self.addressCellM.addressModel.region mj_JSONObject];
+    NSDictionary *addressDic = (NSDictionary *)[self.addressCellM.addressModel mj_JSONObject];
+    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:addressDic];
+    [param addEntriesFromDictionary:addressDic1];
+    
+    [param removeObjectForKey:@"extension_attributes"];//移除格式不正确的无用参数
+    
+    
+    [self.VM ry_requestPostApi:Chectout_addBillingAddress param:@{@"address":param, @"useForShipping":@"true"}];
+}
 //根据邮寄地址获取邮寄方式
 - (void)requestGetShipMethodByAddress {
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
@@ -417,7 +434,7 @@
     [param removeObjectForKey:@"extension_attributes"];//移除格式不正确的无用参数
     
     if (NIL(self.shipmethodCellM.shipMethodModel.method_code) || NIL(self.shipmethodCellM.shipMethodModel.carrier_code)) {
-        [self.view makeToast:@"运输方式获取失败"];
+        [self.view makeToast:self.shipmethodCellM.shipMethodModel.error_message];
         return;
     }
     

+ 4 - 1
Asteria/Fuction/Cart/Cart_MyCartC.m

@@ -57,6 +57,9 @@
 }
 -(void)viewWillAppear:(BOOL)animated{
     [super viewWillAppear:animated];
+    
+    self.addGiftView.hidden = YES;
+    
     [self reqNet_Cart_cartsMineTotals];
     
 }
@@ -432,7 +435,7 @@
             }
         };
         _addGiftView.hidden = YES;
-        [[UIApplication sharedApplication].keyWindow addSubview:_addGiftView];
+        [self.view addSubview:_addGiftView];
     }
     return _addGiftView;
 }

+ 4 - 0
Asteria/Fuction/Cart/M/ASCheckoutModel.h

@@ -32,6 +32,10 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, copy) NSString *method_code;
 @property (nonatomic, assign) BOOL isSelect;
 
+@property (nonatomic, copy) NSString *error_message;
+
+
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 2 - 0
Asteria/Fuction/Cart/VM/CartVM.h

@@ -28,6 +28,8 @@
 #define Chectout_getPaymentMode      BaseRequestrUrl(@"carts/mine/payment-methods")
 //添加邮寄地址
 #define Chectout_addShipAddress_id   BaseRequestrUrl(@"carts/mine/estimate-shipping-methods-by-address-id")
+//添加账单地址
+#define Chectout_addBillingAddress   BaseRequestrUrl(@"carts/mine/billing-address")
 //根据邮寄地址获取邮寄方式
 #define Chectout_getShipMethod       BaseRequestrUrl(@"carts/mine/shipping-methods")
 //根据邮寄地址设置邮寄方式

+ 12 - 1
Asteria/Fuction/Goods/Revies/V/ReviewsTableHearV.m

@@ -18,7 +18,12 @@
 @end
 @implementation ReviewsTableHearV
 +(CGFloat)xxx_viewHeight{
-    return  10+86+10+34+40;
+    if ([ASUserInfoManager shared].isLogin) {
+        return  10+86+10+34;
+    } else {
+        return  10+86+10+34+40;
+    }
+    
 }
 
 - (void)tt_setupViews{
@@ -74,6 +79,12 @@
 - (void)tt_confignewdata:(id)data{
     GoodsInformationM *model = (GoodsInformationM *)data;
     self.reviewsLab.text = [NSString stringWithFormat:@"(%@ Reviews)",model.review_nums];
+    
+    if ([ASUserInfoManager shared].isLogin) {
+        self.tipsLab.hidden = YES;
+    } else {
+        self.tipsLab.hidden = NO;
+    }
 }
 #pragma mark - **************** handle ****************
 -(void)handle_writeEvent:(UIButton *)btn{

+ 2 - 0
Asteria/Fuction/Goods/V/ASGoodsDetailsSizeCell.h

@@ -14,6 +14,8 @@ typedef void(^ASGoodsDetailsSizeBlock)(NSArray<OptionsModel *> *optionArr, NSInt
 
 @interface ASGoodsDetailsSizeCell : TT_BaseCell
 
+@property (nonatomic, strong) GoodsInformationM *model;
+
 @property (nonatomic, copy) ASGoodsDetailsSizeBlock sizeBlock;
 
 @end

+ 10 - 8
Asteria/Fuction/Goods/V/ASGoodsDetailsSizeCell.m

@@ -78,17 +78,19 @@
 
 - (void)configData:(id)Data{
     
-    GoodsInformationM *model = (GoodsInformationM *)Data;
+    _model = (GoodsInformationM *)Data;
+    
+    NSArray *modelAry  = _model.options;
+    
     
-    NSArray *modelAry  = model.options;
 
     for (OptionsModel *m in modelAry) {
         m.isLongValue = false;
-        if (m.is_require.boolValue) {
-            m.optionSelectTag = 0;
-        } else {
-            m.optionSelectTag = -1;
-        }
+//        if (m.is_require.boolValue) {
+//            m.optionSelectTag = 0;
+//        } else {
+//            m.optionSelectTag = -1;
+//        }
         for (OptionsValuesM *val in m.values) {
             if (val.title.length > 7) {
                 m.isLongValue = true;
@@ -98,7 +100,7 @@
     }
     self.sizeV.optionArr = modelAry;
     
-    self.sizeV.tipStr = model.description;
+    self.sizeV.tipStr = _model.description;
 }
 
 

+ 17 - 10
Asteria/Fuction/Goods/V/ASGoodsDetailsTableView.m

@@ -149,21 +149,28 @@
         };
         return cell;
     } else if ([typeStr isEqualToString:@"customer"]) {
-        KWMineMoreProductModel *model =  (KWMineMoreProductModel *)objectM;
+        NSArray *typeArr =  (NSArray *)objectM;
 //        KWMineMoreProductsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KWMineMoreProductsCell" forIndexPath:indexPath];
         KWMineMoreProductsCell *cell = [[KWMineMoreProductsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"KWMineMoreProductsCell"];
         
         cell.topSpace = 20;
 //        KWMineMoreProductModel * model = [KWMineMoreProductModel demoData];
-        [cell setData: model];
-        @weakify(self);
-        [cell setProductClick:^(NSInteger i, ASProductBaseModel *m) {
-    //        if (![weak_self checkLogin:true]) {
-    //            return;
-    //        }
-           // 点击推荐商品
-    //        [weak_self goto_WKM_GoodsDetailsC:m.Id];
-        }];
+//        [cell setData: model];
+        
+        [cell setTypeArray:typeArr];
+        
+        K_WEAK_SELF;
+        cell.productBlock = ^(ASProductBaseModel * _Nonnull model) {
+            K_STRONG_SELF;
+            [self generaltriggermethodType:101 data:model];
+        };
+        
+        cell.addCartBlock = ^(ASProductBaseModel * _Nonnull model) {
+            K_STRONG_SELF;
+            [self generaltriggermethodType:102 data:model];
+        };
+        
+        
         return cell;
     }
     

+ 83 - 14
Asteria/Fuction/Goods/VC/ASGoodsDetailsViewController.m

@@ -20,6 +20,8 @@
 #import "GoodsReviewsListM.h"
 #import "KWMineMoreProductModel.h"
 
+#import "ASProductBaseModel.h"
+
 
 
 @interface ASGoodsDetailsViewController ()<RY_baseVMprotocol>
@@ -32,6 +34,8 @@
 
 //评论数据
 @property (nonatomic, strong) NSArray *reviewDataArray;;
+//推荐商品数据
+@property (nonatomic, strong) NSArray *recommendGoodsArr;;
 
 @property (nonatomic, strong)  UIView *footView;
 
@@ -51,11 +55,13 @@
 
 - (void)viewDidLoad {
     [super viewDidLoad];
-    
+        
     [self reqNet_Goods_productGetProductsReview];
     
     [self reqNet_GoodsDetails_productGetProduct];
     
+    [self request_RecommendGoodsData];
+    
 }
 
 - (void)_shareClick {
@@ -110,6 +116,10 @@
             [self.TableV reloadData];
 //            [self updateGoodsDetailsData];
         } else if (num == 4) {//写商品评论
+            if (![ASUserInfoManager shared].isLogin) {
+                [Fuction_Tool pop_toLoginVC];
+                return;
+            }
             GoodsReviewsWriteC *vc = [[GoodsReviewsWriteC alloc]init];
             vc.goodsM = self.model;
 //            vc.topBgV = self.topBgV;
@@ -117,14 +127,52 @@
             [self.navigationController pushViewController:vc animated:YES];
         } else if (num == 100) {
             self.sizeParam = (NSDictionary *)data;
+        } else if (num == 101) {//推荐商品跳转
+            ASProductBaseModel *model = (ASProductBaseModel *)data;
+            UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":model.Id}];
+            [self.navigationController pushViewController:viewController animated:YES];
+        } else if (num == 102) {//推荐商品加车
+            ASProductBaseModel *model = (ASProductBaseModel *)data;
+            [self action_GoodsSizeC:model.Id];
         } else if (num == 1000) {
             [self.TableV reloadData];
         }
+        
     };
-    
+}
+
+//请求尺寸
+-(void)action_GoodsSizeC:(NSString *)entity_id {
+    if (!ASUserInfoManager.shared.isLogin) {
+        [Fuction_Tool pop_toLoginVC];
+        return;
+    }
+    NSMutableDictionary *params = [NSMutableDictionary dictionary];
+    [params setObject:entity_id forKey:@"productId"];
+    [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
+    [MBProgressHUD showHUDAddedTo:self.view animated:true];
+    __weak typeof(self) weakSelf = self;
+    [ASNetTools.shared getWithPath:getProdectDetail param:params success:^(id _Nonnull json) {
+        [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
+        GoodsInformationM *model = [GoodsInformationM mj_objectWithKeyValues:json];
+        if (model == nil || model.Id == nil || model.Id.isEmpty) {
+            return;
+        }
+        UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsSizeC:@{@"model":model}];
+        viewController.modalPresentationStyle = UIModalPresentationFullScreen;
+        [weakSelf presentViewController:viewController animated:YES completion:nil];
+    } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
+        [self.view makeToast:msg];
+        [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
+    }];
 }
 
 -(void)reqNet_Size_rewriteCartAddProducts {
+    
+    if (![ASUserInfoManager shared].isLogin) {
+        [Fuction_Tool pop_toLoginVC];
+        return;
+    }
         
     if (!AS_Dict_valid(self.sizeParam)) {
         NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
@@ -149,7 +197,7 @@
     NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
 //    [params setObject:@"55475" forKey:@"productId"];
     [params setObject:self.entity_id forKey:@"productId"];
-    [params setObject:@"USD" forKey:@"currencyCode"];
+    [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
     [self.VM ry_requestGetApi:Goods_productGetProductsById param:params];
 }
@@ -163,14 +211,22 @@
     [params setObject:@3 forKey:@"limit"];
     [self.VM ry_requestGetApi:Goods_productGetProductsReview param:params];
 }
+//推荐商品
+- (void)request_RecommendGoodsData {
+    [self.VM ry_requestGetApi:Goods_RecommendGoods param:@{}];
+}
+
 -(void)ry_respnsData:(nullable id)data
             parseAry:(nullable NSMutableArray *)arry
               sucess:(BOOL)sucessOrFail
                 mark:(NSString *)mark
           reqNetType:(ReqNetType)reqNetType{
-    [MBProgressHUD hideHUDForView:self.view animated:YES];
+    
     if(sucessOrFail){
         if([mark isEqualToString:Goods_productGetProductsById]){
+            
+            [MBProgressHUD hideHUDForView:self.view animated:YES];
+            
             GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
             self.model = model;
             self.title = model.name;
@@ -181,6 +237,8 @@
             
         } else if([mark isEqualToString:Size_rewriteCartAddProducts]) {
             
+            [MBProgressHUD hideHUDForView:self.view animated:YES];
+            
             [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
                 if (self.bottomClickType == 1) {
                     Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
@@ -189,14 +247,19 @@
             }];
         } else if ([mark isEqualToString:Goods_productGetProductsReview]) {
             
-//            [self.TableV configDataNew:arry has_more:arry.count==10 ? YES : NO];
-            
             self.reviewDataArray = arry;
+            if (self.model) {
+                [self updateGoodsDetailsData];
+            }
+        } else if ([mark isEqualToString:Goods_RecommendGoods]) {
             
+            self.recommendGoodsArr = arry;
             if (self.model) {
                 [self updateGoodsDetailsData];
             }
         }
+    } else {
+        [MBProgressHUD hideHUDForView:self.view animated:YES];
     }
 }
 
@@ -221,15 +284,21 @@
     //评论头
     NSDictionary *reviewHead = @{@"type":@"reviewHead", @"data":self.model};
     [self.TableV.infodata addObject:reviewHead];
-    //评论数据
-    [self.TableV.infodata addObjectsFromArray:self.reviewDataArray];
-    //评论底部
-    NSDictionary *reviewFoot = @{@"type":@"reviewFoot", @"data":self.model};
-    [self.TableV.infodata addObject:reviewFoot];
+    
+    if (AS_Array_valid(self.reviewDataArray)) {
+        //评论数据
+        [self.TableV.infodata addObjectsFromArray:self.reviewDataArray];
+        //评论底部
+        NSDictionary *reviewFoot = @{@"type":@"reviewFoot", @"data":self.model};
+        [self.TableV.infodata addObject:reviewFoot];
+    }
+    
     //推荐商品
-    KWMineMoreProductModel *model = [KWMineMoreProductModel demoData];
-    NSDictionary *customer = @{@"type":@"customer", @"data":model};
-    [self.TableV.infodata addObject:customer];
+    if (AS_Array_valid(self.recommendGoodsArr)) {
+        NSDictionary *customer = @{@"type":@"customer", @"data":self.recommendGoodsArr};
+        [self.TableV.infodata addObject:customer];
+    }
+    
     
 //    if (self.isReview) {
 //        

+ 9 - 1
Asteria/Fuction/Goods/VC/AS_GoodsSizeC.m

@@ -111,7 +111,15 @@
     
 }
 -(void)configFreshData:(GoodsInformationM *)model{
-    [self.sel_headImg sd_setImageWithURL:[NSURL URLWithString:model.add_gooodsImgUrl] placeholderImage:UIImageDefaultImg_SD];
+    
+    NSArray *media_gallery_entries = model.media_gallery_entries;
+    NSString *imageUrl = @"";
+    if (AS_Array_valid(media_gallery_entries)) {
+        MediaGalleryEntriesModel *model = media_gallery_entries.firstObject;
+        imageUrl =  [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,model.file];
+    }
+    
+    [self.sel_headImg sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:UIImageDefaultImg_SD];
     self.sel_titleLab.text = model.name;
     self.priceLab.attributedText = [ASGoodsDetailsVM tool_changePriceAtr:model];
     if(model.final_prices == model.price){

+ 2 - 0
Asteria/Fuction/Goods/VM/ASGoodsDetailsVM.h

@@ -8,10 +8,12 @@
 #import "RYBaseVM.h"
 #import "GoodsInformationM.h"
 #import "GoodsReviewsListM.h"
+#import "HomeFilterModel.h"
 
 #define Goods_productGetProductsById  BaseRequestrUrl(@"rewrite/product/getProductsById")
 #define Goods_productGetProductsReview  BaseRequestrUrl(@"rewrite/product/getProductReview")
 
+
 ///评论点赞
 #define Reviews_rewriteProductAddReviewzan BaseRequestrUrl(@"rewrite/product/addReviewzan")
 ///添加评论图片

+ 3 - 0
Asteria/Fuction/Goods/VM/ASGoodsDetailsVM.m

@@ -17,6 +17,9 @@
     }else if ([mark isEqualToString:Goods_productGetProductsReview]){
         NSMutableArray <GoodsReviewsListM *>*array = [GoodsReviewsListM mj_objectArrayWithKeyValuesArray:data[@"items"]];
         [self ry_VMconfigDelegateData:data parseAry:array success:YES mark:mark reqNetType:reqNetType];
+    }else if ([mark isEqualToString:Goods_RecommendGoods]){
+        NSMutableArray <HomeFilterModel *>*array = [HomeFilterModel mj_objectArrayWithKeyValuesArray:data];
+        [self ry_VMconfigDelegateData:data parseAry:array success:YES mark:mark reqNetType:reqNetType];
     }else{
         [self ry_VMconfigDelegateData:data parseAry:[NSMutableArray array] success:YES mark:mark reqNetType:reqNetType];
     }

+ 2 - 2
Asteria/Fuction/Login/VC/AS_LoginC.m

@@ -254,7 +254,7 @@
 -(EamilTFmatchV *)xxx_emailTFV{
     if (!_xxx_emailTFV) {
         _xxx_emailTFV = [[EamilTFmatchV alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)];
-//        _xxx_emailTFV.xxx_emailTF.text = @"845600348@qq.com";
+        _xxx_emailTFV.xxx_emailTF.text = @"845600348@qq.com";
     }
     return _xxx_emailTFV;
 }
@@ -263,7 +263,7 @@
 - (PassWordSecureBtnV *)xxx_passwordV {
     if (!_xxx_passwordV) {
         _xxx_passwordV = [[PassWordSecureBtnV alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(self.xxx_emailTFV.frame)+30, KScreenWidth-40, 50+20)];
-//        _xxx_passwordV.xxx_passwordTF.text = @"nuli322103";
+        _xxx_passwordV.xxx_passwordTF.text = @"nuli322103";
     }
     return _xxx_passwordV;
 }

+ 34 - 11
Asteria/Fuction/UserCenter/UserCenterHome/ASUserCenterViewController.m

@@ -30,6 +30,8 @@
 
 @property (nonatomic, strong) NSArray<KWMineHomeOrderModel *> *orderArr;
 
+@property (nonatomic, strong) NSArray *recommendGoodsArr;
+
 @end
 
 @implementation ASUserCenterViewController
@@ -37,6 +39,10 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     self.vm = [ASUserCenterViewModel new];
+    
+    //获取推荐商品
+    [self getRecommendGoodsData];
+    
     [self configSubVs];
     [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(setData) name:UserInfoUpdate object:nil];
     
@@ -55,16 +61,27 @@
 }
 
 - (void)getOrders {
+    K_WEAK_SELF;
     [self.vm getAllOrderNet:^(NSArray<KWMineHomeOrderModel *> * _Nonnull arr) {
+        K_STRONG_SELF;
         self.orderArr = arr;
         [self.tableV reloadData];
     }];
 }
 
+- (void)getRecommendGoodsData {
+    K_WEAK_SELF;
+    [self.vm getRecommmendGoodsData:^(NSArray<HomeFilterModel *> * _Nonnull array) {
+        K_STRONG_SELF;
+        self.recommendGoodsArr = array;
+        [self.tableV reloadData];
+    }];
+}
+
 
 // MARK: - subVs
 - (void)configSubVs {
-    __block typeof(self) wSelf = self;
+//    __block typeof(self) wSelf = self;
     [self ucHomeStyle:^{
         
     }];
@@ -179,16 +196,22 @@
     }
     KWMineMoreProductsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KWMineMoreProductsCell" forIndexPath:indexPath];
     cell.topSpace = 20;
-    KWMineMoreProductModel * model = [KWMineMoreProductModel demoData];
-    [cell setData: model];
-    @weakify(self);
-    [cell setProductClick:^(NSInteger i, ASProductBaseModel *m) {
-//        if (![weak_self checkLogin:true]) {
-//            return;
-//        }
-       // 点击推荐商品
-//        [weak_self goto_WKM_GoodsDetailsC:m.Id];
-    }];
+    [cell setTypeArray:self.recommendGoodsArr];
+    
+    K_WEAK_SELF;
+    cell.productBlock = ^(ASProductBaseModel * _Nonnull model) {
+        K_STRONG_SELF;
+//        [self goto_WKM_GoodsDetailsC:model.Id];
+        UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":model.Id}];
+        [self.navigationController pushViewController:viewController animated:YES];
+    };
+    
+    cell.addCartBlock = ^(ASProductBaseModel * _Nonnull model) {
+        K_STRONG_SELF;
+        [self action_GoodsSizeC:model.Id];
+    };
+    
+    
     return cell;
 }
 

+ 4 - 0
Asteria/Fuction/UserCenter/UserCenterHome/ASUserCenterViewModel.h

@@ -7,6 +7,7 @@
 
 #import <Foundation/Foundation.h>
 #import "KWMineHomeOrderModel.h"
+#import "HomeFilterModel.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
@@ -14,6 +15,9 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)getAllOrderNet:(void(^)(NSArray<KWMineHomeOrderModel *> *))com;
 
+//获取推荐商品列表(分类)
+- (void)getRecommmendGoodsData:(void(^)(NSArray<HomeFilterModel *> * array))complete;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 13 - 0
Asteria/Fuction/UserCenter/UserCenterHome/ASUserCenterViewModel.m

@@ -32,4 +32,17 @@
     }];
 }
 
+- (void)getRecommmendGoodsData:(void(^)(NSArray<HomeFilterModel *> *array))complete {
+    
+    [ASNetTools.shared getWithPath:Goods_RecommendGoods param:@{} success:^(id _Nonnull json) {
+        
+        NSMutableArray <HomeFilterModel *>*array = [HomeFilterModel mj_objectArrayWithKeyValuesArray:json];
+        
+        complete(array);
+        
+    } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
+        complete(@[]);
+    }];
+}
+
 @end

+ 1 - 1
Asteria/Fuction/UserCenter/UserCenterHome/models/HomeFilterModel.h

@@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, copy) NSString *typeId;
 @property (nonatomic, assign) int selected;
 
-@property (nonatomic, strong) NSArray<ASProductBaseModel *> *list;
+@property (nonatomic, strong) NSArray<ASProductBaseModel *> *product;
 
 
 

+ 7 - 6
Asteria/Fuction/UserCenter/UserCenterHome/models/HomeFilterModel.m

@@ -9,17 +9,18 @@
 
 @implementation HomeFilterModel
 
-//+ (NSDictionary *)mj_replacedKeyFromPropertyName {
-//    return @{
-//        @"typeId": @"typeid",
-//    };
-//}
++ (NSDictionary *)mj_replacedKeyFromPropertyName {
+    return @{
+        @"typeId": @"id",
+        @"title": @"name"
+    };
+}
 
 + (NSDictionary *)mj_objectClassInArray{
     
     return @{
         
-        @"list" : [ASProductBaseModel class]
+        @"product" : [ASProductBaseModel class]
         
     };
     

+ 2 - 0
Asteria/Fuction/UserCenter/UserCenterHome/models/KWMineMoreProductModel.h

@@ -14,6 +14,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic, copy) NSString *title;
 
+@property (nonatomic, copy) NSString *Id;
+
 @property (nonatomic, strong) NSArray<HomeFilterModel *> *keysArr;
 
 + (KWMineMoreProductModel *)demoData;

+ 8 - 1
Asteria/Fuction/UserCenter/UserCenterHome/models/KWMineMoreProductModel.m

@@ -9,6 +9,13 @@
 
 @implementation KWMineMoreProductModel
 
++ (NSDictionary *)mj_replacedKeyFromPropertyName {
+    return @{
+        @"Id": @"id",
+        @"title": @"name"
+    };
+}
+
 + (KWMineMoreProductModel *)demoData {
     KWMineMoreProductModel *m = [[KWMineMoreProductModel alloc] init];
     m.title = @"CUSTOMERS ALSO VIEWED";
@@ -23,7 +30,7 @@
         for (int i = 0; i<count; i++) {
             [arr addObject: [ASProductBaseModel demoModel] ];
         }
-        temp.list = arr;
+        temp.product = arr;
         [tempArr addObject:temp];
     }
     

+ 11 - 2
Asteria/Fuction/UserCenter/UserCenterHome/views/KWMineMoreProductsCell.h

@@ -8,9 +8,14 @@
 #import <UIKit/UIKit.h>
 #import "KWScrollOffsetView.h"
 #import "KWMineMoreProductModel.h"
+#import "ASProductBaseModel.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
+typedef void(^ASGoodsClickBlock)(ASProductBaseModel *model);
+
+typedef void(^ASGoodsAddCartBlock)(ASProductBaseModel *model);
+
 @interface KWMineMoreProductsCell : UITableViewCell
 
 @property (nonatomic, assign) CGFloat topSpace;
@@ -22,9 +27,13 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic, strong) KWScrollOffsetView *offsetV;
 
-@property (nonatomic, strong) KWMineMoreProductModel *model;
+//@property (nonatomic, strong) KWMineMoreProductModel *model;
+
+@property (nonatomic, strong) NSArray *typeArray;
+
+@property (nonatomic, copy) ASGoodsClickBlock productBlock;
 
-@property (nonatomic, copy) void(^productClick)(NSInteger i, ASProductBaseModel *m);
+@property (nonatomic, copy) ASGoodsAddCartBlock addCartBlock;
 
 //
 -(void)setData:(KWMineMoreProductModel *)model;

+ 97 - 25
Asteria/Fuction/UserCenter/UserCenterHome/views/KWMineMoreProductsCell.m

@@ -29,26 +29,49 @@
     }];
 }
 
--(void)setData:(KWMineMoreProductModel *)model {
-    self.model = model;
-    for (HomeFilterModel *type in self.model.keysArr) {
-        if (type.selected) {
-            self.currentKey = type;
+- (void)setTypeArray:(NSArray *)typeArray {
+    _typeArray = typeArray;
+    
+    for (int i = 0; i < _typeArray.count; i++) {
+        HomeFilterModel *model = _typeArray[i];
+        if (model.selected) {
+            self.currentKey = model;
+            break;
         }
     }
+    
     if (!self.currentKey) {
-        self.currentKey = self.model.keysArr.firstObject;
+        self.currentKey = self.typeArray.firstObject;
+        self.currentKey.selected = YES;
     }
-    self.titleLb.text = self.model.title;
+    
+    self.titleLb.text = self.currentKey.title;
+    
     [self calulateItemWidth];
     [self.typeCollectV reloadData];
     [self.collectV reloadData];
 }
 
+//-(void)setData:(KWMineMoreProductModel *)model {
+//    self.model = model;
+//    for (HomeFilterModel *type in self.model.keysArr) {
+//        if (type.selected) {
+//            self.currentKey = type;
+//        }
+//    }
+//    if (!self.currentKey) {
+//        self.currentKey = self.model.keysArr.firstObject;
+//    }
+//    self.titleLb.text = self.model.title;
+//    [self calulateItemWidth];
+//    [self.typeCollectV reloadData];
+//    [self.collectV reloadData];
+//}
+
 -(void)calulateItemWidth {
     NSMutableArray<NSNumber *> *tempArr = [NSMutableArray array];
     NSDictionary *attribute = @{NSFontAttributeName: self.titleLb.font};
-    for (HomeFilterModel *typeM in self.model.keysArr) {
+    for (HomeFilterModel *typeM in self.typeArray) {
         NSString *key = typeM.title;
         CGFloat wid = [key boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 34) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size.width + 10;
 //        CGFloat wid = [key widthForFont:[UIFont fontWithName:Rob_Regular size:12]]  + 10;
@@ -72,7 +95,7 @@
             }
             if (i == tempArr.count - 1) {
                 tempArr[i] = [NSNumber numberWithFloat: maxWid];
-                break;
+//                break;
             }
             totalWid = tempW;
             lineBeginI = i;
@@ -236,7 +259,7 @@
     }
     CGFloat offset = scrollView.contentOffset.x;
     CGFloat itemWidth = (KScreenWidth-30)/2;
-    NSArray<ASProductBaseModel*> *arr = self.currentKey.list;
+    NSArray<ASProductBaseModel*> *arr = self.currentKey.product;
     if (arr.count > 0) {
         CGFloat maxOffset = (arr.count * (itemWidth + 10) - 10 ) - (KScreenWidth-20);
         self.offsetV.offset = offset/maxOffset;
@@ -245,45 +268,94 @@
 
 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
     if (collectionView == self.typeCollectV) {
-        for (int i = 0; i < self.model.keysArr.count; i++) {
-            HomeFilterModel *item = self.model.keysArr[i];
-            item.selected = i == indexPath.row;
+        
+        for (int i = 0; i < self.typeArray.count; i++) {
+            HomeFilterModel *item = self.typeArray[i];
+            if (indexPath.row == i) {
+                item.selected = YES;
+                
+                if (item.product.count > 0) {
+                    self.currentKey = item;
+                    [self.typeCollectV reloadData];
+                    [self.collectV reloadData];
+                } else {
+                    [self requestTypeData:item index:indexPath.row];
+                }
+                
+            } else {
+                item.selected = NO;
+            }
         }
-        HomeFilterModel *key = self.model.keysArr[indexPath.row];
-        self.currentKey = key;
-        [self.typeCollectV reloadData];
-        [self.collectV reloadData];
         return;
     }
     
-    if (self.productClick) {
-        NSArray<ASProductBaseModel*> *arr = self.currentKey.list;
-        ASProductBaseModel *m = arr[indexPath.row];
-        self.productClick(indexPath.row, m);
+    if (self.productBlock) {
+        NSArray<ASProductBaseModel*> *arr = self.currentKey.product;
+        ASProductBaseModel *goodsModel = arr[indexPath.row];
+        self.productBlock(goodsModel);
     }
     
 }
 
+- (void)requestTypeData:(HomeFilterModel *)item index:(NSInteger)index {
+    
+    
+    NSString *urlPath = [NSString stringWithFormat:@"%@/%@/products", Goods_RecommendGoods_typeid, item.typeId];
+    
+    K_WEAK_SELF;
+    [MBProgressHUD showHUDAddedTo:self animated:YES];
+    [[ASNetTools shared] getWithPath:urlPath param:@{} success:^(id _Nonnull json) {
+        K_STRONG_SELF;
+        [MBProgressHUD hideHUDForView:self animated:YES];
+        
+        NSArray *productArr = [ASProductBaseModel mj_objectArrayWithKeyValuesArray:[(NSDictionary *)json objectForKey:@"product"]];
+        
+        item.product = productArr;
+        
+        self.currentKey = item;
+
+        [self.typeCollectV reloadData];
+        [self.collectV reloadData];
+        
+        
+    } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
+        K_STRONG_SELF;
+        [MBProgressHUD hideHUDForView:self animated:YES];
+        
+        NSLog(@"=====%@", msg);
+    }];
+    
+}
+
 // MARK: - UICollectionViewDataSource
 - (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
     if (collectionView == self.typeCollectV) {
         KWMineMoreProductTypeCell *ce = [collectionView dequeueReusableCellWithReuseIdentifier:@"KWMineMoreProductTypeCell" forIndexPath:indexPath];
-        HomeFilterModel *ti = self.model.keysArr[indexPath.row];
+        HomeFilterModel *ti = self.typeArray[indexPath.row];
         [ce setTitle:ti.title isSelect:ti.selected];
         return ce;
     }
     HomeFlashDealSubCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeFlashDealSubCollectCell" forIndexPath:indexPath];
-    NSArray<ASProductBaseModel*> *arr = self.currentKey.list;
+    NSArray<ASProductBaseModel*> *arr = self.currentKey.product;
     ASProductBaseModel *m = arr[indexPath.row];
     cell.model = m;
+    
+    K_WEAK_SELF;
+    cell.contView.addCartBlock = ^(ASProductBaseModel * _Nonnull m) {
+        K_STRONG_SELF;
+        if (self.addCartBlock) {
+            self.addCartBlock(m);
+        }
+    };
+    
     return cell;
 }
 
 - (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
     if (collectionView == self.typeCollectV) {
-        return self.model.keysArr.count;
+        return self.typeArray.count;
     }
-    NSArray<ASProductBaseModel*> *arr = self.currentKey.list;
+    NSArray<ASProductBaseModel*> *arr = self.currentKey.product;
     return arr.count;
 }
 

+ 5 - 0
Asteria/NetTools/ASNetApis.h

@@ -95,4 +95,9 @@
 #define postEmailCode BaseRequestrUrl(@"email/send")
 #define postResetPass BaseRequestrUrl(@"app/customer/password")
 
+//推荐商品包含分类
+#define Goods_RecommendGoods             BaseRequestrUrl(@"rewrite/categories/getAlsoViewed")
+//根据分类id查询分类下推荐商品
+#define Goods_RecommendGoods_typeid      BaseRequestrUrl(@"rewrite/categories")
+
 #endif /* ASNetApis_h */