//
|
// DetailDataViewController.m
|
// screendisplay
|
//
|
// Created by 单军华 on 2018/7/5.
|
// Copyright © 2018年 单军华. All rights reserved.
|
//
|
|
#import "DetailDataViewController.h"
|
#import "DetailService.h"
|
#import "CommonReqModel.h"
|
#import "DetailItemCell.h"
|
#import "DynamicViewController.h"
|
|
@interface DetailDataViewController ()<UITableViewDelegate,UITableViewDataSource>
|
{
|
NSTimer * myTimer; // 更新设备状态
|
}
|
|
@property(nonatomic,strong) UITableView * tableView;
|
|
/** <#digest#> */
|
@property (nonatomic, strong) DetailService *detailService;
|
|
@end
|
|
@implementation DetailDataViewController
|
|
#pragma mark - getter
|
|
- (DetailService *)detailService
|
{
|
if(_detailService == nil)
|
{
|
_detailService = [[DetailService alloc] init];
|
}
|
return _detailService;
|
}
|
|
- (UITableView *)tableView
|
{
|
if (!_tableView)
|
{
|
_tableView = [[UITableView alloc] init];
|
|
|
_tableView.delegate = self;
|
_tableView.dataSource = self;
|
_tableView.frame = CGRectMake((SCREEN_WIDTH-AdaptedWidth(340))/2, NavBar_Height+AdaptedHeight(13), AdaptedWidth(350), AdaptedHeight(570));
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
_tableView.backgroundColor = [UIColor clearColor];
|
[self.view addSubview:_tableView];
|
|
UIImageView * viewBackground = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(355))/2, NavBar_Height+AdaptedHeight(13), AdaptedWidth(355), AdaptedHeight(574))];
|
viewBackground.image = [UIImage imageNamed:@"detail_back"];
|
_tableView.backgroundView = viewBackground;
|
|
// [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
// make.edges.mas_equalTo(UIEdgeInsetsMake((SCREEN_WIDTH-AdaptedWidth(355))/2 , AdaptedHeight(13), AdaptedHeight(13),(SCREEN_WIDTH-AdaptedWidth(355))/2));
|
// }];
|
|
_tableView.tableFooterView = [UIView new];
|
}
|
return _tableView;
|
}
|
|
#pragma mark - UITableViewDataSource UITableViewDelegate
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
{
|
return 1;
|
}
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
{
|
return self.detailService.detailViewModels.count;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
return AdaptedHeight(42.0);
|
}
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
DetailItemCell *topicCell = [DetailItemCell topicCellWithTableView:tableView];
|
topicCell.detailViewModel = self.detailService.detailViewModels[indexPath.row];
|
return topicCell;
|
}
|
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
NSInteger index = [indexPath row];
|
|
// 0 正常 1 一级警报 2 二级警报 3 三级警报 4 维保
|
if([self.deviceModel.state intValue] == 4)
|
{
|
[Global alertMessageEx:@"该设备维保中,不能获取实时数据!" title:@"系统提示" okTtitle:nil cancelTitle:@"确定" delegate:self];
|
}
|
else
|
{
|
DynamicViewController * page = [[DynamicViewController alloc] init];
|
page.detailModel = [self.detailService.detailViewModels objectAtIndex:index];
|
[self.navigationController pushViewController:page animated:YES];
|
}
|
|
NSLog(@"click didSelectRowAtIndexPath");
|
}
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
// Do any additional setup after loading the view.
|
|
[self initView];
|
|
[self getDetailList];
|
|
//每1秒运行一次function方法。
|
myTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(updateDynamicData) userInfo:nil repeats:YES];
|
|
}
|
|
-(void)viewWillAppear:(BOOL)animated
|
{
|
[super viewWillAppear:YES];
|
|
self.navigationController.navigationBarHidden = YES;
|
|
if (myTimer == nil)
|
myTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(updateDynamicData) userInfo:nil repeats:YES];
|
else
|
//开启定时器
|
[myTimer setFireDate:[NSDate distantPast]];
|
}
|
|
-(void)viewDidDisappear:(BOOL)animated
|
{
|
[super viewDidDisappear:YES];
|
|
//关闭定时器
|
if(myTimer)
|
[myTimer setFireDate:[NSDate distantFuture]];
|
}
|
|
-(void) initView
|
{
|
// 禁用右滑返回
|
//self.fd_interactivePopDisabled = YES;
|
|
self.view.backgroundColor = kUIColorFromRGB(0x0b2f76);
|
|
|
}
|
|
|
|
- (void)didReceiveMemoryWarning {
|
[super didReceiveMemoryWarning];
|
// Dispose of any resources that can be recreated.
|
}
|
|
|
#pragma mark custom function
|
-(void)updateDynamicData
|
{
|
[self getDetailList];
|
}
|
|
-(void)getDetailList
|
{
|
NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
|
[param setObject:self.deviceModel.deviceVersionId forKey:@"deviceVersionId"];
|
[param setObject:self.deviceModel.mac forKey:@"mac"];
|
[param setObject:self.deviceModel.id forKey:@"deviceId"];
|
|
TWWeak(self);
|
[self.detailService getDetailListWithParameters:param completion:^(NSString *desc, int code) {
|
if(code == 1)
|
{
|
weakself.tableView.hidden = NO;
|
[weakself.tableView reloadData];
|
}
|
else
|
{
|
[Global alertMessageEx:desc title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
}];
|
}
|
|
/*
|
#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.
|
}
|
*/
|
|
#pragma mark - LMJNavUIBaseViewControllerDataSource
|
|
- (UIStatusBarStyle)navUIBaseViewControllerPreferStatusBarStyle:(LMJNavUIBaseViewController *)navUIBaseViewController
|
{
|
return UIStatusBarStyleDefault;
|
}
|
|
/**头部标题*/
|
- (NSMutableAttributedString*)lmjNavigationBarTitle:(LMJNavigationBar *)navigationBar
|
{
|
return [self changeTitle:@"详细数据" changeColor:[UIColor whiteColor]];
|
}
|
|
//背景图片
|
//- (UIImage *)lmjNavigationBarBackgroundImage:(LMJNavigationBar *)navigationBar
|
//{
|
// return [UIImage imageNamed:@"map_top_bar_bk"];
|
//}
|
|
/** 背景色 */
|
- (UIColor *)lmjNavigationBackgroundColor:(LMJNavigationBar *)navigationBar
|
{
|
return kUIColorFromRGB(0x0b2f76);
|
}
|
|
/** 是否隐藏底部黑线 */
|
- (BOOL)lmjNavigationIsHideBottomLine:(LMJNavigationBar *)navigationBar
|
{
|
return YES;
|
}
|
|
/** 导航条左边的按钮 */
|
- (UIImage *)lmjNavigationBarLeftButtonImage:(UIButton *)leftButton navigationBar:(LMJNavigationBar *)navigationBar
|
{
|
return [UIImage imageNamed:@"map_back"];
|
}
|
/** 导航条右边的按钮 */
|
- (UIImage *)lmjNavigationBarRightButtonImage:(UIButton *)rightButton navigationBar:(LMJNavigationBar *)navigationBar
|
{
|
//return [UIImage imageNamed:@"map_back"];
|
|
// [rightButton setTitle:@"立即注册" forState: UIControlStateNormal];
|
// [rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
// [rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
|
// rightButton.titleLabel.font = [UIFont systemFontOfSize:15];
|
//
|
// rightButton.lmj_width = 80;
|
|
return nil;
|
}
|
|
#pragma mark - LMJNavUIBaseViewControllerDelegate
|
/** 左边的按钮的点击 */
|
-(void)leftButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar
|
{
|
[self.navigationController popViewControllerAnimated:YES];
|
//[self dismissViewControllerAnimated:YES completion:nil];
|
}
|
|
|
/** 右边的按钮的点击 */
|
-(void)rightButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar
|
{
|
|
}
|
|
|
|
@end
|