// // ASOrderDetailsViewController.m // Asteria // // Created by xingyu on 2024/5/15. // #import "ASOrderDetailsViewController.h" #import "ASOrderDetailsVM.h" #import "ASOrderDetailsModel.h" #import "ASOrderDetailsInfoCell.h" #import "ASOrderDetailsItemsCell.h" #import "ASOrderDetailsPriceCell.h" #import "ASPayFinishHeadView.h" @interface ASOrderDetailsViewController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) ASOrderDetailsVM *orderDetailsVM; @property (nonatomic, strong) ASOrderDetailsModel *orderDetailsModel; @property (nonatomic, strong) ASPayFinishHeadView *paySuccessView; @end @implementation ASOrderDetailsViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (self.isPay) { //支付成功页面禁止侧滑返回 self.navigationController.interactivePopGestureRecognizer.enabled = NO; } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.navigationController.interactivePopGestureRecognizer.enabled = YES; } - (void)viewDidLoad { [super viewDidLoad]; if (self.isPay) { self.titleStr = @"Payment"; } else { self.titleStr = @"Orders Information"; } self.statusBgV.backgroundColor = Col_FFF; self.customNavBar.backgroundColor = Col_FFF; self.orderDetailsVM = [ASOrderDetailsVM new]; [self loadSubV]; [self requestOrderDetailsData]; } - (void)requestOrderDetailsData { [MBProgressHUD showHUDAddedTo:self.view animated:true]; @weakify(self) [self.orderDetailsVM getOrderDetailsWithOrderid:self.orderId complete:^(ASOrderDetailsModel *orderModel) { @strongify(self) [MBProgressHUD hideHUDForView:self.view animated:true]; self.orderDetailsModel = orderModel; [self.tableView reloadData]; [self checkEmpty]; }]; } - (void)checkEmpty { if (!self.orderDetailsModel) { [self showEmptyV:self.tableView]; } else { [self hiddenEmpty]; } } #pragma mark - UITableViewDelegate,UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if (self.orderDetailsModel) { return 3; } return 0; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 1) { return self.orderDetailsModel.items.count; } return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { ASOrderDetailsInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASOrderDetailsInfoCell" forIndexPath:indexPath]; cell.orderModel = self.orderDetailsModel; return cell; } else if (indexPath.section == 1) { ASOrderDetailsItemsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASOrderDetailsItemsCell" forIndexPath:indexPath]; NSArray *itemArr = self.orderDetailsModel.items; ASOrderDetailsItemModel *itemModel = itemArr[indexPath.row]; cell.itemModel = itemModel; return cell; } else { ASOrderDetailsPriceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASOrderDetailsPriceCell" forIndexPath:indexPath]; cell.orderModel = self.orderDetailsModel; return cell; } } - (void)backAction { if (self.isPay) { [self.navigationController popToRootViewControllerAnimated:YES]; } else { [self.navigationController popViewControllerAnimated:YES]; } } #pragma mark ---- UI ---- - (void)loadSubV { [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.customNavBar.mas_bottom); make.leading.trailing.bottom.equalTo(self.view); }]; if (self.isPay) { self.tableView.tableHeaderView = self.paySuccessView; } } // MARK: - subvs - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; [_tableView registerClass:[ASOrderDetailsInfoCell class] forCellReuseIdentifier:@"ASOrderDetailsInfoCell"]; [_tableView registerClass:[ASOrderDetailsItemsCell class] forCellReuseIdentifier:@"ASOrderDetailsItemsCell"]; [_tableView registerClass:[ASOrderDetailsPriceCell class] forCellReuseIdentifier:@"ASOrderDetailsPriceCell"]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.delegate = self; _tableView.dataSource = self; _tableView.backgroundColor = _F8F8F8; _tableView.estimatedRowHeight = 50; } return _tableView; } - (ASPayFinishHeadView *)paySuccessView { if (!_paySuccessView) { _paySuccessView = [[ASPayFinishHeadView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 100) status:1 desc:self.orderId]; K_WEAK_SELF; _paySuccessView.clickBlock = ^(int type) { K_STRONG_SELF; if (type == 1) { [Fuction_Tool popToHomeVc]; } }; _paySuccessView.frame = CGRectMake(0, 0, KScreenWidth, [_paySuccessView getViewHeight]); } return _paySuccessView; } @end