SPSBMineMessageTableViewController.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // SPSBMineMessageTableViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/5/21.
  6. //
  7. #import "SPSBMineMessageTableViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "UIViewController+SPSBNetworkManager.h"
  10. #import "SPSBMineMessageModel.h"
  11. #import "SPSBSQLProfile.h"
  12. #import "SPSBMineMessageTableViewCell.h"
  13. @interface SPSBMineMessageTableViewController () {
  14. NSArray *_data;
  15. SPSBMineMessageTableViewCell *_firstCell;
  16. }
  17. @end
  18. @implementation SPSBMineMessageTableViewController
  19. - (instancetype)init {
  20. self = [super initWithStyle:UITableViewStylePlain backgroundColor:SPSBTableViewBackgroundColorGray];
  21. if (!self) return nil;
  22. return self;
  23. }
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. [self setupUI];
  27. [self getMessage];
  28. }
  29. #pragma mark - Action
  30. #pragma mark - Network Action
  31. - (void)getMessage {
  32. @weakify(self)
  33. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在加载" isLogin:true url:spsb_appUrl(SPSBUrlGetMessageList) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  34. @strongify(self)
  35. [self getMessageSuccess:data];
  36. return @"";
  37. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  38. @strongify(self)
  39. [self getMessageSuccess:nil];
  40. return @"";
  41. }];
  42. }
  43. - (void)getMessageSuccess:(id)data {
  44. if (data[@"data"]) {
  45. [SPSBMineMessageModel insertMessageDataWithArray:data[@"data"]];
  46. }
  47. NSArray *array = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceLocationSQL backKey:nil condition:^id(FMDatabase *database) {
  48. return [database executeQuery:@"select * from t_sp_message"];
  49. }];
  50. _data = [SPSBMineMessageModel getModelListWithArray:array];
  51. [self.tableView reloadData];
  52. if (_data.count > 0) {
  53. dispatch_async(dispatch_get_main_queue(), ^{
  54. [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self->_data.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:false];
  55. });
  56. }
  57. }
  58. #pragma mark - Delegate & DataSource
  59. static NSString * const reuseIdentifier = @"SPSBMineMessageTableViewCell";
  60. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  61. SPSBMineMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
  62. if (!cell) {
  63. cell = [[SPSBMineMessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
  64. }
  65. if (_data.count > indexPath.row) {
  66. SPSBMineMessageModel *model = _data[indexPath.row];
  67. if (indexPath.row == 0) {
  68. cell = _firstCell;
  69. }
  70. [cell reloadData:model];
  71. }
  72. return cell;
  73. }
  74. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  75. return _data.count;
  76. }
  77. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  78. [tableView deselectRowAtIndexPath:indexPath animated:false];
  79. }
  80. #pragma mark - UI
  81. - (void)setupUI {
  82. self.title = @"我的消息";
  83. _firstCell = [SPSBMineMessageTableViewCell creatFirstCell];
  84. self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:(CGRect){0, 0, jxh_screenWidth(), 20}];
  85. }
  86. @end