// // AddHotelAccountPage // // // Created by WindShan on 2016/11/18. // Copyright © 2016年 Gloria. All rights reserved. // #import "AddHotelAccountPage.h" #import "GloriaLabel.h" #import "AddDeviceReqModel.h" #import "NetworkSingleton.h" #import "HotelSelPage.h" #import "BaseNaviController.h" @interface AddHotelAccountPage () { UITextField * nicknameTextField; // 昵称 UITextField * mobileTextField; // 手机号 UITextField * passwdTextField; // 密码 UIButton * createBtn; NSString * hotel_room; } @property (nonatomic, strong) UITableView * tableView; @end @implementation AddHotelAccountPage - (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, 0, 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) { createBtn = [UIButton buttonWithType:UIButtonTypeCustom]; createBtn.frame = CGRectMake((SCREEN_WIDTH-350)/2, 20, 350, 40); [createBtn setBackgroundImage:[UIImage imageNamed:@"ic_change_device_btn_bk" ] forState:UIControlStateNormal]; [createBtn setTitle:@"创建" forState:UIControlStateNormal]; createBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0]; [createBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; createBtn.layer.masksToBounds=YES; createBtn.layer.cornerRadius=8.0f; [createBtn addTarget:self action:@selector(createAction) forControlEvents:UIControlEventTouchUpInside]; [pView addSubview:createBtn]; } return pView; } -(void)createAction { [self createHotelAccount]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 4; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 50; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString * identifier = @"addHotelAccountCell"; 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"]; if(nicknameTextField==nil) { nicknameTextField = [[UITextField alloc] initWithFrame:CGRectMake(38, 0, SCREEN_WIDTH-60, cell.frame.size.height)]; //nicknameTextField.secureTextEntry = YES; nicknameTextField.placeholder = @"请输入昵称"; nicknameTextField.font = [UIFont fontWithName:@"Arial" size:16]; nicknameTextField.delegate = self; nicknameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 nicknameTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(nicknameTextField.frame.origin.x,nicknameTextField.frame.origin.y,10.0, nicknameTextField.frame.size.height)]; nicknameTextField.leftViewMode =UITextFieldViewModeAlways; [cell.contentView addSubview:nicknameTextField]; } } break; case 1: { cell.image = [UIImage imageNamed:@"ic_device_change"]; if(mobileTextField==nil) { mobileTextField = [[UITextField alloc] initWithFrame:CGRectMake(38, 0, SCREEN_WIDTH-60, cell.frame.size.height)]; //mobileTextField.secureTextEntry = YES; mobileTextField.placeholder = @"请输入手机号码"; mobileTextField.font = [UIFont fontWithName:@"Arial" size:16]; mobileTextField.delegate = self; mobileTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 mobileTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(mobileTextField.frame.origin.x,mobileTextField.frame.origin.y,10.0, mobileTextField.frame.size.height)]; mobileTextField.leftViewMode =UITextFieldViewModeAlways; [cell.contentView addSubview:mobileTextField]; } } break; case 2: { cell.image = [UIImage imageNamed:@"ic_device_change"]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.textLabel.text = _curHotel_Id!= nil? _curHotel_Id.name:@"选择酒店"; } break; case 3: { cell.image = [UIImage imageNamed:@"ic_device_change"]; if(passwdTextField==nil) { passwdTextField = [[UITextField alloc] initWithFrame:CGRectMake(38, 0, SCREEN_WIDTH-60, cell.frame.size.height)]; //passwdTextField.secureTextEntry = YES; passwdTextField.placeholder = @"请输入密码"; passwdTextField.font = [UIFont fontWithName:@"Arial" size:16]; passwdTextField.delegate = self; passwdTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 passwdTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(passwdTextField.frame.origin.x,passwdTextField.frame.origin.y,10.0, passwdTextField.frame.size.height)]; passwdTextField.leftViewMode =UITextFieldViewModeAlways; [cell.contentView addSubview:passwdTextField]; } } break; default: break; } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; if(indexPath.row == 2) { // 跳转选择酒店 // 跳转选择酒店 HotelSelPage* page = [[HotelSelPage alloc] initIsFirstPage:NO]; page.bSelRoom = 0; // 跳转界面 BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page]; [self presentViewController:baseNav animated:YES completion:nil]; //[self.navigationController pushViewController:page animated:YES]; } } #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.title = @"创建酒店账号"; [self setNavigationLeft:@"返回" sel:@selector(backAticon)]; [self.tableView reloadData]; // Do any additional setup after loading the view. } #pragma mark custom action begin -(void)backAticon { //[self.navigationController popToViewController:self animated:YES]; [self dismissViewControllerAnimated:YES completion:nil]; } -(void) createHotelAccount { if(_curHotel_Id ==nil) { [Global alertMessageEx:@"请先选择酒店房间!" title:@"提示信息" okTtitle:nil cancelTitle:@"确定" delegate:self]; } else if(mobileTextField.text.length == 0) { [Global alertMessageEx:@"请输入手机号." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else if(passwdTextField.text.length == 0) { [Global alertMessageEx:@"请输入密码." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else if(nicknameTextField.text.length == 0) { [Global alertMessageEx:@"请输入昵称." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else { // 执行登录操作 MBProgressHUD *HUD = nil; HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; HUD.labelText = @"账号创建中..."; // 隐藏时候从父控件中移除 HUD.removeFromSuperViewOnHide = YES; // YES代表需要蒙版效果 HUD.dimBackground = YES; NSString *path = [[NSString alloc] initWithFormat:CREATE_WAITER]; NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; [param setObject:[UserDefault stringForKey:@"user_id"] forKey:@"userID"]; [param setObject:mobileTextField.text forKey:@"username"]; [param setObject:nicknameTextField.text forKey:@"nickname"]; [param setObject:passwdTextField.text forKey:@"password"]; [param setObject:_curHotel_Id != nil?_curHotel_Id._id:@"0" forKey:@"hotelID"]; MPWeakSelf(self); [NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody) { HUD.hidden = YES; MPStrongSelf(self); BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"确定" delegate:self]; [self dismissViewControllerAnimated:YES completion:nil]; } else { [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"确定" delegate:self]; } } failure:^(NSString *error) { HUD.hidden = YES; [Global alertMessageEx:error title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; }]; } } //-(void)switchAction:(id)sender //{ // UISwitch *switchBtn = (UISwitch *)sender; // // if(switchBtn.on) // { //#ifdef USE_SmartLink // smtlk.isConfigOneDevice = true; //#endif // } // else // { //#ifdef USE_SmartLink // smtlk.isConfigOneDevice = false; //#endif // } // //} #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; if( textField == mobileTextField ) { // 检测手机号是否合法 if( textLength == 11 && [StringUtil isMobile:[mobileTextField.text stringByAppendingString:string]] == NO) { [Global alertMessage:@"手机号码不合法,请重新输入!"]; } // 大于11位数不让输入 if( textLength > 11 ) return NO; } flag = YES; if (flag) { // [loginBtn setBackgroundColor:BLUECOLOR]; // loginBtn.userInteractionEnabled = YES; } else { // loginBtn.backgroundColor = [UIColor lightGrayColor]; // loginBtn.userInteractionEnabled = NO; } return flag; } -(void) viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; if( _curHotel_Id != nil ) { [self.tableView reloadData]; } } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(BOOL)textFieldShouldReturn:(UITextField *)textField { if ([textField isFirstResponder]) { [textField resignFirstResponder]; } return YES; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self textFieldShouldReturn:mobileTextField]; [self textFieldShouldReturn:passwdTextField]; [self textFieldShouldReturn:nicknameTextField]; } /* #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