ProductLibraryViewController.m 26.4 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"
15
#import "ExperienceCentreViewController.h"
曹云霄's avatar
曹云霄 committed
16 17


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

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

曹云霄's avatar
曹云霄 committed
25

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

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

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

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

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

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

勾芒's avatar
勾芒 committed
56 57 58 59 60 61

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

勾芒's avatar
勾芒 committed
62 63 64 65 66
/**
 *  总页数
 */
@property (nonatomic,assign) int totalPages;

67

曹云霄's avatar
曹云霄 committed
68 69
@end

70
@implementation ProductLibraryViewController
曹云霄's avatar
曹云霄 committed
71

曹云霄's avatar
曹云霄 committed
72 73 74 75 76 77 78 79 80 81 82 83 84
/**
 *  初始化筛选数据源
 */
- (NSMutableArray *)screeningDatas
{
    if (_screeningDatas == nil) {
        
        _screeningDatas = [NSMutableArray array];
    }
    return _screeningDatas;
}


勾芒's avatar
勾芒 committed
85 86 87 88 89 90
/**
 *  初始化商品数据源数组
 */
- (NSMutableArray *)datasArray
{
    if (_datasArray == nil) {
勾芒's avatar
勾芒 committed
91
        
勾芒's avatar
勾芒 committed
92
        _datasArray = [NSMutableArray array];
勾芒's avatar
勾芒 committed
93
    }
勾芒's avatar
勾芒 committed
94
    return _datasArray;
勾芒's avatar
勾芒 committed
95
}
96

勾芒's avatar
勾芒 committed
97

98 99 100 101 102 103 104
/**
 *  初始化复选模型
 */
- (GoodsCondition *)condtionModel
{
    if (!_condtionModel) {
        _condtionModel = [[GoodsCondition alloc]init];
曹云霄's avatar
曹云霄 committed
105 106 107 108
        DataPage *page = [[DataPage alloc]init];
        page.page = ONE;
        page.rows = KROWS;
        _condtionModel.page = page;
109 110 111
    }
    return _condtionModel;
}
勾芒's avatar
勾芒 committed
112

曹云霄's avatar
曹云霄 committed
113 114 115
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
曹云霄's avatar
曹云霄 committed
116 117
    
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
118
    [self GetdatasAction];
曹云霄's avatar
曹云霄 committed
119 120
}

121
#pragma mark -获取商品列表数据
勾芒's avatar
勾芒 committed
122
- (void)getGoodsListDatasisRemove:(BOOL)remove Withobject:(GoodsCondition *)conditon
123
{
124
    WS(weakSelf);
125 126
    [self getGoodsListdatas:conditon returnResponse:^(GoodsResponse *response) {
        
127
        if (remove) {
128
            [weakSelf.datasArray removeAllObjects];
129 130 131
        }
        for (TOGoodsEntity *model in response.goodsEntity) {
            [weakSelf.datasArray addObject:model];
132
        }
133
        [weakSelf.productCollectionView reloadData];
134 135 136
    }];
}

