SceneLibraryViewController.m 8.64 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1
//
2
//  SceneLibraryViewController.m
曹云霄's avatar
曹云霄 committed
3 4
//  Lighting
//
5
//  Created by 曹云霄 on 16/5/4.
曹云霄's avatar
曹云霄 committed
6 7 8
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

9
#import "SceneLibraryViewController.h"
曹云霄's avatar
曹云霄 committed
10
#import "SeceneLibraryCollectionViewCell.h"
曹云霄's avatar
曹云霄 committed
11

勾芒's avatar
勾芒 committed
12
@interface SceneLibraryViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,ReturnTableviewcellIndexpathdelegate>
曹云霄's avatar
曹云霄 committed
13

14 15 16 17 18 19 20 21 22 23 24


/**
 *  筛选数据源
 */
@property (nonatomic,strong)  SceneFilter *filter;

/**
 *  列表数据
 */
@property (nonatomic,strong) SceneResponse *response;
勾芒's avatar
勾芒 committed
25 26 27 28 29 30 31 32 33


/**
 *  筛选cell个数图片
 */
@property (nonatomic,strong) NSArray *imageArray;



曹云霄's avatar
曹云霄 committed
34 35
@end

36
@implementation SceneLibraryViewController
曹云霄's avatar
曹云霄 committed
37

勾芒's avatar
勾芒 committed
38 39 40 41 42 43 44 45 46 47 48 49 50

#pragma mark -初始化
- (NSArray *)imageArray
{
    if (_imageArray == nil) {
        
        _imageArray = [NSArray arrayWithObjects:@"视角1",@"视角",@"视角3", nil];
    }
    return _imageArray;
}



曹云霄's avatar
曹云霄 committed
51 52 53
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
曹云霄's avatar
曹云霄 committed
54 55
    
    [self uiConfigAction];
56
    [self getdatasAction];
勾芒's avatar
勾芒 committed
57

曹云霄's avatar
曹云霄 committed
58 59
}

曹云霄's avatar
曹云霄 committed
60 61 62 63 64 65 66 67 68
#pragma mark -UI
- (void)uiConfigAction
{
    self.seceneLibraryCollectionLayout.itemSize = CGSizeMake((ScreenWidth-6)/3, (ScreenWidth-6)/3-50);
    self.seceneLibraryCollectionLayout.minimumLineSpacing = 2;
    self.seceneLibraryCollectionLayout.minimumInteritemSpacing = 2;
    self.seceneLibraryCollectionLayout.sectionInset = UIEdgeInsetsMake(5, 0, 5, 0);
    self.seceneLibararyCollectionView.dataSource = self;
    self.seceneLibararyCollectionView.delegate = self;
勾芒's avatar
勾芒 committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    
    //设置按钮
    self.StyleButton = [screeningButton buttonWithType:UIButtonTypeCustom];
    self.StyleButton.frame = CGRectMake(ScreenWidth-400, 14, 150, 30);
    self.StyleButton.backgroundColor = kTCColor(131, 131, 131);
    [self.StyleButton setTitle:@"风格" forState:UIControlStateNormal];
    [self.StyleButton addTarget:self action:@selector(screeningStyleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.StyleButton setImage:TCImage(@"down_arr") forState:UIControlStateNormal];
    self.StyleButton.layer.masksToBounds = YES;
    self.StyleButton.layer.cornerRadius = 10;
    self.SpaceButton = [screeningButton buttonWithType:UIButtonTypeCustom];
    self.SpaceButton.frame = CGRectMake(ScreenWidth-200, 14, 150, 30);
    [self.SpaceButton setTitle:@"房型" forState:UIControlStateNormal];
    self.SpaceButton.layer.masksToBounds = YES;
    self.SpaceButton.backgroundColor = kTCColor(131, 131, 131);
    [self.SpaceButton addTarget:self action:@selector(HouseStyleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.SpaceButton setImage:TCImage(@"down_arr") forState:UIControlStateNormal];
    self.SpaceButton.layer.cornerRadius = 10;
    [self.backView addSubview:self.StyleButton];
    [self.backView addSubview:self.SpaceButton];
    
    //默认数据
    SceneCondition *condition = [[SceneCondition alloc]init];
    DataPage *page = [[DataPage alloc]init];
    page.page = 0;
    condition.page = page;
    [self getSceneLibrarydatas:condition];
曹云霄's avatar
曹云霄 committed
96
}
曹云霄's avatar
曹云霄 committed
97 98 99
#pragma mark -获取场景筛选数据
- (void)getdatasAction
{
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/scene/getSceneFilter"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
          self.filter = [[SceneFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
    
        }
        else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
    }];
}

曹云霄's avatar
曹云霄 committed
119

120
#pragma mark -获取场景列表数据
勾芒's avatar
勾芒 committed
121
- (void)getSceneLibrarydatas:(SceneCondition *)condition
122
{
勾芒's avatar
勾芒 committed
123
    [self CreateMBProgressHUDLoding];
124 125
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/scene/query"] WithRequestType:0 WithParameter:condition WithReturnValueBlock:^(id returnValue) {
        
勾芒's avatar
勾芒 committed
126 127
        
        [self RemoveMBProgressHUDLoding];
128 129 130
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            self.response = [[SceneResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
勾芒's avatar
勾芒 committed
131
            [self.seceneLibararyCollectionView reloadData];
132 133 134 135 136 137 138 139 140 141
        }
        else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
勾芒's avatar
勾芒 committed
142
        [self RemoveMBProgressHUDLoding];
143
    }];
曹云霄's avatar
曹云霄 committed
144 145 146 147
}



