SceneLibraryViewController.m 12 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,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
曹云霄'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

43

44

曹云霄's avatar
曹云霄 committed
45 46
@end

47
@implementation SceneLibraryViewController
曹云霄's avatar
曹云霄 committed
48

勾芒's avatar
勾芒 committed
49 50 51 52 53 54 55 56 57

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

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


74 75 76 77 78 79 80 81 82 83 84 85
/**
 *  上传模型
 */
- (SceneCondition *)conditionModel
{
    if (!_conditionModel) {
        
        _conditionModel = [[SceneCondition alloc]init];
    }
    return _conditionModel;
}

曹云霄's avatar
曹云霄 committed
86 87 88
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
曹云霄's avatar
曹云霄 committed
89
    [self uiConfigAction];
90
    [self getdatasAction];
曹云霄's avatar
曹云霄 committed
91 92
}

曹云霄's avatar
曹云霄 committed
93 94 95 96 97 98 99 100 101
#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
102 103
    
    //设置按钮
104 105 106 107 108 109 110 111 112 113
    self.styleButton = [ScreeningButton buttonWithType:UIButtonTypeCustom];
    self.styleButton.frame = CGRectMake(ScreenWidth-400, 14, 150, 30);
    [self.styleButton setTitle:@"风格" forState:UIControlStateNormal];
    [self.styleButton addTarget:self action:@selector(screeningstyleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    self.spaceButton = [ScreeningButton buttonWithType:UIButtonTypeCustom];
    self.spaceButton.frame = CGRectMake(ScreenWidth-200, 14, 150, 30);
    [self.spaceButton setTitle:@"空间" forState:UIControlStateNormal];
    [self.spaceButton addTarget:self action:@selector(HousestyleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.backView addSubview:self.styleButton];
    [self.backView addSubview:self.spaceButton];
勾芒's avatar
勾芒 committed
114 115
    
    //下拉刷新
曹云霄's avatar
曹云霄 committed
116
    WS(weakSelf);
勾芒's avatar
勾芒 committed
117 118
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        //默认数据
曹云霄's avatar
曹云霄 committed
119
        weakSelf.indexPage = ONE;
勾芒's avatar
勾芒 committed
120
        DataPage *page = [[DataPage alloc]init];
曹云霄's avatar
曹云霄 committed
121
        page.page = weakSelf.indexPage;
勾芒's avatar
勾芒 committed
122
        page.rows = KROWS;
曹云霄's avatar
曹云霄 committed
123 124 125
        weakSelf.conditionModel.page = page;
        [weakSelf.seceneLibararyCollectionView.mj_footer resetNoMoreData];
        [weakSelf getSceneLibrarydatas:weakSelf.conditionModel isRemove:YES];
勾芒's avatar
勾芒 committed
126 127 128 129 130 131 132 133
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.seceneLibararyCollectionView.mj_header = headerRefresh;
    [self.seceneLibararyCollectionView.mj_header beginRefreshing];
    //上拉加载
    self.seceneLibararyCollectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
曹云霄's avatar
曹云霄 committed
134 135
        if ( ++ weakSelf.indexPage > weakSelf.totalPages) {
            [weakSelf.seceneLibararyCollectionView.mj_footer endRefreshingWithNoMoreData];
勾芒's avatar
勾芒 committed
136 137
        }else
        {
勾芒's avatar
勾芒 committed
138
            //默认数据
勾芒's avatar
勾芒 committed
139
            DataPage *Newpage = [[DataPage alloc]init];
曹云霄's avatar
曹云霄 committed
140
            Newpage.page = weakSelf.indexPage;
勾芒's avatar
勾芒 committed
141
            Newpage.rows = KROWS;
曹云霄's avatar
曹云霄 committed
142 143
            weakSelf.conditionModel.page = Newpage;
            [weakSelf getSceneLibrarydatas:weakSelf.conditionModel isRemove:NO];
勾芒's avatar
勾芒 committed
144 145
        }
    }];
曹云霄's avatar
曹云霄 committed
146 147
    self.seceneLibararyCollectionView.mj_footer.automaticallyHidden = YES;

勾芒's avatar
勾芒 committed
148
    
曹云霄's avatar
曹云霄 committed
149
}
曹云霄's avatar
曹云霄 committed
150 151 152
#pragma mark -获取场景筛选数据
- (void)getdatasAction
{
曹云霄's avatar
曹云霄 committed
153
    WS(weakSelf);
154
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(SCENESCREENING) WithCallClass:weakSelf WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
155 156
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
曹云霄's avatar
曹云霄 committed
157
          weakSelf.filter = [[SceneFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
158 159 160
        }
        else
        {
曹云霄's avatar
曹云霄 committed
161
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
162 163 164
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
曹云霄's avatar
曹云霄 committed
165
        [weakSelf RemoveMBProgressHUDLoding];
166
        [weakSelf ErrorMBProgressView:NETWORK];
167 168 169 170 171
    } WithFailureBlock:^(id error) {
        
    }];
}

曹云霄's avatar
曹云霄 committed
172

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


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

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

