ASGoodsDetailsViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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)_shareClick {
  47. [Fuction_Tool tool_shareImgStr:self.model.add_gooodsImgUrl sharetitle:self.model.name shareUrl:@"https://www.baidu.com" currentVC:self];
  48. }
  49. - (void)initSubviews {
  50. [super initSubviews];
  51. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  52. [button setImage:[UIImage imageNamed:@"share_icon"] forState:UIControlStateNormal];
  53. [button addTarget:self action:@selector(_shareClick) forControlEvents:UIControlEventTouchUpInside];
  54. // button.backgroundColor = [UIColor yellowColor];
  55. [self.customNavBar addSubview:button];
  56. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.right.mas_equalTo(-8);
  58. make.bottom.mas_equalTo(-2);
  59. make.width.height.mas_equalTo(40);
  60. }];
  61. [self.view addSubview:self.bottomV];
  62. @weakify(self)
  63. self.bottomV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {
  64. @strongify(self)
  65. self.bottomClickType = num;
  66. [self reqNet_Size_rewriteCartAddProducts];
  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. discount = (100.00 - discount) / 100.00;
  136. CGFloat add_final_price_f = (add_price * discount + [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. [NSNotificationCenter.defaultCenter postNotificationName:GoodsDetailsUpdatePrice object:nil];
  143. }
  144. //请求尺寸
  145. -(void)action_GoodsSizeC:(NSString *)entity_id {
  146. if (!ASUserInfoManager.shared.isLogin) {
  147. [Fuction_Tool pop_toLoginVC];
  148. return;
  149. }
  150. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  151. [params setObject:entity_id forKey:@"productId"];
  152. [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
  153. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  154. __weak typeof(self) weakSelf = self;
  155. [ASNetTools.shared getWithPath:getProdectDetail param:params success:^(id _Nonnull json) {
  156. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  157. GoodsInformationM *model = [GoodsInformationM mj_objectWithKeyValues:json];
  158. if (model == nil || model.Id == nil || model.Id.isEmpty) {
  159. return;
  160. }
  161. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsSizeC:@{@"model":model}];
  162. viewController.modalPresentationStyle = UIModalPresentationFullScreen;
  163. [weakSelf presentViewController:viewController animated:YES completion:nil];
  164. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  165. [self.view makeToast:msg];
  166. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  167. }];
  168. }
  169. -(void)reqNet_Size_rewriteCartAddProducts {
  170. if (![ASUserInfoManager shared].isLogin) {
  171. [Fuction_Tool pop_toLoginVC];
  172. return;
  173. }
  174. if (!AS_Dict_valid(self.sizeParam)) {
  175. NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
  176. for (OptionsModel *optionM in self.model.options) {
  177. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  178. NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
  179. optionDic[tempStr] =valuesM.option_type_id;
  180. }
  181. NSMutableDictionary *sizeDic = [NSMutableDictionary dictionaryWithDictionary:optionDic];
  182. sizeDic[@"qty"] = [NSString stringWithFormat:@"%@", @"1"];
  183. self.sizeParam = sizeDic;
  184. }
  185. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.sizeParam];
  186. params[@"product"] = self.model.Id;
  187. NSLog(@"=====%@", params);
  188. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  189. [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params];
  190. }
  191. //商品详情信息
  192. -(void)reqNet_GoodsDetails_productGetProduct{
  193. NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
  194. // [params setObject:@"55475" forKey:@"productId"];
  195. [params setObject:self.entity_id forKey:@"productId"];
  196. [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
  197. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  198. [self.VM ry_requestGetApi:Goods_productGetProductsById param:params];
  199. }
  200. //商品评论
  201. -(void)reqNet_Goods_productGetProductsReview{
  202. NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
  203. [params setObject:self.entity_id forKey:@"pid"];
  204. // [params setObject:@0 forKey:@"img"];
  205. [params setObject:@"sortreview" forKey:@"sortreview"];
  206. [params setObject:@(self.TableV.Page) forKey:@"p"];
  207. [params setObject:@3 forKey:@"limit"];
  208. [self.VM ry_requestGetApi:Goods_productGetProductsReview param:params];
  209. }
  210. //推荐商品
  211. - (void)request_RecommendGoodsData {
  212. [self.VM ry_requestGetApi:Goods_RecommendGoods param:@{}];
  213. }
  214. //商品优惠券
  215. - (void)reqNet_GoodsDetailsCouponData {
  216. [self.VM ry_requestGetApi:Goods_productCoupon param:@{}];
  217. }
  218. -(void)ry_respnsData:(nullable id)data
  219. parseAry:(nullable NSMutableArray *)arry
  220. sucess:(BOOL)sucessOrFail
  221. mark:(NSString *)mark
  222. reqNetType:(ReqNetType)reqNetType{
  223. if(sucessOrFail){
  224. if([mark isEqualToString:Goods_productGetProductsById]){
  225. [MBProgressHUD hideHUDForView:self.view animated:YES];
  226. GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
  227. self.model = model;
  228. self.title = model.name;
  229. [self updateGoodsDetailsData];
  230. [self loadWebString];
  231. } else if([mark isEqualToString:Size_rewriteCartAddProducts]) {
  232. [MBProgressHUD hideHUDForView:self.view animated:YES];
  233. [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  234. if (self.bottomClickType == 1) {
  235. Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
  236. [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  237. }
  238. }];
  239. } else if ([mark isEqualToString:Goods_productGetProductsReview]) {
  240. self.reviewDataArray = arry;
  241. if (self.model) {
  242. [self updateGoodsDetailsData];
  243. }
  244. } else if ([mark isEqualToString:Goods_RecommendGoods]) {
  245. self.recommendGoodsArr = arry;
  246. if (self.model) {
  247. [self updateGoodsDetailsData];
  248. }
  249. } else if ([mark isEqualToString:Goods_productCoupon]) {
  250. self.couponDataArray = arry;
  251. if (self.model) {
  252. [self updateGoodsDetailsData];
  253. }
  254. }
  255. } else {
  256. [MBProgressHUD hideHUDForView:self.view animated:YES];
  257. }
  258. }
  259. - (void)updateGoodsDetailsData {
  260. [self.TableV.infodata removeAllObjects];
  261. //商品图
  262. NSDictionary *banner = @{@"type":@"banner", @"data":self.model};
  263. [self.TableV.infodata addObject:banner];
  264. //商品名、价格
  265. NSDictionary *titlePrice = @{@"type":@"titlePrice", @"data":self.model};
  266. [self.TableV.infodata addObject:titlePrice];
  267. //优惠券
  268. if (AS_Array_valid(self.couponDataArray)) {
  269. NSDictionary *coupon = @{@"type":@"coupon", @"data":self.couponDataArray};
  270. [self.TableV.infodata addObject:coupon];
  271. }
  272. //规格
  273. NSDictionary *goodsSize = @{@"type":@"size", @"data":self.model};
  274. [self.TableV.infodata addObject:goodsSize];
  275. //保障信息
  276. NSDictionary *guarantee = @{@"type":@"guarantee", @"data":self.model};
  277. [self.TableV.infodata addObject:guarantee];
  278. //评论头
  279. NSDictionary *reviewHead = @{@"type":@"reviewHead", @"data":self.model};
  280. [self.TableV.infodata addObject:reviewHead];
  281. if (AS_Array_valid(self.reviewDataArray)) {
  282. //评论数据
  283. [self.TableV.infodata addObjectsFromArray:self.reviewDataArray];
  284. //评论底部
  285. NSDictionary *reviewFoot = @{@"type":@"reviewFoot", @"data":self.model};
  286. [self.TableV.infodata addObject:reviewFoot];
  287. }
  288. //推荐商品
  289. if (AS_Array_valid(self.recommendGoodsArr)) {
  290. NSDictionary *customer = @{@"type":@"customer", @"data":self.recommendGoodsArr};
  291. [self.TableV.infodata addObject:customer];
  292. }
  293. // if (self.isReview) {
  294. //
  295. //
  296. // self.TableV.tableFooterView = nil;
  297. //
  298. // } else {
  299. // self.TableV.tableFooterView = _footView;
  300. // }
  301. [self.TableV reloadData];
  302. }
  303. - (void)loadWebString {
  304. _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.001)];
  305. ASGoodsIntrouduceWebView *webInfoView = [[ASGoodsIntrouduceWebView alloc] initWithFrame:CGRectZero];
  306. [_footView addSubview:webInfoView];
  307. [webInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  308. make.edges.mas_equalTo(0);
  309. }];
  310. [webInfoView loadWebUrlWithData:self.model];
  311. K_WEAK_SELF;
  312. webInfoView.loadFinishBlock = ^(float webHeight) {
  313. K_STRONG_SELF;
  314. self.footView.frame = CGRectMake(0, 0, KScreenWidth, webHeight);
  315. [self.TableV reloadData];
  316. };
  317. self.TableV.tableFooterView = _footView;
  318. }
  319. #pragma mark ---- Touch Event ----
  320. //查看评论
  321. -(void)action_GoodsReviewsListC{
  322. AS_GoodsReviewsListC *allPic = [[AS_GoodsReviewsListC alloc]init];
  323. allPic.goodsM = self.model;
  324. [self.navigationController pushViewController:allPic animated:YES];
  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