SceneViewController.m 36.9 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>
勾芒'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 79 80 81 82

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

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

/**
 *  当前页数
 */
@property (nonatomic,assign) int indexPage;

/**
 *  总页数
 */
@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;
83

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

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

94 95 96 97
@end

@implementation SceneViewController

勾芒's avatar
勾芒 committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153


- (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];
    }
    return _conditionModel;
}


- (GoodsCondition *)goodsModel
{
    if (!_goodsModel) {
        _goodsModel = [[GoodsCondition alloc]init];
    }
    return _goodsModel;
}

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

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

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

163 164 165 166
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
勾芒's avatar
勾芒 committed
167
    self.isScene = [[NSUserDefaults standardUserDefaults] boolForKey:@"SCENE"];
168 169
    [self UiConfigAction];
    [self ReturnDismiss];
勾芒's avatar
勾芒 committed
170 171 172 173 174 175 176 177 178 179
    
    if (self.isScene) {
        //场景
        [self getDatasAction];
        
    }else
    {
        //产品
        [self GetdatasAction];
    }
180 181 182 183 184
}

#pragma mark -UI
- (void)UiConfigAction
{
勾芒's avatar
勾芒 committed
185
    
186 187 188 189 190 191 192 193 194 195
    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 198
    self.styleButton.selected = YES;
    self.styleButton.backgroundColor = kMainBlueColor;
    self.rightSelectedIndex = 0;
勾芒'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
    
    //数据列表UICollectionView
勾芒's avatar
勾芒 committed
215 216 217 218 219 220 221 222 223 224 225 226
    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);
    }
227 228 229 230 231
    self.sceneOrProductClollectionView.dataSource = self;
    self.sceneOrProductClollectionView.delegate = self;
}


勾芒's avatar
勾芒 committed
232 233 234
#pragma mark -场景数据
- (void)getDatasAction
{
235
    __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
236 237 238 239 240 241 242 243 244 245 246
    //场景筛选条件
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/scene/getSceneFilter"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
        
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
             SceneFilter *filterModel = [[SceneFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
            //风格
            NSMutableArray *styleArray = [NSMutableArray array];
            //空间
            NSMutableArray *spaceArray = [NSMutableArray array];
247 248
            [weakSelf.sceneScreeningDatasArray addObject:styleArray];
            [weakSelf.sceneScreeningDatasArray addObject:spaceArray];
勾芒's avatar
勾芒 committed
249 250 251 252 253
            for (DataDict *model in filterModel.styles) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
                newModel.typename = model.typename;
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
254
                [[weakSelf.sceneScreeningDatasArray firstObject] addObject:newModel];
勾芒's avatar
勾芒 committed
255 256 257 258 259 260
            }
            for (DataDict *model in filterModel.space) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
                newModel.typename = model.typename;
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
261
                [[weakSelf.sceneScreeningDatasArray lastObject] addObject:newModel];
勾芒's avatar
勾芒 committed
262
            }
263
            [weakSelf.screeningTableView reloadData];
勾芒's avatar
勾芒 committed
264 265 266
        }
        else
        {
267
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
268 269 270 271 272 273 274 275 276 277 278 279
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
    }];
    
    
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        //默认数据
280
        weakSelf.indexPage = 1;
勾芒's avatar
勾芒 committed
281
        DataPage *page = [[DataPage alloc]init];
282
        page.page = weakSelf.indexPage;
勾芒's avatar
勾芒 committed
283
        page.rows = KROWS;
284 285 286
        weakSelf.conditionModel.page = page;
        [weakSelf.sceneOrProductClollectionView.mj_footer resetNoMoreData];
        [weakSelf getSceneLibrarydatas:weakSelf.conditionModel isRemove:YES];
勾芒's avatar
勾芒 committed
287 288 289 290 291 292 293 294 295
    }];
    
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.sceneOrProductClollectionView.mj_header = headerRefresh;
    [self.sceneOrProductClollectionView.mj_header beginRefreshing];
    //上拉加载
    self.sceneOrProductClollectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
