单军华
2018-07-19 83b9d5c682b21d88133f24da0f94dd56bd79e687
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
//
//  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