ASGoodsDetailsViewController.m 15 KB

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