曹云霄's avatar
曹云霄 committed
137
#pragma mark -获取产品筛选数据
勾芒's avatar
勾芒 committed
138
- (void)getScreeningdatasisRemoveArray:(BOOL)remove
曹云霄's avatar
曹云霄 committed
139
{
140
    WS(weakSelf);
141
  [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:SERVERREQUESTURL(PRODUCTSCREENING)  WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
142 143
      
      if ([returnValue[@"code"] isEqualToNumber:@0]) {
勾芒's avatar
勾芒 committed
144
          if (remove) {
145
              [weakSelf.screeningDatas removeAllObjects];
勾芒's avatar
勾芒 committed
146
          }
曹云霄's avatar
曹云霄 committed
147
          GoodsFilter *goodsStyle = [[GoodsFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
148 149 150 151 152
          [weakSelf.screeningDatas addObject:goodsStyle.styles];
          [weakSelf.screeningDatas addObject:goodsStyle.categories];
          [weakSelf.screeningDatas addObject:goodsStyle.space];
          [weakSelf.screeningDatas addObject:goodsStyle.material];
          [weakSelf.screeningDatas addObject:goodsStyle.price];
勾芒's avatar
勾芒 committed
153
    }
曹云霄's avatar
曹云霄 committed
154 155
      else
      {
曹云霄's avatar
曹云霄 committed
156
          [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
曹云霄's avatar
曹云霄 committed
157 158
      }
      
159
  }WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
160
      [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
161
  }];
曹云霄's avatar
曹云霄 committed
162 163 164
}


勾芒's avatar
勾芒 committed
165

166 167 168
#pragma mark -获取商品列表数据
- (void)getGoodsListdatas:(GoodsCondition *)conditon returnResponse:(void(^)(GoodsResponse *))finish
{
曹云霄's avatar
曹云霄 committed
169
    [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
170
    WS(weakSelf);
171
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(PRODUCTLIST)  WithRequestType:ZERO WithParameter:conditon WithReturnValueBlock:^(id returnValue) {
172
        
曹云霄's avatar
曹云霄 committed
173 174 175
        weakSelf.productCollectionView.emptyDataSetSource = weakSelf;
        weakSelf.productCollectionView.emptyDataSetDelegate = weakSelf;
        [weakSelf endRefreshingForTableView:weakSelf.productCollectionView];
曹云霄's avatar
曹云霄 committed
176
        [XBLoadingView hideHUDViewWithDefault];
177 178 179
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            GoodsResponse *sponse = [[GoodsResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
曹云霄's avatar
曹云霄 committed
180
            weakSelf.totalPages = [returnValue[@"data"][@"totalpages"] intValue];
181 182 183 184 185
            //返回结果
            finish(sponse);
        }
        else
        {
曹云霄's avatar
曹云霄 committed
186
           [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
187
        }
188
    }WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
189
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
190 191 192
    }];
}

曹云霄's avatar
曹云霄 committed
193 194 195
#pragma mark -布局
- (void)uiConfigAction
{
196
    self.selectedIndex = 9999;//无任何意义
曹云霄's avatar
曹云霄 committed
197 198 199 200 201
    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
202
    self.productCollectionView.delegate = self;
203
    self.productCollectionView.alwaysBounceVertical = YES;
204
    [self CreateScreeningButton];
勾芒's avatar
勾芒 committed
205
}
勾芒's avatar
勾芒 committed
206

勾芒's avatar
勾芒 committed
207 208 209
#pragma mark -获取数据
- (void)GetdatasAction
{
210
    WS(weakSelf);
勾芒's avatar
勾芒 committed
211 212
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
勾芒's avatar
勾芒 committed
213
        //扫描二维码结果
勾芒's avatar
勾芒 committed
214 215
        if (weakSelf.barcode) {
            [weakSelf barCodeSearchRequest];
勾芒's avatar
勾芒 committed
216 217
        }else
        {
曹云霄's avatar
曹云霄 committed
218
            weakSelf.condtionModel.page.page = ONE;
勾芒's avatar
勾芒 committed
219 220
            //搜索
            if (_selectedCode) {
勾芒's avatar
勾芒 committed
221
                switch (weakSelf.selectedIndex) {
222 223
                    case 0://风格
                    {
勾芒's avatar
勾芒 committed
224
                        weakSelf.condtionModel.styleEquals = weakSelf.selectedCode;
225 226 227 228
                    }
                        break;
                    case 1://类型
                    {
勾芒's avatar
勾芒 committed
229
                        weakSelf.condtionModel.categoryEquals = weakSelf.selectedCode;
230 231 232 233
                    }
                        break;
                    case 2://空间
                    {
勾芒's avatar
勾芒 committed
234
                        weakSelf.condtionModel.spaceEquals = weakSelf.selectedCode;
235 236 237 238
                    }
                        break;
                    case 3://材质
                    {
勾芒's avatar
勾芒 committed
239
                        weakSelf.condtionModel.materialEqueals = weakSelf.selectedCode;
240 241 242 243 244
                    }
                        break;
                    case 4://价格
                    {
                        //价格字符串切割
勾芒's avatar
勾芒 committed
245
                        NSArray *spacrArray = [weakSelf.selectedCode componentsSeparatedByString:@"到"];
246 247
                        weakSelf.condtionModel.startprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
                        weakSelf.condtionModel.endprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
248 249 250
                    }
                        break;
                    default:
勾芒's avatar
勾芒 committed
251
                        weakSelf.condtionModel.nameLike = weakSelf.selectedCode;
252 253
                        break;
                }
勾芒's avatar
勾芒 committed
254
            }
勾芒's avatar
勾芒 committed
255 256 257
            [weakSelf.productCollectionView.mj_footer resetNoMoreData];
            [weakSelf getScreeningdatasisRemoveArray:YES];
            [weakSelf getGoodsListDatasisRemove:YES Withobject:self.condtionModel];
勾芒's avatar
勾芒 committed
258 259 260 261 262 263 264 265
        }
    }];
    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
266
        //扫描二维码结果
勾芒's avatar
勾芒 committed
267 268
        if (weakSelf.barcode) {
            [weakSelf barCodeSearchRequest];
勾芒's avatar
勾芒 committed
269 270
        }else
        {
曹云霄's avatar
曹云霄 committed
271
            if ( ++ weakSelf.condtionModel.page.page > weakSelf.totalPages) {
勾芒's avatar
勾芒 committed
272
                [weakSelf.productCollectionView.mj_footer endRefreshingWithNoMoreData];
勾芒's avatar
勾芒 committed
273 274 275 276
            }else
            {
                //搜索
                if (_selectedCode) {
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
                    switch (weakSelf.selectedIndex) {
                        case 0://风格
                        {
                            weakSelf.condtionModel.styleEquals = weakSelf.selectedCode;
                        }
                            break;
                        case 1://类型
                        {
                            weakSelf.condtionModel.categoryEquals = weakSelf.selectedCode;
                        }
                            break;
                        case 2://空间
                        {
                            weakSelf.condtionModel.spaceEquals = weakSelf.selectedCode;
                        }
                            break;
                        case 3://材质
                        {
                            weakSelf.condtionModel.materialEqueals = weakSelf.selectedCode;
                        }
                            break;
                        case 4://价格
                        {
                            //价格字符串切割
                            NSArray *spacrArray = [weakSelf.selectedCode componentsSeparatedByString:@"到"];
302 303
                            weakSelf.condtionModel.startprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
                            weakSelf.condtionModel.endprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
304 305 306 307 308 309
                        }
                            break;
                        default:
                            weakSelf.condtionModel.nameLike = weakSelf.selectedCode;
                            break;
                    }
勾芒's avatar
勾芒 committed
310
                }
勾芒's avatar
勾芒 committed
311
                [weakSelf getGoodsListDatasisRemove:NO Withobject:self.condtionModel];
勾芒's avatar
勾芒 committed
312 313 314
            }
        }
    }];
