ProductLibraryView.m 24 KB
Newer Older
zhu's avatar
zhu committed
1 2 3 4 5 6 7 8 9 10
//
//  ProductLibraryView.m
//  Lighting
//
//  Created by mac on 16/5/11.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ProductLibraryView.h"

11

zhu's avatar
zhu committed
12
@implementation ProductLibraryView
13 14 15 16 17 18 19 20 21 22 23
/**
 *  初始化商品数据源数组
 */
- (NSMutableArray *)datasArray
{
    if (_datasArray == nil) {
        
        _datasArray = [NSMutableArray array];
    }
    return _datasArray;
}
ZCJ's avatar
ZCJ committed
24 25 26
/**
 *  初始化筛选数据源
 */
zhu's avatar
zhu committed
27
- (NSMutableArray *)arrayData
ZCJ's avatar
ZCJ committed
28
{
zhu's avatar
zhu committed
29
    if (_arrayData == nil) {
ZCJ's avatar
ZCJ committed
30
        
zhu's avatar
zhu committed
31
        _arrayData = [NSMutableArray array];
ZCJ's avatar
ZCJ committed
32
    }
zhu's avatar
zhu committed
33 34
    return _arrayData;
}
35 36 37 38 39 40 41 42 43 44
/**
 *  初始化复选模型
 */
- (GoodsCondition *)condtionModel
{
    if (!_condtionModel) {
        _condtionModel = [[GoodsCondition alloc]init];
    }
    return _condtionModel;
}
zhu's avatar
zhu committed
45 46 47 48

- (void)viewDidLoad {
    [self initdata];
    [self initSubView];
49 50
  
    
zhu's avatar
zhu committed
51

ZCJ's avatar
ZCJ committed
52
}
zhu's avatar
zhu committed
53

zhu's avatar
zhu committed
54 55 56
-(void)initdata
{
    self.arrayData=[[NSMutableArray alloc]init];
57
    self.nameData=[[NSMutableArray alloc]initWithObjects:@"风格",@"类型",@"空间",@"材质",@"价格",nil];
58 59 60 61 62 63 64
    self.cellArray=[[NSMutableArray alloc]init];
    self.showSection=[[NSMutableArray alloc]init];
    self.typeBtnArray=[[NSMutableArray alloc]init];
    self.sectionBtnArray=[[NSMutableArray alloc]init];
    self.cellBtnArray=[[NSMutableArray alloc]init];
    self.indexPage = 1;
    self.selectedIndex=100;
zhu's avatar
zhu committed
65 66 67 68 69 70
    
}
- (void)uiConfigAction
{
    //下拉刷新
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
        
       
            //分页数据
            DataPage *Newpage = [[DataPage alloc]init];
            Newpage.page = 1;
            Newpage.rows = KROWS;
            self.condtionModel.page = Newpage;
            self.indexPage = 1;
            //搜索
            if (self.selectedCode) {
                switch (self.selectedIndex) {
                    case 100://风格
                    {
                        self.condtionModel.styleEquals = self.selectedCode;
                    }
                        break;
                    case 101://类型
                    {
                        self.condtionModel.categoryEquals = self.selectedCode;
                    }
                        break;
                    case 102://空间
                    {
                        self.condtionModel.spaceEquals = self.selectedCode;
                    }
                        break;
                    case 103://材质
                    {
                        self.condtionModel.materialEqueals = self.selectedCode;
                    }
                        break;
                    case 104://价格
                    {
                        //价格字符串切割
                        NSArray *spacrArray = [self.selectedCode componentsSeparatedByString:@"到"];
                        self.condtionModel.startprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
                        self.condtionModel.endprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
                        self.condtionModel.categoryEquals = self.selectedCode;
                    }
                        break;
                        
                    default:
                        break;
                }
                
           }
            [self.collectionView.mj_footer resetNoMoreData];
            [self getScreeningdatasisRemoveArray:YES];
            [self getGoodsListDatasisRemove:YES Withobject:self.condtionModel];
        
zhu's avatar
zhu committed
121 122 123 124 125
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.collectionView.mj_header = headerRefresh;
    [self.collectionView.mj_header beginRefreshing];
126
    
zhu's avatar
zhu committed
127 128 129
    //上拉加载
    self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
        
            if (self.indexPage ++ > self.totalPages) {
                [self.collectionView.mj_footer endRefreshingWithNoMoreData];
            }else
            {
                //分页数据
                DataPage *Newpage = [[DataPage alloc]init];
                Newpage.page = self.indexPage ++;
                Newpage.rows = KROWS;
                self.condtionModel.page = Newpage;
                //搜索
                if (self.selectedCode) {
                    self.condtionModel.categoryEquals = self.selectedCode;
                }
                [self getGoodsListDatasisRemove:NO Withobject:self.condtionModel];
            }
        
zhu's avatar
zhu committed
147 148
    }];

