ASGoodsDetailsViewController.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. if (!AS_Dict_valid(self.sizeParam)) {
  86. NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
  87. for (OptionsModel *optionM in self.model.options) {
  88. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  89. NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
  90. optionDic[tempStr] =valuesM.option_type_id;
  91. }
  92. NSMutableDictionary *sizeDic = [NSMutableDictionary dictionaryWithDictionary:optionDic];
  93. sizeDic[@"qty"] = [NSString stringWithFormat:@"%@", @"1"];
  94. self.sizeParam = sizeDic;
  95. }
  96. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.sizeParam];
  97. params[@"product"] = self.model.Id;
  98. NSLog(@"=====%@", params);
  99. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  100. [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params];
  101. }
  102. //商品详情信息
  103. -(void)reqNet_GoodsDetails_productGetProduct{
  104. NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
  105. // [params setObject:@"55475" forKey:@"productId"];
  106. [params setObject:self.entity_id forKey:@"productId"];
  107. [params setObject:@"USD" forKey:@"currencyCode"];
  108. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  109. [self.VM ry_requestGetApi:Goods_productGetProductsById param:params];
  110. }
  111. //商品评论
  112. -(void)reqNet_Goods_productGetProductsReview{
  113. NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
  114. [params setObject:self.entity_id forKey:@"pid"];
  115. // [params setObject:@0 forKey:@"img"];
  116. [params setObject:@"Newest" forKey:@"sortreview"];
  117. [params setObject:@(self.TableV.Page) forKey:@"p"];
  118. [params setObject:@3 forKey:@"limit"];
  119. [self.VM ry_requestGetApi:Goods_productGetProductsReview param:params];
  120. }
  121. -(void)ry_respnsData:(nullable id)data
  122. parseAry:(nullable NSMutableArray *)arry
  123. sucess:(BOOL)sucessOrFail
  124. mark:(NSString *)mark
  125. reqNetType:(ReqNetType)reqNetType{
  126. [MBProgressHUD hideHUDForView:self.view animated:YES];
  127. if(sucessOrFail){
  128. if([mark isEqualToString:Goods_productGetProductsById]){
  129. GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
  130. self.model = model;
  131. self.title = model.name;
  132. [self updateGoodsDetailsData];
  133. [self loadWebString];
  134. } else if([mark isEqualToString:Size_rewriteCartAddProducts]) {
  135. [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  136. if (self.bottomClickType == 1) {
  137. Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
  138. [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  139. }
  140. }];
  141. } else if ([mark isEqualToString:Goods_productGetProductsReview]) {
  142. // [self.TableV configDataNew:arry has_more:arry.count==10 ? YES : NO];
  143. self.reviewDataArray = arry;
  144. if (self.model) {
  145. [self updateGoodsDetailsData];
  146. }
  147. }
  148. }
  149. }
  150. - (void)updateGoodsDetailsData {
  151. // [self.TableV.infodata removeAllObjects];
  152. //商品图
  153. NSDictionary *banner = @{@"type":@"banner", @"data":self.model};
  154. [self.TableV.infodata addObject:banner];
  155. //商品名、价格
  156. NSDictionary *titlePrice = @{@"type":@"titlePrice", @"data":self.model};
  157. [self.TableV.infodata addObject:titlePrice];
  158. //优惠券
  159. NSDictionary *coupon = @{@"type":@"coupon", @"data":self.model};
  160. [self.TableV.infodata addObject:coupon];
  161. //规格
  162. NSDictionary *goodsSize = @{@"type":@"size", @"data":self.model};
  163. [self.TableV.infodata addObject:goodsSize];
  164. //保障信息
  165. NSDictionary *guarantee = @{@"type":@"guarantee", @"data":self.model};
  166. [self.TableV.infodata addObject:guarantee];
  167. //评论头
  168. NSDictionary *reviewHead = @{@"type":@"reviewHead", @"data":self.model};
  169. [self.TableV.infodata addObject:reviewHead];
  170. //评论数据
  171. [self.TableV.infodata addObjectsFromArray:self.reviewDataArray];
  172. //评论底部
  173. NSDictionary *reviewFoot = @{@"type":@"reviewFoot", @"data":self.model};
  174. [self.TableV.infodata addObject:reviewFoot];
  175. //推荐商品
  176. KWMineMoreProductModel *model = [KWMineMoreProductModel demoData];
  177. NSDictionary *customer = @{@"type":@"customer", @"data":model};
  178. [self.TableV.infodata addObject:customer];
  179. // if (self.isReview) {
  180. //
  181. //
  182. // self.TableV.tableFooterView = nil;
  183. //
  184. // } else {
  185. // self.TableV.tableFooterView = _footView;
  186. // }
  187. [self.TableV reloadData];
  188. }
  189. - (void)loadWebString {
  190. _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.001)];
  191. ASGoodsIntrouduceWebView *webInfoView = [[ASGoodsIntrouduceWebView alloc] initWithFrame:CGRectZero];
  192. [_footView addSubview:webInfoView];
  193. [webInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  194. make.edges.mas_equalTo(0);
  195. }];
  196. [webInfoView loadWebUrlWithData:self.model];
  197. K_WEAK_SELF;
  198. webInfoView.loadFinishBlock = ^(float webHeight) {
  199. K_STRONG_SELF;
  200. self.footView.frame = CGRectMake(0, 0, KScreenWidth, webHeight);
  201. [self.TableV reloadData];
  202. };
  203. self.TableV.tableFooterView = _footView;
  204. }
  205. #pragma mark ---- Touch Event ----
  206. //查看评论
  207. -(void)action_GoodsReviewsListC{
  208. AS_GoodsReviewsListC *allPic = [[AS_GoodsReviewsListC alloc]init];
  209. allPic.goodsM = self.model;
  210. [self.navigationController pushViewController:allPic animated:YES];
  211. }
  212. - (void)ucm_bindvmmodel{
  213. self.VM = [[ASGoodsDetailsVM alloc] initDelegate:self];
  214. }
  215. - (GoodsDetailsBottomV *)bottomV {
  216. if (!_bottomV) {
  217. IPhoneXHeigh
  218. _bottomV = [[GoodsDetailsBottomV alloc] initWithFrame:CGRectMake(0, KScreenHeight - securityBottom_H-65, KScreenWidth, securityBottom_H+65)];
  219. _bottomV.backgroundColor = Col_FFF;
  220. }
  221. return _bottomV;
  222. }
  223. @end