You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
187 lines
7.1 KiB
187 lines
7.1 KiB
// |
|
// MonitorViewController.m |
|
// watch |
|
// |
|
// Created by xTT on 2017/7/17. |
|
// Copyright © 2017年 xTT. All rights reserved. |
|
// |
|
|
|
#import "MonitorViewController.h" |
|
#import "EditMeViewController.h" |
|
|
|
@interface MonitorViewController () |
|
@property (strong, nonatomic) NSString *admin_contact; //管理员与设备的关系 |
|
@property (strong, nonatomic) NSString *admin_phone; //管理员的手机号码 |
|
@property (strong, nonatomic) UIButton *monitorBtn; //监听按钮 |
|
|
|
@end |
|
|
|
@implementation MonitorViewController |
|
|
|
@synthesize myDataSource = _myDataSource; |
|
|
|
- (NSMutableArray *)myDataSource{ |
|
if (!_myDataSource) { |
|
_myDataSource = [[NSMutableArray alloc] initWithArray:@[@[@"智能设备将回拨到"]]]; |
|
} |
|
return _myDataSource; |
|
} |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
|
|
} |
|
- (void)viewWillAppear:(BOOL)animated{ |
|
[super viewWillAppear:animated]; |
|
[self loadData]; |
|
} |
|
-(void)loadData{ |
|
WEAKSELF |
|
if(cUser.phone.length > 0){ |
|
[cUser.cDevice getAdminInfosuccess:^(id responseObject) { |
|
if(responseObject){ |
|
weakSelf.admin_contact = responseObject[@"admin_name"]; |
|
weakSelf.admin_phone = responseObject[@"admin_phone"]; |
|
cUser.cDevice.opMonitorPhone = weakSelf.admin_phone; |
|
[weakSelf.myTableView reloadData]; |
|
} |
|
} failure:^(id faiObject) { |
|
|
|
}]; |
|
} |
|
|
|
} |
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
|
NSString *title = self.myDataSource[indexPath.section][indexPath.row]; |
|
TextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TextFieldCell"]; |
|
if (!cell) { |
|
cell = [[TextFieldCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"TextFieldCell"]; |
|
cell.accessoryType = UITableViewCellAccessoryNone; |
|
|
|
} |
|
cell.textLabel.text = title; |
|
cell.textField.textColor = mainColor; |
|
cell.textField.textAlignment = NSTextAlignmentRight; // 2 |
|
cell.textField.userInteractionEnabled = NO; |
|
cell.textField.text = (self.admin_contact) ? self.admin_contact : @"" ; |
|
|
|
|
|
return cell; |
|
} |
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ |
|
if (section == self.myDataSource.count - 1) { |
|
return 50 + 44 + 15 + 88; |
|
} |
|
return [super tableView:tableView heightForFooterInSection:section]; |
|
} |
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ |
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; |
|
if (section == self.myDataSource.count - 1) { |
|
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(14, 50, |
|
SWIDTH-28, 44)]; |
|
[btn setTitle:@"监听设备" forState:UIControlStateNormal]; |
|
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
|
[btn setBackgroundColor:mainColor]; |
|
// if([cUser.cDevice.identity isEqualToString:@"admin"]){ |
|
// [btn setBackgroundColor:mainColor]; |
|
// }else{ |
|
// [btn setBackgroundColor:mainColor]; |
|
// btn.alpha = 0.5; |
|
// btn.enabled = NO; |
|
// } |
|
|
|
[btn addTarget:self action:@selector(monitorDevice:) forControlEvents:UIControlEventTouchUpInside]; |
|
btn.layer.cornerRadius = 3; |
|
btn.layer.masksToBounds = YES; |
|
|
|
[view addSubview:btn]; |
|
self.monitorBtn = btn; |
|
|
|
UILabel *lable1 = [[UILabel alloc] initWithFrame:CGRectMake(14, 50+44+15, |
|
SWIDTH-28, 88)]; |
|
lable1.text = @"温馨提示:使用监听设备时,设备会静默呼出电话到家长端,请保证电话号码有效且正确。"; |
|
lable1.numberOfLines = 0; |
|
lable1.font = [UIFont systemFontOfSize:13]; |
|
lable1.lineBreakMode = NSLineBreakByCharWrapping; |
|
lable1.textColor = [UIColor lightGrayColor]; |
|
[view addSubview:lable1]; |
|
} |
|
return view; |
|
} |
|
|
|
- (void)monitorDevice:(UIButton *)sender{ |
|
WEAKSELF |
|
//如果连用户的 phone 都没有就需要去 用户资料页面设置 |
|
if( cUser.phone == nil ||cUser.phone.length == 0){ |
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:@"未设置用户号码,是否设置?" style:LGAlertViewStyleAlert buttonTitles:@[@"设置"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { |
|
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; |
|
EditMeViewController * vc = [sb instantiateViewControllerWithIdentifier:@"EditMeViewController"]; |
|
[weakSelf.navigationController pushViewController:vc animated:YES]; |
|
|
|
|
|
} cancelHandler:nil destructiveHandler:nil]; |
|
[alertView showAnimated:YES completionHandler:nil]; |
|
return; |
|
} |
|
|
|
NSString *phone = @""; |
|
if(cUser.cDevice.opMonitorPhone){ |
|
phone = cUser.cDevice.opMonitorPhone; |
|
} |
|
|
|
[cUser.cDevice editOperationDeviceInfoWithParameters:@{@"opMonitor":@(YES), |
|
@"opMonitorPhone":phone} |
|
success:^(id responseObject) { |
|
// [UICommon MessageSuccessText:@"监听成功,请等待设备拨打监护人号码"]; |
|
// [UICommon HidenLoadingWithDelay:[SVProgressHUD displayDurationForString:@"监听成功,请等待设备拨打监护人号码"] |
|
// completion:^ |
|
// { |
|
// [weakSelf.navigationController popViewControllerAnimated:YES]; |
|
// }]; |
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:@"监听成功,请等待设备拨打监护人号码" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:nil destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { |
|
//设置按钮不可点击 |
|
[weakSelf setBtnBadRoGoodFlag:NO WithBtn:weakSelf.monitorBtn]; |
|
} cancelHandler:nil destructiveHandler:nil]; |
|
[alertView showAnimated:YES completionHandler:nil]; |
|
|
|
} failure:^(NSError *error) { |
|
|
|
}]; |
|
|
|
} |
|
|
|
/** |
|
设置按钮不可选且半透明 |
|
@param flag Bad is NO , Good is YES |
|
@param button button |
|
*/ |
|
-(void)setBtnBadRoGoodFlag:(BOOL)flag WithBtn:(UIButton*) button{ |
|
if(flag){ |
|
[button setAlpha:1]; |
|
[button setEnabled:YES]; |
|
}else{ |
|
[button setAlpha:0.5]; |
|
[button setEnabled:NO]; |
|
} |
|
} |
|
- (void)didReceiveMemoryWarning { |
|
[super didReceiveMemoryWarning]; |
|
// Dispose of any resources that can be recreated. |
|
} |
|
|
|
/* |
|
#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
|
|
|