曹云霄's avatar
曹云霄 committed
315
    self.productCollectionView.mj_footer.automaticallyHidden = YES;
曹云霄's avatar
曹云霄 committed
316 317 318
}


勾芒's avatar
勾芒 committed
319 320 321
#pragma mark 填条形码搜索
- (void)barCodeSearchRequest
{
322
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
323
    [XBLoadingView showHUDViewWithDefault];
324
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(BARCODESEARCH),_barcode]  WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
325
        
326
        [weakSelf endRefreshingForTableView:self.productCollectionView];
曹云霄's avatar
曹云霄 committed
327
        [XBLoadingView hideHUDViewWithDefault];
勾芒's avatar
勾芒 committed
328
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
勾芒's avatar
勾芒 committed
329
            
勾芒's avatar
勾芒 committed
330
            if ([returnValue[@"data"] isKindOfClass:[NSNull class]]) {
曹云霄's avatar
曹云霄 committed
331
                [XBLoadingView showHUDViewWithText:@"暂无商品信息"];
勾芒's avatar
勾芒 committed
332 333
                return;
            }
勾芒's avatar
勾芒 committed
334
            TOGoodsEntity *goods = [[TOGoodsEntity alloc]initWithDictionary:returnValue[@"data"] error:nil];
335 336 337
            [weakSelf.datasArray removeAllObjects];
            [weakSelf.datasArray addObject:goods];
            [weakSelf.productCollectionView reloadData];