zhu's avatar
zhu committed
149
}
ZCJ's avatar
ZCJ committed
150 151

#pragma mark -获取商品列表数据
zhu's avatar
zhu committed
152
- (void)getGoodsListDatasisRemove:(BOOL)remove Withobject:(GoodsCondition *)conditon
ZCJ's avatar
ZCJ committed
153 154 155 156
{

    [self getGoodsListdatas:conditon returnResponse:^(GoodsResponse *response) {
        if (response.goodsEntity.count == 0) {
zhu's avatar
zhu committed
157
            
ZCJ's avatar
ZCJ committed
158
            [self ErrorMBProgressView:@"暂无数据"];
159
            
zhu's avatar
zhu committed
160 161 162 163
        }else
        {
            if (remove) {
                [self.datasArray removeAllObjects];
ZCJ's avatar
ZCJ committed
164
            }
zhu's avatar
zhu committed
165
            for (TOGoodsEntity *model in response.goodsEntity) {
166
                [self.datasArray addObject:model];
zhu's avatar
zhu committed
167
            }
168 169
            [self.collectionView reloadData];
             [self.seceneTableView reloadData];
zhu's avatar
zhu committed
170
        }
ZCJ's avatar
ZCJ committed
171 172 173 174
    }];
}

#pragma mark -获取产品筛选数据
zhu's avatar
zhu committed
175 176
- (void)getScreeningdatasisRemoveArray:(BOOL)remove

ZCJ's avatar
ZCJ committed
177 178 179
{

    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/goods/getGoodsFilter"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
zhu's avatar
zhu committed
180

ZCJ's avatar
ZCJ committed
181
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
zhu's avatar
zhu committed
182 183 184
            if (remove) {
                [self.arrayData removeAllObjects];
            }
ZCJ's avatar
ZCJ committed
185 186

            GoodsFilter *goodsStyle = [[GoodsFilter alloc]initWithDictionary:returnValue[@"data"] error:nil];
187
            self.goodsFilter=goodsStyle;
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
            switch (self.selectedIndex) {
                case 100:
                    //            风格
                    self.arrayData=[NSMutableArray arrayWithArray:self.goodsFilter.styles];
                    
                    break;
                case 101:
                    //            类型
                    self.arrayData=[NSMutableArray arrayWithArray:self.goodsFilter.categories];
                    break;
                case 102:
                    //            空间
                    self.arrayData=[NSMutableArray arrayWithArray:self.goodsFilter.space];
                    break;
                case 103:
                    //            材质
                    self.arrayData=[NSMutableArray arrayWithArray:self.goodsFilter.material];
                    break;
                case 104:
                    //            价格
                    self.arrayData=[NSMutableArray arrayWithArray:self.goodsFilter.price];
                    break;
                    
                default:
                    break;
            }
            
215
            [self.seceneTableView reloadData];
ZCJ's avatar
ZCJ committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
        }
        else
            {
            [self ErrorMBProgressView:returnValue[@"message"]];
            }

    } WithErrorCodeBlock:^(id errorCodeValue) {

    } WithFailureBlock:^(id error) {

        NSLog(@"%@",error);
    }];
}



