ProductLibraryViewController.m 24.2 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1
//
2
//  ProductLibraryViewController.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 "ProductLibraryViewController.h"
曹云霄's avatar
曹云霄 committed
10
#import "ProductCollectionViewCell.h"
曹云霄's avatar
曹云霄 committed
11
#import "ProductDetailsViewController.h"
曹云霄's avatar
曹云霄 committed
12 13 14
#import "ScreeningView.h"
#import "screeningFirstView.h"
#import "screeningSecondView.h"
曹云霄's avatar
曹云霄 committed
15 16


17
@interface ProductLibraryViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UIGestureRecognizerDelegate,ScreeningButtonClickdelegate,TableviewSelectedIndexdelegate,SelectedCollectionItemDelegate>
曹云霄's avatar
曹云霄 committed
18

曹云霄's avatar
曹云霄 committed
19 20 21 22
/**
 *  筛选背景框View
 */
@property (nonatomic,strong) ScreeningView *screenView;
曹云霄's avatar
曹云霄 committed
23

曹云霄's avatar
曹云霄 committed
24

曹云霄's avatar
曹云霄 committed
25 26 27 28 29 30 31 32 33
/**
 *  分类View
 */
@property (nonatomic,strong) screeningFirstView *screenFirstView;

/**
 *  筛选View
 */
@property (nonatomic,strong) screeningSecondView *screenSecondView;
曹云霄's avatar
曹云霄 committed
34

曹云霄's avatar
曹云霄 committed
35 36 37 38 39
/**
 *  筛选数据源
 */
@property (nonatomic,strong) NSMutableArray *screeningDatas;

40 41 42 43 44 45 46 47
/**
 *  当前筛选按钮选中状态
 */
@property (nonatomic,assign) NSInteger selectedIndex;

/**
 *  商品数据源对象
 */
勾芒's avatar
勾芒 committed
48
@property (nonatomic,strong) NSMutableArray *datasArray;
49 50 51 52 53 54

/**
 *  复选返回时临时保存数据
 */
@property (nonatomic,strong) GoodsResponse *temporaryArray;

勾芒's avatar
勾芒 committed
55 56 57 58 59 60 61 62 63 64
/**
 *  当前页数
 */
@property (nonatomic,assign) int indexPage;

/**
 *  搜索结果个数
 */
@property (nonatomic,assign) int resultCount;

勾芒's avatar
勾芒 committed
65 66 67 68 69
/**
 *  总页数
 */
@property (nonatomic,assign) int totalPages;

70

71

勾芒's avatar
勾芒 committed
72 73 74 75




曹云霄's avatar
曹云霄 committed
76 77
@end

78
@implementation ProductLibraryViewController
曹云霄's avatar
曹云霄 committed
79

曹云霄's avatar
曹云霄 committed
80 81 82 83 84 85 86 87 88 89 90 91 92
/**
 *  初始化筛选数据源
 */
- (NSMutableArray *)screeningDatas
{
    if (_screeningDatas == nil) {
        
        _screeningDatas = [NSMutableArray array];
    }
    return _screeningDatas;
}


勾芒's avatar
勾芒 committed
93 94 95 96 97 98
/**
 *  初始化商品数据源数组
 */
- (NSMutableArray *)datasArray
{
    if (_datasArray == nil) {
勾芒's avatar
勾芒 committed
99
        
勾芒's avatar
勾芒 committed
100
        _datasArray = [NSMutableArray array];
勾芒's avatar
勾芒 committed
101
    }
勾芒's avatar
勾芒 committed
102
    return _datasArray;
勾芒's avatar
勾芒 committed
103
}
104

勾芒's avatar
勾芒 committed
105

106 107 108 109 110 111 112 113 114 115
/**
 *  初始化复选模型
 */
- (GoodsCondition *)condtionModel
{
    if (!_condtionModel) {
        _condtionModel = [[GoodsCondition alloc]init];
    }
    return _condtionModel;
}
勾芒's avatar
勾芒 committed
116

