TransportBoltView.m 11.1 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
//
//  TransportBoltView.m
//  XFFruit
//
//  Created by 陈俊俊 on 15/9/7.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "TransportBoltView.h"

#import "MaskCell.h"
#define TableHeight 45
#define LeftMargin 80
#define TotalHeight 224
#define LeftHeight 44
#define BottomHeight 50
@interface TransportBoltView ()<UITextFieldDelegate>
{
    UIView *_leftView;
    UIButton *_currentBtn;
    NSIndexPath *_currentIndexPath;
    NSString *_state;
    NSString *_billNumber;
    NSString *_title;
    UIButton *_clearBtn;
}
@property (nonatomic,strong)NSString *state;
@property (nonatomic,strong)NSString *billNumber;
@property (nonatomic,strong)NSString *userNumber;
30
@property (nonatomic,strong)NSString *productNumber;
陈俊俊's avatar
陈俊俊 committed
31 32 33 34 35

@end

@implementation TransportBoltView

36
- (instancetype)initWithFrame:(CGRect)frame state:(NSString *)state userNumber:(NSString *)userNumber billNumber:(NSString *)billNumber productNumber:(NSString *)productNumber{
陈俊俊's avatar
陈俊俊 committed
37 38 39 40 41
    self = [super initWithFrame:frame];
    if (self) {
        self.userNumber = userNumber;
        self.billNumber = billNumber;
        self.state = state;
42
        self.productNumber = productNumber;
陈俊俊's avatar
陈俊俊 committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        [self createView];
        [self createRightView];
        [self preferData];
    }
    return self;
}
- (void)preferData{
    if ([self.state isEqualToString:TRANSPORT_STATE_INITIAL]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    }else if ([self.state isEqualToString:TRANSPORT_STATE_UNRECEIVED]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:1 inSection:0];
    }else if ([self.state isEqualToString:TRANSPORT_STATE_RECEIVED]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:2 inSection:0];
    }else if ([self.state isEqualToString:TRANSPORT_STATE_ABORTED]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:3 inSection:0];
58 59 60 61
    }else if ([self.state isEqualToString:TRANSPORT_STATE_PROCESS]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:4 inSection:0];
    }else if ([self.state isEqualToString:TRANSPORT_STATE_PROCESSFAIL]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:5 inSection:0];
陈俊俊's avatar
陈俊俊 committed
62
    }
63
    self.userFiled.hidden = YES;
陈俊俊's avatar
陈俊俊 committed
64 65 66
    if(self.userNumber.length > 0){
        self.userFiled.text = self.userNumber;
    }
67
    self.billFiled.hidden = YES;
陈俊俊's avatar
陈俊俊 committed
68 69 70
    if (self.billNumber.length > 0) {
        self.billFiled.text = self.billNumber;
    }
71 72 73 74
    self.productField.hidden = YES;
    if (self.productNumber.length > 0) {
        self.productField.text = self.productNumber;
    }
陈俊俊's avatar
陈俊俊 committed
75 76 77 78 79 80 81
}

#pragma mark - 创建视图
- (void)createView
{
    _leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, LeftMargin,self.frame.size.height- BottomHeight)];
    [self addSubview:_leftView];
82
    NSArray *arr = @[@"按状态",@"创建人代码",@"调研单号",@"商品"];
