123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- //
- // Cart_CheckoutC.m
- // Asteria
- //
- // Created by 王猛 on 2024/2/16.
- //
- #import "Cart_CheckoutC.h"
- #import "ASAddressListViewController.h"
- #import "ASCheckoutTopView.h"
- #import "CartCheckTableV.h"
- #import "CartVM.h"
- #import "ASUserModel.h"
- @interface Cart_CheckoutC ()<RY_baseVMprotocol>
- @property (nonatomic, strong) CartVM *VM;
- @property (nonatomic, strong) ASCheckoutTopView *topView;
- @property (nonatomic, strong) CartCheckTableV *TableV;
- @property (nonatomic, strong) MyCartCouponCellData *couponCellM;
- @property (nonatomic, strong) MyCartGrandTotalCellData *totalCellM;
- @property (nonatomic, strong) ASCheckoutPointData *pointCellM;
- @property (nonatomic, strong) ASCheckoutAddressData *addressCellM;
- //存放支付方式
- @property (nonatomic, strong) NSArray *paymentArray;
- @end
- @implementation Cart_CheckoutC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"Checkout";
-
- //获取支付方式
- [self requestPaymentMode];
- //获取运输方式
- [self requestGetShipMethodByAddress];
- //获取购物车信息(地址信息)
- [self requestCartInfo];
- }
- - (void)initSubviews {
- [super initSubviews];
-
- //顶部
- [self.view addSubview:self.topView];
-
-
-
- IPhoneXHeigh
- [self setupTableV:[CartCheckTableV class] Frame:CGRectMake(0, CGRectGetMaxY(self.topView.frame) , KScreenWidth, KScreenHeight-securityBottom_H - 65 - CGRectGetMaxY(self.topView.frame))];
- self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
-
- @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];
- }
- }
- };
-
- // [self updateData];
- }
- - (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 updateData];
- }
- } else if ([mark isEqualToString:Chectout_getPaymentMode]) {
- if(sucessOrFail){
- // 更新支付方式
- self.paymentArray = arry;
- //首次进入展示购物车数据UI
- [self updateData];
- }
- } else if ([mark isEqualToString:Cart_cartInfo]) {
- if(sucessOrFail){
- // 获取上次下单地址
- NSDictionary *dic = (NSDictionary *)data;
- NSArray *array = [[dic objectForKey:@"extension_attributes"] objectForKey:@"shipping_assignments"];
-
- if (array.count > 0) {
- NSDictionary *shipping_assignments = array[0];
- NSDictionary *shippingDic = [shipping_assignments objectForKey:@"shipping"];
- NSDictionary *addressDic = [shippingDic objectForKey:@"address"];
- // ASAddressModel *addressModel = [ASAddressModel defualtData];
- ASAddressModel *addressModel = [ASAddressModel mj_objectWithKeyValues:addressDic];
- if (NIL(addressModel.postcode)) {
- self.addressCellM.addressInfoStr = @"";
- self.addressCellM.shipmethodStr = @"";
- } else {
- self.addressCellM.addressInfoStr = [NSString stringWithFormat:@"%@ %@ %@ %@,%@ tel:%@", addressModel.firstname, addressModel.lastname, [addressModel.street componentsJoinedByString:@" "], addressModel.city, addressModel.postcode, addressModel.telephone];
- self.addressCellM.shipmethodStr = [shippingDic objectForKey:@"method"];
- self.addressCellM.addressId = [addressDic objectForKey:@"customer_address_id"];
- }
- }
- //首次进入展示购物车数据UI
- [self updateData];
- }
-
- } else if ([mark isEqualToString:Chectout_addShipAddress_id]) {
-
- if(sucessOrFail){
- NSArray *shipMethodArr = (NSArray *)data;
- if (shipMethodArr.count > 0) {
- NSDictionary *shipMethodDic = shipMethodArr[0];
- self.addressCellM.shipmethodStr = [NSString stringWithFormat:@"%@ %@", shipMethodDic[@"method_title"], shipMethodDic[@"carrier_title"]];
- self.addressCellM.shipmethodPrice = shipMethodDic[@"amount"];
- self.addressCellM.shipmethodSymbol = self.totalsM.currency_symbol;
- }
-
- }
- [self updateData];
-
- } else if ([mark isEqualToString:Chectout_getShipMethod]) {
-
- if(sucessOrFail){
- NSArray *shipMethodArr = (NSArray *)data;
- if (shipMethodArr.count > 0) {
- NSDictionary *shipMethodDic = shipMethodArr[0];
- self.addressCellM.shipmethodStr = [NSString stringWithFormat:@"%@ %@", shipMethodDic[@"method_title"], shipMethodDic[@"carrier_title"]];
- self.addressCellM.shipmethodPrice = shipMethodDic[@"amount"];
- self.addressCellM.shipmethodSymbol = self.totalsM.currency_symbol;
- }
- }
- [self updateData];
-
- } else if ([mark isEqualToString:Cart_cartsMineItems_Post]
- || [mark isEqualToString:DEL_cartsMineItems]
- || [mark isEqualToString:PUT_cartsMineCoupons]){
- if(sucessOrFail){
- [self reqNet_Cart_cartsMineTotals];
- }else{
- [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
- }
- }
- }
- - (void)updateData{
-
- [self.topView setTopViewData:self.totalsM.items_qty price:[NSString stringWithFormat:@"%@%@",self.totalsM.currency_symbol,self.totalsM.subtotal]];
-
- [self.TableV.infodata removeAllObjects];
- self.TableV.infodata = [NSMutableArray arrayWithArray:self.totalsM.items];
-
- self.totalCellM.total_segments = [NSMutableArray arrayWithArray:self.totalsM.total_segments];
- self.totalCellM.currency_symbol = self.totalsM.currency_symbol;
- [self.TableV.infodata addObject:self.totalCellM];
-
- self.couponCellM.couponAry =[NSMutableArray arrayWithArray: [ASNetTools shared].xxx_couponAry];
- self.couponCellM.coupon_code = self.totalsM.coupon_code;
- self.couponCellM.discount_amount = self.totalsM.discount_amount;
- self.couponCellM.currency_symbol = self.totalsM.currency_symbol;
- [self.TableV.infodata addObject:self.couponCellM];
-
- self.pointCellM.pointCountInput = @"20";
- self.pointCellM.pointBalance = @"10";
- [self.TableV.infodata addObject:self.pointCellM];
-
- //邮寄地址--邮寄方式
- [self.TableV.infodata addObject:self.addressCellM];
-
-
-
- // MyCartPayTypeCellData *data = [[MyCartPayTypeCellData alloc]init];
- // data.final_prices_f = [self.totalsM.subtotal floatValue];
- // data.currency_symbol = self.totalsM.currency_symbol;
- // [self.TableV.infodata addObject:data];
-
- //支付方式数据
- [self.TableV.infodata addObjectsFromArray:self.paymentArray];
-
-
- [self.TableV reloadData];
- }
- - (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];
- } else if ([model isKindOfClass:[ASCheckoutPaymentModel class]]) {
- ASCheckoutPaymentModel *paymentModel = (ASCheckoutPaymentModel *)model;
- if (paymentModel.isSelect) {
- return;
- }
-
- for (int i = 0; i < self.TableV.infodata.count; i++) {
- id itemModel = self.TableV.infodata[i];
-
- if ([itemModel isKindOfClass:[ASCheckoutPaymentModel class]]) {
- ASCheckoutPaymentModel *tempModel = (ASCheckoutPaymentModel *)itemModel;
- if (index.row == i) {
- tempModel.isSelect = YES;
- } else {
- tempModel.isSelect = NO;
- }
- }
- }
-
- [self.TableV reloadData];
- } else if ([model isKindOfClass:[ASCheckoutAddressData class]]) {
- ASAddressListViewController *vc = [ASAddressListViewController new];
- vc.isSelMode = true;
- vc.sel_Id = self.addressCellM.addressId;
- @weakify(self)
- vc.selectAddressBlock = ^(ASAddressModel * _Nonnull addressM) {
- @strongify(self)
- self.addressCellM.addressInfoStr = [NSString stringWithFormat:@"%@ %@ %@ %@,%@ tel:%@", addressM.firstname, addressM.lastname, [addressM.street componentsJoinedByString:@" "], addressM.city, addressM.postcode, addressM.telephone];
- self.addressCellM.addressId = addressM.Id;
-
- [self requestAddShipAddress];
- };
- [self.navigationController pushViewController:vc animated:true];
- }
- }
- #pragma mark - **************** reqNet ****************
- //获取支付方式
- - (void)requestPaymentMode {
- [self.VM ry_requestGetApi:Chectout_getPaymentMode param:@{}];
- }
- //添加邮寄地址
- - (void)requestAddShipAddress {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestPostApi:Chectout_addShipAddress_id param:@{@"addressId":self.addressCellM.addressId}];
- }
- //根据邮寄地址获取邮寄方式
- - (void)requestGetShipMethodByAddress {
- [self.VM ry_requestGetApi:Chectout_getShipMethod param:@{}];
- }
- //获取购物车信息(地址信息)
- - (void)requestCartInfo {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestGetApi:Cart_cartInfo param:@{}];
- }
- ///获取购物车信息(报价整合)
- -(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.VM ry_requestPutApi:PUT_cartsMineCoupons param:coupon];
- }
- -(void)reqNet_DEL_cartsMineCoupons{
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestDeleteApi:DEL_cartsMineCoupons paramStr:@""];
- }
- #pragma mark --- 懒加载 ---
- - (void)ucm_bindvmmodel{
- self.VM = [[CartVM alloc] initDelegate:self];
- }
- - (MyCartCouponCellData *)couponCellM {
- if (!_couponCellM) {
- _couponCellM = [[MyCartCouponCellData alloc] init];
- }
- return _couponCellM;
- }
- - (MyCartGrandTotalCellData *)totalCellM {
- if (!_totalCellM) {
- _totalCellM = [[MyCartGrandTotalCellData alloc] init];
- }
- return _totalCellM;
- }
- - (ASCheckoutPointData *)pointCellM {
- if (!_pointCellM) {
- _pointCellM = [[ASCheckoutPointData alloc] init];
- }
- return _pointCellM;
- }
- - (ASCheckoutAddressData *)addressCellM {
- if (!_addressCellM) {
- _addressCellM = [[ASCheckoutAddressData alloc] init];
- _addressCellM.addressInfoStr = @"";
- }
- return _addressCellM;
- }
- - (ASCheckoutTopView *)topView {
- if (!_topView) {
- IPhoneXHeigh
- _topView = [[ASCheckoutTopView alloc] initWithFrame:CGRectMake(0, securitytop_Y, KScreenWidth, 60)];
- @weakify(self)
- _topView.isFlodBlock = ^(BOOL isFlod) {
- @strongify(self)
- self.TableV.isFlod = isFlod;
- [self.TableV reloadData];
- };
- //
- }
- return _topView;
- }
- #pragma mark - **************** reqNet ****************
- @end
|