ASGoodsDetailsViewController.m 8.7 KB

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