ASOrderListSubController.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // ASOrderListSubController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2024/5/13.
  6. //
  7. #import "ASOrderListSubController.h"
  8. #import "ASOrderListCell.h"
  9. #import "ASOrderListViewModel.h"
  10. #import "ASOrderDetailsViewController.h"
  11. @interface ASOrderListSubController ()<UITableViewDelegate, UITableViewDataSource>
  12. @property (nonatomic, strong) UITableView *tableV;
  13. @property (nonatomic, strong) NSMutableArray<KWMineHomeOrderModel *> *orderArr;
  14. @property (nonatomic, assign) NSInteger page;
  15. @property (nonatomic, strong) ASOrderListViewModel *vm;
  16. @property (nonatomic, assign) NSInteger addCartCount;
  17. @end
  18. @implementation ASOrderListSubController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.customNavBar.hidden = true;
  22. self.statusBgV.hidden = true;
  23. self.vm = [ASOrderListViewModel new];
  24. self.page = 1;
  25. [self getOrderData];
  26. [self loadSubV];
  27. [self viewAction];
  28. self.view.backgroundColor = _F8F8F8;
  29. }
  30. - (void)refreshListData {
  31. [self.tableV.mj_header beginRefreshing];
  32. }
  33. - (void)checkEmpty {
  34. if (self.orderArr.count == 0) {
  35. [self showEmptyV: self.tableV];
  36. } else {
  37. [self hiddenEmpty];
  38. }
  39. }
  40. - (void)viewAction {
  41. __weak typeof(self) weakSelf = self;
  42. self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  43. weakSelf.page = 1;
  44. [weakSelf getOrderData];
  45. }];
  46. self.tableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  47. weakSelf.page += 1;
  48. [weakSelf getOrderData];
  49. }];
  50. }
  51. // MARK: - net
  52. - (void)getOrderData {
  53. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  54. __weak typeof(self) weakSelf = self;
  55. [self.vm getOrderNet:self.status page:self.page com:^(NSArray<KWMineHomeOrderModel *> * _Nonnull arr) {
  56. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  57. [weakSelf.tableV.mj_header endRefreshing];
  58. if (arr.count < 10) {
  59. [weakSelf.tableV.mj_footer endRefreshingWithNoMoreData];
  60. } else {
  61. [weakSelf.tableV.mj_footer endRefreshing];
  62. }
  63. if (weakSelf.page == 1) {
  64. weakSelf.orderArr = [NSMutableArray arrayWithArray:arr];
  65. } else {
  66. [weakSelf.orderArr addObjectsFromArray:arr];
  67. }
  68. [weakSelf.tableV reloadData];
  69. [weakSelf checkEmpty];
  70. }];
  71. }
  72. // MARK: - loadSubv
  73. - (void)loadSubV {
  74. [self.view addSubview:self.tableV];
  75. [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.edges.equalTo(self.view);
  77. }];
  78. }
  79. // MARK: - subvs
  80. - (UITableView *)tableV {
  81. if (!_tableV) {
  82. UITableView *v = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  83. [v registerClass:[ASOrderListCell class] forCellReuseIdentifier:@"ASOrderListCell"];
  84. v.delegate = self;
  85. v.dataSource = self;
  86. [v baseSet];
  87. v.backgroundColor = _F8F8F8;
  88. _tableV = v;
  89. }
  90. return _tableV;
  91. }
  92. #pragma mark - UITableViewDelegate,UITableViewDataSource
  93. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  94. }
  95. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  96. return self.orderArr.count;
  97. }
  98. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  99. ASOrderListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASOrderListCell" forIndexPath:indexPath];
  100. if (self.orderArr.count <= indexPath.row) {
  101. return cell;
  102. }
  103. KWMineHomeOrderModel *m = self.orderArr[indexPath.row];
  104. [cell setData:m];
  105. @weakify(self);
  106. [cell setViewOrderCall:^(NSInteger type, KWMineHomeOrderModel *model){
  107. @strongify(self)
  108. // type 0: view Order 1: trackOrder 2: reorder 3: pay now
  109. if (![ASUserInfoManager.shared isLogin]) {
  110. [self popAndToLogin];
  111. return;
  112. }
  113. // 查看订单
  114. if (type == 0) {//订单详情
  115. ASOrderDetailsViewController *orderDetailsVC = [[ASOrderDetailsViewController alloc] init];
  116. orderDetailsVC.orderId = model.entity_id;
  117. [self.navigationController pushViewController:orderDetailsVC animated:YES];
  118. } else if (type == 1) {//Track Order
  119. ASOrderDetailsViewController *orderDetailsVC = [[ASOrderDetailsViewController alloc] init];
  120. orderDetailsVC.orderId = model.entity_id;
  121. [self.navigationController pushViewController:orderDetailsVC animated:YES];
  122. } else if (type == 2) {
  123. [self reorderClickWithData:model];
  124. }
  125. // KWM_OrderViewC *vc = [[KWM_OrderViewC alloc]init];
  126. // vc.order_id = m.orderId;
  127. // [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  128. }];
  129. return cell;
  130. }
  131. - (void)reorderClickWithData:(KWMineHomeOrderModel *)orderModel {
  132. NSMutableArray *itemOptionArr = [[NSMutableArray alloc] initWithCapacity:1];
  133. for (KWMineOrderProInfoModel *proModel in orderModel.items) {
  134. if (![proModel.name hasPrefix:@"FREE"]) {
  135. if (AS_Array_valid(proModel.custom_options)) {
  136. NSMutableDictionary *optionParam = [NSMutableDictionary dictionary];
  137. for (NSDictionary *optionsDic in proModel.custom_options) {
  138. [optionParam setValue:optionsDic[@"option_value"] forKey:[NSString stringWithFormat:@"options[%@]", optionsDic[@"option_id"]]];
  139. }
  140. [optionParam setValue:proModel.product_id forKey:@"product"];
  141. [optionParam setValue:@"1" forKey:@"qty"];
  142. [itemOptionArr addObject:optionParam];
  143. }
  144. }
  145. }
  146. self.addCartCount = itemOptionArr.count;
  147. if (self.addCartCount == 0) {
  148. return;
  149. }
  150. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  151. for (NSDictionary *param in itemOptionArr) {
  152. [self requestAddCartWithParams:param];
  153. }
  154. }
  155. - (void)requestAddCartWithParams:(NSDictionary *)params {
  156. K_WEAK_SELF;
  157. [self.vm orderGoodsAddCartWithParam:params complete:^(BOOL isSuccess, NSString * _Nonnull msg) {
  158. K_STRONG_SELF;
  159. self.addCartCount--;
  160. if (self.addCartCount == 0) {
  161. [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  162. [Fuction_Tool popToRootViewController:2];
  163. }];
  164. [MBProgressHUD hideHUDForView:self.view animated:YES];
  165. }
  166. }];
  167. }
  168. @end