cdts/xdts-ios 3/TreeHole/Code/Features/Settings/ViewController/BlackListViewController.m
2023-07-27 09:20:00 +08:00

85 lines
2.2 KiB
Objective-C

//
// BlackListViewController.m
// Youth
//
// Created by mambaxie on 2022/1/2.
//
#import "BlackListViewController.h"
#import "BlackListCell.h"
@interface BlackListViewController ()
@property (nonatomic, copy) NSString *nextStartDate;
@end
@implementation BlackListViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"黑名单";
[self startLoading];
}
- (BOOL)mt_hasContentForStateful {
return self.itemsM.count;
}
- (BOOL)mt_shouldSetupStateful {
return YES;
}
- (void)startRefresh {
// [super startRefresh];
[UserService getUserBlackListWithStartDate:@"" completion:^(NSArray<User *> * _Nonnull users, NSString *nextStartDate) {
self.nextStartDate = nextStartDate;
self.itemsM = [NSMutableArray array];
[self.itemsM addObjectsFromArray:users];
if (users.count >= 20) {
self.totalCount = self.itemsM.count + 1;
} else {
self.totalCount = self.itemsM.count;
}
[self.tableView reloadData];
[self endLoading:nil];
}];
}
- (void)startLoadMore {
[super startLoadMore];
[UserService getUserBlackListWithStartDate:self.nextStartDate completion:^(NSArray<User *> * _Nonnull users, NSString *nextStartDate) {
self.nextStartDate = nextStartDate;
[self.itemsM addObjectsFromArray:users];
if (users.count < 20) {
self.totalCount = self.itemsM.count;
} else {
self.totalCount = self.itemsM.count + 1;
}
[self.tableView reloadData];
}];
}
- (Class)cellClass {
return [BlackListCell class];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
BlackListCell *cell = (BlackListCell *)[super tableView:tableView cellForRowAtIndexPath:indexPath];
WeakSelf(self);
cell.removeAction = ^(User * _Nonnull user) {
[UserService setUserBlackWithUserID:user.ID isBlack:NO completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
[SVProgressHUD showSuccessWithStatus:@"移除成功"];
[weakself.itemsM removeObject:user];
[tableView reloadData];
}
}];
};
return cell;
}
@end