ASGoodsDetailsViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. #import "ASProductBaseModel.h"
  19. @interface ASGoodsDetailsViewController ()<RY_baseVMprotocol>
  20. @property (nonatomic, strong) ASGoodsDetailsVM *VM;
  21. @property (nonatomic, strong) ASGoodsDetailsTableView *TableV;
  22. @property (nonatomic, strong) GoodsInformationM *model;
  23. //评论数据
  24. @property (nonatomic, strong) NSArray *reviewDataArray;;
  25. //推荐商品数据
  26. @property (nonatomic, strong) NSArray *recommendGoodsArr;;
  27. @property (nonatomic, strong) UIView *footView;
  28. @property (nonatomic, strong) GoodsDetailsBottomV *bottomV;
  29. //尺寸数据
  30. @property (nonatomic, strong) NSDictionary *sizeParam;
  31. //底部按钮点击类型
  32. @property (nonatomic, assign) NSInteger bottomClickType;
  33. //底部按钮点击类型
  34. @property (nonatomic, assign) BOOL isReview;
  35. @end
  36. @implementation ASGoodsDetailsViewController
  37. - (void)viewDidLoad {
  38. [super viewDidLoad];
  39. [self reqNet_Goods_productGetProductsReview];
  40. [self reqNet_GoodsDetails_productGetProduct];
  41. [self request_RecommendGoodsData];
  42. }
  43. - (void)_shareClick {
  44. [Fuction_Tool tool_shareImgStr:self.model.add_gooodsImgUrl sharetitle:self.model.name shareUrl:@"https://www.baidu.com" currentVC:self];
  45. }
  46. - (void)initSubviews {
  47. [super initSubviews];
  48. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  49. [button setImage:[UIImage imageNamed:@"share_icon"] forState:UIControlStateNormal];
  50. [button addTarget:self action:@selector(_shareClick) forControlEvents:UIControlEventTouchUpInside];
  51. // button.backgroundColor = [UIColor yellowColor];
  52. [self.customNavBar addSubview:button];
  53. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.right.mas_equalTo(-8);
  55. make.bottom.mas_equalTo(-2);
  56. make.width.height.mas_equalTo(40);
  57. }];
  58. [self.view addSubview:self.bottomV];
  59. @weakify(self)
  60. self.bottomV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {
  61. @strongify(self)
  62. self.bottomClickType = num;
  63. [self reqNet_Size_rewriteCartAddProducts];
  64. };
  65. IPhoneXHeigh
  66. [self setupTableV:[ASGoodsDetailsTableView class] Frame:CGRectMake(0, securitytop_Y , KScreenWidth, KScreenHeight - securitytop_Y - securityBottom_H - 65)];
  67. self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  68. self.TableV.estimatedRowHeight = 0;
  69. self.TableV.estimatedSectionHeaderHeight = 0;
  70. self.TableV.estimatedSectionFooterHeight = 0;
  71. K_WEAK_SELF;
  72. self.TableV.tapClose = ^(NSInteger num, id data) {
  73. K_STRONG_SELF;
  74. if (num == 1 || num == 5) {//查看评论
  75. [self action_GoodsReviewsListC];
  76. } else if (num == 2) {//商品web详情
  77. self.isReview = NO;
  78. self.TableV.isReview = NO;
  79. self.TableV.tableFooterView = self.footView;
  80. [self.TableV reloadData];
  81. // [self updateGoodsDetailsData];
  82. } else if (num == 3) {//商品评论列表
  83. self.isReview = YES;
  84. self.TableV.isReview = YES;
  85. self.TableV.tableFooterView = nil;
  86. [self.TableV reloadData];
  87. // [self updateGoodsDetailsData];
  88. } else if (num == 4) {//写商品评论
  89. if (![ASUserInfoManager shared].isLogin) {
  90. [Fuction_Tool pop_toLoginVC];
  91. return;
  92. }
  93. GoodsReviewsWriteC *vc = [[GoodsReviewsWriteC alloc]init];
  94. vc.goodsM = self.model;
  95. // vc.topBgV = self.topBgV;
  96. vc.nav_title = [NSString stringWithFormat:@"REVIEWS (%@)",self.model.review_nums];
  97. [self.navigationController pushViewController:vc animated:YES];
  98. } else if (num == 100) {
  99. self.sizeParam = (NSDictionary *)data;
  100. } else if (num == 101) {//推荐商品跳转
  101. ASProductBaseModel *model = (ASProductBaseModel *)data;
  102. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":model.Id}];
  103. [self.navigationController pushViewController:viewController animated:YES];
  104. } else if (num == 102) {//推荐商品加车
  105. ASProductBaseModel *model = (ASProductBaseModel *)data;
  106. [self action_GoodsSizeC:model.Id];
  107. } else if (num == 1000) {
  108. [self.TableV reloadData];
  109. }
  110. };
  111. }
  112. //请求尺寸
  113. -(void)action_GoodsSizeC:(NSString *)entity_id {
  114. if (!ASUserInfoManager.shared.isLogin) {
  115. [Fuction_Tool pop_toLoginVC];
  116. return;
  117. }
  118. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  119. [params setObject:entity_id forKey:@"productId"];
  120. [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
  121. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  122. __weak typeof(self) weakSelf = self;
  123. [ASNetTools.shared getWithPath:getProdectDetail param:params success:^(id _Nonnull json) {
  124. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  125. GoodsInformationM *model = [GoodsInformationM mj_objectWithKeyValues:json];
  126. if (model == nil || model.Id == nil || model.Id.isEmpty) {
  127. return;
  128. }
  129. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsSizeC:@{@"model":model}];
  130. viewController.modalPresentationStyle = UIModalPresentationFullScreen;
  131. [weakSelf presentViewController:viewController animated:YES completion:nil];
  132. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  133. [self.view makeToast:msg];
  134. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  135. }];
  136. }
  137. -(void)reqNet_Size_rewriteCartAddProducts {
  138. if (![ASUserInfoManager shared].isLogin) {
  139. [Fuction_Tool pop_toLoginVC];
  140. return;
  141. }
  142. if (!AS_Dict_valid(self.sizeParam)) {
  143. NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
  144. for (OptionsModel *optionM in self.model.options) {
  145. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  146. NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
  147. optionDic[tempStr] =valuesM.option_type_id;
  148. }
  149. NSMutableDictionary *sizeDic = [NSMutableDictionary dictionaryWithDictionary:optionDic];
  150. sizeDic[@"qty"] = [NSString stringWithFormat:@"%@", @"1"];
  151. self.sizeParam = sizeDic;
  152. }
  153. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.sizeParam];
  154. params[@"product"] = self.model.Id;
  155. NSLog(@"=====%@", params);
  156. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  157. [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params];
  158. }
  159. //商品详情信息
  160. -(void)reqNet_GoodsDetails_productGetProduct{
  161. NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
  162. // [params setObject:@"55475" forKey:@"productId"];
  163. [params setObject:self.entity_id forKey:@"productId"];
  164. [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
  165. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  166. [self.VM ry_requestGetApi:Goods_productGetProductsById param:params];
  167. }
  168. //商品评论
  169. -(void)reqNet_Goods_productGetProductsReview{
  170. NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
  171. [params setObject:self.entity_id forKey:@"pid"];
  172. // [params setObject:@0 forKey:@"img"];
  173. [params setObject:@"Newest" forKey:@"sortreview"];
  174. [params setObject:@(self.TableV.Page) forKey:@"p"];
  175. [params setObject:@3 forKey:@"limit"];
  176. [self.VM ry_requestGetApi:Goods_productGetProductsReview param:params];
  177. }
  178. //推荐商品
  179. - (void)request_RecommendGoodsData {
  180. [self.VM ry_requestGetApi:Goods_RecommendGoods param:@{}];
  181. }
  182. -(void)ry_respnsData:(nullable id)data
  183. parseAry:(nullable NSMutableArray *)arry
  184. sucess:(BOOL)sucessOrFail
  185. mark:(NSString *)mark
  186. reqNetType:(ReqNetType)reqNetType{
  187. if(sucessOrFail){
  188. if([mark isEqualToString:Goods_productGetProductsById]){
  189. [MBProgressHUD hideHUDForView:self.view animated:YES];
  190. GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
  191. self.model = model;
  192. self.title = model.name;
  193. [self updateGoodsDetailsData];
  194. [self loadWebString];
  195. } else if([mark isEqualToString:Size_rewriteCartAddProducts]) {
  196. [MBProgressHUD hideHUDForView:self.view animated:YES];
  197. [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  198. if (self.bottomClickType == 1) {
  199. Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
  200. [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  201. }
  202. }];
  203. } else if ([mark isEqualToString:Goods_productGetProductsReview]) {
  204. self.reviewDataArray = arry;
  205. if (self.model) {
  206. [self updateGoodsDetailsData];
  207. }
  208. } else if ([mark isEqualToString:Goods_RecommendGoods]) {
  209. self.recommendGoodsArr = arry;
  210. if (self.model) {
  211. [self updateGoodsDetailsData];
  212. }
  213. }
  214. } else {
  215. [MBProgressHUD hideHUDForView:self.view animated:YES];
  216. }
  217. }
  218. - (void)updateGoodsDetailsData {
  219. [self.TableV.infodata removeAllObjects];
  220. //商品图
  221. NSDictionary *banner = @{@"type":@"banner", @"data":self.model};
  222. [self.TableV.infodata addObject:banner];
  223. //商品名、价格
  224. NSDictionary *titlePrice = @{@"type":@"titlePrice", @"data":self.model};
  225. [self.TableV.infodata addObject:titlePrice];
  226. //优惠券
  227. NSDictionary *coupon = @{@"type":@"coupon", @"data":self.model};
  228. [self.TableV.infodata addObject:coupon];
  229. //规格
  230. NSDictionary *goodsSize = @{@"type":@"size", @"data":self.model};
  231. [self.TableV.infodata addObject:goodsSize];
  232. //保障信息
  233. NSDictionary *guarantee = @{@"type":@"guarantee", @"data":self.model};
  234. [self.TableV.infodata addObject:guarantee];
  235. //评论头
  236. NSDictionary *reviewHead = @{@"type":@"reviewHead", @"data":self.model};
  237. [self.TableV.infodata addObject:reviewHead];
  238. if (AS_Array_valid(self.reviewDataArray)) {
  239. //评论数据
  240. [self.TableV.infodata addObjectsFromArray:self.reviewDataArray];
  241. //评论底部
  242. NSDictionary *reviewFoot = @{@"type":@"reviewFoot", @"data":self.model};
  243. [self.TableV.infodata addObject:reviewFoot];
  244. }
  245. //推荐商品
  246. if (AS_Array_valid(self.recommendGoodsArr)) {
  247. NSDictionary *customer = @{@"type":@"customer", @"data":self.recommendGoodsArr};
  248. [self.TableV.infodata addObject:customer];
  249. }
  250. // if (self.isReview) {
  251. //
  252. //
  253. // self.TableV.tableFooterView = nil;
  254. //
  255. // } else {
  256. // self.TableV.tableFooterView = _footView;
  257. // }
  258. [self.TableV reloadData];
  259. }
  260. - (void)loadWebString {
  261. _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.001)];
  262. ASGoodsIntrouduceWebView *webInfoView = [[ASGoodsIntrouduceWebView alloc] initWithFrame:CGRectZero];
  263. [_footView addSubview:webInfoView];
  264. [webInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  265. make.edges.mas_equalTo(0);
  266. }];
  267. [webInfoView loadWebUrlWithData:self.model];
  268. K_WEAK_SELF;
  269. webInfoView.loadFinishBlock = ^(float webHeight) {
  270. K_STRONG_SELF;
  271. self.footView.frame = CGRectMake(0, 0, KScreenWidth, webHeight);
  272. [self.TableV reloadData];
  273. };
  274. self.TableV.tableFooterView = _footView;
  275. }
  276. #pragma mark ---- Touch Event ----
  277. //查看评论
  278. -(void)action_GoodsReviewsListC{
  279. AS_GoodsReviewsListC *allPic = [[AS_GoodsReviewsListC alloc]init];
  280. allPic.goodsM = self.model;
  281. [self.navigationController pushViewController:allPic animated:YES];
  282. }
  283. - (void)ucm_bindvmmodel{
  284. self.VM = [[ASGoodsDetailsVM alloc] initDelegate:self];
  285. }
  286. - (GoodsDetailsBottomV *)bottomV {
  287. if (!_bottomV) {
  288. IPhoneXHeigh
  289. _bottomV = [[GoodsDetailsBottomV alloc] initWithFrame:CGRectMake(0, KScreenHeight - securityBottom_H-65, KScreenWidth, securityBottom_H+65)];
  290. _bottomV.backgroundColor = Col_FFF;
  291. }
  292. return _bottomV;
  293. }
  294. @end