单军华
2018-04-18 de88ae127e305e0b153c327b073645f9353cace5
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
//
//  MinePage.m
//  GoldRich
//
//  Created by WindShan on 2017/2/13.
//  Copyright © 2017年 WindShan. All rights reserved.
//
 
#import "MinePage.h"
#import "ChangePwdPage.h"
#import "cameraHelper.h"
#import "BaseNaviController.h"
#import "CommonReqModel.h"
#import "NetworkSingleton.h"
#import "MBProgressHUD+Add.h"
#import "LoginPage.h"
#import "GloriaLabel.h"
#import "XZPickView.h"
#import "MusicSetPage.h"
 
@interface MinePage ()<XZPickViewDelegate, XZPickViewDataSource>
{
    UISwitch *switchButton;
    GloriaLabel* _TitleLabel;
    GloriaLabel* _SulvLabel;
    GloriaLabel* _IsUpLoadLabel;
    GloriaLabel* _MusicLabel;
    UIImageView * icon_refresh;
    UIImageView * icon_data;
    UIImageView * icon_police;
}
 
@property(nonatomic,strong) UITableView * tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic,strong) XZPickView * pickView;
 
@property (nonatomic,copy) NSDictionary * dateDic;
@property (nonatomic,strong) NSString * is_open_upload;
@property (nonatomic,strong) NSString * weekStr;
@property (nonatomic, strong) NSDate *selectDate;
@property (nonatomic, assign) NSInteger currentSelectDay;
 
@end
 
@implementation MinePage
 
// 确定操作处理
-(void)pickView:(XZPickView *)pickerView confirmButtonClick:(UIButton *)button{
    
    NSInteger left = [pickerView selectedRowInComponent:0];
    self.selectDate = [self.dateDic[@"week"] objectAtIndex:left];
    self.weekStr = self.dateDic[@"week"][left];
    self.weekStr = [self.weekStr substringWithRange:NSMakeRange(0,[self.weekStr length]-1)];
    [self update_refresh_frequency];
}
 
