SeceneLibraryView.m 14.1 KB
Newer Older
zhu's avatar
zhu committed
1 2 3 4 5 6 7 8 9
//
//  SeceneLibraryView.m
//  Lighting
//
//  Created by mac on 16/5/11.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "SeceneLibraryView.h"
zhu's avatar
zhu committed
10 11 12
@interface SeceneLibraryView ()

@end
zhu's avatar
zhu committed
13 14

@implementation SeceneLibraryView
15 16 17 18 19 20 21 22 23 24 25
/**
 *  上传模型
 */
- (SceneCondition *)conditionModel
{
    if (!_conditionModel) {
        
        _conditionModel = [[SceneCondition alloc]init];
    }
    return _conditionModel;
}
zhu's avatar
zhu committed
26 27 28

- (void)viewDidLoad {
    
ZCJ's avatar
ZCJ committed
29 30
     [self  initdata];
     [self  initView ];
zhu's avatar
zhu committed
31 32
     [self  uiConfigAction];
     [self  getdatasAction];
ZCJ's avatar
ZCJ committed
33 34 35 36
    
}
-(void)initdata
{
zhu's avatar
zhu committed
37 38
    self.arrayData=[[NSMutableArray alloc]init];
    self.indexPage = 0;
39
    self.isSelectBtnType=@"space";
ZCJ's avatar
ZCJ committed
40
  
zhu's avatar
zhu committed
41 42 43 44 45 46
}
-(void)uiConfigAction
{
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        //默认数据
47
        self.indexPage = 1;
zhu's avatar
zhu committed
48 49
        DataPage *page = [[DataPage alloc]init];
        page.page = self.indexPage;
50 51 52 53 54
        page.rows = KROWS;
        self.conditionModel.page = page;
        
        [self.collectionView.mj_footer resetNoMoreData];
        [self getSceneLibrarydatas:self.conditionModel isRemove:YES];
zhu's avatar
zhu committed
55
    }];
56
    
zhu's avatar
zhu committed
57 58 59 60 61 62 63
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.collectionView.mj_header = headerRefresh;
    [self.collectionView.mj_header beginRefreshing];
    //上拉加载
    self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
mei's avatar
mei committed
64
        if (++self.indexPage > self.totalPages) {
65 66 67 68 69 70 71 72 73 74
            [self.collectionView.mj_footer endRefreshingWithNoMoreData];
        }else
        {
            //默认数据
            DataPage *Newpage = [[DataPage alloc]init];
            Newpage.page = self.indexPage ++;
            Newpage.rows = KROWS;
            self.conditionModel.page = Newpage;
            [self getSceneLibrarydatas:self.conditionModel isRemove:NO];
        }
zhu's avatar
zhu committed
75 76
    }];

77 78 79
    
    
   }
ZCJ's avatar
ZCJ committed
80 81 82 83 84 85 86 87 88
#pragma mark -获取场景筛选数据
- (void)getdatasAction
{
    [self CreateMBProgressHUDLoding];
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/scene/getSceneFilter"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
        [self RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            self.filter = [[SceneFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
89
            self.arrayData=[NSMutableArray arrayWithArray:self.filter.space];
ZCJ's avatar
ZCJ committed
90 91 92 93 94 95 96 97 98 99 100 101
            [self.seceneTableView reloadData];
        }
        else
            {
            [self ErrorMBProgressView:returnValue[@"message"]];
            }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        [self RemoveMBProgressHUDLoding];
    }];
zhu's avatar
zhu committed
102
}
zhu's avatar
zhu committed
103 104
//
//
ZCJ's avatar
ZCJ committed
105
#pragma mark -获取场景列表数据
zhu's avatar
zhu committed
106
- (void)getSceneLibrarydatas:(SceneCondition *)condition isRemove:(BOOL)remove
zhu's avatar
zhu committed
107
{
ZCJ's avatar
ZCJ committed
108 109 110
    [self CreateMBProgressHUDLoding];
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/scene/query"] WithRequestType:0 WithParameter:condition WithReturnValueBlock:^(id returnValue) {
        
zhu's avatar
zhu committed
111
          [self endRefreshingForTableView:self.collectionView];
ZCJ's avatar
ZCJ committed
112 113
        [self RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
zhu's avatar
zhu committed
114 115 116
//            if (remove) {
//                [self.responseArray removeAllObjects];
//            }
ZCJ's avatar
ZCJ committed
117
            self.response = [[SceneResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
mei's avatar
mei committed
118
             self.totalPages = [returnValue[@"data"][@"totalpages"] intValue];
zhu's avatar
zhu committed
119 120
            NSArray* array=[[NSArray alloc]init];
            array=self.response.list;
ZCJ's avatar
ZCJ committed
121 122 123 124 125 126 127 128 129 130 131 132
            [ self.collectionView reloadData];
        }
        else
            {
            [self ErrorMBProgressView:returnValue[@"message"]];
            }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
        [self RemoveMBProgressHUDLoding];
zhu's avatar
zhu committed
133
          [self endRefreshingForTableView:self.collectionView];
ZCJ's avatar
ZCJ committed
134
    }];
zhu's avatar
zhu committed
135
}
ZCJ's avatar
ZCJ committed
136