陈俊俊's avatar
陈俊俊 committed
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
    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:GXF_DETAIL_COLOR 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];
    }
    _clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _clearBtn.frame = CGRectMake(0, CGRectGetMaxY(_leftView.frame), self.frame.size.width, BottomHeight);
    [_clearBtn setTitle:@"清空选项" forState:UIControlStateNormal];
    [_clearBtn setTitleColor:GXF_CONTENT_COLOR forState:UIControlStateNormal];
    _clearBtn.titleLabel.font = GXF_FIFTEENTEN_SIZE;
    [_clearBtn addTarget:self action:@selector(clearBolt) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_clearBtn];
}
- (void)createRightView{
    
    
109
    NSArray *arr = @[@"输入类似创建人代码",@"输入类似调研单号",@"输入类似商品"];
110 111 112 113 114 115 116
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(LeftMargin, 0, ScreenSize.width - LeftMargin, self.frame.size.height - BottomHeight)];
    contentView.backgroundColor = [UIColor whiteColor];
    [self addSubview:contentView];
    UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, (ScreenSize.width - LeftMargin - 10*2), 20)];
    contentLabel.font = GXF_FIFTEENTEN_SIZE;
    contentLabel.text = @"类似于:";
    [contentView addSubview:contentLabel];
陈俊俊's avatar
陈俊俊 committed
117
    
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    for (NSInteger i = 0; i < arr.count; i ++) {
        UITextField *contentField = [[UITextField alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(contentLabel.frame) + 10, (ScreenSize.width - LeftMargin - 10*2), 30)];
        contentField.textAlignment = NSTextAlignmentLeft;
        contentField.textColor = GXF_CONTENT_COLOR;
        contentField.borderStyle = UITextBorderStyleRoundedRect;
        contentField.font = GXF_FIFTEENTEN_SIZE;
        contentField.placeholder = arr[i];
        
        contentField.returnKeyType = UIReturnKeyDone;
        contentField.delegate = self;
        [contentView addSubview:contentField];
        if (i == 0) {
            self.userFiled = contentField;
        }else if(i == 1){
            self.billFiled = contentField;
133 134
        }else if(i == 2){
            self.productField = contentField;
135 136 137
        }
    }

陈俊俊's avatar
陈俊俊 committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(LeftMargin, 0, ScreenSize.width - LeftMargin, self.frame.size.height - BottomHeight) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self addSubview:self.tableView];
    
}


- (void)leftBtnClick:(UIButton *)btn{
    _currentBtn.enabled = YES;
    btn.enabled = NO;
    _currentBtn = btn;
    [self keyBoardHidden];
    switch (btn.tag) {
        case 1001://状态
        {
            self.tableView.hidden = NO;
156 157
            self.userFiled.hidden = YES;
            self.billFiled.hidden = YES;
158
            self.productField.hidden = YES;
陈俊俊's avatar
陈俊俊 committed
159 160 161 162 163
        }
            break;
        case 1002://条件二
        {
            self.tableView.hidden = YES;
164 165
            self.userFiled.hidden = NO;
            self.billFiled.hidden = YES;
166
            self.productField.hidden = YES;
陈俊俊's avatar
陈俊俊 committed
167 168 169 170 171
        }
            break;
        case 1003://条件三
        {
            self.tableView.hidden = YES;
172 173
            self.userFiled.hidden = YES;
            self.billFiled.hidden = NO;
174 175 176 177 178 179 180 181 182
            self.productField.hidden = YES;
        }
            break;
        case 1004://条件四
        {
            self.tableView.hidden = YES;
            self.userFiled.hidden = YES;
            self.billFiled.hidden = YES;
            self.productField.hidden = NO;
陈俊俊's avatar
陈俊俊 committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196
        }
            break;
        default:
            break;
    }
}

- (void)clearBolt{
    if (_billFiled.text.length > 0) {
        _billFiled.text = @"";
    }
    if (_userFiled.text.length > 0) {
        _userFiled.text = @"";
    }
197 198 199
    if (_productField.text.length > 0) {
        _productField.text = @"";
    }
陈俊俊's avatar
陈俊俊 committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
    if (_currentIndexPath) {
        _currentIndexPath = nil;
        [self.tableView reloadData];
    }
    if ([self.delegate respondsToSelector:@selector(clearBoltInformation)]) {
        [self.delegate clearBoltInformation];
    }
}

