SceneLibraryViewController.m 10.9 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
#import "FullScreenViewController.h"
勾芒's avatar
勾芒 committed
12
@interface SceneLibraryViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,ReturnTableviewcellIndexpathdelegate>
曹云霄's avatar
曹云霄 committed
13

14 15 16 17 18 19 20 21 22 23


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

/**
 *  列表数据
 */
勾芒's avatar
勾芒 committed
24
@property (nonatomic,strong) NSMutableArray *responseArray;
勾芒's avatar
勾芒 committed
25 26 27 28 29 30 31


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

勾芒's avatar
勾芒 committed
32 33 34 35
/**
 *  当前页数
 */
@property (nonatomic,assign) int indexPage;
勾芒's avatar
勾芒 committed
36

勾芒's avatar
勾芒 committed
37 38 39 40 41
/**
 *  总页数
 */
@property (nonatomic,assign) int totalPages;

勾芒's avatar
勾芒 committed
42

曹云霄's avatar
曹云霄 committed
43 44
@end

45
@implementation SceneLibraryViewController
曹云霄's avatar
曹云霄 committed
46

勾芒's avatar
勾芒 committed
47 48 49 50 51 52 53 54 55

#pragma mark -初始化
- (NSArray *)imageArray
{
    if (_imageArray == nil) {
        
        _imageArray = [NSArray arrayWithObjects:@"视角1",@"视角",@"视角3", nil];
    }
    return _imageArray;
勾芒's avatar
勾芒 committed
56
    
勾芒's avatar
勾芒 committed
57 58
}

勾芒's avatar
勾芒 committed
59 60 61 62 63 64 65 66 67 68 69
/**
 *  初始化数据源
 */
- (NSMutableArray *)responseArray
{
    if (_responseArray == nil) {
        
        _responseArray = [NSMutableArray array];
    }
    return _responseArray;
}
勾芒's avatar
勾芒 committed
70 71


曹云霄's avatar
曹云霄 committed
72 73 74
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
曹云霄's avatar
曹云霄 committed
75 76
    
    [self uiConfigAction];
77
    [self getdatasAction];
勾芒's avatar
勾芒 committed
78

曹云霄's avatar
曹云霄 committed
79 80
}

勾芒's avatar
勾芒 committed
81 82


曹云霄's avatar
曹云霄 committed
83 84 85 86 87 88 89 90 91
#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
92 93 94 95 96 97 98 99 100 101 102 103
    
    //设置按钮
    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);
104
    [self.SpaceButton setTitle:@"空间" forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
105 106 107 108 109 110 111 112
    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];
    
勾芒's avatar
勾芒 committed
113 114 115 116
    
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        //默认数据
勾芒's avatar
勾芒 committed
117
        self.indexPage = 1;
勾芒's avatar
勾芒 committed
118 119
        SceneCondition *condition = [[SceneCondition alloc]init];
        DataPage *page = [[DataPage alloc]init];
勾芒's avatar
勾芒 committed
120 121
        page.page = self.indexPage;
        page.rows = KROWS;
勾芒's avatar
勾芒 committed
122
        condition.page = page;
勾芒's avatar
勾芒 committed
123
        
勾芒's avatar
勾芒 committed
124 125 126
        [self.seceneLibararyCollectionView.mj_footer resetNoMoreData];
        [self getSceneLibrarydatas:condition isRemove:YES];
    }];
勾芒's avatar
勾芒 committed
127
    
勾芒's avatar
勾芒 committed
128 129 130 131 132 133 134 135 136 137 138
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.seceneLibararyCollectionView.mj_header = headerRefresh;
    [self.seceneLibararyCollectionView.mj_header beginRefreshing];
    //上拉加载
    self.seceneLibararyCollectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
        if (self.indexPage ++ > self.totalPages) {
            [self.seceneLibararyCollectionView.mj_footer endRefreshingWithNoMoreData];
        }else
        {
勾芒's avatar
勾芒 committed
139 140 141
            //默认数据
            SceneCondition *condition = [[SceneCondition alloc]init];
            DataPage *page = [[DataPage alloc]init];
勾芒's avatar
勾芒 committed
142
            page.page = self.indexPage ++;
勾芒's avatar
勾芒 committed
143
            page.rows = KROWS;
勾芒's avatar
勾芒 committed
144 145 146 147 148
            condition.page = page;
            [self getSceneLibrarydatas:condition isRemove:NO];
        }
    }];
    