296 297
        if (++ weakSelf.indexPage > weakSelf.totalPages) {
            [weakSelf.sceneOrProductClollectionView.mj_footer endRefreshingWithNoMoreData];
勾芒's avatar
勾芒 committed
298 299 300 301 302
            
        }else
        {
            //默认数据
            DataPage *Newpage = [[DataPage alloc]init];
303
            Newpage.page = weakSelf.indexPage ++;
勾芒's avatar
勾芒 committed
304
            Newpage.rows = KROWS;
305 306
            weakSelf.conditionModel.page = Newpage;
            [weakSelf getSceneLibrarydatas:weakSelf.conditionModel isRemove:NO];
勾芒's avatar
勾芒 committed
307 308 309 310 311 312 313 314
        }
    }];
}


#pragma mark -获取场景列表数据
- (void)getSceneLibrarydatas:(SceneCondition *)condition isRemove:(BOOL)remove
{
315
    __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
316 317
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/scene/query"] WithRequestType:0 WithParameter:condition WithReturnValueBlock:^(id returnValue) {
        
318 319
        weakSelf.sceneOrProductClollectionView.emptyDataSetSource = weakSelf;
        [weakSelf endRefreshingForTableView:weakSelf.sceneOrProductClollectionView];
勾芒's avatar
勾芒 committed
320 321 322
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            if (remove) {
323
                [weakSelf.sceneDatasArray removeAllObjects];
勾芒's avatar
勾芒 committed
324 325
            }
            SceneResponse *response = [[SceneResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
326
            weakSelf.totalPages = [returnValue[@"data"][@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
327 328 329 330 331 332 333 334 335 336 337 338 339
            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
340 341 342 343 344 345 346
            for (SceneListModel *model in SHARED_APPDELEGATE.sceneArray) {
                for (SceneListModel *sceneModel in self.sceneDatasArray) {
                    if ([model.fid isEqualToString:sceneModel.fid]) {
                        sceneModel.isSelectedSate = YES;
                    }
                }
            }
勾芒's avatar
勾芒 committed
347
            
348
            [weakSelf.sceneOrProductClollectionView reloadData];
勾芒's avatar
勾芒 committed
349 350 351
        }
        else
        {
352
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
353 354 355 356 357 358
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
359
        [weakSelf endRefreshingForTableView:weakSelf.sceneOrProductClollectionView];
勾芒's avatar
勾芒 committed
360 361 362 363 364 365 366 367 368
    }];
}


#pragma mark -产品数据
- (void)GetdatasAction
{
    [self getScreeningdatasisRemoveArray:YES];
    //下拉刷新
369
    __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
370 371 372 373 374 375
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        
        //分页数据
        DataPage *Newpage = [[DataPage alloc]init];
        Newpage.page = 1;
        Newpage.rows = KROWS;
376 377 378 379
        weakSelf.goodsModel.page = Newpage;
        weakSelf.indexPage = 1;
        [weakSelf.sceneOrProductClollectionView.mj_footer resetNoMoreData];
        [weakSelf getGoodsListDatasisRemove:YES Withobject:self.goodsModel];
勾芒's avatar
勾芒 committed
380 381 382 383 384 385 386 387 388 389
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.sceneOrProductClollectionView.mj_header = headerRefresh;
    [self.sceneOrProductClollectionView.mj_header beginRefreshing];
    
    //上拉加载
    self.sceneOrProductClollectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        

390 391
        if (++ weakSelf.indexPage > weakSelf.totalPages) {
            [weakSelf.sceneOrProductClollectionView.mj_footer endRefreshingWithNoMoreData];
勾芒's avatar
勾芒 committed
392 393 394 395
        }else
        {
            //分页数据
            DataPage *Newpage = [[DataPage alloc]init];
396
            Newpage.page = weakSelf.indexPage ++;
勾芒's avatar
勾芒 committed
397
            Newpage.rows = KROWS;
398 399
            weakSelf.goodsModel.page = Newpage;
            [weakSelf getGoodsListDatasisRemove:NO Withobject:weakSelf.goodsModel];
勾芒's avatar
勾芒 committed
400 401 402 403 404 405 406 407
        }
    }];
}


