ASGoodsDetailsViewController.m 8.4 KB

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