曹云霄's avatar
曹云霄 committed
149
}
曹云霄's avatar
曹云霄 committed
150 151 152
#pragma mark -获取场景筛选数据
- (void)getdatasAction
{
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    [[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
171

172
#pragma mark -获取场景列表数据
勾芒's avatar
勾芒 committed
173
- (void)getSceneLibrarydatas:(SceneCondition *)condition isRemove:(BOOL)remove
174
{
勾芒's avatar
勾芒 committed
175
    [self CreateMBProgressHUDLoding];
176 177
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/scene/query"] WithRequestType:0 WithParameter:condition WithReturnValueBlock:^(id returnValue) {
        
勾芒's avatar
勾芒 committed
178
        [self endRefreshingForTableView:self.seceneLibararyCollectionView];
勾芒's avatar
勾芒 committed
179
        [self RemoveMBProgressHUDLoding];
180 181
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
勾芒's avatar
勾芒 committed
182 183 184 185
            if (remove) {
                [self.responseArray removeAllObjects];
            }
            SceneResponse *response = [[SceneResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
勾芒's avatar
勾芒 committed
186
            self.indexPage = (int)returnValue[@"data"][@"totalPages"];
勾芒's avatar
勾芒 committed
187 188 189 190
            for (TOSceneEntity *model in response.list) {
                [self.responseArray addObject:model];
            }
            
勾芒's avatar
勾芒 committed
191
            [self.seceneLibararyCollectionView reloadData];
192 193 194 195 196 197 198 199 200 201
        }
        else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
勾芒's avatar
勾芒 committed
202
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
203
        [self endRefreshingForTableView:self.seceneLibararyCollectionView];
204
    }];
曹云霄's avatar
曹云霄 committed
205 206 207
}


曹云霄's avatar
曹云霄 committed
208 209 210
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SeceneLibraryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"secenelibrary" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
211
    cell.model = [self.responseArray objectAtIndex_opple:indexPath.item];
曹云霄's avatar
曹云霄 committed
212 213 214 215 216
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
217
    return self.responseArray.count;
曹云霄's avatar
曹云霄 committed
218 219
}

勾芒's avatar
勾芒 committed
220 221 222 223
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    FullScreenViewController *fullScreenVC = [[FullScreenViewController alloc]init];
勾芒's avatar
勾芒 committed
224
    [self presentViewController:fullScreenVC animated:NO completion:nil];
勾芒's avatar
勾芒 committed
225 226
}

曹云霄's avatar
曹云霄 committed
227 228 229 230

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


235
#pragma mark -筛选风格
勾芒's avatar
勾芒 committed
236 237 238
- (void)screeningStyleButtonClick:(UIButton *)sender {

    [self ShowPopoverViewController:CGSizeMake(200, 300) Withdatas:self.filter.styles ShowButton:sender SelectedIndex:0];
239 240 241 242
    
}


243
#pragma mark -空间风格
勾芒's avatar
勾芒 committed
244
- (void)HouseStyleButtonClick:(UIButton *)sender {
245
    
勾芒's avatar
勾芒 committed
246 247 248 249 250 251 252
    [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
{
253
    PopoverViewController *popover = [[PopoverViewController alloc]init];
勾芒's avatar
勾芒 committed
254 255 256 257 258 259 260 261
    popover.datasArray = datasArray;
    popover.delegate = self;
    popover.Selectedindex = index;
    if (size.width == 55) {
        popover.isPictures = YES;
    }
    popover.contentSize = size;
    popover.preferredContentSize = size;
262 263 264 265
    popover.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *pop = popover.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = popover.view;
勾芒's avatar
勾芒 committed
266
    pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
267 268
    [self presentViewController:popover animated:YES completion:nil];
}
曹云霄's avatar
曹云霄 committed
269 270


勾芒's avatar
勾芒 committed
271 272 273 274 275 276 277 278 279
#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;
    
280
    //空间code
勾芒's avatar
勾芒 committed
281 282 283 284 285 286 287 288 289
    if (Selected) {
        
        condition.spaceEquals = Type;
        [self.SpaceButton setTitle:title forState:UIControlStateNormal];
    }else
    {//风格code
        condition.styleEquals = Type;
        [self.StyleButton setTitle:title forState:UIControlStateNormal];
    }
勾芒's avatar
勾芒 committed
290
    [self getSceneLibrarydatas:condition isRemove:YES];
勾芒's avatar
勾芒 committed
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
}


#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
325 326


曹云霄's avatar
曹云霄 committed
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
- (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