Cart_CheckoutC.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // Cart_CheckoutC.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2024/2/16.
  6. //
  7. #import "Cart_CheckoutC.h"
  8. #import "CartCheckTableV.h"
  9. #import "CartVM.h"
  10. #import "ASCheckoutTopView.h"
  11. @interface Cart_CheckoutC ()<RY_baseVMprotocol>
  12. @property (nonatomic, strong) CartVM *VM;
  13. @property (nonatomic, strong) ASCheckoutTopView *topView;
  14. @property (nonatomic, strong) CartCheckTableV *TableV;
  15. @property (nonatomic, strong) MyCartCouponCellData *couponCellM;
  16. @property (nonatomic, strong) MyCartGrandTotalCellData *totalCellM;
  17. @property (nonatomic, strong) ASCheckoutPointData *pointCellM;
  18. //存放支付方式
  19. @property (nonatomic, strong) NSArray *paymentArray;
  20. @end
  21. @implementation Cart_CheckoutC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.title = @"Checkout";
  25. //获取支付方式
  26. [self requestPaymentMode];
  27. }
  28. - (void)initSubviews {
  29. [super initSubviews];
  30. //顶部
  31. [self.view addSubview:self.topView];
  32. IPhoneXHeigh
  33. [self setupTableV:[CartCheckTableV class] Frame:CGRectMake(0, CGRectGetMaxY(self.topView.frame) , KScreenWidth, KScreenHeight-securityBottom_H - 65 - CGRectGetMaxY(self.topView.frame))];
  34. self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  35. @weakify(self)
  36. self.TableV.tapClose = ^(NSInteger num, id data) {
  37. //num = 0 删除商品 ,1 修改数量 countV
  38. @strongify(self)
  39. if([data isKindOfClass:[CartTotalsItemsM class]]){
  40. switch (num) {
  41. case 0:
  42. [self reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)data];
  43. break;
  44. case 1:
  45. [self reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)data];
  46. break;
  47. default:
  48. break;
  49. }
  50. }else if ([data isKindOfClass:[MyCartCouponCellData class]]){
  51. MyCartCouponCellData *couponM = (MyCartCouponCellData *)data;
  52. if(num ==0){ //使用优惠券
  53. [self reqNet_PUT_cartsMineCoupons:couponM.coupon_code];
  54. }else if(num == 1){//删除优惠券
  55. [self reqNet_DEL_cartsMineCoupons];
  56. }
  57. }
  58. };
  59. // [self updateData];
  60. }
  61. - (void)ry_respnsData:(id)data
  62. parseAry:(NSMutableArray *)arry
  63. sucess:(BOOL)sucessOrFail
  64. mark:(NSString *)mark
  65. reqNetType:(ReqNetType)reqNetType{
  66. [MBProgressHUD hideHUDForView:self.view animated:YES];
  67. if([mark isEqualToString:Cart_cartsMineTotals]){
  68. if(sucessOrFail){
  69. CartTotalsM *model = [arry firstObject];
  70. self.totalsM = model;
  71. [self updateData];
  72. }
  73. } else if ([mark isEqualToString:Chectout_getPaymentMode]) {
  74. if(sucessOrFail){
  75. // 更新支付方式
  76. self.paymentArray = arry;
  77. //首次进入展示购物车数据UI
  78. [self updateData];
  79. }
  80. } else if ([mark isEqualToString:Cart_cartsMineItems_Post]
  81. || [mark isEqualToString:DEL_cartsMineItems]
  82. || [mark isEqualToString:PUT_cartsMineCoupons]){
  83. if(sucessOrFail){
  84. [self reqNet_Cart_cartsMineTotals];
  85. }else{
  86. [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
  87. }
  88. }
  89. }
  90. - (void)updateData{
  91. [self.topView setTopViewData:self.totalsM.items_qty price:[NSString stringWithFormat:@"%@%@",self.totalsM.currency_symbol,self.totalsM.subtotal]];
  92. [self.TableV.infodata removeAllObjects];
  93. self.TableV.infodata = [NSMutableArray arrayWithArray:self.totalsM.items];
  94. self.totalCellM.total_segments = [NSMutableArray arrayWithArray:self.totalsM.total_segments];
  95. self.totalCellM.currency_symbol = self.totalsM.currency_symbol;
  96. [self.TableV.infodata addObject:self.totalCellM];
  97. self.couponCellM.couponAry =[NSMutableArray arrayWithArray: [ASNetTools shared].xxx_couponAry];
  98. self.couponCellM.coupon_code = self.totalsM.coupon_code;
  99. self.couponCellM.discount_amount = self.totalsM.discount_amount;
  100. self.couponCellM.currency_symbol = self.totalsM.currency_symbol;
  101. [self.TableV.infodata addObject:self.couponCellM];
  102. self.pointCellM.pointCountInput = @"20";
  103. self.pointCellM.pointBalance = @"10";
  104. [self.TableV.infodata addObject:self.pointCellM];
  105. // MyCartPayTypeCellData *data = [[MyCartPayTypeCellData alloc]init];
  106. // data.final_prices_f = [self.totalsM.subtotal floatValue];
  107. // data.currency_symbol = self.totalsM.currency_symbol;
  108. // [self.TableV.infodata addObject:data];
  109. //支付方式数据
  110. [self.TableV.infodata addObjectsFromArray:self.paymentArray];
  111. [self.TableV reloadData];
  112. }
  113. - (void)tapcellTriggereventIndex:(NSIndexPath *)index model:(id)model{
  114. if([model isKindOfClass:[CartTotalsItemsM class]]){
  115. CartTotalsItemsM *itemM = (CartTotalsItemsM *)model;
  116. if(itemM.isGift){
  117. return;
  118. }
  119. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":itemM.product_id}];
  120. [self.navigationController pushViewController:viewController animated:YES];
  121. } else if ([model isKindOfClass:[ASCheckoutPaymentModel class]]) {
  122. ASCheckoutPaymentModel *paymentModel = (ASCheckoutPaymentModel *)model;
  123. if (paymentModel.isSelect) {
  124. return;
  125. }
  126. for (int i = 0; i < self.TableV.infodata.count; i++) {
  127. id itemModel = self.TableV.infodata[i];
  128. if ([itemModel isKindOfClass:[ASCheckoutPaymentModel class]]) {
  129. ASCheckoutPaymentModel *tempModel = (ASCheckoutPaymentModel *)itemModel;
  130. if (index.row == i) {
  131. tempModel.isSelect = YES;
  132. } else {
  133. tempModel.isSelect = NO;
  134. }
  135. }
  136. }
  137. [self.TableV reloadData];
  138. }
  139. }
  140. #pragma mark - **************** reqNet ****************
  141. //获取支付方式
  142. - (void)requestPaymentMode {
  143. [self.VM ry_requestGetApi:Chectout_getPaymentMode param:@{}];
  144. }
  145. ///获取购物车
  146. -(void)reqNet_Cart_cartsMineTotals{
  147. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  148. [self.VM ry_requestGetApi:Cart_cartsMineTotals param:@{}];
  149. }
  150. ///修改商品的数量
  151. -(void)reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)itemM{
  152. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  153. NSDictionary *cartItemDic = @{
  154. @"item_id":itemM.item_id,
  155. @"qty":itemM.qty,
  156. @"quote_id":self.totalsM.cart_id
  157. };
  158. NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{
  159. @"cartItem":cartItemDic
  160. }];
  161. [self.VM ry_requestPostApi:Cart_cartsMineItems_Post param:param];
  162. }
  163. ///删除商品
  164. -(void)reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)itemM{
  165. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  166. [self.VM ry_requestDeleteApi:DEL_cartsMineItems paramStr:itemM.item_id];
  167. }
  168. -(void)reqNet_PUT_cartsMineCoupons:(NSString *)coupon{
  169. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  170. [self.VM ry_requestPutApi:PUT_cartsMineCoupons param:coupon];
  171. }
  172. -(void)reqNet_DEL_cartsMineCoupons{
  173. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  174. [self.VM ry_requestDeleteApi:DEL_cartsMineCoupons paramStr:@""];
  175. }
  176. #pragma mark --- 懒加载 ---
  177. - (void)ucm_bindvmmodel{
  178. self.VM = [[CartVM alloc] initDelegate:self];
  179. }
  180. - (MyCartCouponCellData *)couponCellM {
  181. if (!_couponCellM) {
  182. _couponCellM = [[MyCartCouponCellData alloc] init];
  183. }
  184. return _couponCellM;
  185. }
  186. - (MyCartGrandTotalCellData *)totalCellM {
  187. if (!_totalCellM) {
  188. _totalCellM = [[MyCartGrandTotalCellData alloc] init];
  189. }
  190. return _totalCellM;
  191. }
  192. - (ASCheckoutPointData *)pointCellM {
  193. if (!_pointCellM) {
  194. _pointCellM = [[ASCheckoutPointData alloc] init];
  195. }
  196. return _pointCellM;
  197. }
  198. - (ASCheckoutTopView *)topView {
  199. if (!_topView) {
  200. IPhoneXHeigh
  201. _topView = [[ASCheckoutTopView alloc] initWithFrame:CGRectMake(0, securitytop_Y, KScreenWidth, 60)];
  202. @weakify(self)
  203. _topView.isFlodBlock = ^(BOOL isFlod) {
  204. @strongify(self)
  205. self.TableV.isFlod = isFlod;
  206. [self.TableV reloadData];
  207. };
  208. //
  209. }
  210. return _topView;
  211. }
  212. #pragma mark - **************** reqNet ****************
  213. @end