SceneLibraryViewController.m 11.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 36
/**
 *  总页数
 */
@property (nonatomic,assign) int totalPages;

勾芒's avatar
勾芒 committed
37

38

39

曹云霄's avatar
曹云霄 committed
40 41
@end

42
@implementation SceneLibraryViewController
曹云霄's avatar
曹云霄 committed
43

勾芒's avatar
勾芒 committed
44 45 46 47 48 49 50 51 52

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

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


69 70 71 72 73 74 75
/**
 *  上传模型
 */
- (SceneCondition *)conditionModel
{
    if (!_conditionModel) {
        _conditionModel = [[SceneCondition alloc]init];
曹云霄's avatar
曹云霄 committed
76 77 78 79
        DataPage *page = [[DataPage alloc]init];
        page.page = ONE;
        page.rows = KROWS;
        _conditionModel.page = page;
80 81 82 83
    }
    return _conditionModel;
}

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

曹云霄's avatar
曹云霄 committed
91 92 93 94 95 96 97 98 99
#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
100 101
    
    //设置按钮
102 103 104 105 106 107 108 109 110 111
    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
112 113
    
    //下拉刷新
曹云霄's avatar
曹云霄 committed
114
    WS(weakSelf);
勾芒's avatar
勾芒 committed
115
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
曹云霄's avatar
曹云霄 committed
116 117

        weakSelf.conditionModel.page.page = ONE;
曹云霄's avatar
曹云霄 committed
118 119
        [weakSelf.seceneLibararyCollectionView.mj_footer resetNoMoreData];
        [weakSelf getSceneLibrarydatas:weakSelf.conditionModel isRemove:YES];
勾芒's avatar
勾芒 committed
120 121 122 123 124 125 126 127
    }];
    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
128
        if ( ++ weakSelf.conditionModel.page.page > weakSelf.totalPages) {
曹云霄's avatar
曹云霄 committed
129
            [weakSelf.seceneLibararyCollectionView.mj_footer endRefreshingWithNoMoreData];
勾芒's avatar
勾芒 committed
130 131
        }else
        {
曹云霄's avatar
曹云霄 committed
132
            [weakSelf getSceneLibrarydatas:weakSelf.conditionModel isRemove:NO];
勾芒's avatar
勾芒 committed
133 134
        }
    }];
曹云霄's avatar
曹云霄 committed
135 136
    self.seceneLibararyCollectionView.mj_footer.automaticallyHidden = YES;

勾芒's avatar
勾芒 committed
137
    
曹云霄's avatar
曹云霄 committed
138
}
曹云霄's avatar
曹云霄 committed
139 140 141
#pragma mark -获取场景筛选数据
- (void)getdatasAction
{
曹云霄's avatar
曹云霄 committed
142
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
143
    [HTTP networkRequestWithURL:SERVERREQUESTURL(SCENESCREENING)  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
144
        
曹云霄's avatar
曹云霄 committed
145
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
146
          weakSelf.filter = [[SceneFilter alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
147 148 149
        }
        else
        {
150
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
151
        }
152
    }withFailureBlock:^(id error) {
153 154 155 156
        
    }];
}

曹云霄's avatar
曹云霄 committed
157

