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

#import "ProductLibraryView.h"

11

zhu's avatar
zhu committed
12
@implementation ProductLibraryView
13 14 15 16 17 18 19 20 21 22 23
/**
 *  初始化商品数据源数组
 */
- (NSMutableArray *)datasArray
{
    if (_datasArray == nil) {
        
        _datasArray = [NSMutableArray array];
    }
    return _datasArray;
}
zhu's avatar
zhu committed
24 25
- (void)viewDidLoad {
    [self initdata];
ZCJ's avatar
ZCJ committed
26
    [self getScreeningdatas];
zhu's avatar
zhu committed
27 28
    [self initSubView];

zhu's avatar
zhu committed
29
}
ZCJ's avatar
ZCJ committed
30 31 32 33 34 35 36 37 38 39 40
/**
 *  初始化筛选数据源
 */
- (NSMutableArray *)screeningDatas
{
    if (_screeningDatas == nil) {
        
        _screeningDatas = [NSMutableArray array];
    }
    return _screeningDatas;
}
zhu's avatar
zhu committed
41 42 43 44 45 46 47 48 49

//- (instancetype)initWithFrame:(CGRect)frame
//{
//    if (self = [super initWithFrame:frame]) {
//        [self initdata];
//        [self initSubView];
//    }
//    return self;
//}
zhu's avatar
zhu committed
50 51 52
-(void)initdata
{
    self.arrayData=[[NSMutableArray alloc]init];
53 54
    self.nameData=[[NSMutableArray alloc]initWithObjects:@"风格",@"类型",@"空间",@"材质",@"价格",nil];
   
zhu's avatar
zhu committed
55
}
ZCJ's avatar
ZCJ committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
//#pragma mark -热门搜索
//- (void)setSelectedCode:(NSString *)selectedCode
//{
//    _selectedCode = selectedCode;
//    //默认数据
//    GoodsCondition *conditon = [[GoodsCondition alloc]init];
//    //分页数据
//    DataPage *Newpage = [[DataPage alloc]init];
//    Newpage.page = 0;
//    conditon.page = Newpage;
//    conditon.categoryEquals = _selectedCode;
//
//    __weak typeof(self)weakSelf = self;
//    [self getGoodsListdatas:conditon returnResponse:^(GoodsResponse *response) {
//
//        if (response.goodsEntity.count == 0) {
//
//            [self ErrorMBProgressView:@"暂无数据"];
//        }else
//            {
//            weakSelf.datasArray = response;
//            [weakSelf.productCollectionView reloadData];
//            }
//    }];
//
//}

#pragma mark -获取商品列表数据
- (void)getGoodsListDatas
{

    //默认数据
    GoodsCondition *conditon = [[GoodsCondition alloc]init];
    //分页数据
    DataPage *Newpage = [[DataPage alloc]init];
    Newpage.page = 0;
    conditon.page = Newpage;

    __weak typeof(self)weakSelf = self;
    [self getGoodsListdatas:conditon returnResponse:^(GoodsResponse *response) {

        if (response.goodsEntity.count == 0) {

            [self ErrorMBProgressView:@"暂无数据"];

        }else
            {
103 104 105 106 107
                for (TOGoodsEntity *model in response.goodsEntity) {
                    [self.datasArray addObject:model];
                }

            
ZCJ's avatar
ZCJ committed
108 109 110 111 112 113 114 115 116 117
//            [weakSelf.productCollectionView reloadData];
            }
    }];
}

#pragma mark -获取产品筛选数据
- (void)getScreeningdatas
{

    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/goods/getGoodsFilter"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
zhu's avatar
zhu committed
118

ZCJ's avatar
ZCJ committed
119 120 121
        if ([returnValue[@"code"] isEqualToNumber:@0]) {

            GoodsFilter *goodsStyle = [[GoodsFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
122 123 124
            self.goodsFilter=goodsStyle;
            self.arrayData=self.goodsFilter.styles;
            [self.seceneTableView reloadData];
ZCJ's avatar
ZCJ committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
        }
        else
            {
            [self ErrorMBProgressView:returnValue[@"message"]];
            }

    } WithErrorCodeBlock:^(id errorCodeValue) {

    } WithFailureBlock:^(id error) {

        NSLog(@"%@",error);
    }];
}



