SceneViewController.m 36.1 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.
    
勾芒's avatar
勾芒 committed
170
    self.isScene = [[NSUserDefaults standardUserDefaults] 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
    //场景筛选条件
240
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(SCENESCREENING)  WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
241 242 243 244 245 246 247
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
             SceneFilter *filterModel = [[SceneFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
            //风格
            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
        {
曹云霄's avatar
曹云霄 committed
268
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
269 270 271 272 273 274 275
        }
    } WithFailureBlock:^(id error) {
        
    }];
    //下拉刷新
    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);
304
    [[NetworkRequestClassManager Manager] 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 309 310
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            if (remove) {
311
                [weakSelf.sceneDatasArray removeAllObjects];
勾芒's avatar
勾芒 committed
312 313
            }
            SceneResponse *response = [[SceneResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
314
            weakSelf.totalPages = [returnValue[@"data"][@"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
        {
曹云霄's avatar
曹云霄 committed
339
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
勾芒'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);
381
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:SERVERREQUESTURL(PRODUCTSCREENING)  WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
382 383 384 385
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            if (remove) {
386
                [weakSelf.productScreeningDatasArray removeAllObjects];
勾芒's avatar
勾芒 committed
387 388
            }
            GoodsFilter *goodsScreening = [[GoodsFilter alloc]initWithDictionary:returnValue[@"data"] 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
        {
曹云霄's avatar
曹云霄 committed
434
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
435 436
        }
    } WithFailureBlock:^(NSError *error) {
437
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
438
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
439 440 441 442 443 444 445
    }];
}


#pragma mark -获取商品列表数据
- (void)getGoodsListDatasisRemove:(BOOL)remove Withobject:(GoodsCondition *)conditon
{
446
    WS(weakSelf);
勾芒's avatar
勾芒 committed
447 448 449 450
    [self getGoodsListdatas:conditon returnResponse:^(GoodsResponse *response) {
        
        weakSelf.sceneOrProductClollectionView.emptyDataSetSource = weakSelf;
        if (remove) {
勾芒's avatar
勾芒 committed
451
            [weakSelf.productDatasArray removeAllObjects];
勾芒's avatar
勾芒 committed
452 453 454 455 456 457 458
        }
        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
459
            newModel.categoryName = model.categoryName;
勾芒's avatar
勾芒 committed
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 495
            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;
496
            newModel.goodsNumber = ONE;
勾芒's avatar
勾芒 committed
497 498
            [weakSelf.productDatasArray addObject:newModel];
        }
勾芒's avatar
勾芒 committed
499 500 501 502 503 504 505
        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
506 507 508 509 510 511 512
        [weakSelf.sceneOrProductClollectionView reloadData];
    }];
}

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



535 536 537
#pragma mark - UITableViewDataSource代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
538
    if (self.rightSelectedIndex == 2) {
勾芒's avatar
勾芒 committed
539
        
勾芒's avatar
勾芒 committed
540 541 542
        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
543 544
    }
    return 0;
545 546 547 548 549
}

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

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

勾芒's avatar
勾芒 committed
560 561 562 563 564 565
- (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;
566 567
    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
568
    [self.sceneOrProductClollectionView.mj_header beginRefreshing];
勾芒's avatar
勾芒 committed
569 570
}

571

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

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

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


勾芒's avatar
勾芒 committed
604

勾芒's avatar
勾芒 committed
605 606 607 608
#pragma mark -区头选中
- (void)SectionButtonClickAction:(UIButton *)button
{
    [self CancelTableviewSectionState];
勾芒's avatar
勾芒 committed
609 610 611 612
    if (self.rightSelectedIndex !=2 ) {
        button.selected = YES;
        button.backgroundColor = kTCColor(221, 221, 221);
    }
勾芒's avatar
勾芒 committed
613
    [self emptyModel];
勾芒's avatar
勾芒 committed
614 615 616
    switch (self.rightSelectedIndex) {
        case 0://风格
        {
勾芒's avatar
勾芒 committed
617 618 619 620 621 622 623 624
            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
625 626 627 628
        }
            break;
        case 1://空间
        {
勾芒's avatar
勾芒 committed
629 630 631 632 633 634 635 636
            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
637 638 639 640
        }
            break;
        case 2://类型
        {
勾芒's avatar
勾芒 committed
641

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



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

    NSArray *array = nil;
    if (self.isScene) {
        array = [self.sceneScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex];
    }else
    {
        if (self.rightSelectedIndex == 2) {
693
            array = [[[self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex] firstObject] children];
勾芒's avatar
勾芒 committed
694 695 696 697 698
        }else
        {
          array = [self.productScreeningDatasArray objectAtIndex_opple:self.rightSelectedIndex];
        }
    }
勾芒's avatar
勾芒 committed
699
    for (int i=0; i<array.count; i++) {
700 701 702 703 704 705 706 707 708
        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
709 710
    }
}
711 712 713



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

勾芒's avatar
勾芒 committed
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
- (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
740
        cell.model = [self.productDatasArray objectAtIndex_opple:indexPath.item];
勾芒's avatar
勾芒 committed
741 742 743 744
        return cell;
    }
}

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



791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
#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];
807
    [movePath addQuadCurveToPoint:endPoint controlPoint:controlPoint];
808 809 810
    //关键帧
    CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    moveAnim.path = movePath.CGPath;
811
    moveAnim.calculationMode = kCAAnimationLinear;
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 853 854
    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
855 856 857 858

#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
曹云霄's avatar
曹云霄 committed
859
    return kNoDataImage;
勾芒's avatar
勾芒 committed
860 861 862 863 864 865 866
}


- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
}
867 868 869 870 871 872 873 874 875 876 877 878



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


勾芒's avatar
勾芒 committed
917 918 919 920 921 922 923 924 925 926 927 928 929
#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];
        }
    }
}
930 931 932 933 934 935 936 937 938 939 940 941 942 943


#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
944 945 946 947
#pragma mark -搜索框
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self emptyModel];
948
    [textField resignFirstResponder];
勾芒's avatar
勾芒 committed
949 950 951 952 953
    self.goodsModel.nameLike = textField.text;
    [self.sceneOrProductClollectionView.mj_header beginRefreshing];
    return YES;
}

954 955 956 957 958 959 960 961 962 963 964
#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
965 966 967
    if (self.dismissBlock) {
        self.dismissBlock();
    }
968 969 970 971
    [self dismissViewControllerAnimated:YES completion:nil];
}


勾芒's avatar
勾芒 committed
972 973 974 975 976 977 978 979 980 981 982 983
#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;
}

984

985
- (void)didReceiveMemoryWarning {
986
    
987
    [super didReceiveMemoryWarning];
988 989
    [[SDImageCache sharedImageCache] clearDisk];
    NSLog(@"结算到内存警告");
990 991 992 993 994
    // Dispose of any resources that can be recreated.
}


@end