| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 | 
							- //
 
- //  Cart_MyCartC.m
 
- //  Asteria
 
- //
 
- //  Created by 王猛 on 2024/1/26.
 
- //
 
- #import "Cart_MyCartC.h"
 
- #import "CartVM.h"
 
- #import "MyCarlTableV.h"
 
- #import "Cart_CheckoutC.h"
 
- #import "ASGoodsDetailsVM.h"
 
- #import "ASAddGiftGoodsView.h"
 
- #import "ASMyCartNoDataView.h"
 
- #import "ASGoodsDetailsViewController.h"
 
- @interface Cart_MyCartC ()<RY_baseVMprotocol>
 
- @property (nonatomic, strong) CartVM *VM;
 
- @property (nonatomic, strong) UIView *topBgV;
 
- @property (nonatomic, strong) UILabel *top_totalLab;
 
- @property (nonatomic, strong) QMUILabel *top_priceLab;
 
- @property (nonatomic, strong) MyCarlTableV *TableV;
 
- @property (nonatomic, strong) CartTotalsM *totalsM;
 
- @property (nonatomic, strong) MyCartCouponCellData *couponCellM;
 
- @property (nonatomic, strong) MyCartGrandTotalCellData *totalCellM;
 
- @property (nonatomic, strong) UIButton *postBtn;
 
- //手动添加赠品至购物车
 
- @property (nonatomic, strong) ASGoodsDetailsVM *goodsDetailsVM;
 
- @property (nonatomic, strong) ASAddGiftGoodsView *addGiftView;
 
- @property (nonatomic, strong) NSMutableArray *addGiftParamArr;
 
- @property (nonatomic, assign) int index;
 
- @property (nonatomic, assign) int giftShowCount;
 
- //空页面
 
- @property (nonatomic, strong) ASMyCartNoDataView *noDataView;
 
- @property (nonatomic, strong) UITabBarItem *cartTabbarItem;
 
- @end
 
- @implementation Cart_MyCartC
 
- - (void)viewDidLoad {
 
-     [super viewDidLoad];
 
-     self.title = @"My Cart";
 
-     
 
-     self.cartTabbarItem  = self.tabBarController.tabBar.items[2];
 
-     
 
-     [self ucm_subVeiwsTapBlock];
 
- }
 
- -(void)viewWillAppear:(BOOL)animated{
 
-     [super viewWillAppear:animated];
 
-     
 
-     self.addGiftView.hidden = YES;
 
-     
 
-     [self reqNet_Cart_cartsMineTotals];
 
-     
 
- }
 
- - (void)initSubviews {
 
-     [super initSubviews];
 
-     
 
-     self.view.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
 
-     
 
-     [self.view addSubview:self.topBgV];
 
-     [self.topBgV addSubview:self.top_totalLab];
 
-     [self.topBgV addSubview:self.top_priceLab];
 
-     [self.top_totalLab mas_makeConstraints:^(MASConstraintMaker *make) {
 
-         make.left.mas_offset(20);
 
-         make.centerY.equalTo(self.topBgV);
 
-     }];
 
-     [self.top_priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
 
-         make.left.equalTo(self.top_totalLab.mas_right).offset(20);
 
-         make.right.mas_equalTo(-20);
 
-         make.centerY.equalTo(self.topBgV);
 
-     }];
 
-     
 
-     
 
-     
 
-     IPhoneXHeigh
 
-     [self setupTableV:[MyCarlTableV class] Frame:CGRectMake(0, CGRectGetMaxY(self.topBgV.frame), KScreenWidth, KScreenHeight-securityBottom_H - 65- CGRectGetMaxY(self.topBgV.frame)-self.postBtn.mj_h)];
 
-     self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
 
-     
 
-     [self.view addSubview:self.postBtn];
 
-     self.postBtn.mj_y = CGRectGetMaxY(self.TableV.frame);
 
-     
 
-     self.addGiftParamArr = [[NSMutableArray alloc] initWithCapacity:1];
 
-     self.index = 0;
 
