// // 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" #import "KWMineMoreProductModel.h" #import "ASProductBaseModel.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) NSArray *recommendGoodsArr;; @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_Goods_productGetProductsReview]; [self reqNet_GoodsDetails_productGetProduct]; [self request_RecommendGoodsData]; } - (void)_shareClick { [Fuction_Tool tool_shareImgStr:self.model.add_gooodsImgUrl sharetitle:self.model.name shareUrl:@"https://www.baidu.com" currentVC:self]; } - (void)initSubviews { [super initSubviews]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"share_icon"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(_shareClick) forControlEvents:UIControlEventTouchUpInside]; // button.backgroundColor = [UIColor yellowColor]; [self.customNavBar addSubview:button]; [button mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-8); make.bottom.mas_equalTo(-2); make.width.height.mas_equalTo(40); }]; [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 || num == 5) {//查看评论 [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) {//写商品评论 if (![ASUserInfoManager shared].isLogin) { [Fuction_Tool pop_toLoginVC]; return; } 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; // self.model.final_prices = @"" [self refresh_optionChangePrice]; } 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]; } }; } #pragma mark - **************** fresh 选择不同规格后的金额变化 **************** -(void)refresh_optionChangePrice{ CGFloat add_price = 0.00; for (OptionsModel *optionM in self.model.options) { OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag]; add_price = add_price + valuesM.price; } NSInteger num = [[self.sizeParam objectForKey:@"qty"] integerValue]; float discount = [self.model.percent floatValue]; if (discount == 0) { //优惠价 CGFloat add_final_price_f = (add_price + [self.model.final_prices floatValue]) * num; self.model.show_final_prices = [NSString stringWithFormat:@"%.2lf", add_final_price_f]; //原价 CGFloat show_prices = (add_price + [self.model.price floatValue]) * num; self.model.show_prices = [NSString stringWithFormat:@"%.2lf", show_prices]; } else { //优惠价 discount = (100.00 - discount) / 100.00; CGFloat add_final_price_f = (add_price * discount + [self.model.final_prices floatValue]) * num; self.model.show_final_prices = [NSString stringWithFormat:@"%.2lf", add_final_price_f]; //原价 CGFloat show_prices = (add_price + [self.model.price floatValue]) * num; self.model.show_prices = [NSString stringWithFormat:@"%.2lf", show_prices]; } [NSNotificationCenter.defaultCenter postNotificationName:GoodsDetailsUpdatePrice object:nil]; } //请求尺寸 -(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]; for (OptionsModel *optionM in self.model.options) { OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag]; NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id]; optionDic[tempStr] =valuesM.option_type_id; } NSMutableDictionary *sizeDic = [NSMutableDictionary dictionaryWithDictionary:optionDic]; sizeDic[@"qty"] = [NSString stringWithFormat:@"%@", @"1"]; self.sizeParam = sizeDic; } 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:ASCurrencyManager.shared.currentCur 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:@"sortreview" forKey:@"sortreview"]; [params setObject:@(self.TableV.Page) forKey:@"p"]; [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{ 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; [self updateGoodsDetailsData]; [self loadWebString]; } 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]; [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES]; } }]; } else if ([mark isEqualToString:Goods_productGetProductsReview]) { 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]; } } - (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]; if (AS_Array_valid(self.reviewDataArray)) { //评论数据 [self.TableV.infodata addObjectsFromArray:self.reviewDataArray]; //评论底部 NSDictionary *reviewFoot = @{@"type":@"reviewFoot", @"data":self.model}; [self.TableV.infodata addObject:reviewFoot]; } //推荐商品 if (AS_Array_valid(self.recommendGoodsArr)) { NSDictionary *customer = @{@"type":@"customer", @"data":self.recommendGoodsArr}; [self.TableV.infodata addObject:customer]; } // 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