ProductLibraryViewController.m 27.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"
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 62 63 64 65
/**
 *  当前页数
 */
@property (nonatomic,assign) int indexPage;

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

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

71

曹云霄's avatar
曹云霄 committed
72 73
@end

74
@implementation ProductLibraryViewController
曹云霄's avatar
曹云霄 committed
75

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


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

勾芒's avatar
勾芒 committed
101

102 103 104 105 106 107 108 109 110 111
/**
 *  初始化复选模型
 */
- (GoodsCondition *)condtionModel
{
    if (!_condtionModel) {
        _condtionModel = [[GoodsCondition alloc]init];
    }
    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) WithCallClass:weakSelf WithRequestType:1 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
      {
156
          [weakSelf ErrorMBProgressView:returnValue[@"message"]];
曹云霄's avatar
曹云霄 committed
157 158 159
      }
      
  } WithErrorCodeBlock:^(id errorCodeValue) {
160
      [weakSelf ErrorMBProgressView:NETWORK];
勾芒's avatar
勾芒 committed
161
  } WithFailureBlock:^(NSError *error) {
162
      [weakSelf ErrorMBProgressView:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
163
  }];
曹云霄's avatar
曹云霄 committed
164 165 166
}


勾芒's avatar
勾芒 committed
167

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

曹云霄's avatar
曹云霄 committed
199 200 201
#pragma mark -布局
- (void)uiConfigAction
{
202
    self.indexPage = ONE;
203
    self.selectedIndex = 9999;//无任何意义
曹云霄's avatar
曹云霄 committed
204 205 206 207 208
    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
209
    self.productCollectionView.delegate = self;
210
    self.productCollectionView.alwaysBounceVertical = YES;
211
    [self CreateScreeningButton];
勾芒's avatar
勾芒 committed
212
}
勾芒's avatar
勾芒 committed
213

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


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

勾芒's avatar
勾芒 committed
369

曹云霄's avatar
曹云霄 committed
370
#pragma mark -筛选按钮
371
- (void)CreateScreeningButton
曹云霄's avatar
曹云霄 committed
372
{
373 374
    UIButton *ScreeningButton = [UIButton buttonWithType:UIButtonTypeSystem];
    ScreeningButton.frame = CGRectMake(ScreenWidth-100, ScreenHeight*6/10, 50, 50);
曹云霄's avatar
曹云霄 committed
375 376 377 378 379 380 381 382 383 384 385
    
    //阴影层
    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];
    
    //筛选按钮
386 387 388 389 390 391 392 393 394
    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
395 396 397 398 399 400 401
    
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ProductCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"productcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
402
    TOGoodsEntity *model = [self.datasArray objectAtIndex_opple:indexPath.item];
403 404
    cell.model = model;
    cell.cellindex = indexPath.row;
勾芒's avatar
勾芒 committed
405
    //加入购物车
曹云霄's avatar
曹云霄 committed
406
    WS(weakSelf);
勾芒's avatar
勾芒 committed
407
    __weak typeof(ProductCollectionViewCell *) weakCell = cell;
408
    [cell setReturnCellCgpoint:^void(CGPoint centerPoint,NSInteger cellindex ,CGSize size) {
勾芒's avatar
勾芒 committed
409 410
        //判断是否有当前客户
        if (![Shoppersmanager manager].currentCustomer) {
曹云霄's avatar
曹云霄 committed
411
            [weakSelf ErrorMBProgressView:@"必须设置当前客户"];
勾芒's avatar
勾芒 committed
412 413
            return;
        }
曹云霄's avatar
曹云霄 committed
414
        //库存为0时不能加入购物车
曹云霄's avatar
曹云霄 committed
415 416
        if (model.number == 0) {
            [weakSelf ErrorMBProgressView:@"此商品库存不足"];
曹云霄's avatar
曹云霄 committed
417 418
            return;
        }
曹云霄's avatar
曹云霄 committed
419
        TOGoodsEntity *model = [weakSelf.datasArray objectAtIndex_opple:cellindex];
420
        [weakSelf CreateMBProgressHUDLoding];
曹云霄's avatar
曹云霄 committed
421
        [weakSelf addGoodsShoppingbags:model complate:^{
勾芒's avatar
勾芒 committed
422
            NSLog(@"加入购物车完成");
423
            [weakSelf RemoveMBProgressHUDLoding];
曹云霄's avatar
曹云霄 committed
424
            [weakSelf StartAddShoppingCarAnimationWithimage:weakCell.productImageView.image withStartpoint:centerPoint withSize:size];
勾芒's avatar
勾芒 committed
425 426
        }];
    }];
曹云霄's avatar
曹云霄 committed
427 428 429
    return cell;
}

勾芒's avatar
勾芒 committed
430 431

