ProductLibraryViewController.m 27.1 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

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
#pragma mark -渲染完成
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

#pragma mark -视图即将消失
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES;
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}

曹云霄's avatar
曹云霄 committed
133 134 135
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
曹云霄's avatar
曹云霄 committed
136 137
    
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
138
    [self GetdatasAction];
曹云霄's avatar
曹云霄 committed
139 140
}

141
#pragma mark -获取商品列表数据
勾芒's avatar
勾芒 committed
142
- (void)getGoodsListDatasisRemove:(BOOL)remove Withobject:(GoodsCondition *)conditon
143
{
144
    WS(weakSelf);
145 146
    [self getGoodsListdatas:conditon returnResponse:^(GoodsResponse *response) {
        
147
        if (remove) {
148
            [weakSelf.datasArray removeAllObjects];
149 150 151
        }
        for (TOGoodsEntity *model in response.goodsEntity) {
            [weakSelf.datasArray addObject:model];
152
        }
153
        [weakSelf.productCollectionView reloadData];
154 155 156
    }];
}

曹云霄's avatar
曹云霄 committed
157
#pragma mark -获取产品筛选数据
勾芒's avatar
勾芒 committed
158
- (void)getScreeningdatasisRemoveArray:(BOOL)remove
曹云霄's avatar
曹云霄 committed
159
{
160
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
161
  [HTTP networkWithDictionaryRequestWithURL:SERVERREQUESTURL(PRODUCTSCREENING)  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
162
      
曹云霄's avatar
曹云霄 committed
163
      if (RESULT(returnValue)) {
勾芒's avatar
勾芒 committed
164
          if (remove) {
165
              [weakSelf.screeningDatas removeAllObjects];
勾芒's avatar
勾芒 committed
166
          }
曹云霄's avatar
曹云霄 committed
167
          GoodsFilter *goodsStyle = [[GoodsFilter alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
168 169 170 171 172
          [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
173
    }
曹云霄's avatar
曹云霄 committed
174 175
      else
      {
曹云霄's avatar
曹云霄 committed
176
          [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
曹云霄's avatar
曹云霄 committed
177 178
      }
      
179
  }withFailureBlock:^(NSError *error) {
180
      [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
181
      [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
182
  }];
曹云霄's avatar
曹云霄 committed
183 184 185
}


勾芒's avatar
勾芒 committed
186

187 188 189
#pragma mark -获取商品列表数据
- (void)getGoodsListdatas:(GoodsCondition *)conditon returnResponse:(void(^)(GoodsResponse *))finish
{
曹云霄's avatar
曹云霄 committed
190
    [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
191
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
192
    [HTTP networkRequestWithURL:SERVERREQUESTURL(PRODUCTLIST)  withRequestType:ZERO withParameter:conditon withReturnValueBlock:^(id returnValue) {
193
        
曹云霄's avatar
曹云霄 committed
194 195 196
        weakSelf.productCollectionView.emptyDataSetSource = weakSelf;
        weakSelf.productCollectionView.emptyDataSetDelegate = weakSelf;
        [weakSelf endRefreshingForTableView:weakSelf.productCollectionView];
曹云霄's avatar
曹云霄 committed
197
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
198
        if (RESULT(returnValue)) {
199
            
曹云霄's avatar
曹云霄 committed
200 201
            GoodsResponse *sponse = [[GoodsResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
            weakSelf.totalPages = [RESPONSE(returnValue)[@"totalpages"] intValue];
202 203 204 205 206
            //返回结果
            finish(sponse);
        }
        else
        {
曹云霄's avatar
曹云霄 committed
207
           [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
208
        }
209
    }withFailureBlock:^(NSError *error) {
210
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
211
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
212 213 214
    }];
}

曹云霄's avatar
曹云霄 committed
215 216 217
#pragma mark -布局
- (void)uiConfigAction
{
218
    self.selectedIndex = 9999;//无任何意义
曹云霄's avatar
曹云霄 committed
219 220 221 222 223
    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
224
    self.productCollectionView.delegate = self;
225
    self.productCollectionView.alwaysBounceVertical = YES;
226
    [self CreateScreeningButton];
勾芒's avatar
勾芒 committed
227
}
勾芒's avatar
勾芒 committed
228

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


勾芒's avatar
勾芒 committed
341 342 343
#pragma mark 填条形码搜索
- (void)barCodeSearchRequest
{
344
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
345
    [XBLoadingView showHUDViewWithDefault];
346 347
    NSString *urlString = [NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(BARCODESEARCH),self.barcode];
    [HTTP networkWithDictionaryRequestWithURL:[self returnUrlString:urlString]  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
348
        
349
        [weakSelf endRefreshingForTableView:self.productCollectionView];
曹云霄's avatar
曹云霄 committed
350
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
351
        if (RESULT(returnValue)) {
勾芒's avatar
勾芒 committed
352
            
曹云霄's avatar
曹云霄 committed
353
            if ([RESPONSE(returnValue) isKindOfClass:[NSNull class]]) {
曹云霄's avatar
曹云霄 committed
354
                [XBLoadingView showHUDViewWithText:@"暂无商品信息"];
勾芒's avatar
勾芒 committed
355 356
                return;
            }
曹云霄's avatar
曹云霄 committed
357
            TOGoodsEntity *goods = [[TOGoodsEntity alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
358 359 360
            [weakSelf.datasArray removeAllObjects];
            [weakSelf.datasArray addObject:goods];
            [weakSelf.productCollectionView reloadData];
勾芒's avatar
勾芒 committed
361 362
        }else
        {
曹云霄's avatar
曹云霄 committed
363
            [XBLoadingView showHUDViewWithText:@"查询失败"];
勾芒's avatar
勾芒 committed
364
        }
365
    }withFailureBlock:^(id error) {
勾芒's avatar
勾芒 committed
366
        
367
        [weakSelf endRefreshingForTableView:self.productCollectionView];
曹云霄's avatar
曹云霄 committed
368 369
        [XBLoadingView hideHUDViewWithDefault];
        [XBLoadingView showHUDViewWithText:@"查询失败"];
勾芒's avatar
勾芒 committed
370
    }];
勾芒's avatar
勾芒 committed
371 372
}

勾芒's avatar
勾芒 committed
373

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


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

勾芒's avatar
勾芒 committed
434 435

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

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


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

曹云霄's avatar
曹云霄 committed
500 501
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
502
    return self.datasArray.count;
曹云霄's avatar
曹云霄 committed
503 504
}

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


曹云霄's avatar
曹云霄 committed
513 514 515
#pragma mark -筛选
- (void)ScreeningButtonClick
{
勾芒's avatar
勾芒 committed
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
    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
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 562 563 564 565
}


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

曹云霄's avatar
曹云霄 committed
571

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

曹云霄's avatar
曹云霄 committed
583 584

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

601
#pragma mark -选中条件
602
- (void)selectedItem:(NSString *)typecode withTitle:(NSString *)title
603
{
勾芒's avatar
勾芒 committed
604
    [self emptyModel];
605

606
    [self DismissScreenView];
607 608 609 610 611 612
    if (self.selectedIndex == 4) {
        self.selectedCode = title;
    }else
    {
      self.selectedCode = typecode;
    }
613
    [self.productCollectionView.mj_header beginRefreshing];
614 615 616
}


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


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


675 676 677 678 679
#pragma mark -显示筛选后的结果
- (void)ShowScreeningResponse
{
    if (self.temporaryArray.goodsEntity.count == 0) {
        
曹云霄's avatar
曹云霄 committed
680
        [XBLoadingView showHUDViewWithText:@"暂无数据"];
681 682 683 684 685
    }else
    {
        self.datasArray = [NSMutableArray arrayWithArray:self.temporaryArray.goodsEntity];
        [self.productCollectionView reloadData];
        [self DismissScreenView];
686 687 688
    }
}

曹云霄's avatar
曹云霄 committed
689

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

曹云霄's avatar
曹云霄 committed
700

曹云霄's avatar
曹云霄 committed
701 702 703 704 705 706 707 708 709
#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
710 711


勾芒's avatar
勾芒 committed
712 713 714 715
#pragma mark -添加至购物车
- (void)addGoodsShoppingbags:(TOGoodsEntity *)model complate:(void(^)())response
{
    SaveShoppingCartRequest *shopCar = [[SaveShoppingCartRequest alloc]init];
勾芒's avatar
勾芒 committed
716
    shopCar.consumerId = [Customermanager manager].model.fid;
勾芒's avatar
勾芒 committed
717
    shopCar.goodsId = model.fid;
718
    shopCar.count = @"1";
曹云霄's avatar
曹云霄 committed
719
    [HTTP networkRequestWithURL:SERVERREQUESTURL(ADDSHOPPINGBAG)  withRequestType:ZERO withParameter:shopCar withReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
720
        if (RESULT(returnValue)) {
勾芒's avatar
勾芒 committed
721 722 723
            response();
        }else
        {
曹云霄's avatar
曹云霄 committed
724
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
725
        }
726
    }withFailureBlock:^(id error) {
曹云霄's avatar
曹云霄 committed
727 728
        [XBLoadingView hideHUDViewWithDefault];
        [XBLoadingView showHUDViewWithText:@"加入购物车失败"];
729

勾芒's avatar
勾芒 committed
730 731
    }];
}
勾芒's avatar
勾芒 committed
732 733 734



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

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

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