SceneLibraryViewController.m 12.6 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.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);
114
    [self.SpaceButton setTitle:@"空间" forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
115 116 117 118 119 120 121
    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
122 123 124 125
    
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        //默认数据
126
        self.indexPage = ONE;
勾芒's avatar
勾芒 committed
127
        DataPage *page = [[DataPage alloc]init];
勾芒's avatar
勾芒 committed
128 129
        page.page = self.indexPage;
        page.rows = KROWS;
130
        self.conditionModel.page = page;
勾芒's avatar
勾芒 committed
131
        [self.seceneLibararyCollectionView.mj_footer resetNoMoreData];
132
        [self getSceneLibrarydatas:self.conditionModel isRemove:YES];
勾芒's avatar
勾芒 committed
133
    }];
勾芒's avatar
勾芒 committed
134
    
勾芒's avatar
勾芒 committed
135 136 137 138 139 140 141
    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
142
        if ( ++ self.indexPage > self.totalPages) {
勾芒's avatar
勾芒 committed
143 144 145
            [self.seceneLibararyCollectionView.mj_footer endRefreshingWithNoMoreData];
        }else
        {
勾芒's avatar
勾芒 committed
146
            //默认数据
勾芒's avatar
勾芒 committed
147
            DataPage *Newpage = [[DataPage alloc]init];
148
            Newpage.page = self.indexPage;
勾芒's avatar
勾芒 committed
149
            Newpage.rows = KROWS;
150 151
            self.conditionModel.page = Newpage;
            [self getSceneLibrarydatas:self.conditionModel isRemove:NO];
勾芒's avatar
勾芒 committed
152 153
        }
    }];
曹云霄's avatar
曹云霄 committed
154 155
    self.seceneLibararyCollectionView.mj_footer.automaticallyHidden = YES;

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

曹云霄's avatar
曹云霄 committed
181

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


曹云霄's avatar
曹云霄 committed
223 224 225
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SeceneLibraryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"secenelibrary" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
226
    cell.model = [self.responseArray objectAtIndex_opple:indexPath.item];
曹云霄's avatar
曹云霄 committed
227 228 229 230 231
    return cell;
}

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

勾芒's avatar
勾芒 committed
235 236 237
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    FullScreenViewController *fullScreenVC = [[FullScreenViewController alloc]init];
勾芒's avatar
勾芒 committed
238 239 240
    fullScreenVC.datasArray = self.responseArray;
    fullScreenVC.currentindex = indexPath.row;
    [self presentViewController:fullScreenVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
241 242
}

曹云霄's avatar
曹云霄 committed
243 244 245 246

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


252
#pragma mark -筛选风格
勾芒's avatar
勾芒 committed
253 254
- (void)screeningStyleButtonClick:(UIButton *)sender {

255 256
    NSMutableArray *styleArray = [NSMutableArray arrayWithArray:self.filter.styles];
    DataDict *style = [[DataDict alloc]init];
257
    style.typeName = @"全部";
258
    [styleArray insertObject:style atIndex:0];
勾芒's avatar
勾芒 committed
259
    [self dismissViewControllerAnimated:NO completion:nil];
260
    [self ShowPopoverViewController:CGSizeMake(150, 200) Withdatas:styleArray ShowButton:sender SelectedIndex:0];
261 262 263
}


264
#pragma mark -空间风格
勾芒's avatar
勾芒 committed
265
- (void)HouseStyleButtonClick:(UIButton *)sender {
266
    
267 268
    NSMutableArray *spaceArray = [NSMutableArray arrayWithArray:self.filter.space];
    DataDict *space = [[DataDict alloc]init];
269
    space.typeName = @"全部";
270
    [spaceArray insertObject:space atIndex:0];
勾芒's avatar
勾芒 committed
271
    [self dismissViewControllerAnimated:NO completion:nil];
272
    [self ShowPopoverViewController:CGSizeMake(150, 200) Withdatas:spaceArray ShowButton:sender SelectedIndex:1];
勾芒's avatar
勾芒 committed
273 274 275 276 277 278
}


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


勾芒's avatar
勾芒 committed
297 298 299 300
#pragma mark -选中筛选条件回传typecode
- (void)returnCellindexpathwithrow:(NSString *)Type WithcellTitle:(NSString *)title Withselected:(NSInteger)Selected
{
    [self dismissViewControllerAnimated:YES completion:nil];
301

302
    //空间code
勾芒's avatar
勾芒 committed
303 304
    if (Selected) {
        
305 306
        self.conditionModel.spaceEquals = Type;
        [self.SpaceButton setTitle:[title isEqualToString:@"全部"]?@"空间":title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
307 308
    }else
    {//风格code
309 310 311
        
        self.conditionModel.styleEquals = Type;
        [self.StyleButton setTitle:[title isEqualToString:@"全部"]?@"风格":title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
312
    }
313
    [self.seceneLibararyCollectionView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
314 315 316 317 318 319 320
}


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

曹云霄's avatar
曹云霄 committed
321
    NSInteger showcellNumber = 0;
勾芒's avatar
勾芒 committed
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
    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
346 347 348 349 350 351 352
}



#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
曹云霄's avatar
曹云霄 committed
353
    return kNoDataImage;
勾芒's avatar
勾芒 committed
354 355 356 357 358
}

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

曹云霄's avatar
曹云霄 committed
361 362 363 364
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}
曹云霄's avatar
曹云霄 committed
365

曹云霄's avatar
曹云霄 committed
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
- (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