#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) {
        cell = [[MaskCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID totalWidth: ScreenSize.width - 80 totalHeight:TableHeight];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (_dataArr.count > 0) {
        cell.Commitbtn.hidden = YES;
        [cell setTitleStr:self.dataArr[indexPath.row]];
        
    }
    if (_currentIndexPath) {
        if (indexPath.row == _currentIndexPath.row) {
            cell.Commitbtn.hidden = NO;
        }else{
            cell.Commitbtn.hidden = YES;
        }
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //获取选中的cell
    MaskCell *currentCell = (MaskCell *)[tableView cellForRowAtIndexPath:_currentIndexPath];
    currentCell.Commitbtn.hidden = YES;
    MaskCell *cell = (MaskCell *)[tableView cellForRowAtIndexPath:indexPath];
    cell.Commitbtn.hidden = NO;
    _currentIndexPath = indexPath;
    
    //initial(未提交)submitted(已提交)rejected(已拒绝)approved(已审批)shipping(发运中)finished(已完成)
Sandy's avatar
Sandy committed
248
    NSString *string = self.dataArr[indexPath.row];
陈俊俊's avatar
陈俊俊 committed
249
    NSString *stateStr = @"";
Sandy's avatar
Sandy committed
250 251
    
    if ([string isEqualToString:@"未提交"]) {
陈俊俊's avatar
陈俊俊 committed
252
        stateStr = TRANSPORT_STATE_INITIAL;
Sandy's avatar
Sandy committed
253 254
    }else if ([string isEqualToString:@"未审批"]){
    }else if ([string isEqualToString:@"提交系统处理"]){
255
        stateStr = TRANSPORT_STATE_PROCESS;
Sandy's avatar
Sandy committed
256
    }else if ([string isEqualToString:@"系统处理失败"]){
257
        stateStr = TRANSPORT_STATE_PROCESSFAIL;
Sandy's avatar
Sandy committed
258 259 260 261 262 263 264 265 266 267 268
    }else if ([string isEqualToString:@"已拒绝"]){
    }else if ([string isEqualToString:@"发运中"]){
    }else if ([string isEqualToString:@"已完成"]){
    }else if ([string isEqualToString:@"已作废"]){
        stateStr = TRANSPORT_STATE_ABORTED;
    }else if ([string isEqualToString:@"已收货"]){
        stateStr = TRANSPORT_STATE_RECEIVED;
    }else if ([string isEqualToString:@"待收货"]){
        stateStr = TRANSPORT_STATE_UNRECEIVED;
    }else if ([string isEqualToString:@"全部"]){
        stateStr = @"";
陈俊俊's avatar
陈俊俊 committed
269
    }
270
    
陈俊俊's avatar
陈俊俊 committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    [self.delegate getBoltValueSelectRow:stateStr];
}

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

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self keyBoardHidden];
    return YES;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [self keyBoardHidden];
}
- (void)keyBoardHidden{
    [self.userFiled resignFirstResponder];
    [self.billFiled resignFirstResponder];
288
    [self.productField resignFirstResponder];
陈俊俊's avatar
陈俊俊 committed
289 290 291 292
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField == self.userFiled) {
陈俊俊's avatar
陈俊俊 committed
293
//        if (self.userFiled.text.length > 0) {
陈俊俊's avatar
陈俊俊 committed
294
            [self.delegate getuserLike:self.userFiled.text];
陈俊俊's avatar
陈俊俊 committed
295
//        }
陈俊俊's avatar
陈俊俊 committed
296
    }else if(textField == self.billFiled){
陈俊俊's avatar
陈俊俊 committed
297
//        if (self.billFiled.text.length > 0) {
陈俊俊's avatar
陈俊俊 committed
298
            [self.delegate getbillLike:self.billFiled.text];
陈俊俊's avatar
陈俊俊 committed
299
//        }
300 301 302 303
    }else if(textField == self.productField){
        //        if (self.billFiled.text.length > 0) {
        [self.delegate getproductLike:self.productField.text];
        //        }
陈俊俊's avatar
陈俊俊 committed
304 305 306 307 308
    }
}


@end