SceneViewController.m 35.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
//
//  SceneViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/6/1.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "SceneViewController.h"
#import "ScreeningTableViewCell.h"
#import "ScreeningCollectionViewCell.h"
勾芒's avatar
勾芒 committed
12 13 14 15 16 17 18
#import "SceneSectionHeaderView.h"
#import "SceneListModel.h"
#import "DataDictModel.h"
#import "TOGoodsEntityModel.h"
#import "ProductScreeningCollectionViewCell.h"
#import "GoodsCategoryModel.h"

曹云霄's avatar
曹云霄 committed
19
@interface SceneViewController ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate,UICollectionViewDelegate,UICollectionViewDataSource,DZNEmptyDataSetSource,UITextFieldDelegate,CAAnimationDelegate>
勾芒's avatar
勾芒 committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

/**
 *  场景数据源
 */
@property (nonatomic,strong) NSMutableArray *sceneDatasArray;

/**
 *  产品数据源
 */
@property (nonatomic,strong) NSMutableArray *productDatasArray;


/**
 *  总页数
 */
@property (nonatomic,assign) int totalPages;


/**
 *  场景参数模型
 */
@property (nonatomic,strong) SceneCondition *conditionModel;

/**
 *  产品参数模型
 */
@property (nonatomic,strong) GoodsCondition *goodsModel;

/**
 *  场景筛选条件数据源
 */
@property (nonatomic,strong) NSMutableArray *sceneScreeningDatasArray;

/**
 *  产品筛选条件数据源
 */
@property (nonatomic,strong) NSMutableArray *productScreeningDatasArray;


/**
 *  右侧筛选条件选中下标
 */
@property (nonatomic,assign) NSInteger rightSelectedIndex;

/**
 *  区分场景和产品
 */
@property (nonatomic,assign) BOOL isScene;


/**
 *  类型区cell格式
 */
@property (nonatomic,assign) NSInteger sectionCellNumber;

/**
 *  当前选中的区头
 */
@property (nonatomic,assign) NSInteger selectedSectionNumber;
79

勾芒's avatar
勾芒 committed
80 81 82 83 84 85 86 87 88 89
/**
 *  管理section开关(0,表示关闭,1,表示开启)
 */
@property (nonatomic,strong) NSMutableArray *openArray;

/**
 *  选中code
 */
@property (nonatomic,copy) NSString *selectedCode;

90 91 92 93
@end

@implementation SceneViewController

勾芒's avatar
勾芒 committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117


- (NSMutableArray *)sceneDatasArray
{
    if (!_sceneDatasArray) {
        
        _sceneDatasArray = [NSMutableArray array];
    }
    return _sceneDatasArray;
}

- (NSMutableArray *)productDatasArray
{
    if (!_productDatasArray) {
        
        _productDatasArray = [NSMutableArray array];
    }
    return _productDatasArray;
}

- (SceneCondition *)conditionModel
{
    if (!_conditionModel) {
        _conditionModel = [[SceneCondition alloc]init];
118 119 120 121
        DataPage *page = [[DataPage alloc]init];
        page.page = ONE;
        page.rows = KROWS;
        _conditionModel.page = page;
勾芒's avatar
勾芒 committed
122 123 124 125 126 127 128 129 130
    }
    return _conditionModel;
}


- (GoodsCondition *)goodsModel
{
    if (!_goodsModel) {
        _goodsModel = [[GoodsCondition alloc]init];
131 132 133 134
        DataPage *page = [[DataPage alloc]init];
        page.page = ONE;
        page.rows = KROWS;
        _goodsModel.page = page;
勾芒's avatar
勾芒 committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    }
    return _goodsModel;
}

- (NSMutableArray *)sceneScreeningDatasArray
{
    if (!_sceneScreeningDatasArray) {
        
        _sceneScreeningDatasArray = [NSMutableArray array];
    }
    return _sceneScreeningDatasArray;
}

- (NSMutableArray *)productScreeningDatasArray
{
    if (!_productScreeningDatasArray) {
        
        _productScreeningDatasArray = [NSMutableArray array];
    }
    return _productScreeningDatasArray;
}

勾芒's avatar
勾芒 committed
157 158 159 160 161 162 163 164 165
- (NSMutableArray *)openArray
{
    if (!_openArray) {
        
        _openArray = [NSMutableArray array];
    }
    return _openArray;
}

166 167 168 169
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
170
    self.isScene = [UserDefault boolForKey:@"SCENE"];
171 172
    [self UiConfigAction];
    [self ReturnDismiss];
勾芒's avatar
勾芒 committed
173 174 175 176 177 178 179 180
    if (self.isScene) {
        //场景
        [self getDatasAction];
    }else
    {
        //产品
        [self GetdatasAction];
    }
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
}

