//
|
// HotelSelPage.m
|
// istanbul
|
//
|
// Created by WindShan on 2017/6/16.
|
// Copyright © 2017年 WindShan. All rights reserved.
|
//
|
|
#import "HotelSelPage.h"
|
#import "NetworkSingleton.h"
|
#import "Hotel.h"
|
#import "HotelCell.h"
|
#import "BaseNaviController.h"
|
#import "RoomSelPage.h"
|
#import "HotelDevicePage.h"
|
#import "Room.h"
|
#import "RoomCell.h"
|
|
@interface HotelSelPage ()<UITableViewDelegate,UITableViewDataSource>
|
{
|
NSInteger pageIndex;
|
NSInteger pageSize;
|
|
}
|
@property (nonatomic, strong) NSMutableArray * modelArray;
|
@property (nonatomic, strong) UITableView * tableView;
|
@end
|
|
@implementation HotelSelPage
|
|
- (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)setUpTableView
|
{
|
//添加下拉的动画图片
|
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
|
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(getFirstPageData)];
|
|
// 马上进入刷新状态
|
[_tableView.mj_header beginRefreshing];
|
|
|
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
|
_tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(reloadData)];
|
}
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
|
self.title = @"选择酒店";
|
[self setNavigationLeft:@"返回" sel:@selector(backAticon)];
|
pageIndex = 1;
|
pageSize = 20;
|
|
self.modelArray = [[NSMutableArray alloc] init];
|
|
|
self.tableView.hidden = NO;
|
[self setUpTableView];
|
// Do any additional setup after loading the view.
|
}
|
|
-(void)getFirstPageData
|
{
|
pageIndex=1;
|
|
[self getHotelList:[UserDefault stringForKey:@"user_id"] isTips:NO pageIndex:[NSString stringWithFormat:@"%ld",pageIndex] pageSize:[NSString stringWithFormat:@"%ld",pageSize]];
|
}
|
|
-(void) reloadData
|
{
|
//pageIndex++;
|
[self getHotelList:[UserDefault stringForKey:@"user_id"] isTips:NO pageIndex:[NSString stringWithFormat:@"%ld",pageIndex] pageSize:[NSString stringWithFormat:@"%ld",pageSize]];
|
}
|
|
-(void) getHotelList:(NSString *) userID isTips:(BOOL) isShow pageIndex:(NSString *)page pageSize:(NSString *)size
|
{
|
// 执行登录操作
|
MBProgressHUD *HUD = nil;
|
if( isShow == YES)
|
{
|
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
HUD.labelText = @"数据加载中...";
|
// 隐藏时候从父控件中移除
|
HUD.removeFromSuperViewOnHide = YES;
|
// YES代表需要蒙版效果
|
HUD.dimBackground = YES;
|
}
|
|
|
NSString *path = [[NSString alloc] initWithFormat:@"%@",[NSString stringWithFormat:GET_HOTEL_LIST,userID]];
|
|
NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
|
|
|
MPWeakSelf(self);
|
[NetworkSingleton networkingGetMethod:param urlName:path success:^(id responseBody)
|
{
|
if( isShow == YES)
|
HUD.hidden = YES;
|
|
[_tableView.mj_header endRefreshing];
|
[_tableView.mj_footer endRefreshing];
|
MPStrongSelf(self);
|
BaseResModel * resModel = [Global toBaseModel:responseBody];
|
|
|
if(pageIndex == 1)
|
{
|
[_modelArray removeAllObjects];
|
}
|
|
if(resModel.code == 0)
|
{
|
if(![Global isEmptyObject:resModel.content])
|
{
|
NSMutableArray *modelTempArray = [Hotel mj_objectArrayWithKeyValuesArray:resModel.content];
|
|
BASE_INFO_FUN(resModel.content);
|
|
[_modelArray addObjectsFromArray:modelTempArray];
|
|
_tableView.hidden = NO;
|
[_tableView reloadData];
|
|
}
|
else
|
{
|
// 出错处理
|
if(self.modelArray.count > 0)
|
{
|
[self.modelArray removeAllObjects];
|
[_tableView reloadData];
|
}
|
|
_tableView.hidden = YES;
|
|
[Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"确定" delegate:self];
|
}
|
|
}
|
else
|
{
|
if(self.modelArray.count > 0)
|
{
|
[self.modelArray removeAllObjects];
|
[_tableView reloadData];
|
}
|
|
_tableView.hidden = YES;
|
|
|
}
|
}
|
failure:^(NSString *error)
|
{
|
[_tableView.mj_header endRefreshing];
|
[_tableView.mj_footer endRefreshing];
|
if( isShow == YES)
|
HUD.hidden = YES;
|
|
_tableView.hidden = YES;
|
|
|
[Global alertMessageEx:error title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}];
|
|
|
}
|
|
|
#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 0;
|
}
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
{
|
return self.modelArray.count;
|
}
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
return 60;
|
}
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
|
NSString * identifier = @"hotelCell";
|
HotelCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
|
if (nil == cell) {
|
cell = [[HotelCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
|
|
}
|
|
//cell.delegate = self;
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
cell.userInteractionEnabled = YES;
|
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
Hotel * model = [self.modelArray objectAtIndex:indexPath.row];
|
|
[cell setItemView:model.name];
|
|
return cell;
|
}
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
if(self.bSelRoom == 0)
|
{
|
Hotel * model = [self.modelArray objectAtIndex:indexPath.row];
|
_curHotel_Id = model;
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
}
|
else if(self.bSelRoom == 1)
|
{
|
//跳转选择酒店房间
|
RoomSelPage* page = [[RoomSelPage alloc] initIsFirstPage:NO];
|
Hotel * model = [self.modelArray objectAtIndex:indexPath.row];
|
page.hotel_id = model._id;
|
_curHotel_Id = model;
|
[self.navigationController pushViewController:page animated:YES];
|
}
|
else if(self.bSelRoom == 2)
|
{
|
//跳转选择酒店备用设备
|
HotelDevicePage* page = [[HotelDevicePage alloc] initIsFirstPage:NO];
|
Hotel * model = [self.modelArray objectAtIndex:indexPath.row];
|
page.hotelid = model._id;
|
_curHotel_Id = model;
|
[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)didReceiveMemoryWarning {
|
[super didReceiveMemoryWarning];
|
|
|
// Dispose of any resources that can be recreated.
|
}
|
|
#pragma mark custom action begin
|
-(void)backAticon
|
{
|
if(self.bSelRoom == 0)
|
{
|
[self dismissViewControllerAnimated:YES completion:nil];
|
}
|
else if(self.bSelRoom == 1)
|
{
|
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
|
}
|
else if(self.bSelRoom == 2)
|
{
|
[self dismissViewControllerAnimated:YES completion:nil];
|
}
|
|
|
//[self dismissViewControllerAnimated: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
|