#pragma mark -获取商品列表数据
- (void)getGoodsListdatas:(GoodsCondition *)conditon returnResponse:(void(^)(GoodsResponse *))finish
{

    [self CreateMBProgressHUDLoding];
zhu's avatar
zhu committed
237
     [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/goods/query"] WithRequestType:0 WithParameter:conditon WithReturnValueBlock:^(id returnValue) {
ZCJ's avatar
ZCJ committed
238 239

        [self RemoveMBProgressHUDLoding];
zhu's avatar
zhu committed
240
        [self endRefreshingForTableView:self.collectionView];
ZCJ's avatar
ZCJ committed
241 242 243 244 245 246 247 248 249 250 251 252 253 254
        if ([returnValue[@"code"] isEqualToNumber:@0]) {

            GoodsResponse *sponse = [[GoodsResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
            //返回结果
            finish(sponse);
        }
        else
            {
            [self ErrorMBProgressView:@"暂无数据"];
            }

    } WithErrorCodeBlock:^(id errorCodeValue) {

    } WithFailureBlock:^(id error) {
zhu's avatar
zhu committed
255
         [self endRefreshingForTableView:self.collectionView];
ZCJ's avatar
ZCJ committed
256 257 258
        [self RemoveMBProgressHUDLoding];
    }];
}
zhu's avatar
zhu committed
259 260 261 262 263
-(void)initSubView
{
    for (int i=0; i<self.nameData.count; i++) {
        if (i !=5) {
            UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
264
            btn.frame=CGRectMake(ScreenWidth-250, 52+i*50, 100, 46) ;
zhu's avatar
zhu committed
265 266
            btn.backgroundColor=[UIColor whiteColor];
            [btn setTitle:[self.nameData objectAtIndex:i] forState:UIControlStateNormal];
267
             btn.contentEdgeInsets = UIEdgeInsetsMake(0, 40, 0, 0);
zhu's avatar
zhu committed
268 269
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(selectedType:) forControlEvents:UIControlEventTouchUpInside];
270 271 272 273 274 275 276 277
            if (i==0) {
                btn.backgroundColor=RGB(79, 153, 217, 1);
                [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            }else
            {
                 btn.backgroundColor=RGB(225, 225, 225, 1);
                 [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            }
zhu's avatar
zhu committed
278 279
            btn.tag=100 +i;
            btn.layer.masksToBounds = YES;
280 281
            btn.layer.cornerRadius = 20;
            [self.typeBtnArray addObject:btn];
zhu's avatar
zhu committed
282
            [self.view addSubview:btn];
zhu's avatar
zhu committed
283 284 285 286 287
        }
       
    }
    self.subView=[[UIView alloc]initWithFrame:CGRectMake(100, 50, ScreenWidth-300, ScreenHeight-200)];
    self.subView.backgroundColor=[UIColor whiteColor];
zhu's avatar
zhu committed
288
    [self.view  addSubview:self.subView];
zhu's avatar
zhu committed
289 290 291 292 293 294 295

    //点击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(DismissScreenView:)];
    tap.delegate = self;
    tap.cancelsTouchesInView = NO;
    [[UIApplication sharedApplication].keyWindow addGestureRecognizer:tap];
    [self initSubViews];
zhu's avatar
zhu committed
296
   
ZCJ's avatar
ZCJ committed
297
    
zhu's avatar
zhu committed
298 299 300 301 302 303
}


-(void)initSubViews
{
    self.headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.subView.frame.size.width-100, 50)];
304
    self.headerView.backgroundColor=RGB(225, 225, 225, 1);
zhu's avatar
zhu committed
305 306 307
    [self.subView addSubview:self.headerView];
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(10, 10, 30, 30);
308
    [btn setBackgroundImage:[UIImage imageNamed:@"Folder"] forState:UIControlStateNormal];
zhu's avatar
zhu committed
309 310 311 312
    [self.headerView addSubview:btn];
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(45, 10, 100, 30)];
    lable.text=@"选择产品";
    [self.headerView addSubview:lable];
313 314 315 316 317 318
    //输入框背景
    UIImageView *backView = [[UIImageView alloc]initWithFrame:CGRectMake(self.headerView.frame.size.width-300, 10,250, 30)];
    backView.userInteractionEnabled=YES;
    [backView setImage:[UIImage imageNamed:@"line"]];
    [self.headerView addSubview:backView];
    //搜索图标
