149 lines
4.2 KiB
Objective-C
Executable File
149 lines
4.2 KiB
Objective-C
Executable File
//
|
|
// SPTrendListVC.m
|
|
// SweetParty
|
|
//
|
|
// Created by bj_szd on 2022/6/1.
|
|
//
|
|
|
|
#import "SPTrendListVC.h"
|
|
#import "SPTrendListCell.h"
|
|
#import "SPTrendDetailVC.h"
|
|
|
|
@interface SPTrendListVC ()
|
|
|
|
@end
|
|
|
|
@implementation SPTrendListVC
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
[self createUI];
|
|
|
|
[self fetchData];
|
|
}
|
|
|
|
-(void)createUI {
|
|
self.view.backgroundColor = [UIColor clearColor];
|
|
|
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.view);
|
|
}];
|
|
|
|
[self.tableView registerNib:[UINib nibWithNibName:@"SPTrendListCell" bundle:nil] forCellReuseIdentifier:@"SPTrendListCell"];
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
|
self.tableView.estimatedRowHeight = 152;
|
|
|
|
[self showPullToRefresh];
|
|
[self showLoadMoreRefresh];
|
|
|
|
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
|
|
self.tableView.tableHeaderView = headerView;
|
|
}
|
|
|
|
- (void)fetchData {
|
|
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:@{@"page":@(self.page), @"page_limit":@(10)}];
|
|
if (self.type == 2) {
|
|
[params setObject:@"2" forKey:@"is_recommend"];
|
|
}else if (self.type == 3) {
|
|
[params setObject:@"1" forKey:@"is_follow"];
|
|
}
|
|
|
|
[AFNetworkRequset.shared postRequestWithParams:params Path:@"api/User_Zone/get_zone_list" Loading:YES Hud:NO Success:^(id _Nonnull responseDic) {
|
|
if (self.page == 1) {
|
|
[self.dataArray removeAllObjects];
|
|
[self.tableView reloadData];
|
|
}
|
|
[self endRefresh];
|
|
|
|
NSArray *arr = [SPTrendListModel mj_objectArrayWithKeyValuesArray:responseDic[@"data"]];
|
|
|
|
[self.dataArray addObjectsFromArray:arr];
|
|
[self.tableView reloadData];
|
|
|
|
if (arr.count > 0) {
|
|
[self endFooterRefreshWithMore];
|
|
}else {
|
|
[self endFooterRefreshWithNoMore];
|
|
}
|
|
|
|
if (self.dataArray.count <= 0) {
|
|
[self showNoContentView];
|
|
} else {
|
|
[self hideNoContentView];
|
|
}
|
|
} Failure:^(id _Nonnull errorData) {
|
|
|
|
}];
|
|
}
|
|
|
|
- (void)refreshFetchData {
|
|
self.page = 1;
|
|
[self fetchData];
|
|
}
|
|
|
|
- (void)fetchMoreData {
|
|
self.page ++;
|
|
[self fetchData];
|
|
}
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return self.dataArray.count;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
SPTrendListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SPTrendListCell" forIndexPath:indexPath];
|
|
cell.selectionStyle = NO;
|
|
|
|
SPTrendListModel *model = self.dataArray[indexPath.row];
|
|
cell.model = model;
|
|
WEAK_SELF
|
|
cell.onDeleteBlock = ^{
|
|
[weakSelf onDeleteWith:indexPath.row];
|
|
};
|
|
|
|
return cell;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
SPTrendListModel *model = self.dataArray[indexPath.row];
|
|
SPTrendDetailVC *vc = [[SPTrendDetailVC alloc] init];
|
|
vc.zid = model.zid;
|
|
WEAK_SELF
|
|
vc.onDeleteBlock = ^(NSString * _Nonnull zid) {
|
|
[weakSelf.dataArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
SPTrendListModel *topicObj = obj;
|
|
if ([topicObj.zid isEqualToString:zid]) {
|
|
[weakSelf.dataArray removeObject:topicObj];
|
|
}
|
|
}];
|
|
[weakSelf.tableView reloadData];
|
|
};
|
|
[[UIViewController currentViewController].navigationController pushViewController:vc animated:YES];
|
|
}
|
|
|
|
-(void)onDeleteWith:(NSInteger)index {
|
|
SPTrendListModel *model = self.dataArray[index];
|
|
NSDictionary *params = @{@"zid":model.zid};
|
|
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"api/User_Zone/delete_zone" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
|
|
[self.dataArray removeObjectAtIndex:index];
|
|
[self.tableView reloadData];
|
|
} Failure:^(id _Nonnull errorData) {
|
|
|
|
}];
|
|
}
|
|
|
|
#pragma mark - JXCategoryListContentViewDelegate
|
|
|
|
- (UIView *)listView {
|
|
return self.view;
|
|
}
|
|
|
|
@end
|