// // IfishMessageViewController.m // ifishTabTest // // Created by imac on 16/7/25. // Copyright © 2016年 xiang. All rights reserved. // #import "IfishMessageViewController.h" #import "AFNetworking.h" #import "IfishMessageViewCell.h" //#import "IfishDatabaseManager.h" //#import "JHRefresh.h" #import "IfishNomassageView.h" //#import "PushMasssageWebViewController.h" //#import "ShareReportViewController.h" //#import "KanHuBaoGaoModel.h" //#import "PingfenModel.h" #import "AFNOHeaderHttpTool.h" #import "MessageAlertView.h" #import "SVProgressHUD.h" #import "IfishUserAsset.h" #import "YYCache.h" @interface IfishMessageViewController () { BOOL _isRefreshing; BOOL _isLoadMore; } @property(nonatomic,copy) NSString *pushId; @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,strong) NSMutableArray *messageArray;//新消息 @property(nonatomic,strong) NSMutableArray *oldMessageArr;//旧消息 @property(nonatomic,strong) NSMutableArray *dataSource;//数据源 @property(nonatomic)BOOL isRefreshing; @property(nonatomic)BOOL isLoadMore; @property(nonatomic,strong) IfishNomassageView *nomassagView; @property(nonatomic,copy) NSString* total; @property(nonatomic) int page; Copy NSString *lastPushId;//最近一次推送的Id @property(nonatomic,strong)NSDictionary*para; Strong NSMutableArray *deleteArray;//将要删除字符串的id集合 Assign BOOL isDelteAll;//是否全选删除 Assign BOOL isShowDelete;//是否显示删除按钮 Strong MessageAlertView *comboxView; Strong UIView *deleteView; Strong UIButton *deleteBtn; Strong UIAlertController *alertController; Strong UIAlertAction *okAction; Strong UIAlertAction *cancelAction; @end extern BOOL launchedByNotification; @implementation IfishMessageViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.isShowDelete = NO; self.isDelteAll = NO; self.titleString = @"消息"; [self.rightButton setImage:IMAGEBYENAME(@"message_more") forState:UIControlStateNormal]; [self.rightButton addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:self.tableView]; [self.view addSubview:self.comboxView]; [self.comboxView loadInfoWithTitle:@[@"删除"] Icons:@[@"ifishdropview_delect_device"]]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self.view); }]; [self.view addSubview:self.deleteView]; [self getRequest]; } -(NSMutableArray *)dataSource { if (!_dataSource) { _dataSource = [[NSMutableArray alloc]init]; } return _dataSource; } -(NSMutableArray *)messageArray { if (!_messageArray) { _messageArray = [[NSMutableArray alloc]init]; } return _messageArray; } -(NSMutableArray *)oldMessageArr { if (!_oldMessageArr) { _oldMessageArr = [[NSMutableArray alloc]init]; } return _oldMessageArr; } -(NSMutableArray *)deleteArray { if (!_deleteArray) { _deleteArray = [[NSMutableArray alloc]init]; } return _deleteArray; } -(UITableView*)tableView{ if (!_tableView) { _tableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped]; _tableView.dataSource=self; _tableView.delegate=self; _tableView.showsVerticalScrollIndicator=NO; _tableView.backgroundColor = TABLE_BACKGROUD_COLOR; } return _tableView; } -(MessageAlertView *)comboxView{ if (!_comboxView) { _comboxView = [[MessageAlertView alloc]initWithFrame:RECT(screen_width - kSizeFrom750(220), 0, kSizeFrom750(220), kSizeFrom750(90))]; WEAK_SELF; //点击删除 _comboxView.comboxBlock = ^(NSInteger tag) { [weakSelf showComboxView:NO]; weakSelf.isShowDelete = YES; [weakSelf.deleteView setHidden:NO]; [weakSelf.tableView mas_updateConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(-kSizeFrom750(100)); }]; //刷新页面,显示删除按钮 [weakSelf.tableView reloadData]; }; } return _comboxView; } -(UIView *)deleteView{ if (!_deleteView) { _deleteView = [[UIView alloc]initWithFrame:RECT(0, screen_height - NavigationBarHeight - kSizeFrom750(100), screen_width, kSizeFrom750(100))]; _deleteView.backgroundColor = [UIColor whiteColor]; _deleteView.hidden = YES; [self loadDelteSubViews]; } return _deleteView; } -(void)loadDelteSubViews{ self.deleteBtn = InitObject(UIButton); [self.deleteBtn setTitle:@"删除" forState:UIControlStateNormal]; [self.deleteBtn.titleLabel setFont:SYSTEMSIZE(34)]; [self.deleteBtn setTitleColor:RGB(178, 178, 178) forState:UIControlStateNormal]; [self.deleteBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; [self.deleteBtn addTarget:self action:@selector(deleBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.deleteView addSubview:self.deleteBtn]; UIButton *allDeleteBtn = InitObject(UIButton); [allDeleteBtn setTitle:@"全选" forState:UIControlStateNormal]; [allDeleteBtn setTitle:@"取消" forState:UIControlStateSelected]; [allDeleteBtn.titleLabel setFont:SYSTEMSIZE(34)]; [allDeleteBtn setTitleColor:RGB(4, 99, 201) forState:UIControlStateNormal]; [allDeleteBtn addTarget:self action:@selector(allDeleteBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.deleteView addSubview:allDeleteBtn]; [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.deleteView); make.left.mas_equalTo(0); make.width.mas_equalTo(screen_width/2); make.top.height.mas_equalTo(self.deleteView); }]; [allDeleteBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.width.height.mas_equalTo(self.deleteBtn); make.left.mas_equalTo(self.deleteBtn.mas_right); }]; UIView *line = [[UIView alloc]init]; line.backgroundColor = RGB(178, 178, 178); [_deleteView addSubview:line]; [line mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.deleteView); make.left.mas_equalTo(kSizeFrom750(30)); make.right.mas_equalTo(-kSizeFrom750(30)); make.height.mas_equalTo(ONE_PIXEL_SIZE); }]; } #pragma mark --buttonClick -(void)deleBtnClick:(UIButton *)sender{ if (self.deleteArray.count==0) { [SVProgressHUD showInfoWithStatus:@"请先选择要删除的消息"]; }else{ //调用删除接口,删除选中的消息内容 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确认删除所有选中消息么" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { NSLog(@"cancel Action"); }]; UIAlertAction *delteActicon = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"delete Action"); [self deleteMessage]; }]; [alertController addAction:cancelAction]; [alertController addAction:delteActicon]; [self presentViewController:alertController animated:YES completion:nil]; } } -(void)allDeleteBtnClick:(UIButton *)sender{ if (!sender.selected) {//全选 //全部为选中状态 self.isDelteAll = YES; self.deleteBtn.selected = YES; [self.deleteArray removeAllObjects]; for (NSArray *arr in self.dataSource) { for (PushmessageModel *model in arr) { [self.deleteArray addObject:model.pushId]; } } }else{//取消全选 [self.deleteArray removeAllObjects]; self.isDelteAll = NO; self.deleteBtn.selected = NO; } sender.selected = !sender.selected; [self.tableView reloadData]; } #pragma mark --comboxView显示与隐藏 -(void)rightBtnClick:(UIButton *)sender{ BOOL isHidden = self.comboxView.hidden; if (isHidden) { self.comboxView.hidden = NO; } [UIView animateWithDuration:0.3 animations:^{ self.comboxView.transform = CGAffineTransformScale(self.comboxView.transform,isHidden?100:0.01,isHidden?100:0.01); } completion:^(BOOL finished) { self.comboxView.hidden = !isHidden; }]; } -(void)showComboxView:(BOOL)isShow{ BOOL isHidden = self.comboxView.hidden; if (isHidden) { self.comboxView.hidden = NO; } [UIView animateWithDuration:0.3 animations:^{ self.comboxView.transform = CGAffineTransformScale(self.comboxView.transform,isHidden?100:0.01,isHidden?100:0.01); } completion:^(BOOL finished) { self.comboxView.hidden = !isHidden; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - Table view data source -(void)getRequest { [SVProgressHUD show]; self.pushId = @""; UserModel*userModel=[dataContorl getUserInfo]; NSDictionary *params = @{@"pushId":self.pushId, @"userId":userModel.userId, @"firstResult":@(0), @"pageSize":@(999) }; [AFNOHeaderHttpTool requestWihtMethod:RequestTypePost url:Push_Message_Url params:params success:^(id response) { [SVProgressHUD dismiss]; if (response) { id resault=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSString *totalCount = [resault objectForKey:@"total"]; NSArray *dataArray = [resault objectForKey:@"data"]; if ([totalCount integerValue]>0) { NSMutableArray *newMessageArray = InitObject(NSMutableArray); NSMutableArray *oldMessageArray = InitObject(NSMutableArray); for (int i=0; i0) { self.deleteBtn.selected = YES; }else self.deleteBtn.selected = NO; }; return cell; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (section==1) { UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screen_width, kSizeFrom750(90))]; header.backgroundColor = [UIColor whiteColor]; UILabel *headerLabel = [[UILabel alloc]init]; headerLabel.frame = CGRectMake(0, kSizeFrom750(30), screen_width, kSizeFrom750(30)); headerLabel.textColor = RGB(178, 178, 178); headerLabel.textAlignment = NSTextAlignmentCenter; headerLabel.text = @"···············以上为最新消息···············"; headerLabel.font = SYSTEMSIZE(30); [header addSubview:headerLabel]; return header; }else return nil; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section==1) { return kSizeFrom750(90); }else return 0; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return nil; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (self.dataSource.count!=0) { PushmessageModel *model = [[self.dataSource objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; return model.cellHeight; } return 0; } // -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ dispatch_async(dispatch_get_main_queue(), ^{ //默认消息已读 // [self postReadMessageRequestWithIndexPath:indexPath]; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确认删除该消息么" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { NSLog(@"cancel Action"); }]; WEAK_SELF; UIAlertAction *delteActicon = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [weakSelf deleteSingleMessageWithIndex:indexPath]; }]; [alertController addAction:cancelAction]; [alertController addAction:delteActicon]; [weakSelf presentViewController:alertController animated:YES completion:nil]; }); } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; } @end