TopTransportView.m 12.4 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
//
//  TopTransportView.m
//  XFFruit
//
//  Created by 陈俊俊 on 15/9/6.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "TopTransportView.h"
#import "SurveyCell.h"
#import "Warehouse.h"
#import "ChooseWarehouseViewController.h"
#import "ChooseTypeViewController.h"
#define LeftMargin 15
#define TopMargin 20
#define LeftWidth 80
#define TableHeight 44
#define SpaceHeight 10

陈俊俊's avatar
陈俊俊 committed
20
@interface TopTransportView ()<UITableViewDataSource,UITableViewDelegate,HPGrowingTextViewDelegate,UITextFieldDelegate,FinishTimeViewDelegate>
陈俊俊's avatar
陈俊俊 committed
21 22 23 24
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
}
陈俊俊's avatar
陈俊俊 committed
25 26 27
@property (nonatomic,strong)NSString *selectType;
@property (nonatomic,strong)NSString *selectRwarehouse;
@property (nonatomic,strong)NSString *selectWarehouse;
陈俊俊's avatar
陈俊俊 committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
@end


@implementation TopTransportView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //界面
        [self bulidLayout];
    }
    return self;
}

#pragma mark - 布局
- (void)bulidLayout
{
    self.backgroundColor  = XXFBgColor;
    _dataArr = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
46
    NSArray *arr = @[@"发货仓库:",@"收货仓库:",@"运输类型:",@"车辆:",@"司机电话:",@"预计到货时间:",@"备注:"];
陈俊俊's avatar
陈俊俊 committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    [_dataArr addObjectsFromArray:arr];
    
    _tableView = [[UITableView alloc]initWithFrame:(CGRectMake(0, TopMargin,self.frame.size.width, self.frame.size.height - TopMargin)) style:(UITableViewStylePlain)];
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.bounces = NO;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self addSubview:_tableView];
}
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"cellID";
    SurveyCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[SurveyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
陈俊俊's avatar
陈俊俊 committed
70
        if (indexPath.row ==0 || indexPath.row == 1 || indexPath.row == 2 || indexPath.row == 5) {
陈俊俊's avatar
陈俊俊 committed
71 72
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
陈俊俊's avatar
陈俊俊 committed
73
        
陈俊俊's avatar
陈俊俊 committed
74 75 76 77 78 79 80 81 82 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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
        [self createViewInCell:cell indexPath:indexPath];
    }
    [cell setTitleStr:_dataArr[indexPath.row]];
    return cell;
}
-  (void)createViewInCell:(SurveyCell *)cell indexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 3 || indexPath.row == 4) {
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-10, TableHeight)];
        textField.textAlignment = NSTextAlignmentRight;
        textField.textColor = GXF_CONTENT_COLOR;
        textField.font = GXF_FIFTEENTEN_SIZE;
        textField.returnKeyType = UIReturnKeyDone;
        textField.delegate = self;
        [cell.contentView addSubview:textField];
        if (indexPath.row == 3) {
            self.carTextFiled = textField;
            self.carTextFiled.placeholder = @"请输入车辆";
        }else if(indexPath.row == 4){
            textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
            textField.returnKeyType = UIReturnKeyDone;
            self.phoneTextFiled = textField;
            self.phoneTextFiled.placeholder = @"请输入司机电话";
        }
        
    }else if (indexPath.row == _dataArr.count -1){
        self.remarkTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-10, TableHeight)];
        self.remarkTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
        self.remarkTextView.minNumberOfLines = 1;
        self.remarkTextView.maxNumberOfLines = 1;
        self.remarkTextView.isScrollable = YES;
        self.remarkTextView.font = GXF_FIFTEENTEN_SIZE;
        self.remarkTextView.textAlignment = NSTextAlignmentRight;
        self.remarkTextView.delegate = self;
        self.remarkTextView.returnKeyType = UIReturnKeyDone;
        self.remarkTextView.placeholder = @"输入备注内容";
        [cell.contentView addSubview:self.remarkTextView];
    }else{
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-10, TableHeight))];
        contentLabel.textAlignment= NSTextAlignmentRight;
        contentLabel.textColor = GXF_PLACEHOLDER_COLOR;
        contentLabel.font = GXF_FIFTEENTEN_SIZE;
        [cell.contentView addSubview:contentLabel];
        if (indexPath.row == 0) {
            contentLabel.text = @"选择发货仓库";
            self.warehouseLabel = contentLabel;
            
        }else if(indexPath.row == 1){
            contentLabel.text = @"选择收货仓库";
            self.rwarehouseLabel = contentLabel;
            
        }else if(indexPath.row == 2){
            contentLabel.text = @"选择类型";
            self.typeLabel = contentLabel;
127 128 129
            self.typeLabel.text = @"普通";
            self.typeLabel.textColor = GXF_CONTENT_COLOR;
            self.type = GXF_Normal;
陈俊俊's avatar
陈俊俊 committed
130
            
陈俊俊's avatar
陈俊俊 committed
131 132 133
        }else if(indexPath.row == 5){
            contentLabel.text = @"选择预计到货时间";
            self.arriveDateLabel = contentLabel;
陈俊俊's avatar
陈俊俊 committed
134 135 136
        }
    }
}
陈俊俊's avatar
陈俊俊 committed
137 138 139 140 141 142 143 144
- (void)setTransport:(Transport *)transport{
    if (transport) {
        if (transport.warehouseName.length > 0) {
            self.warehouseLabel.text = transport.warehouseName;
            self.warehouseLabel.textColor = GXF_CONTENT_COLOR;
            self.warehouseCode = transport.warehouseCode;
            self.warehouseName = transport.warehouseName;
            self.warehouseUuid = transport.warehouseUuid;
陈俊俊's avatar
陈俊俊 committed
145
            self.selectWarehouse = transport.warehouseUuid;
陈俊俊's avatar
陈俊俊 committed
146 147 148 149 150 151
        }
        if (transport.type.length > 0) {
            NSString *type = [transport.type isEqualToString:GXF_Critical] ? @"紧急" : @"普通";
            self.typeLabel.text = type;
            self.typeLabel.textColor = GXF_CONTENT_COLOR;
            self.type = transport.type;
陈俊俊's avatar
陈俊俊 committed
152
            self.selectType = transport.type;
陈俊俊's avatar
陈俊俊 committed
153 154 155 156 157 158 159
        }
        if (transport.rwarehouseName.length > 0) {
            self.rwarehouseLabel.text = transport.rwarehouseName;
            self.rwarehouseLabel.textColor = GXF_CONTENT_COLOR;
            self.rwarehouseCode = transport.rwarehouseCode;
            self.rwarehouseName = transport.rwarehouseName;
            self.rwarehouseUuid = transport.rwarehouseUuid;
陈俊俊's avatar
陈俊俊 committed
160
            self.selectRwarehouse = transport.rwarehouseUuid;
陈俊俊's avatar
陈俊俊 committed
161 162 163 164 165 166 167 168 169
        }
        if (transport.carnumber.length > 0) {
            self.carTextFiled.text = transport.carnumber;
            self.carnumber = transport.carnumber;
        }
        if (transport.carphone) {
            self.phoneTextFiled.text = transport.carphone;
            self.carphone = transport.carphone;
        }
陈俊俊's avatar
陈俊俊 committed
170
        if (transport.arriveDate) {
陈俊俊's avatar
陈俊俊 committed
171 172
            if (transport.arriveDate.length > 15) {
                _arriveDateLabel.text = [[IBTCommon checkString:transport.arriveDate]substringToIndex:16];
陈俊俊's avatar
陈俊俊 committed
173 174 175 176 177
            }
            _arriveDateLabel.textColor = GXF_CONTENT_COLOR;
            self.arriveDate = [IBTCommon checkString:transport.arriveDate];
        }

陈俊俊's avatar
陈俊俊 committed
178 179 180 181 182 183 184
        if (transport.note) {
            self.remarkTextView.text = transport.note;
            self.note = transport.note;
        }
    }
}

