Files
yinmeng-ios-store/yinmeng-ios/DingDangApp/CodeClass/MyInfo/CC/DDMyInfoCommonListViewController.m
2023-12-13 10:48:56 +08:00

233 lines
9.0 KiB
Objective-C

//
// DDMyInfoCommonListViewController.m
// DingDangApp
//
// Created by apple on 2023/5/30.
//
#import "DDMyInfoCommonListViewController.h"
#import "Api+DDMineApi.h"
#import "DDMyInfoCommonListTableView.h"
@interface DDMyInfoCommonListViewController ()
@end
@implementation DDMyInfoCommonListViewController
-(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 initRequest];
}];
_myTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
weakSelf.pageNum ++ ;
[weakSelf refreshListData:weakSelf.listStyle];
}];
}
return _myTableView;
}
-(NSMutableArray *)listArr
{
if (!_listArr) {
_listArr = [NSMutableArray array];
}
return _listArr;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString * titleString = @"";
if (self.listStyle ==DDMyInfoCommonListStyleFans){
titleString = @"粉丝";
}else if (self.listStyle ==DDMyInfoCommonListStyleFollow){
titleString = @"关注";
}else if (self.listStyle ==DDMyInfoCommonListStyleVisitor){
titleString = @"访客";
}else{
titleString = @"";
}
[self defaultNavTitle:titleString hideLine:YES];
self.view.backgroundColor = UIColor.whiteColor;
[self.view addSubview:self.myTableView];
[self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(DDNavigationBarHeight());
make.left.right.mas_equalTo(0);
make.bottom.mas_equalTo(-DDBottomHeight());
}];
[self initRequest];
}
-(void)initRequest
{
self.pageNum = 1;
[self refreshListData:self.listStyle];
}
- (void)refreshListData:(DDMyInfoCommonListStyle)listStyle {
WeakSelf(weakSelf)
[Api getVisitorListCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
[weakSelf.myTableView.mj_header endRefreshing];
[weakSelf.myTableView.mj_footer endRefreshing];
if(code == 200){
if (weakSelf.pageNum == 1) {
[weakSelf.listArr removeAllObjects];
}
NSArray *list = [DDFansFollowVisitModel DD_ModelsWithArray:data.data];
[weakSelf.listArr addObjectsFromArray:list];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.myTableView.mj_header endRefreshing];
[weakSelf.myTableView.mj_footer endRefreshing];
[weakSelf.myTableView reloadData];
});
}
} pageNum:@(self.pageNum).stringValue pageSize:@"20"];
return;
NSString * urlString = @"";
if (listStyle ==DDMyInfoCommonListStyleFans){
urlString = @"/my/fans/list";
}else if (listStyle ==DDMyInfoCommonListStyleFollow){
urlString = @"/my/attention/list";
}else if (listStyle ==DDMyInfoCommonListStyleVisitor){
urlString = @"/my/visitor/list";
}else{
return;
}
NSMutableDictionary *requestDict = [NSMutableDictionary dictionary];
[requestDict setObject:@(20) forKey:@"current_page"];
[requestDict setObject:@(self.pageNum) forKey:@"page_number"];
[NetworkRequest requestPOST:urlString 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"]]];
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];
}
}
}];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 10;
}
-(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 88;
}
-(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) {
NSString * uid = [[AccountInfoStorage instance] getUid];
NSString * ticket = [[AccountInfoStorage instance] getTicket];
NSString * type = @"1";
[Api attentionCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if(code == 200){
[ToolsObject addPopVieToText:@"关注成功"];
return;
}
[ToolsObject addPopVieToText:@"关注失败"];
} uid:uid likedUid:fansModel.uid ticket:ticket type:type];
};
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) {
[ToolsObject DismissSVProgressHUD];
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) {
[ToolsObject DismissSVProgressHUD];
if (response.code == 200) {
tempModel.is_attention = !tempModel.is_attention;
[weakSelf.listArr replaceObjectAtIndex:index.row withObject:tempModel];
[weakSelf.myTableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
}
}];
}
@end