SceneLibraryViewController.m 12.2 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 86 87
/**
 *  上传模型
 */
- (SceneCondition *)conditionModel
{
    if (!_conditionModel) {
        
        _conditionModel = [[SceneCondition alloc]init];
    }
    return _conditionModel;
}



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

曹云霄's avatar
曹云霄 committed
95 96
}

勾芒's avatar
勾芒 committed
97 98


曹云霄's avatar
曹云霄 committed
99 100 101 102 103 104 105 106 107
#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
108 109 110 111 112 113 114 115 116 117 118 119
    
    //设置按钮
    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);
120
    [self.SpaceButton setTitle:@"空间" forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
121 122 123 124 125 126 127
    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
128
    self.indexPage = 1;
勾芒's avatar
勾芒 committed
129
    
勾芒's avatar
勾芒 committed
130 131 132 133
    
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        //默认数据
勾芒's avatar
勾芒 committed
134
        self.indexPage = 1;
勾芒's avatar
勾芒 committed
135
        DataPage *page = [[DataPage alloc]init];
勾芒's avatar
勾芒 committed
136 137
        page.page = self.indexPage;
        page.rows = KROWS;
138
        self.conditionModel.page = page;
勾芒's avatar
勾芒 committed
139
        [self.seceneLibararyCollectionView.mj_footer resetNoMoreData];
140
        [self getSceneLibrarydatas:self.conditionModel isRemove:YES];
勾芒's avatar
勾芒 committed
141
    }];
勾芒's avatar
勾芒 committed
142
    
勾芒's avatar
勾芒 committed
143 144 145 146 147 148 149
    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
150
        if ( ++ self.indexPage > self.totalPages) {
勾芒's avatar
勾芒 committed
151 152 153
            [self.seceneLibararyCollectionView.mj_footer endRefreshingWithNoMoreData];
        }else
        {
勾芒's avatar
勾芒 committed
154
            //默认数据
勾芒's avatar
勾芒 committed
155
            DataPage *Newpage = [[DataPage alloc]init];
156
            Newpage.page = self.indexPage;
勾芒's avatar
勾芒 committed
157
            Newpage.rows = KROWS;
158 159
            self.conditionModel.page = Newpage;
            [self getSceneLibrarydatas:self.conditionModel isRemove:NO];
勾芒's avatar
勾芒 committed
160 161
        }
    }];
曹云霄's avatar
曹云霄 committed
162 163
    self.seceneLibararyCollectionView.mj_footer.automaticallyHidden = YES;

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

曹云霄's avatar
曹云霄 committed
188

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


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

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

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

曹云霄's avatar
曹云霄 committed
247 248 249 250

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


256
#pragma mark -筛选风格
勾芒's avatar
勾芒 committed
257 258
- (void)screeningStyleButtonClick:(UIButton *)sender {

259 260 261 262 263

    NSMutableArray *styleArray = [NSMutableArray arrayWithArray:self.filter.styles];
    DataDict *style = [[DataDict alloc]init];
    style.typename = @"全部";
    [styleArray insertObject:style atIndex:0];
勾芒's avatar
勾芒 committed
264
    [self dismissViewControllerAnimated:NO completion:nil];
265
    [self ShowPopoverViewController:CGSizeMake(150, 200) Withdatas:styleArray ShowButton:sender SelectedIndex:0];
266 267 268
}


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


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


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

307
    //空间code
勾芒's avatar
勾芒 committed
308 309
    if (Selected) {
        
310 311
        self.conditionModel.spaceEquals = Type;
        [self.SpaceButton setTitle:[title isEqualToString:@"全部"]?@"空间":title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
312 313
    }else
    {//风格code
314 315 316
        
        self.conditionModel.styleEquals = Type;
        [self.StyleButton setTitle:[title isEqualToString:@"全部"]?@"风格":title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
317
    }
318
    [self.seceneLibararyCollectionView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
}


#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
351 352 353 354 355 356 357
}



#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
曹云霄's avatar
曹云霄 committed
358
    return kNoDataImage;
勾芒's avatar
勾芒 committed
359 360 361 362 363
}

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

曹云霄's avatar
曹云霄 committed
366 367 368 369
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}
曹云霄's avatar
曹云霄 committed
370

曹云霄's avatar
曹云霄 committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
- (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