陈俊俊's avatar
陈俊俊 committed
185 186 187
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        ChooseWarehouseViewController *cvc = [ChooseWarehouseViewController new];
陈俊俊's avatar
陈俊俊 committed
188 189 190
        if (self.selectWarehouse.length > 0) {
            cvc.selectStr = self.selectWarehouse;
        }
Sandy's avatar
Sandy committed
191
        cvc.warehouseType = WareHouseTypeCenter;
陈俊俊's avatar
陈俊俊 committed
192 193 194 195 196 197 198 199
        cvc.choseBaseInfo = ^(NSArray *warehouses){
            if (warehouses.count > 0) {
                Warehouse *warehouse = warehouses[0];
                self.warehouseLabel.text = [NSString stringWithFormat:@"%@[%@]",warehouse.name,warehouse.code];
                self.warehouseLabel.textColor = GXF_CONTENT_COLOR;
                self.warehouseUuid = warehouse.uuid;
                self.warehouseCode = warehouse.code;
                self.warehouseName = warehouse.name;
陈俊俊's avatar
陈俊俊 committed
200
                self.selectWarehouse = warehouse.uuid;
陈俊俊's avatar
陈俊俊 committed
201 202 203 204 205 206 207
            }
            
        };
        cvc.isMoreChose = NO;
        [self.delegate pushNextViewController:cvc];
    }else if(indexPath.row == 1){
        ChooseWarehouseViewController *tvc = [[ChooseWarehouseViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
208 209 210
        if (self.selectRwarehouse.length > 0) {
            tvc.selectStr = self.selectRwarehouse;
        }
Sandy's avatar
Sandy committed
211 212
        tvc.warehouseType = WareHouseTypeNotCenter;

陈俊俊's avatar
陈俊俊 committed
213 214 215 216 217 218 219 220
        tvc.choseBaseInfo = ^(NSArray *warehouses){
            if (warehouses.count > 0) {
                Warehouse *warehouse = warehouses[0];
                self.rwarehouseLabel.text = [NSString stringWithFormat:@"%@[%@]",warehouse.name,warehouse.code];
                self.rwarehouseLabel.textColor = GXF_CONTENT_COLOR;
                self.rwarehouseUuid = warehouse.uuid;
                self.rwarehouseCode = warehouse.code;
                self.rwarehouseName = warehouse.name;
陈俊俊's avatar
陈俊俊 committed
221 222
                self.selectRwarehouse = warehouse.uuid;

陈俊俊's avatar
陈俊俊 committed
223 224 225 226 227 228
            }
            
        };
        [self.delegate pushNextViewController:tvc];
    }else if(indexPath.row == 2){
        ChooseTypeViewController *tvc = [[ChooseTypeViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
229 230 231
        if (self.selectType.length > 0) {
            tvc.selectStr = self.selectType;
        }
陈俊俊's avatar
陈俊俊 committed
232 233 234
        tvc.choseBaseInfo = ^(NSArray *types){
            if (types.count > 0) {
                NSString *type = types[0];
陈俊俊's avatar
陈俊俊 committed
235
                self.typeLabel.text = type;
陈俊俊's avatar
陈俊俊 committed
236
                self.selectType = type;
陈俊俊's avatar
陈俊俊 committed
237
                self.typeLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
238 239 240 241 242
                if ([type isEqualToString:@"紧急"]) {
                    self.type = GXF_Critical;
                }else{
                    self.type = GXF_Normal;
                }
陈俊俊's avatar
陈俊俊 committed
243 244 245 246
            }
            
        };
        [self.delegate pushNextViewController:tvc];
陈俊俊's avatar
陈俊俊 committed
247 248
    }else if(indexPath.row == 5){
        [self startDatePickView];
陈俊俊's avatar
陈俊俊 committed
249 250 251
    }

}
陈俊俊's avatar
陈俊俊 committed
252
- (void)startDatePickView{
陈俊俊's avatar
陈俊俊 committed
253 254 255
    if (!self.startTimeView) {
        NSString *currentStr  = @"";
        if ([self.arriveDateLabel.text isEqualToString:@"选择预计到货时间"] || self.arriveDateLabel.text.length < 1) {
陈俊俊's avatar
陈俊俊 committed
256
            currentStr = [IBTCommon stringFromDateWithFormat:[NSDate date] format:@"yyyy-MM-dd HH:mm:ss"];
陈俊俊's avatar
陈俊俊 committed
257 258 259 260 261 262 263
        }else{
            currentStr = self.arriveDateLabel.text;
        }
        self.startTimeView = [[FinishTimeView alloc] initWithFrame:CGRectMake(0, ScreenSize.height, ScreenSize.width, ScreenSize.height - 64) withDate:currentStr];
        self.startTimeView.delegate = self;
        self.startTimeView.backgroundColor        = RGBA(0, 0, 0 ,0.5);
        [AppWindow addSubview:self.startTimeView];
陈俊俊's avatar
陈俊俊 committed
264 265
        
        [UIView animateWithDuration:0.15 animations:^{
陈俊俊's avatar
陈俊俊 committed
266
            CGRect startFrame =  self.startTimeView.frame;
陈俊俊's avatar
陈俊俊 committed
267
            startFrame.origin.y =  64;
陈俊俊's avatar
陈俊俊 committed
268
            self.startTimeView.frame = startFrame;
陈俊俊's avatar
陈俊俊 committed
269 270 271 272 273 274 275 276
        } completion:^(BOOL finished) {
            
        }];
    }
}
- (void)cancelTimeView{
    [self clearDatePickView];
}
陈俊俊's avatar
陈俊俊 committed
277
- (void)okTimeView:(NSString *)time withType:(NSString *)type{
陈俊俊's avatar
陈俊俊 committed
278 279
    
    _arriveDateLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
280 281 282
    if (time.length > 15) {
        _arriveDateLabel.text = [time substringToIndex:16];
    }
陈俊俊's avatar
陈俊俊 committed
283
    self.arriveDate = time;
陈俊俊's avatar
陈俊俊 committed
284 285 286 287 288 289
    // 关闭选择器
    [self clearDatePickView];
}
#pragma mark - 取消
- (void)clearDatePickView{
    [UIView animateWithDuration:0.15 animations:^{
陈俊俊's avatar
陈俊俊 committed
290
        CGRect startFrame =  self.startTimeView.frame;
陈俊俊's avatar
陈俊俊 committed
291
        startFrame.origin.y = ScreenSize.height;
陈俊俊's avatar
陈俊俊 committed
292
        self.startTimeView.frame = startFrame;
陈俊俊's avatar
陈俊俊 committed
293
    } completion:^(BOOL finished) {
陈俊俊's avatar
陈俊俊 committed
294 295
        [self.startTimeView removeFromSuperview];
        self.startTimeView = nil;
陈俊俊's avatar
陈俊俊 committed
296 297
    }];
}
陈俊俊's avatar
陈俊俊 committed
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316

- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
    [self.remarkTextView resignFirstResponder];
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.delegate hiddenKeyBoard];
    return YES;
}

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

@end