#pragma mark -获取产品筛选数据
- (void)getScreeningdatasisRemoveArray:(BOOL)remove
{
408
    __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
409 410 411 412 413
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/goods/getGoodsFilter"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            if (remove) {
414
                [weakSelf.productScreeningDatasArray removeAllObjects];
勾芒's avatar
勾芒 committed
415 416
            }
            GoodsFilter *goodsScreening = [[GoodsFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
417 418 419 420 421

            for (int i=0; i<5; i++) {
                NSMutableArray *array = [NSMutableArray array];
                [weakSelf.productScreeningDatasArray addObject:array];
            }
勾芒's avatar
勾芒 committed
422 423 424 425 426 427
            
            for (DataDict *model in goodsScreening.styles) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
                newModel.typename = model.typename;
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
428
                [[weakSelf.productScreeningDatasArray objectAtIndex_opple:0] addObject:newModel];
勾芒's avatar
勾芒 committed
429 430 431 432 433 434
            }
            for (DataDict *model in goodsScreening.space) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
                newModel.typename = model.typename;
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
435
                [[weakSelf.productScreeningDatasArray objectAtIndex_opple:1] addObject:newModel];
勾芒's avatar
勾芒 committed
436 437 438 439 440 441 442
            }
            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;
443 444
                [weakSelf.openArray addObject:@"0"];//section关闭状态;
                [[weakSelf.productScreeningDatasArray objectAtIndex_opple:2] addObject:newModel];
勾芒's avatar
勾芒 committed
445 446 447 448 449 450
            }
            for (DataDict *model in goodsScreening.material) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
                newModel.typename = model.typename;
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
451
                [[weakSelf.productScreeningDatasArray objectAtIndex_opple:3] addObject:newModel];
勾芒's avatar
勾芒 committed
452 453 454 455 456 457
            }
            for (DataDict *model in goodsScreening.price) {
                DataDictModel *newModel = [[DataDictModel alloc]init];
                newModel.typename = model.typename;
                newModel.typecode = model.typecode;
                newModel.isSelectedSate = NO;
458
                [[weakSelf.productScreeningDatasArray objectAtIndex_opple:4] addObject:newModel];
勾芒's avatar
勾芒 committed
459
            }
460
            [weakSelf.screeningTableView reloadData];
勾芒's avatar
勾芒 committed
461 462 463
        }
        else
        {
464
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
465 466 467 468 469 470
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(NSError *error) {
        
471
        [weakSelf ErrorMBProgressView:error.localizedDescription];
勾芒's avatar
勾芒 committed
472 473 474 475 476 477 478 479 480 481 482 483 484
    }];
}


#pragma mark -获取商品列表数据
- (void)getGoodsListDatasisRemove:(BOOL)remove Withobject:(GoodsCondition *)conditon
{
    
    __weak typeof(self)weakSelf = self;
    [self getGoodsListdatas:conditon returnResponse:^(GoodsResponse *response) {
        
        weakSelf.sceneOrProductClollectionView.emptyDataSetSource = weakSelf;
        if (remove) {
勾芒's avatar
勾芒 committed
485
            [weakSelf.productDatasArray removeAllObjects];
勾芒's avatar
勾芒 committed
486 487 488 489 490 491 492
        }
        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
493
            newModel.categoryName = model.categoryName;
勾芒's avatar
勾芒 committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
            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;
曹云霄's avatar
曹云霄 committed
530
            newModel.goodsNumber = 1;
勾芒's avatar
勾芒 committed
531 532
            [weakSelf.productDatasArray addObject:newModel];
        }
勾芒's avatar
勾芒 committed
533 534 535 536 537 538 539
        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
540 541 542 543 544 545 546
        [weakSelf.sceneOrProductClollectionView reloadData];
    }];
}