mei's avatar
mei committed
319
    UIButton *searchBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 0, 25, 25)];
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
    searchBtn.backgroundColor=RGB(225, 225, 225, 1);
    [searchBtn setBackgroundImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal] ;
    [searchBtn addTarget:self action:@selector(searchProduct:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:searchBtn];

    
    //输入框
   self.searchTextField = [[UITextField alloc]initWithFrame:CGRectMake(50, 0, backView.frame.size.width-50, 29)];
    self.searchTextField.borderStyle = UITextBorderStyleNone;
    self.searchTextField.placeholder = @" 请输入产品关键字";
    self.searchTextField.font = [UIFont systemFontOfSize:12];
    self.searchTextField.returnKeyType = UIReturnKeySearch;
    [backView addSubview:self.searchTextField];
//
    
zhu's avatar
zhu committed
335 336 337
    self.seceneTableView=[[UITableView alloc]initWithFrame:CGRectMake( self.headerView.frame.size.width, 0, 100, self.subView.frame.size.height)];
    self.seceneTableView.delegate=self;
    self.seceneTableView.dataSource=self;
338 339
    self.seceneTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.seceneTableView.tableHeaderView=nil;
zhu's avatar
zhu committed
340 341
    [self.subView addSubview:self.seceneTableView];
    
zhu's avatar
zhu committed
342 343 344 345 346 347 348 349
 
    //确定是水平滚动,还是垂直滚动
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    
    self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake( 0, 50, self.headerView.frame.size.width, self.subView.frame.size.height-50) collectionViewLayout:flowLayout];
    self.collectionView.dataSource=self;
    self.collectionView.delegate=self;
350
    [self.collectionView setBackgroundColor:RGB(241, 241, 241, 1)];
