BoltMaskView.m 9.76 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9 10
//
//  BoltMaskView.m
//  XFFurit
//
//  Created by 陈俊俊 on 15/8/1.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "BoltMaskView.h"
#import "MaskCell.h"
陈俊俊's avatar
陈俊俊 committed
11
#define TableHeight 45
陈俊俊's avatar
陈俊俊 committed
12
#define LeftMargin 80
陈俊俊's avatar
陈俊俊 committed
13
#define TotalHeight 224
陈俊俊's avatar
陈俊俊 committed
14
#define LeftHeight 44
n22's avatar
n22 committed
15 16
#define BottomHeight 50

陈俊俊's avatar
陈俊俊 committed
17
@interface BoltMaskView ()<UITextFieldDelegate>
陈俊俊's avatar
陈俊俊 committed
18 19 20
{
    UIView *_leftView;
    UIButton *_currentBtn;
n22's avatar
n22 committed
21
    NSIndexPath *_currentIndexPath;
陈俊俊's avatar
陈俊俊 committed
22 23 24 25 26
    UIView *_titleView;
    UIView *_billNumberView;
    NSString *_state;
    NSString *_billNumber;
    NSString *_title;
n22's avatar
n22 committed
27
    UIButton *_clearBtn;
陈俊俊's avatar
陈俊俊 committed
28
}
陈俊俊's avatar
陈俊俊 committed
29 30 31 32 33
@property (nonatomic,strong)NSString *state;
@property (nonatomic,strong)NSString *title;
@property (nonatomic,strong)NSString *billNumber;


陈俊俊's avatar
陈俊俊 committed
34 35 36
@end

@implementation BoltMaskView
陈俊俊's avatar
陈俊俊 committed
37
- (instancetype)initWithFrame:(CGRect)frame state:(NSString *)state title:(NSString *)title bill:(NSString *)bill{
陈俊俊's avatar
陈俊俊 committed
38 39
    self = [super initWithFrame:frame];
    if (self) {
陈俊俊's avatar
陈俊俊 committed
40 41 42
        self.title = title;
        self.billNumber = bill;
        self.state = state;
陈俊俊's avatar
陈俊俊 committed
43
        [self createView];
陈俊俊's avatar
陈俊俊 committed
44 45
        [self createRightView];
        [self preferData];
陈俊俊's avatar
陈俊俊 committed
46 47 48
    }
    return self;
}
陈俊俊's avatar
陈俊俊 committed
49 50 51 52 53 54 55 56 57 58 59 60 61
- (void)preferData{
    //initial(未提交),submitted(已提交),insurvey(调研中)
    if ([self.state isEqualToString:@"none"]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    }else if ([self.state isEqualToString:@"initial"]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:1 inSection:0];
    }else if ([self.state isEqualToString:@"submitted"]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:2 inSection:0];
    }else if ([self.state isEqualToString:@"insurvey"]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:3 inSection:0];
    }
    _titleView.hidden = YES;
    if(self.title.length > 0){
n22's avatar
n22 committed
62
        self.titleFiled.text = self.title;
陈俊俊's avatar
陈俊俊 committed
63 64 65
    }
    _billNumberView.hidden = YES;
    if (self.billNumber.length > 0) {
n22's avatar
n22 committed
66
        self.billFiled.text = self.billNumber;
陈俊俊's avatar
陈俊俊 committed
67 68
    }
}
陈俊俊's avatar
陈俊俊 committed
69 70 71 72

#pragma mark - 创建视图
- (void)createView
{
n22's avatar
n22 committed
73
    _leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, LeftMargin,self.frame.size.height- BottomHeight)];
陈俊俊's avatar
陈俊俊 committed
74
    [self addSubview:_leftView];
n22's avatar
n22 committed
75
    NSArray *arr = @[@"按状态",@"单号",@"标题"];