曹云霄's avatar
曹云霄 committed
117 118 119
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
120
    self.view.backgroundColor = [UIColor blueColor];
曹云霄's avatar
曹云霄 committed
121 122
    
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
123
    [self GetdatasAction];
勾芒's avatar
勾芒 committed
124
    
曹云霄's avatar
曹云霄 committed
125 126
}

曹云霄's avatar
曹云霄 committed
127

勾芒's avatar
勾芒 committed
128

129
#pragma mark -获取商品列表数据
勾芒's avatar
勾芒 committed
130
- (void)getGoodsListDatasisRemove:(BOOL)remove Withobject:(GoodsCondition *)conditon
131 132 133 134 135 136 137 138
{
    
    __weak typeof(self)weakSelf = self;
    [self getGoodsListdatas:conditon returnResponse:^(GoodsResponse *response) {
        
        if (response.goodsEntity.count == 0) {
            
            [self ErrorMBProgressView:@"暂无数据"];
勾芒's avatar
勾芒 committed
139 140 141
            
        }else
        {
勾芒's avatar
勾芒 committed
142 143 144 145 146 147
            if (remove) {
                [self.datasArray removeAllObjects];
            }
            for (TOGoodsEntity *model in response.goodsEntity) {
                [weakSelf.datasArray addObject:model];
            }
勾芒's avatar
勾芒 committed
148
            [weakSelf.productCollectionView reloadData];
149 150 151 152
        }
    }];
}