#pragma mark -UI
- (void)UiConfigAction
{
    self.styleButton.layer.masksToBounds = YES;
    self.styleButton.layer.cornerRadius = kSelectedCornerRadius;
    self.typeButton.layer.masksToBounds = YES;
    self.typeButton.layer.cornerRadius = kSelectedCornerRadius;
    self.spaceButton.layer.masksToBounds = YES;
    self.spaceButton.layer.cornerRadius = kSelectedCornerRadius;
    self.materialButton.layer.masksToBounds = YES;
    self.materialButton.layer.cornerRadius = kSelectedCornerRadius;
    self.priceButton.layer.masksToBounds = YES;
    self.priceButton.layer.cornerRadius = kSelectedCornerRadius;
勾芒's avatar
勾芒 committed
196 197
    self.styleButton.selected = YES;
    self.styleButton.backgroundColor = kMainBlueColor;
198
    self.rightSelectedIndex = ZERO;
勾芒's avatar
勾芒 committed
199
    self.searchProductField.delegate = self;
200 201 202 203
    
    //筛选Tableview
    self.screeningTableView.delegate = self;
    self.screeningTableView.dataSource = self;
勾芒's avatar
勾芒 committed
204
    self.screeningTableView.tableFooterView = [UIView new];
205
    [self.screeningTableView registerClass:[ScreeningTableViewCell class] forCellReuseIdentifier:@"ScreeningCellNew"];
勾芒's avatar
勾芒 committed
206 207 208 209 210 211 212
    //section
    [self.screeningTableView registerClass:[SceneSectionHeaderView class] forHeaderFooterViewReuseIdentifier:@"headerView"];
    self.myTableViewBackView.layer.shadowColor = [UIColor blackColor].CGColor;
    self.myTableViewBackView.layer.shadowOffset = CGSizeMake(0, 0);
    self.myTableViewBackView.layer.shadowRadius = 4;
    self.myTableViewBackView.layer.shadowOpacity = 0.5;
    self.myTableViewBackView.layer.masksToBounds = NO;
213 214 215 216 217 218 219
    self.sceneOrProductClollectionView.dataSource = self;
    self.sceneOrProductClollectionView.delegate = self;
}

#pragma mark - 布局完成
- (void)viewDidLayoutSubviews
{
220
    //数据列表UICollectionView
勾芒's avatar
勾芒 committed
221 222 223 224 225 226 227 228 229 230 231 232
    if (self.isScene) {
        self.collectionViewLayout.itemSize = CGSizeMake((self.sceneOrProductClollectionView.mj_w-40)/3, (self.sceneOrProductClollectionView.mj_w-40)/4);
        self.collectionViewLayout.minimumLineSpacing = 10;
        self.collectionViewLayout.minimumInteritemSpacing = 10;
        self.collectionViewLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    }else
    {
        self.collectionViewLayout.itemSize = CGSizeMake((self.sceneOrProductClollectionView.mj_w-40)/3, self.sceneOrProductClollectionView.mj_w/3);
        self.collectionViewLayout.minimumLineSpacing = 10;
        self.collectionViewLayout.minimumInteritemSpacing = 10;
        self.collectionViewLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    }
233 234
}

勾芒's avatar
勾芒 committed
235 236 237
#pragma mark -场景数据
- (void)getDatasAction
{
曹云霄's avatar
曹云霄 committed
238
    WS(weakSelf);
勾芒's avatar
勾芒 committed
239
    //场景筛选条件
曹云霄's avatar
曹云霄 committed
240
    [HTTP networkRequestWithURL:SERVERREQUESTURL(SCENESCREENING)  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
241
        
曹云霄's avatar
曹云霄 committed
242
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
243
             SceneFilter *filterModel = [[SceneFilter alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
勾芒's avatar
勾芒 committed
244 245 246 247
            //风格
            NSMutableArray *styleArray = [NSMutableArray array];
            //空间
            NSMutableArray *spaceArray = [NSMutableArray array];
248 249
            [weakSelf.sceneScreeningDatasArray addObject:styleArray];
            [weakSelf.sceneScreeningDatasArray addObject:spaceArray];
勾芒's avatar
勾芒 committed
250 251
            for (DataDict *model in filterModel.styles) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
252
                newModel.typeName = model.typeName;
勾芒's avatar
勾芒 committed
253 254
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
255
                [[weakSelf.sceneScreeningDatasArray firstObject] addObject:newModel];
勾芒's avatar
勾芒 committed
256 257 258
            }
            for (DataDict *model in filterModel.space) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
259
                newModel.typeName = model.typeName;
勾芒's avatar
勾芒 committed
260 261
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
262
                [[weakSelf.sceneScreeningDatasArray lastObject] addObject:newModel];
勾芒's avatar
勾芒 committed
263
            }
264
            [weakSelf.screeningTableView reloadData];
勾芒's avatar
勾芒 committed
265 266 267
        }
        else
        {
268
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
269
        }
270
    } withFailureBlock:^(id error) {
勾芒's avatar
勾芒 committed
271 272 273 274 275
        
    }];
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        //默认数据
276
        weakSelf.conditionModel.page.page = ONE;
