TopTransportView.m 9.78 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
//
//  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

@interface TopTransportView ()<UITableViewDataSource,UITableViewDelegate,HPGrowingTextViewDelegate,UITextFieldDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
}
陈俊俊's avatar
陈俊俊 committed
26 27 28
@property (nonatomic,strong)NSString *selectType;
@property (nonatomic,strong)NSString *selectRwarehouse;
@property (nonatomic,strong)NSString *selectWarehouse;
陈俊俊's avatar
陈俊俊 committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 127 128 129 130
@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];
    NSArray *arr = @[@"发货仓库:",@"收货仓库:",@"运输类型:",@"车辆:",@"司机电话:",@"备注:"];
    [_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;
        if (indexPath.row ==0 || indexPath.row == 1 || indexPath.row == 2) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        [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;
            
        }
    }
}
陈俊俊's avatar
陈俊俊 committed
131 132 133 134 135 136 137 138
- (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
139
            self.selectWarehouse = transport.warehouseUuid;
陈俊俊's avatar
陈俊俊 committed
140 141 142 143 144 145
        }
        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
146
            self.selectType = transport.type;
陈俊俊's avatar
陈俊俊 committed
147 148 149 150 151 152 153
        }
        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
154
            self.selectRwarehouse = transport.rwarehouseUuid;
陈俊俊's avatar
陈俊俊 committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
        }
        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;
        }
        if (transport.note) {
            self.remarkTextView.text = transport.note;
            self.note = transport.note;
        }
    }
}

陈俊俊's avatar
陈俊俊 committed
171 172 173
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        ChooseWarehouseViewController *cvc = [ChooseWarehouseViewController new];
陈俊俊's avatar
陈俊俊 committed
174 175 176
        if (self.selectWarehouse.length > 0) {
            cvc.selectStr = self.selectWarehouse;
        }
陈俊俊's avatar
陈俊俊 committed
177 178 179 180 181 182 183 184
        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
185
                self.selectWarehouse = warehouse.uuid;
陈俊俊's avatar
陈俊俊 committed
186 187 188 189 190 191 192
            }
            
        };
        cvc.isMoreChose = NO;
        [self.delegate pushNextViewController:cvc];
    }else if(indexPath.row == 1){
        ChooseWarehouseViewController *tvc = [[ChooseWarehouseViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
193 194 195
        if (self.selectRwarehouse.length > 0) {
            tvc.selectStr = self.selectRwarehouse;
        }
陈俊俊's avatar
陈俊俊 committed
196 197 198 199 200 201 202 203
        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
204 205
                self.selectRwarehouse = warehouse.uuid;

陈俊俊's avatar
陈俊俊 committed
206 207 208 209 210 211
            }
            
        };
        [self.delegate pushNextViewController:tvc];
    }else if(indexPath.row == 2){
        ChooseTypeViewController *tvc = [[ChooseTypeViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
212 213 214
        if (self.selectType.length > 0) {
            tvc.selectStr = self.selectType;
        }
陈俊俊's avatar
陈俊俊 committed
215 216 217
        tvc.choseBaseInfo = ^(NSArray *types){
            if (types.count > 0) {
                NSString *type = types[0];
陈俊俊's avatar
陈俊俊 committed
218
                self.typeLabel.text = type;
陈俊俊's avatar
陈俊俊 committed
219
                self.selectType = type;
陈俊俊's avatar
陈俊俊 committed
220
                self.typeLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
221 222 223 224 225
                if ([type isEqualToString:@"紧急"]) {
                    self.type = GXF_Critical;
                }else{
                    self.type = GXF_Normal;
                }
陈俊俊's avatar
陈俊俊 committed
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
            }
            
        };
        [self.delegate pushNextViewController:tvc];
    }

}

- (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