曹云霄's avatar
曹云霄 committed
153
#pragma mark -获取产品筛选数据
勾芒's avatar
勾芒 committed
154
- (void)getScreeningdatasisRemoveArray:(BOOL)remove
曹云霄's avatar
曹云霄 committed
155 156
{
    
曹云霄's avatar
曹云霄 committed
157 158 159 160
  [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/goods/getGoodsFilter"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
      
      if ([returnValue[@"code"] isEqualToNumber:@0]) {
          
勾芒's avatar
勾芒 committed
161 162 163
          if (remove) {
              [self.screeningDatas removeAllObjects];
          }
曹云霄's avatar
曹云霄 committed
164 165 166 167 168 169
          GoodsFilter *goodsStyle = [[GoodsFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
          [self.screeningDatas addObject:goodsStyle.styles];
          [self.screeningDatas addObject:goodsStyle.categories];
          [self.screeningDatas addObject:goodsStyle.space];
          [self.screeningDatas addObject:goodsStyle.material];
          [self.screeningDatas addObject:goodsStyle.price];
勾芒's avatar
勾芒 committed
170
    }
曹云霄's avatar
曹云霄 committed
171 172 173 174 175 176 177 178 179 180 181
      else
      {
          [self ErrorMBProgressView:returnValue[@"message"]];
      }
      
  } WithErrorCodeBlock:^(id errorCodeValue) {
      
  } WithFailureBlock:^(id error) {
      
      NSLog(@"%@",error);
  }];
曹云霄's avatar
曹云霄 committed
182 183 184
}


勾芒's avatar
勾芒 committed
185

186 187 188
#pragma mark -获取商品列表数据
- (void)getGoodsListdatas:(GoodsCondition *)conditon returnResponse:(void(^)(GoodsResponse *))finish
{
勾芒's avatar
勾芒 committed
189
    
190 191 192
    [self CreateMBProgressHUDLoding];
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/goods/query"] WithRequestType:0 WithParameter:conditon WithReturnValueBlock:^(id returnValue) {
        
勾芒's avatar
勾芒 committed
193
        [self endRefreshingForTableView:self.productCollectionView];
194 195 196 197
        [self RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            GoodsResponse *sponse = [[GoodsResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
勾芒's avatar
勾芒 committed
198
            self.totalPages = (int)returnValue[@"data"][@"totalPages"];
199 200 201 202 203
            //返回结果
            finish(sponse);
        }
        else
        {
勾芒's avatar
勾芒 committed
204
           [self ErrorMBProgressView:@"暂无数据"];
205 206 207 208
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
勾芒's avatar
勾芒 committed
209 210
        [self ErrorMBProgressView:@"网络连接中断"];
        [self RemoveMBProgressHUDLoding];
211 212
    } WithFailureBlock:^(id error) {
        
勾芒's avatar
勾芒 committed
213
        [self endRefreshingForTableView:self.productCollectionView];
214 215 216 217 218
        [self RemoveMBProgressHUDLoding];
    }];
}


曹云霄's avatar
曹云霄 committed
219 220 221
#pragma mark -布局
- (void)uiConfigAction
{
勾芒's avatar
勾芒 committed
222
    self.indexPage = 1;
曹云霄's avatar
曹云霄 committed
223 224 225 226 227
    self.productCollectionLayout.itemSize = CGSizeMake((ScreenWidth-100)/3, (ScreenWidth-100)/3);
    self.productCollectionLayout.sectionInset = UIEdgeInsetsMake(20, 30, 20, 30);
    self.productCollectionLayout.minimumLineSpacing = 20;
    self.productCollectionLayout.minimumInteritemSpacing = 20;
    self.productCollectionView.dataSource = self;
曹云霄's avatar
曹云霄 committed
228
    self.productCollectionView.delegate = self;
229
    self.productCollectionView.alwaysBounceVertical = YES;
曹云霄's avatar
曹云霄 committed
230
    [self CreatescreeningButton];
勾芒's avatar
勾芒 committed
231
}
勾芒's avatar
勾芒 committed
232

勾芒's avatar
勾芒 committed
233 234 235 236 237 238
#pragma mark -获取数据
- (void)GetdatasAction
{
    
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
勾芒's avatar
勾芒 committed
239 240 241 242 243 244 245 246 247 248 249 250
        
        //扫描二维码结果
        if (self.barcode) {
            
            [self barCodeSearchRequest];
            
        }else
        {
            //分页数据
            DataPage *Newpage = [[DataPage alloc]init];
            Newpage.page = 1;
            Newpage.rows = KROWS;
251
            self.condtionModel.page = Newpage;
勾芒's avatar
勾芒 committed
252 253 254
            self.indexPage = 1;
            //搜索
            if (_selectedCode) {
255 256 257 258 259 260 261 262 263 264 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
                switch (self.selectedIndex) {
                    case 0://风格
                    {
                        self.condtionModel.styleEquals = self.selectedCode;
                    }
                        break;
                    case 1://类型
                    {
                        self.condtionModel.categoryEquals = self.selectedCode;
                    }
                        break;
                    case 2://空间
                    {
                        self.condtionModel.spaceEquals = self.selectedCode;
                    }
                        break;
                    case 3://材质
                    {
                        self.condtionModel.materialEqueals = self.selectedCode;
                    }
                        break;
                    case 4://价格
                    {
                        //价格字符串切割
                        NSArray *spacrArray = [self.selectedCode componentsSeparatedByString:@"到"];
                        self.condtionModel.startprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
                        self.condtionModel.endprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
                        self.condtionModel.categoryEquals = _selectedCode;
                    }
                        break;
                        
                    default:
                        break;
                }
                
勾芒's avatar
勾芒 committed
290 291 292
            }
            [self.productCollectionView.mj_footer resetNoMoreData];
            [self getScreeningdatasisRemoveArray:YES];
293
            [self getGoodsListDatasisRemove:YES Withobject:self.condtionModel];
勾芒's avatar
勾芒 committed
294 295 296 297 298 299 300 301 302 303
        }
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.productCollectionView.mj_header = headerRefresh;
    [self.productCollectionView.mj_header beginRefreshing];
    
    //上拉加载
    self.productCollectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
勾芒's avatar
勾芒 committed
304 305 306 307 308
        //扫描二维码结果
        if (self.barcode) {
            
            [self barCodeSearchRequest];
            
勾芒's avatar
勾芒 committed
309 310
        }else
        {
311

勾芒's avatar
勾芒 committed
312 313 314 315
            if (self.indexPage ++ > self.totalPages) {
                [self.productCollectionView.mj_footer endRefreshingWithNoMoreData];
            }else
            {
316 317
                //分页数据
                DataPage *Newpage = [[DataPage alloc]init];
勾芒's avatar
勾芒 committed
318 319
                Newpage.page = self.indexPage ++;
                Newpage.rows = KROWS;
320
                self.condtionModel.page = Newpage;
勾芒's avatar
勾芒 committed
321 322
                //搜索
                if (_selectedCode) {
323
                    self.condtionModel.categoryEquals = _selectedCode;
勾芒's avatar
勾芒 committed
324
                }
325
                [self getGoodsListDatasisRemove:NO Withobject:self.condtionModel];
勾芒's avatar
勾芒 committed
326 327 328
            }
        }
    }];
曹云霄's avatar
曹云霄 committed
329 330 331
}


