// // ASGoodsDetailsViewController.m // Asteria // // Created by xingyu on 2024/5/17. // #import "ASGoodsDetailsViewController.h" #import "AS_GoodsReviewsListC.h" #import "Cart_CheckoutC.h" #import "ASGoodsDetailsVM.h" #import "ASGoodsDetailsTableView.h" #import "ASGoodsIntrouduceWebView.h" #import "GoodsDetailsBottomV.h" #import "GoodsInformationM.h" #import "WKM_goodsBanner.h" @interface ASGoodsDetailsViewController () @property (nonatomic, strong) ASGoodsDetailsVM *VM; @property (nonatomic, strong) ASGoodsDetailsTableView *TableV; @property (nonatomic, strong) GoodsInformationM *model; @property (nonatomic, strong) WKM_goodsBanner *goodsBanner; @property (nonatomic, strong) UIView *footView; @property (nonatomic, strong) GoodsDetailsBottomV *bottomV; //尺寸数据 @property (nonatomic, strong) NSDictionary *sizeParam; //底部按钮点击类型 @property (nonatomic, assign) NSInteger bottomClickType; //底部按钮点击类型 @property (nonatomic, assign) BOOL isReview; @end @implementation ASGoodsDetailsViewController - (void)viewDidLoad { [super viewDidLoad]; [self reqNet_GoodsDetails_productGetProduct]; } - (void)initSubviews { [super initSubviews]; [self.view addSubview:self.bottomV]; @weakify(self) self.bottomV.ViewtapClose = ^(NSInteger num, id _Nonnull data) { @strongify(self) self.bottomClickType = num; [self reqNet_Size_rewriteCartAddProducts]; }; IPhoneXHeigh [self setupTableV:[ASGoodsDetailsTableView class] Frame:CGRectMake(0, securitytop_Y , KScreenWidth, KScreenHeight - securitytop_Y - securityBottom_H - 65)]; self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"]; self.TableV.estimatedRowHeight = 0; self.TableV.estimatedSectionHeaderHeight = 0; self.TableV.estimatedSectionFooterHeight = 0; K_WEAK_SELF; self.TableV.tapClose = ^(NSInteger num, id data) { K_STRONG_SELF; if (num == 1) {//查看评论 [self action_GoodsReviewsListC]; } else if (num == 2) {//商品web详情 self.isReview = NO; [self updateGoodsDetailsData]; } else if (num == 3) {//商品评论 self.isReview = YES; [self updateGoodsDetailsData]; } else if (num == 100) { self.sizeParam = (NSDictionary *)data; } else if (num == 1000) { [self.TableV reloadData]; } }; } -(void)reqNet_Size_rewriteCartAddProducts { NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.sizeParam]; params[@"product"] = self.model.Id; NSLog(@"=====%@", params); [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params]; } -(void)reqNet_GoodsDetails_productGetProduct{ NSMutableDictionary * params = [[NSMutableDictionary alloc] init]; // [params setObject:@"55475" forKey:@"productId"]; [params setObject:self.entity_id forKey:@"productId"]; [params setObject:@"USD" forKey:@"currencyCode"]; [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [self.VM ry_requestGetApi:Goods_productGetProductsById param:params]; } -(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]){ GoodsInformationM *model = (GoodsInformationM *)[arry firstObject]; self.model = model; self.title = model.name; [self updateGoodsDetailsData]; } else if([mark isEqualToString:Size_rewriteCartAddProducts]) { [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]; [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES]; } }]; } } } - (void)updateGoodsDetailsData { [self.TableV.infodata removeAllObjects]; //商品图 NSDictionary *banner = @{@"type":@"banner", @"data":self.model}; [self.TableV.infodata addObject:banner]; //商品名、价格 NSDictionary *titlePrice = @{@"type":@"titlePrice", @"data":self.model}; [self.TableV.infodata addObject:titlePrice]; //优惠券 NSDictionary *coupon = @{@"type":@"coupon", @"data":self.model}; [self.TableV.infodata addObject:coupon]; //规格 NSDictionary *goodsSize = @{@"type":@"size", @"data":self.model}; [self.TableV.infodata addObject:goodsSize]; //保障信息 NSDictionary *guarantee = @{@"type":@"guarantee", @"data":self.model}; [self.TableV.infodata addObject:guarantee]; if (self.isReview) { //评论头 NSDictionary *reviewHead = @{@"type":@"reviewHead", @"data":self.model}; [self.TableV.infodata addObject:reviewHead]; self.TableV.tableFooterView = nil; } else { [self loadWebString]; } [self.TableV reloadData]; } - (void)loadWebString { _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.001)]; self.TableV.tableFooterView = _footView; ASGoodsIntrouduceWebView *webInfoView = [[ASGoodsIntrouduceWebView alloc] initWithFrame:CGRectZero]; [_footView addSubview:webInfoView]; [webInfoView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(0); }]; [webInfoView loadWebUrlWithData:self.model]; K_WEAK_SELF; webInfoView.loadFinishBlock = ^(float webHeight) { K_STRONG_SELF; self.footView.frame = CGRectMake(0, 0, KScreenWidth, webHeight); [self.TableV reloadData]; }; } #pragma mark ---- Touch Event ---- //查看评论 -(void)action_GoodsReviewsListC{ AS_GoodsReviewsListC *allPic = [[AS_GoodsReviewsListC alloc]init]; allPic.goodsM = self.model; [self.navigationController pushViewController:allPic animated:YES]; } - (void)ucm_bindvmmodel{ self.VM = [[ASGoodsDetailsVM alloc] initDelegate:self]; } - (GoodsDetailsBottomV *)bottomV { if (!_bottomV) { IPhoneXHeigh _bottomV = [[GoodsDetailsBottomV alloc] initWithFrame:CGRectMake(0, KScreenHeight - securityBottom_H-65, KScreenWidth, securityBottom_H+65)]; _bottomV.backgroundColor = Col_FFF; } return _bottomV; } @end