// // Message_VC.m // Haishenghai-master // // Created by GG on 2018/12/30. // Copyright © 2018年 Haishenghai intelligence network technology. All rights reserved. // #import "Message_VC.h" #import "MessageTableCell.h" #import "Header.h" @interface Message_VC () { NSString *messageID; NSString *location; NSString *siteName; NSString *D_location; NSString *deviceType; NSString *recheckTime; NSString *recheckId; NSString *ID; } @property(nonatomic,strong)NSMutableArray *dataArray; @end @implementation Message_VC -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; } ////传值 -(void)comitWithData:(NSNotification *)noti{ NSDictionary *dict = noti.userInfo; NSMutableArray *dataArray = [dict objectForKey:@"array"]; if (dataArray.count==0) { [_dataArray removeAllObjects]; [self.tableView reloadData]; return; }else{ [_dataArray removeAllObjects]; _dataArray = nil; _dataArray = dataArray; [self.tableView reloadData]; } } - (void)viewDidLoad { [super viewDidLoad]; // //接收回调来的条件筛选值 // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1]; [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}]; self.navigationItem.title =@"消息"; [self setupUI]; [DataSourceManager gettroubledeviceWithUrlPagesize:100 Page:1 formTime:@"" toTime:@"" completionBlock:^(NSMutableArray *array) { _dataArray =array; [_tableView reloadData]; }]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(comitWithData:) name:@"search" object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(refreshData) name:@"refreshData" object:nil]; //集成下拉刷新控件 [self setupDownRefresh]; } -(void)refreshData{ //集成下拉刷新控件 [self.tableView.mj_header beginRefreshing]; } /** * 集成下拉刷新控件 */ - (void)setupDownRefresh { // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法) self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewDatas)]; //马上进入刷新状态 [self.tableView.mj_header beginRefreshing]; } -(void)loadNewDatas{ _pageIndex =1;//默认加载第一页 self.dataArray = [NSMutableArray array]; //请求数据 [DataSourceManager gettroubledeviceWithUrlPagesize:100 Page:1 formTime:@"" toTime:@"" completionBlock:^(NSMutableArray *array) { _dataArray =array; [_tableView reloadData]; //结束刷新 [self.tableView.mj_header endRefreshing]; }]; } // 如果不想让其他页面的导航栏变为透明 需要重置 - (void)viewWillDisappear:(BOOL)animated{ [super viewWillAppear:animated]; } -(void)setupUI{ UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; rightButton.frame = CGRectMake(0, 0, 44, 44); [rightButton setImage:[UIImage imageNamed:@"hsh_news_search"] forState:UIControlStateNormal]; [rightButton addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton]; self.navigationItem.rightBarButtonItem = rightItem; _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain]; // _tableView.backgroundColor = [UIColor grayColor]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.userInteractionEnabled = YES; _tableView.showsHorizontalScrollIndicator=NO; [self.view addSubview:_tableView]; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; } #pragma mark-- tableviewDelegate -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _dataArray.count; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 159; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellId = @"cell"; MessageTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (!cell) { cell = [[MessageTableCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.layer.cornerRadius = 18; UIView *line = [[UIView alloc]init]; line.frame = CGRectMake(0, 150, WIDTH, 9); line.backgroundColor = [UIColor colorWithRed:227/255.0 green:227/255.0 blue:227/255.0 alpha:1]; [cell.contentView addSubview:line]; troubleDeveceModel *model = [self.dataArray objectAtIndex:indexPath.row]; // messageID = model.messageId; // location =model.location; // D_location = model.deviceLoation; // siteName = model.deployment; // deviceType = model.deviceName; // ID = model.ID; cell.nameLabel.text = model.deviceName; cell.numberLabel.text = model.deveceID; cell.locationLabel.text = model.deviceLoation; cell.detailLocationLabel.text = model.location; cell.detailLocationLabel.numberOfLines =0; cell.detailLocationLabel.lineBreakMode = NSLineBreakByWordWrapping; cell.placeLabel.text = model.deployment; //iOS开发服务器返回的时间戳变成时间 // NSString *timeStampString = [NSString stringWithFormat:@"%@",model.gmtCreate]; // // iOS 生成的时间戳是10位 // NSTimeInterval interval =[timeStampString doubleValue] / 1000.0; // NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval]; // // NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; // [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // NSString *dateString = [formatter stringFromDate: date]; cell.timelabel.text = model.gmtCreate; if ([model.troubleType isEqualToString:@"1"]) { cell.image.image = [UIImage imageNamed:@"hsh_home_alert"]; cell.stateLabel.text = @"火警"; cell.stateLabel.textColor = [UIColor redColor]; }else if ([model.troubleType isEqualToString:@"0"]){ cell.stateLabel.text = @"设备故障"; cell.stateLabel.textColor = [UIColor orangeColor]; cell.image.image = [UIImage imageNamed:@"hsh_home_fault"]; }else{ cell.stateLabel.textColor = [UIColor blueColor]; cell.stateLabel.text = @"火警恢复正常"; cell.image.image = [UIImage imageNamed:@"hsh_home_normal"]; } NSString *checkId = model.recheckId; if (checkId.length>4) { //hsh_news_audited [cell.checkButton setBackgroundImage:[UIImage imageNamed:@"hsh_news_audited"] forState:UIControlStateNormal]; }else{ [cell.checkButton setBackgroundImage:[UIImage imageNamed:@"hsh_news_unaudited"] forState:UIControlStateNormal]; } cell.checkButton.tag = indexPath.row; [cell.checkButton addTarget:self action:@selector(checkButton:) forControlEvents:UIControlEventTouchUpInside]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:NO]; } #pragma mark----Event -(void)searchClick{ CommitMessage_VC *commit = [[CommitMessage_VC alloc]init]; // commit.delegte = self; commit.navigationItem.title = @"消息"; commit.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:commit animated:YES]; } -(void)checkButton:(UIButton*)btn{ troubleDeveceModel *model = _dataArray[btn.tag]; Recorddetail_VC *record = [[Recorddetail_VC alloc]init]; record.msgID = model.messageId; record.loaction = model.location; record.D_loaction = model.deviceLoation; record.siteName = model.deployment; record.deviceType =model.deviceName; record.recheckTime = model.recheckTime; record.recheckId = model.recheckId; record.ID = model.ID; record.navigationItem.title = @"记录详情"; record.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:record animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end