ASOrderDetailsViewController.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // ASOrderDetailsViewController.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/15.
  6. //
  7. #import "ASOrderDetailsViewController.h"
  8. #import "ASOrderDetailsVM.h"
  9. #import "ASOrderDetailsModel.h"
  10. #import "ASOrderDetailsInfoCell.h"
  11. #import "ASOrderDetailsItemsCell.h"
  12. #import "ASOrderDetailsPriceCell.h"
  13. #import "ASPayFinishHeadView.h"
  14. @interface ASOrderDetailsViewController ()<UITableViewDelegate, UITableViewDataSource>
  15. @property (nonatomic, strong) UITableView *tableView;
  16. @property (nonatomic, strong) ASOrderDetailsVM *orderDetailsVM;
  17. @property (nonatomic, strong) ASOrderDetailsModel *orderDetailsModel;
  18. @property (nonatomic, strong) ASPayFinishHeadView *paySuccessView;
  19. @end
  20. @implementation ASOrderDetailsViewController
  21. - (void)viewWillAppear:(BOOL)animated {
  22. [super viewWillAppear:animated];
  23. if (self.isPay) {
  24. //支付成功页面禁止侧滑返回
  25. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  26. }
  27. }
  28. - (void)viewWillDisappear:(BOOL)animated {
  29. [super viewWillDisappear:animated];
  30. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  31. }
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. if (self.isPay) {
  35. self.titleStr = @"Payment";
  36. } else {
  37. self.titleStr = @"Orders Information";
  38. }
  39. self.statusBgV.backgroundColor = Col_FFF;
  40. self.customNavBar.backgroundColor = Col_FFF;
  41. self.orderDetailsVM = [ASOrderDetailsVM new];
  42. [self loadSubV];
  43. [self requestOrderDetailsData];
  44. }
  45. - (void)requestOrderDetailsData {
  46. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  47. @weakify(self)
  48. [self.orderDetailsVM getOrderDetailsWithOrderid:self.orderId complete:^(ASOrderDetailsModel *orderModel) {
  49. @strongify(self)
  50. [MBProgressHUD hideHUDForView:self.view animated:true];
  51. self.orderDetailsModel = orderModel;
  52. [self.tableView reloadData];
  53. [self checkEmpty];
  54. }];
  55. }
  56. - (void)checkEmpty {
  57. if (!self.orderDetailsModel) {
  58. [self showEmptyV:self.tableView];
  59. } else {
  60. [self hiddenEmpty];
  61. }
  62. }
  63. #pragma mark - UITableViewDelegate,UITableViewDataSource
  64. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  65. if (self.orderDetailsModel) {
  66. return 3;
  67. }
  68. return 0;
  69. }
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  71. if (section == 1) {
  72. return self.orderDetailsModel.items.count;
  73. }
  74. return 1;
  75. }
  76. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  77. if (indexPath.section == 0) {
  78. ASOrderDetailsInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASOrderDetailsInfoCell" forIndexPath:indexPath];
  79. cell.orderModel = self.orderDetailsModel;
  80. return cell;
  81. } else if (indexPath.section == 1) {
  82. ASOrderDetailsItemsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASOrderDetailsItemsCell" forIndexPath:indexPath];
  83. NSArray *itemArr = self.orderDetailsModel.items;
  84. ASOrderDetailsItemModel *itemModel = itemArr[indexPath.row];
  85. cell.itemModel = itemModel;
  86. return cell;
  87. } else {
  88. ASOrderDetailsPriceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASOrderDetailsPriceCell" forIndexPath:indexPath];
  89. cell.orderModel = self.orderDetailsModel;
  90. return cell;
  91. }
  92. }
  93. - (void)backAction {
  94. if (self.isPay) {
  95. [self.navigationController popToRootViewControllerAnimated:YES];
  96. } else {
  97. [self.navigationController popViewControllerAnimated:YES];
  98. }
  99. }
  100. #pragma mark ---- UI ----
  101. - (void)loadSubV {
  102. [self.view addSubview:self.tableView];
  103. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.top.equalTo(self.customNavBar.mas_bottom);
  105. make.leading.trailing.bottom.equalTo(self.view);
  106. }];
  107. if (self.isPay) {
  108. self.tableView.tableHeaderView = self.paySuccessView;
  109. }
  110. }
  111. // MARK: - subvs
  112. - (UITableView *)tableView {
  113. if (!_tableView) {
  114. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  115. [_tableView registerClass:[ASOrderDetailsInfoCell class] forCellReuseIdentifier:@"ASOrderDetailsInfoCell"];
  116. [_tableView registerClass:[ASOrderDetailsItemsCell class] forCellReuseIdentifier:@"ASOrderDetailsItemsCell"];
  117. [_tableView registerClass:[ASOrderDetailsPriceCell class] forCellReuseIdentifier:@"ASOrderDetailsPriceCell"];
  118. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  119. _tableView.delegate = self;
  120. _tableView.dataSource = self;
  121. _tableView.backgroundColor = _F8F8F8;
  122. _tableView.estimatedRowHeight = 50;
  123. }
  124. return _tableView;
  125. }
  126. - (ASPayFinishHeadView *)paySuccessView {
  127. if (!_paySuccessView) {
  128. _paySuccessView = [[ASPayFinishHeadView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 100) status:1 desc:self.orderId];
  129. K_WEAK_SELF;
  130. _paySuccessView.clickBlock = ^(int type) {
  131. K_STRONG_SELF;
  132. if (type == 1) {
  133. [Fuction_Tool popToHomeVc];
  134. }
  135. };
  136. _paySuccessView.frame = CGRectMake(0, 0, KScreenWidth, [_paySuccessView getViewHeight]);
  137. }
  138. return _paySuccessView;
  139. }
  140. @end