曹云霄's avatar
曹云霄 committed
148 149 150
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SeceneLibraryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"secenelibrary" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
151
    cell.model = [self.response.list objectAtIndex_opple:indexPath.item];
曹云霄's avatar
曹云霄 committed
152 153 154 155 156
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
157
    return self.response.list.count;
曹云霄's avatar
曹云霄 committed
158 159 160 161 162 163
}


#pragma mark -切换显示风格
- (IBAction)SwitchdisplayStyleClick:(UIButton *)sender {
    
勾芒's avatar
勾芒 committed
164
    [self ShowPopoverViewController:CGSizeMake(55, 180) Withdatas:self.imageArray ShowButton:sender SelectedIndex:100];
曹云霄's avatar
曹云霄 committed
165 166 167
}


168
#pragma mark -筛选风格
勾芒's avatar
勾芒 committed
169 170
- (void)screeningStyleButtonClick:(UIButton *)sender {

171
    
勾芒's avatar
勾芒 committed
172
    [self ShowPopoverViewController:CGSizeMake(200, 300) Withdatas:self.filter.styles ShowButton:sender SelectedIndex:0];
173 174 175 176 177
    
}


#pragma mark -房型风格
勾芒's avatar
勾芒 committed
178
- (void)HouseStyleButtonClick:(UIButton *)sender {
179
    
勾芒's avatar
勾芒 committed
180 181 182 183 184 185 186 187
    [self ShowPopoverViewController:CGSizeMake(200, 300) Withdatas:self.filter.space ShowButton:sender SelectedIndex:1];
}


#pragma mark -弹出popover视图控制器
- (void)ShowPopoverViewController:(CGSize)size Withdatas:(NSArray *)datasArray ShowButton:(UIButton *)button SelectedIndex:(NSInteger)index
{
 
188
    PopoverViewController *popover = [[PopoverViewController alloc]init];
勾芒's avatar
勾芒 committed
189 190 191 192 193 194 195 196 197
    popover.datasArray = datasArray;
    popover.delegate = self;
    popover.Selectedindex = index;
    if (size.width == 55) {
        
        popover.isPictures = YES;
    }
    popover.contentSize = size;
    popover.preferredContentSize = size;
198 199 200 201
    popover.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *pop = popover.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = popover.view;
勾芒's avatar
勾芒 committed
202
    pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
203 204
    [self presentViewController:popover animated:YES completion:nil];
}
曹云霄's avatar
曹云霄 committed
205 206


勾芒's avatar
勾芒 committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
#pragma mark -选中筛选条件回传typecode
- (void)returnCellindexpathwithrow:(NSString *)Type WithcellTitle:(NSString *)title Withselected:(NSInteger)Selected
{
    [self dismissViewControllerAnimated:YES completion:nil];
    SceneCondition *condition = [[SceneCondition alloc]init];
    DataPage *page = [[DataPage alloc]init];
    page.page = 0;
    condition.page = page;
    
    //房型code
    if (Selected) {
        
        condition.spaceEquals = Type;
        [self.SpaceButton setTitle:title forState:UIControlStateNormal];
    }else
    {//风格code
        condition.styleEquals = Type;
        [self.StyleButton setTitle:title forState:UIControlStateNormal];
    }
    
    [self getSceneLibrarydatas:condition];
}


#pragma mark -筛选条件回传cellindex
- (void)returnWithIndexSelected:(NSInteger)selectedIndex
{

    NSInteger showcellNumber;
    switch (selectedIndex) {
        case 0:
        {
            showcellNumber = 2;
        }
            break;
        case 1:
        {
            showcellNumber = 3;
        }
            break;
        case 2:
        {
            showcellNumber = 4;
        }
            break;
            
        default:
            break;
    }
    
    [self.accordingStyle setBackgroundImage:TCImage([self.imageArray objectAtIndex_opple:selectedIndex]) forState:UIControlStateNormal];
    [self dismissViewControllerAnimated:YES completion:nil];
    self.seceneLibraryCollectionLayout.itemSize = CGSizeMake((ScreenWidth-showcellNumber*2)/showcellNumber, (ScreenWidth-showcellNumber*2)/showcellNumber-50);
    [self.seceneLibararyCollectionView reloadData];
    
}
曹云霄's avatar
曹云霄 committed
263 264


曹云霄's avatar
曹云霄 committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
- (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