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

#import "PurchaseBoltView.h"
#import "MaskCell.h"
#define TableHeight 45
#define LeftMargin 80
#define TotalHeight 224
#define LeftHeight 44
#define BottomHeight 50
@interface PurchaseBoltView ()<UITextFieldDelegate>
{
    UIView *_leftView;
    UIButton *_currentBtn;
    NSIndexPath *_currentIndexPath;
    UIButton *_clearBtn;
}
@property (nonatomic,strong)NSString *state;
24 25 26
@property (nonatomic,strong)NSString *titleStr;
@property (nonatomic,strong)NSString *vendorNumber;

n22's avatar
n22 committed
27
@property (nonatomic,strong)NSString *billNumber;
28 29
@property (nonatomic,strong)NSString *productNumber;

n22's avatar
n22 committed
30 31 32 33 34

@end

@implementation PurchaseBoltView

35
- (instancetype)initWithFrame:(CGRect)frame state:(NSString *)state billNumber:(NSString *)billNumber titleStr:(NSString *)titleStr vendorNumber:(NSString *)vendorNumber productNumber:(NSString *)productNumber{
n22's avatar
n22 committed
36 37 38
    self = [super initWithFrame:frame];
    if (self) {
        self.billNumber = billNumber;
39 40
        self.titleStr = titleStr;
        self.vendorNumber = vendorNumber;
n22's avatar
n22 committed
41
        self.state = state;
42
        self.productNumber = productNumber;
n22's avatar
n22 committed
43 44 45 46 47 48 49 50
        [self createView];
        [self createRightView];
        [self preferData];
    }
    return self;
}
- (void)preferData{
    //initial(未提交)submitted(已提交)rejected(已拒绝)approved(已审批)shipping(发运中)finished(已完成)
n22's avatar
n22 committed
51
    if ([self.state isEqualToString:PURCHASE_STATE_INITIAL]) {
n22's avatar
n22 committed
52
        _currentIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
n22's avatar
n22 committed
53
    }else if ([self.state isEqualToString:PURCHASE_STATE_SUBMITTED]) {
n22's avatar
n22 committed
54
        _currentIndexPath = [NSIndexPath indexPathForRow:1 inSection:0];
n22's avatar
n22 committed
55
    }else if ([self.state isEqualToString:PURCHASE_STATE_REJECTED]) {
n22's avatar
n22 committed
56
        _currentIndexPath = [NSIndexPath indexPathForRow:2 inSection:0];
n22's avatar
n22 committed
57
    }else if ([self.state isEqualToString:PURCHASE_STATE_SHIPPING]) {
58 59
        _currentIndexPath = [NSIndexPath indexPathForRow:3 inSection:0];
    }else if ([self.state isEqualToString:PURCHASE_STATE_ABORTED]) {
n22's avatar
n22 committed
60
        _currentIndexPath = [NSIndexPath indexPathForRow:4 inSection:0];
n22's avatar
n22 committed
61
    }else if ([self.state isEqualToString:PURCHASE_STATE_FINISHED]) {
n22's avatar
n22 committed
62
        _currentIndexPath = [NSIndexPath indexPathForRow:5 inSection:0];
63 64 65 66
    }else if ([self.state isEqualToString:PURCHASE_STATE_PROCESS]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:6 inSection:0];
    }else if ([self.state isEqualToString:PURCHASE_STATE_PROCESSFAIL]) {
        _currentIndexPath = [NSIndexPath indexPathForRow:7 inSection:0];
n22's avatar
n22 committed
67
    }
68
    self.billFiled.hidden = YES;
n22's avatar
n22 committed
69 70 71
    if(self.billNumber.length > 0){
        self.billFiled.text = self.billNumber;
    }
72 73 74 75 76 77 78
    self.titleFiled.hidden = YES;
    if (self.titleStr.length > 0) {
        self.titleFiled.text = self.titleStr;
    }
    self.vendorFiled.hidden = YES;
    if (self.vendorNumber.length > 0) {
        self.vendorFiled.text = self.vendorNumber;
n22's avatar
n22 committed
79
    }
80 81 82 83
    self.productFiled.hidden = YES;
    if (self.productNumber.length > 0) {
        self.productFiled.text = self.productNumber;
    }
n22's avatar
n22 committed
84 85 86 87 88 89 90
}

#pragma mark - 创建视图
- (void)createView
{
    _leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, LeftMargin,self.frame.size.height- BottomHeight)];
    [self addSubview:_leftView];
91
    NSArray *arr = @[@"按状态",@"采购单号",@"标题",@"供应商Uuid",@"商品"];
n22's avatar
n22 committed
92 93 94 95
    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];
陈俊俊's avatar
陈俊俊 committed
96
        [button setTitleColor:GXF_DETAIL_COLOR forState:UIControlStateNormal];
n22's avatar
n22 committed
97 98 99 100 101 102 103 104 105 106 107 108 109
        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];
陈俊俊's avatar
陈俊俊 committed
110 111
    [_clearBtn setTitleColor:GXF_CONTENT_COLOR forState:UIControlStateNormal];
    _clearBtn.titleLabel.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