#pragma mark -获取商品列表数据
- (void)getGoodsListdatas:(GoodsCondition *)conditon returnResponse:(void(^)(GoodsResponse *))finish
{
547
    __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
548 549 550
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/goods/query"] WithRequestType:0 WithParameter:conditon WithReturnValueBlock:^(id returnValue) {
        
        
551
        [weakSelf endRefreshingForTableView:weakSelf.sceneOrProductClollectionView];
勾芒's avatar
勾芒 committed
552 553 554
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            GoodsResponse *sponse = [[GoodsResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
555
            weakSelf.totalPages = [returnValue[@"data"][@"totalpages"] intValue];
勾芒's avatar
勾芒 committed
556 557 558 559
            //返回结果
            finish(sponse);
        }else
        {
560
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
561 562 563 564
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
565
        [weakSelf ErrorMBProgressView:@"网络连接中断"];
勾芒's avatar
勾芒 committed
566 567
    } WithFailureBlock:^(NSError *error) {
        
568 569
        [weakSelf endRefreshingForTableView:weakSelf.sceneOrProductClollectionView];
        [weakSelf ErrorMBProgressView:error.localizedDescription];
勾芒's avatar
勾芒 committed
570 571 572 573 574
    }];
}



575 576 577
#pragma mark - UITableViewDataSource代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
578
    if (self.rightSelectedIndex == 2) {
勾芒's avatar
勾芒 committed
579
        
勾芒's avatar
勾芒 committed
580 581 582
        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
583 584
    }
    return 0;
585 586 587 588 589
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ScreeningTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ScreeningCellNew" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
590 591
    GoodsCategoryModel *model= [self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex][indexPath.section];
    cell.screeningLabe.text = [[model.children objectAtIndex_opple:indexPath.row] name];
592 593 594 595 596 597 598 599
    return cell;
}

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

勾芒's avatar
勾芒 committed
600 601 602 603 604 605
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self CancelTableviewSectionState];
    ScreeningTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.screeningLabe.backgroundColor = kTCColor(221, 221, 221);
    cell.screeningLabe.textColor = kMainBlueColor;
勾芒's avatar
勾芒 committed
606 607
    self.goodsModel.categoryEquals = [[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:indexPath.row] fid];
    [self.sceneOrProductClollectionView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
608 609
}

610

勾芒's avatar
勾芒 committed
611
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
612
{
勾芒's avatar
勾芒 committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
    SceneSectionHeaderView *sectionView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerView"];
    if (self.isScene) {
        [sectionView.sectionButton setTitle:[[self.sceneScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex][section] typename] forState:UIControlStateNormal];
    }else
    {
        if (self.rightSelectedIndex == 2) {
          [sectionView.sectionButton setTitle:[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex][section] name] forState:UIControlStateNormal];
        }else
        {
          [sectionView.sectionButton setTitle:[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex][section] typename] forState:UIControlStateNormal];
        }
    }
    sectionView.sectionButton.tag = section+100;
    [sectionView.sectionButton addTarget:self action:@selector(SectionButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    return sectionView;
628 629
}

勾芒's avatar
勾芒 committed
630
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
631 632
{
    
勾芒's avatar
勾芒 committed
633 634
    NSArray *array = [self.isScene?self.sceneScreeningDatasArray:self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex];
    return array.count;
635 636
}

勾芒's avatar
勾芒 committed
637 638 639 640
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 55;
}
641 642


勾芒's avatar
勾芒 committed
643

