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

#import "screeningSecondView.h"
10
#import "SelectedTableViewCell.h"
曹云霄's avatar
曹云霄 committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

#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
29
    [super awakeFromNib];
30 31 32
    self.defaultDatasArray = [NSMutableArray array];
    for (int i=0; i<5; i++) {
        
曹云霄's avatar
曹云霄 committed
33
        NSDictionary *defaultDict = @{@"typecode":@"",@"typename":@"全部"};
34 35 36
        [self.defaultDatasArray addObject:defaultDict];
    }
    [self uiConfigAction];
曹云霄's avatar
曹云霄 committed
37 38 39
}


曹云霄's avatar
曹云霄 committed
40 41 42 43
#pragma mark -获取数据
- (void)setDatasArray:(NSArray *)datasArray
{
    _datasArray = datasArray;
44 45 46 47
    [self resetCellselectedState];
    SelectedTableViewCell *cell = [self.screeningTableview cellForRowAtIndexPath:[NSIndexPath indexPathForRow:_selectedIndex inSection:0]];
    cell.titleLabe.backgroundColor = [UIColor whiteColor];
    cell.titleLabe.textColor = kMainBlueColor;
勾芒's avatar
勾芒 committed
48 49
    
    
曹云霄's avatar
曹云霄 committed
50 51 52
    [self.screeningCollectionView reloadData];
}

曹云霄's avatar
曹云霄 committed
53

54 55 56 57 58 59 60 61 62 63
#pragma mark -取消cell的选中状态
- (void)resetCellselectedState
{
    NSArray *cellArray = [self.screeningTableview visibleCells];
    for (SelectedTableViewCell *CELL in cellArray) {
        CELL.titleLabe.backgroundColor = [UIColor grayColor];
        CELL.titleLabe.textColor = [UIColor whiteColor];
    }
}

曹云霄's avatar
曹云霄 committed
64 65 66 67 68
#pragma mark - 布局
- (void)uiConfigAction
{
    self.screeningTableview.delegate = self;
    self.screeningTableview.dataSource = self;
69
    self.screeningTableview.tableFooterView = [UIView new];
70
    self.screeningTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
曹云霄's avatar
曹云霄 committed
71
    self.screeningTableview.backgroundColor = [UIColor grayColor];
72
    [self.screeningTableview registerClass:[SelectedTableViewCell class] forCellReuseIdentifier:@"tableviewcell"];
曹云霄's avatar
曹云霄 committed
73 74 75 76
    self.screeningLayout.itemSize = CGSizeMake((WIDTH-127)/3, 35);
    self.screeningLayout.minimumLineSpacing = 30;
    self.screeningLayout.minimumInteritemSpacing = 10;
    self.screeningLayout.sectionInset = UIEdgeInsetsMake(20, 30, 20, 30);
77 78
    self.screeningResultButton.layer.masksToBounds = YES;
    self.screeningResultButton.layer.cornerRadius = kCornerRadius;
曹云霄's avatar
曹云霄 committed
79
    [self.screeningCollectionView registerClass:[ScreeningFirstCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
曹云霄's avatar
曹云霄 committed
80
    [self.screeningCollectionView registerClass:[ScreeningSecondCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"screeningcell"];
曹云霄's avatar
曹云霄 committed
81 82
    self.screeningCollectionView.dataSource = self;
    self.screeningCollectionView.delegate = self;
曹云霄's avatar
曹云霄 committed
83
    self.screeningCollectionView.alwaysBounceVertical = YES;
曹云霄's avatar
曹云霄 committed
84 85 86 87 88
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
89 90 91
    SelectedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tableviewcell" forIndexPath:indexPath];
    cell.titleLabe.text = [self.defaultDatasArray objectAtIndex_opple:indexPath.row][@"typename"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
曹云霄's avatar
曹云霄 committed
92 93 94 95 96
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
97
    return self.defaultDatasArray.count;
曹云霄's avatar
曹云霄 committed
98 99 100 101
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
102
    return 55;
曹云霄's avatar
曹云霄 committed
103 104
}

曹云霄's avatar
曹云霄 committed
105 106
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
107 108 109 110
   [self resetCellselectedState];
    SelectedTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.titleLabe.backgroundColor = [UIColor whiteColor];
    cell.titleLabe.textColor = kMainBlueColor;
曹云霄's avatar
曹云霄 committed
111 112 113 114 115
    if ([self.delegate respondsToSelector:@selector(tableSelectedindex:)]) {
        
        [self.delegate tableSelectedindex:indexPath.row];
    }
}
曹云霄's avatar
曹云霄 committed
116 117 118 119

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ScreeningFirstCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
120 121
    cell.indexpath = indexPath;
    cell.delegate = self;
122 123
    if (self.selectedIndex == 1) {
        
124
        [cell.titleLabe setTitle:[[[[self.datasArray objectAtIndex_opple:indexPath.section] children] objectAtIndex_opple:indexPath.row] name] forState:UIControlStateNormal];
125 126 127
    }
    else
    {
128
        [cell.titleLabe setTitle:[[self.datasArray objectAtIndex_opple:indexPath.row] typeName] forState:UIControlStateNormal];
129
    }
曹云霄's avatar
曹云霄 committed
130 131 132 133 134
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
135 136 137 138 139
    if (self.selectedIndex == 1) {
        
        return [[[self.datasArray objectAtIndex_opple:section] children] count];
        
    }
曹云霄's avatar
曹云霄 committed
140 141 142
    return self.datasArray.count;
}

143 144 145 146 147 148 149
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    if (self.selectedIndex == 1) {
       return self.datasArray.count;
    }
    return 1;
}
曹云霄's avatar
曹云霄 committed
150 151 152 153


- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
154
    
155
    ScreeningSecondCollectionReusableView *cell = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"screeningcell" forIndexPath:indexPath];