勾芒's avatar
勾芒 committed
338 339
        }else
        {
曹云霄's avatar
曹云霄 committed
340
            [XBLoadingView showHUDViewWithText:@"查询失败"];
勾芒's avatar
勾芒 committed
341
        }
342
    }WithFailureBlock:^(id error) {
勾芒's avatar
勾芒 committed
343
        
344
        [weakSelf endRefreshingForTableView:self.productCollectionView];
曹云霄's avatar
曹云霄 committed
345 346
        [XBLoadingView hideHUDViewWithDefault];
        [XBLoadingView showHUDViewWithText:@"查询失败"];
勾芒's avatar
勾芒 committed
347
    }];
勾芒's avatar
勾芒 committed
348 349
}

勾芒's avatar
勾芒 committed
350

曹云霄's avatar
曹云霄 committed
351
#pragma mark -筛选按钮
352
- (void)CreateScreeningButton
曹云霄's avatar
曹云霄 committed
353
{
354 355
    UIButton *ScreeningButton = [UIButton buttonWithType:UIButtonTypeSystem];
    ScreeningButton.frame = CGRectMake(ScreenWidth-100, ScreenHeight*6/10, 50, 50);
曹云霄's avatar
曹云霄 committed
356 357 358 359 360 361 362 363 364 365 366
    
    //阴影层
    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];
    
    //筛选按钮
367 368 369 370 371 372 373 374 375
    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];
    [ScreeningButton addTarget:self action:@selector(ScreeningButtonClick) forControlEvents:UIControlEventTouchUpInside];
    ScreeningButton.backgroundColor = kMainBlueColor;
    [self.view addSubview:ScreeningButton];
曹云霄's avatar
曹云霄 committed
376 377 378 379 380 381 382
    
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ProductCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"productcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
383
    TOGoodsEntity *model = [self.datasArray objectAtIndex_opple:indexPath.item];
384 385
    cell.model = model;
    cell.cellindex = indexPath.row;
勾芒's avatar
勾芒 committed
386
    //加入购物车
曹云霄's avatar
曹云霄 committed
387
    WS(weakSelf);
勾芒's avatar
勾芒 committed
388
    __weak typeof(ProductCollectionViewCell *) weakCell = cell;