陈俊俊's avatar
陈俊俊 committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    for (NSInteger i = 0; i<arr.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(0, LeftHeight * i ,  LeftMargin ,LeftHeight);
        [button setTitle:arr[i] forState:UIControlStateNormal];
        [button setTitleColor:HexColor(@"888888") forState:UIControlStateNormal];
        if (i == 0) {
            button.enabled = NO;
            _currentBtn = button;
        }
        [button setBackgroundImage:[UIImage imageNamed:@"maskEnable"] forState:UIControlStateDisabled];
        [button setBackgroundImage:[UIImage imageNamed:@"mask"] forState:UIControlStateNormal];
        button.tag = 1001+i;
        [button addTarget:self action:@selector(leftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_leftView addSubview:button];
    }
n22's avatar
n22 committed
91 92 93 94 95 96 97
    _clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _clearBtn.frame = CGRectMake(0, CGRectGetMaxY(_leftView.frame), self.frame.size.width, BottomHeight);
    [_clearBtn setTitle:@"清空选项" forState:UIControlStateNormal];
    [_clearBtn setTitleColor:HexColor(@"444444") forState:UIControlStateNormal];
    _clearBtn.titleLabel.font = FontSize(15);
    [_clearBtn addTarget:self action:@selector(clearBolt) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_clearBtn];
陈俊俊's avatar
陈俊俊 committed
98 99 100
}
- (void)createRightView{
    
n22's avatar
n22 committed
101
    _titleView = [[UIView alloc]initWithFrame:CGRectMake(LeftMargin, 0, ScreenSize.width - LeftMargin, self.frame.size.height - BottomHeight)];
陈俊俊's avatar
陈俊俊 committed
102 103 104 105
    _titleView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_titleView];
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, (ScreenSize.width - LeftMargin - 10*2), 20)];
    titleLabel.font = FontSize(15);
n22's avatar
n22 committed
106
    titleLabel.text = @"类似于:";
陈俊俊's avatar
陈俊俊 committed
107
    [_titleView addSubview:titleLabel];
n22's avatar
n22 committed
108 109 110
    self.titleFiled = [[UITextField alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(titleLabel.frame) + 10, (ScreenSize.width - LeftMargin - 10*2), 30)];
    self.titleFiled.textAlignment = NSTextAlignmentLeft;
    self.titleFiled.textColor = HexColor(@"444444");
n22's avatar
n22 committed
111
    self.titleFiled.placeholder = @"输入类似标题";
n22's avatar
n22 committed
112 113 114 115 116
    self.titleFiled.borderStyle = UITextBorderStyleRoundedRect;
    self.titleFiled.font = FontSize(15);
    self.titleFiled.returnKeyType = UIReturnKeyDone;
    self.titleFiled.delegate = self;
    [_titleView addSubview:self.titleFiled];
陈俊俊's avatar
陈俊俊 committed
117 118
    
    
n22's avatar
n22 committed
119
    _billNumberView = [[UIView alloc]initWithFrame:CGRectMake(LeftMargin, 0, ScreenSize.width - LeftMargin, self.frame.size.height - BottomHeight)];
陈俊俊's avatar
陈俊俊 committed
120 121 122 123
    _billNumberView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_billNumberView];
    UILabel *billLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, (ScreenSize.width - LeftMargin - 10*2), 20)];
    billLabel.font = FontSize(15);
n22's avatar
n22 committed
124
    billLabel.text = @"类似于:";
陈俊俊's avatar
陈俊俊 committed
125 126
    [_billNumberView addSubview:billLabel];
    
n22's avatar
n22 committed
127 128 129
    self.billFiled = [[UITextField alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(billLabel.frame) + 10, (ScreenSize.width - LeftMargin - 10*2), 30)];
    self.billFiled.textAlignment = NSTextAlignmentLeft;
    self.billFiled.textColor = HexColor(@"444444");
n22's avatar
n22 committed
130
    self.billFiled.placeholder = @"输入类似单号";
n22's avatar
n22 committed
131 132 133 134 135
    self.billFiled.borderStyle = UITextBorderStyleRoundedRect;
    self.billFiled.font = FontSize(15);
    self.billFiled.returnKeyType = UIReturnKeyDone;
    self.billFiled.delegate = self;
    [_billNumberView addSubview:self.billFiled];
陈俊俊's avatar
陈俊俊 committed
136
    
n22's avatar
n22 committed
137
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(LeftMargin, 0, ScreenSize.width - LeftMargin, self.frame.size.height - BottomHeight) style:(UITableViewStylePlain)];
陈俊俊's avatar
陈俊俊 committed
138 139 140 141
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self addSubview:self.tableView];
n22's avatar
n22 committed
142
   
陈俊俊's avatar
陈俊俊 committed
143 144
}

陈俊俊's avatar
陈俊俊 committed
145