277 278
        [weakSelf.sceneOrProductClollectionView.mj_footer resetNoMoreData];
        [weakSelf getSceneLibrarydatas:weakSelf.conditionModel isRemove:YES];
勾芒's avatar
勾芒 committed
279 280 281 282 283 284 285 286 287
    }];
    
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.sceneOrProductClollectionView.mj_header = headerRefresh;
    [self.sceneOrProductClollectionView.mj_header beginRefreshing];
    //上拉加载
    self.sceneOrProductClollectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
288
        if ( ++ weakSelf.conditionModel.page.page > weakSelf.totalPages) {
289
            [weakSelf.sceneOrProductClollectionView.mj_footer endRefreshingWithNoMoreData];
勾芒's avatar
勾芒 committed
290 291 292
            
        }else
        {
293
            [weakSelf getSceneLibrarydatas:weakSelf.conditionModel isRemove:NO];
勾芒's avatar
勾芒 committed
294 295
        }
    }];
曹云霄's avatar
曹云霄 committed
296
    self.sceneOrProductClollectionView.mj_footer.automaticallyHidden = YES;
勾芒's avatar
勾芒 committed
297 298 299 300 301 302
}


#pragma mark -获取场景列表数据
- (void)getSceneLibrarydatas:(SceneCondition *)condition isRemove:(BOOL)remove
{
曹云霄's avatar
曹云霄 committed
303
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
304
    [HTTP networkRequestWithURL:SERVERREQUESTURL(SCENELIST)  withRequestType:ZERO withParameter:condition withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
305
        
306 307
        weakSelf.sceneOrProductClollectionView.emptyDataSetSource = weakSelf;
        [weakSelf endRefreshingForTableView:weakSelf.sceneOrProductClollectionView];
曹云霄's avatar
曹云霄 committed
308
        if (RESULT(returnValue)) {
勾芒's avatar
勾芒 committed
309 310
            
            if (remove) {
311
                [weakSelf.sceneDatasArray removeAllObjects];
勾芒's avatar
勾芒 committed
312
            }
曹云霄's avatar
曹云霄 committed
313 314
            SceneResponse *response = [[SceneResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
            weakSelf.totalPages = [RESPONSE(returnValue)[@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
315 316 317 318 319 320 321 322 323 324 325 326 327
            for (TOSceneEntity *model in response.list) {
                
                SceneListModel *newModel = [[SceneListModel alloc]init];
                newModel.fid = model.fid;
                newModel.sceneCode = model.sceneCode;
                newModel.name = model.name;
                newModel.pricure = model.pricure;
                newModel.category = model.category;
                newModel.style = model.style;
                newModel.space = model.space;
                newModel.isSelectedSate = NO;
                [self.sceneDatasArray addObject:newModel];
            }
勾芒's avatar
勾芒 committed
328 329 330 331 332 333 334
            for (SceneListModel *model in SHARED_APPDELEGATE.sceneArray) {
                for (SceneListModel *sceneModel in self.sceneDatasArray) {
                    if ([model.fid isEqualToString:sceneModel.fid]) {
                        sceneModel.isSelectedSate = YES;
                    }
                }
            }
335
            [weakSelf.sceneOrProductClollectionView reloadData];
勾芒's avatar
勾芒 committed
336 337 338
        }
        else
        {
339
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
340
        }
341
    } withFailureBlock:^(id error) {
342
        [weakSelf endRefreshingForTableView:weakSelf.sceneOrProductClollectionView];
勾芒's avatar
勾芒 committed
343 344 345 346 347 348 349 350 351
    }];
}


#pragma mark -产品数据
- (void)GetdatasAction
{
    [self getScreeningdatasisRemoveArray:YES];
    //下拉刷新
352
    WS(weakSelf);
勾芒's avatar
勾芒 committed
353 354
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        
355
        weakSelf.goodsModel.page.page = ONE;
356
        [weakSelf.sceneOrProductClollectionView.mj_footer resetNoMoreData];
357
        [weakSelf getGoodsListDatasisRemove:YES Withobject:weakSelf.goodsModel];
勾芒's avatar
勾芒 committed
358 359 360 361 362 363 364 365
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.sceneOrProductClollectionView.mj_header = headerRefresh;
    [self.sceneOrProductClollectionView.mj_header beginRefreshing];
    //上拉加载
    self.sceneOrProductClollectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
366
        if (++ weakSelf.goodsModel.page.page > weakSelf.totalPages) {
367
            [weakSelf.sceneOrProductClollectionView.mj_footer endRefreshingWithNoMoreData];
勾芒's avatar
勾芒 committed
368 369
        }else
        {
370
            [weakSelf getGoodsListDatasisRemove:NO Withobject:weakSelf.goodsModel];
勾芒's avatar
勾芒 committed
371 372
        }
    }];
曹云霄's avatar
曹云霄 committed
373
    self.sceneOrProductClollectionView.mj_footer.automaticallyHidden = YES;
勾芒's avatar
勾芒 committed
374 375 376 377 378 379
}


#pragma mark -获取产品筛选数据
- (void)getScreeningdatasisRemoveArray:(BOOL)remove
{
380
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
381
    [HTTP networkWithDictionaryRequestWithURL:SERVERREQUESTURL(PRODUCTSCREENING)  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
382
        
曹云霄's avatar
曹云霄 committed
383
        if (RESULT(returnValue)) {
勾芒's avatar
勾芒 committed
384 385
            
            if (remove) {
386
                [weakSelf.productScreeningDatasArray removeAllObjects];
勾芒's avatar
勾芒 committed
387
            }
曹云霄's avatar
曹云霄 committed
388
            GoodsFilter *goodsScreening = [[GoodsFilter alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
389 390 391 392
            for (int i=0; i<5; i++) {
                NSMutableArray *array = [NSMutableArray array];
                [weakSelf.productScreeningDatasArray addObject:array];
            }
勾芒's avatar
勾芒 committed
393 394
            for (DataDict *model in goodsScreening.styles) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
395
                newModel.typeName = model.typeName;
勾芒's avatar
勾芒 committed
396 397
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
398
                [[weakSelf.productScreeningDatasArray objectAtIndex_opple:0] addObject:newModel];
勾芒's avatar
勾芒 committed
399 400 401
            }
            for (DataDict *model in goodsScreening.space) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
402
                newModel.typeName = model.typeName;
勾芒's avatar
勾芒 committed
403 404
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
405
                [[weakSelf.productScreeningDatasArray objectAtIndex_opple:1] addObject:newModel];
勾芒's avatar
勾芒 committed
406 407 408 409 410 411 412
            }
            for (GoodsCategory *model in goodsScreening.categories) {
                GoodsCategoryModel *newModel = [[GoodsCategoryModel alloc]init];
                newModel.fid = model.fid;
                newModel.name = model.name;
                newModel.children = model.children;
                newModel.isSelectedState = NO;
413 414
                [weakSelf.openArray addObject:@"0"];//section关闭状态;
                [[weakSelf.productScreeningDatasArray objectAtIndex_opple:2] addObject:newModel];
勾芒's avatar
勾芒 committed
415 416 417
            }
            for (DataDict *model in goodsScreening.material) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
418
                newModel.typeName = model.typeName;
勾芒's avatar
勾芒 committed
419 420
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
421
                [[weakSelf.productScreeningDatasArray objectAtIndex_opple:3] addObject:newModel];
勾芒's avatar
勾芒 committed
422 423 424
            }
            for (DataDict *model in goodsScreening.price) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
425
                newModel.typeName = model.typeName;
勾芒's avatar
勾芒 committed
426 427
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
428
                [[weakSelf.productScreeningDatasArray objectAtIndex_opple:4] addObject:newModel];
勾芒's avatar
勾芒 committed
429
            }
430
            [weakSelf.screeningTableView reloadData];
勾芒's avatar
勾芒 committed
431 432 433
        }
        else
        {
434
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
435
        }
436
    } withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
