// // DeviceListMgrPage.m // istanbul // // Created by WindShan on 2017/5/17. // Copyright © 2017年 WindShan. All rights reserved. // #import "DeviceListMgrPage.h" #import "JSDropDownMenu.h" #import "MyDeviceStatusView.h" #import "HBdansView.h" #import "CommonReqModel.h" #import "NetworkSingleton.h" #import "HotelSelModel.h" #import "NoticeModel.h" #import "AdvertisePage.h" #import "BaseNaviController.h" #import "JXTAlertManagerHeader.h" #import "UserSignPage.h" #import "ChangeDevicePage.h" #import "AddDevicePage.h" @interface DeviceListMgrPage () { UIButton * sign_btn; UITextField * searchEdit; NSMutableArray *_data2; NSMutableArray *_data3; NSInteger _currentData2Index; NSInteger _currentData3Index; HBdansView *_dansView; JSDropDownMenu *menu; } @property (nonatomic, strong) MyDeviceStatusView * myFileViewList; @property (nonatomic, assign) int roleType; // 1 酒店人员 2 维保人员 @end @implementation DeviceListMgrPage -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; HotelSelModel * hotelSelModel = [_data2 objectAtIndex:_currentData2Index]; self.myFileViewList.hotel_id = hotelSelModel._id; [self.myFileViewList reSetView: [UserDefault stringForKey:@"user_id"] devicetype: [NSString stringWithFormat:@"%ld",_currentData3Index] searchkey:searchEdit.text]; } -(void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:YES]; //self.navigationController.navigationBarHidden = NO; } - (void)viewDidLoad { [super viewDidLoad]; [self setNavigationRight:@"签到" sel:@selector(signAction)]; // Do any additional setup after loading the view. CGFloat bkWith = 285; CGFloat labaBLW = 351; if( IsiPhone4 || IsiPhone5 ) { bkWith = 250; labaBLW = 300; } self.roleType = [_loginUser[@"opt"] intValue]; if( self.roleType == 1 ) { [self setNavigationLeft:@"add_device_btn.png" sel:@selector(addAction)]; } UIImageView * ic_laba_scroll_bk = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-labaBLW)/2, 20, labaBLW, 42)]; ic_laba_scroll_bk.image = [UIImage imageNamed:@"ic_laba_scroll_bk"]; //ic_laba_scroll_bk.userInteractionEnabled = YES; [self.view addSubview:ic_laba_scroll_bk]; UIImageView * ic_laba_tag = [[UIImageView alloc] initWithFrame:CGRectMake(10, 19, 14, 14)]; ic_laba_tag.image = [UIImage imageNamed:@"ic_laba_tag"]; //ic_laba_scroll_bk.userInteractionEnabled = YES; [ic_laba_scroll_bk addSubview:ic_laba_tag]; UIImageView * ic_search_edit_bk = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-bkWith-62-2)/2, 2, bkWith, 33)]; ic_search_edit_bk.image = [UIImage imageNamed:@"ic_search_edit_bk"]; ic_search_edit_bk.userInteractionEnabled = YES; [self.view addSubview:ic_search_edit_bk]; UIImageView * ic_search_tag = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 13, 13)]; ic_search_tag.image = [UIImage imageNamed:@"ic_search_tag"]; [ic_search_edit_bk addSubview:ic_search_tag]; searchEdit = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, bkWith-20, 33)]; searchEdit.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入设备关键字"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0xa0a0a0)}]; //searchEdit.secureTextEntry = YES; searchEdit.font = [UIFont fontWithName:@"Arial" size:16]; searchEdit.delegate = self; //[searchEdit setValue:kUIColorFromRGB(0x00b744) forKeyPath:@"_placeholderLabel.textColor"]; searchEdit.layer.borderColor = [RgbColor(213, 213, 213) CGColor]; // searchEdit.textColor = RgbColor(213, 213, 213); searchEdit.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 UIView *blankView2 = [[UIView alloc] initWithFrame:CGRectMake(ic_search_edit_bk.frame.origin.x,ic_search_edit_bk.frame.origin.y,10.0, ic_search_edit_bk.frame.size.height)]; searchEdit.leftView = blankView2; searchEdit.leftViewMode =UITextFieldViewModeAlways; searchEdit.returnKeyType = UIReturnKeySearch; [ic_search_edit_bk addSubview:searchEdit]; sign_btn = [UIButton buttonWithType:UIButtonTypeCustom]; [sign_btn setBackgroundImage:[UIImage imageNamed:@"sign_btn_bk" ] forState:UIControlStateNormal]; [sign_btn setTitle:@"检索" forState:UIControlStateNormal]; [sign_btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; //sign_btn.backgroundColor = [UIColor redColor]; //上左下右 sign_btn.titleLabel.font = [UIFont systemFontOfSize: 14.0]; [sign_btn addTarget:self action:@selector(searchAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:sign_btn]; sign_btn.frame = CGRectMake((SCREEN_WIDTH-bkWith-62-2)/2 + bkWith+2, 2, 63, 33); //[sign_btn setTintColor:[UIColor whiteColor]]; //sign_btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0); //UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) //sign_btn.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10); HotelSelModel *selModel = [[HotelSelModel alloc] init]; selModel._id = @""; selModel.name = @"全部酒店"; _data2 = [NSMutableArray arrayWithObjects:selModel, nil]; _data3 = [NSMutableArray arrayWithObjects:@"全部机器", @"维修状态机器", @"保养提醒机器", nil]; menu = [[JSDropDownMenu alloc] initWithOrigin:CGPointMake(0, 65) andHeight:35]; menu.indicatorColor = [UIColor colorWithRed:175.0f/255.0f green:175.0f/255.0f blue:175.0f/255.0f alpha:1.0]; menu.separatorColor = [UIColor colorWithRed:210.0f/255.0f green:210.0f/255.0f blue:210.0f/255.0f alpha:1.0]; menu.textColor = [UIColor colorWithRed:83.f/255.0f green:83.f/255.0f blue:83.f/255.0f alpha:1.0f]; menu.dataSource = self; menu.delegate = self; [self.view addSubview:menu]; //[menu reloadInputViews]; self.myFileViewList.hidden = NO; _dansView = [[HBdansView alloc] initDansViewFrame:CGRectMake(10+28, 30, SCREEN_WIDTH-30-28, 30)]; _dansView.backgroundColor = [UIColor clearColor]; _dansView.textColor = [UIColor redColor]; [self.view addSubview:_dansView]; //[_dansView starDans]; [self get_hotel_list]; [self get_latest_list]; } -(void)addAction { AddDevicePage* page = [[AddDevicePage alloc] initIsFirstPage:NO]; //page.currentModel = model; // 跳转界面 BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page]; [self presentViewController:baseNav animated:YES completion:nil]; //[self.navigationController pushViewController:page animated:YES]; } -(void)get_device_list:(NSString*)keyword hotel_id:(NSString*)hotel_id type:(NSString*)type { //[UserDefault stringForKey:@"user_id"] NSString *path = [[NSString alloc] initWithFormat: GET_LATEST_LIST]; CommonReqModel * model = [[CommonReqModel alloc] init]; MPWeakSelf(self); [NetworkSingleton networkingGetMethod:model.toDic urlName:path success:^(id responseBody) { MPStrongSelf(self); BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { //发送成功提示 if(![Global isEmptyObject:resModel.content]) { NSMutableArray *modelTempArray = [NoticeModel mj_objectArrayWithKeyValuesArray:resModel.content]; [_dansView.randomMutableArray addObjectsFromArray:modelTempArray]; [_dansView starDans]; //HotelSelModel * hotelSelModel = [HotelSelModel mj_objectWithKeyValues:resModel.content]; } else { [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)get_latest_list { //[UserDefault stringForKey:@"user_id"] NSString *path = [[NSString alloc] initWithFormat: GET_LATEST_LIST]; CommonReqModel * model = [[CommonReqModel alloc] init]; MPWeakSelf(self); [NetworkSingleton networkingGetMethod:model.toDic urlName:path success:^(id responseBody) { MPStrongSelf(self); BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { //发送成功提示 if(![Global isEmptyObject:resModel.content]) { NSMutableArray *modelTempArray = [NoticeModel mj_objectArrayWithKeyValuesArray:resModel.content]; [_dansView.randomMutableArray addObjectsFromArray:modelTempArray]; [_dansView starDans]; //HotelSelModel * hotelSelModel = [HotelSelModel mj_objectWithKeyValues:resModel.content]; } else { [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)get_hotel_list { //[UserDefault stringForKey:@"user_id"] NSString *path = [[NSString alloc] initWithFormat: @"%@", [NSString stringWithFormat:GET_Hotel_LIST, [UserDefault stringForKey:@"user_id"]]]; CommonReqModel * model = [[CommonReqModel alloc] init]; MPWeakSelf(self); [NetworkSingleton networkingGetMethod:model.toDic urlName:path success:^(id responseBody) { MPStrongSelf(self); BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { //发送成功提示 if(![Global isEmptyObject:resModel.content]) { NSMutableArray *modelTempArray = [HotelSelModel mj_objectArrayWithKeyValuesArray:resModel.content]; [_data2 addObjectsFromArray:modelTempArray]; //HotelSelModel * hotelSelModel = [HotelSelModel mj_objectWithKeyValues:resModel.content]; } else { [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]; }]; } - (MyDeviceStatusView *)myFileViewList { if (!_myFileViewList) { _myFileViewList = [[MyDeviceStatusView alloc] initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, SCREEN_HEIGHT-100-64) userId:[UserDefault stringForKey:@"user_id"] devicetype:@"0" searchkey:@""]; _myFileViewList.delegate = self; _myFileViewList.detailDelegate = self; _myFileViewList.hotel_id = @""; [self.view addSubview:_myFileViewList]; } return _myFileViewList; } - (void)didSelectedSection:(MyDeviceStatus*)model { //DeviceDetailPage* page = [[DeviceDetailPage alloc] initIsFirstPage:NO]; //page.model = model; // 跳转界面 // BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page]; // [self presentViewController:baseNav animated:YES completion:nil]; } -(void)update_RETURN_BACK:(MyDeviceStatus*)model { //[UserDefault stringForKey:@"user_id"] NSString *path = [[NSString alloc] initWithFormat: RETURN_BACK]; NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; [param setObject:model._id forKey:@"deviceID"]; MPWeakSelf(self); [NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody) { MPStrongSelf(self); BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { [_myFileViewList.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_admode:(MyDeviceStatus*)model { //[UserDefault stringForKey:@"user_id"] NSString *path = [[NSString alloc] initWithFormat: UPDATE_ADMODE]; NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; [param setObject:model.mac forKey:@"mac"]; // ad_mode 0关闭 1开启 [param setObject:[NSString stringWithFormat:@"%d",model.ad_mode] forKey:@"ad_mode"]; [param setObject:[NSString stringWithFormat:@"%d",model.ad_speed] forKey:@"ad_speed"]; [param setObject:[NSString stringWithFormat:@"%d",model.ad_rollmd] forKey:@"ad_rollmd"]; MPWeakSelf(self); [NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody) { MPStrongSelf(self); BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { [_myFileViewList.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)didDetailSection:(MyDeviceStatus*)model; { //NSString * btncmd; // 按钮命令 0 发布广告 1 关闭广告&开启广告 2 更换设备 switch ([model.btncmd intValue]) { case 0: { AdvertisePage* page = [[AdvertisePage alloc] initIsFirstPage:NO]; page.currentModel = model; // 跳转界面 BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page]; [self presentViewController:baseNav animated:YES completion:nil]; } break; case 1: { //int ad_mode;//": 1 广告已开 0 广告已关 if( model.ad_mode == 1 ) { jxt_showAlertTwoButton(@"系统提示", @"是否关闭该广告", @"取消", ^(NSInteger buttonIndex) { NSLog(@"取消"); }, @"确定", ^(NSInteger buttonIndex) { model.ad_mode = 0; [self update_admode:model]; NSLog(@"确定"); }); } else if( model.ad_mode == 0 ) { jxt_showAlertTwoButton(@"系统提示", @"是否开启该广告", @"取消", ^(NSInteger buttonIndex) { NSLog(@"取消"); }, @"确定", ^(NSInteger buttonIndex) { model.ad_mode = 1; [self update_admode:model]; NSLog(@"确定"); }); } } break; case 2: { if(model.status == 1) { // 更换设备 ChangeDevicePage* page = [[ChangeDevicePage alloc] initIsFirstPage:NO]; _selectedDevice = nil; page.currentModel = model; // 跳转界面 BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page]; [self presentViewController:baseNav animated:YES completion:nil]; } else { // 换回设备 jxt_showAlertTwoButton(@"系统提示", @"是否确定换回", @"取消", ^(NSInteger buttonIndex) { NSLog(@"取消"); }, @"确定", ^(NSInteger buttonIndex) { model.status = 1; [self update_RETURN_BACK:model]; NSLog(@"确定"); }); } } break; default: break; } } #pragma mark - begin - (NSInteger)numberOfColumnsInMenu:(JSDropDownMenu *)menu { return 2; } -(BOOL)displayByCollectionViewInColumn:(NSInteger)column{ return NO; } -(BOOL)haveRightTableViewInColumn:(NSInteger)column { return NO; } -(CGFloat)widthRatioOfLeftColumn:(NSInteger)column{ return 1; } -(NSInteger)currentLeftSelectedRow:(NSInteger)column{ if (column==0) { return _currentData2Index; } else if (column==1) { return _currentData3Index; } return 0; } - (NSInteger)menu:(JSDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow{ if (column==0) { return _data2.count; } else if (column==1) { return _data3.count; } return 0; } - (NSString *)menu:(JSDropDownMenu *)menu titleForColumn:(NSInteger)column{ switch (column) { case 0: { HotelSelModel * hotelSelModel = [HotelSelModel mj_objectWithKeyValues:_data2[0]]; if(hotelSelModel) return hotelSelModel.name; else return @""; } break; case 1: return _data3[0]; break; default: return nil; break; } } - (NSString *)menu:(JSDropDownMenu *)menu titleForRowAtIndexPath:(JSIndexPath *)indexPath { if (indexPath.column==0) { HotelSelModel * hotelSelModel = [HotelSelModel mj_objectWithKeyValues:_data2[indexPath.row]]; if(hotelSelModel) return hotelSelModel.name; else return @""; } else { return _data3[indexPath.row]; } } - (void)menu:(JSDropDownMenu *)menu didSelectRowAtIndexPath:(JSIndexPath *)indexPath { if(indexPath.column == 0) { _currentData2Index = indexPath.row; } else { _currentData3Index = indexPath.row; } HotelSelModel * hotelSelModel = [_data2 objectAtIndex:_currentData2Index]; self.myFileViewList.hotel_id = hotelSelModel._id; [self.myFileViewList reSetView: [UserDefault stringForKey:@"user_id"] devicetype: [NSString stringWithFormat:@"%ld",_currentData3Index] searchkey:searchEdit.text]; } #pragma mark - end -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSInteger textLength = 0; if ([string isEqualToString:@""]) { textLength = textField.text.length-1; } else { textLength = textField.text.length+1; } BOOL flag = NO; flag = YES; if (flag) { // [loginBtn setBackgroundColor:BLUECOLOR]; // loginBtn.userInteractionEnabled = YES; } else { // loginBtn.backgroundColor = [UIColor lightGrayColor]; // loginBtn.userInteractionEnabled = NO; } return flag; } -(BOOL)textFieldShouldReturn:(UITextField *)textField { if ([textField isFirstResponder]) { [textField resignFirstResponder]; } return YES; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self textFieldShouldReturn:searchEdit]; } -(void)signAction { UserSignPage* page = [[UserSignPage alloc] initIsFirstPage:NO]; //page.model = model; // 跳转界面 BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page]; [self presentViewController:baseNav animated:YES completion:nil]; } -(void)searchAction { if(searchEdit.text.length == 0) { [Global alertMessageEx:@"请输入检索的关键字!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; return; } HotelSelModel * hotelSelModel = [_data2 objectAtIndex:_currentData2Index]; self.myFileViewList.hotel_id = hotelSelModel._id; [self.myFileViewList reSetView: [UserDefault stringForKey:@"user_id"] devicetype: [NSString stringWithFormat:@"%ld",_currentData3Index] searchkey:searchEdit.text]; } - (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