zhu's avatar
zhu committed
137 138 139
-(void)initView
{

ZCJ's avatar
ZCJ committed
140
    //    空间
zhu's avatar
zhu committed
141 142 143 144 145
    self.kongJianBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.kongJianBtn.frame=CGRectMake(ScreenWidth-250, 52, 100, 46) ;
    self.kongJianBtn.backgroundColor=[UIColor whiteColor];
    [self.kongJianBtn setTitle:@"空间   " forState:UIControlStateNormal];
    [self.kongJianBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
146 147 148
    self.kongJianBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 55, 0, 0);
    self.kongJianBtn.backgroundColor=RGB(79, 153, 217, 1);
    [self.kongJianBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
zhu's avatar
zhu committed
149 150 151
    [self.kongJianBtn addTarget:self action:@selector(selectedType:) forControlEvents:UIControlEventTouchUpInside];
    self.kongJianBtn.tag=101;
    self.kongJianBtn.layer.masksToBounds = YES;
152
    self.kongJianBtn.layer.cornerRadius = 20;
zhu's avatar
zhu committed
153
    [self.view addSubview:self.kongJianBtn];
ZCJ's avatar
ZCJ committed
154
    //    风格
zhu's avatar
zhu committed
155 156
    self.fengGeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.fengGeBtn.frame=CGRectMake(ScreenWidth-250, 102, 100, 46) ;
ZCJ's avatar
ZCJ committed
157
    self.fengGeBtn.backgroundColor=[UIColor whiteColor];
zhu's avatar
zhu committed
158 159
    [self.fengGeBtn setTitle:@"风格  " forState:UIControlStateNormal];
    [self.fengGeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
ZCJ's avatar
ZCJ committed
160
    
161 162 163
    self.fengGeBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 55, 0, 0);
    self.fengGeBtn.backgroundColor=RGB(225, 225, 225, 1);
    [self.fengGeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
zhu's avatar
zhu committed
164 165 166 167
    [self.fengGeBtn addTarget:self action:@selector(selectedType:) forControlEvents:UIControlEventTouchUpInside];
    self.fengGeBtn.tag=102;
    self.fengGeBtn.layer.masksToBounds = YES;
    self.fengGeBtn.layer.cornerRadius = 15;
zhu's avatar
zhu committed
168
    [self.view addSubview:self.fengGeBtn];
zhu's avatar
zhu committed
169
    
ZCJ's avatar
ZCJ committed
170
    self.subView=[[UIView alloc]initWithFrame:CGRectMake(100, 50, ScreenWidth-300, ScreenHeight-200)];
zhu's avatar
zhu committed
171
    self.subView.backgroundColor=[UIColor whiteColor];
zhu's avatar
zhu committed
172
    [self.view  addSubview:self.subView];
zhu's avatar
zhu committed
173
    
ZCJ's avatar
ZCJ committed
174
    
zhu's avatar
zhu committed
175 176 177 178 179 180
    //点击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(DismissScreenView:)];
    tap.delegate = self;
    tap.cancelsTouchesInView = NO;
    [[UIApplication sharedApplication].keyWindow addGestureRecognizer:tap];
    [self initSubViews];
zhu's avatar
zhu committed
181
   
zhu's avatar
zhu committed
182 183 184 185
}
-(void)initSubViews
{
    self.headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.subView.frame.size.width-100, 50)];
186
    self.headerView.backgroundColor=RGB(225, 225, 225, 1);
zhu's avatar
zhu committed
187 188 189
    [self.subView addSubview:self.headerView];
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(10, 10, 30, 30);
190
    [btn setBackgroundImage:[UIImage imageNamed:@"Folder"] forState:UIControlStateNormal];
zhu's avatar
zhu committed
191 192 193
    [self.headerView addSubview:btn];
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(45, 10, 100, 30)];
    lable.text=@"选择场景";
