ASGoodsDetailsViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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_Goods_productGetProductsReview];
  37. [self reqNet_GoodsDetails_productGetProduct];
  38. }
  39. - (void)_shareClick {
  40. [Fuction_Tool tool_shareImgStr:self.model.add_gooodsImgUrl sharetitle:self.model.name shareUrl:@"https://www.baidu.com" currentVC:self];
  41. }
  42. - (void)initSubviews {
  43. [super initSubviews];
  44. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  45. [button setImage:[UIImage imageNamed:@"share_icon"] forState:UIControlStateNormal];
  46. [button addTarget:self action:@selector(_shareClick) forControlEvents:UIControlEventTouchUpInside];
  47. // button.backgroundColor = [UIColor yellowColor];
  48. [self.customNavBar addSubview:button];
  49. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.right.mas_equalTo(-8);
  51. make.bottom.mas_equalTo(-2);
  52. make.width.height.mas_equalTo(40);
  53. }];
  54. [self.view addSubview:self.bottomV];
  55. @weakify(self)
  56. self.bottomV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {
  57. @strongify(self)
  58. self.bottomClickType = num;
  59. [self reqNet_Size_rewriteCartAddProducts];
  60. };
  61. IPhoneXHeigh
  62. [self setupTableV:[ASGoodsDetailsTableView class] Frame:CGRectMake(0, securitytop_Y , KScreenWidth, KScreenHeight - securitytop_Y - securityBottom_H - 65)];
  63. self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  64. self.TableV.estimatedRowHeight = 0;
  65. self.TableV.estimatedSectionHeaderHeight = 0;
  66. self.TableV.estimatedSectionFooterHeight = 0;
  67. K_WEAK_SELF;
  68. self.TableV.tapClose = ^(NSInteger num, id data) {
  69. K_STRONG_SELF;
  70. if (num == 1 || num == 5) {//查看评论
  71. [self action_GoodsReviewsListC];
  72. } else if (num == 2) {//商品web详情
  73. self.isReview = NO;
  74. self.TableV.isReview = NO;
  75. self.TableV.tableFooterView = self.footView;
  76. [self.TableV reloadData];
  77. // [self updateGoodsDetailsData];
  78. } else if (num == 3) {//商品评论列表
  79. self.isReview = YES;
  80. self.TableV.isReview = YES;
  81. self.TableV.tableFooterView = nil;
  82. [self.TableV reloadData];
  83. // [self updateGoodsDetailsData];
  84. } else if (num == 4) {//写商品评论
  85. GoodsReviewsWriteC *vc = [[GoodsReviewsWriteC alloc]init];
  86. vc.goodsM = self.model;
  87. // vc.topBgV = self.topBgV;
  88. vc.nav_title = [NSString stringWithFormat:@"REVIEWS (%@)",self.model.review_nums];
  89. [self.navigationController pushViewController:vc animated:YES];
  90. } else if (num == 100) {
  91. self.sizeParam = (NSDictionary *)data;
  92. } else if (num == 1000) {
  93. [self.TableV reloadData];
  94. }
  95. };
  96. }
  97. -(void)reqNet_Size_rewriteCartAddProducts {
  98. if (!AS_Dict_valid(self.sizeParam)) {
  99. NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
  100. for (OptionsModel *optionM in self.model.options) {
  101. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  102. NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
  103. optionDic[tempStr] =valuesM.option_type_id;
  104. }
  105. NSMutableDictionary *sizeDic = [NSMutableDictionary dictionaryWithDictionary:optionDic];
  106. sizeDic[@"qty"] = [NSString stringWithFormat:@"%@", @"1"];
  107. self.sizeParam = sizeDic;
  108. }
  109. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.sizeParam];
  110. params[@"product"] = self.model.Id;
  111. NSLog(@"=====%@", params);
  112. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  113. [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params];
  114. }
  115. //商品详情信息
  116. -(void)reqNet_GoodsDetails_productGetProduct{
  117. NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
  118. // [params setObject:@"55475" forKey:@"productId"];
  119. [params setObject:self.entity_id forKey:@"productId"];
  120. [params setObject:@"USD" forKey:@"currencyCode"];
  121. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  122. [self.VM ry_requestGetApi:Goods_productGetProductsById param:params];
  123. }
  124. //商品评论
  125. -(void)reqNet_Goods_productGetProductsReview{
  126. NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
  127. [params setObject:self.entity_id forKey:@"pid"];
  128. // [params setObject:@0 forKey:@"img"];
  129. [params setObject:@"Newest" forKey:@"sortreview"];
  130. [params setObject:@(self.TableV.Page) forKey:@"p"];
  131. [params setObject:@3 forKey:@"limit"];
  132. [self.VM ry_requestGetApi:Goods_productGetProductsReview param:params];
  133. }
  134. -(void)ry_respnsData:(nullable id)data
  135. parseAry:(nullable NSMutableArray *)arry
  136. sucess:(BOOL)sucessOrFail
  137. mark:(NSString *)mark
  138. reqNetType:(ReqNetType)reqNetType{
  139. [MBProgressHUD hideHUDForView:self.view animated:YES];
  140. if(sucessOrFail){
  141. if([mark isEqualToString:Goods_productGetProductsById]){
  142. GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
  143. self.model = model;
  144. self.title = model.name;
  145. [self updateGoodsDetailsData];
  146. [self loadWebString];
  147. } else if([mark isEqualToString:Size_rewriteCartAddProducts]) {
  148. [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  149. if (self.bottomClickType == 1) {
  150. Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
  151. [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  152. }
  153. }];
  154. } else if ([mark isEqualToString:Goods_productGetProductsReview]) {
  155. // [self.TableV configDataNew:arry has_more:arry.count==10 ? YES : NO];
  156. self.reviewDataArray = arry;
  157. if (self.model) {
  158. [self updateGoodsDetailsData];
  159. }
  160. }
  161. }
  162. }
  163. - (void)updateGoodsDetailsData {
  164. [self.TableV.infodata removeAllObjects];
  165. //商品图
  166. NSDictionary *banner = @{@"type":@"banner", @"data":self.model};
  167. [self.TableV.infodata addObject:banner];
  168. //商品名、价格
  169. NSDictionary *titlePrice = @{@"type":@"titlePrice", @"data":self.model};
  170. [self.TableV.infodata addObject:titlePrice];
  171. //优惠券
  172. NSDictionary *coupon = @{@"type":@"coupon", @"data":self.model};
  173. [self.TableV.infodata addObject:coupon];
  174. //规格
  175. NSDictionary *goodsSize = @{@"type":@"size", @"data":self.model};
  176. [self.TableV.infodata addObject:goodsSize];
  177. //保障信息
  178. NSDictionary *guarantee = @{@"type":@"guarantee", @"data":self.model};
  179. [self.TableV.infodata addObject:guarantee];
  180. //评论头
  181. NSDictionary *reviewHead = @{@"type":@"reviewHead", @"data":self.model};
  182. [self.TableV.infodata addObject:reviewHead];
  183. //评论数据
  184. [self.TableV.infodata addObjectsFromArray:self.reviewDataArray];
  185. //评论底部
  186. NSDictionary *reviewFoot = @{@"type":@"reviewFoot", @"data":self.model};
  187. [self.TableV.infodata addObject:reviewFoot];
  188. //推荐商品
  189. KWMineMoreProductModel *model = [KWMineMoreProductModel demoData];
  190. NSDictionary *customer = @{@"type":@"customer", @"data":model};
  191. [self.TableV.infodata addObject:customer];
  192. // if (self.isReview) {
  193. //
  194. //
  195. // self.TableV.tableFooterView = nil;
  196. //
  197. // } else {
  198. // self.TableV.tableFooterView = _footView;
  199. // }
  200. [self.TableV reloadData];
  201. }
  202. - (void)loadWebString {
  203. _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.001)];
  204. ASGoodsIntrouduceWebView *webInfoView = [[ASGoodsIntrouduceWebView alloc] initWithFrame:CGRectZero];
  205. [_footView addSubview:webInfoView];
  206. [webInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  207. make.edges.mas_equalTo(0);
  208. }];
  209. [webInfoView loadWebUrlWithData:self.model];
  210. K_WEAK_SELF;
  211. webInfoView.loadFinishBlock = ^(float webHeight) {
  212. K_STRONG_SELF;
  213. self.footView.frame = CGRectMake(0, 0, KScreenWidth, webHeight);
  214. [self.TableV reloadData];
  215. };
  216. self.TableV.tableFooterView = _footView;
  217. }
  218. #pragma mark ---- Touch Event ----
  219. //查看评论
  220. -(void)action_GoodsReviewsListC{
  221. AS_GoodsReviewsListC *allPic = [[AS_GoodsReviewsListC alloc]init];
  222. allPic.goodsM = self.model;
  223. [self.navigationController pushViewController:allPic animated:YES];
  224. }
  225. - (void)ucm_bindvmmodel{
  226. self.VM = [[ASGoodsDetailsVM alloc] initDelegate:self];
  227. }
  228. - (GoodsDetailsBottomV *)bottomV {
  229. if (!_bottomV) {
  230. IPhoneXHeigh
  231. _bottomV = [[GoodsDetailsBottomV alloc] initWithFrame:CGRectMake(0, KScreenHeight - securityBottom_H-65, KScreenWidth, securityBottom_H+65)];
  232. _bottomV.backgroundColor = Col_FFF;
  233. }
  234. return _bottomV;
  235. }
  236. @end