#pragma mark -开发加入购物车动画
432
- (void)StartAddShoppingCarAnimationWithimage:(UIImage *)image withStartpoint:(CGPoint)point withSize:(CGSize)size
勾芒's avatar
勾芒 committed
433
{
曹云霄's avatar
曹云霄 committed
434
    //起点
勾芒's avatar
勾芒 committed
435
    CGPoint startPoint = point;
曹云霄's avatar
曹云霄 committed
436
    //终点
勾芒's avatar
勾芒 committed
437
    CGPoint endPoint = SHARED_APPDELEGATE.shoppingCarPoint;
曹云霄's avatar
曹云霄 committed
438
    //控点
勾芒's avatar
勾芒 committed
439
    CGPoint controlPoint = CGPointMake(endPoint.x, startPoint.x);
440 441 442

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    imageView.backgroundColor = kTCColor(252, 248, 239);
勾芒's avatar
勾芒 committed
443
    imageView.image = image;
444 445
    imageView.center = point;
    [self.view.window.layer addSublayer:imageView.layer];
勾芒's avatar
勾芒 committed
446
    
447 448 449 450 451 452 453 454 455
    //路径曲线
    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
456
    
457
    //缩小变化
458 459 460 461 462
    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
463
    
464 465 466 467 468
    //透明度变化
    CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
    opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
    opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
    opacityAnim.removedOnCompletion = YES;
勾芒's avatar
勾芒 committed
469
    
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
    //关键帧,旋转,透明度组合起来执行
    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
485
    
486
    [layerAnimation removeFromSuperlayer];
勾芒's avatar
勾芒 committed
487 488 489 490 491 492
}


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

曹云霄's avatar
曹云霄 committed
496 497
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
498
    return self.datasArray.count;
曹云霄's avatar
曹云霄 committed
499 500
}

曹云霄's avatar
曹云霄 committed
501 502
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
503
    ProductDetailsViewController *productDetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"productdetails"];
勾芒's avatar
勾芒 committed
504
    productDetails.goodsID = [[self.datasArray objectAtIndex_opple:indexPath.item] fid];
曹云霄's avatar
曹云霄 committed
505 506
    [self.navigationController pushViewController:productDetails animated:YES];
}
曹云霄's avatar
曹云霄 committed
507 508


曹云霄's avatar
曹云霄 committed
509 510 511
#pragma mark -筛选
- (void)ScreeningButtonClick
{
勾芒's avatar
勾芒 committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
    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
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
}


#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);
562
    self.screenFirstView.delegate = self;
563
    [self ScreeningButtonClick:self.selectedIndex];
曹云霄's avatar
曹云霄 committed
564 565 566
    [self.screenView.backgroundView addSubview:self.screenFirstView];
}

曹云霄's avatar
曹云霄 committed
567

曹云霄's avatar
曹云霄 committed
568 569 570 571 572
#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
573
    self.screenSecondView.delegate = self;
574
    [self ScreeningButtonClick:self.selectedIndex];
勾芒's avatar
勾芒 committed
575
    self.screenSecondView.totalNumber = self.datasArray.count;
曹云霄's avatar
曹云霄 committed
576 577
    [self.screenView.backgroundView addSubview:self.screenSecondView];
}
曹云霄's avatar
曹云霄 committed
578

曹云霄's avatar
曹云霄 committed
579 580

#pragma mark -ScreeningButtonClickdelegate代理
581
- (void)ScreeningButtonClick:(NSInteger)buttontag
曹云霄's avatar
曹云霄 committed
582
{
583
    self.selectedIndex = buttontag;
曹云霄's avatar
曹云霄 committed
584 585 586 587 588 589 590 591
    //分类
    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)
    {
592
        self.screenSecondView.selectedIndex = buttontag;
曹云霄's avatar
曹云霄 committed
593
        self.screenSecondView.datasArray = [self.screeningDatas objectAtIndex_opple:buttontag];
曹云霄's avatar
曹云霄 committed
594 595 596
    }
}

597
#pragma mark -选中条件
598
- (void)selectedItem:(NSString *)typecode withTitle:(NSString *)title
599
{
勾芒's avatar
勾芒 committed
600
    [self emptyModel];
601

602
    [self DismissScreenView];
603 604 605 606 607 608
    if (self.selectedIndex == 4) {
        self.selectedCode = title;
    }else
    {
      self.selectedCode = typecode;
    }
609
    [self.productCollectionView.mj_header beginRefreshing];
610 611 612
}


曹云霄's avatar
曹云霄 committed
613 614 615
#pragma mark -筛选子模块的
- (void)tableSelectedindex:(NSInteger)index
{
616
    
617
    [self ScreeningButtonClick:index];
曹云霄's avatar
曹云霄 committed
618 619 620
    self.screenView.indexselected = index;
    
}
曹云霄's avatar
曹云霄 committed
621 622