437
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
438 439 440 441 442 443 444
    }];
}


#pragma mark -获取商品列表数据
- (void)getGoodsListDatasisRemove:(BOOL)remove Withobject:(GoodsCondition *)conditon
{
445
    WS(weakSelf);
勾芒's avatar
勾芒 committed
446 447 448 449
    [self getGoodsListdatas:conditon returnResponse:^(GoodsResponse *response) {
        
        weakSelf.sceneOrProductClollectionView.emptyDataSetSource = weakSelf;
        if (remove) {
勾芒's avatar
勾芒 committed
450
            [weakSelf.productDatasArray removeAllObjects];
勾芒's avatar
勾芒 committed
451 452 453 454 455 456 457
        }
        for (TOGoodsEntity *model in response.goodsEntity) {
            
            TOGoodsEntityModel *newModel = [[TOGoodsEntityModel alloc]init];
            newModel.resellerInv = model.resellerInv;
            newModel.resellerTagPrice = model.resellerTagPrice;
            newModel.resellerState = model.resellerState;
勾芒's avatar
勾芒 committed
458
            newModel.categoryName = model.categoryName;
勾芒's avatar
勾芒 committed
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
            newModel.brandName = model.brandName;
            newModel.fid = model.fid;
            newModel.createDate = model.createDate;
            newModel.onlineTime = model.onlineTime;
            newModel.company = model.company;
            newModel.code = model.code;
            newModel.name = model.name;
            newModel.number = model.number;
            newModel.categoryId = model.categoryId;
            newModel.brandId = model.brandId;
            newModel.keyword = model.keyword;
            newModel.guidePrice = model.guidePrice;
            newModel.tagPrice = model.tagPrice;
            newModel.costPrice = model.costPrice;
            newModel.state = model.state;
            newModel.inv = model.inv;
            newModel.detailedIntro = model.detailedIntro;
            newModel.weight = model.weight;
            newModel.unit = model.unit;
            newModel.productProfile = model.productProfile;
            newModel.power = model.power;
            newModel.colorTemperature = model.colorTemperature;
            newModel.spec = model.spec;
            newModel.function = model.function;
            newModel.material = model.material;
            newModel.lightSource = model.lightSource;
            newModel.goodsStyle = model.goodsStyle;
            newModel.series = model.series;
            newModel.area = model.area;
            newModel.size = model.size;
            newModel.space = model.space;
            newModel.installMethod = model.installMethod;
            newModel.lightNumber = model.lightNumber;
            newModel.pictures = model.pictures;
            newModel.barcode = model.barcode;
            newModel.isSelectedState = NO;
495
            newModel.goodsNumber = ONE;
勾芒's avatar
勾芒 committed
496 497
            [weakSelf.productDatasArray addObject:newModel];
        }
勾芒's avatar
勾芒 committed
498 499 500 501 502 503 504
        for (TOGoodsEntityModel *model in SHARED_APPDELEGATE.productArray) {
            for (TOGoodsEntityModel *productModel in weakSelf.productDatasArray) {
                if ([model.fid isEqualToString:productModel.fid]) {
                    productModel.isSelectedState = YES;
                }
            }
        }
勾芒's avatar
勾芒 committed
505 506 507 508 509 510 511
        [weakSelf.sceneOrProductClollectionView reloadData];
    }];
}

