// // SPSBSalaryTableViewController.m // 我的社保 // // Created by shanp on 2021/6/18. // #import "SPSBSalaryTableViewController.h" #import "SPSBUIGeneralHeader.h" #import "UIViewController+SPSBNetworkManager.h" #import "SPSBOrderListTableViewCell.h" #import "SPSBSalaryOrderModel.h" #import "UITableView+SPSBDefault.h" #import "SPSBSalaryPayViewController.h" @interface SPSBSalaryTableViewController () { NSArray *_dataArray; } @end @implementation SPSBSalaryTableViewController - (instancetype)init { self = [super initWithStyle:UITableViewStyleGrouped]; if (!self) return nil; return self; } - (void)viewDidLoad { [super viewDidLoad]; [self setupTableView]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (!_dataArray) { [self getData]; } } #pragma mark - Action - (void)cellAction:(SPSBOrderListTableViewCell *)cell type:(SPSBOrderListTableActionType)type { NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; if (!indexPath || indexPath.row >= _dataArray.count) return; switch (type) { case SPSBOrderListTableActionTypePay: [self showOrderDetailsWithIndexPath:indexPath type:SPSBSalaryPayViewTypePaid]; break; case SPSBOrderListTableActionTypeDetails: [self showOrderDetailsWithIndexPath:indexPath type:SPSBSalaryPayViewTypeDetails]; break; case SPSBOrderListTableActionTypeProgress: [self showOrderDetailsWithIndexPath:indexPath type:SPSBSalaryPayViewTypeProgress]; break; default: break; } } - (void)showOrderDetailsWithIndexPath:(NSIndexPath *)indexPath type:(SPSBSalaryPayViewType)type { SPSBSalaryPayViewController *vc = SPSBSalaryPayViewController.new; vc.spsb_data = _dataArray[indexPath.row]; vc.spsb_type = type; [self presentViewController:vc animated:false completion:nil]; } #pragma mark - Network Action - (void)getData { @weakify(self) [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在加载" isLogin:true url:spsb_appUrl(_spsb_type == SPSBSalaryTableViewTypeWaitForPay ? SPSBUrlUndoneSalaryList : SPSBUrlDoneSalaryList) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) { @strongify(self) [self getDataSuccess:data]; return @""; } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) { @strongify(self) [self getDataFailure:error]; return @"加载失败"; }]; } - (void)getDataSuccess:(id)data { _dataArray = [SPSBSalaryOrderModel getModelListWithArray:data[@"data"]]; [self.tableView reloadData]; if (_dataArray.count == 0) { self.tableView.backgroundColor = spsb_FFFFFF_color(1.f); [self.tableView setDefaultFootViewWithError:nil image:jxh_getImage(liushui_qs) height:jxh_viewHeight(self.tableView) action:^{ }]; } else { self.tableView.backgroundColor = spsb_F5F5F5_color(); [self.tableView removeDefaultFootView]; } } - (void)getDataFailure:(NSError *)error { @weakify(self) self.tableView.backgroundColor = spsb_FFFFFF_color(1.f); [self.tableView setDefaultFootViewWithError:error image:nil height:jxh_viewHeight(self.tableView) action:^{ @strongify(self) self.tableView.backgroundColor = spsb_F5F5F5_color(); [self getData]; }]; } #pragma mark - Delegate & DataSource static NSString * const reuseIdentifier = @"SPSBSalaryTableViewCell"; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SPSBOrderListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; if (!cell) { cell = [[SPSBOrderListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier orderType:SPSBOrderTypeSalary]; @weakify(self) cell.spsb_action = ^(SPSBOrderListTableViewCell * _Nonnull cell, SPSBOrderListTableActionType type) { @strongify(self) [self cellAction:cell type:type]; }; } SPSBSalaryOrderModel *model = _dataArray[indexPath.row]; [cell reloadSalaryData:model]; return cell; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _dataArray.count; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:false]; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 10; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return UIView.new; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 10; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return UIView.new; } #pragma mark - UI - (void)setupTableView { self.tableView.estimatedRowHeight = 100.f; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.showsHorizontalScrollIndicator = false; self.tableView.showsVerticalScrollIndicator = false; self.tableView.alwaysBounceVertical = true; } @end