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

#import "screeningSecondView.h"
#import "ScreeningFirstCollectionViewCell.h"
曹云霄's avatar
曹云霄 committed
11 12
#import "ScreeningSecondCollectionReusableView.h"

曹云霄's avatar
曹云霄 committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

#define WIDTH self.screeningCollectionView.frame.size.width

@implementation screeningSecondView

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




- (void)awakeFromNib
{
曹云霄's avatar
曹云霄 committed
31
//    [self uiConfigAction];
32 33 34
    self.defaultDatasArray = [NSMutableArray array];
    for (int i=0; i<5; i++) {
        
曹云霄's avatar
曹云霄 committed
35
        NSDictionary *defaultDict = @{@"typecode":@"",@"typename":@"全部"};
36 37 38
        [self.defaultDatasArray addObject:defaultDict];
    }
    [self uiConfigAction];
曹云霄's avatar
曹云霄 committed
39 40 41
}


曹云霄's avatar
曹云霄 committed
42 43 44 45 46 47 48
#pragma mark -获取数据
- (void)setDatasArray:(NSArray *)datasArray
{
    _datasArray = datasArray;
    [self.screeningCollectionView reloadData];
}

曹云霄's avatar
曹云霄 committed
49 50 51 52 53 54

#pragma mark - 布局
- (void)uiConfigAction
{
    self.screeningTableview.delegate = self;
    self.screeningTableview.dataSource = self;
55
    self.screeningTableview.tableFooterView = [UIView new];
曹云霄's avatar
曹云霄 committed
56
    self.screeningTableview.backgroundColor = [UIColor grayColor];
曹云霄's avatar
曹云霄 committed
57 58 59 60 61
    [self.screeningTableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"tableviewcell"];
    self.screeningLayout.itemSize = CGSizeMake((WIDTH-127)/3, 35);
    self.screeningLayout.minimumLineSpacing = 30;
    self.screeningLayout.minimumInteritemSpacing = 10;
    self.screeningLayout.sectionInset = UIEdgeInsetsMake(20, 30, 20, 30);
62 63
    self.screeningResultButton.layer.masksToBounds = YES;
    self.screeningResultButton.layer.cornerRadius = kCornerRadius;
曹云霄's avatar
曹云霄 committed
64
    [self.screeningCollectionView registerClass:[ScreeningFirstCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
曹云霄's avatar
曹云霄 committed
65
    [self.screeningCollectionView registerClass:[ScreeningSecondCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"screeningcell"];
曹云霄's avatar
曹云霄 committed
66 67
    self.screeningCollectionView.dataSource = self;
    self.screeningCollectionView.delegate = self;
曹云霄's avatar
曹云霄 committed
68
    self.screeningCollectionView.alwaysBounceVertical = YES;
曹云霄's avatar
曹云霄 committed
69 70 71 72 73 74
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tableviewcell" forIndexPath:indexPath];
75 76
    cell.textLabel.text = [self.defaultDatasArray objectAtIndex_opple:indexPath.row][@"typename"];
    cell.textLabel.font = [UIFont systemFontOfSize:10];
曹云霄's avatar
曹云霄 committed
77 78
    cell.selectedBackgroundView.backgroundColor = [UIColor whiteColor];
    cell.backgroundColor = [UIColor grayColor];
曹云霄's avatar
曹云霄 committed
79 80 81 82 83 84
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
85
    return self.defaultDatasArray.count;
曹云霄's avatar
曹云霄 committed
86 87 88 89
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
90
    return 55;
曹云霄's avatar
曹云霄 committed
91 92
}

曹云霄's avatar
曹云霄 committed
93 94 95 96 97 98 99 100
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    if ([self.delegate respondsToSelector:@selector(tableSelectedindex:)]) {
        
        [self.delegate tableSelectedindex:indexPath.row];
    }
}
曹云霄's avatar
曹云霄 committed
101 102 103 104

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ScreeningFirstCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
105 106 107 108 109 110 111 112
    if (self.selectedIndex == 1) {
        
        cell.titleLabe.text = [[[[self.datasArray objectAtIndex_opple:indexPath.section] children] objectAtIndex_opple:indexPath.row] name];
    }
    else
    {
        cell.titleLabe.text = [[self.datasArray objectAtIndex_opple:indexPath.row] typename];
    }
曹云霄's avatar
曹云霄 committed
113 114 115 116 117
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
118 119 120 121 122
    if (self.selectedIndex == 1) {
        
        return [[[self.datasArray objectAtIndex_opple:section] children] count];
        
    }
曹云霄's avatar
曹云霄 committed
123 124 125 126 127 128 129 130
    return self.datasArray.count;
}



- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    ScreeningSecondCollectionReusableView *cell = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"screeningcell" forIndexPath:indexPath];
131 132 133 134 135 136 137 138 139 140
    
    self.selectedIndex == 1?(cell.subTitleButton.hidden = NO):(cell.subTitleButton.hidden = YES);
    [cell.alltitleButton addTarget:self action:@selector(AllButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    if (self.selectedIndex == 1) {
       
        NSString *subTitle = [[self.datasArray objectAtIndex_opple:indexPath.section] name];
        [cell.subTitleButton setTitle:subTitle forState:UIControlStateNormal];
    }

曹云霄's avatar
曹云霄 committed
141 142 143 144 145 146
    return cell;
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{

147 148 149 150
    if (self.selectedIndex == 1 && section == 0) {
        
        return CGSizeMake(self.screeningCollectionView.frame.size.width, 130);
    }
曹云霄's avatar
曹云霄 committed
151
    return CGSizeMake(self.screeningCollectionView.frame.size.width, 75);
曹云霄's avatar
曹云霄 committed
152 153 154
}


155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //选中后的tableview赋值,并传递typecode筛选商品
    UITableViewCell *cell = [self.screeningTableview cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIndex inSection:0]];
    
    //选中类型的文本
    NSString *selectedTitle = nil;
    //选中的key
    NSString *selectedTypecode = nil;
    if (self.selectedIndex == 1) {
        
        selectedTitle = [[[[self.datasArray objectAtIndex_opple:indexPath.section] children] objectAtIndex_opple:indexPath.row] name];
        selectedTypecode = [[[[self.datasArray objectAtIndex_opple:indexPath.section] children] objectAtIndex_opple:indexPath.row] fid];
    }
    else
    {
        selectedTitle = [[self.datasArray objectAtIndex_opple:indexPath.row] typename];
        selectedTypecode = [[self.datasArray objectAtIndex_opple:indexPath.row] typecode];
    }
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:selectedTitle,@"typename",selectedTypecode,@"typecode", nil];
    [self.defaultDatasArray replaceObjectAtIndex:self.selectedIndex withObject:dict];
    cell.textLabel.text = selectedTitle;
    [self JudgeDelegateIsPerformWithPassParamater];
}
曹云霄's avatar
曹云霄 committed
180 181


