SPSBSalaryTableViewController.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // SPSBSalaryTableViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/6/18.
  6. //
  7. #import "SPSBSalaryTableViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "UIViewController+SPSBNetworkManager.h"
  10. #import "SPSBOrderListTableViewCell.h"
  11. #import "SPSBSalaryOrderModel.h"
  12. #import "UITableView+SPSBDefault.h"
  13. #import "SPSBSalaryPayViewController.h"
  14. @interface SPSBSalaryTableViewController () {
  15. NSArray<SPSBSalaryOrderModel *> *_dataArray;
  16. }
  17. @end
  18. @implementation SPSBSalaryTableViewController
  19. - (instancetype)init {
  20. self = [super initWithStyle:UITableViewStyleGrouped];
  21. if (!self) return nil;
  22. return self;
  23. }
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. [self setupTableView];
  27. }
  28. - (void)viewWillAppear:(BOOL)animated {
  29. [super viewWillAppear:animated];
  30. if (!_dataArray) {
  31. [self getData];
  32. }
  33. }
  34. #pragma mark - Action
  35. - (void)cellAction:(SPSBOrderListTableViewCell *)cell type:(SPSBOrderListTableActionType)type {
  36. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  37. if (!indexPath || indexPath.row >= _dataArray.count) return;
  38. switch (type) {
  39. case SPSBOrderListTableActionTypePay:
  40. [self showOrderDetailsWithIndexPath:indexPath type:SPSBSalaryPayViewTypePaid];
  41. break;
  42. case SPSBOrderListTableActionTypeDetails:
  43. [self showOrderDetailsWithIndexPath:indexPath type:SPSBSalaryPayViewTypeDetails];
  44. break;
  45. case SPSBOrderListTableActionTypeProgress:
  46. [self showOrderDetailsWithIndexPath:indexPath type:SPSBSalaryPayViewTypeProgress];
  47. break;
  48. default:
  49. break;
  50. }
  51. }
  52. - (void)showOrderDetailsWithIndexPath:(NSIndexPath *)indexPath type:(SPSBSalaryPayViewType)type {
  53. SPSBSalaryPayViewController *vc = SPSBSalaryPayViewController.new;
  54. vc.spsb_data = _dataArray[indexPath.row];
  55. vc.spsb_type = type;
  56. [self presentViewController:vc animated:false completion:nil];
  57. }
  58. #pragma mark - Network Action
  59. - (void)getData {
  60. @weakify(self)
  61. [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) {
  62. @strongify(self)
  63. [self getDataSuccess:data];
  64. return @"";
  65. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  66. @strongify(self)
  67. [self getDataFailure:error];
  68. return @"加载失败";
  69. }];
  70. }
  71. - (void)getDataSuccess:(id)data {
  72. _dataArray = [SPSBSalaryOrderModel getModelListWithArray:data[@"data"]];
  73. [self.tableView reloadData];
  74. if (_dataArray.count == 0) {
  75. self.tableView.backgroundColor = spsb_FFFFFF_color(1.f);
  76. [self.tableView setDefaultFootViewWithError:nil image:jxh_getImage(liushui_qs) height:jxh_viewHeight(self.tableView) action:^{
  77. }];
  78. } else {
  79. self.tableView.backgroundColor = spsb_F5F5F5_color();
  80. [self.tableView removeDefaultFootView];
  81. }
  82. }
  83. - (void)getDataFailure:(NSError *)error {
  84. @weakify(self)
  85. self.tableView.backgroundColor = spsb_FFFFFF_color(1.f);
  86. [self.tableView setDefaultFootViewWithError:error image:nil height:jxh_viewHeight(self.tableView) action:^{
  87. @strongify(self)
  88. self.tableView.backgroundColor = spsb_F5F5F5_color();
  89. [self getData];
  90. }];
  91. }
  92. #pragma mark - Delegate & DataSource
  93. static NSString * const reuseIdentifier = @"SPSBSalaryTableViewCell";
  94. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  95. SPSBOrderListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
  96. if (!cell) {
  97. cell = [[SPSBOrderListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier orderType:SPSBOrderTypeSalary];
  98. @weakify(self)
  99. cell.spsb_action = ^(SPSBOrderListTableViewCell * _Nonnull cell, SPSBOrderListTableActionType type) {
  100. @strongify(self)
  101. [self cellAction:cell type:type];
  102. };
  103. }
  104. SPSBSalaryOrderModel *model = _dataArray[indexPath.row];
  105. [cell reloadSalaryData:model];
  106. return cell;
  107. }
  108. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  109. return _dataArray.count;
  110. }
  111. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  112. [tableView deselectRowAtIndexPath:indexPath animated:false];
  113. }
  114. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  115. return 10;
  116. }
  117. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  118. return UIView.new;
  119. }
  120. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  121. return 10;
  122. }
  123. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  124. return UIView.new;
  125. }
  126. #pragma mark - UI
  127. - (void)setupTableView {
  128. self.tableView.estimatedRowHeight = 100.f;
  129. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  130. self.tableView.showsHorizontalScrollIndicator = false;
  131. self.tableView.showsVerticalScrollIndicator = false;
  132. self.tableView.alwaysBounceVertical = true;
  133. }
  134. @end