112 113 114 115
    [_clearBtn addTarget:self action:@selector(clearBolt) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_clearBtn];
}
- (void)createRightView{
116
    NSArray *arr = @[@"输入类似采购单号",@"输入类似标题",@"输入类似供应商Uuid",@"输入类似商品"];
117 118 119 120 121 122 123
    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];
n22's avatar
n22 committed
124
    
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    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) {
            _billFiled = contentField;
        }else if(i == 1){
            _titleFiled = contentField;
        }else if(i == 2){
            _vendorFiled = contentField;
142 143
        }else if (i == 3){
            _productFiled = contentField;
144 145
        }
    }
n22's avatar
n22 committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    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;
164 165 166
            _billFiled.hidden = YES;
            _titleFiled.hidden = YES;
            _vendorFiled.hidden = YES;
167
            _productFiled.hidden = YES;
n22's avatar
n22 committed
168 169 170 171 172
        }
            break;
        case 1002://条件二
        {
            self.tableView.hidden = YES;
173 174 175
            _billFiled.hidden = NO;
            _titleFiled.hidden = YES;
            _vendorFiled.hidden = YES;
176
            _productFiled.hidden = YES;
n22's avatar
n22 committed
177 178 179 180 181
        }
            break;
        case 1003://条件三
        {
            self.tableView.hidden = YES;
182 183 184
            _billFiled.hidden = YES;
            _titleFiled.hidden = NO;
            _vendorFiled.hidden = YES;
185
            _productFiled.hidden = YES;
186 187 188 189 190 191 192 193
        }
            break;
        case 1004://条件四
        {
            self.tableView.hidden = YES;
            _billFiled.hidden = YES;
            _titleFiled.hidden = YES;
            _vendorFiled.hidden = NO;
194 195 196 197 198 199 200 201 202 203
            _productFiled.hidden = YES;
        }
            break;
        case 1005://条件五
        {
            self.tableView.hidden = YES;
            _billFiled.hidden = YES;
            _titleFiled.hidden = YES;
            _vendorFiled.hidden = YES;
            _productFiled.hidden = NO;
n22's avatar
n22 committed
204 205 206 207 208 209 210 211 212 213 214
        }
            break;
        default:
            break;
    }
}

- (void)clearBolt{
    if (_billFiled.text.length > 0) {
        _billFiled.text = @"";
    }
215 216 217 218 219
    if (_titleFiled.text.length > 0) {
        _titleFiled.text = @"";
    }
    if (_vendorFiled.text.length > 0) {
        _vendorFiled.text = @"";
n22's avatar
n22 committed
220
    }
221 222 223
    if (_productFiled.text.length > 0) {
        _productFiled.text = @"";
    }
n22's avatar
n22 committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
    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(已完成)
    
    NSString *stateStr = @"";
    if (indexPath.row == 0) {
n22's avatar
n22 committed
275
        stateStr = PURCHASE_STATE_INITIAL;
n22's avatar
n22 committed
276
    }else if(indexPath.row == 1){
n22's avatar
n22 committed
277
        stateStr = PURCHASE_STATE_SUBMITTED;
n22's avatar
n22 committed
278
    }else if(indexPath.row == 2){
n22's avatar
n22 committed
279
        stateStr = PURCHASE_STATE_REJECTED;
n22's avatar
n22 committed
280
    }else if(indexPath.row == 3){
n22's avatar
n22 committed
281
        stateStr = PURCHASE_STATE_SHIPPING;
282 283
    }else if(indexPath.row == 4){
        stateStr = PURCHASE_STATE_ABORTED;
n22's avatar
n22 committed
284
    }else if(indexPath.row == 5){
n22's avatar
n22 committed
285
        stateStr = PURCHASE_STATE_FINISHED;
286 287 288 289
    }else if(indexPath.row == 6){
        stateStr = PURCHASE_STATE_PROCESS;
    }else if(indexPath.row == 7){
        stateStr = PURCHASE_STATE_PROCESSFAIL;
n22's avatar
n22 committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
    }
    [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.billFiled resignFirstResponder];
307 308
    [self.titleFiled resignFirstResponder];
    [self.vendorFiled resignFirstResponder];
309
    [self.productFiled resignFirstResponder];
n22's avatar
n22 committed
310 311 312 313
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField == self.billFiled) {
陈俊俊's avatar
陈俊俊 committed
314
//        if (self.billFiled.text.length > 0) {
n22's avatar
n22 committed
315
            [self.delegate getbillLike:self.billFiled.text];
陈俊俊's avatar
陈俊俊 committed
316
//        }
317
    }else if(textField == self.titleFiled){
陈俊俊's avatar
陈俊俊 committed
318
//        if (self.titleFiled.text.length > 0) {
319
            [self.delegate gettitleLike:self.titleFiled.text];
陈俊俊's avatar
陈俊俊 committed
320
//        }
321
    }else if(textField == self.vendorFiled){
陈俊俊's avatar
陈俊俊 committed
322
//        if (self.vendorFiled.text.length > 0) {
323
            [self.delegate getvendorLike:self.vendorFiled.text];
陈俊俊's avatar
陈俊俊 committed
324
//        }
325 326 327 328
    }else if(textField == self.productFiled){
        //        if (self.vendorFiled.text.length > 0) {
        [self.delegate getproductLike:self.productFiled.text];
        //        }
n22's avatar
n22 committed
329 330 331 332 333
    }
}


@end