AS_GoodsSizeC.m 10 KB

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