389
    [cell setReturnCellCgpoint:^void(CGPoint centerPoint,NSInteger cellindex ,CGSize size) {
勾芒's avatar
勾芒 committed
390 391
        //判断是否有当前客户
        if (![Shoppersmanager manager].currentCustomer) {
曹云霄's avatar
曹云霄 committed
392
            [XBLoadingView showHUDViewWithText:@"必须设置当前客户"];
勾芒's avatar
勾芒 committed
393 394
            return;
        }
曹云霄's avatar
曹云霄 committed
395
        //库存为0时不能加入购物车
曹云霄's avatar
曹云霄 committed
396
        if (model.number == 0) {
曹云霄's avatar
曹云霄 committed
397
            [XBLoadingView showHUDViewWithText:@"此商品库存不足"];
曹云霄's avatar
曹云霄 committed
398 399
            return;
        }
曹云霄's avatar
曹云霄 committed
400
        TOGoodsEntity *model = [weakSelf.datasArray objectAtIndex_opple:cellindex];
曹云霄's avatar
曹云霄 committed
401
        [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
402
        [weakSelf addGoodsShoppingbags:model complate:^{
勾芒's avatar
勾芒 committed
403
            NSLog(@"加入购物车完成");
曹云霄's avatar
曹云霄 committed
404
            [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
405
            [weakSelf StartAddShoppingCarAnimationWithimage:weakCell.productImageView.image withStartpoint:centerPoint withSize:size];
勾芒's avatar
勾芒 committed
406 407
        }];
    }];
曹云霄's avatar
曹云霄 committed
408 409 410
    return cell;
}

勾芒's avatar
勾芒 committed
411 412

#pragma mark -开发加入购物车动画
413
- (void)StartAddShoppingCarAnimationWithimage:(UIImage *)image withStartpoint:(CGPoint)point withSize:(CGSize)size
勾芒's avatar
勾芒 committed
414
{
曹云霄's avatar
曹云霄 committed
415
    //起点
勾芒's avatar
勾芒 committed
416
    CGPoint startPoint = point;
曹云霄's avatar
曹云霄 committed
417
    //终点
勾芒's avatar
勾芒 committed
418
    CGPoint endPoint = SHARED_APPDELEGATE.shoppingCarPoint;
曹云霄's avatar
曹云霄 committed
419
    //控点
勾芒's avatar
勾芒 committed
420
    CGPoint controlPoint = CGPointMake(endPoint.x, startPoint.x);
421 422 423

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    imageView.backgroundColor = kTCColor(252, 248, 239);
勾芒's avatar
勾芒 committed
424
    imageView.image = image;
425 426
    imageView.center = point;
    [self.view.window.layer addSublayer:imageView.layer];
勾芒's avatar
勾芒 committed
427
    
428 429 430 431 432 433 434 435 436
    //路径曲线
    UIBezierPath *movePath = [UIBezierPath bezierPath];
    [movePath moveToPoint:imageView.center];
    [movePath addQuadCurveToPoint:endPoint
                     controlPoint:controlPoint];
    //关键帧
    CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    moveAnim.path = movePath.CGPath;
    moveAnim.removedOnCompletion = YES;
勾芒's avatar
勾芒 committed
437
    
438
    //缩小变化
439 440 441 442 443
    CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
    scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    //x,y轴缩小到0.1,Z 轴不变
    scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
    scaleAnim.removedOnCompletion = YES;
勾芒's avatar
勾芒 committed
444
    
445 446 447 448 449
    //透明度变化
    CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
    opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
    opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
    opacityAnim.removedOnCompletion = YES;
勾芒's avatar
勾芒 committed
450
    
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
    //关键帧,旋转,透明度组合起来执行
    CAAnimationGroup *animGroup = [CAAnimationGroup animation];
    //当动画完成,停留到结束位置
    animGroup.removedOnCompletion = NO;
    animGroup.fillMode = kCAFillModeForwards;
    animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim,opacityAnim, nil];
    animGroup.duration = 1;
    animGroup.delegate = self;
    [imageView.layer addAnimation:animGroup forKey:nil];
    [self performSelector:@selector(removeFromLayer:) withObject:imageView.layer afterDelay:1];

}

#pragma mark -动画完成后移除
- (void)removeFromLayer:(CALayer *)layerAnimation{
勾芒's avatar
勾芒 committed
466
    
467
    [layerAnimation removeFromSuperlayer];
勾芒's avatar
勾芒 committed
468 469 470 471 472 473
}


#pragma mark -完成加入购物车动画完成后回调
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
474
    [[NSNotificationCenter defaultCenter]postNotificationName:REFRESHSHOPPINGCAR object:@(1)];
勾芒's avatar
勾芒 committed
475 476
}

曹云霄's avatar
曹云霄 committed
477 478
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
479
    return self.datasArray.count;
曹云霄's avatar
曹云霄 committed
480 481
}

曹云霄's avatar
曹云霄 committed
482 483
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
484
    ProductDetailsViewController *productDetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"productdetails"];
勾芒's avatar
勾芒 committed
485
    productDetails.goodsID = [[self.datasArray objectAtIndex_opple:indexPath.item] fid];
曹云霄's avatar
曹云霄 committed
486 487
    [self.navigationController pushViewController:productDetails animated:YES];
}
曹云霄's avatar
曹云霄 committed
488 489