182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
#pragma mark -区头的全部按钮点击
- (void)AllButtonClick:(UIButton *)button
{
    UITableViewCell *cell = [self.screeningTableview cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIndex inSection:0]];
    cell.textLabel.text = @"全部";
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:button.currentTitle,@"typename", nil];
    [self.defaultDatasArray replaceObjectAtIndex:self.selectedIndex withObject:dict];
    [self JudgeDelegateIsPerformWithPassParamater];

}


#pragma mark -判断代理是否被执行,并传递复选的参数
- (void)JudgeDelegateIsPerformWithPassParamater
{
    if ([self.delegate respondsToSelector:@selector(collectionSelectedindexWithStyleCode:withCategories:withSpace:withMaterial:withPrice:)]) {
        
        //传回选中的所有条件
        [self.delegate collectionSelectedindexWithStyleCode:[self.defaultDatasArray objectAtIndex_opple:0][@"typecode"] withCategories:[self.defaultDatasArray objectAtIndex_opple:1][@"typecode"] withSpace:[self.defaultDatasArray objectAtIndex_opple:2][@"typecode"] withMaterial:[self.defaultDatasArray objectAtIndex_opple:3][@"typecode"] withPrice:[self.defaultDatasArray objectAtIndex_opple:4][@"typename"]];
    }
}

曹云霄's avatar
曹云霄 committed
204

曹云霄's avatar
曹云霄 committed
205 206
#pragma mark -筛选结果点击
- (IBAction)ScreeningResultButtonClick:(UIButton *)sender {
曹云霄's avatar
曹云霄 committed
207
    
208 209 210 211
    if ([self.delegate respondsToSelector:@selector(ShowScreeningResponse)]) {
        
        [self.delegate ShowScreeningResponse];
    }
曹云霄's avatar
曹云霄 committed
212 213
}

曹云霄's avatar
曹云霄 committed
214 215


216 217 218 219 220 221 222
#pragma mark -传入满足搜索条件的个数
- (void)setTotalNumber:(NSInteger)totalNumber
{
    _totalNumber = totalNumber;
    [self.screeningResultButton setTitle:[NSString stringWithFormat:@"筛选结果共%ld件商品",totalNumber] forState:UIControlStateNormal];
     
}
曹云霄's avatar
曹云霄 committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242



















@end