ASGoodsDetailsViewController.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // ASGoodsDetailsViewController.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/17.
  6. //
  7. #import "ASGoodsDetailsViewController.h"
  8. #import "AS_GoodsReviewsListC.h"
  9. #import "Cart_CheckoutC.h"
  10. #import "ASGoodsDetailsVM.h"
  11. #import "ASGoodsDetailsTableView.h"
  12. #import "ASGoodsIntrouduceWebView.h"
  13. #import "GoodsDetailsBottomV.h"
  14. #import "GoodsInformationM.h"
  15. #import "WKM_goodsBanner.h"
  16. @interface ASGoodsDetailsViewController ()<RY_baseVMprotocol>
  17. @property (nonatomic, strong) ASGoodsDetailsVM *VM;
  18. @property (nonatomic, strong) ASGoodsDetailsTableView *TableV;
  19. @property (nonatomic, strong) GoodsInformationM *model;
  20. @property (nonatomic, strong) WKM_goodsBanner *goodsBanner;
  21. @property (nonatomic, strong) UIView *footView;
  22. @property (nonatomic, strong) GoodsDetailsBottomV *bottomV;
  23. //尺寸数据
  24. @property (nonatomic, strong) NSDictionary *sizeParam;
  25. //底部按钮点击类型
  26. @property (nonatomic, assign) NSInteger bottomClickType;
  27. //底部按钮点击类型
  28. @property (nonatomic, assign) BOOL isReview;
  29. @end
  30. @implementation ASGoodsDetailsViewController
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. [self reqNet_GoodsDetails_productGetProduct];
  34. }
  35. - (void)initSubviews {
  36. [super initSubviews];
  37. [self.view addSubview:self.bottomV];
  38. @weakify(self)
  39. self.bottomV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {
  40. @strongify(self)
  41. self.bottomClickType = num;
  42. [self reqNet_Size_rewriteCartAddProducts];
  43. };
  44. IPhoneXHeigh
  45. [self setupTableV:[ASGoodsDetailsTableView class] Frame:CGRectMake(0, securitytop_Y , KScreenWidth, KScreenHeight - securitytop_Y - securityBottom_H - 65)];
  46. self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  47. self.TableV.estimatedRowHeight = 0;
  48. self.TableV.estimatedSectionHeaderHeight = 0;
  49. self.TableV.estimatedSectionFooterHeight = 0;
  50. K_WEAK_SELF;
  51. self.TableV.tapClose = ^(NSInteger num, id data) {
  52. K_STRONG_SELF;
  53. if (num == 1) {//查看评论
  54. [self action_GoodsReviewsListC];
  55. } else if (num == 2) {//商品web详情
  56. self.isReview = NO;
  57. [self updateGoodsDetailsData];
  58. } else if (num == 3) {//商品评论
  59. self.isReview = YES;
  60. [self updateGoodsDetailsData];
  61. } else if (num == 100) {
  62. self.sizeParam = (NSDictionary *)data;
  63. } else if (num == 1000) {
  64. [self.TableV reloadData];
  65. }
  66. };
  67. }
  68. -(void)reqNet_Size_rewriteCartAddProducts {
  69. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.sizeParam];
  70. params[@"product"] = self.model.Id;
  71. NSLog(@"=====%@", params);
  72. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  73. [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params];
  74. }
  75. -(void)reqNet_GoodsDetails_productGetProduct{
  76. NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
  77. // [params setObject:@"55475" forKey:@"productId"];
  78. [params setObject:self.entity_id forKey:@"productId"];
  79. [params setObject:@"USD" forKey:@"currencyCode"];
  80. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  81. [self.VM ry_requestGetApi:Goods_productGetProductsById param:params];
  82. }
  83. -(void)ry_respnsData:(nullable id)data
  84. parseAry:(nullable NSMutableArray *)arry
  85. sucess:(BOOL)sucessOrFail
  86. mark:(NSString *)mark
  87. reqNetType:(ReqNetType)reqNetType{
  88. [MBProgressHUD hideHUDForView:self.view animated:YES];
  89. if(sucessOrFail){
  90. if([mark isEqualToString:Goods_productGetProductsById]){
  91. GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
  92. self.model = model;
  93. self.title = model.name;
  94. [self updateGoodsDetailsData];
  95. } else if([mark isEqualToString:Size_rewriteCartAddProducts]) {
  96. [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  97. if (self.bottomClickType == 1) {
  98. Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
  99. [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  100. }
  101. }];
  102. }
  103. }
  104. }
  105. - (void)updateGoodsDetailsData {
  106. [self.TableV.infodata removeAllObjects];
  107. //商品图
  108. NSDictionary *banner = @{@"type":@"banner", @"data":self.model};
  109. [self.TableV.infodata addObject:banner];
  110. //商品名、价格
  111. NSDictionary *titlePrice = @{@"type":@"titlePrice", @"data":self.model};
  112. [self.TableV.infodata addObject:titlePrice];
  113. //优惠券
  114. NSDictionary *coupon = @{@"type":@"coupon", @"data":self.model};
  115. [self.TableV.infodata addObject:coupon];
  116. //规格
  117. NSDictionary *goodsSize = @{@"type":@"size", @"data":self.model};
  118. [self.TableV.infodata addObject:goodsSize];
  119. //保障信息
  120. NSDictionary *guarantee = @{@"type":@"guarantee", @"data":self.model};
  121. [self.TableV.infodata addObject:guarantee];
  122. if (self.isReview) {
  123. //评论头
  124. NSDictionary *reviewHead = @{@"type":@"reviewHead", @"data":self.model};
  125. [self.TableV.infodata addObject:reviewHead];
  126. self.TableV.tableFooterView = nil;
  127. } else {
  128. [self loadWebString];
  129. }
  130. [self.TableV reloadData];
  131. }
  132. - (void)loadWebString {
  133. _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.001)];
  134. self.TableV.tableFooterView = _footView;
  135. ASGoodsIntrouduceWebView *webInfoView = [[ASGoodsIntrouduceWebView alloc] initWithFrame:CGRectZero];
  136. [_footView addSubview:webInfoView];
  137. [webInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.edges.mas_equalTo(0);
  139. }];
  140. [webInfoView loadWebUrlWithData:self.model];
  141. K_WEAK_SELF;
  142. webInfoView.loadFinishBlock = ^(float webHeight) {
  143. K_STRONG_SELF;
  144. self.footView.frame = CGRectMake(0, 0, KScreenWidth, webHeight);
  145. [self.TableV reloadData];
  146. };
  147. }
  148. #pragma mark ---- Touch Event ----
  149. //查看评论
  150. -(void)action_GoodsReviewsListC{
  151. AS_GoodsReviewsListC *allPic = [[AS_GoodsReviewsListC alloc]init];
  152. allPic.goodsM = self.model;
  153. [self.navigationController pushViewController:allPic animated:YES];
  154. }
  155. - (void)ucm_bindvmmodel{
  156. self.VM = [[ASGoodsDetailsVM alloc] initDelegate:self];
  157. }
  158. - (GoodsDetailsBottomV *)bottomV {
  159. if (!_bottomV) {
  160. IPhoneXHeigh
  161. _bottomV = [[GoodsDetailsBottomV alloc] initWithFrame:CGRectMake(0, KScreenHeight - securityBottom_H-65, KScreenWidth, securityBottom_H+65)];
  162. _bottomV.backgroundColor = Col_FFF;
  163. }
  164. return _bottomV;
  165. }
  166. @end