ASOrderListSubController.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. @end
  17. @implementation ASOrderListSubController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.customNavBar.hidden = true;
  21. self.statusBgV.hidden = true;
  22. self.vm = [ASOrderListViewModel new];
  23. self.page = 1;
  24. [self getOrderData];
  25. [self loadSubV];
  26. [self viewAction];
  27. self.view.backgroundColor = _F8F8F8;
  28. }
  29. - (void)refreshListData {
  30. [self.tableV.mj_header beginRefreshing];
  31. }
  32. - (void)checkEmpty {
  33. if (self.orderArr.count == 0) {
  34. [self showEmptyV: self.tableV];
  35. } else {
  36. [self hiddenEmpty];
  37. }
  38. }
  39. - (void)viewAction {
  40. __weak typeof(self) weakSelf = self;
  41. self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  42. weakSelf.page = 1;
  43. [weakSelf getOrderData];
  44. }];
  45. self.tableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  46. weakSelf.page += 1;
  47. [weakSelf getOrderData];
  48. }];
  49. }
  50. // MARK: - net
  51. - (void)getOrderData {
  52. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  53. __weak typeof(self) weakSelf = self;
  54. [self.vm getOrderNet:self.status page:self.page com:^(NSArray<KWMineHomeOrderModel *> * _Nonnull arr) {
  55. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  56. [weakSelf.tableV.mj_header endRefreshing];
  57. if (arr.count < 10) {
  58. [weakSelf.tableV.mj_footer endRefreshingWithNoMoreData];
  59. } else {
  60. [weakSelf.tableV.mj_footer endRefreshing];
  61. }
  62. if (weakSelf.page == 1) {
  63. weakSelf.orderArr = [NSMutableArray arrayWithArray:arr];
  64. } else {
  65. [weakSelf.orderArr addObjectsFromArray:arr];
  66. }
  67. [weakSelf.tableV reloadData];
  68. [weakSelf checkEmpty];
  69. }];
  70. }
  71. // MARK: - loadSubv
  72. - (void)loadSubV {
  73. [self.view addSubview:self.tableV];
  74. [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.edges.equalTo(self.view);
  76. }];
  77. }
  78. // MARK: - subvs
  79. - (UITableView *)tableV {
  80. if (!_tableV) {
  81. UITableView *v = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  82. [v registerClass:[ASOrderListCell class] forCellReuseIdentifier:@"ASOrderListCell"];
  83. v.delegate = self;
  84. v.dataSource = self;
  85. [v baseSet];
  86. v.backgroundColor = _F8F8F8;
  87. _tableV = v;
  88. }
  89. return _tableV;
  90. }
  91. #pragma mark - UITableViewDelegate,UITableViewDataSource
  92. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  93. }
  94. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  95. return self.orderArr.count;
  96. }
  97. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  98. ASOrderListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASOrderListCell" forIndexPath:indexPath];
  99. if (self.orderArr.count <= indexPath.row) {
  100. return cell;
  101. }
  102. KWMineHomeOrderModel *m = self.orderArr[indexPath.row];
  103. [cell setData:m];
  104. @weakify(self);
  105. [cell setViewOrderCall:^(NSInteger type, KWMineHomeOrderModel *model){
  106. @strongify(self)
  107. // type 0: view Order 1: trackOrder 2: reorder 3: pay now
  108. if (![ASUserInfoManager.shared isLogin]) {
  109. [self popAndToLogin];
  110. return;
  111. }
  112. // 查看订单
  113. NSLog(@"查看订单 view order");
  114. ASOrderDetailsViewController *orderDetailsVC = [[ASOrderDetailsViewController alloc] init];
  115. orderDetailsVC.orderId = model.entity_id;
  116. [self.navigationController pushViewController:orderDetailsVC animated:YES];
  117. // KWM_OrderViewC *vc = [[KWM_OrderViewC alloc]init];
  118. // vc.order_id = m.orderId;
  119. // [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  120. }];
  121. return cell;
  122. }
  123. @end