zhu's avatar
zhu committed
351 352 353 354
    //注册Cell,必须要有
    [self.collectionView registerClass:[ProductCollectionPictureCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
    
    [self.subView addSubview:self.collectionView];
355
    [self uiConfigAction];
zhu's avatar
zhu committed
356 357 358
}
-(void)selectedType:(UIButton *)sender
{
359 360 361 362 363 364 365 366 367 368
   
    for (UIButton *btn in self.typeBtnArray) {
        btn.backgroundColor=RGB(225, 225, 225, 1);
       [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    sender.backgroundColor=RGB(79, 153, 217, 1);
    [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    btn.backgroundColor=RGB(79, 153, 217, 1);
//    btn.backgroundColor=RGB(225, 225, 225, 1);
    self.selectedIndex=sender.tag;
zhu's avatar
zhu committed
369 370 371
            switch (sender.tag) {
                case 100:
                    //            风格
zhu's avatar
zhu committed
372
                    self.arrayData=[NSMutableArray arrayWithArray:self.goodsFilter.styles];
373
                    
zhu's avatar
zhu committed
374 375 376
                    break;
                case 101:
                    //            类型
zhu's avatar
zhu committed
377
                    self.arrayData=[NSMutableArray arrayWithArray:self.goodsFilter.categories];
zhu's avatar
zhu committed
378 379 380
                    break;
                case 102:
                    //            空间
zhu's avatar
zhu committed
381
                    self.arrayData=[NSMutableArray arrayWithArray:self.goodsFilter.space];
zhu's avatar
zhu committed
382 383 384
                    break;
                case 103:
                    //            材质
zhu's avatar
zhu committed
385
                    self.arrayData=[NSMutableArray arrayWithArray:self.goodsFilter.material];
zhu's avatar
zhu committed
386 387 388
                    break;
                case 104:
                    //            价格
zhu's avatar
zhu committed
389
                    self.arrayData=[NSMutableArray arrayWithArray:self.goodsFilter.price];
zhu's avatar
zhu committed
390
                    break;
391
              
zhu's avatar
zhu committed
392 393 394 395
                default:
                    break;
            }
    [self.seceneTableView reloadData];
mei's avatar
mei committed
396
//    [self.collectionView.mj_header beginRefreshing];
zhu's avatar
zhu committed
397
}
398
-(void)didSelectSection:(UIButton *)sender
zhu's avatar
zhu committed
399
{
400 401 402 403 404 405 406 407 408
    [self.sectionBtnArray removeAllObjects];
    [self.sectionBtnArray addObject:sender.titleLabel.text];
    sender.backgroundColor=RGB(221, 221, 221, 1);
   
    switch (self.selectedIndex) {
        case 100://风格
        {
            self.selectedCode = [[self.arrayData objectAtIndex_opple:sender.tag-100] typecode] ;
            [self.collectionView.mj_header beginRefreshing];
409
        }
410 411 412
            break;
        case 101://类型
        {
勾芒's avatar
勾芒 committed
413
            if ([[NSString stringWithFormat:@"%ld",sender.tag-100 ]isEqualToString:[NSString stringWithFormat:@"%@",[self.showSection firstObject]]]) {
414 415 416 417 418 419 420 421 422 423
                [self.cellArray removeAllObjects ];
                [self.showSection removeAllObjects];
                [self.seceneTableView reloadData];
            }else
            {
                [self.cellArray removeAllObjects ];
                [self.showSection removeAllObjects];
                self.selectedCode = [[self.arrayData objectAtIndex_opple:sender.tag-100] fid] ;
                [self.collectionView.mj_header beginRefreshing];
                self.cellArray=[NSMutableArray arrayWithArray:[[self.arrayData objectAtIndex_opple:sender.tag-100] children]];
勾芒's avatar
勾芒 committed
424
                [self.showSection addObject:[NSString stringWithFormat:@"%ld",sender.tag-100]];
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
                [self.seceneTableView reloadData];
            }
          
        }
            break;
        case 102://空间
        {
         self.selectedCode = [[self.arrayData objectAtIndex_opple:sender.tag-100] typecode] ;
        [self.collectionView.mj_header beginRefreshing];
        }
            break;
        case 103://材质
        {
            self.selectedCode = [[self.arrayData objectAtIndex_opple:sender.tag-100] typecode] ;
            [self.collectionView.mj_header beginRefreshing];

        }
            break;
        case 104://价格
        {
            self.selectedCode = [[self.arrayData objectAtIndex_opple:sender.tag-100] typecode] ;
            [self.collectionView.mj_header beginRefreshing];
        }
            break;
            
        default:
            break;
452
    }
453

zhu's avatar
zhu committed
454
}
455
#pragma mark -- UICollectionViewDataSource
zhu's avatar
zhu committed
456 457 458
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
459 460
      return self.datasArray.count;

zhu's avatar
zhu committed
461 462
}

463

zhu's avatar
zhu committed
464 465 466 467 468
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"UICollectionViewCell";
    ProductCollectionPictureCell * cell = (ProductCollectionPictureCell*)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
zhu's avatar
zhu committed
469
    NSArray *imageArray = [[[self.datasArray objectAtIndex_opple:indexPath.item] pictures] componentsSeparatedByString:@","];
470 471 472 473 474 475
    [cell.productImageView sd_setImageWithURL:[NSURL URLWithString:[imageArray firstObject]] placeholderImage:REPLACEIMAGE];
    cell.productDesce.text=[[self.datasArray objectAtIndex_opple:indexPath.item] name];

   TOGoodsEntity *model = [self.datasArray objectAtIndex_opple:indexPath.item];
    cell.productPrice.text = [NSString stringWithFormat:@"¥%@",[[[self.datasArray objectAtIndex_opple:indexPath.item] tagPrice] stringValue]];
    cell.productParameter.text=[NSString stringWithFormat:@"%@ %@ ",model.code,model.size];
zhu's avatar
zhu committed
476
    cell.productModel=[self.datasArray objectAtIndex_opple:indexPath.item];
477

zhu's avatar
zhu committed
478 479 480 481 482 483
    return cell;
}
#pragma mark --UICollectionViewDelegateFlowLayout
//定义每个Item 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
zhu's avatar
zhu committed
484
    return CGSizeMake(190, 150);
zhu's avatar
zhu committed
485 486 487 488 489
}

//定义每个UICollectionView 的边距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
490
    return UIEdgeInsetsMake(10, 10, 20, 20);
zhu's avatar
zhu committed
491 492 493 494 495 496 497 498 499 500 501 502
}
//定义每个UICollectionView 的纵向间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 2;
}

#pragma mark --UICollectionViewDelegate

//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ProductCollectionPictureCell * cell = (ProductCollectionPictureCell *)[collectionView cellForItemAtIndexPath:indexPath];
zhu's avatar
zhu committed
503
    if ([self.delegate respondsToSelector:@selector(addProductImage:productModel:)]) {
zhu's avatar
zhu committed
504
        
zhu's avatar
zhu committed
505
        [self.delegate addProductImage:cell.productImageView.image productModel:cell.productModel];
zhu's avatar
zhu committed
506 507 508 509 510 511 512 513 514 515
    }

}

//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

zhu's avatar
zhu committed
516
#pragma mark - 协议方法
517 518 519 520 521
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}

zhu's avatar
zhu committed
522
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
523
    return self.arrayData.count;;
