ProductLibraryViewController.m 26.7 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
      {
176
          [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
曹云霄'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
        {
207
           [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
208
        }
209
    }withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
210
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
211 212 213
    }];
}

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

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


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

勾芒's avatar
勾芒 committed
372

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


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

勾芒's avatar
勾芒 committed
433 434

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

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

#pragma mark -完成加入购物车动画完成后回调
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
494
    [self queryShoppingCarNumber];
勾芒's avatar
勾芒 committed
495 496
}

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

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


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


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

曹云霄's avatar
曹云霄 committed
568

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

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

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

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

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


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


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


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

曹云霄's avatar
曹云霄 committed
686

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

曹云霄's avatar
曹云霄 committed
697

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


勾芒's avatar
勾芒 committed
709 710 711 712
#pragma mark -添加至购物车
- (void)addGoodsShoppingbags:(TOGoodsEntity *)model complate:(void(^)())response
{
    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";
曹云霄's avatar
曹云霄 committed
716
    [HTTP networkRequestWithURL:SERVERREQUESTURL(ADDSHOPPINGBAG)  withRequestType:ZERO withParameter:shopCar withReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
717
        if (RESULT(returnValue)) {
勾芒's avatar
勾芒 committed
718 719 720
            response();
        }else
        {
721
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
722
        }
723
    }withFailureBlock:^(id error) {
曹云霄's avatar
曹云霄 committed
724 725
        [XBLoadingView hideHUDViewWithDefault];
        [XBLoadingView showHUDViewWithText:@"加入购物车失败"];
勾芒's avatar
勾芒 committed
726 727
    }];
}
勾芒's avatar
勾芒 committed
728 729


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

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

- (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
760 761
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
762 763
    [[SDImageCache sharedImageCache] clearDisk];
    NSLog(@"结算到内存警告");
曹云霄's avatar
曹云霄 committed
764 765 766 767
    // Dispose of any resources that can be recreated.
}

@end