#pragma mark -获取商品列表数据
- (void)getGoodsListdatas:(GoodsCondition *)conditon returnResponse:(void(^)(GoodsResponse *))finish
{

    [self CreateMBProgressHUDLoding];
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/goods/query"] WithRequestType:0 WithParameter:conditon WithReturnValueBlock:^(id returnValue) {

        [self RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {

            GoodsResponse *sponse = [[GoodsResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
            //返回结果
            finish(sponse);
        }
        else
            {
            [self ErrorMBProgressView:@"暂无数据"];
            }

    } WithErrorCodeBlock:^(id errorCodeValue) {

    } WithFailureBlock:^(id error) {

        [self RemoveMBProgressHUDLoding];
    }];
}
//#pragma mark -获取商品详情
//- (void)getGoodsListDetails
//
//{
//    [self CreateMBProgressHUDLoding];
//    NSString *url = [NSString stringWithFormat:@"%@%@%@",ServerAddress,@"/goods/getGoods/",_goodsID];
//    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:url WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
//
//        [self RemoveMBProgressHUDLoding];
//        if ([returnValue[@"code"] isEqualToNumber:@0]) {
//
//            self.entity = [[TOGoodsEntity alloc]initWithDictionary:returnValue[@"data"] error:nil];
//            [self HeaderViewAssignment];
//            [self.productDetilsTableview reloadData];
//        }
//        else
//            {
//            [self ErrorMBProgressView:returnValue[@"message"]];
//            }
//
//
//
//    } WithErrorCodeBlock:^(id errorCodeValue) {
//
//
//    } WithFailureBlock:^(id error) {
//
//        [self RemoveMBProgressHUDLoding];
//        NSLog(@"%@",error);
//    }];
//}
zhu's avatar
zhu committed
198 199 200 201 202
-(void)initSubView
{
    for (int i=0; i<self.nameData.count; i++) {
        if (i !=5) {
            UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
203
            btn.frame=CGRectMake(ScreenWidth-250, 52+i*50, 100, 46) ;
zhu's avatar
zhu committed
204 205
            btn.backgroundColor=[UIColor whiteColor];
            [btn setTitle:[self.nameData objectAtIndex:i] forState:UIControlStateNormal];
206
             btn.contentEdgeInsets = UIEdgeInsetsMake(0, 40, 0, 0);
zhu's avatar
zhu committed
207 208 209 210
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(selectedType:) forControlEvents:UIControlEventTouchUpInside];
            btn.tag=100 +i;
            btn.layer.masksToBounds = YES;
211
            btn.layer.cornerRadius = 25;
zhu's avatar
zhu committed
212
            [self.view addSubview:btn];
zhu's avatar
zhu committed
213 214 215 216 217
        }
       
    }
    self.subView=[[UIView alloc]initWithFrame:CGRectMake(100, 50, ScreenWidth-300, ScreenHeight-200)];
    self.subView.backgroundColor=[UIColor whiteColor];
zhu's avatar
zhu committed
218
    [self.view  addSubview:self.subView];
zhu's avatar
zhu committed
219 220 221 222 223 224 225

    //点击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(DismissScreenView:)];
    tap.delegate = self;
    tap.cancelsTouchesInView = NO;
    [[UIApplication sharedApplication].keyWindow addGestureRecognizer:tap];
    [self initSubViews];
ZCJ's avatar
ZCJ committed
226 227
    [self  getGoodsListDatas];
    
zhu's avatar
zhu committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
}


-(void)initSubViews
{
    self.headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.subView.frame.size.width-100, 50)];
    self.headerView.backgroundColor=[UIColor grayColor];
    [self.subView addSubview:self.headerView];
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(10, 10, 30, 30);
    [btn setBackgroundImage:[UIImage imageNamed:@"changjingtubiao"] forState:UIControlStateNormal];
    [self.headerView addSubview:btn];
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(45, 10, 100, 30)];
    lable.text=@"选择产品";
    [self.headerView addSubview:lable];
    self.seceneTableView=[[UITableView alloc]initWithFrame:CGRectMake( self.headerView.frame.size.width, 0, 100, self.subView.frame.size.height)];
    self.seceneTableView.delegate=self;
    self.seceneTableView.dataSource=self;
    [self.subView addSubview:self.seceneTableView];
    