陈俊俊's avatar
陈俊俊 committed
146 147 148 149
- (void)leftBtnClick:(UIButton *)btn{
    _currentBtn.enabled = YES;
    btn.enabled = NO;
    _currentBtn = btn;
陈俊俊's avatar
陈俊俊 committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    [self keyBoardHidden];
    switch (btn.tag) {
        case 1001://状态
        {
            self.tableView.hidden = NO;
            _titleView.hidden = YES;
            _billNumberView.hidden = YES;
        }
            break;
        case 1002://条件二
        {
            self.tableView.hidden = YES;
            _titleView.hidden = YES;
            _billNumberView.hidden = NO;
        }
            break;
        case 1003://条件三
        {
            self.tableView.hidden = YES;
            _titleView.hidden = NO;
            _billNumberView.hidden = YES;
        }
            break;
        default:
            break;
    }
陈俊俊's avatar
陈俊俊 committed
176
}
n22's avatar
n22 committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

- (void)clearBolt{
    if (_titleFiled.text.length > 0) {
        _titleFiled.text = @"";
    }
    if (_billFiled.text.length > 0) {
        _billFiled.text = @"";
    }
    if (_currentIndexPath) {
        _currentIndexPath = nil;
        [self.tableView reloadData];
    }
    if ([self.delegate respondsToSelector:@selector(clearBoltInformation)]) {
        [self.delegate clearBoltInformation];
    }
}

陈俊俊's avatar
陈俊俊 committed
194 195 196 197 198 199 200 201 202 203 204
#pragma mark - 协议
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"MaskID";
    MaskCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
n22's avatar
n22 committed
205
        cell = [[MaskCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID totalWidth: ScreenSize.width - 80 totalHeight:TableHeight];
陈俊俊's avatar
陈俊俊 committed
206 207 208 209 210 211 212 213
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (_dataArr.count > 0) {
        cell.Commitbtn.hidden = YES;
        [cell setTitleStr:self.dataArr[indexPath.row]];
        
    }
n22's avatar
n22 committed
214 215 216 217 218 219 220
    if (_currentIndexPath) {
        if (indexPath.row == _currentIndexPath.row) {
            cell.Commitbtn.hidden = NO;
        }else{
            cell.Commitbtn.hidden = YES;
        }
    }
陈俊俊's avatar
陈俊俊 committed
221 222 223 224 225
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //获取选中的cell
n22's avatar
n22 committed
226 227
    MaskCell *currentCell = (MaskCell *)[tableView cellForRowAtIndexPath:_currentIndexPath];
    currentCell.Commitbtn.hidden = YES;
陈俊俊's avatar
陈俊俊 committed
228 229
    MaskCell *cell = (MaskCell *)[tableView cellForRowAtIndexPath:indexPath];
    cell.Commitbtn.hidden = NO;
n22's avatar
n22 committed
230 231
    _currentIndexPath = indexPath;
    
陈俊俊's avatar
陈俊俊 committed
232 233 234 235 236 237 238 239 240 241 242 243 244
    //initial(未提交),submitted(已提交),insurvey(调研中)

    NSString *stateStr = @"";
    if (indexPath.row == 0) {
        stateStr = @"none";
    }else if(indexPath.row == 1){
        stateStr = @"initial";
    }else if(indexPath.row == 2){
        stateStr = @"submitted";
    }else if(indexPath.row == 3){
        stateStr = @"insurvey";
    }
    [self.delegate getBoltValueSelectRow:stateStr];
陈俊俊's avatar
陈俊俊 committed
245 246 247 248 249 250
}

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

陈俊俊's avatar
陈俊俊 committed
251 252 253 254 255 256 257 258
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self keyBoardHidden];
    return YES;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [self keyBoardHidden];
}
- (void)keyBoardHidden{
n22's avatar
n22 committed
259 260
    [self.titleFiled resignFirstResponder];
    [self.billFiled resignFirstResponder];
陈俊俊's avatar
陈俊俊 committed
261 262 263
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
n22's avatar
n22 committed
264 265 266 267 268 269 270 271
    if (textField == self.titleFiled) {
        if (self.titleFiled.text.length > 0) {
            [self.delegate getTitleLike:self.titleFiled.text];
        }
    }else if(textField == self.billFiled){
        if (self.billFiled.text.length > 0) {
            [self.delegate getBillNumber:self.billFiled.text];
        }
陈俊俊's avatar
陈俊俊 committed
272 273 274
    }
}

n22's avatar
n22 committed
275

陈俊俊's avatar
陈俊俊 committed
276
@end