zhu's avatar
zhu committed
524
}
525
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
zhu's avatar
zhu committed
526
{
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 50)];
    view.backgroundColor = [UIColor whiteColor];
    NSString *str=[[NSString alloc]init];
    if (self.selectedIndex==101) {
        str=[NSString stringWithFormat:@"%@",[[self.arrayData objectAtIndex_opple:section] name]];
    }else
    {
       str=[NSString stringWithFormat:@"%@",[[self.arrayData objectAtIndex_opple:section] typename]];
    }
    
    UIButton *btn=[[ UIButton alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height-1)];
    [btn setTitle:str forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    if ([str isEqualToString:[self.sectionBtnArray firstObject]]) {
        btn.backgroundColor=RGB(221, 221, 221, 1);
        [btn setTitleColor:RGB(79, 153, 217, 1) forState:UIControlStateNormal];
    }else
    {
        btn.backgroundColor=[UIColor whiteColor];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    btn.tag=section+100;
    btn.titleLabel.font=[UIFont systemFontOfSize:15];
    [btn addTarget:self action:@selector(didSelectSection:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(0, view.frame.size.height-1, view.frame.size.width, 1)];
    lable.backgroundColor=[UIColor grayColor];
    [view addSubview:lable];
    return view;
zhu's avatar
zhu committed
556
}
557 558 559
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.selectedIndex==101) {//类型
勾芒's avatar
勾芒 committed
560
        if ([self.showSection containsObject:[NSString stringWithFormat:@"%ld",(long)section]]) {
561 562 563 564 565 566 567 568 569 570
            return self.cellArray.count;
        }else
        {
            return 0;
        }
    }else
    {
        return 0;
    }
    
zhu's avatar
zhu committed
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([tableView isEqual:self.seceneTableView])
    {
        return 50;
    }else
    {
        return 150;
    }
    
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
zhu's avatar
zhu committed
589
           static NSString *cellID = @"ChooseTansferCell";
zhu's avatar
zhu committed
590 591 592
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
593 594
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;

zhu's avatar
zhu committed
595
        }
596 597
    cell.backgroundColor=[UIColor whiteColor];
    cell.textLabel.textColor=[UIColor blackColor];
598
    
599 600 601 602 603 604 605 606 607
    if ([[self.cellArray objectAtIndex_opple:indexPath.row]isKindOfClass:[GoodsCategory class]]) {
        cell.textLabel.text=[[self.cellArray objectAtIndex_opple:indexPath.row] name];
        if ([cell.textLabel.text isEqualToString:[self.cellBtnArray firstObject]]) {
            cell.backgroundColor=RGB(221, 221, 221, 1);
            cell.textLabel.textColor=RGB(79, 153, 217, 1);
        }
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }//        05产品库-详情_03
           return cell;
zhu's avatar
zhu committed
608 609 610 611 612
        
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
613 614 615 616 617 618 619 620 621 622 623 624 625 626
    [self.cellBtnArray removeAllObjects];
    self.selectedCode = [[self.cellArray objectAtIndex_opple:indexPath.row] fid] ;
    [self.cellBtnArray addObject:[[self.cellArray objectAtIndex_opple:indexPath.row] name]];

    [self.collectionView.mj_header beginRefreshing];
    
}
//产品搜索
-(void)searchProduct:(UIButton *)sender
{
    if (self.searchTextField.text==nil||[self.searchTextField.text isEqualToString:@""]) {
        [self  SHOWPrompttext:@"请先输入搜索关键字"];
    }else
    {
627 628 629
    self.condtionModel.nameLike=self.searchTextField.text;
    [self.collectionView.mj_header beginRefreshing];
 
630
    }
zhu's avatar
zhu committed
631
    
zhu's avatar
zhu committed
632
}
633

zhu's avatar
zhu committed
634
-(void)DismissScreenView:(UITapGestureRecognizer*)sender{
zhu's avatar
zhu committed
635
    CGPoint point = [sender locationInView:self.view];
zhu's avatar
zhu committed
636
    if (point.x<100 || point.x >ScreenWidth-150||point.y<50||point.y>ScreenHeight-150) {
zhu's avatar
zhu committed
637 638
        
        if (self) {
639 640 641 642
            if ([self.delegate respondsToSelector:@selector(restProductBtnImage)]) {
                [self.delegate restProductBtnImage];
            }
           
zhu's avatar
zhu committed
643 644 645
        }
    }
}
zhu's avatar
zhu committed
646 647 648 649 650 651 652 653 654 655

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end