123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- //
- // AS_GoodsSizeC.m
- // Asteria
- //
- // Created by 王猛 on 2024/1/23.
- //
- #import "AS_GoodsSizeC.h"
- #import "GoodsSizeSelectTableV.h"
- #import "GoodsDetailsBottomV.h"
- #import "ASGoodsDetailsVM.h"
- #import "Cart_CheckoutC.h"
- @interface AS_GoodsSizeC ()<RY_baseVMprotocol>
- @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 <OptionsModel *>*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.saveLab];
- [self.view addSubview:self.priceLab];
- [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.right.equalTo(self.saveLab.mas_left).offset(-4);
- make.width.mas_lessThanOrEqualTo((KScreenWidth - 128)/3 * 2);
- 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(5);
- make.height.mas_equalTo(20);
- make.centerY.equalTo(self.priceLab);
- make.width.mas_lessThanOrEqualTo((KScreenWidth - 128)/3);
- }];
-
-
-
- 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{
-
- NSArray *media_gallery_entries = model.media_gallery_entries;
- NSString *imageUrl = @"";
- if (AS_Array_valid(media_gallery_entries)) {
- MediaGalleryEntriesModel *model = media_gallery_entries.firstObject;
- imageUrl = [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,model.file];
- }
-
- [self.sel_headImg sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:UIImageDefaultImg_SD];
- self.sel_titleLab.text = model.name;
- self.priceLab.attributedText = [ASGoodsDetailsVM tool_changePriceAtr:model];
- if([model.final_prices isEqualToString: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;
- }
-
- float discount = [self.model.percent floatValue];
- if (discount == 0) {
- //优惠价
- CGFloat add_final_price_f = (add_price + [self.model.final_prices floatValue]) * self.xxx_quantityNum;
- self.model.show_final_prices = [NSString stringWithFormat:@"%.2lf", add_final_price_f];
- //原价
- CGFloat show_prices = (add_price + [self.model.price floatValue]) * self.xxx_quantityNum;
- self.model.show_prices = [NSString stringWithFormat:@"%.2lf", show_prices];
- } else {
- //优惠价
- discount = (100.00 - discount) / 100.00;
- CGFloat add_final_price_f = (add_price * discount + [self.model.final_prices floatValue]) * self.xxx_quantityNum;
- self.model.show_final_prices = [NSString stringWithFormat:@"%.2lf", add_final_price_f];
- //原价
- CGFloat show_prices = (add_price + [self.model.price floatValue]) * self.xxx_quantityNum;
- self.model.show_prices = [NSString stringWithFormat:@"%.2lf", show_prices];
- }
-
- self.priceLab.attributedText = [ASGoodsDetailsVM tool_addOptionPrice:add_price quantity:self.xxx_quantityNum infoMoel:self.model];
-
- CGFloat savePrice = ([self.model.show_prices doubleValue]-[self.model.show_final_prices doubleValue]);
- self.saveLab.text = [NSString stringWithFormat:@" Save %@%.2f ",self.model.currency_symbol,savePrice];
-
- CGFloat add_final_price_f = [self.model.show_final_prices doubleValue];
- [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];
- // K_WEAK_SELF;
- [self dismissViewControllerAnimated:YES completion:^{
- // K_STRONG_SELF;
- Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
- [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
- }];
- }
- }];
- }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:20];
- _priceLab.adjustsFontSizeToFitWidth = YES;
- }
- 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];
- _saveLab.adjustsFontSizeToFitWidth = YES;
- }
- 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
|