-     self.giftShowCount = 0;
 
-     
 
-     self.topBgV.hidden = YES;
 
-     self.postBtn.hidden = YES;
 
-     self.TableV.hidden = YES;
 
- }
 
- - (void)ucm_subVeiwsTapBlock{
 
-     @weakify(self)
 
-     self.TableV.tapClose = ^(NSInteger num, id data) {
 
-         //num = 0 删除商品 ,1 修改数量 countV
 
-         @strongify(self)
 
-         if([data isKindOfClass:[CartTotalsItemsM class]]){
 
-             switch (num) {
 
-                 case 0:
 
-                     [self reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)data];
 
-                     break;
 
-                 case 1:
 
-                     [self reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)data];
 
-                     break;
 
-                 default:
 
-                     break;
 
-             }
 
-         } else if ([data isKindOfClass:[MyCartCouponCellData class]]){
 
-             MyCartCouponCellData *couponM = (MyCartCouponCellData *)data;
 
-             if(num ==0){ //使用优惠券
 
-                 [self reqNet_PUT_cartsMineCoupons:couponM.coupon_code];
 
-             }else if(num == 1){//删除优惠券
 
-                 [self reqNet_DEL_cartsMineCoupons];
 
-             }
 
-         } else if ([data isKindOfClass:[MyCartGrandTotalCellData class]]){
 
- //            MyCartGrandTotalCellData *totalData = (MyCartGrandTotalCellData *)data;
 
-             
 
-             [self requestLostExtraFee:num];
 
-         }
 
-         
 
-         
 
-         
 
-     };
 
- }
 
- - (void)ucm_bindvmmodel{
 
-     self.VM = [[CartVM alloc] initDelegate:self];
 
-     self.goodsDetailsVM = [[ASGoodsDetailsVM alloc] initDelegate:self];
 
- }
 
- #pragma mark - **************** reqNet ****************
 
- ///获取购物车
 
- -(void)reqNet_Cart_cartsMineTotals{
 
-     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 
-     [self.VM ry_requestGetApi:Cart_cartsMineTotals param:@{}];
 
- }
 
- ///修改商品的数量
 
- -(void)reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)itemM{
 
-     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 
-     NSDictionary *cartItemDic = @{
 
-         @"item_id":itemM.item_id,
 
-         @"qty":itemM.qty,
 
-         @"quote_id":self.totalsM.cart_id
 
-     };
 
-     NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{
 
-         @"cartItem":cartItemDic
 
-     }];
 
-     [self.VM ry_requestPostApi:Cart_cartsMineItems_Post param:param];
 
- }
 
- ///删除商品
 
- -(void)reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)itemM{
 
-     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 
-     [self.VM ry_requestDeleteApi:DEL_cartsMineItems paramStr:itemM.item_id];
 
- }
 
- -(void)reqNet_PUT_cartsMineCoupons:(NSString *)coupon{
 
-     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 
-     self.giftShowCount = 0;
 
-     [self.VM ry_requestPutApi:PUT_cartsMineCoupons param:coupon];
 
- }
 
- -(void)reqNet_DEL_cartsMineCoupons{
 
-     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 
-     [self.VM ry_requestDeleteApi:DEL_cartsMineCoupons paramStr:@""];
 
- }
 
- //丢件险
 
- - (void)requestLostExtraFee:(BOOL)isOpen {
 
-     
 
-     NSDictionary *address = @{@"countryId":@"US",
 
-                               @"postcode":@"*"};
 
-     NSDictionary *addressInformation = @{@"address":address,
 
-                                          @"shipping_method_code":@"bestway",
 
-                                          @"shipping_carrier_code":@"tablerate"};
 
-     
 
-     NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithCapacity:1];
 
-     if(isOpen ==0){ //取消丢件险
 
-         NSDictionary *information = @{@"fee_id":@(1), @"options_ids":@[]};
 
-         [params addEntriesFromDictionary:@{@"information":information}];
 
-     }else if(isOpen == 1){//打开丢件险
 
-         NSDictionary *information = @{@"fee_id":@(1), @"options_ids":@[@"1"]};
 
-         [params addEntriesFromDictionary:@{@"information":information}];
 
-     }
 