zhu's avatar
zhu committed
194
    [self.headerView addSubview:lable];
zhu's avatar
zhu committed
195
    self.seceneTableView=[[UITableView alloc]initWithFrame:CGRectMake( self.headerView.frame.size.width, 0, 100, self.subView.frame.size.height)];
196
    self.seceneTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
zhu's avatar
zhu committed
197 198 199
    self.seceneTableView.delegate=self;
    self.seceneTableView.dataSource=self;
    [self.subView addSubview:self.seceneTableView];
zhu's avatar
zhu committed
200 201 202
    //确定是水平滚动,还是垂直滚动
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
zhu's avatar
zhu committed
203
    
zhu's avatar
zhu committed
204 205 206 207 208 209 210 211 212 213
    self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake( 0, 50, self.headerView.frame.size.width, self.subView.frame.size.height-50) collectionViewLayout:flowLayout];
    self.collectionView.dataSource=self;
    self.collectionView.delegate=self;
    [self.collectionView setBackgroundColor:[UIColor clearColor]];
    
    //注册Cell,必须要有
    [self.collectionView registerClass:[SeceneCollectionPictureCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
    
    [self.subView addSubview:self.collectionView];

zhu's avatar
zhu committed
214 215 216
}
-(void)selectedType:(UIButton *)sender
{
217 218 219 220 221 222 223 224 225 226 227 228
    if ([sender.titleLabel.text isEqualToString:self.fengGeBtn.titleLabel.text ]) {
        self.fengGeBtn.backgroundColor=RGB(79, 153, 217, 1);
        [self.fengGeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.kongJianBtn.backgroundColor=RGB(225, 225, 225, 1);
        [self.kongJianBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }else
    {
        self.fengGeBtn.backgroundColor=RGB(225, 225, 225, 1);
        [self.fengGeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.kongJianBtn.backgroundColor=RGB(79, 153, 217, 1);
        [self.kongJianBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
zhu's avatar
zhu committed
229 230 231
    switch (sender.tag) {
        case 101:
//            空间
zhu's avatar
zhu committed
232
            self.arrayData=[NSMutableArray arrayWithArray:self.filter.space];
233
            self.isSelectBtnType=@"space";
zhu's avatar
zhu committed
234 235 236
            break;
        case 102:
//            风格
zhu's avatar
zhu committed
237
             self.arrayData=[NSMutableArray arrayWithArray:self.filter.styles];
238 239
            self.isSelectBtnType=@"style";

zhu's avatar
zhu committed
240 241 242 243 244 245 246 247 248 249
            break;
        case 103:
//            类型
             self.arrayData=self.array3;
            break;
        default:
            break;
    }
    [self.seceneTableView reloadData];
}
zhu's avatar
zhu committed
250 251 252 253
#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
254 255

   return self.response.list.count;
zhu's avatar
zhu committed
256
    
zhu's avatar
zhu committed
257 258 259 260 261 262 263
}

//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"UICollectionViewCell";
    SeceneCollectionPictureCell * cell = (SeceneCollectionPictureCell*)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
ZCJ's avatar
ZCJ committed
264
    cell.model = [self.response.list objectAtIndex_opple:indexPath.item];
zhu's avatar
zhu committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
   
    return cell;
}
#pragma mark --UICollectionViewDelegateFlowLayout
//定义每个Item 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(190, 130);
}

//定义每个UICollectionView 的边距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 0, 20);
}
//定义每个UICollectionView 的纵向间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 2;
}

#pragma mark --UICollectionViewDelegate

//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    SeceneCollectionPictureCell * cell = (SeceneCollectionPictureCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if ([self.delegate respondsToSelector:@selector(addSeceneImage:)]) {
        
        [self.delegate addSeceneImage:cell.imageView.image];
    }
}

