//
|
// 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
|