Cart_MyCartC.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. //
  2. // Cart_MyCartC.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2024/1/26.
  6. //
  7. #import "Cart_MyCartC.h"
  8. #import "CartVM.h"
  9. #import "MyCarlTableV.h"
  10. #import "Cart_CheckoutC.h"
  11. @interface Cart_MyCartC ()<RY_baseVMprotocol>
  12. @property (nonatomic, strong) CartVM *VM;
  13. @property (nonatomic, strong) UIView *topBgV;
  14. @property (nonatomic, strong) UILabel *top_totalLab;
  15. @property (nonatomic, strong) QMUILabel *top_priceLab;
  16. @property (nonatomic, strong) MyCarlTableV *TableV;
  17. @property (nonatomic, strong) CartTotalsM *totalsM;
  18. @property (nonatomic, strong) MyCartCouponCellData *couponCellM;
  19. @property (nonatomic, strong) MyCartGrandTotalCellData *totalCellM;
  20. @property (nonatomic, strong) UIButton *postBtn;
  21. @end
  22. @implementation Cart_MyCartC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.title = @"My Cart";
  26. [self ucm_subVeiwsTapBlock];
  27. }
  28. -(void)viewWillAppear:(BOOL)animated{
  29. [super viewWillAppear:animated];
  30. [self reqNet_Cart_cartsMineTotals];
  31. }
  32. - (void)initSubviews {
  33. [super initSubviews];
  34. [self.view addSubview:self.topBgV];
  35. [self.topBgV addSubview:self.top_totalLab];
  36. [self.topBgV addSubview:self.top_priceLab];
  37. [self.top_totalLab mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.left.mas_offset(20);
  39. make.centerY.equalTo(self.topBgV);
  40. }];
  41. [self.top_priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.equalTo(self.top_totalLab.mas_right).offset(20);
  43. make.right.mas_equalTo(-20);
  44. make.centerY.equalTo(self.topBgV);
  45. }];
  46. IPhoneXHeigh
  47. [self setupTableV:[MyCarlTableV class] Frame:CGRectMake(0, CGRectGetMaxY(self.topBgV.frame), KScreenWidth, KScreenHeight-securityBottom_H - 65- CGRectGetMaxY(self.topBgV.frame)-self.postBtn.mj_h)];
  48. self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  49. [self.view addSubview:self.postBtn];
  50. self.postBtn.mj_y = CGRectGetMaxY(self.TableV.frame);
  51. }
  52. - (void)ucm_subVeiwsTapBlock{
  53. @weakify(self)
  54. self.TableV.tapClose = ^(NSInteger num, id data) {
  55. //num = 0 删除商品 ,1 修改数量 countV
  56. @strongify(self)
  57. if([data isKindOfClass:[CartTotalsItemsM class]]){
  58. switch (num) {
  59. case 0:
  60. [self reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)data];
  61. break;
  62. case 1:
  63. [self reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)data];
  64. break;
  65. default:
  66. break;
  67. }
  68. }else if ([data isKindOfClass:[MyCartCouponCellData class]]){
  69. MyCartCouponCellData *couponM = (MyCartCouponCellData *)data;
  70. if(num ==0){ //使用优惠券
  71. [self reqNet_PUT_cartsMineCoupons:couponM.coupon_code];
  72. }else if(num == 1){//删除优惠券
  73. [self reqNet_DEL_cartsMineCoupons];
  74. }
  75. }
  76. };
  77. }
  78. - (void)ucm_bindvmmodel{
  79. self.VM = [[CartVM alloc]initDelegate:self];
  80. }
  81. #pragma mark - **************** reqNet ****************
  82. ///获取购物车
  83. -(void)reqNet_Cart_cartsMineTotals{
  84. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  85. [self.VM ry_requestGetApi:Cart_cartsMineTotals param:@{}];
  86. }
  87. ///修改商品的数量
  88. -(void)reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)itemM{
  89. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  90. NSDictionary *cartItemDic = @{
  91. @"item_id":itemM.item_id,
  92. @"qty":itemM.qty,
  93. @"quote_id":self.totalsM.cart_id
  94. };
  95. NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{
  96. @"cartItem":cartItemDic
  97. }];
  98. [self.VM ry_requestPostApi:Cart_cartsMineItems_Post param:param];
  99. }
  100. ///删除商品
  101. -(void)reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)itemM{
  102. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  103. [self.VM ry_requestDeleteApi:DEL_cartsMineItems paramStr:itemM.item_id];
  104. }
  105. -(void)reqNet_PUT_cartsMineCoupons:(NSString *)coupon{
  106. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  107. [self.VM ry_requestPutApi:PUT_cartsMineCoupons param:coupon];
  108. }
  109. -(void)reqNet_DEL_cartsMineCoupons{
  110. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  111. [self.VM ry_requestDeleteApi:DEL_cartsMineCoupons paramStr:@""];
  112. }
  113. - (void)ry_respnsData:(id)data
  114. parseAry:(NSMutableArray *)arry
  115. sucess:(BOOL)sucessOrFail
  116. mark:(NSString *)mark
  117. reqNetType:(ReqNetType)reqNetType{
  118. [MBProgressHUD hideHUDForView:self.view animated:YES];
  119. if([mark isEqualToString:Cart_cartsMineTotals]){
  120. if(sucessOrFail){
  121. CartTotalsM *model = [arry firstObject];
  122. self.totalsM = model;
  123. self.top_totalLab.text = [NSString stringWithFormat:@"%@ pcs | total",model.items_qty];
  124. self.top_priceLab.text =[NSString stringWithFormat:@"%@%@",model.currency_symbol,model.subtotal];
  125. [self.TableV.infodata removeAllObjects];
  126. self.TableV.infodata = [NSMutableArray arrayWithArray:model.items];
  127. self.couponCellM.couponAry =[NSMutableArray arrayWithArray: [ASNetTools shared].xxx_couponAry];
  128. self.couponCellM.coupon_code = model.coupon_code;
  129. self.couponCellM.discount_amount = model.discount_amount;
  130. self.couponCellM.currency_symbol = model.currency_symbol;
  131. [self.TableV.infodata addObject:self.couponCellM];
  132. self.totalCellM.total_segments = [NSMutableArray arrayWithArray:model.total_segments];
  133. self.totalCellM.currency_symbol = model.currency_symbol;
  134. [self.TableV.infodata addObject:self.totalCellM];
  135. MyCartPayTypeCellData *data = [[MyCartPayTypeCellData alloc]init];
  136. data.final_prices_f = [model.subtotal floatValue];
  137. data.currency_symbol = model.currency_symbol;
  138. [self.TableV.infodata addObject:data];
  139. [self.TableV reloadData];
  140. }
  141. }else if ([mark isEqualToString:Cart_cartsMineItems_Post]
  142. || [mark isEqualToString:DEL_cartsMineItems]
  143. || [mark isEqualToString:PUT_cartsMineCoupons]){
  144. if(sucessOrFail){
  145. [self reqNet_Cart_cartsMineTotals];
  146. }else{
  147. [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
  148. }
  149. }
  150. }
  151. - (void)tapcellTriggereventIndex:(NSIndexPath *)index model:(id)model{
  152. if([model isKindOfClass:[CartTotalsItemsM class]]){
  153. CartTotalsItemsM *itemM = (CartTotalsItemsM *)model;
  154. if(itemM.isGift){
  155. return;
  156. }
  157. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":itemM.product_id}];
  158. [self.navigationController pushViewController:viewController animated:YES];
  159. }
  160. }
  161. -(void)handle_postEvent:(UIButton *)btn{
  162. Cart_CheckoutC *vc = [[Cart_CheckoutC alloc]init];
  163. vc.totalsM = self.totalsM;
  164. [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  165. }
  166. #pragma mark - **************** lazy ****************
  167. -(UIView *)topBgV{
  168. if(!_topBgV){
  169. IPhoneXHeigh
  170. _topBgV = [[UIView alloc]initWithFrame:CGRectMake(0, securitytop_Y, KScreenWidth, 60)];
  171. _topBgV.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"];
  172. }
  173. return _topBgV;
  174. }
  175. - (UILabel *)top_totalLab {
  176. if (!_top_totalLab) {
  177. _top_totalLab = [[UILabel alloc] initWithFrame:CGRectZero];
  178. _top_totalLab.textAlignment = NSTextAlignmentLeft;
  179. _top_totalLab.font = [UIFont fontWithName:Rob_Regular size:14];
  180. _top_totalLab.textColor = [UIColor colorWithHexString:@"#000000"];
  181. }
  182. return _top_totalLab;
  183. }
  184. - (QMUILabel *)top_priceLab {
  185. if (!_top_priceLab) {
  186. _top_priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  187. _top_priceLab.textAlignment = NSTextAlignmentLeft;
  188. _top_priceLab.font = [UIFont fontWithName:Rob_Bold size:16];
  189. }
  190. return _top_priceLab;
  191. }
  192. - (MyCartCouponCellData *)couponCellM {
  193. if (!_couponCellM) {
  194. _couponCellM = [[MyCartCouponCellData alloc] init];
  195. }
  196. return _couponCellM;
  197. }
  198. - (MyCartGrandTotalCellData *)totalCellM {
  199. if (!_totalCellM) {
  200. _totalCellM = [[MyCartGrandTotalCellData alloc] init];
  201. }
  202. return _totalCellM;
  203. }
  204. - (UIButton *)postBtn {
  205. if (!_postBtn) {
  206. _postBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  207. _postBtn.layer.cornerRadius = 4;
  208. _postBtn.clipsToBounds = YES;
  209. IPhoneXHeigh
  210. _postBtn.frame = CGRectMake(10, 0, KScreenWidth-20, 45);
  211. _postBtn.backgroundColor = [UIColor colorWithHexString:@"#000000"];
  212. [_postBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  213. _postBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  214. [_postBtn setTitle:@"POST COMMENT" forState:UIControlStateNormal];
  215. [_postBtn addTarget:self action:@selector(handle_postEvent:) forControlEvents:UIControlEventTouchUpInside];
  216. }
  217. return _postBtn;
  218. }
  219. @end