// // ChangeDevicePage.m // istanbul // // Created by WindShan on 2017/6/15. // Copyright © 2017年 WindShan. All rights reserved. // #import "ChangeDevicePage.h" #import "HMSegmentedControl.h" #import "GloriaLabel.h" #import "BaseNaviController.h" #import "DeviceSelPage.h" #import "DeviceSpareModel.h" #import "Global.h" #import "NetworkSingleton.h" @interface ChangeDevicePage () { int tableViewrowCount; UITextField * sucessReasonTF; UITextField * failedReasonTF; NSString * failOrSuccess; // 1 sucess 2 failed } @property (nonatomic, strong) HMSegmentedControl *segmentedControl; @property (nonatomic, strong) UITableView * tableView; @end @implementation ChangeDevicePage -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; if( _selectedDevice != nil) { [self.tableView reloadData]; } } -(void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:YES]; //self.navigationController.navigationBarHidden = NO; } -(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; } return YES; } -(BOOL)textFieldShouldReturn:(UITextField *)textField { if ([textField isFirstResponder]) { [textField resignFirstResponder]; } return YES; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self textFieldShouldReturn:sucessReasonTF]; [self textFieldShouldReturn:failedReasonTF]; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] init]; _tableView.delegate = self; _tableView.dataSource = self; //_tableView.separatorColor = [UIColor clearColor]; _tableView.backgroundColor = [UIColor clearColor]; //_tableView.userInteractionEnabled = NO; //[_tableView setSeparatorInset:UIEdgeInsetsZero]; //[_tableView setLayoutMargins:UIEdgeInsetsZero]; _tableView.frame = CGRectMake(0, 40, SCREEN_WIDTH, 208); [self.view addSubview:_tableView]; [_tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(UIEdgeInsetsMake(0 , 0, 0, 0)); }]; _tableView.tableFooterView = [UIView new]; } return _tableView; } #pragma mark - UITableViewDelegate&UITableViewDataSource -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } //-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section //{ // return 0; //} // -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 80; } - (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section // custom view for footer. will be adjusted to default or { UIView * pView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 80)]; if(pView) { UIButton* changeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; changeBtn.frame = CGRectMake((SCREEN_WIDTH-350)/2, 20, 350, 40); [changeBtn setBackgroundImage:[UIImage imageNamed:@"ic_change_device_btn_bk" ] forState:UIControlStateNormal]; [changeBtn setTitle:@"提 交" forState:UIControlStateNormal]; changeBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0]; [changeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; changeBtn.layer.masksToBounds=YES; changeBtn.layer.cornerRadius=8.0f; [changeBtn addTarget:self action:@selector(changeCommitAction) forControlEvents:UIControlEventTouchUpInside]; [pView addSubview:changeBtn]; } return pView; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return tableViewrowCount; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { switch (indexPath.row) { case 0: { return 44; } break; case 1: { return 44; } break; case 2: { return 40; } break; case 3: { return 40; } break; case 4: { return 80; } break; case 5: { return 80; } break; default: break; } return 35; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString * identifier = @"changeCell"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (nil == cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } //cell.delegate = self; //cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.userInteractionEnabled = YES; switch (indexPath.row) { case 0: { cell.image = [UIImage imageNamed:@"ic_device_change"]; GloriaLabel* deviceNameTips = [[GloriaLabel alloc] initWithFrame:CGRectMake(48, 0, (SCREEN_WIDTH-48)/2, 44)]; deviceNameTips.font = FONT16; deviceNameTips.textAlignment = NSTextAlignmentLeft; deviceNameTips.userInteractionEnabled = NO; deviceNameTips.textColor = kUIColorFromRGB(0x6e6e6e); deviceNameTips.text = @"设备名称"; [cell.contentView addSubview:deviceNameTips]; GloriaLabel* deviceName = [[GloriaLabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2, 0, (SCREEN_WIDTH-48)/2, 44)]; deviceName.font = FONT16; deviceName.textAlignment = NSTextAlignmentLeft; deviceName.userInteractionEnabled = NO; deviceName.textColor = kUIColorFromRGB(0x6e6e6e); deviceName.text = _currentModel.name; [cell.contentView addSubview:deviceName]; } break; case 1: { cell.image = [UIImage imageNamed:@"ic_device_change"]; GloriaLabel* hotelRoomNameTips = [[GloriaLabel alloc] initWithFrame:CGRectMake(48, 0, SCREEN_WIDTH/4, 44)]; hotelRoomNameTips.font = FONT16; hotelRoomNameTips.textAlignment = NSTextAlignmentLeft; hotelRoomNameTips.userInteractionEnabled = NO; hotelRoomNameTips.textColor = kUIColorFromRGB(0x6e6e6e); hotelRoomNameTips.text = @"酒店房间"; [cell.contentView addSubview:hotelRoomNameTips]; GloriaLabel* hotelRoomName = [[GloriaLabel alloc] initWithFrame:CGRectMake(48+SCREEN_WIDTH/4+10, 0, SCREEN_WIDTH/3, 44)]; hotelRoomName.font = FONT16; hotelRoomName.textAlignment = NSTextAlignmentLeft; hotelRoomName.userInteractionEnabled = NO; hotelRoomName.textColor = kUIColorFromRGB(0x6e6e6e); hotelRoomName.text = _currentModel.hotel_id.name; [cell.contentView addSubview:hotelRoomName]; GloriaLabel* hotelRoomNo = [[GloriaLabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH*2)/3, 0, SCREEN_WIDTH/3, 44)]; hotelRoomNo.font = FONT16; hotelRoomNo.textAlignment = NSTextAlignmentLeft; hotelRoomNo.userInteractionEnabled = NO; hotelRoomNo.textColor = kUIColorFromRGB(0x6e6e6e); hotelRoomNo.text = [NSString stringWithFormat:@"%@号房",_currentModel.room_id.name]; [cell.contentView addSubview:hotelRoomNo]; } break; case 2: { cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.image = [UIImage imageNamed:@"ic_device_change"]; GloriaLabel* hotelRoomNameTips = [[GloriaLabel alloc] initWithFrame:CGRectMake(48, 0, SCREEN_WIDTH-80, 44)]; hotelRoomNameTips.font = FONT16; hotelRoomNameTips.textAlignment = NSTextAlignmentLeft; hotelRoomNameTips.userInteractionEnabled = NO; hotelRoomNameTips.textColor = kUIColorFromRGB(0x6e6e6e); hotelRoomNameTips.text = @"备用设备"; [cell.contentView addSubview:hotelRoomNameTips]; GloriaLabel* hotelRoomName = [[GloriaLabel alloc] initWithFrame:CGRectMake(48+SCREEN_WIDTH/2, 0, SCREEN_WIDTH-80, 44)]; hotelRoomName.font = FONT16; hotelRoomName.textAlignment = NSTextAlignmentLeft; hotelRoomName.userInteractionEnabled = NO; hotelRoomName.textColor = kUIColorFromRGB(0x6e6e6e); hotelRoomName.text = _selectedDevice != nil?_selectedDevice.name:@""; [cell.contentView addSubview:hotelRoomName]; } break; case 3: { cell.selectionStyle = UITableViewCellSelectionStyleNone; if(_segmentedControl == nil) { _segmentedControl = [[HMSegmentedControl alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height-4)]; /*! 设置标题 */ _segmentedControl.sectionTitles = @[@"更换成功",@"更换失败"]; /*! 自适应宽度,随着屏幕滑动自动滚动 */ _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; /*! 默认选中第0个view */ _segmentedControl.selectedSegmentIndex = 0; /*! 标题背景颜色 */ _segmentedControl.backgroundColor = [UIColor clearColor]; /*! 标题默认字体颜色 */ _segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : RgbColor(25, 31, 35), NSFontAttributeName: BA_FontSize(16)}; /*! 标题选中字体颜色 */ _segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : RgbColor(23, 172, 67), NSFontAttributeName: BA_FontSize(18)}; /*! 标题选中的下划线的颜色 */ _segmentedControl.selectionIndicatorColor = [UIColor clearColor]; /*! 标题选中的下划线的高度 */ _segmentedControl.selectionIndicatorHeight = 1.0f; /*! 标题选中的样式:本样式为下划线 */ _segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe; /*! 标题选中的下划线的方向:本样式为向下 */ _segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown; /*! 标题的中间的隔线:默认为:NO */ _segmentedControl.verticalDividerEnabled = YES; /*! 标题的中间的隔线颜色 */ _segmentedControl.verticalDividerColor = RgbColor(23, 172, 67); /*! 标题的中间的隔线宽度 */ _segmentedControl.verticalDividerWidth = 1.0f; [cell.contentView addSubview:_segmentedControl]; /*! 标题点击事件 */ BA_WEAKSELF; [_segmentedControl setIndexChangeBlock:^(NSInteger index) { if(index == 0 ) { tableViewrowCount = 5; [weakSelf.tableView reloadData]; failOrSuccess = @"1"; //weakSelf.views1.type = @"2"; //[weakSelf.views1 reSetView:[UserDefault stringForKey:@"user_id"] devicetype:weakSelf.views1.type searchkey:@""]; } else if( index == 1 ) { failOrSuccess = @"2"; tableViewrowCount = 6; [weakSelf.tableView reloadData]; //weakSelf.views2.type = @"1"; // [weakSelf.views2 reSetView:[UserDefault stringForKey:@"user_id"] devicetype:weakSelf.views1.type searchkey:@""]; } }]; } } break; case 4: { cell.image = [UIImage imageNamed:@"ic_device_change"]; if(sucessReasonTF==nil) { sucessReasonTF = [[UITextField alloc] initWithFrame:CGRectMake(38, 0, SCREEN_WIDTH-48, cell.frame.size.height)]; sucessReasonTF.font = [UIFont fontWithName:@"Arial" size:16]; sucessReasonTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入更换原因"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x6e6e6e)}]; sucessReasonTF.delegate = self; [sucessReasonTF setValue:kUIColorFromRGB(0x00b744) forKeyPath:@"_placeholderLabel.textColor"]; //userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor]; sucessReasonTF.textColor = kUIColorFromRGB(0x00b744); //zhengmingNameTF.keyboardType = UIKeyboardTypeNumberPad; sucessReasonTF.textAlignment = NSTextAlignmentLeft; sucessReasonTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(sucessReasonTF.frame.origin.x,sucessReasonTF.frame.origin.y,10.0, sucessReasonTF.frame.size.height)]; sucessReasonTF.leftView = blankView; sucessReasonTF.leftViewMode =UITextFieldViewModeAlways; sucessReasonTF.userInteractionEnabled = YES; [cell.contentView addSubview:sucessReasonTF]; } } break; case 5: { cell.image = [UIImage imageNamed:@"ic_device_change"]; if(failedReasonTF==nil) { failedReasonTF = [[UITextField alloc] initWithFrame:CGRectMake(38, 0, SCREEN_WIDTH-48, cell.frame.size.height)]; failedReasonTF.font = [UIFont fontWithName:@"Arial" size:16]; failedReasonTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入失败原因"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x6e6e6e)}]; failedReasonTF.delegate = self; [failedReasonTF setValue:kUIColorFromRGB(0x00b744) forKeyPath:@"_placeholderLabel.textColor"]; //failedReasonTF = [RgbColor(213, 213, 213) CGColor]; failedReasonTF.textColor = kUIColorFromRGB(0x00b744); //failedReasonTF.keyboardType = UIKeyboardTypeNumberPad; failedReasonTF.textAlignment = NSTextAlignmentLeft; failedReasonTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(failedReasonTF.frame.origin.x,failedReasonTF.frame.origin.y,10.0, failedReasonTF.frame.size.height)]; failedReasonTF.leftView = blankView; failedReasonTF.leftViewMode =UITextFieldViewModeAlways; failedReasonTF.userInteractionEnabled = YES; [cell.contentView addSubview:failedReasonTF]; } } break; default: break; } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; [self.view endEditing:YES]; if(indexPath.row == 2) { // 跳转选择酒店 // 更换设备 DeviceSelPage* page = [[DeviceSelPage alloc] initIsFirstPage:NO]; page.hotelid = _currentModel.hotel_id._id; // 跳转界面 BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page]; [self presentViewController:baseNav animated:YES completion:nil]; } } #pragma mark - 补全分隔线左侧缺失 - (void)viewDidLayoutSubviews { if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [self.tableView setSeparatorInset:UIEdgeInsetsZero]; } if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { [self.tableView setLayoutMargins:UIEdgeInsetsZero]; } } -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{ if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setSeparatorInset:)]){ [cell setSeparatorInset:UIEdgeInsetsZero]; } } - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"更换设备"; [self setNavigationLeft:@"返回" sel:@selector(backAction)]; //self.segmentedControl.hidden = NO; tableViewrowCount = 5; failOrSuccess = @"1"; self.tableView.hidden = NO; // Do any additional setup after loading the view. } -(void)backAction { [self dismissViewControllerAnimated:YES completion:nil]; } -(void)changeCommitAction { if(failedReasonTF.text.length == 0 && [failOrSuccess intValue] == 2) { [Global alertMessageEx:@"请输入失败原因." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; return; } if(sucessReasonTF.text.length == 0 ) { [Global alertMessageEx:@"请输入更换原因." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; return; } if(_selectedDevice == nil ) { [Global alertMessageEx:@"请选择备用设备." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; return; } //[UserDefault stringForKey:@"user_id"] NSString *path = [[NSString alloc] initWithFormat:CHANGE_DEVICE]; //params.put("userID", MainApp.userId); //params.put("deviceID", TextUtils.isEmpty(deviceID)?"":deviceID); //params.put("roomID", TextUtils.isEmpty(roomID)?"":roomID); //params.put("hotelID", TextUtils.isEmpty(hotelID)?"":hotelID); //params.put("spareID", TextUtils.isEmpty(spareId)?"":spareId); //params.put("reason", TextUtils.isEmpty(reason)?"":reason); //params.put("result", result+""); //params.put("fail", TextUtils.isEmpty(fail)?"":fail); NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; [param setObject:[UserDefault stringForKey:@"user_id"] forKey:@"userID"]; [param setObject:_currentModel._id forKey:@"deviceID"]; [param setObject:_currentModel.room_id._id forKey:@"roomID"]; [param setObject:_currentModel.hotel_id._id forKey:@"hotelID"]; [param setObject:_selectedDevice._id forKey:@"spareID"]; [param setObject:sucessReasonTF.text forKey:@"reason"]; [param setObject:failOrSuccess forKey:@"result"]; [param setObject:[failOrSuccess intValue] == 2?failedReasonTF.text:@"" forKey:@"fail"]; MPWeakSelf(self); [NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody) { MPStrongSelf(self); BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { //发送成功提示 [Global alertMessageEx:resModel.desc title:@"成功信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; [self dismissViewControllerAnimated:YES completion:nil]; } 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)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