#pragma mark -获取商品列表数据
- (void)getGoodsListdatas:(GoodsCondition *)conditon returnResponse:(void(^)(GoodsResponse *))finish
{
曹云霄's avatar
曹云霄 committed
512
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
513
    [HTTP networkRequestWithURL:SERVERREQUESTURL(PRODUCTLIST)  withRequestType:ZERO withParameter:conditon withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
514
        
515
        [weakSelf endRefreshingForTableView:weakSelf.sceneOrProductClollectionView];
曹云霄's avatar
曹云霄 committed
516
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
517 518
            GoodsResponse *sponse = [[GoodsResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
            weakSelf.totalPages = [RESPONSE(returnValue)[@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
519 520 521 522
            //返回结果
            finish(sponse);
        }else
        {
523
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
524
        }
525
    }withFailureBlock:^(NSError *error) {
526
        [XBLoadingView hideHUDViewWithDefault];
527
        [weakSelf endRefreshingForTableView:weakSelf.sceneOrProductClollectionView];
曹云霄's avatar
曹云霄 committed
528
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
529 530 531 532 533
    }];
}



534 535 536
#pragma mark - UITableViewDataSource代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
537
    if (self.rightSelectedIndex == 2) {
勾芒's avatar
勾芒 committed
538
        
勾芒's avatar
勾芒 committed
539 540 541
        BOOL boolValue = [[self.openArray objectAtIndex_opple:section] boolValue];
        GoodsCategoryModel *model = [[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:section];
        return boolValue?model.children.count:0;
勾芒's avatar
勾芒 committed
542 543
    }
    return 0;
544 545 546 547 548
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ScreeningTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ScreeningCellNew" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
549 550
    GoodsCategoryModel *model= [self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex][indexPath.section];
    cell.screeningLabe.text = [[model.children objectAtIndex_opple:indexPath.row] name];
551 552 553 554 555 556 557 558
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

勾芒's avatar
勾芒 committed
559 560 561 562
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self CancelTableviewSectionState];
    ScreeningTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
曹云霄's avatar
曹云霄 committed
563
    cell.screeningLabe.backgroundColor = RGB(221, 221, 221,1);
勾芒's avatar
勾芒 committed
564
    cell.screeningLabe.textColor = kMainBlueColor;
565 566
    GoodsCategoryModel *model = [[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:indexPath.section];
    self.goodsModel.categoryEquals = [[model.children objectAtIndex_opple:indexPath.row] fid];
勾芒's avatar
勾芒 committed
567
    [self.sceneOrProductClollectionView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
568 569
}

570

勾芒's avatar
勾芒 committed
571
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
572
{
勾芒's avatar
勾芒 committed
573 574
    SceneSectionHeaderView *sectionView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerView"];
    if (self.isScene) {
575
        [sectionView.sectionButton setTitle:[[self.sceneScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex][section] typeName] forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
576 577 578 579 580 581
    }else
    {
        if (self.rightSelectedIndex == 2) {
          [sectionView.sectionButton setTitle:[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex][section] name] forState:UIControlStateNormal];
        }else
        {
582
          [sectionView.sectionButton setTitle:[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex][section] typeName] forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
583 584 585 586 587
        }
    }
    sectionView.sectionButton.tag = section+100;
    [sectionView.sectionButton addTarget:self action:@selector(SectionButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    return sectionView;
588 589
}

勾芒's avatar
勾芒 committed
590
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
591 592
{
    
勾芒's avatar
勾芒 committed
593 594
    NSArray *array = [self.isScene?self.sceneScreeningDatasArray:self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex];
    return array.count;
595 596
}

勾芒's avatar
勾芒 committed
597 598 599 600
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 55;
}
601 602


勾芒's avatar
勾芒 committed
603

勾芒's avatar
勾芒 committed
604 605 606 607
#pragma mark -区头选中
- (void)SectionButtonClickAction:(UIButton *)button
{
    [self CancelTableviewSectionState];
勾芒's avatar
勾芒 committed
608 609
    if (self.rightSelectedIndex !=2 ) {
        button.selected = YES;
曹云霄's avatar
曹云霄 committed
610
        button.backgroundColor = RGB(221, 221, 221,1);
勾芒's avatar
勾芒 committed
611
    }
勾芒's avatar
勾芒 committed
612
    [self emptyModel];
勾芒's avatar
勾芒 committed
613 614 615
    switch (self.rightSelectedIndex) {
        case 0://风格
        {
勾芒's avatar
勾芒 committed
616 617 618 619 620 621 622 623
            if (self.isScene) {
                
                self.conditionModel.styleEquals = [[[self.sceneScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:button.tag-100] typecode];
                self.conditionModel.spaceEquals = nil;
            }else
            {
                self.goodsModel.styleEquals = [[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:button.tag-100] typecode];
            }
勾芒's avatar
勾芒 committed
624 625 626 627
        }
            break;
        case 1://空间
        {
勾芒's avatar
勾芒 committed
628 629 630 631 632 633 634 635
            if (self.isScene) {
                
                self.conditionModel.spaceEquals = [[[self.sceneScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:button.tag-100] typecode];
                self.conditionModel.styleEquals = nil;
            }else
            {
                self.goodsModel.spaceEquals = [[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:button.tag-100] typecode];
            }
勾芒's avatar
勾芒 committed
636 637 638 639
        }
            break;
        case 2://类型
        {
勾芒's avatar
勾芒 committed
640

勾芒's avatar
勾芒 committed
641 642 643 644
        }
            break;
        case 3://材质
        {
勾芒's avatar
勾芒 committed
645
            self.goodsModel.materialEqueals = [[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:button.tag-100] typecode];
勾芒's avatar
勾芒 committed
646 647 648 649
        }
            break;
        case 4://价格
        {
勾芒's avatar
勾芒 committed
650
            //价格字符串切割
651 652 653
            NSArray *spacrArray = [[[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:button.tag-100] typeName] componentsSeparatedByString:@"到"];
            self.goodsModel.startprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
            self.goodsModel.endprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
勾芒's avatar
勾芒 committed
654 655 656 657 658 659 660
        }
            break;
            
        default:
            break;
    }
    if (self.rightSelectedIndex == 2) {
勾芒's avatar
勾芒 committed
661 662 663
        BOOL boolValue = [[self.openArray objectAtIndex_opple:button.tag-100] boolValue];
        NSMutableIndexSet *index = [[NSMutableIndexSet alloc]init];
        for (int i=0; i<self.openArray.count; i++) {
664 665
            if ([[self.openArray objectAtIndex_opple:i] isEqualToString:@"1"]) {
                [self.openArray replaceObjectAtIndex:i withObject:@"0"];
666
               [index addIndex:i];
667 668 669 670
            }
            else if (i == button.tag -100) {
                [index addIndex:i];
            }
勾芒's avatar
勾芒 committed
671 672
        }
        [self.openArray replaceObjectAtIndex:button.tag-100 withObject:boolValue?@"0":@"1"];
673
        [self.screeningTableView reloadSections:index withRowAnimation:UITableViewRowAnimationTop];
勾芒's avatar
勾芒 committed
674 675 676 677 678
    }else
    {
      [self.sceneOrProductClollectionView.mj_header beginRefreshing];
    }
}
679 680 681



勾芒's avatar
勾芒 committed
682 683 684
#pragma mark -tableview取消所有cell选中
- (void)CancelTableviewSectionState
{
勾芒's avatar
勾芒 committed
685 686 687 688 689 690 691

    NSArray *array = nil;
    if (self.isScene) {
        array = [self.sceneScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex];
    }else
    {
        if (self.rightSelectedIndex == 2) {
692
            array = [[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] firstObject] children];
勾芒's avatar
勾芒 committed
693 694 695 696 697
        }else
        {
          array = [self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex];
        }
    }
勾芒's avatar
勾芒 committed
698
    for (int i=0; i<array.count; i++) {
699 700 701 702 703 704 705 706 707
        UITableViewHeaderFooterView *sectionView = [self.screeningTableView headerViewForSection:i];
        for (id objc in sectionView.subviews) {
            if ([objc isKindOfClass:[UIButton class]]) {
                
                UIButton *button = (UIButton *)objc;
                button.selected = NO;
                button.backgroundColor = [UIColor whiteColor];
            }
        }
勾芒's avatar
勾芒 committed
708 709
    }
}
710 711 712



勾芒's avatar
勾芒 committed
713 714 715 716 717 718 719 720 721 722
#pragma mark -UICollectionViewDataSource代理
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.isScene) {
       return self.sceneDatasArray.count;
    }else
    {
        return self.productDatasArray.count;
    }
}
723

勾芒's avatar
勾芒 committed
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.isScene) {
        ScreeningCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ScreeningCollectioncell" forIndexPath:indexPath];
        cell.model = [self.sceneDatasArray objectAtIndex_opple:indexPath.item];
        cell.layer.shadowColor = [UIColor blackColor].CGColor;
        cell.layer.shadowRadius = 4;
        cell.layer.shadowOpacity = 0.5;
        cell.contentView.layer.shadowOffset = CGSizeMake(0, 0);
        cell.layer.masksToBounds = NO;
        return cell;
    }else
    {
        ProductScreeningCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductCollectionViewCell" forIndexPath:indexPath];
        cell.backgroundColor = kMainGrayColor;
勾芒's avatar
勾芒 committed
739
        cell.model = [self.productDatasArray objectAtIndex_opple:indexPath.item];
勾芒's avatar
勾芒 committed
740 741 742 743
        return cell;
    }
}

744 745
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
746
    WS(weakSelf);
勾芒's avatar
勾芒 committed
747
    [self emptyModel];
748 749 750
    if (self.isScene) {
        ScreeningCollectionViewCell *cell = (ScreeningCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
        CGPoint startPoint = [cell convertPoint:cell.sceneImageView.center toView:self.sceneOrProductClollectionView.window];
勾芒's avatar
勾芒 committed
751 752 753
        if ([self.delegate respondsToSelector:@selector(SelectedImageswithModel:withisScene:returnResponse:)]) {
            SceneListModel *model = [self.sceneDatasArray objectAtIndex_opple:indexPath.item];
            [self.delegate SelectedImageswithModel:model withisScene:self.isScene returnResponse:^(BOOL boolValue) {
754 755 756 757
                //判断选中的图片是否存在
                if (!boolValue) {
                   [weakSelf StartAddShoppingCarAnimationWithimage:[cell.sceneImageView image] withStartpoint:startPoint withSize:cell.mj_size];
                    model.isSelectedSate = YES;
勾芒's avatar
勾芒 committed
758
                    [weakSelf.sceneOrProductClollectionView reloadItemsAtIndexPaths:@[indexPath]];
759 760 761
                }else
                {
                    model.isSelectedSate = NO;
勾芒's avatar
勾芒 committed
762
                    [weakSelf.sceneOrProductClollectionView reloadItemsAtIndexPaths:@[indexPath]];
763 764 765 766 767 768 769
                }
            }];
        }
    }else
    {
        ProductScreeningCollectionViewCell *cell = (ProductScreeningCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
        CGPoint startPoint = [cell convertPoint:cell.goodsImageView.center toView:self.sceneOrProductClollectionView.window];
770
                if ([self.delegate respondsToSelector:@selector(SelectedImageswithModel:withisScene:returnResponse:)]) {
勾芒's avatar
勾芒 committed
771 772
            GoodsCategoryModel *model = [self.productDatasArray objectAtIndex_opple:indexPath.item];
            [self.delegate SelectedImageswithModel:model withisScene:self.isScene returnResponse:^(BOOL boolValue) {
773 774
                //判断图片是否存在
                if (!boolValue) {
勾芒's avatar
勾芒 committed
775
                    [weakSelf StartAddShoppingCarAnimationWithimage:[cell.goodsImageView image] withStartpoint:startPoint withSize:cell.mj_size];
776
                    model.isSelectedState = YES;
勾芒's avatar
勾芒 committed
777
                    [weakSelf.sceneOrProductClollectionView reloadItemsAtIndexPaths:@[indexPath]];
778 779 780
                }else
                {
                    model.isSelectedState = NO;
勾芒's avatar
勾芒 committed
781
                    [weakSelf.sceneOrProductClollectionView reloadItemsAtIndexPaths:@[indexPath]];
782 783 784 785 786
                }
            }];
        }
    }
}
勾芒's avatar
勾芒 committed
787 788 789



790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
#pragma mark -加入场景库、产品库动画
- (void)StartAddShoppingCarAnimationWithimage:(UIImage *)image withStartpoint:(CGPoint)point withSize:(CGSize)imageSize
{
    CGPoint startPoint = point;
    CGPoint endPoint = self.endAnimationPoint;
    CGPoint controlPoint = CGPointMake(endPoint.x, startPoint.x);
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, imageSize.width, imageSize.height)];
    imageView.center = point;

    imageView.tag = 100;
    imageView.image = image;
    [self.view.window.layer addSublayer:imageView.layer];
    
    //路径曲线
    UIBezierPath *movePath = [UIBezierPath bezierPath];
    [movePath moveToPoint:imageView.center];
806
    [movePath addQuadCurveToPoint:endPoint controlPoint:controlPoint];
807 808 809
    //关键帧
    CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    moveAnim.path = movePath.CGPath;
810
    moveAnim.calculationMode = kCAAnimationLinear;
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
    moveAnim.removedOnCompletion = YES;
    
    //旋转变化
    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;
    
    //透明度变化
    CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
    opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
    opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
    opacityAnim.removedOnCompletion = YES;
    
    //关键帧,旋转,透明度组合起来执行
    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{
    
    [layerAnimation removeFromSuperlayer];
}

#pragma mark -动画完成
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    if ([self.delegate respondsToSelector:@selector(RefreshSceneAndProduct:)]) {
        
        [self.delegate RefreshSceneAndProduct:self.isScene];
    }
}

