项目



#import "ShopOnFloorViewController.h"
#import "sysConfig.h"
#import "shopModel.h"
#import "ShopTableViewCell.h"
#import "ShopDetailViewController.h"
#import "TypeListModel.h"
#import "TypeListTableViewCell.h"
#import "RestaurantModel.h"
#import "MyWebViewController.h"

@interface ShopOnFloorViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_floorTableView;
    UITableView *_shopTableView;
    UITableView *_listTableView;
    NSMutableArray *_floorArray;
    NSMutableArray *_shopArray;
    NSMutableArray *_listArray;
    id _floorID;
    id _shopType;
    BOOL _listOn;
    NSInteger _currentPage;
    UILabel *_listHeaderView;
    UIImageView *_arrowImageView;

}
@end

@implementation ShopOnFloorViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initParameter];
    self.view.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"背景填充图案.jpg"]];
    self.navigationItem.title=self.itemTitle;
    [self createFloorTableView];
    [self createShopTableView];
    [self createListTableView];
    [self downloadFloorData];
    [self downloadTypeData];
}

-(void)initParameter
{
    _floorID=@"";
    _shopType=@"";
}





- (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.
}
*/

#pragma mark--数据获取

-(void)downloadFloorData
{
    LocalData *data=[LocalData shareInstance];
    NSString *urlStr;
    if (self.itemTitle) {
        urlStr=[NSString stringWithFormat:@"%@shop/floors?mallId=%@&hasCatering=true",MAIN_URL,data.mallId];
    }
    else
    {
        urlStr=[NSString stringWithFormat:@"%@shop/floors?mallId=%@&hasCatering=false",MAIN_URL,data.mallId];
    }
    
[HTTPRequestClientele httpGetRequest:urlStr andParameter:nil result:^(NSDictionary *resultesDic, NSError *error) {
    
    if (resultesDic) {
        int httpCode = [resultesDic[@"errorCode"]intValue];
        if (httpCode !=0) {
            DLog(@"网络响应失败,错误%@",resultesDic[@"message"])
            UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"" message:ALERT_MESSAGE delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
            [alertView show];
        }
    
        else
        {
        NSArray *array=resultesDic[@"items"];
        NSMutableArray *array1=[NSMutableArray array];
        NSMutableArray *array2=[NSMutableArray array];
        for (NSDictionary *dic in array) {
            NSString *str=dic[@"name"];
            if ([str hasPrefix:@"一期"]) {
                [array1 addObject:dic];
            }
            else
            {
                [array2 addObject:dic];
            }
        }
        [_floorArray addObject:array1];
        [_floorArray addObject:array2];
        if (array1.count) {
            [self downloadShopDataWithtype:@"" floor:array1[0][@"id"]];
        }
        [_floorTableView reloadData];
       }
    }
    else
    {
        DLog(@"网络响应失败,错误%@",error.localizedDescription);
    }

}];

}


-(void)downloadShopDataWithtype:(NSString *)type floor:(id)floorId
{
    
    LocalData *data=[LocalData shareInstance];
    NSString *urlStr;
    if (self.itemTitle) {
        urlStr=[NSString stringWithFormat:@"%@catering/restaurants?mallId=%@&type=%@&city=&area=&keywork=&floorid=%@&page=%ld&pagesize=%d",MAIN_URL,data.mallId,@"",floorId,(long)_currentPage,20];
        
    }
    else
    {
        urlStr=[NSString stringWithFormat:@"%@shop/list?mallId=%@&type=%@&floor=%@",MAIN_URL,data.mallId,type,floorId];
        
    }
    
    [HTTPRequestClientele httpGetRequest:urlStr andParameter:nil result:^(NSDictionary *resultesDic, NSError *error) {
        [_shopArray removeAllObjects];
        if (resultesDic) {
            int httpCode = [resultesDic[@"errorCode"]intValue];
            if (httpCode !=0) {
                DLog(@"网络响应失败,错误%@",resultesDic[@"message"])
                UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"" message:ALERT_MESSAGE delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
                [alertView show];
            }
            
            else
            {
                if (!self.itemTitle) {
                    JshopModel *model=  [[JshopModel alloc]initWithDictionary:resultesDic error:nil];
                    for (MallModel *mModel in model.items) {
                        [_shopArray addObject:mModel];
                    }
                }
                else
                {
                    RestaurantModel *model=[[RestaurantModel alloc]initWithDictionary:resultesDic error:nil];
                    for (RestaurantDetailModel *detailModel in model.items) {
                        [_shopArray addObject:detailModel];
                    }
                    
                }
                
                [_shopTableView reloadData];
            }
        }
        else
        {
            DLog(@"网络响应失败,错误%@",error.localizedDescription);
        }
        
        
        
    }];

}