-(void)update_refresh_frequency
{
    //[UserDefault stringForKey:@"user_id"]
    NSString *path = [[NSString alloc] initWithFormat:UPDATE_USERINFO];
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
    
    //['refresh_frequency', 'video', 'is_open_upload']
    [param setValue:[UserDefault stringForKey:@"user_id"] forKey:@"user_id"];
    [param setValue:@"refresh_frequency" forKey:@"field"];
    [param setValue:self.weekStr forKey:@"value"];
    
    MPWeakSelf(self);
    [NetworkSingleton networkingGetMethod:param urlName:path success:^(id responseBody)
     {
         MPStrongSelf(self);
         BaseResModel * resModel = [Global toBaseModel:responseBody];
         
         if(resModel.code == 0)
         {
             [UserDefault setObject:self.weekStr forKey:@"refresh_frequency"];
             [UserDefault synchronize];
             
             [self.tableView reloadData];
             [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
         }
         else
         {
             [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
         }
     }
                                  failure:^(NSString *error)
     {
         
         [Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
     }];
}
 
-(void)update_is_open_upload
{
    //[UserDefault stringForKey:@"user_id"]
    NSString *path = [[NSString alloc] initWithFormat:UPDATE_USERINFO];
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
    
    //['refresh_frequency', 'video', 'is_open_upload']
    [param setValue:[UserDefault stringForKey:@"user_id"] forKey:@"user_id"];
    [param setValue:@"is_open_upload" forKey:@"field"]; // 1 上传 0 不传
    [param setValue:self.is_open_upload forKey:@"value"];
    
    MPWeakSelf(self);
    [NetworkSingleton networkingGetMethod:param urlName:path success:^(id responseBody)
     {
         MPStrongSelf(self);
         BaseResModel * resModel = [Global toBaseModel:responseBody];
         
         if(resModel.code == 0)
         {
             [UserDefault setObject:self.is_open_upload forKey:@"is_open_upload"];
             [UserDefault synchronize];
             
             [self.tableView reloadData];
             [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
         }
         else
         {
             [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
         }
     }
                                  failure:^(NSString *error)
     {
         
         [Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
     }];
}
 
-(NSInteger)pickerView:(XZPickView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    
    //时间
    return [self.dateDic[@"week"] count];
}
 
-(void)pickerView:(XZPickView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.currentSelectDay = [pickerView selectedRowInComponent:0];
    //[pickerView pickReloadComponent:1];
    self.weekStr = self.dateDic[@"week"][row];
    
}
 
-(NSString *)pickerView:(XZPickView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.dateDic[@"week"][row];
}
 
-(NSInteger)numberOfComponentsInPickerView:(XZPickView *)pickerView{
    return  1;
}
 
#pragma mark -
 
 
- (NSDictionary *)LHGetStartTime
{
    NSMutableArray *weekStrArr = [NSMutableArray array];
    [weekStrArr addObject:@"10秒"];
    [weekStrArr addObject:@"20秒"];
    [weekStrArr addObject:@"30秒"];
    NSDictionary *resultDic = @{@"week" : weekStrArr};
    return resultDic;
}
 
 
#pragma mark - getter methods
 
-(XZPickView *)pickView
{
    if(!_pickView){
        _pickView = [[XZPickView alloc]initWithFrame:kScreenBounds title:@"请选择"];
        _pickView.delegate = self;
        _pickView.dataSource = self;
    }
    return _pickView;
}
 
 
- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] init];
        
        
        _tableView.delegate = self;
        _tableView.dataSource = self;
        //_tableView.separatorColor = [UIColor clearColor];
        
        [self.view addSubview:_tableView];
        
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsMake(0 , 0, 0, 0));
        }];
        
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}
 
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:YES];
    //self.navigationController.navigationBarHidden = NO;
}
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title =  @"设置";
    
    self.tableView.hidden = NO;
    
 
    
}
 
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 80;
}
 
 
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 80)];
    
    UIButton *quitLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quitLoginBtn.frame =CGRectMake((SCREEN_WIDTH-350)/2, 20, 350, 40);
    [quitLoginBtn.layer setMasksToBounds:YES];
    [quitLoginBtn.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
    [quitLoginBtn setBackgroundImage:[UIImage imageNamed:@"exit_btn" ] forState:UIControlStateNormal];
    [quitLoginBtn setTitle:@"退出当前账号" forState:UIControlStateNormal];
    quitLoginBtn.userInteractionEnabled = YES;
    [quitLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [quitLoginBtn addTarget:self action:@selector(exitLoginAction) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:quitLoginBtn];
    return view;
}
 
 
//此处上面和下面 是设置 footerview
 
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"PersonCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    
    NSUInteger index = [indexPath row];
    
    switch (index)
    {
        case 0:
        {
            if(icon_refresh==nil)
            {
                icon_refresh = [[UIImageView alloc] initWithFrame:CGRectMake(20, 22, 15, 15)];
                icon_refresh.image = [UIImage imageNamed:@"icon_refresh"];
                [cell.contentView addSubview:icon_refresh];
            }
            
            if(_TitleLabel == nil)
            {
                _TitleLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(50, 15,SCREEN_WIDTH/2, 30)];
                _TitleLabel.font = [UIFont systemFontOfSize:14];
                _TitleLabel.textAlignment = UITextAlignmentLeft;
                _TitleLabel.textColor = kUIColorFromRGB(0x595959);
                _TitleLabel.text = @"刷新率:";
                [cell.contentView addSubview:_TitleLabel];
            }
 
            
            if(_SulvLabel == nil)
            {
                _SulvLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60, 15,SCREEN_WIDTH/2, 30)];
                _SulvLabel.font = [UIFont systemFontOfSize:14];
                _SulvLabel.textAlignment = UITextAlignmentLeft;
                _SulvLabel.textColor = kUIColorFromRGB(0x595959);
                [cell.contentView addSubview:_SulvLabel];
            }
            
            
            _SulvLabel.text = [NSString stringWithFormat:@"%@秒",[UserDefault stringForKey:@"refresh_frequency"]];
        }
            break;
        case 1:
        {
            if(icon_data==nil)
            {
                icon_data = [[UIImageView alloc] initWithFrame:CGRectMake(20, 22, 15, 15)];
                icon_data.image = [UIImage imageNamed:@"icon_data"];
                [cell.contentView addSubview:icon_data];
            }
 
            
            if(_IsUpLoadLabel==nil)
            {
                _IsUpLoadLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(50, 15,SCREEN_WIDTH/2, 30)];
                _IsUpLoadLabel.font = [UIFont systemFontOfSize:14];
                _IsUpLoadLabel.textAlignment = UITextAlignmentLeft;
                _IsUpLoadLabel.textColor = kUIColorFromRGB(0x595959);
                _IsUpLoadLabel.text = @"是否上传数据";
                [cell.contentView addSubview:_IsUpLoadLabel];
            }
 
            if(switchButton == nil)
            {
                switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60, 15, 20, 10)];
                [switchButton setOn:[[UserDefault stringForKey:@"is_open_upload"] intValue] == 1? YES:NO];
                [switchButton addTarget:self action:@selector(switchAction) forControlEvents:UIControlEventValueChanged];
                [cell.contentView addSubview:switchButton];
            }
        }
 
            break;
        case 2:
        {
            if(icon_police==nil)
            {
                icon_police = [[UIImageView alloc] initWithFrame:CGRectMake(20, 22, 15, 15)];
                icon_police.image = [UIImage imageNamed:@"icon_police"];
                [cell.contentView addSubview:icon_police];
            }
            
            if(_MusicLabel==nil)
            {
                _MusicLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(50,15,SCREEN_WIDTH/2, 30)];
                _MusicLabel.font = [UIFont systemFontOfSize:14];
                _MusicLabel.textAlignment = UITextAlignmentLeft;
                _MusicLabel.textColor = kUIColorFromRGB(0x595959);
                _MusicLabel.text = @"报警铃音";
                [cell.contentView addSubview:_MusicLabel];
            }
 
            
            UIImageView * icon_line = [[UIImageView alloc] initWithFrame:CGRectMake(20, 59, SCREEN_WIDTH, 1)];
            icon_line.image = [UIImage imageNamed:@"icon_line"];
            [cell.contentView addSubview:icon_line];
            
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
 
            break;
    }
    return cell;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60.0;
}
 
 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 8.0;
}
 
 
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger index = [indexPath row];
    
    if(index == 0)
    {
        NSLog(@"%s",__func__);
        self.dateDic = [self LHGetStartTime];
        self.weekStr = self.dateDic[@"week"][0];
        [self.pickView reloadData];
        //[self.userNumPickView selectRow:0 inComponent:0 animated:NO];
        [[UIApplication sharedApplication].keyWindow addSubview:self.pickView];
        [self.pickView show];
    }
    else if(index == 2)
    {
 
        // 跳转酒店备用界面
        MusicSetPage* page = [[MusicSetPage alloc] initIsFirstPage:NO];
        // 跳转界面
        BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page];
        [self presentViewController:baseNav animated:YES completion:nil];
    }
}
 
- (void)switchAction
{
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn)
    {
        self.is_open_upload = @"1";
    }
    else
    {
        self.is_open_upload = @"0";
    }
    
    [self update_is_open_upload];
}
 
#pragma mark - custom function begin
 
 
-(void)exitLoginAction
{
    [UserDefault setObject:@"0" forKey:@"isLogin"];
    [UserDefault setObject:nil forKey:@"user_id"];
    
    _loginUser = nil;
    
    // 跳转设备列表信息界面
    LoginPage *page = [[LoginPage alloc] initIsFirstPage:NO];
    BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page];
    [self presentViewController:baseNav animated:YES completion:nil];
}
/*
#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