勾芒's avatar
勾芒 committed
644 645 646 647 648
#pragma mark -区头选中
- (void)SectionButtonClickAction:(UIButton *)button
{
    
    [self CancelTableviewSectionState];
勾芒's avatar
勾芒 committed
649 650 651 652
    if (self.rightSelectedIndex !=2 ) {
        button.selected = YES;
        button.backgroundColor = kTCColor(221, 221, 221);
    }
勾芒's avatar
勾芒 committed
653
    [self emptyModel];
勾芒's avatar
勾芒 committed
654 655 656
    switch (self.rightSelectedIndex) {
        case 0://风格
        {
勾芒's avatar
勾芒 committed
657 658 659 660 661 662 663 664
            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
665 666 667 668
        }
            break;
        case 1://空间
        {
勾芒's avatar
勾芒 committed
669 670 671 672 673 674 675 676
            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
677 678 679 680
        }
            break;
        case 2://类型
        {
勾芒's avatar
勾芒 committed
681

勾芒's avatar
勾芒 committed
682 683 684 685
        }
            break;
        case 3://材质
        {
勾芒's avatar
勾芒 committed
686
            self.goodsModel.materialEqueals = [[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:button.tag-100] typecode];
勾芒's avatar
勾芒 committed
687 688 689 690
        }
            break;
        case 4://价格
        {
勾芒's avatar
勾芒 committed
691 692 693 694
            //价格字符串切割
            NSArray *spacrArray = [[[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] objectAtIndex_opple:button.tag-100] typename] componentsSeparatedByString:@"到"];
            self.goodsModel.startprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
            self.goodsModel.endprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
勾芒's avatar
勾芒 committed
695 696 697 698 699 700 701
        }
            break;
            
        default:
            break;
    }
    if (self.rightSelectedIndex == 2) {
勾芒's avatar
勾芒 committed
702 703 704 705 706 707 708 709

        BOOL boolValue = [[self.openArray objectAtIndex_opple:button.tag-100] boolValue];
        NSMutableIndexSet *index = [[NSMutableIndexSet alloc]init];
        for (int i=0; i<self.openArray.count; i++) {
            [self.openArray replaceObjectAtIndex:i withObject:@"0"];
            [index addIndex:i];
        }
        [self.openArray replaceObjectAtIndex:button.tag-100 withObject:boolValue?@"0":@"1"];
710
        [self.screeningTableView reloadSections:index withRowAnimation:UITableViewRowAnimationMiddle];
勾芒's avatar
勾芒 committed
711 712 713 714 715 716
        
    }else
    {
      [self.sceneOrProductClollectionView.mj_header beginRefreshing];
    }
}
717 718 719



勾芒's avatar
勾芒 committed
720 721 722
#pragma mark -tableview取消所有cell选中
- (void)CancelTableviewSectionState
{
勾芒's avatar
勾芒 committed
723 724 725 726 727 728 729

    NSArray *array = nil;
    if (self.isScene) {
        array = [self.sceneScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex];
    }else
    {
        if (self.rightSelectedIndex == 2) {
730
            array = [[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] firstObject] children];
勾芒's avatar
勾芒 committed
731 732 733 734 735
        }else
        {
          array = [self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex];
        }
    }
勾芒's avatar
勾芒 committed
736
    for (int i=0; i<array.count; i++) {
737 738 739 740 741 742 743 744 745
        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
746 747
    }
}
748 749 750



勾芒's avatar
勾芒 committed
751 752 753 754 755 756 757 758 759 760
#pragma mark -UICollectionViewDataSource代理
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.isScene) {
       return self.sceneDatasArray.count;
    }else
    {
        return self.productDatasArray.count;
    }
}
761

勾芒's avatar
勾芒 committed
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
- (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
777
        cell.model = [self.productDatasArray objectAtIndex_opple:indexPath.item];
勾芒's avatar
勾芒 committed
778 779 780 781
        return cell;
    }
}

782 783
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
勾芒's avatar
勾芒 committed
784
    __weak typeof(self)weakSelf = self;
勾芒's avatar
勾芒 committed
785
    [self emptyModel];