勾芒's avatar
勾芒 committed
332 333 334
#pragma mark 填条形码搜索
- (void)barCodeSearchRequest
{
勾芒's avatar
勾芒 committed
335
    [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
336
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@%@",ServerAddress,@"/goods/getGoodsByCode/",_barcode] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
337
        
338
        [self endRefreshingForTableView:self.productCollectionView];
勾芒's avatar
勾芒 committed
339
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
340
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
勾芒's avatar
勾芒 committed
341
            
勾芒's avatar
勾芒 committed
342 343 344 345
            if ([returnValue[@"data"] isKindOfClass:[NSNull class]]) {
                [self ErrorMBProgressView:@"暂无商品信息"];
                return;
            }
勾芒's avatar
勾芒 committed
346
            TOGoodsEntity *goods = [[TOGoodsEntity alloc]initWithDictionary:returnValue[@"data"] error:nil];
勾芒's avatar
勾芒 committed
347 348 349
            [self.datasArray removeAllObjects];
            [self.datasArray addObject:goods];
            [self.productCollectionView reloadData];
勾芒's avatar
勾芒 committed
350
            
勾芒's avatar
勾芒 committed
351 352
        }else
        {
勾芒's avatar
勾芒 committed
353
            [self ErrorMBProgressView:@"查询失败"];
勾芒's avatar
勾芒 committed
354 355 356 357
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
358
        [self endRefreshingForTableView:self.productCollectionView];
勾芒's avatar
勾芒 committed
359 360
        [self ErrorMBProgressView:@"网络连接中断"];
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
361 362 363
        
    } WithFailureBlock:^(id error) {
        
勾芒's avatar
勾芒 committed
364
        [self ErrorMBProgressView:@"查询失败"];
365
        [self endRefreshingForTableView:self.productCollectionView];
勾芒's avatar
勾芒 committed
366
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
367
    }];
勾芒's avatar
勾芒 committed
368 369
}

勾芒's avatar
勾芒 committed
370

曹云霄's avatar
曹云霄 committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393