-     [params setValue:addressInformation forKey:@"addressInformation"];
 
-     
 
-     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 
-     [self.VM ry_requestPostApi:Chectout_lost_extrafee param:params];
 
- }
 
- //请求赠品商品详情
 
- -(void)reqNet_GoodsDetails_productGetProduct:(NSString *)enterId{
 
-     NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
 
-     [params setObject:enterId forKey:@"productId"];
 
- //    [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
 
- //    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 
-     [self.goodsDetailsVM ry_requestGetApi:Goods_productGetProductsById param:params];
 
- }
 
- //赠品加车
 
- - (void)requestGiftAddCart {
 
-     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 
-     
 
-     for (int i = 0; i < self.addGiftParamArr.count; i++) {
 
-         NSDictionary *param = self.addGiftParamArr[i];
 
-         self.index ++;
 
-         [self.VM ry_formDataRequestPostApi:Chectout_giftAddCart param:param];
 
-     }
 
- }
 
- - (void)ry_respnsData:(id)data 
 
-              parseAry:(NSMutableArray *)arry
 
-                sucess:(BOOL)sucessOrFail 
 
-                  mark:(NSString *)mark
 
-            reqNetType:(ReqNetType)reqNetType{
 
-     [MBProgressHUD hideHUDForView:self.view animated:YES];
 
-     if([mark isEqualToString:Cart_cartsMineTotals]){
 
-         if(sucessOrFail){
 
-             
 
-             CartTotalsM *model = [arry firstObject];
 
-             self.totalsM = model;
 
-             
 
-             self.cartTabbarItem.qmui_badgeInteger = [model.items_qty integerValue];
 
-             
 
-             if (AS_Array_valid(self.totalsM.items)) {
 
-                 //空页面
 
-                 self.noDataView.hidden = YES;
 
-                 self.TableV.hidden = NO;
 
-                 self.topBgV.hidden = NO;
 
-                 self.postBtn.hidden = NO;
 
-                 
 
-                 self.top_totalLab.text = [NSString stringWithFormat:@"%@ pcs | total",model.items_qty];
 
-                 self.top_priceLab.text =[NSString stringWithFormat:@"%@%.2f",model.currency_symbol, [model.subtotal floatValue]];
 
-                 [self.TableV.infodata removeAllObjects];
 
-                 self.TableV.infodata = [NSMutableArray arrayWithArray:model.items];
 
-                 
 
-                 self.couponCellM.couponAry =[NSMutableArray arrayWithArray: [ASNetTools shared].xxx_couponAry];
 
-                 self.couponCellM.coupon_code = model.coupon_code;
 
-                 self.couponCellM.discount_amount = model.discount_amount;
 
-                 self.couponCellM.currency_symbol = model.currency_symbol;
 
-                 [self.TableV.infodata addObject:self.couponCellM];
 
-                 
 
-                 self.totalCellM.total_segments = [NSMutableArray arrayWithArray:model.total_segments];
 
-                 self.totalCellM.currency_symbol = model.currency_symbol;
 
-                 [self.TableV.infodata addObject:self.totalCellM];
 
-                 
 
-                 MyCartPayTypeCellData *data = [[MyCartPayTypeCellData alloc]init];
 
-                 data.final_prices_f = [model.grand_total floatValue];
 
-                 data.currency_symbol = model.currency_symbol;
 
-                 [self.TableV.infodata addObject:data];
 
-                 
 
-                 //手动添加赠品功能
 
-                 [self.addGiftParamArr removeAllObjects];
 
-                 
 
-                 NSDictionary *freeData = (NSDictionary *)[[self.totalsM.extension_attributes objectForKey:@"free_data"] mj_JSONObject];
 
-                 BOOL is_show = [[freeData objectForKey:@"is_show"] boolValue];
 
-                 if (is_show && self.giftShowCount< 1) {//显示存在赠品
 
-                     NSArray *productArr = [freeData objectForKey:@"products"];
 
-                     if (productArr.count > 0) { //存在赠品
 
-                         for (int i = 0; i < productArr.count; i++) {
 
-                             NSDictionary *productDic = productArr[i];
 
-                             NSString *entity_id = productDic[@"entity_id"];
 
-                             [self reqNet_GoodsDetails_productGetProduct:entity_id];
 
-                         }
 
-                     }
 
-                 }
 
-                 
 
-                 [self.TableV reloadData];
 
-                 
 
-                 
 
-             } else {
 
-                 
 
-                 self.cartTabbarItem.qmui_badgeInteger = 0;
 
-                 //空页面
 
-                 self.noDataView.hidden = NO;
 
-                 self.TableV.hidden = YES;
 
-                 self.topBgV.hidden = YES;
 
-                 self.postBtn.hidden = YES;
 
-             }
 
-             
 
-         } else {
 
-             
 
-             self.cartTabbarItem.qmui_badgeInteger = 0;
 
-             //空页面
 
-             self.noDataView.hidden = NO;
 
-             self.TableV.hidden = YES;
 
-             self.topBgV.hidden = YES;
 
-             self.postBtn.hidden = YES;
 
-             
 
-         }
 
-     }else if ([mark isEqualToString:Cart_cartsMineItems_Post]
 
-               || [mark isEqualToString:DEL_cartsMineItems]
 
-               || [mark isEqualToString:PUT_cartsMineCoupons]
 
-               || [mark isEqualToString:Chectout_giftAddCart]
 
-               || [mark isEqualToString:Chectout_lost_extrafee]){
 
-         if(sucessOrFail){
 
-             
 
-             if ([mark isEqualToString:Chectout_giftAddCart]) {
 
-                 self.index --;
 
-                 if (self.index == 0) {
 
-                     [self reqNet_Cart_cartsMineTotals];
 
-                 }
 
-             } else {
 
-                 [self reqNet_Cart_cartsMineTotals];
 
-             }
 
-             
 
-             
 
-         }else{
 
-             [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
 
-         }
 
-     } else if ([mark isEqualToString:Goods_productGetProductsById]) {
 
-         //请求赠品详情
 
-         if(sucessOrFail) {
 
-             GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];            
 
-             NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{@"product_id":model.Id, @"isPromoItems":@"yes"}];
 
-             if (model.options.count > 0) {
 
-                 NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
 
-                 for (OptionsModel *optionM in model.options) {
 
-                     OptionsValuesM *valuesM = optionM.values[0];
 
-                     NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
 
-                     optionDic[tempStr] =valuesM.option_type_id;
 
-                 }
 
-                 [param addEntriesFromDictionary:optionDic];
 
-             }
 
-     //        param = /*@{@"product_id":model.Id, @"isPromoItems":@"1"}*/;
 
-             [self.addGiftParamArr addObject:param];
 
-             if (self.giftShowCount < 1 && self.addGiftParamArr.count == 1 && self.addGiftView.hidden) {
 
-                 self.addGiftView.hidden = NO;
 
-                 [self.addGiftView setGiftData:model.add_gooodsImgUrl];
 
-             }
 
-         }
 
-         
 
-     }
 
