ASGoodsDetailsViewController.m 15 KB

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