AS_GoodsSizeC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. //
  2. // AS_GoodsSizeC.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2024/1/23.
  6. //
  7. #import "AS_GoodsSizeC.h"
  8. #import "GoodsSizeSelectTableV.h"
  9. #import "GoodsDetailsBottomV.h"
  10. #import "ASGoodsDetailsVM.h"
  11. #import "Cart_CheckoutC.h"
  12. @interface AS_GoodsSizeC ()<RY_baseVMprotocol>
  13. @property (nonatomic, strong) UIImageView *sel_headImg;
  14. @property (nonatomic, strong) QMUILabel *sel_titleLab;
  15. @property (nonatomic, strong) QMUILabel *priceLab;
  16. @property (nonatomic, strong) QMUILabel *saveLab;
  17. @property (nonatomic, strong) GoodsSizeSelectTableV *TableV;
  18. @property (nonatomic, strong) GoodsDetailsBottomV *bottomV;
  19. //商品的数量
  20. @property (nonatomic, assign) NSInteger xxx_quantityNum;
  21. //所有的规格数据
  22. @property (nonatomic, strong) NSMutableArray <OptionsModel *>*xxx_optionAry;
  23. @property (nonatomic, strong) ASGoodsDetailsVM *VM;
  24. @property (nonatomic, assign) BOOL xxx_isCart;
  25. @end
  26. @implementation AS_GoodsSizeC
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. [self ucm_subVeiwsTapBlock];
  31. [self ucm_configNavbar];
  32. self.xxx_quantityNum = 1;
  33. if(self.model){
  34. [self configFreshData:self.model];
  35. }
  36. }
  37. - (void)ucm_configNavbar{
  38. self.navigationController.navigationBar.hidden = YES;
  39. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  40. [closeBtn setImage:[UIImage imageNamed:@"base_close_black"] forState:UIControlStateNormal];
  41. [closeBtn addTarget:self action:@selector(handle_closeVC) forControlEvents:UIControlEventTouchUpInside];
  42. [self.view addSubview:closeBtn];
  43. NSInteger top = IPHONEX ? 44 : 20;
  44. closeBtn.frame = CGRectMake(KScreenWidth -44-20, top, 44, 44);
  45. }
  46. - (void)ucm_subVeiwsTapBlock{
  47. @weakify(self)
  48. self.TableV.tapClose = ^(NSInteger num, id data) {
  49. //选择规格xxx_optionAry 和 修改商品数量xxx_quantityNum
  50. @strongify(self)
  51. if([data isKindOfClass:[GoodsSizeCountCellData class]]){
  52. GoodsSizeCountCellData *model = (GoodsSizeCountCellData *)data;
  53. self.xxx_quantityNum = model.quantityNum;
  54. }
  55. [self refresh_optionChangePrice];
  56. };
  57. self.bottomV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {
  58. @strongify(self)
  59. [self hanale_isShopOrCart:num];
  60. };
  61. }
  62. - (void)initSubviews {
  63. [super initSubviews];
  64. [self.view addSubview:self.sel_headImg];
  65. [self.view addSubview:self.sel_titleLab];
  66. [self.view addSubview:self.saveLab];
  67. [self.view addSubview:self.priceLab];
  68. [self.view addSubview:self.bottomV];
  69. IPhoneXHeigh
  70. self.sel_headImg.frame = CGRectMake(10, securitytop_Y +10, 93, 93);
  71. self.sel_titleLab.frame = CGRectMake(CGRectGetMaxX(self.sel_headImg.frame)+10, securitytop_Y +10,KScreenWidth - 93-10-20,40);
  72. [self.sel_headImg mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_equalTo(10);
  74. make.top.mas_equalTo(securitytop_Y +10);
  75. make.width.height.mas_equalTo(93);
  76. }];
  77. [self.sel_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.top.mas_equalTo(securitytop_Y +10);
  79. make.left.equalTo(self.sel_headImg.mas_right).offset(10);
  80. make.right.mas_equalTo(-10);
  81. make.height.mas_equalTo(40);
  82. }];
  83. [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.equalTo(self.sel_headImg.mas_right).offset(10);
  85. // make.right.equalTo(self.saveLab.mas_left).offset(-4);
  86. make.width.mas_lessThanOrEqualTo((KScreenWidth - 128)/3 * 2);
  87. make.bottom.equalTo(self.sel_headImg);
  88. make.height.mas_equalTo(24);
  89. }];
  90. [self.saveLab mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.equalTo(self.priceLab.mas_right).offset(5);
  92. make.height.mas_equalTo(20);
  93. make.centerY.equalTo(self.priceLab);
  94. make.width.mas_lessThanOrEqualTo((KScreenWidth - 128)/3);
  95. }];
  96. CGFloat tableVorgY = CGRectGetMaxY(self.sel_headImg.frame)+20;
  97. [self setupTableV:[GoodsSizeSelectTableV class] Frame:CGRectMake(0, tableVorgY, KScreenWidth, KScreenHeight-tableVorgY-self.bottomV.mj_h)];
  98. }
  99. -(void)configFreshData:(GoodsInformationM *)model{
  100. NSArray *media_gallery_entries = model.media_gallery_entries;
  101. NSString *imageUrl = @"";
  102. if (AS_Array_valid(media_gallery_entries)) {
  103. MediaGalleryEntriesModel *model = media_gallery_entries.firstObject;
  104. imageUrl = [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,model.file];
  105. }
  106. [self.sel_headImg sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:UIImageDefaultImg_SD];
  107. self.sel_titleLab.text = model.name;
  108. self.priceLab.attributedText = [ASGoodsDetailsVM tool_changePriceAtr:model];
  109. if([model.final_prices isEqualToString:model.price]){
  110. self.saveLab.hidden = YES;
  111. }else{
  112. self.saveLab.hidden = NO;
  113. double savePrice = [model.price doubleValue]-[model.final_prices doubleValue];
  114. self.saveLab.text = [NSString stringWithFormat:@" Save %@%.2f ",model.currency_symbol,savePrice];
  115. }
  116. for (OptionsModel *optM in model.options) {
  117. optM.optionSelectTag = 0;
  118. }
  119. [self.TableV.infodata removeAllObjects];
  120. self.xxx_optionAry = [NSMutableArray arrayWithArray:model.options];
  121. [self.TableV.infodata addObjectsFromArray:self.xxx_optionAry];
  122. GoodsSizeCountCellData *countM = [[GoodsSizeCountCellData alloc]init];
  123. countM.maxNum = 10;
  124. countM.quantityNum = self.xxx_quantityNum;
  125. [self.TableV.infodata addObject:countM];
  126. GoodsSizePayMentCellData *paytypeM = [[GoodsSizePayMentCellData alloc]init];
  127. paytypeM.paytypeAry = [NSMutableArray arrayWithArray:@[@"paypal",@"afterpay"]];
  128. paytypeM.final_prices_f = [self.model.final_prices floatValue];
  129. paytypeM.currency_symbol = self.model.currency_symbol;
  130. [self.TableV.infodata addObject:paytypeM];
  131. [self.TableV reloadData];
  132. }
  133. #pragma mark - **************** fresh 选择不同规格后的金额变化 ****************
  134. -(void)refresh_optionChangePrice{
  135. CGFloat add_price = 0.00;
  136. for (OptionsModel *optionM in self.xxx_optionAry) {
  137. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  138. add_price = add_price + valuesM.price;
  139. }
  140. float discount = [self.model.percent floatValue];
  141. if (discount == 0) {
  142. //优惠价
  143. CGFloat add_final_price_f = (add_price + [self.model.final_prices floatValue]) * self.xxx_quantityNum;
  144. self.model.show_final_prices = [NSString stringWithFormat:@"%.2lf", add_final_price_f];
  145. //原价
  146. CGFloat show_prices = (add_price + [self.model.price floatValue]) * self.xxx_quantityNum;
  147. self.model.show_prices = [NSString stringWithFormat:@"%.2lf", show_prices];
  148. } else {
  149. //优惠价
  150. discount = (100.00 - discount) / 100.00;
  151. CGFloat add_final_price_f = (add_price * discount + [self.model.final_prices floatValue]) * self.xxx_quantityNum;
  152. self.model.show_final_prices = [NSString stringWithFormat:@"%.2lf", add_final_price_f];
  153. //原价
  154. CGFloat show_prices = (add_price + [self.model.price floatValue]) * self.xxx_quantityNum;
  155. self.model.show_prices = [NSString stringWithFormat:@"%.2lf", show_prices];
  156. }
  157. self.priceLab.attributedText = [ASGoodsDetailsVM tool_addOptionPrice:add_price quantity:self.xxx_quantityNum infoMoel:self.model];
  158. CGFloat savePrice = ([self.model.show_prices doubleValue]-[self.model.show_final_prices doubleValue]);
  159. self.saveLab.text = [NSString stringWithFormat:@" Save %@%.2f ",self.model.currency_symbol,savePrice];
  160. CGFloat add_final_price_f = [self.model.show_final_prices doubleValue];
  161. [self refresh_PayViewchangeValueCell:add_final_price_f];
  162. }
  163. -(void)refresh_PayViewchangeValueCell:(CGFloat )change_final_prices_f{
  164. GoodsSizePayMentCellData *payModel = (GoodsSizePayMentCellData *)[self.TableV.infodata lastObject];
  165. payModel.final_prices_f = change_final_prices_f;
  166. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.TableV.infodata.count-1 inSection:0];
  167. [self.TableV reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  168. }
  169. #pragma mark - **************** handle ****************
  170. -(void)handle_closeVC{
  171. [self dismissViewControllerAnimated:YES completion:nil];
  172. }
  173. -(void)hanale_isShopOrCart:(NSInteger)type{
  174. //1 shop 2cart
  175. if(type == 1){
  176. self.xxx_isCart = NO;
  177. }else{
  178. self.xxx_isCart = YES;
  179. }
  180. [self reqNet_Size_rewriteCartAddProducts:type];
  181. }
  182. - (void)ucm_bindvmmodel{
  183. self.VM = [[ASGoodsDetailsVM alloc]initDelegate:self];
  184. }
  185. -(void)reqNet_Size_rewriteCartAddProducts:(NSInteger)type{
  186. NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
  187. for (OptionsModel *optionM in self.xxx_optionAry) {
  188. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  189. NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
  190. optionDic[tempStr] =valuesM.option_type_id;
  191. }
  192. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:optionDic];
  193. params[@"product"] = self.model.Id;
  194. params[@"qty"] =[NSString stringWithFormat:@"%ld",(long)self.xxx_quantityNum];
  195. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  196. [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params];
  197. }
  198. - (void)ry_respnsData:(id)data
  199. parseAry:(NSMutableArray *)arry
  200. sucess:(BOOL)sucessOrFail
  201. mark:(NSString *)mark
  202. reqNetType:(ReqNetType)reqNetType{
  203. [MBProgressHUD hideHUDForView:self.view animated:YES];
  204. if(sucessOrFail){
  205. [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  206. if(self.xxx_isCart){
  207. [self dismissViewControllerAnimated:YES completion:^{
  208. }];
  209. }else{
  210. // [self handle_closeVC];
  211. // K_WEAK_SELF;
  212. [self dismissViewControllerAnimated:YES completion:^{
  213. // K_STRONG_SELF;
  214. Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
  215. [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  216. }];
  217. }
  218. }];
  219. }else{
  220. [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
  221. }
  222. }
  223. - (UIImageView *)sel_headImg {
  224. if (!_sel_headImg) {
  225. _sel_headImg = [[UIImageView alloc] initWithImage:nil];
  226. _sel_headImg.contentMode = UIViewContentModeScaleAspectFill;
  227. _sel_headImg.clipsToBounds = YES;
  228. }
  229. return _sel_headImg;
  230. }
  231. - (QMUILabel *)sel_titleLab {
  232. if (!_sel_titleLab) {
  233. _sel_titleLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  234. _sel_titleLab.textAlignment = NSTextAlignmentLeft;
  235. _sel_titleLab.textColor = [UIColor colorWithHexString:@"#000000"];
  236. _sel_titleLab.font = [UIFont fontWithName:Rob_Regular size:12];
  237. _sel_titleLab.text = @"test";
  238. _sel_titleLab.numberOfLines = 2;
  239. }
  240. return _sel_titleLab;
  241. }
  242. - (QMUILabel *)priceLab {
  243. if (!_priceLab) {
  244. _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  245. _priceLab.textAlignment = NSTextAlignmentLeft;
  246. _priceLab.textColor = [UIColor blackColor];
  247. _priceLab.font = [UIFont fontWithName:Rob_Bold size:20];
  248. _priceLab.adjustsFontSizeToFitWidth = YES;
  249. }
  250. return _priceLab;
  251. }
  252. - (QMUILabel *)saveLab {
  253. if (!_saveLab) {
  254. _saveLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  255. // _saveLab.contentEdgeInsets= UIEdgeInsetsMake(10, 10, 10, 10);
  256. _saveLab.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"];
  257. _saveLab.textAlignment = NSTextAlignmentCenter;
  258. _saveLab.textColor = [UIColor colorWithHexString:@"#113632"];
  259. _saveLab.font = [UIFont fontWithName:Rob_Bold size:12];
  260. _saveLab.adjustsFontSizeToFitWidth = YES;
  261. }
  262. return _saveLab;
  263. }
  264. - (GoodsDetailsBottomV *)bottomV {
  265. if (!_bottomV) {
  266. IPhoneXHeigh
  267. _bottomV = [[GoodsDetailsBottomV alloc] initWithFrame:CGRectMake(0, KScreenHeight - securityBottom_H-65, KScreenWidth, securityBottom_H+65)];
  268. _bottomV.backgroundColor = Col_FFF;
  269. }
  270. return _bottomV;
  271. }
  272. @end