曹云霄's avatar
曹云霄 committed
490 491 492
#pragma mark -筛选
- (void)ScreeningButtonClick
{
勾芒's avatar
勾芒 committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 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];
    self.screenView.delegate = self;
    //点击手势
    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];
    self.selectedIndex = 0;
    [self CreateClassificationView];
    [UIView animateWithDuration:0.2 animations:^{
        self.screenView.alpha = 1;
    }];
曹云霄's avatar
曹云霄 committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
}


#pragma mark -分类、筛选view切换
- (void)sortingSegmentedClick:(UISegmentedControl *)sender {
    
    switch (sender.selectedSegmentIndex) {
        case 0://分类
        {
            [self.screenSecondView removeFromSuperview];
            [self CreateClassificationView];
        }
            break;
        case 1://筛选
        {
            [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);
543
    self.screenFirstView.delegate = self;
544
    [self ScreeningButtonClick:self.selectedIndex];
曹云霄's avatar
曹云霄 committed
545 546 547
    [self.screenView.backgroundView addSubview:self.screenFirstView];
}

曹云霄's avatar
曹云霄 committed
548

曹云霄's avatar
曹云霄 committed
549 550 551 552 553
#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
554
    self.screenSecondView.delegate = self;
555
    [self ScreeningButtonClick:self.selectedIndex];
勾芒's avatar
勾芒 committed
556
    self.screenSecondView.totalNumber = self.datasArray.count;
曹云霄's avatar
曹云霄 committed
557 558
    [self.screenView.backgroundView addSubview:self.screenSecondView];
}
曹云霄's avatar
曹云霄 committed
559

曹云霄's avatar
曹云霄 committed
560 561

#pragma mark -ScreeningButtonClickdelegate代理
562
- (void)ScreeningButtonClick:(NSInteger)buttontag
曹云霄's avatar
曹云霄 committed
563
{
564
    self.selectedIndex = buttontag;
曹云霄's avatar
曹云霄 committed
565 566 567 568 569 570 571 572
    //分类
    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)
    {
573
        self.screenSecondView.selectedIndex = buttontag;
曹云霄's avatar
曹云霄 committed
574
        self.screenSecondView.datasArray = [self.screeningDatas objectAtIndex_opple:buttontag];
曹云霄's avatar
曹云霄 committed
575 576 577
    }
}

578
#pragma mark -选中条件
579
- (void)selectedItem:(NSString *)typecode withTitle:(NSString *)title
580
{
勾芒's avatar
勾芒 committed
581
    [self emptyModel];
582

583
    [self DismissScreenView];
584 585 586 587 588 589
    if (self.selectedIndex == 4) {
        self.selectedCode = title;
    }else
    {
      self.selectedCode = typecode;
    }
590
    [self.productCollectionView.mj_header beginRefreshing];
591 592 593
}


曹云霄's avatar
曹云霄 committed
594 595 596
#pragma mark -筛选子模块的
- (void)tableSelectedindex:(NSInteger)index
{
597
    
598
    [self ScreeningButtonClick:index];
曹云霄's avatar
曹云霄 committed
599 600 601
    self.screenView.indexselected = index;
    
}
曹云霄's avatar
曹云霄 committed
602 603


604 605 606 607 608 609 610 611 612 613
#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];
614 615
    page.rows = 10;
    page.page = 1;
616
    condition.page = page;
617
    if (![[self class] isBlankString:styleCode]) {
曹云霄's avatar
曹云霄 committed
618 619
       condition.styleEquals = styleCode;
    }
620
    if (![[self class] isBlankString:categoriesCode]) {
曹云霄's avatar
曹云霄 committed
621 622
       condition.categoryEquals = categoriesCode;
    }
623
    if (![[self class] isBlankString:spaceCode]) {
曹云霄's avatar
曹云霄 committed
624 625
        condition.spaceEquals = spaceCode;
    }
626
    if (![[self class] isBlankString:materialCode]) {
曹云霄's avatar
曹云霄 committed
627 628
        condition.materialEqueals = materialCode;
    }
