Message_VC.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. //
  2. // Message_VC.m
  3. // Haishenghai-master
  4. //
  5. // Created by GG on 2018/12/30.
  6. // Copyright © 2018年 Haishenghai intelligence network technology. All rights reserved.
  7. //
  8. #import "Message_VC.h"
  9. #import "MessageTableCell.h"
  10. #import "Header.h"
  11. @interface Message_VC ()<UITableViewDataSource,UITableViewDelegate>
  12. {
  13. NSString *messageID;
  14. NSString *location;
  15. NSString *siteName;
  16. NSString *D_location;
  17. NSString *deviceType;
  18. NSString *recheckTime;
  19. NSString *recheckId;
  20. NSString *ID;
  21. }
  22. @property(nonatomic,strong)NSMutableArray *dataArray;
  23. @end
  24. @implementation Message_VC
  25. -(void)viewWillAppear:(BOOL)animated{
  26. [super viewWillAppear:animated];
  27. }
  28. ////传值
  29. -(void)comitWithData:(NSNotification *)noti{
  30. NSDictionary *dict = noti.userInfo;
  31. NSMutableArray *dataArray = [dict objectForKey:@"array"];
  32. if (dataArray.count==0) {
  33. [_dataArray removeAllObjects];
  34. [self.tableView reloadData];
  35. return;
  36. }else{
  37. [_dataArray removeAllObjects];
  38. _dataArray = nil;
  39. _dataArray = dataArray;
  40. [self.tableView reloadData];
  41. }
  42. }
  43. - (void)viewDidLoad {
  44. [super viewDidLoad];
  45. // //接收回调来的条件筛选值
  46. // Do any additional setup after loading the view.
  47. self.view.backgroundColor = [UIColor whiteColor];
  48. self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
  49. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
  50. self.navigationItem.title =@"消息";
  51. [self setupUI];
  52. [DataSourceManager gettroubledeviceWithUrlPagesize:100 Page:1 formTime:@"" toTime:@"" completionBlock:^(NSMutableArray *array) {
  53. _dataArray =array;
  54. [_tableView reloadData];
  55. }];
  56. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(comitWithData:) name:@"search" object:nil];
  57. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(refreshData) name:@"refreshData" object:nil];
  58. //集成下拉刷新控件
  59. [self setupDownRefresh];
  60. }
  61. -(void)refreshData{
  62. //集成下拉刷新控件
  63. [self.tableView.mj_header beginRefreshing];
  64. }
  65. /**
  66. * 集成下拉刷新控件
  67. */
  68. - (void)setupDownRefresh
  69. {
  70. // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
  71. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewDatas)];
  72. //马上进入刷新状态
  73. [self.tableView.mj_header beginRefreshing];
  74. }
  75. -(void)loadNewDatas{
  76. _pageIndex =1;//默认加载第一页
  77. self.dataArray = [NSMutableArray array];
  78. //请求数据
  79. [DataSourceManager gettroubledeviceWithUrlPagesize:100 Page:1 formTime:@"" toTime:@"" completionBlock:^(NSMutableArray *array) {
  80. _dataArray =array;
  81. [_tableView reloadData];
  82. //结束刷新
  83. [self.tableView.mj_header endRefreshing];
  84. }];
  85. }
  86. // 如果不想让其他页面的导航栏变为透明 需要重置
  87. - (void)viewWillDisappear:(BOOL)animated{
  88. [super viewWillAppear:animated];
  89. }
  90. -(void)setupUI{
  91. UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
  92. rightButton.frame = CGRectMake(0, 0, 44, 44);
  93. [rightButton setImage:[UIImage imageNamed:@"hsh_news_search"] forState:UIControlStateNormal];
  94. [rightButton addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
  95. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
  96. self.navigationItem.rightBarButtonItem = rightItem;
  97. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
  98. // _tableView.backgroundColor = [UIColor grayColor];
  99. _tableView.delegate = self;
  100. _tableView.dataSource = self;
  101. _tableView.userInteractionEnabled = YES;
  102. _tableView.showsHorizontalScrollIndicator=NO;
  103. [self.view addSubview:_tableView];
  104. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  105. }
  106. #pragma mark-- tableviewDelegate
  107. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  108. return _dataArray.count;
  109. }
  110. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  111. return 159;
  112. }
  113. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  114. static NSString *cellId = @"cell";
  115. MessageTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  116. if (!cell) {
  117. cell = [[MessageTableCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
  118. }
  119. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  120. cell.layer.cornerRadius = 18;
  121. UIView *line = [[UIView alloc]init];
  122. line.frame = CGRectMake(0, 150, WIDTH, 9);
  123. line.backgroundColor = [UIColor colorWithRed:227/255.0 green:227/255.0 blue:227/255.0 alpha:1];
  124. [cell.contentView addSubview:line];
  125. troubleDeveceModel *model = [self.dataArray objectAtIndex:indexPath.row];
  126. // messageID = model.messageId;
  127. // location =model.location;
  128. // D_location = model.deviceLoation;
  129. // siteName = model.deployment;
  130. // deviceType = model.deviceName;
  131. // ID = model.ID;
  132. cell.nameLabel.text = model.deviceName;
  133. cell.numberLabel.text = model.deveceID;
  134. cell.locationLabel.text = model.deviceLoation;
  135. cell.detailLocationLabel.text = model.location;
  136. cell.detailLocationLabel.numberOfLines =0;
  137. cell.detailLocationLabel.lineBreakMode = NSLineBreakByWordWrapping;
  138. cell.placeLabel.text = model.deployment;
  139. //iOS开发服务器返回的时间戳变成时间
  140. // NSString *timeStampString = [NSString stringWithFormat:@"%@",model.gmtCreate];
  141. // // iOS 生成的时间戳是10位
  142. // NSTimeInterval interval =[timeStampString doubleValue] / 1000.0;
  143. // NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
  144. //
  145. // NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  146. // [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  147. // NSString *dateString = [formatter stringFromDate: date];
  148. cell.timelabel.text = model.gmtCreate;
  149. if ([model.troubleType isEqualToString:@"1"]) {
  150. cell.image.image = [UIImage imageNamed:@"hsh_home_alert"];
  151. cell.stateLabel.text = @"火警";
  152. cell.stateLabel.textColor = [UIColor redColor];
  153. }else if ([model.troubleType isEqualToString:@"0"]){
  154. cell.stateLabel.text = @"设备故障";
  155. cell.stateLabel.textColor = [UIColor orangeColor];
  156. cell.image.image = [UIImage imageNamed:@"hsh_home_fault"];
  157. }else{
  158. cell.stateLabel.textColor = [UIColor blueColor];
  159. cell.stateLabel.text = @"火警恢复正常";
  160. cell.image.image = [UIImage imageNamed:@"hsh_home_normal"];
  161. }
  162. NSString *checkId = model.recheckId;
  163. if (checkId.length>4) {
  164. //hsh_news_audited
  165. [cell.checkButton setBackgroundImage:[UIImage imageNamed:@"hsh_news_audited"] forState:UIControlStateNormal];
  166. }else{
  167. [cell.checkButton setBackgroundImage:[UIImage imageNamed:@"hsh_news_unaudited"] forState:UIControlStateNormal];
  168. }
  169. cell.checkButton.tag = indexPath.row;
  170. [cell.checkButton addTarget:self action:@selector(checkButton:) forControlEvents:UIControlEventTouchUpInside];
  171. return cell;
  172. }
  173. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  174. [tableView deselectRowAtIndexPath:indexPath animated:NO];
  175. }
  176. #pragma mark----Event
  177. -(void)searchClick{
  178. CommitMessage_VC *commit = [[CommitMessage_VC alloc]init];
  179. // commit.delegte = self;
  180. commit.navigationItem.title = @"消息";
  181. commit.hidesBottomBarWhenPushed = YES;
  182. [self.navigationController pushViewController:commit animated:YES];
  183. }
  184. -(void)checkButton:(UIButton*)btn{
  185. troubleDeveceModel *model = _dataArray[btn.tag];
  186. Recorddetail_VC *record = [[Recorddetail_VC alloc]init];
  187. record.msgID = model.messageId;
  188. record.loaction = model.location;
  189. record.D_loaction = model.deviceLoation;
  190. record.siteName = model.deployment;
  191. record.deviceType =model.deviceName;
  192. record.recheckTime = model.recheckTime;
  193. record.recheckId = model.recheckId;
  194. record.ID = model.ID;
  195. record.navigationItem.title = @"记录详情";
  196. record.hidesBottomBarWhenPushed = YES;
  197. [self.navigationController pushViewController:record animated:YES];
  198. }
  199. - (void)didReceiveMemoryWarning {
  200. [super didReceiveMemoryWarning];
  201. // Dispose of any resources that can be recreated.
  202. }
  203. /*
  204. #pragma mark - Navigation
  205. // In a storyboard-based application, you will often want to do a little preparation before navigation
  206. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  207. // Get the new view controller using [segue destinationViewController].
  208. // Pass the selected object to the new view controller.
  209. }
  210. */
  211. @end