-(void)downloadTypeData
{
    NSString *urlStr;
    if (self.itemTitle) {
        urlStr=[NSString stringWithFormat:@"%@catering/restaurants/types",MAIN_URL];
//        NSLog(@"%@",urlStr);
    }
    else
    {
        urlStr=[NSString stringWithFormat:@"%@shop/type",MAIN_URL];
    }
    [HTTPRequestClientele httpGetRequest:urlStr andParameter:nil result:^(NSDictionary *resultesDic, NSError *error) {
        if (resultesDic) {
            int httpCode = [resultesDic[@"errorCode"]intValue];
            if (httpCode !=0) {
                DLog(@"网络响应失败,错误%@",resultesDic[@"message"])
                UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"" message:ALERT_MESSAGE delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
                [alertView show];
            }
            else
            {
                TypeListModel *model=[[TypeListModel alloc]initWithDictionary:resultesDic error:nil];
                for (ListDetailModel *detailModel in model.items) {
                    [_listArray addObject:detailModel];
                }
                [_listTableView reloadData];
                
            }
        }
        else
        {
            DLog(@"网络响应失败,错误%@",error.localizedDescription);
        }
        
    }];


}

#pragma mark--创建界面

-(void)createFloorTableView
{
    _floorArray=[NSMutableArray array];
    _floorTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 129*SCALE_RATIO, SCREEN_HEIGHT-64) style:UITableViewStyleGrouped];
    _floorTableView.backgroundColor=[UIColor clearColor];
    _floorTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _floorTableView.showsVerticalScrollIndicator=NO;
    _floorTableView.delegate=self;
    _floorTableView.dataSource=self;

    [self.view addSubview:_floorTableView];
    

}

-(void)createShopTableView
{
    _shopArray=[NSMutableArray array];
    _shopTableView = [[UITableView alloc]initWithFrame:CGRectMake(130*SCALE_RATIO, 0, SCREEN_WIDTH-130*SCALE_RATIO, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
    _shopTableView.backgroundColor=[UIColor clearColor];
    _shopTableView.showsVerticalScrollIndicator=NO;
    _shopTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    UIView *bgView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 80*SCALE_RATIO)];
    _shopTableView.tableHeaderView=bgView;
    _listHeaderView=[[UILabel alloc]initWithFrame:CGRectMake(130*SCALE_RATIO, 0, SCREEN_WIDTH-130*SCALE_RATIO, 79*SCALE_RATIO)];
    _listHeaderView.userInteractionEnabled=YES;
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(listType)];
    [_listHeaderView addGestureRecognizer:tap];
    _listHeaderView.textAlignment=1;
    _listHeaderView.text=@"全部";
    _listHeaderView.font=[UIFont fontWithName:FONT_FZLTH size:32*SCALE_RATIO];
    _listHeaderView.textColor=[UIColor whiteColor];
    _listHeaderView.backgroundColor=[UIColor colorWithRed:80/255.0 green:57/255.0 blue:35/255.0 alpha:0.8];
    _arrowImageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"向下白箭头"]];
    _arrowImageView.frame=CGRectMake((SCREEN_WIDTH-130*SCALE_RATIO)/2.0+130*SCALE_RATIO+20, 35*SCALE_RATIO, 18*SCALE_RATIO, 10*SCALE_RATIO);
    
    _shopTableView.delegate=self;
    _shopTableView.dataSource=self;
    [self.view addSubview:_shopTableView];
    [self.view addSubview:_listHeaderView];
    [self.view addSubview:_arrowImageView];
}

-(void)createListTableView
{
    _listArray=[NSMutableArray array];
    _listTableView=[[UITableView alloc]initWithFrame:CGRectMake(130*SCALE_RATIO, 80*SCALE_RATIO, SCREEN_WIDTH-130*SCALE_RATIO, 0) style:UITableViewStylePlain];
    _listTableView.showsVerticalScrollIndicator=NO;
    _listTableView.bounces=NO;
    _listTableView.backgroundColor=[UIColor clearColor];
    _listTableView.delegate=self;
    _listTableView.dataSource =self;
    [self.view addSubview:_listTableView];
    

}

-(void)listType
{
    _listOn ^=1;
    if (_listOn) {
        _listTableView.frame=CGRectMake(130*SCALE_RATIO, 80*SCALE_RATIO, SCREEN_WIDTH-130*SCALE_RATIO, 400);
    }
    else
    {
        _listTableView.frame=CGRectZero;
    
    }

}



#pragma mark--<UITableViewDataSource,UITableViewDelegate>
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView==_floorTableView) {
        return 2;
    }
    else
    {
        return 1;
    }

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_floorTableView) {
        return 80*SCALE_RATIO;
    }
    else if(tableView==_shopTableView)
    {
        return 140*SCALE_RATIO;
    }
    else
    {
        return 80*SCALE_RATIO;
    }

}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (tableView==_floorTableView) {
        return 80*SCALE_RATIO;
    }
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (tableView==_floorTableView) {
        
        UILabel *headerLabel=[[UILabel alloc]init];
        headerLabel.backgroundColor=[UIColor colorWithRed:80/255.0 green:57/255.0 blue:35/255.0 alpha:1];
        headerLabel.textColor=[UIColor whiteColor];
        headerLabel.tag=101+section;
        headerLabel.textAlignment=1;
        if (section==0) {
            
            headerLabel.text=@"一期";
            return headerLabel;
        }
        else if(section==1)
        {
            
            headerLabel.text=@"二期";
            
            return headerLabel;
        }
    }

    return nil;
}

