FireAlarm_VC.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // FireAlarm_VC.m
  3. // Haishenghai-master
  4. //
  5. // Created by GG on 2019/1/4.
  6. // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
  7. //
  8. #import "FireAlarm_VC.h"
  9. #import "FireAlarmCell.h"
  10. @interface FireAlarm_VC ()<UITableViewDelegate,UITableViewDataSource>
  11. {
  12. NSInteger selectindexpath;
  13. }
  14. @property(nonatomic,strong)NSMutableArray *dataArray;
  15. @end
  16. @implementation FireAlarm_VC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.navigationItem.title = @"火警通知";
  20. self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
  21. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
  22. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  23. [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal];
  24. backBtn.frame = CGRectMake(0, 0, 44, 44);
  25. [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  26. backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  27. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
  28. _dataArray = [NSMutableArray array];
  29. [self setupUI];
  30. [self setupDownRefresh];
  31. }
  32. -(void)backClick{
  33. [self.navigationController popViewControllerAnimated:YES];
  34. }
  35. - (void)setupDownRefresh
  36. {
  37. // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
  38. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewDatas)];
  39. //马上进入刷新状态
  40. [self.tableView.mj_header beginRefreshing];
  41. }
  42. -(void)loadNewDatas{
  43. [self.dataArray removeAllObjects];
  44. //请求数据
  45. [DataSourceManager getFireAlarmURLWithPage:1 Pagesize:100 completionBlock:^(NSMutableArray *array) {
  46. _dataArray =array;
  47. [self.tableView reloadData];
  48. [self.tableView.mj_header endRefreshing];
  49. }];
  50. }
  51. -(void)setupRefresh{
  52. // self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadNewDatas)];
  53. // [self.tableView.mj_footer beginRefreshing];
  54. }
  55. -(void)setupUI{
  56. self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
  57. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
  58. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, HEIGHT) style:UITableViewStylePlain];
  59. // _tableView.backgroundColor = [UIColor grayColor];
  60. _tableView.delegate = self;
  61. _tableView.dataSource = self;
  62. _tableView.userInteractionEnabled = YES;
  63. _tableView.showsHorizontalScrollIndicator=NO;
  64. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  65. [self.view addSubview:_tableView];
  66. }
  67. #pragma mark-- tableviewDelegate
  68. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  69. return _dataArray.count;
  70. }
  71. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  72. return 150;
  73. }
  74. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  75. static NSString *cellId = @"cell";
  76. FireAlarmCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  77. if (!cell) {
  78. cell = [[FireAlarmCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
  79. }
  80. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  81. FireNoticeModel *model = [_dataArray objectAtIndex:indexPath.row];
  82. cell.model =model;
  83. cell.nameLabel.text = model.deviceName;
  84. cell.deployLabel.text =model.deployment;
  85. if ([model.troubleType isEqualToString:@"1"]) {
  86. cell.typeLabel.text = @"火警";
  87. }
  88. cell.numberLabel.text = model.deviceId;
  89. cell.locationLabel.text = model.location;
  90. cell.locationLabel.numberOfLines =0;
  91. cell.locationLabel.lineBreakMode = NSLineBreakByWordWrapping;
  92. cell.timeLabel.text = model.gmtCreate;
  93. cell.adressLabel.text = model.deviceLocation;
  94. //需要自定义
  95. cell.sureBtn.tag = indexPath.row;
  96. [cell.sureBtn addTarget:self action:@selector(onBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  97. return cell;
  98. }
  99. -(void)onBtnClick:(UIButton *)btn{
  100. FireNoticeModel *model = _dataArray[btn.tag];
  101. NSLog(@"------%@",model.ID);
  102. [DataSourceManager readFireAlarmWithUrlprocessID:model.ID completionBlock:^(NSDictionary *dic) {
  103. NSLog(@"%ld",btn.tag);
  104. if (btn.tag) {
  105. [btn removeFromSuperview];
  106. }
  107. }];
  108. }
  109. - (void)didReceiveMemoryWarning {
  110. [super didReceiveMemoryWarning];
  111. // Dispose of any resources that can be recreated.
  112. }
  113. /*
  114. #pragma mark - Navigation
  115. // In a storyboard-based application, you will often want to do a little preparation before navigation
  116. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  117. // Get the new view controller using [segue destinationViewController].
  118. // Pass the selected object to the new view controller.
  119. }
  120. */
  121. @end