ASGoodsDetailsViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 *couponDataArray;
  25. //评论数据
  26. @property (nonatomic, strong) NSArray *reviewDataArray;
  27. //推荐商品数据
  28. @property (nonatomic, strong) NSArray *recommendGoodsArr;
  29. @property (nonatomic, strong) UIView *footView;
  30. @property (nonatomic, strong) GoodsDetailsBottomV *bottomV;
  31. //尺寸数据
  32. @property (nonatomic, strong) NSDictionary *sizeParam;
  33. //底部按钮点击类型
  34. @property (nonatomic, assign) NSInteger bottomClickType;
  35. //底部按钮点击类型
  36. @property (nonatomic, assign) BOOL isReview;
  37. @end
  38. @implementation ASGoodsDetailsViewController
  39. - (void)viewDidLoad {
  40. [super viewDidLoad];
  41. [self reqNet_GoodsDetailsCouponData];
  42. [self reqNet_Goods_productGetProductsReview];
  43. [self reqNet_GoodsDetails_productGetProduct];
  44. [self request_RecommendGoodsData];
  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. if (num != 1) {
  65. [[ASFireBaseEventManager shareInstance] addcartEventWithCur:[ASCurrencyManager shared].currentCur value:self.model.final_prices.doubleValue items:@[@{@"item_name":self.model.name, @"item_id":self.model.Id}]];
  66. }
  67. };
  68. IPhoneXHeigh
  69. [self setupTableV:[ASGoodsDetailsTableView class] Frame:CGRectMake(0, securitytop_Y , KScreenWidth, KScreenHeight - securitytop_Y - securityBottom_H - 65)];
  70. self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  71. self.TableV.estimatedRowHeight = 0;
  72. self.TableV.estimatedSectionHeaderHeight = 0;
  73. self.TableV.estimatedSectionFooterHeight = 0;
  74. K_WEAK_SELF;
  75. self.TableV.tapClose = ^(NSInteger num, id data) {
  76. K_STRONG_SELF;
  77. if (num == 1 || num == 5) {//查看评论
  78. [self action_GoodsReviewsListC];
  79. } else if (num == 2) {//商品web详情
  80. self.isReview = NO;
  81. self.TableV.isReview = NO;
  82. self.TableV.tableFooterView = self.footView;
  83. [self.TableV reloadData];
  84. // [self updateGoodsDetailsData];
  85. } else if (num == 3) {//商品评论列表
  86. self.isReview = YES;
  87. self.TableV.isReview = YES;
  88. self.TableV.tableFooterView = nil;
  89. [self.TableV reloadData];
  90. // [self updateGoodsDetailsData];
  91. } else if (num == 4) {//写商品评论
  92. if (![ASUserInfoManager shared].isLogin) {
  93. [Fuction_Tool pop_toLoginVC];
  94. return;
  95. }
  96. GoodsReviewsWriteC *vc = [[GoodsReviewsWriteC alloc]init];
  97. vc.goodsM = self.model;
  98. // vc.topBgV = self.topBgV;
  99. vc.nav_title = [NSString stringWithFormat:@"REVIEWS (%@)",self.model.review_nums];
  100. [self.navigationController pushViewController:vc animated:YES];
  101. } else if (num == 100) {
  102. self.sizeParam = (NSDictionary *)data;
  103. // self.model.final_prices = @""
  104. [self refresh_optionChangePrice];
  105. } else if (num == 101) {//推荐商品跳转
  106. ASProductBaseModel *model = (ASProductBaseModel *)data;
  107. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":model.Id}];
  108. [self.navigationController pushViewController:viewController animated:YES];
  109. } else if (num == 102) {//推荐商品加车
  110. ASProductBaseModel *model = (ASProductBaseModel *)data;
  111. [self action_GoodsSizeC:model.Id];
  112. } else if (num == 1000) {
  113. [self.TableV reloadData];
  114. }
  115. };
  116. }
  117. #pragma mark - **************** fresh 选择不同规格后的金额变化 ****************
  118. -(void)refresh_optionChangePrice{
  119. CGFloat add_price = 0.00;
  120. for (OptionsModel *optionM in self.model.options) {
  121. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  122. add_price = add_price + valuesM.price;
  123. }
  124. NSInteger num = [[self.sizeParam objectForKey:@"qty"] integerValue];
  125. float discount = [self.model.percent floatValue];
  126. if (discount == 0) {
  127. //优惠价
  128. CGFloat add_final_price_f = (add_price + [self.model.final_prices floatValue]) * num;
  129. self.model.show_final_prices = [NSString stringWithFormat:@"%.2lf", add_final_price_f];
  130. //原价
  131. CGFloat show_prices = (add_price + [self.model.price floatValue]) * num;
  132. self.model.show_prices = [NSString stringWithFormat:@"%.2lf", show_prices];
  133. } else {
  134. //优惠价
  135. float discount1 = (100.00 - discount) / 100.00;
  136. CGFloat add_final_price_f = (add_price * discount1 + [self.model.final_prices floatValue]) * num;
  137. self.model.show_final_prices = [NSString stringWithFormat:@"%.2lf", add_final_price_f];
  138. //原价
  139. CGFloat show_prices = (add_price + [self.model.price floatValue]) * num;
  140. self.model.show_prices = [NSString stringWithFormat:@"%.2lf", show_prices];
  141. }
  142. //通知价格变化
  143. [NSNotificationCenter.defaultCenter postNotificationName:GoodsDetailsUpdatePrice object:nil];
  144. }
  145. //请求尺寸
  146. -(void)action_GoodsSizeC:(NSString *)entity_id {
  147. if (!ASUserInfoManager.shared.isLogin) {
  148. [Fuction_Tool pop_toLoginVC];
  149. return;
  150. }
  151. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  152. [params setObject:entity_id forKey:@"productId"];
  153. [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
  154. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  155. __weak typeof(self) weakSelf = self;
  156. [ASNetTools.shared getWithPath:getProdectDetail param:params success:^(id _Nonnull json) {
  157. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  158. GoodsInformationM *model = [GoodsInformationM mj_objectWithKeyValues:json];
  159. if (model == nil || model.Id == nil || model.Id.isEmpty) {
  160. return;
  161. }
  162. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsSizeC:@{@"model":model}];
  163. viewController.modalPresentationStyle = UIModalPresentationFullScreen;
  164. [weakSelf presentViewController:viewController animated:YES completion:nil];
  165. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  166. [self.view makeToast:msg];
  167. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  168. }];
  169. }
  170. -(void)reqNet_Size_rewriteCartAddProducts {
  171. if (![ASUserInfoManager shared].isLogin) {
  172. [Fuction_Tool pop_toLoginVC];
  173. return;
  174. }
  175. if (!AS_Dict_valid(self.sizeParam)) {
  176. NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
  177. for (OptionsModel *optionM in self.model.options) {
  178. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  179. NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
  180. optionDic[tempStr] =valuesM.option_type_id;
  181. }
  182. NSMutableDictionary *sizeDic = [NSMutableDictionary dictionaryWithDictionary:optionDic];
  183. sizeDic[@"qty"] = [NSString stringWithFormat:@"%@", @"1"];
  184. self.sizeParam = sizeDic;
  185. }
  186. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.sizeParam];
  187. params[@"product"] = self.model.Id;
  188. NSLog(@"=====%@", params);
  189. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  190. [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params];
  191. }
  192. //商品详情信息
  193. -(void)reqNet_GoodsDetails_productGetProduct{
  194. NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
  195. // [params setObject:@"55475" forKey:@"productId"];
  196. [params setObject:self.entity_id forKey:@"productId"];
  197. [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
  198. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  199. [self.VM ry_requestGetApi:Goods_productGetProductsById param:params];
  200. }
  201. //商品评论
  202. -(void)reqNet_Goods_productGetProductsReview{
  203. NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
  204. [params setObject:self.entity_id forKey:@"pid"];
  205. // [params setObject:@0 forKey:@"img"];
  206. [params setObject:@"sortreview" forKey:@"sortreview"];
  207. [params setObject:@(self.TableV.Page) forKey:@"p"];
  208. [params setObject:@3 forKey:@"limit"];
  209. [self.VM ry_requestGetApi:Goods_productGetProductsReview param:params];
  210. }
  211. //推荐商品
  212. - (void)request_RecommendGoodsData {
  213. [self.VM ry_requestGetApi:Goods_RecommendGoods param:@{}];
  214. }
  215. //商品优惠券
  216. - (void)reqNet_GoodsDetailsCouponData {
  217. [self.VM ry_requestGetApi:Goods_productCoupon param:@{}];
  218. }
  219. -(void)ry_respnsData:(nullable id)data
  220. parseAry:(nullable NSMutableArray *)arry
  221. sucess:(BOOL)sucessOrFail
  222. mark:(NSString *)mark
  223. reqNetType:(ReqNetType)reqNetType{
  224. if(sucessOrFail){
  225. if([mark isEqualToString:Goods_productGetProductsById]){
  226. [MBProgressHUD hideHUDForView:self.view animated:YES];
  227. GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
  228. self.model = model;
  229. self.title = model.name;
  230. [[ASFireBaseEventManager shareInstance] viewItemEventWithCur:[ASCurrencyManager shared].currentCur value:model.final_prices.doubleValue items:@[@{@"item_id":model.Id,@"item_name":model.name}]];
  231. // NSLog(@"=======%@", [arry objectAtIndex:9]);
  232. [self updateGoodsDetailsData];
  233. [self loadWebString];
  234. } else if([mark isEqualToString:Size_rewriteCartAddProducts]) {
  235. [MBProgressHUD hideHUDForView:self.view animated:YES];
  236. [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  237. if (self.bottomClickType == 1) {
  238. Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
  239. [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  240. }
  241. }];
  242. } else if ([mark isEqualToString:Goods_productGetProductsReview]) {
  243. self.reviewDataArray = arry;
  244. if (self.model) {
  245. [self updateGoodsDetailsData];
  246. }
  247. } else if ([mark isEqualToString:Goods_RecommendGoods]) {
  248. self.recommendGoodsArr = arry;
  249. if (self.model) {
  250. [self updateGoodsDetailsData];
  251. }
  252. } else if ([mark isEqualToString:Goods_productCoupon]) {
  253. self.couponDataArray = arry;
  254. if (self.model) {
  255. [self updateGoodsDetailsData];
  256. }
  257. }
  258. } else {
  259. [MBProgressHUD hideHUDForView:self.view animated:YES];
  260. }
  261. }
  262. - (void)updateGoodsDetailsData {
  263. [self.TableV.infodata removeAllObjects];
  264. //商品图
  265. NSDictionary *banner = @{@"type":@"banner", @"data":self.model};
  266. [self.TableV.infodata addObject:banner];
  267. //商品名、价格
  268. NSDictionary *titlePrice = @{@"type":@"titlePrice", @"data":self.model};
  269. [self.TableV.infodata addObject:titlePrice];
  270. //优惠券
  271. if (AS_Array_valid(self.couponDataArray)) {
  272. NSDictionary *coupon = @{@"type":@"coupon", @"data":self.couponDataArray};
  273. [self.TableV.infodata addObject:coupon];
  274. }
  275. //规格
  276. NSDictionary *goodsSize = @{@"type":@"size", @"data":self.model};
  277. [self.TableV.infodata addObject:goodsSize];
  278. //保障信息
  279. NSDictionary *guarantee = @{@"type":@"guarantee", @"data":self.model};
  280. [self.TableV.infodata addObject:guarantee];
  281. //评论头
  282. NSDictionary *reviewHead = @{@"type":@"reviewHead", @"data":self.model};
  283. [self.TableV.infodata addObject:reviewHead];
  284. if (AS_Array_valid(self.reviewDataArray)) {
  285. //评论数据
  286. [self.TableV.infodata addObjectsFromArray:self.reviewDataArray];
  287. //评论底部
  288. NSDictionary *reviewFoot = @{@"type":@"reviewFoot", @"data":self.model};
  289. [self.TableV.infodata addObject:reviewFoot];
  290. }
  291. //推荐商品
  292. if (AS_Array_valid(self.recommendGoodsArr)) {
  293. NSDictionary *customer = @{@"type":@"customer", @"data":self.recommendGoodsArr};
  294. [self.TableV.infodata addObject:customer];
  295. }
  296. [self.TableV reloadData];
  297. }
  298. - (void)loadWebString {
  299. _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.001)];
  300. ASGoodsIntrouduceWebView *webInfoView = [[ASGoodsIntrouduceWebView alloc] initWithFrame:CGRectZero];
  301. [_footView addSubview:webInfoView];
  302. [webInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  303. make.edges.mas_equalTo(0);
  304. }];
  305. [webInfoView loadWebUrlWithData:self.model];
  306. K_WEAK_SELF;
  307. webInfoView.loadFinishBlock = ^(float webHeight) {
  308. K_STRONG_SELF;
  309. self.footView.frame = CGRectMake(0, 0, KScreenWidth, webHeight);
  310. [self.TableV reloadData];
  311. };
  312. self.TableV.tableFooterView = _footView;
  313. }
  314. #pragma mark ---- Touch Event ----
  315. //查看评论
  316. -(void)action_GoodsReviewsListC{
  317. AS_GoodsReviewsListC *allPic = [[AS_GoodsReviewsListC alloc]init];
  318. allPic.goodsM = self.model;
  319. [self.navigationController pushViewController:allPic animated:YES];
  320. }
  321. - (void)_shareClick {
  322. [Fuction_Tool tool_shareImgStr:self.model.add_gooodsImgUrl sharetitle:self.model.name shareUrl:self.model.href currentVC:self];
  323. }
  324. - (void)ucm_bindvmmodel{
  325. self.VM = [[ASGoodsDetailsVM alloc] initDelegate:self];
  326. }
  327. - (GoodsDetailsBottomV *)bottomV {
  328. if (!_bottomV) {
  329. IPhoneXHeigh
  330. _bottomV = [[GoodsDetailsBottomV alloc] initWithFrame:CGRectMake(0, KScreenHeight - securityBottom_H-65, KScreenWidth, securityBottom_H+65)];
  331. _bottomV.backgroundColor = Col_FFF;
  332. }
  333. return _bottomV;
  334. }
  335. @end