//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
zhu's avatar
zhu committed
301
    
zhu's avatar
zhu committed
302
}
zhu's avatar
zhu committed
303 304 305 306 307
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
zhu's avatar
zhu committed
308
{
zhu's avatar
zhu committed
309
          return self.arrayData.count;
zhu's avatar
zhu committed
310
     
zhu's avatar
zhu committed
311 312 313
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
zhu's avatar
zhu committed
314
    
zhu's avatar
zhu committed
315
        return 50;
zhu's avatar
zhu committed
316 317
    
}
zhu's avatar
zhu committed
318 319
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
zhu's avatar
zhu committed
320
           static NSString *cellID = @"ChooseTansferCell";
321
        SecenTableViewCell *cell = (SecenTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID];
zhu's avatar
zhu committed
322
        if (cell == nil) {
323 324
            cell = [[SecenTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
//                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
zhu's avatar
zhu committed
325
        }
326 327 328 329 330 331 332 333
    if ([[[self.arrayData objectAtIndex_opple:indexPath.row] typename] isEqualToString:self.isSelectCell]) {
        cell.contentView.backgroundColor=RGB(221, 221, 221, 1);
        cell.textLabel.textColor=RGB(79, 153, 217, 1) ;
    }else
    {
        cell.contentView.backgroundColor=[UIColor whiteColor];
        cell.textLabel.textColor=[UIColor blackColor];
    }
ZCJ's avatar
ZCJ committed
334
        cell.textLabel.text=[[self.arrayData objectAtIndex_opple:indexPath.row] typename];
zhu's avatar
zhu committed
335 336
        
        return cell;
zhu's avatar
zhu committed
337
    
zhu's avatar
zhu committed
338 339 340 341
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
342 343 344 345 346 347 348 349 350 351 352
    if ([self.isSelectBtnType isEqualToString:@"style"]) {
        self.conditionModel.spaceEquals=nil;
         self.conditionModel.styleEquals=[[self.arrayData objectAtIndex_opple:indexPath.row] typecode];
    }else
    {
        self.conditionModel.styleEquals=nil;
         self.conditionModel.spaceEquals=[[self.arrayData objectAtIndex_opple:indexPath.row] typecode];
    }
    self.isSelectCell=[[self.arrayData objectAtIndex_opple:indexPath.row] typename];
    [self.seceneTableView reloadData];
    [self.collectionView.mj_header beginRefreshing];
zhu's avatar
zhu committed
353 354 355 356 357
}



-(void)DismissScreenView:(UITapGestureRecognizer*)sender{
zhu's avatar
zhu committed
358
    CGPoint point = [sender locationInView:self.view];
zhu's avatar
zhu committed
359
    if (point.x<100 || point.x >ScreenWidth-150||point.y<50||point.y>ScreenHeight-150) {
zhu's avatar
zhu committed
360 361
        
        if (self) {
362 363 364 365
            if ([self.delegate respondsToSelector:@selector(restSeceneBtnImage)]) {
                [self.delegate restSeceneBtnImage];
            }

zhu's avatar
zhu committed
366
            [self.view removeFromSuperview];
zhu's avatar
zhu committed
367 368 369 370
        }
    }
}

zhu's avatar
zhu committed
371 372 373 374 375 376 377 378 379
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end