623 624 625 626 627 628 629 630 631 632
#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];
633 634
    page.rows = 10;
    page.page = 1;
635
    condition.page = page;
636
    if (![[self class] isBlankString:styleCode]) {
曹云霄's avatar
曹云霄 committed
637 638
       condition.styleEquals = styleCode;
    }
639
    if (![[self class] isBlankString:categoriesCode]) {
曹云霄's avatar
曹云霄 committed
640 641
       condition.categoryEquals = categoriesCode;
    }
642
    if (![[self class] isBlankString:spaceCode]) {
曹云霄's avatar
曹云霄 committed
643 644
        condition.spaceEquals = spaceCode;
    }
645
    if (![[self class] isBlankString:materialCode]) {
曹云霄's avatar
曹云霄 committed
646 647
        condition.materialEqueals = materialCode;
    }
曹云霄's avatar
曹云霄 committed
648 649 650
    if (![priceTitle isEqualToString:@"全部"]) {
        //价格字符串切割
        NSArray *spacrArray = [priceTitle componentsSeparatedByString:@"到"];
651 652
        condition.startprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
        condition.endprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
曹云霄's avatar
曹云霄 committed
653
    }
654 655 656 657 658 659 660
    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;//清空单选
661
    WS(weakSelf);
662 663
    [self getGoodsListdatas:condition returnResponse:^(GoodsResponse *response) {
        
664
        weakSelf.screenSecondView.totalNumber = response.total;
665
        //临时保存
666
        weakSelf.temporaryArray = response;
667 668
    }];
}
曹云霄's avatar
曹云霄 committed
669 670


671 672 673 674 675 676
#pragma mark -显示筛选后的结果
- (void)ShowScreeningResponse
{
    if (self.temporaryArray.goodsEntity.count == 0) {
        
        [self ErrorMBProgressView:@"暂无数据"];
677 678 679 680 681
    }else
    {
        self.datasArray = [NSMutableArray arrayWithArray:self.temporaryArray.goodsEntity];
        [self.productCollectionView reloadData];
        [self DismissScreenView];
682 683 684
    }
}

曹云霄's avatar
曹云霄 committed
685

曹云霄's avatar
曹云霄 committed
686 687 688 689 690 691 692 693 694
#pragma mark -移除筛选框
- (void)DismissScreenView
{
    [UIView animateWithDuration:0.2 animations:^{
        self.screenView.alpha = 0;
    }completion:^(BOOL finished) {
        [self.screenView removeFromSuperview];
    }];
}
曹云霄's avatar
曹云霄 committed
695

曹云霄's avatar
曹云霄 committed
696

曹云霄's avatar
曹云霄 committed
697 698 699 700 701 702 703 704 705
#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
706 707


勾芒's avatar
勾芒 committed
708 709 710
#pragma mark -添加至购物车
- (void)addGoodsShoppingbags:(TOGoodsEntity *)model complate:(void(^)())response
{
711
    WS(weakSelf);
勾芒's avatar
勾芒 committed
712
    SaveShoppingCartRequest *shopCar = [[SaveShoppingCartRequest alloc]init];
勾芒's avatar
勾芒 committed
713
    shopCar.consumerId = [Customermanager manager].model.fid;
勾芒's avatar
勾芒 committed
714
    shopCar.goodsId = model.fid;
715
    shopCar.count = @"1";
716
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(ADDSHOPPINGBAG) WithCallClass:weakSelf WithRequestType:0 WithParameter:shopCar WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
717 718 719 720
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            response();
        }else
        {
曹云霄's avatar
曹云霄 committed
721
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
722 723
        }
    } WithErrorCodeBlock:^(id errorCodeValue) {
724
        [weakSelf SHOWPrompttext:NETWORK];
勾芒's avatar
勾芒 committed
725
    } WithFailureBlock:^(id error) {
曹云霄's avatar
曹云霄 committed
726
        [weakSelf ErrorMBProgressView:@"加入购物车失败"];
勾芒's avatar
勾芒 committed
727 728
    }];
}
勾芒's avatar
勾芒 committed
729 730 731



勾芒's avatar
勾芒 committed
732 733 734
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
曹云霄's avatar
曹云霄 committed
735
    return kNoDataImage;
勾芒's avatar
勾芒 committed
736 737
}

曹云霄's avatar
曹云霄 committed
738 739 740 741
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}
勾芒's avatar
勾芒 committed
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761

- (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
762 763
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
764 765
    [[SDImageCache sharedImageCache] clearDisk];
    NSLog(@"结算到内存警告");
曹云霄's avatar
曹云霄 committed
766 767 768 769 770 771 772 773 774 775 776 777 778 779
    // 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