#pragma mark -筛选按钮
- (void)CreatescreeningButton
{
    UIButton *screeningbutton = [UIButton buttonWithType:UIButtonTypeSystem];
    screeningbutton.frame = CGRectMake(ScreenWidth-100, ScreenHeight*6/10, 50, 50);
    
    //阴影层
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(ScreenWidth-97.5, ScreenHeight*6/10+2.5, 45, 45);//保证layer的size比筛选按钮高宽都短5像素
    layer.backgroundColor = [UIColor blackColor].CGColor;
    layer.shadowOffset = CGSizeMake(0, 8);
    layer.shadowOpacity = 0.7;
    layer.cornerRadius = 25;
    [self.view.layer addSublayer:layer];
    
    //筛选按钮
    screeningbutton.layer.masksToBounds = YES;
    screeningbutton.layer.cornerRadius = 25;
    [screeningbutton setTitle:@"筛选" forState:UIControlStateNormal];
    screeningbutton.titleLabel.font = [UIFont systemFontOfSize:15];
    [screeningbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [screeningbutton setTitleColor:kMainBlueColor forState:UIControlStateSelected];
曹云霄's avatar
曹云霄 committed
394
    [screeningbutton addTarget:self action:@selector(ScreeningButtonClick) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
395 396 397 398 399 400 401 402 403
    screeningbutton.backgroundColor = kMainBlueColor;
    [self.view addSubview:screeningbutton];
    
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ProductCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"productcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
404 405
    TOGoodsEntity *model = [self.datasArray objectAtIndex_opple:indexPath.item];
    NSArray *imageArray = [model.pictures componentsSeparatedByString:@","];
勾芒's avatar
勾芒 committed
406
    [cell.productImageView sd_setImageWithURL:[NSURL URLWithString:[imageArray firstObject]] placeholderImage:REPLACEIMAGE];
勾芒's avatar
勾芒 committed
407
    cell.productPrice.text = [NSString stringWithFormat:@"¥%@",model.tagPrice];
勾芒's avatar
勾芒 committed
408
    cell.cellindex = indexPath.item;
勾芒's avatar
勾芒 committed
409 410 411
    
    cell.productParameter.text = model.name;
    cell.specifications.text = [NSString stringWithFormat:@"%@(%@)",model.code,model.size];
勾芒's avatar
勾芒 committed
412
    
勾芒's avatar
勾芒 committed
413 414
    //加入购物车
    __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
415
    __weak typeof(ProductCollectionViewCell *) weakCell = cell;
勾芒's avatar
勾芒 committed
416 417 418 419 420 421 422 423 424 425 426 427
    [cell setReturnCellCgpoint:^void(CGPoint centerPoint,NSInteger cellindex) {
        
        //判断是否有当前客户
        if (![Shoppersmanager manager].currentCustomer) {
            
            [self ErrorMBProgressView:@"必须设置当前客户"];
            return;
        }
        TOGoodsEntity *model = [self.datasArray objectAtIndex_opple:cellindex];
        [self addGoodsShoppingbags:model complate:^{
            NSLog(@"加入购物车完成");
        }];
勾芒's avatar
勾芒 committed
428
        [weakSelf StartAddShoppingCarAnimationWithimage:weakCell.productImageView.image withStartpoint:centerPoint];
勾芒's avatar
勾芒 committed
429
    }];
曹云霄's avatar
曹云霄 committed
430 431 432
    return cell;
}

勾芒's avatar
勾芒 committed
433 434 435 436 437 438 439 440 441 442 443 444

#pragma mark -开发加入购物车动画
- (void)StartAddShoppingCarAnimationWithimage:(UIImage *)image withStartpoint:(CGPoint)point
{
    //起点
    CGPoint startPoint = point;
    //终点
    CGPoint endPoint = SHARED_APPDELEGATE.shoppingCarPoint;
    //控点
    CGPoint controlPoint = CGPointMake(endPoint.x, startPoint.x);
    
    
勾芒's avatar
勾芒 committed
445
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 60, 42)];
勾芒's avatar
勾芒 committed
446
    imageView.layer.position = point;
勾芒's avatar
勾芒 committed
447 448
//    imageView.layer.masksToBounds = YES;
//    imageView.layer.cornerRadius = 50;
勾芒's avatar
勾芒 committed
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
    imageView.tag = 100;
    imageView.image = image;
    
    [self.view.layer addSublayer:imageView.layer];
    
    //创建关键帧
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.delegate = self;
    //动画时间
    animation.duration = 1;
    
    //当动画完成,停留到结束位置
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    
    //当方法名字遇到create,new,copy,retain,都需要管理内存
    CGMutablePathRef path = CGPathCreateMutable();
    //设置起点
    CGPathMoveToPoint(path, NULL, startPoint.x, startPoint.y);
    CGPathAddQuadCurveToPoint(path, NULL, controlPoint.x, controlPoint.y, endPoint.x,endPoint.y);
    
    //设置动画路径
    animation.path = path;
    
    //执行动画
    [imageView.layer addAnimation:animation forKey:nil];
    
    //释放路径
    CGPathRelease(path);
}


