我的



#import "CouponsViewController.h"
#import "CouponsModel.h"
#import "TestTableViewCell.h"
#import "sysConfig.h"
#import "FloorModel.h"


@interface CouponsViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    
    UIImageView *_arrorImage;
    
    //楼层
    UITableView *_floorTableView;
    NSMutableArray *_floorArray;
    
    //折扣列表
    UITableView *_couponsTableView;
    NSMutableArray *_couponsArray;

    ZHCouponsModel *_couponsModel;
    FloorModel *_floorModel;
    


}
@end

@implementation CouponsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"背景填充图案.jpg"]];


    self.navigationItem.title=self.itemTitle;
    
    [self createFloorTableView];
    [self createCouponsTableView];
    
    [self httpGetRequestCouponsList];
    [self httpGetFlooridList];
    
    
 
}

//创建楼层TableView
-(void) createFloorTableView{
    
    _floorArray=[[NSMutableArray alloc] init];
    _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) createCouponsTableView{
    _couponsArray = [[NSMutableArray alloc] init];
    _couponsTableView = [[UITableView alloc] initWithFrame:CGRectMake(130*SCALE_RATIO, 0, SCREEN_WIDTH-130*SCALE_RATIO, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
    _couponsTableView.backgroundColor = [UIColor clearColor];
    _couponsTableView.showsVerticalScrollIndicator = NO;
//    _couponsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    _couponsTableView.delegate=self;
    _couponsTableView.dataSource=self;
    [self.view addSubview:_couponsTableView];


}
//http://192.168.0.13:8080/deji/api/v1/coupon/list?floorid=4&mallId=11
- (void) httpGetFlooridList{
    
    LocalData *locaData = [LocalData shareInstance];
    
    NSString *floorUrl = [NSString stringWithFormat:@"%@shop/floors?mallId=%@&hasCatering=false",MAIN_URL,locaData.mallId];
   [HTTPRequestClientele httpDeleteRequest:floorUrl andParameter:nil result:^(NSDictionary *resultDic, NSError *e) {

       
       if (!e) {
           int errorCode = [resultDic[@"errorCode"] intValue];
           if (errorCode == 0) {
               
//               NSArray *array = resultDic[@"items"];
//               NSMutableArray *array1 = [[NSMutableArray alloc] init];
//               NSMutableArray *array2 = [[NSMutableArray alloc] init];
//               for (NSDictionary *floorDic in array) {
//                   NSString *str = floorDic[@"name"];
//                   if ([str hasPrefix:@"一期"]) {
//                       [array1 addObject:str];//一期
//                   }else{
//                   
//                       [array2 addObject:str];//二期
//                   
//                   }
//                   [_floorArray addObject:array1];
//                   [_floorArray addObject:array2];
//                
//                   if (array1.count) {
//                       [self downloadFloorMessageWithKeyWord:@"" floor:array1[0] [@"id"]];
//                   }
                   [_floorTableView reloadData];
//               }
               
               _floorModel = [[FloorModel alloc] initWithDictionary:resultDic error:nil];
               
               
           }
           else{
               
               
               DLog(@"获取优惠券列表失败,errorcode=%@ and message=%@",resultDic[@"errorCode"],resultDic[@"message"]);
               
           }
           
       }else{
           
           DLog(@"获取优惠列表失败,响应结果:%@",[e localizedDescription]);
       }
   
   }];
    
    
    



}


//http://192.168.0.13:8080/deji/api/v1/coupon/list?mallId=11&pagesize=20
//http://192.168.0.13:8080/deji/api/v1/coupon/list?floorid=4&mallId=11


- (void) downloadFloorMessageWithKeyWord:(NSString *)key floor:(id)floorId{

    LocalData *data = [LocalData shareInstance];
    NSString *urlStr = [NSString stringWithFormat:@"%@coupon/list?floorid=%@&mallId=%@",MAIN_URL,floorId,data.mallId];
    [HTTPRequestClientele httpDeleteRequest:urlStr andParameter:nil result:^(NSDictionary *resultDic, NSError *error) {
        
        if (!error) {
            int errorCode = [resultDic[@"errorCode"] intValue];
            if (errorCode == 0) {
                
                _couponsModel = [[ZHCouponsModel alloc] initWithDictionary:resultDic error:nil];
                
                for (CouponsItemModel *itemModel in _couponsModel.items) {
                    
                    [_couponsArray addObject:itemModel];
                }
                
//                [_couponsTableView reloadData];
                
            }
            else{
                
                
                DLog(@"获取优惠券列表失败,errorcode=%@ and message=%@",resultDic[@"errorCode"],resultDic[@"message"]);
                

                
            }
            
            
        }else{
            
            DLog(@"获取优惠列表失败,响应结果:%@",[error localizedDescription]);
            
            
        }
   
        
    }];
    
    







}


- (void)httpGetRequestCouponsList{
    //%@coupon/list?floorid=4&mallId=%@


    LocalData *locaData = [LocalData shareInstance];
    NSString *urlStr = [NSString stringWithFormat:@"%@coupon/list?floorid=4&mallId=%@",MAIN_URL,locaData.mallId];
    [HTTPRequestClientele httpGetRequest:urlStr andParameter:nil result:^(NSDictionary *resultDic, NSError *e) {
        
        if (!e) {
            int errorCode = [resultDic[@"errorCode"] intValue];
            if (errorCode == 0) {
                
                _couponsModel = [[ZHCouponsModel alloc] initWithDictionary:resultDic error:nil];
                
                for (CouponsItemModel *itemModel in _couponsModel.items) {
                    
                    [_couponsArray addObject:itemModel];
                }
                
                [_couponsTableView reloadData];
             
            }
            else{
            
            
                DLog(@"获取优惠券列表失败,errorcode=%@ and message=%@",resultDic[@"errorCode"],resultDic[@"message"]);
            
//                UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"" message:ALERT_MESSAGE delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
//                [alertView show];
            
            }
            
            
        }else{
        
            DLog(@"获取优惠列表失败,响应结果:%@",[e localizedDescription]);
        
        
        }
        
        
    }];

}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    

    if (tableView == _couponsTableView) {
        return _couponsArray.count;
    }
    return 20;

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    if (tableView == _floorTableView) {
        return 2;
    }else{
    
        return 1;
    
    }

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellID = @"floor";
    static NSString *couponsID = @"coupon";
    if (tableView == _floorTableView) {
        UITableViewCell *floorCell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (floorCell == nil) {
            floorCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            
            UILabel *floorLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 129*SCALE_RATIO, 80*SCALE_RATIO)];
            floorLabel.tag = 20000;
            floorLabel.textAlignment = NSTextAlignmentCenter;
            floorLabel.font=[UIFont fontWithName:FONT_FZLTH size:28*SCALE_RATIO];
            [floorCell.contentView addSubview:floorLabel];
            
            //选中时的箭头
//            _arrorImage = [[UIImageView alloc] initWithFrame:CGRectMake(60, 60, 5, 5)];
//            _arrorImage.image = [UIImage imageNamed:@"楼层点击(深色)"];
//            _arrorImage.hidden = YES;
//            [floorCell.contentView addSubview:_arrorImage];
            
            
        }
        UILabel *label = (UILabel *)[floorCell.contentView viewWithTag:20000];
//        label.text = [_floorArray [indexPath.section][indexPath.row][@"name"]substringFromIndex:2];
        label.text = @"楼层";
        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 (tableView == _couponsTableView){
    
        TestTableViewCell *couponsCell = [tableView dequeueReusableCellWithIdentifier:couponsID];
        if (couponsCell == nil) {
            couponsCell = [[NSBundle mainBundle] loadNibNamed:@"TestTableViewCell" owner:self options:nil].lastObject ;
            couponsCell.selectionStyle = UITableViewCellSeparatorStyleNone;
            
        }
        
        couponsCell.backgroundColor=[UIColor colorWithRed:250/255.0 green:234/255.0 blue:202.0/255.0 alpha:1];

        couponsCell.model = _couponsArray[indexPath.row];
        return couponsCell;
    
    }
    

    return nil;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    if (tableView == _floorTableView) {
        return 80 * SCALE_RATIO;
    }

    return 0;
}
- (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 = 200 + section;
        headerLabel.textAlignment = NSTextAlignmentCenter;
        if (section == 0) {
            headerLabel.text = @"一期";
            return headerLabel;
        }else if (section == 1){
            headerLabel.text = @"二期";
            return headerLabel;
        
        
        }
    
    }
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (tableView == _floorTableView) {


        
    }

    


}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (tableView == _floorTableView) {
        return 80 * SCALE_RATIO;
    }else if (tableView == _couponsTableView){
    
        return 90;
    }else{
        return 0;
    
    }

}

@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值