勾芒's avatar
勾芒 committed
225 226 227
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    FullScreenViewController *fullScreenVC = [[FullScreenViewController alloc]init];
勾芒's avatar
勾芒 committed
228 229 230
    fullScreenVC.datasArray = self.responseArray;
    fullScreenVC.currentindex = indexPath.row;
    [self presentViewController:fullScreenVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
231 232
}

曹云霄's avatar
曹云霄 committed
233 234 235 236

#pragma mark -切换显示风格
- (IBAction)SwitchdisplayStyleClick:(UIButton *)sender {
    
237
    [self dismissViewControllerAnimated:NO completion:nil];
勾芒's avatar
勾芒 committed
238
    [self ShowPopoverViewController:CGSizeMake(55, 180) Withdatas:self.imageArray ShowButton:sender SelectedIndex:100];
曹云霄's avatar
曹云霄 committed
239 240 241
}


242
#pragma mark -筛选风格
243
- (void)screeningstyleButtonClick:(UIButton *)sender {
勾芒's avatar
勾芒 committed
244

245 246
    NSMutableArray *styleArray = [NSMutableArray arrayWithArray:self.filter.styles];
    DataDict *style = [[DataDict alloc]init];
247
    style.typeName = @"全部";
248
    [styleArray insertObject:style atIndex:0];
勾芒's avatar
勾芒 committed
249
    [self dismissViewControllerAnimated:NO completion:nil];
250
    [self ShowPopoverViewController:CGSizeMake(150, 200) Withdatas:styleArray ShowButton:sender SelectedIndex:0];
251 252 253
}


254
#pragma mark -空间风格
255
- (void)HousestyleButtonClick:(UIButton *)sender {
256
    
257 258
    NSMutableArray *spaceArray = [NSMutableArray arrayWithArray:self.filter.space];
    DataDict *space = [[DataDict alloc]init];
259
    space.typeName = @"全部";
260
    [spaceArray insertObject:space atIndex:0];
勾芒's avatar
勾芒 committed
261
    [self dismissViewControllerAnimated:NO completion:nil];
262
    [self ShowPopoverViewController:CGSizeMake(150, 200) Withdatas:spaceArray ShowButton:sender SelectedIndex:1];
勾芒's avatar
勾芒 committed
263 264 265 266 267 268
}


#pragma mark -弹出popover视图控制器
- (void)ShowPopoverViewController:(CGSize)size Withdatas:(NSArray *)datasArray ShowButton:(UIButton *)button SelectedIndex:(NSInteger)index
{
269
    PopoverViewController *popover = [[PopoverViewController alloc]init];
勾芒's avatar
勾芒 committed
270 271 272 273 274 275 276 277
    popover.datasArray = datasArray;
    popover.delegate = self;
    popover.Selectedindex = index;
    if (size.width == 55) {
        popover.isPictures = YES;
    }
    popover.contentSize = size;
    popover.preferredContentSize = size;
278 279 280 281
    popover.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *pop = popover.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = popover.view;
勾芒's avatar
勾芒 committed
282
    pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
283 284
    [self presentViewController:popover animated:YES completion:nil];
}
曹云霄's avatar
曹云霄 committed
285 286


勾芒's avatar
勾芒 committed
287 288 289
#pragma mark -选中筛选条件回传typecode
- (void)returnCellindexpathwithrow:(NSString *)Type WithcellTitle:(NSString *)title Withselected:(NSInteger)Selected
{
290
    //空间code
勾芒's avatar
勾芒 committed
291 292
    if (Selected) {
        
293
        self.conditionModel.spaceEquals = Type;
294
        [self.spaceButton setTitle:[title isEqualToString:@"全部"]?@"空间":title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
295 296
    }else
    {//风格code
297 298
        
        self.conditionModel.styleEquals = Type;
299
        [self.styleButton setTitle:[title isEqualToString:@"全部"]?@"风格":title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
300
    }
301
    [self.seceneLibararyCollectionView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
302 303 304 305 306 307
}


#pragma mark -筛选条件回传cellindex
- (void)returnWithIndexSelected:(NSInteger)selectedIndex
{
曹云霄's avatar
曹云霄 committed
308
    NSInteger showcellNumber = 0;
勾芒's avatar
勾芒 committed
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
    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.seceneLibraryCollectionLayout.itemSize = CGSizeMake((ScreenWidth-showcellNumber*2)/showcellNumber, (ScreenWidth-showcellNumber*2)/showcellNumber-50);
    [self.seceneLibararyCollectionView reloadData];
勾芒's avatar
勾芒 committed
332 333 334 335 336 337 338
}



#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
曹云霄's avatar
曹云霄 committed
339
    return kNoDataImage;
勾芒's avatar
勾芒 committed
340 341 342 343 344
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
勾芒's avatar
勾芒 committed
345
}
曹云霄's avatar
曹云霄 committed
346

曹云霄's avatar
曹云霄 committed
347 348 349 350
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}
曹云霄's avatar
曹云霄 committed
351

曹云霄's avatar
曹云霄 committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
- (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