#pragma mark -完成加入购物车动画完成后回调
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    NSLog(@"动画完成了");
勾芒's avatar
勾芒 committed
485
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ADDGOODSNUMBER" object:@(1)];
勾芒's avatar
勾芒 committed
486 487 488 489
}



曹云霄's avatar
曹云霄 committed
490 491
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
492
    return self.datasArray.count;
曹云霄's avatar
曹云霄 committed
493 494
}

曹云霄's avatar
曹云霄 committed
495 496 497 498 499
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
    ProductDetailsViewController *productDetails = [storyboard instantiateViewControllerWithIdentifier:@"productdetails"];
勾芒's avatar
勾芒 committed
500
    productDetails.goodsID = [[self.datasArray objectAtIndex_opple:indexPath.item] fid];
曹云霄's avatar
曹云霄 committed
501 502
    [self.navigationController pushViewController:productDetails animated:YES];
}
曹云霄's avatar
曹云霄 committed
503 504


曹云霄's avatar
曹云霄 committed
505 506 507
#pragma mark -筛选
- (void)ScreeningButtonClick
{
勾芒's avatar
勾芒 committed
508

曹云霄's avatar
曹云霄 committed
509 510 511
    self.screenView = [[[NSBundle mainBundle] loadNibNamed:@"ScreeningView" owner:self options:nil]firstObject];
    self.screenView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    self.screenView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
曹云霄's avatar
曹云霄 committed
512
    self.screenView.delegate = self;
曹云霄's avatar
曹云霄 committed
513 514 515 516 517 518 519 520 521 522 523 524
    //点击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(DismissScreenView)];
    tap.delegate = self;
    tap.cancelsTouchesInView = NO;
    [self.screenView addGestureRecognizer:tap];
    self.screenView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [self.view.window addSubview:self.screenView];
    self.screenView.alpha = 0;
    
    //监听Segmented菜单
    [self.screenView.sortingSegmented addTarget:self action:@selector(sortingSegmentedClick:) forControlEvents:UIControlEventValueChanged];
    
525
    self.selectedIndex = 0;
曹云霄's avatar
曹云霄 committed
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
    [self CreateClassificationView];
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.screenView.alpha = 1;
    }];
}


