// // ASGoodsDetailsViewController.m // Asteria // // Created by xingyu on 2024/5/17. // #import "ASGoodsDetailsViewController.h" #import "AS_GoodsReviewsListC.h" #import "Cart_CheckoutC.h" #import "GoodsReviewsWriteC.h" #import "ASGoodsDetailsVM.h" #import "ASGoodsDetailsTableView.h" #import "ASGoodsIntrouduceWebView.h" #import "GoodsDetailsBottomV.h" #import "GoodsInformationM.h" #import "GoodsReviewsListM.h" @interface ASGoodsDetailsViewController () @property (nonatomic, strong) ASGoodsDetailsVM *VM; @property (nonatomic, strong) ASGoodsDetailsTableView *TableV; @property (nonatomic, strong) GoodsInformationM *model; //评论数据 @property (nonatomic, strong) NSArray *reviewDataArray;; @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]; [self reqNet_Goods_productGetProductsReview]; } - (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.TableV.isReview = NO; self.TableV.tableFooterView = self.footView; [self.TableV reloadData]; // [self updateGoodsDetailsData]; } else if (num == 3) {//商品评论列表 self.isReview = YES; self.TableV.isReview = YES; self.TableV.tableFooterView = nil; [self.TableV reloadData]; // [self updateGoodsDetailsData]; } else if (num == 4) {//写商品评论 GoodsReviewsWriteC *vc = [[GoodsReviewsWriteC alloc]init]; vc.goodsM = self.model; // vc.topBgV = self.topBgV; vc.nav_title = [NSString stringWithFormat:@"REVIEWS (%@)",self.model.review_nums]; [self.navigationController pushViewController:vc animated:YES]; } 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)reqNet_Goods_productGetProductsReview{ NSMutableDictionary *params = [[NSMutableDictionary alloc]init]; [params setObject:self.entity_id forKey:@"pid"]; // [params setObject:@0 forKey:@"img"]; [params setObject:@"Newest" forKey:@"sortreview"]; [params setObject:@(self.TableV.Page) forKey:@"p"]; [params setObject:@3 forKey:@"limit"]; [self.VM ry_requestGetApi:Goods_productGetProductsReview 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]; [self loadWebString]; } 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]; } }]; } 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]; } } } } - (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]; //评论头 NSDictionary *reviewHead = @{@"type":@"reviewHead", @"data":self.model}; [self.TableV.infodata addObject:reviewHead]; //评论数据 [self.TableV.infodata addObjectsFromArray:self.reviewDataArray]; // if (self.isReview) { // // // self.TableV.tableFooterView = nil; // // } else { // self.TableV.tableFooterView = _footView; // } [self.TableV reloadData]; } - (void)loadWebString { _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.001)]; 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]; }; self.TableV.tableFooterView = _footView; } #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