zhu's avatar
zhu committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261
 
    //确定是水平滚动,还是垂直滚动
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    
    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:[ProductCollectionPictureCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
    
    [self.subView addSubview:self.collectionView];
ZCJ's avatar
ZCJ committed
262
    
zhu's avatar
zhu committed
263 264 265 266 267 268 269
}
-(void)selectedType:(UIButton *)sender
{

            switch (sender.tag) {
                case 100:
                    //            风格
270
                    self.arrayData=self.goodsFilter.styles;
zhu's avatar
zhu committed
271 272 273
                    break;
                case 101:
                    //            类型
274
                    self.arrayData=self.goodsFilter.categories;
zhu's avatar
zhu committed
275 276 277
                    break;
                case 102:
                    //            空间
278
                    self.arrayData=self.goodsFilter.space;
zhu's avatar
zhu committed
279 280 281
                    break;
                case 103:
                    //            材质
282
                    self.arrayData=self.goodsFilter.material;
zhu's avatar
zhu committed
283 284 285
                    break;
                case 104:
                    //            价格
286
                    self.arrayData=self.goodsFilter.price;
zhu's avatar
zhu committed
287
                    break;
288
              
zhu's avatar
zhu committed
289 290 291 292 293
                default:
                    break;
            }
    [self.seceneTableView reloadData];
}
zhu's avatar
zhu committed
294 295 296 297
#pragma mark -- UICollectionViewDataSource
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
298 299 300 301 302 303 304 305 306 307 308
    if (self.datasArray.count/3==0 && self.datasArray.count%3!=0 ) {
        return 1;
    }else
    {
        if (self.datasArray.count%3==0) {
            return self.datasArray.count/3;
        }else{
            return self.datasArray.count/3 +1;
        }
        
    }
zhu's avatar
zhu committed
309 310 311 312 313 314 315 316 317 318 319 320
}
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"UICollectionViewCell";
    ProductCollectionPictureCell * cell = (ProductCollectionPictureCell*)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
321 322
    [cell.productImageView sd_setImageWithURL:[NSURL URLWithString:[[self.datasArray objectAtIndex_opple:indexPath.row] pictures]] placeholderImage:REPLACEIMAGE];

zhu's avatar
zhu committed
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 351 352 353 354 355 356 357 358 359 360 361
    
    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
{
    ProductCollectionPictureCell * cell = (ProductCollectionPictureCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if ([self.delegate respondsToSelector:@selector(addProductImage:)]) {
        
        [self.delegate addProductImage:cell.productImageView.image];
    }

}

//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

zhu's avatar
zhu committed
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{    if ([tableView isEqual:self.seceneTableView])
{
    return self.arrayData.count;
}else
{
    return 5;
}
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([tableView isEqual:self.seceneTableView])
    {
        return 50;
    }else
    {
        return 150;
    }
    
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
zhu's avatar
zhu committed
392
           static NSString *cellID = @"ChooseTansferCell";
zhu's avatar
zhu committed
393 394 395 396 397
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
         
        }
398 399 400 401 402 403 404
    if ([[self.arrayData objectAtIndex_opple:indexPath.row]isKindOfClass:[GoodsCategory class]]) {
        cell.textLabel.text=[[self.arrayData objectAtIndex_opple:indexPath.row] name];
    }else
    {//类型是多级的这里要改动
        cell.textLabel.text=[[self.arrayData objectAtIndex_opple:indexPath.row] typename];
    }
    
zhu's avatar
zhu committed
405
//        05产品库-详情_03
zhu's avatar
zhu committed
406 407 408 409 410 411
        return cell;
        
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
412
    [self getGoodsListDatas];
zhu's avatar
zhu committed
413 414 415
}

-(void)DismissScreenView:(UITapGestureRecognizer*)sender{
zhu's avatar
zhu committed
416
    CGPoint point = [sender locationInView:self.view];
zhu's avatar
zhu committed
417 418 419
    if (point.x<100 || point.x >ScreenWidth-100||point.y<50||point.y>ScreenHeight-150) {
        
        if (self) {
zhu's avatar
zhu committed
420
            [self.view removeFromSuperview];
zhu's avatar
zhu committed
421 422 423
        }
    }
}
zhu's avatar
zhu committed
424 425 426 427 428 429 430 431 432 433

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end