156
    [cell.alltitleButton addTarget:self action:@selector(AllButtonClick:) forControlEvents:UIControlEventTouchUpInside];
157
    cell.clipsToBounds = YES;
158
    if (self.selectedIndex == 1) {
159

160 161
        NSString *subTitle = [[self.datasArray objectAtIndex_opple:indexPath.section] name];
        [cell.subTitleButton setTitle:subTitle forState:UIControlStateNormal];
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
        if (indexPath.section != 0) {
            [cell.alltitleButton setTitle:subTitle forState:UIControlStateNormal];
            cell.alltitleButton.layer.masksToBounds = NO;
            cell.alltitleButton.layer.borderWidth = 0;
            cell.alltitleButton.enabled = NO;
        }else
        {
            [cell.alltitleButton setTitle:@"全部" forState:UIControlStateNormal];
            cell.alltitleButton.layer.masksToBounds = YES;
            cell.alltitleButton.layer.borderWidth = 1;
            cell.alltitleButton.enabled = YES;
        }
    }else
    {
        [cell.alltitleButton setTitle:@"全部" forState:UIControlStateNormal];
        cell.alltitleButton.layer.masksToBounds = YES;
        cell.alltitleButton.layer.borderWidth = 1;
        cell.alltitleButton.enabled = YES;
180
    }
曹云霄's avatar
曹云霄 committed
181 182 183 184 185 186
    return cell;
}


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

187
    if (self.selectedIndex == 1 && section == 0) {
188

189 190
        return CGSizeMake(self.screeningCollectionView.frame.size.width, 130);
    }
曹云霄's avatar
曹云霄 committed
191
    return CGSizeMake(self.screeningCollectionView.frame.size.width, 75);
曹云霄's avatar
曹云霄 committed
192 193 194
}


195

196 197


198 199
#pragma mark -选中回调
- (void)SelectedButtonClickAction:(NSIndexPath *)indexpath
200 201
{
    //选中后的tableview赋值,并传递typecode筛选商品
202
    SelectedTableViewCell *cell = [self.screeningTableview cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIndex inSection:0]];
203 204 205 206
    //选中类型的文本
    NSString *selectedTitle = nil;
    //选中的key
    NSString *selectedTypecode = nil;
207
    
勾芒's avatar
勾芒 committed
208 209 210 211
    //选中状态
//    ScreeningFirstCollectionViewCell *newCell = (ScreeningFirstCollectionViewCell *)[self.screeningCollectionView cellForItemAtIndexPath:indexpath];
//    newCell.titleLabe.selected = YES;
//    newCell.titleLabe.backgroundColor = kMainBlueColor;
212
    
213 214
    if (self.selectedIndex == 1) {
        
215 216
        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];
217 218 219
    }
    else
    {
220
        selectedTitle = [[self.datasArray objectAtIndex_opple:indexpath.row] typeName];
221
        selectedTypecode = [[self.datasArray objectAtIndex_opple:indexpath.row] typecode];
222 223 224
    }
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:selectedTitle,@"typename",selectedTypecode,@"typecode", nil];
    [self.defaultDatasArray replaceObjectAtIndex:self.selectedIndex withObject:dict];
225
    cell.titleLabe.text = selectedTitle;
226 227
    [self JudgeDelegateIsPerformWithPassParamater];
}
曹云霄's avatar
曹云霄 committed
228 229


230 231 232 233




234 235 236
#pragma mark -区头的全部按钮点击
- (void)AllButtonClick:(UIButton *)button
{
237 238 239

    SelectedTableViewCell *cell = (SelectedTableViewCell *)[self.screeningTableview cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIndex inSection:0]];
    cell.titleLabe.text = @"全部";
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
    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
257

曹云霄's avatar
曹云霄 committed
258 259
#pragma mark -筛选结果点击
- (IBAction)ScreeningResultButtonClick:(UIButton *)sender {
曹云霄's avatar
曹云霄 committed
260
    
261 262 263 264
    if ([self.delegate respondsToSelector:@selector(ShowScreeningResponse)]) {
        
        [self.delegate ShowScreeningResponse];
    }
曹云霄's avatar
曹云霄 committed
265 266
}

曹云霄's avatar
曹云霄 committed
267 268


269 270 271 272 273 274 275
#pragma mark -传入满足搜索条件的个数
- (void)setTotalNumber:(NSInteger)totalNumber
{
    _totalNumber = totalNumber;
    [self.screeningResultButton setTitle:[NSString stringWithFormat:@"筛选结果共%ld件商品",totalNumber] forState:UIControlStateNormal];
     
}
曹云霄's avatar
曹云霄 committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295



















@end