// // SPSBMineMessageTableViewController.m // 我的社保 // // Created by shanp on 2021/5/21. // #import "SPSBMineMessageTableViewController.h" #import "SPSBUIGeneralHeader.h" #import "UIViewController+SPSBNetworkManager.h" #import "SPSBMineMessageModel.h" #import "SPSBSQLProfile.h" #import "SPSBMineMessageTableViewCell.h" @interface SPSBMineMessageTableViewController () { NSArray *_data; SPSBMineMessageTableViewCell *_firstCell; } @end @implementation SPSBMineMessageTableViewController - (instancetype)init { self = [super initWithStyle:UITableViewStylePlain backgroundColor:SPSBTableViewBackgroundColorGray]; if (!self) return nil; return self; } - (void)viewDidLoad { [super viewDidLoad]; [self setupUI]; [self getMessage]; } #pragma mark - Action #pragma mark - Network Action - (void)getMessage { @weakify(self) [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在加载" isLogin:true url:spsb_appUrl(SPSBUrlGetMessageList) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) { @strongify(self) [self getMessageSuccess:data]; return @""; } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) { @strongify(self) [self getMessageSuccess:nil]; return @""; }]; } - (void)getMessageSuccess:(id)data { if (data[@"data"]) { [SPSBMineMessageModel insertMessageDataWithArray:data[@"data"]]; } NSArray *array = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceLocationSQL backKey:nil condition:^id(FMDatabase *database) { return [database executeQuery:@"select * from t_sp_message"]; }]; _data = [SPSBMineMessageModel getModelListWithArray:array]; [self.tableView reloadData]; if (_data.count > 0) { dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self->_data.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:false]; }); } } #pragma mark - Delegate & DataSource static NSString * const reuseIdentifier = @"SPSBMineMessageTableViewCell"; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SPSBMineMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; if (!cell) { cell = [[SPSBMineMessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]; } if (_data.count > indexPath.row) { SPSBMineMessageModel *model = _data[indexPath.row]; if (indexPath.row == 0) { cell = _firstCell; } [cell reloadData:model]; } return cell; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _data.count; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:false]; } #pragma mark - UI - (void)setupUI { self.title = @"我的消息"; _firstCell = [SPSBMineMessageTableViewCell creatFirstCell]; self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:(CGRect){0, 0, jxh_screenWidth(), 20}]; } @end