勾芒's avatar
勾芒 committed
853 854 855
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
曹云霄's avatar
曹云霄 committed
856
    return kNoDataImage;
勾芒's avatar
勾芒 committed
857 858 859 860 861 862
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
}
863 864 865 866 867 868 869 870 871 872

#pragma mark -筛选条件
- (IBAction)ScreeningConditionsSelectedButtonClick:(UIButton *)sender {
    
    switch (sender.tag) {
        case 100://风格
        {
            
        }
            break;
勾芒's avatar
勾芒 committed
873
        case 101://空间
874 875 876 877
        {
            
        }
            break;
勾芒's avatar
勾芒 committed
878
        case 102://类型
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
        {
            
        }
            break;
        case 103://材质
        {
            
        }
            break;
        case 104://价格
        {
            
        }
            break;
            
        default:
            break;
    }
    
勾芒's avatar
勾芒 committed
898 899 900
    for (int i=0; i<self.openArray.count; i++) {
        [self.openArray replaceObjectAtIndex:i withObject:@"0"];
    }
勾芒's avatar
勾芒 committed
901
    [self emptyModel];
勾芒's avatar
勾芒 committed
902 903 904 905 906 907
    self.rightSelectedIndex = sender.tag - 100;
    [self RemoveAllButtonisSelected];
    [self CancelTableviewSectionState];
    sender.selected = YES;
    sender.backgroundColor = kMainBlueColor;
    [self.screeningTableView reloadData];
908 909 910
}


