// // AS_GoodsSizeC.m // Asteria // // Created by 王猛 on 2024/1/23. // #import "AS_GoodsSizeC.h" #import "GoodsSizeSelectTableV.h" #import "GoodsDetailsBottomV.h" #import "ASGoodsDetailsVM.h" @interface AS_GoodsSizeC () @property (nonatomic, strong) UIImageView *sel_headImg; @property (nonatomic, strong) QMUILabel *sel_titleLab; @property (nonatomic, strong) QMUILabel *priceLab; @property (nonatomic, strong) QMUILabel *saveLab; @property (nonatomic, strong) GoodsSizeSelectTableV *TableV; @property (nonatomic, strong) GoodsDetailsBottomV *bottomV; //商品的数量 @property (nonatomic, assign) NSInteger xxx_quantityNum; //所有的规格数据 @property (nonatomic, strong) NSMutableArray *xxx_optionAry; @property (nonatomic, strong) ASGoodsDetailsVM *VM; @property (nonatomic, assign) BOOL xxx_isCart; @end @implementation AS_GoodsSizeC - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self ucm_subVeiwsTapBlock]; [self ucm_configNavbar]; self.xxx_quantityNum = 1; if(self.model){ [self configFreshData:self.model]; } } - (void)ucm_configNavbar{ self.navigationController.navigationBar.hidden = YES; UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [closeBtn setImage:[UIImage imageNamed:@"base_close_black"] forState:UIControlStateNormal]; [closeBtn addTarget:self action:@selector(handle_closeVC) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:closeBtn]; NSInteger top = IPHONEX ? 44 : 20; closeBtn.frame = CGRectMake(KScreenWidth -44-20, top, 44, 44); } - (void)ucm_subVeiwsTapBlock{ @weakify(self) self.TableV.tapClose = ^(NSInteger num, id data) { //选择规格xxx_optionAry 和 修改商品数量xxx_quantityNum @strongify(self) if([data isKindOfClass:[GoodsSizeCountCellData class]]){ GoodsSizeCountCellData *model = (GoodsSizeCountCellData *)data; self.xxx_quantityNum = model.quantityNum; } [self refresh_optionChangePrice]; }; self.bottomV.ViewtapClose = ^(NSInteger num, id _Nonnull data) { @strongify(self) [self hanale_isShopOrCart:num]; }; } - (void)initSubviews { [super initSubviews]; [self.view addSubview:self.sel_headImg]; [self.view addSubview:self.sel_titleLab]; [self.view addSubview:self.priceLab]; [self.view addSubview:self.saveLab]; [self.view addSubview:self.bottomV]; IPhoneXHeigh self.sel_headImg.frame = CGRectMake(10, securitytop_Y +10, 93, 93); self.sel_titleLab.frame = CGRectMake(CGRectGetMaxX(self.sel_headImg.frame)+10, securitytop_Y +10,KScreenWidth - 93-10-20,40); [self.sel_headImg mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.top.mas_equalTo(securitytop_Y +10); make.width.height.mas_equalTo(93); }]; [self.sel_titleLab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(securitytop_Y +10); make.left.equalTo(self.sel_headImg.mas_right).offset(10); make.right.mas_equalTo(-10); make.height.mas_equalTo(40); }]; [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.sel_headImg.mas_right).offset(10); make.bottom.equalTo(self.sel_headImg); make.height.mas_equalTo(24); }]; [self.saveLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.priceLab.mas_right).offset(10); make.height.mas_equalTo(20); make.centerY.equalTo(self.priceLab); }]; CGFloat tableVorgY = CGRectGetMaxY(self.sel_headImg.frame)+20; [self setupTableV:[GoodsSizeSelectTableV class] Frame:CGRectMake(0, tableVorgY, KScreenWidth, KScreenHeight-tableVorgY-self.bottomV.mj_h)]; } -(void)configFreshData:(GoodsInformationM *)model{ [self.sel_headImg sd_setImageWithURL:[NSURL URLWithString:model.add_gooodsImgUrl] placeholderImage:UIImageDefaultImg_SD]; self.sel_titleLab.text = model.name; self.priceLab.attributedText = [ASGoodsDetailsVM tool_changePriceAtr:model]; if(model.final_prices == model.price){ self.saveLab.hidden = YES; }else{ self.saveLab.hidden = NO; double savePrice = [model.price doubleValue]-[model.final_prices doubleValue]; self.saveLab.text = [NSString stringWithFormat:@"Save %@%.2f",model.currency_symbol,savePrice]; } for (OptionsModel *optM in model.options) { optM.optionSelectTag = 0; } [self.TableV.infodata removeAllObjects]; self.xxx_optionAry = [NSMutableArray arrayWithArray:model.options]; [self.TableV.infodata addObjectsFromArray:self.xxx_optionAry]; GoodsSizeCountCellData *countM = [[GoodsSizeCountCellData alloc]init]; countM.maxNum = 10; countM.quantityNum = self.xxx_quantityNum; [self.TableV.infodata addObject:countM]; GoodsSizePayMentCellData *paytypeM = [[GoodsSizePayMentCellData alloc]init]; paytypeM.paytypeAry = [NSMutableArray arrayWithArray:@[@"paypal",@"afterpay"]]; paytypeM.final_prices_f = [self.model.final_prices floatValue]; paytypeM.currency_symbol = self.model.currency_symbol; [self.TableV.infodata addObject:paytypeM]; [self.TableV reloadData]; } #pragma mark - **************** fresh 选择不同规格后的金额变化 **************** -(void)refresh_optionChangePrice{ CGFloat add_price = 0.00; for (OptionsModel *optionM in self.xxx_optionAry) { OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag]; add_price = add_price + valuesM.price; } self.priceLab.attributedText = [ASGoodsDetailsVM tool_addOptionPrice:add_price quantity:self.xxx_quantityNum infoMoel:self.model]; CGFloat savePrice = ([self.model.price doubleValue]-[self.model.final_prices doubleValue])*self.xxx_quantityNum; self.saveLab.text = [NSString stringWithFormat:@"Save %@%.2f",self.model.currency_symbol,savePrice]; CGFloat add_final_price_f = (add_price+[self.model.final_prices floatValue])*self.xxx_quantityNum; [self refresh_PayViewchangeValueCell:add_final_price_f]; } -(void)refresh_PayViewchangeValueCell:(CGFloat )change_final_prices_f{ GoodsSizePayMentCellData *payModel = (GoodsSizePayMentCellData *)[self.TableV.infodata lastObject]; payModel.final_prices_f = change_final_prices_f; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.TableV.infodata.count-1 inSection:0]; [self.TableV reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; } #pragma mark - **************** handle **************** -(void)handle_closeVC{ [self dismissViewControllerAnimated:YES completion:nil]; } -(void)hanale_isShopOrCart:(NSInteger)type{ //1 shop 2cart if(type == 1){ self.xxx_isCart = NO; }else{ self.xxx_isCart = YES; } [self reqNet_Size_rewriteCartAddProducts:type]; } - (void)ucm_bindvmmodel{ self.VM = [[ASGoodsDetailsVM alloc]initDelegate:self]; } -(void)reqNet_Size_rewriteCartAddProducts:(NSInteger)type{ NSMutableDictionary *optionDic = [NSMutableDictionary dictionary]; for (OptionsModel *optionM in self.xxx_optionAry) { OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag]; NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id]; optionDic[tempStr] =valuesM.option_type_id; } NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:optionDic]; params[@"product"] = self.model.Id; params[@"qty"] =[NSString stringWithFormat:@"%ld",(long)self.xxx_quantityNum]; [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params]; } - (void)ry_respnsData:(id)data parseAry:(NSMutableArray *)arry sucess:(BOOL)sucessOrFail mark:(NSString *)mark reqNetType:(ReqNetType)reqNetType{ [MBProgressHUD hideHUDForView:self.view animated:YES]; if(sucessOrFail){ [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) { if(self.xxx_isCart){ [self dismissViewControllerAnimated:YES completion:^{ }]; }else{ [self handle_closeVC]; } }]; }else{ [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter]; } } - (UIImageView *)sel_headImg { if (!_sel_headImg) { _sel_headImg = [[UIImageView alloc] initWithImage:nil]; _sel_headImg.contentMode = UIViewContentModeScaleAspectFill; _sel_headImg.clipsToBounds = YES; } return _sel_headImg; } - (QMUILabel *)sel_titleLab { if (!_sel_titleLab) { _sel_titleLab = [[QMUILabel alloc] initWithFrame:CGRectZero]; _sel_titleLab.textAlignment = NSTextAlignmentLeft; _sel_titleLab.textColor = [UIColor colorWithHexString:@"#000000"]; _sel_titleLab.font = [UIFont fontWithName:Rob_Regular size:12]; _sel_titleLab.text = @"test"; _sel_titleLab.numberOfLines = 2; } return _sel_titleLab; } - (QMUILabel *)priceLab { if (!_priceLab) { _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero]; _priceLab.textAlignment = NSTextAlignmentLeft; _priceLab.textColor = [UIColor blackColor]; _priceLab.font = [UIFont fontWithName:Rob_Bold size:18]; } return _priceLab; } - (QMUILabel *)saveLab { if (!_saveLab) { _saveLab = [[QMUILabel alloc] initWithFrame:CGRectZero]; _saveLab.contentEdgeInsets= UIEdgeInsetsMake(10, 10, 10, 10); _saveLab.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"]; _saveLab.textAlignment = NSTextAlignmentCenter; _saveLab.textColor = [UIColor colorWithHexString:@"#113632"]; _saveLab.font = [UIFont fontWithName:Rob_Bold size:12]; } return _saveLab; } - (GoodsDetailsBottomV *)bottomV { if (!_bottomV) { IPhoneXHeigh _bottomV = [[GoodsDetailsBottomV alloc] initWithFrame:CGRectMake(0, KScreenHeight - securityBottom_H-65, KScreenWidth, securityBottom_H+65)]; _bottomV.backgroundColor = Col_FFF; } return _bottomV; } @end