-(void)reloadShopData:(UITapGestureRecognizer *)tap
{
    _listHeaderView.text=@"全部";
    switch (tap.view.tag) {
        case 100:
            _floorID=@"";
            _shopType=@"";
            [self downloadShopDataWithtype:_shopType floor:_floorID];
            break;
        case 101:
            
            break;
        case 102:
            
            break;
        default:
            break;
    }
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView==_floorTableView&&_floorArray.count) {
        return [_floorArray[section] count];
    }
    else if(tableView==_shopTableView&&_shopArray)
    {
        return _shopArray.count;
    }
    else
    {
        return _listArray.count;
    }

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *floorCellId=@"floorCell";
    if (_floorTableView==tableView) {
        UITableViewCell *floorCell=[tableView dequeueReusableCellWithIdentifier:floorCellId];
        if (floorCell==nil) {
            floorCell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:floorCellId];
            UILabel *floorLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 129*SCALE_RATIO, 80*SCALE_RATIO)];
            floorLabel.tag=10000;
            floorLabel.textAlignment=1;
            floorLabel.font=[UIFont fontWithName:FONT_FZLTH size:28*SCALE_RATIO];
            [floorCell.contentView addSubview:floorLabel];
            floorCell.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        UILabel *label=(UILabel *)[floorCell.contentView viewWithTag:10000];
        label.text=[_floorArray[indexPath.section][indexPath.row][@"name"] substringFromIndex:2];
        
        if (indexPath.row%2) {
            
            floorCell.backgroundColor=[UIColor colorWithRed:247/255.0 green:222/255.0 blue:172.0/255.0 alpha:1];
        }
        else
        {
            floorCell.backgroundColor=[UIColor colorWithRed:250/255.0 green:234/255.0 blue:202.0/255.0 alpha:1];

        }
        floorCell.textLabel.textAlignment=1;
        return floorCell;
        
    }
    else if(_shopTableView==tableView)
    {
        ShopTableViewCell *shopCell=[tableView dequeueReusableCellWithIdentifier:@"shopCell"];
        if (shopCell==nil) {
            shopCell=[[ShopTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"shopCell"];
            shopCell.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        [shopCell configCellWithModel:_shopArray[indexPath.row]];
        return shopCell;
    
    }
    else if(_listTableView==tableView)
    {
        TypeListTableViewCell *typeListCell=[tableView dequeueReusableCellWithIdentifier:@"typeListCell"];
        if (typeListCell==nil) {
            typeListCell=[[TypeListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"typeListCell"];
            typeListCell.contentView.backgroundColor=[UIColor clearColor];
            typeListCell.backgroundColor=[UIColor clearColor];
            typeListCell.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        [typeListCell configCellWith:_listArray[indexPath.row]];
        return typeListCell;
    
    }

    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_floorTableView) {
        _arrowImageView.frame=CGRectMake((SCREEN_WIDTH-130*SCALE_RATIO)/2.0+130*SCALE_RATIO+20,35*SCALE_RATIO, 18*SCALE_RATIO, 10*SCALE_RATIO);
        _listHeaderView.text=@"全部";
        _floorID=_floorArray[indexPath.section][indexPath.row][@"id"];
        _shopType=@"";
        _listTableView.frame=CGRectZero;
        [self downloadShopDataWithtype:_shopType floor:_floorID];
    }
    else if(tableView ==_shopTableView)
    {
        
        if (self.itemTitle) {
        
            
        }
        else
        {
            MallModel *mModel=_shopArray[indexPath.row];
            MyWebViewController *MyWebVC=[[MyWebViewController alloc]initWithshopId:mModel.mallID productId:nil presentId:nil suitPresentId:nil];
            MyWebVC.navTitle=@"商户详情";
            [self.navigationController pushViewController:MyWebVC animated:YES];
        
        }

    }
    else
    {
        ListDetailModel *model=_listArray[indexPath.row];
        _listHeaderView.text=model.name;
        _shopType=model.typeID;
        [self downloadShopDataWithtype:_shopType floor:_floorID];
        tableView.frame=CGRectZero;
        _arrowImageView.frame=CGRectMake((SCREEN_WIDTH-130*SCALE_RATIO)/2.0+130*SCALE_RATIO+model.name.length/1.8*15, 35*SCALE_RATIO, 18*SCALE_RATIO, 10*SCALE_RATIO);
        _listOn^=1;
    }

}






@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值