158
#pragma mark -获取场景列表数据
勾芒's avatar
勾芒 committed
159
- (void)getSceneLibrarydatas:(SceneCondition *)condition isRemove:(BOOL)remove
160
{
曹云霄's avatar
曹云霄 committed
161
    [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
162
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
163
    [HTTP networkRequestWithURL:SERVERREQUESTURL(SCENELIST)  withRequestType:ZERO withParameter:condition withReturnValueBlock:^(id returnValue) {
164
        
曹云霄's avatar
曹云霄 committed
165 166 167
        weakSelf.seceneLibararyCollectionView.emptyDataSetSource = weakSelf;
        weakSelf.seceneLibararyCollectionView.emptyDataSetDelegate = weakSelf;
        [weakSelf endRefreshingForTableView:weakSelf.seceneLibararyCollectionView];
曹云霄's avatar
曹云霄 committed
168
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
169
        if (RESULT(returnValue)) {
勾芒's avatar
勾芒 committed
170
            if (remove) {
曹云霄's avatar
曹云霄 committed
171
                [weakSelf.responseArray removeAllObjects];
勾芒's avatar
勾芒 committed
172
            }
曹云霄's avatar
曹云霄 committed
173 174
            SceneResponse *response = [[SceneResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
            weakSelf.totalPages = [RESPONSE(returnValue)[@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
175
            for (TOSceneEntity *model in response.list) {
曹云霄's avatar
曹云霄 committed
176
                [weakSelf.responseArray addObject:model];
勾芒's avatar
勾芒 committed
177
            }
曹云霄's avatar
曹云霄 committed
178
            [weakSelf.seceneLibararyCollectionView reloadData];
179 180 181
        }
        else
        {
182
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
183 184
        }
        
185
    }withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
186
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
187
        [weakSelf endRefreshingForTableView:weakSelf.seceneLibararyCollectionView];
曹云霄's avatar
曹云霄 committed
188
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
189
    }];
曹云霄's avatar
曹云霄 committed
190 191 192
}


曹云霄's avatar
曹云霄 committed
193 194 195
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SeceneLibraryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"secenelibrary" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
196
    cell.model = [self.responseArray objectAtIndex_opple:indexPath.item];
曹云霄's avatar
曹云霄 committed
197 198 199 200 201
    return cell;
}

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

勾芒's avatar
勾芒 committed
205 206 207
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    FullScreenViewController *fullScreenVC = [[FullScreenViewController alloc]init];
勾芒's avatar
勾芒 committed
208 209 210
    fullScreenVC.datasArray = self.responseArray;
    fullScreenVC.currentindex = indexPath.row;
    [self presentViewController:fullScreenVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
211 212
}

曹云霄's avatar
曹云霄 committed
213 214 215 216

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


222
#pragma mark -筛选风格
223
- (void)screeningstyleButtonClick:(UIButton *)sender {
勾芒's avatar
勾芒 committed
224

225 226
    NSMutableArray *styleArray = [NSMutableArray arrayWithArray:self.filter.styles];
    DataDict *style = [[DataDict alloc]init];
227
    style.typeName = @"全部";
228
    [styleArray insertObject:style atIndex:0];
勾芒's avatar
勾芒 committed
229
    [self dismissViewControllerAnimated:NO completion:nil];
230
    [self ShowPopoverViewController:CGSizeMake(150, 200) Withdatas:styleArray ShowButton:sender SelectedIndex:0];
231 232 233
}


234
#pragma mark -空间风格
235
- (void)HousestyleButtonClick:(UIButton *)sender {
236
    
237 238
    NSMutableArray *spaceArray = [NSMutableArray arrayWithArray:self.filter.space];
    DataDict *space = [[DataDict alloc]init];
239
    space.typeName = @"全部";
240
    [spaceArray insertObject:space atIndex:0];
勾芒's avatar
勾芒 committed
241
    [self dismissViewControllerAnimated:NO completion:nil];
242
    [self ShowPopoverViewController:CGSizeMake(150, 200) Withdatas:spaceArray ShowButton:sender SelectedIndex:1];
勾芒's avatar
勾芒 committed
243 244 245 246 247 248
}


#pragma mark -弹出popover视图控制器
- (void)ShowPopoverViewController:(CGSize)size Withdatas:(NSArray *)datasArray ShowButton:(UIButton *)button SelectedIndex:(NSInteger)index
{
249
    PopoverViewController *popover = [[PopoverViewController alloc]init];
勾芒's avatar
勾芒 committed
250 251
    popover.datasArray = datasArray;
    popover.delegate = self;
252
    popover.selectedindex = index;
勾芒's avatar
勾芒 committed
253 254 255 256 257
    if (size.width == 55) {
        popover.isPictures = YES;
    }
    popover.contentSize = size;
    popover.preferredContentSize = size;
258 259 260 261
    popover.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *pop = popover.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = popover.view;
勾芒's avatar
勾芒 committed
262
    pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
263 264
    [self presentViewController:popover animated:YES completion:nil];
}
曹云霄's avatar
曹云霄 committed
265 266


勾芒's avatar
勾芒 committed
267
#pragma mark -选中筛选条件回传typecode
268
- (void)returnCellindexpathwithrow:(NSString *)type withCellTitle:(NSString *)title withSelected:(NSInteger)selected
勾芒's avatar
勾芒 committed
269
{
270
    //空间code
271
    if (selected) {
勾芒's avatar
勾芒 committed
272
        
273
        self.conditionModel.spaceEquals = type;
274
        [self.spaceButton setTitle:[title isEqualToString:@"全部"]?@"空间":title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
275 276
    }else
    {//风格code
277
        
278
        self.conditionModel.styleEquals = type;
279
        [self.styleButton setTitle:[title isEqualToString:@"全部"]?@"风格":title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
280
    }
281
    [self.seceneLibararyCollectionView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
282 283 284 285 286 287
}


#pragma mark -筛选条件回传cellindex
- (void)returnWithIndexSelected:(NSInteger)selectedIndex
{
曹云霄's avatar
曹云霄 committed
288
    NSInteger showcellNumber = 0;
勾芒's avatar
勾芒 committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
    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
312 313 314 315 316 317 318
}



#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
曹云霄's avatar
曹云霄 committed
319
    return kNoDataImage;
勾芒's avatar
勾芒 committed
320 321 322 323 324
}

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

曹云霄's avatar
曹云霄 committed
327 328 329 330
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}
曹云霄's avatar
曹云霄 committed
331

曹云霄's avatar
曹云霄 committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
- (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