AS_GoodsSizeC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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.priceLab];
  67. [self.view addSubview:self.saveLab];
  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.bottom.equalTo(self.sel_headImg);
  86. make.height.mas_equalTo(24);
  87. }];
  88. [self.saveLab mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.left.equalTo(self.priceLab.mas_right).offset(10);
  90. make.height.mas_equalTo(20);
  91. make.centerY.equalTo(self.priceLab);
  92. }];
  93. CGFloat tableVorgY = CGRectGetMaxY(self.sel_headImg.frame)+20;
  94. [self setupTableV:[GoodsSizeSelectTableV class] Frame:CGRectMake(0, tableVorgY, KScreenWidth, KScreenHeight-tableVorgY-self.bottomV.mj_h)];
  95. }
  96. -(void)configFreshData:(GoodsInformationM *)model{
  97. [self.sel_headImg sd_setImageWithURL:[NSURL URLWithString:model.add_gooodsImgUrl] placeholderImage:UIImageDefaultImg_SD];
  98. self.sel_titleLab.text = model.name;
  99. self.priceLab.attributedText = [ASGoodsDetailsVM tool_changePriceAtr:model];
  100. if(model.final_prices == model.price){
  101. self.saveLab.hidden = YES;
  102. }else{
  103. self.saveLab.hidden = NO;
  104. double savePrice = [model.price doubleValue]-[model.final_prices doubleValue];
  105. self.saveLab.text = [NSString stringWithFormat:@"Save %@%.2f",model.currency_symbol,savePrice];
  106. }
  107. for (OptionsModel *optM in model.options) {
  108. optM.optionSelectTag = 0;
  109. }
  110. [self.TableV.infodata removeAllObjects];
  111. self.xxx_optionAry = [NSMutableArray arrayWithArray:model.options];
  112. [self.TableV.infodata addObjectsFromArray:self.xxx_optionAry];
  113. GoodsSizeCountCellData *countM = [[GoodsSizeCountCellData alloc]init];
  114. countM.maxNum = 10;
  115. countM.quantityNum = self.xxx_quantityNum;
  116. [self.TableV.infodata addObject:countM];
  117. GoodsSizePayMentCellData *paytypeM = [[GoodsSizePayMentCellData alloc]init];
  118. paytypeM.paytypeAry = [NSMutableArray arrayWithArray:@[@"paypal",@"afterpay"]];
  119. paytypeM.final_prices_f = [self.model.final_prices floatValue];
  120. paytypeM.currency_symbol = self.model.currency_symbol;
  121. [self.TableV.infodata addObject:paytypeM];
  122. [self.TableV reloadData];
  123. }
  124. #pragma mark - **************** fresh 选择不同规格后的金额变化 ****************
  125. -(void)refresh_optionChangePrice{
  126. CGFloat add_price = 0.00;
  127. for (OptionsModel *optionM in self.xxx_optionAry) {
  128. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  129. add_price = add_price + valuesM.price;
  130. }
  131. self.priceLab.attributedText = [ASGoodsDetailsVM tool_addOptionPrice:add_price quantity:self.xxx_quantityNum infoMoel:self.model];
  132. CGFloat savePrice = ([self.model.price doubleValue]-[self.model.final_prices doubleValue])*self.xxx_quantityNum;
  133. self.saveLab.text = [NSString stringWithFormat:@"Save %@%.2f",self.model.currency_symbol,savePrice];
  134. CGFloat add_final_price_f = (add_price+[self.model.final_prices floatValue])*self.xxx_quantityNum;
  135. [self refresh_PayViewchangeValueCell:add_final_price_f];
  136. }
  137. -(void)refresh_PayViewchangeValueCell:(CGFloat )change_final_prices_f{
  138. GoodsSizePayMentCellData *payModel = (GoodsSizePayMentCellData *)[self.TableV.infodata lastObject];
  139. payModel.final_prices_f = change_final_prices_f;
  140. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.TableV.infodata.count-1 inSection:0];
  141. [self.TableV reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  142. }
  143. #pragma mark - **************** handle ****************
  144. -(void)handle_closeVC{
  145. [self dismissViewControllerAnimated:YES completion:nil];
  146. }
  147. -(void)hanale_isShopOrCart:(NSInteger)type{
  148. //1 shop 2cart
  149. if(type == 1){
  150. self.xxx_isCart = NO;
  151. }else{
  152. self.xxx_isCart = YES;
  153. }
  154. [self reqNet_Size_rewriteCartAddProducts:type];
  155. }
  156. - (void)ucm_bindvmmodel{
  157. self.VM = [[ASGoodsDetailsVM alloc]initDelegate:self];
  158. }
  159. -(void)reqNet_Size_rewriteCartAddProducts:(NSInteger)type{
  160. NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
  161. for (OptionsModel *optionM in self.xxx_optionAry) {
  162. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  163. NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
  164. optionDic[tempStr] =valuesM.option_type_id;
  165. }
  166. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:optionDic];
  167. params[@"product"] = self.model.Id;
  168. params[@"qty"] =[NSString stringWithFormat:@"%ld",(long)self.xxx_quantityNum];
  169. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  170. [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params];
  171. }
  172. - (void)ry_respnsData:(id)data
  173. parseAry:(NSMutableArray *)arry
  174. sucess:(BOOL)sucessOrFail
  175. mark:(NSString *)mark
  176. reqNetType:(ReqNetType)reqNetType{
  177. [MBProgressHUD hideHUDForView:self.view animated:YES];
  178. if(sucessOrFail){
  179. [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  180. if(self.xxx_isCart){
  181. [self dismissViewControllerAnimated:YES completion:^{
  182. }];
  183. }else{
  184. // [self handle_closeVC];
  185. K_WEAK_SELF;
  186. [self dismissViewControllerAnimated:YES completion:^{
  187. K_STRONG_SELF;
  188. Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
  189. [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  190. }];
  191. }
  192. }];
  193. }else{
  194. [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
  195. }
  196. }
  197. - (UIImageView *)sel_headImg {
  198. if (!_sel_headImg) {
  199. _sel_headImg = [[UIImageView alloc] initWithImage:nil];
  200. _sel_headImg.contentMode = UIViewContentModeScaleAspectFill;
  201. _sel_headImg.clipsToBounds = YES;
  202. }
  203. return _sel_headImg;
  204. }
  205. - (QMUILabel *)sel_titleLab {
  206. if (!_sel_titleLab) {
  207. _sel_titleLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  208. _sel_titleLab.textAlignment = NSTextAlignmentLeft;
  209. _sel_titleLab.textColor = [UIColor colorWithHexString:@"#000000"];
  210. _sel_titleLab.font = [UIFont fontWithName:Rob_Regular size:12];
  211. _sel_titleLab.text = @"test";
  212. _sel_titleLab.numberOfLines = 2;
  213. }
  214. return _sel_titleLab;
  215. }
  216. - (QMUILabel *)priceLab {
  217. if (!_priceLab) {
  218. _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  219. _priceLab.textAlignment = NSTextAlignmentLeft;
  220. _priceLab.textColor = [UIColor blackColor];
  221. _priceLab.font = [UIFont fontWithName:Rob_Bold size:18];
  222. }
  223. return _priceLab;
  224. }
  225. - (QMUILabel *)saveLab {
  226. if (!_saveLab) {
  227. _saveLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  228. _saveLab.contentEdgeInsets= UIEdgeInsetsMake(10, 10, 10, 10);
  229. _saveLab.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"];
  230. _saveLab.textAlignment = NSTextAlignmentCenter;
  231. _saveLab.textColor = [UIColor colorWithHexString:@"#113632"];
  232. _saveLab.font = [UIFont fontWithName:Rob_Bold size:12];
  233. }
  234. return _saveLab;
  235. }
  236. - (GoodsDetailsBottomV *)bottomV {
  237. if (!_bottomV) {
  238. IPhoneXHeigh
  239. _bottomV = [[GoodsDetailsBottomV alloc] initWithFrame:CGRectMake(0, KScreenHeight - securityBottom_H-65, KScreenWidth, securityBottom_H+65)];
  240. _bottomV.backgroundColor = Col_FFF;
  241. }
  242. return _bottomV;
  243. }
  244. @end