Files
yinmeng-ios-store/yinmeng-ios/DingDangApp/CodeClass/SearchPage/DDSearchUserListViewController.m

174 lines
7.1 KiB
Objective-C

//
// DDSearchUserListViewController.m
// DingDangApp
//
// Created by apple on 2023/5/31.
//
#import "DDSearchUserListViewController.h"
#import "DDMyInfoCommonListTableView.h"
@interface DDSearchUserListViewController ()
@end
@implementation DDSearchUserListViewController
-(UITableView *)myTableView
{
if (!_myTableView) {
_myTableView = [[UITableView alloc] initWithFrame:CGRectZero
style:UITableViewStyleGrouped];
_myTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
_myTableView.estimatedSectionHeaderHeight = 0;
_myTableView.estimatedSectionFooterHeight = 0;
_myTableView.dataSource = self;
_myTableView.delegate = self;
_myTableView.estimatedRowHeight = 0;
_myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_myTableView.separatorColor = [UIColor clearColor];
_myTableView.backgroundColor = [UIColor clearColor];
[_myTableView registerClass:DDMyInfoCommonListTableView.class forCellReuseIdentifier:@"DDMyInfoCommonListTableView"];
[ToolsObject customResetTableView:_myTableView];
WeakSelf(weakSelf)
_myTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
weakSelf.pageNum = 1;
[weakSelf refreshListData];
}];
_myTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
weakSelf.pageNum ++ ;
[weakSelf refreshListData];
}];
}
return _myTableView;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view addSubview:self.myTableView];
[self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(self.view);
make.left.right.mas_equalTo(0);
}];
}
- (void)refreshListData{
NSMutableDictionary * requestDict = [NSMutableDictionary dictionary];
[requestDict setObject:[ToolsObject IsNullWithObject:self.searchStr]?@"":self.searchStr forKey:@"keywords"];
[requestDict setObject:@"user" forKey:@"type"];
[requestDict setObject:@(20) forKey:@"current_page"];
[requestDict setObject:@(self.pageNum) forKey:@"page_number"];
WeakSelf(weakSelf)
/// /home/search
NSString *url = [DDEncryptManager dd_aesDecryptWithText:@"9IiqdwQ2vgAWrRrCUnNGlA=="];
[NetworkRequest requestPOST:url parameters:requestDict block:^(BaseResponse * _Nonnull response) {
if (response.code == 200) {
if ([ToolsObject IsNullWithObject:response.data]) {
[weakSelf.myTableView.mj_header endRefreshing];
[weakSelf.myTableView.mj_footer endRefreshing];
return;
}
if (weakSelf.pageNum == 1) {
[weakSelf.listArr removeAllObjects];
}
[weakSelf.listArr addObjectsFromArray:[NSArray yy_modelArrayWithClass:DDFansFollowVisitModel.class json:response.data[@"record"][@"userList"][@"list"]]];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.myTableView.mj_header endRefreshing];
[weakSelf.myTableView.mj_footer endRefreshing];
[weakSelf.myTableView reloadData];
});
if ([response.data[@"next"]integerValue] == 0) {
[weakSelf.myTableView.mj_footer endRefreshingWithNoMoreData];
}
}
}];
}
- (void)setSearchStr:(NSString *)searchStr{
_searchStr = searchStr;
if (![ToolsObject IsNullWithObject:searchStr]){
self.pageNum = 1;
[self refreshListData];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.listArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *indentifiers = @"DDMyInfoCommonListTableView";
DDMyInfoCommonListTableView *cell = [tableView dequeueReusableCellWithIdentifier:indentifiers];
if (!cell) {
cell = [[DDMyInfoCommonListTableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifiers];
}
cell.rowIndex = indexPath;
cell.model = self.listArr[indexPath.row];
WeakSelf(weakSelf)
cell.didFollowBlock = ^(DDFansFollowVisitModel * _Nonnull fansModel, NSIndexPath * _Nonnull index) {
if (fansModel.is_attention) {
[weakSelf requestcancelFollow:fansModel withIndexPath:index];
}else{
[weakSelf requestAddFollow:fansModel withIndexPath:index];
}
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DDFansFollowVisitModel *model = self.listArr[indexPath.row];
[ToolsObject pushMyInformationViewController:model.id];
}
- (void)requestAddFollow:(DDFansFollowVisitModel *)userModel withIndexPath:(NSIndexPath *)index{
if ([ToolsObject IsNullWithObject:userModel.id]) {
[ToolsObject addPopVieToText:@"未获取到该用户信息,请刷新重试"];
return;
}
[ToolsObject ShowSVProgressHUD:@""];
NSMutableDictionary *parameter =@{@"followed_user_id":userModel.id}.mutableCopy;
WeakSelf(weakSelf)
__block DDFansFollowVisitModel * tempModel = userModel;
[NetworkRequest requestPOST:@"/dynamic/attention" parameters:parameter block:^(BaseResponse * _Nonnull response) {
if (response.code == 200) {
tempModel.is_attention = !tempModel.is_attention;
[ToolsObject addPopVieToText:@"关注成功"];
[weakSelf.listArr replaceObjectAtIndex:index.row withObject:tempModel];
[weakSelf.myTableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
}
}];
}
- (void)requestcancelFollow:(DDFansFollowVisitModel *)userModel withIndexPath:(NSIndexPath *)index{
if ([ToolsObject IsNullWithObject:userModel.id]) {
[ToolsObject addPopVieToText:@"未获取到该用户信息,请刷新重试"];
return;
}
[ToolsObject ShowSVProgressHUD:@""];
NSMutableDictionary *parameter =@{@"followed_user_id":userModel.id}.mutableCopy;
__block DDFansFollowVisitModel * tempModel = userModel;
WeakSelf(weakSelf)
[NetworkRequest requestPOST:@"/dynamic/cancel/attention" parameters:parameter block:^(BaseResponse * _Nonnull response) {
if (response.code == 200) {
tempModel.is_attention = !tempModel.is_attention;
[weakSelf.listArr replaceObjectAtIndex:index.row withObject:tempModel];
[weakSelf.myTableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
}
}];
}
@end