#pragma mark -分类、筛选view切换
- (void)sortingSegmentedClick:(UISegmentedControl *)sender {
    
    switch (sender.selectedSegmentIndex) {
        case 0://分类
        {
541
//            self.selectedIndex = 0;
曹云霄's avatar
曹云霄 committed
542 543 544 545 546 547
            [self.screenSecondView removeFromSuperview];
            [self CreateClassificationView];
        }
            break;
        case 1://筛选
        {
548
//            self.selectedIndex = 0;
曹云霄's avatar
曹云霄 committed
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
            [self.screenFirstView removeFromSuperview];
            [self CreateScreenSubView];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark -创建分类View
- (void)CreateClassificationView
{
    //分类View
    self.screenFirstView = [[[NSBundle mainBundle] loadNibNamed:@"screeningFirstView" owner:self options:nil] firstObject];
    self.screenFirstView.frame = CGRectMake(0, 50, 470, 310);
565
    self.screenFirstView.delegate = self;
566
    [self screeningButtonClick:self.selectedIndex];
曹云霄's avatar
曹云霄 committed
567 568 569
    [self.screenView.backgroundView addSubview:self.screenFirstView];
}

曹云霄's avatar
曹云霄 committed
570

曹云霄's avatar
曹云霄 committed
571 572 573 574 575
#pragma mark -创建筛选选项View
- (void)CreateScreenSubView
{
    self.screenSecondView = [[[NSBundle mainBundle] loadNibNamed:@"screeningSecondView" owner:self options:nil] firstObject];
    self.screenSecondView.frame = CGRectMake(0, 50, 470, 310);
曹云霄's avatar
曹云霄 committed
576
    self.screenSecondView.delegate = self;
577
    [self screeningButtonClick:self.selectedIndex];
勾芒's avatar
勾芒 committed
578
    self.screenSecondView.totalNumber = self.datasArray.count;
曹云霄's avatar
曹云霄 committed
579 580
    [self.screenView.backgroundView addSubview:self.screenSecondView];
}
曹云霄's avatar
曹云霄 committed
581

曹云霄's avatar
曹云霄 committed
582 583 584 585 586


#pragma mark -ScreeningButtonClickdelegate代理
- (void)screeningButtonClick:(NSInteger)buttontag
{
587
    self.selectedIndex = buttontag;
曹云霄's avatar
曹云霄 committed
588 589 590 591 592 593 594 595 596
    //分类
    if (self.screenView.sortingSegmented.selectedSegmentIndex == 0) {
        
        self.screenFirstView.selectedIndex = buttontag;
        self.screenFirstView.datasArray = [self.screeningDatas objectAtIndex_opple:buttontag];
    }
    //筛选
    else if (self.screenView.sortingSegmented.selectedSegmentIndex == 1)
    {
597
        self.screenSecondView.selectedIndex = buttontag;
曹云霄's avatar
曹云霄 committed
598
        self.screenSecondView.datasArray = [self.screeningDatas objectAtIndex_opple:buttontag];
曹云霄's avatar
曹云霄 committed
599 600 601
    }
}

602
#pragma mark -选中条件
603
- (void)selectedItem:(NSString *)typecode withTitle:(NSString *)title
604 605
{
    [self DismissScreenView];
606 607 608 609 610 611
    if (self.selectedIndex == 4) {
        self.selectedCode = title;
    }else
    {
      self.selectedCode = typecode;
    }
612
    [self.productCollectionView.mj_header beginRefreshing];
613 614 615 616
}



曹云霄's avatar
曹云霄 committed
617

曹云霄's avatar
曹云霄 committed
618 619 620
#pragma mark -筛选子模块的
- (void)tableSelectedindex:(NSInteger)index
{
621
    
曹云霄's avatar
曹云霄 committed
622 623 624 625
    [self screeningButtonClick:index];
    self.screenView.indexselected = index;
    
}
曹云霄's avatar
曹云霄 committed
626 627


628 629 630 631 632 633 634 635 636 637
#pragma mark -筛选复选模块选中的uicollection cell
- (void)collectionSelectedindexWithStyleCode:(NSString *)styleCode
                              withCategories:(NSString *)categoriesCode
                                   withSpace:(NSString *)spaceCode
                                withMaterial:(NSString *)materialCode
                                   withPrice:(NSString *)priceTitle
{
    
    GoodsCondition *condition = [[GoodsCondition alloc]init];
    DataPage *page = [[DataPage alloc]init];
638 639
    page.rows = 10;
    page.page = 1;
640
    condition.page = page;
曹云霄's avatar
曹云霄 committed
641 642 643 644 645 646 647 648 649 650 651 652
    if (styleCode.length != 0) {
       condition.styleEquals = styleCode;
    }
    if (categoriesCode.length != 0) {
       condition.categoryEquals = categoriesCode;
    }
    if (spaceCode.length!= 0) {
        condition.spaceEquals = spaceCode;
    }
    if (materialCode.length!= 0) {
        condition.materialEqueals = materialCode;
    }
曹云霄's avatar
曹云霄 committed
653 654 655 656 657 658 659
    if (![priceTitle isEqualToString:@"全部"]) {
     
        //价格字符串切割
        NSArray *spacrArray = [priceTitle componentsSeparatedByString:@"到"];
        condition.startprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
        condition.endprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
    }
660 661 662 663 664 665 666 667 668 669
    
    self.condtionModel.styleEquals = condition.styleEquals;
    self.condtionModel.categoryEquals = condition.categoryEquals;
    self.condtionModel.spaceEquals = condition.spaceEquals;
    self.condtionModel.materialEqueals = condition.materialEqueals;
    self.condtionModel.startprice = condition.startprice;
    self.condtionModel.endprice = condition.endprice;
    self.selectedCode = nil;//清空单选
    
//    [self.productCollectionView.mj_header beginRefreshing];
670 671 672 673 674 675 676 677
    __weak typeof (self) Weakself = self;
    [self getGoodsListdatas:condition returnResponse:^(GoodsResponse *response) {
        
        Weakself.screenSecondView.totalNumber = response.total;
        //临时保存
        self.temporaryArray = response;
    }];
}
曹云霄's avatar
曹云霄 committed
678 679


680 681 682 683 684 685 686 687
#pragma mark -显示筛选后的结果
- (void)ShowScreeningResponse
{
    if (self.temporaryArray.goodsEntity.count == 0) {
        
        [self ErrorMBProgressView:@"暂无数据"];
        return;
    }
勾芒's avatar
勾芒 committed
688
    self.datasArray = [NSMutableArray arrayWithArray:self.temporaryArray.goodsEntity];
689 690 691 692
    [self.productCollectionView reloadData];
    [self DismissScreenView];
}

曹云霄's avatar
曹云霄 committed
693

曹云霄's avatar
曹云霄 committed
694 695 696 697 698 699 700 701 702 703 704 705
#pragma mark -移除筛选框
- (void)DismissScreenView
{
    [UIView animateWithDuration:0.2 animations:^{
        
        self.screenView.alpha = 0;
        
    }completion:^(BOOL finished) {
        
        [self.screenView removeFromSuperview];
    }];
}
曹云霄's avatar
曹云霄 committed
706

曹云霄's avatar
曹云霄 committed
707

曹云霄's avatar
曹云霄 committed
708 709 710 711 712 713 714 715 716 717
#pragma mark -UIGestureRecognizerDelegate代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    //取消子视图的的时间穿透,否则子视图的点击无效,会被传递到父视图响应
    if (CGRectContainsPoint(self.screenView.backgroundView.frame, [touch locationInView:self.screenView])) {
        
        return NO;
    }
    return YES;
}
曹云霄's avatar
曹云霄 committed
718 719


勾芒's avatar
勾芒 committed
720 721 722 723 724
//#pragma mark -释放
//- (void)dealloc
//{
//    [[NSNotificationCenter defaultCenter]removeObserver:self];
//}
勾芒's avatar
勾芒 committed
725 726


勾芒's avatar
勾芒 committed
727 728 729 730 731 732 733
#pragma mark -添加至购物车
- (void)addGoodsShoppingbags:(TOGoodsEntity *)model complate:(void(^)())response
{

    SaveShoppingCartRequest *shopCar = [[SaveShoppingCartRequest alloc]init];
    shopCar.consumerId = [[Customermanager manager] customerID];
    shopCar.goodsId = model.fid;
734
    shopCar.count = @"1";
勾芒's avatar
勾芒 committed
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/shopcart/save"] WithRequestType:0 WithParameter:shopCar WithReturnValueBlock:^(id returnValue) {
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            response();
            
        }else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        [self ErrorMBProgressView:@"加入购物车失败"];
    }];
}
勾芒's avatar
勾芒 committed
752 753 754



曹云霄's avatar
曹云霄 committed
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
- (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