ASGoodsDetailsViewController.m 7.6 KB

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