勾芒's avatar
勾芒 committed
911 912 913 914 915 916 917 918 919 920 921 922 923
#pragma mark -取消所有筛选条件按钮的选中
- (void)RemoveAllButtonisSelected
{
    for (UIView *view in self.clickEventView.subviews) {
        
        if ([view isKindOfClass:[UIButton class]]) {
            
            UIButton *button = (UIButton *)view;
            button.selected = NO;
            button.backgroundColor = [UIColor whiteColor];
        }
    }
}
924 925 926 927 928 929 930 931 932 933 934 935 936 937


#pragma mark -UIGestureRecognizerDelegate代理
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    //取消子视图的的时间穿透,否则子视图的点击无效,会被传递到父视图响应
    if (CGRectContainsPoint(self.clickEventView.frame, [touch locationInView:self.view.window])) {
        
        return NO;
    }
    return YES;
}


勾芒's avatar
勾芒 committed
938 939 940 941
#pragma mark -搜索框
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self emptyModel];
942
    [textField resignFirstResponder];
勾芒's avatar
勾芒 committed
943 944 945 946 947
    self.goodsModel.nameLike = textField.text;
    [self.sceneOrProductClollectionView.mj_header beginRefreshing];
    return YES;
}

948 949 950 951 952 953 954 955 956 957 958
#pragma mark -返回手势
- (void)ReturnDismiss
{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ReturnButtonClickAction)];
    tap.delegate = self;
    [self.view addGestureRecognizer:tap];
}

#pragma mark -销毁
- (void)ReturnButtonClickAction
{
曹云霄's avatar
曹云霄 committed
959 960 961
    if (self.dismissBlock) {
        self.dismissBlock();
    }
962 963 964 965
    [self dismissViewControllerAnimated:YES completion:nil];
}


勾芒's avatar
勾芒 committed
966 967 968 969 970 971 972 973 974 975 976 977
#pragma mark -清空模型
- (void)emptyModel
{
    self.goodsModel.nameLike = nil;
    self.goodsModel.styleEquals = nil;
    self.goodsModel.spaceEquals = nil;
    self.goodsModel.categoryEquals = nil;
    self.goodsModel.startprice = nil;
    self.goodsModel.endprice = nil;
    self.goodsModel.materialEqueals = nil;
}

978

979
- (void)didReceiveMemoryWarning {
980
    
981
    [super didReceiveMemoryWarning];
982 983
    [[SDImageCache sharedImageCache] clearDisk];
    NSLog(@"结算到内存警告");
984 985 986 987 988
    // Dispose of any resources that can be recreated.
}


@end