ProductLibraryViewController.m 27.4 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1
//
2
//  ProductLibraryViewController.m
曹云霄's avatar
曹云霄 committed
3 4
//  Lighting
//
5
//  Created by 曹云霄 on 16/5/4.
曹云霄's avatar
曹云霄 committed
6 7 8
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

9
#import "ProductLibraryViewController.h"
曹云霄's avatar
曹云霄 committed
10
#import "ProductCollectionViewCell.h"
曹云霄's avatar
曹云霄 committed
11
#import "ProductDetailsViewController.h"
曹云霄's avatar
曹云霄 committed
12 13 14
#import "ScreeningView.h"
#import "screeningFirstView.h"
#import "screeningSecondView.h"
15
#import "ExperienceCentreViewController.h"
曹云霄's avatar
曹云霄 committed
16 17


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

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

曹云霄's avatar
曹云霄 committed
25

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

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

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

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

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

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

勾芒's avatar
勾芒 committed
56 57 58 59 60 61 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
        [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
195
    } WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
196 197
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:error.localizedDescription];
198 199 200
    }];
}

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

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


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

勾芒's avatar
勾芒 committed
376

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


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

勾芒's avatar
勾芒 committed
437 438

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

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


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

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

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


曹云霄's avatar
曹云霄 committed
516 517 518
#pragma mark -筛选
- (void)ScreeningButtonClick
{
勾芒's avatar
勾芒 committed
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
    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
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 566 567 568
}


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

曹云霄's avatar
曹云霄 committed
574

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

曹云霄's avatar
曹云霄 committed
586 587 588 589

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

605
#pragma mark -选中条件
606
- (void)selectedItem:(NSString *)typecode withTitle:(NSString *)title
607
{
勾芒's avatar
勾芒 committed
608
    [self emptyModel];
609

610
    [self DismissScreenView];
611 612 613 614 615 616
    if (self.selectedIndex == 4) {
        self.selectedCode = title;
    }else
    {
      self.selectedCode = typecode;
    }
617
    [self.productCollectionView.mj_header beginRefreshing];
618 619 620
}


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


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


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

曹云霄's avatar
曹云霄 committed
693

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

曹云霄's avatar
曹云霄 committed
704

曹云霄's avatar
曹云霄 committed
705 706 707 708 709 710 711 712 713
#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
714 715


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



勾芒's avatar
勾芒 committed
742 743 744
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
曹云霄's avatar
曹云霄 committed
745
    return kNoDataImage;
勾芒's avatar
勾芒 committed
746 747
}

曹云霄's avatar
曹云霄 committed
748 749 750 751
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}
勾芒's avatar
勾芒 committed
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771

- (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
772 773
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
774 775
    [[SDImageCache sharedImageCache] clearDisk];
    NSLog(@"结算到内存警告");
曹云霄's avatar
曹云霄 committed
776 777 778 779 780 781 782 783 784 785 786 787 788 789
    // 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