786 787 788
    if (self.isScene) {
        ScreeningCollectionViewCell *cell = (ScreeningCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
        CGPoint startPoint = [cell convertPoint:cell.sceneImageView.center toView:self.sceneOrProductClollectionView.window];
勾芒's avatar
勾芒 committed
789 790 791
        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) {
792 793 794 795
                //判断选中的图片是否存在
                if (!boolValue) {
                   [weakSelf StartAddShoppingCarAnimationWithimage:[cell.sceneImageView image] withStartpoint:startPoint withSize:cell.mj_size];
                    model.isSelectedSate = YES;
勾芒's avatar
勾芒 committed
796
                    [weakSelf.sceneOrProductClollectionView reloadItemsAtIndexPaths:@[indexPath]];
797 798 799
                }else
                {
                    model.isSelectedSate = NO;
勾芒's avatar
勾芒 committed
800
                    [weakSelf.sceneOrProductClollectionView reloadItemsAtIndexPaths:@[indexPath]];
801 802 803 804 805 806 807
                }
            }];
        }
    }else
    {
        ProductScreeningCollectionViewCell *cell = (ProductScreeningCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
        CGPoint startPoint = [cell convertPoint:cell.goodsImageView.center toView:self.sceneOrProductClollectionView.window];
808
                if ([self.delegate respondsToSelector:@selector(SelectedImageswithModel:withisScene:returnResponse:)]) {
勾芒's avatar
勾芒 committed
809 810
            GoodsCategoryModel *model = [self.productDatasArray objectAtIndex_opple:indexPath.item];
            [self.delegate SelectedImageswithModel:model withisScene:self.isScene returnResponse:^(BOOL boolValue) {
811 812
                //判断图片是否存在
                if (!boolValue) {
勾芒's avatar
勾芒 committed
813
                    [weakSelf StartAddShoppingCarAnimationWithimage:[cell.goodsImageView image] withStartpoint:startPoint withSize:cell.mj_size];
814
                    model.isSelectedState = YES;
勾芒's avatar
勾芒 committed
815
                    [weakSelf.sceneOrProductClollectionView reloadItemsAtIndexPaths:@[indexPath]];
816 817 818
                }else
                {
                    model.isSelectedState = NO;
勾芒's avatar
勾芒 committed
819
                    [weakSelf.sceneOrProductClollectionView reloadItemsAtIndexPaths:@[indexPath]];
820 821 822 823 824
                }
            }];
        }
    }
}
勾芒's avatar
勾芒 committed
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 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
#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];
    [movePath addQuadCurveToPoint:endPoint
                     controlPoint:controlPoint];
    //关键帧
    CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    
    moveAnim.path = movePath.CGPath;
    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
893 894 895 896

#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
曹云霄's avatar
曹云霄 committed
897
    return kNoDataImage;
勾芒's avatar
勾芒 committed
898 899 900 901 902 903 904
}


- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
}
905 906 907 908 909 910 911 912 913 914 915 916



#pragma mark -筛选条件
- (IBAction)ScreeningConditionsSelectedButtonClick:(UIButton *)sender {
    
    switch (sender.tag) {
        case 100://风格
        {
            
        }
            break;
勾芒's avatar
勾芒 committed
917
        case 101://空间
918 919 920 921
        {
            
        }
            break;
勾芒's avatar
勾芒 committed
922
        case 102://类型
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
        {
            
        }
            break;
        case 103://材质
        {
            
        }
            break;
        case 104://价格
        {
            
        }
            break;
            
        default:
            break;
    }
    
勾芒's avatar
勾芒 committed
942 943 944
    for (int i=0; i<self.openArray.count; i++) {
        [self.openArray replaceObjectAtIndex:i withObject:@"0"];
    }
勾芒's avatar
勾芒 committed
945
    [self emptyModel];
勾芒's avatar
勾芒 committed
946 947 948 949 950 951
    self.rightSelectedIndex = sender.tag - 100;
    [self RemoveAllButtonisSelected];
    [self CancelTableviewSectionState];
    sender.selected = YES;
    sender.backgroundColor = kMainBlueColor;
    [self.screeningTableView reloadData];
952 953 954
}


勾芒's avatar
勾芒 committed
955 956 957 958 959 960 961 962 963 964 965 966 967
#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];
        }
    }
}
968 969 970 971 972 973 974 975 976 977 978 979 980 981


#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
982 983 984 985 986 987 988 989 990 991 992 993
#pragma mark -搜索框
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    [self emptyModel];
    self.goodsModel.nameLike = textField.text;
    [self.sceneOrProductClollectionView.mj_header beginRefreshing];
    return YES;
}



994 995 996 997 998 999 1000 1001 1002 1003 1004
#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
1005 1006 1007
    if (self.dismissBlock) {
        self.dismissBlock();
    }
1008 1009 1010 1011
    [self dismissViewControllerAnimated:YES completion:nil];
}


勾芒's avatar
勾芒 committed
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
#pragma mark -清空模型
- (void)emptyModel
{
    self.searchProductField.text = nil;
    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;
}

1025 1026 1027 1028 1029 1030

- (void)dealloc
{
    
}

1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // 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