|
@@ -8,8 +8,27 @@
|
|
|
#import "Cart_CheckoutC.h"
|
|
|
#import "CartCheckTableV.h"
|
|
|
|
|
|
-@interface Cart_CheckoutC ()
|
|
|
+#import "CartVM.h"
|
|
|
+
|
|
|
+#import "ASCheckoutTopView.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) NSArray *paymentArray;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation Cart_CheckoutC
|
|
@@ -17,14 +36,228 @@
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
self.title = @"Checkout";
|
|
|
+
|
|
|
+ //获取支付方式
|
|
|
+ [self requestPaymentMode];
|
|
|
}
|
|
|
|
|
|
- (void)initSubviews {
|
|
|
[super initSubviews];
|
|
|
+
|
|
|
+ //顶部
|
|
|
+ [self.view addSubview:self.topView];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
IPhoneXHeigh
|
|
|
- [self setupTableV:[CartCheckTableV class] Frame:CGRectMake(0, securitytop_Y , KScreenWidth, security_H)];
|
|
|
+ [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_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];
|
|
|
+
|
|
|
+// 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];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - **************** reqNet ****************
|
|
|
+//获取支付方式
|
|
|
+- (void)requestPaymentMode {
|
|
|
+ [self.VM ry_requestGetApi:Chectout_getPaymentMode 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;
|
|
|
+}
|
|
|
+
|
|
|
+- (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 ****************
|
|
|
|