曹云霄's avatar
曹云霄 committed
629 630 631
    if (![priceTitle isEqualToString:@"全部"]) {
        //价格字符串切割
        NSArray *spacrArray = [priceTitle componentsSeparatedByString:@"到"];
632 633
        condition.startprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
        condition.endprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
曹云霄's avatar
曹云霄 committed
634
    }
635 636 637 638 639 640 641
    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;//清空单选
642
    WS(weakSelf);
643 644
    [self getGoodsListdatas:condition returnResponse:^(GoodsResponse *response) {
        
645
        weakSelf.screenSecondView.totalNumber = response.total;
646
        //临时保存
647
        weakSelf.temporaryArray = response;
648 649
    }];
}
曹云霄's avatar
曹云霄 committed
650 651


652 653 654 655 656
#pragma mark -显示筛选后的结果
- (void)ShowScreeningResponse
{
    if (self.temporaryArray.goodsEntity.count == 0) {
        
曹云霄's avatar
曹云霄 committed
657
        [XBLoadingView showHUDViewWithText:@"暂无数据"];
658 659 660 661 662
    }else
    {
        self.datasArray = [NSMutableArray arrayWithArray:self.temporaryArray.goodsEntity];
        [self.productCollectionView reloadData];
        [self DismissScreenView];
663 664 665
    }
}

曹云霄's avatar
曹云霄 committed
666

曹云霄's avatar
曹云霄 committed
667 668 669 670 671 672 673 674 675
#pragma mark -移除筛选框
- (void)DismissScreenView
{
    [UIView animateWithDuration:0.2 animations:^{
        self.screenView.alpha = 0;
    }completion:^(BOOL finished) {
        [self.screenView removeFromSuperview];
    }];
}
曹云霄's avatar
曹云霄 committed
676

曹云霄's avatar
曹云霄 committed
677

曹云霄's avatar
曹云霄 committed
678 679 680 681 682 683 684 685 686
#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
687 688


勾芒's avatar
勾芒 committed
689 690 691 692
#pragma mark -添加至购物车
- (void)addGoodsShoppingbags:(TOGoodsEntity *)model complate:(void(^)())response
{
    SaveShoppingCartRequest *shopCar = [[SaveShoppingCartRequest alloc]init];
勾芒's avatar
勾芒 committed
693
    shopCar.consumerId = [Customermanager manager].model.fid;
勾芒's avatar
勾芒 committed
694
    shopCar.goodsId = model.fid;
695
    shopCar.count = @"1";
696
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(ADDSHOPPINGBAG)  WithRequestType:ZERO WithParameter:shopCar WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
697 698 699 700
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            response();
        }else
        {
曹云霄's avatar
曹云霄 committed
701
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
702
        }
703
    }WithFailureBlock:^(id error) {
曹云霄's avatar
曹云霄 committed
704 705
        [XBLoadingView hideHUDViewWithDefault];
        [XBLoadingView showHUDViewWithText:@"加入购物车失败"];
706

勾芒's avatar
勾芒 committed
707 708
    }];
}
勾芒's avatar
勾芒 committed
709 710 711



勾芒's avatar
勾芒 committed
712 713 714
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
曹云霄's avatar
曹云霄 committed
715
    return kNoDataImage;
勾芒's avatar
勾芒 committed
716 717
}

曹云霄's avatar
曹云霄 committed
718 719 720 721
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}
勾芒's avatar
勾芒 committed
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
}


#pragma mark -清空模型
- (void)emptyModel
{
    self.condtionModel.nameLike = nil;
    self.condtionModel.styleEquals = nil;
    self.condtionModel.spaceEquals = nil;
    self.condtionModel.categoryEquals = nil;
    self.condtionModel.startprice = nil;
    self.condtionModel.endprice = nil;
    self.condtionModel.materialEqueals = nil;
}


曹云霄's avatar
曹云霄 committed
742 743
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
744 745
    [[SDImageCache sharedImageCache] clearDisk];
    NSLog(@"结算到内存警告");
曹云霄's avatar
曹云霄 committed
746 747 748 749 750 751 752 753 754 755 756 757 758 759
    // 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