- }
 
- - (void)tapcellTriggereventIndex:(NSIndexPath *)index model:(id)model{
 
-     if([model isKindOfClass:[CartTotalsItemsM class]]){
 
-         CartTotalsItemsM *itemM = (CartTotalsItemsM *)model;
 
-         if(itemM.isGift){
 
-             return;
 
-         }
 
- //        UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":itemM.product_id}];
 
- //        [self.navigationController pushViewController:viewController animated:YES];
 
-         
 
-         ASGoodsDetailsViewController *goodsVC = [[ASGoodsDetailsViewController alloc] init];
 
-         goodsVC.entity_id = itemM.product_id;
 
-         [self.navigationController pushViewController:goodsVC animated:YES];
 
-     }
 
- }
 
- -(void)handle_postEvent:(UIButton *)btn{
 
-     Cart_CheckoutC *vc = [[Cart_CheckoutC alloc]init];
 
-     vc.totalsM = self.totalsM;
 
-     [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
 
- }
 
- #pragma mark - **************** lazy ****************
 
- -(UIView *)topBgV{
 
-     if(!_topBgV){
 
-         IPhoneXHeigh
 
-         _topBgV = [[UIView alloc]initWithFrame:CGRectMake(0, securitytop_Y, KScreenWidth, 60)];
 
-         _topBgV.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"];
 
-     }
 
-     return _topBgV;
 
- }
 
- - (UILabel *)top_totalLab {
 
-     if (!_top_totalLab) {
 
-         _top_totalLab = [[UILabel alloc] initWithFrame:CGRectZero];
 
-         _top_totalLab.textAlignment = NSTextAlignmentLeft;
 
-         _top_totalLab.font = [UIFont fontWithName:Rob_Regular size:14];
 
-         _top_totalLab.textColor = [UIColor colorWithHexString:@"#000000"];
 
-     }
 
-     return  _top_totalLab;
 
- }
 
- - (QMUILabel *)top_priceLab {
 
-     if (!_top_priceLab) {
 
-         _top_priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
 
-         _top_priceLab.textAlignment = NSTextAlignmentLeft;
 
-         _top_priceLab.font = [UIFont fontWithName:Rob_Bold size:16];
 
-     }
 
-     return  _top_priceLab;
 
- }
 
- - (MyCartCouponCellData *)couponCellM {
 
-     if (!_couponCellM) {
 
-         _couponCellM = [[MyCartCouponCellData alloc] init];
 
-     }
 
-     return _couponCellM;
 
- }
 
- - (MyCartGrandTotalCellData *)totalCellM {
 
-     if (!_totalCellM) {
 
-         _totalCellM = [[MyCartGrandTotalCellData alloc] init];
 
-     }
 
-     return _totalCellM;
 
- }
 
- - (UIButton *)postBtn {
 
-     if (!_postBtn) {
 
-         _postBtn = [UIButton buttonWithType:UIButtonTypeCustom];
 
-         _postBtn.layer.cornerRadius = 4;
 
-         _postBtn.clipsToBounds = YES;
 
-         IPhoneXHeigh
 
-         _postBtn.frame = CGRectMake(10, 0, KScreenWidth-20, 45);
 
-         _postBtn.backgroundColor = [UIColor colorWithHexString:@"#000000"];
 
-         [_postBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
 
-         _postBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
 
-         [_postBtn setTitle:@"POST COMMENT" forState:UIControlStateNormal];
 
-         [_postBtn addTarget:self action:@selector(handle_postEvent:) forControlEvents:UIControlEventTouchUpInside];
 
-      }
 
-     return _postBtn;
 
- }
 
- - (ASAddGiftGoodsView *)addGiftView {
 
-     if (!_addGiftView) {
 
-         _addGiftView = [[ASAddGiftGoodsView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
 
-         @weakify(self)
 
-         _addGiftView.addBlock = ^(int type) {
 
-             @strongify(self)
 
-             self.addGiftView.hidden = YES;
 
-             if (type == 1) {
 
-                 [self requestGiftAddCart];
 
-             } else {
 
-                 self.giftShowCount ++;
 
-             }
 
-         };
 
-         _addGiftView.hidden = YES;
 
-         [self.view addSubview:_addGiftView];
 
-     }
 
-     return _addGiftView;
 
- }
 
- - (ASMyCartNoDataView *)noDataView {
 
-     if (!_noDataView) {
 
-         IPhoneXHeigh
 
-         _noDataView = [[ASMyCartNoDataView alloc] initWithFrame:CGRectMake(0, securitytop_Y, KScreenWidth, KScreenHeight - securitytop_Y - securityBottom_H)];
 
-         _noDataView.hidden = YES;
 
-         [self.view addSubview:_noDataView];
 
-     }
 
-     return _noDataView;
 
- }
 
- @end
 
 
  |