// // CollectRegionsInfoVC.m // LN_School // // Created by apple on 2017/12/8. // Copyright © 2017年 Danson. All rights reserved. // #import "CollectRegionsInfoVC.h" #import "CollectRegionsVC.h" @interface CollectRegionsInfoVC () { NSMutableArray *fieldArray; NSMutableArray *selectCarType; NSArray *carTypeArray; } @end @implementation CollectRegionsInfoVC - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"围栏信息采集"; self.view.backgroundColor = [UIColor whiteColor]; self.navigationController.navigationBar.translucent = NO; [self goBackByNavigation]; fieldArray = [NSMutableArray array]; selectCarType = [NSMutableArray array]; carTypeArray = @[@"A1",@"A2",@"A3",@"B1",@"B2",@"C1",@"C2",@"C3",@"C4",@"C5",@"D",@"E",@"F",@"M",@"N",@"p"]; UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:kFrame]; scrollView.delegate = self; [self.view addSubview:scrollView]; CGFloat y = 20; CGFloat h = 40; NSArray *titleArray = @[@"场地名称:",@"场地面积(㎡):",@"可容纳车辆:",@"已投放车辆:",]; for (int i = 0; i < titleArray.count; i ++) { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, y + i*h + 4, 100, h - 5)]; [label setText:titleArray[i] Font:Font17 TextColor:KTitleColor]; [scrollView addSubview:label]; [label addViewWithRect:CGRectMake(15, y + i*h + h - 1, kSize.width - 30, 1)]; UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(120, y + i*h + 4, kSize.width - 130, h - 5)]; tf.borderStyle = UITextBorderStyleNone; tf.textAlignment = NSTextAlignmentCenter; if (i != 0) { tf.keyboardType = UIKeyboardTypeNumberPad; } [scrollView addSubview:tf]; [fieldArray addObject:tf]; } y += titleArray.count*h + 10; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, y, kSize.width - 40, 30)]; [label setText:@"培训车型:" Font:Font17 TextColor:KTitleColor]; [scrollView addSubview:label]; y += 30; NSInteger wid = kSize.width; NSInteger num = wid/40; if (wid%40 < 15) { num -= 1; } CGFloat x = (kSize.width - 40*num + 5)/2.0; for (int i = 0; i < carTypeArray.count; i ++) { int row = i/num; int column = i%num; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(x + column*40, y + row*40, 35, 35)]; [btn setTitle:carTypeArray[i] textColor:KTitleColor font:Font17 fotState:UIControlStateNormal]; btn.backgroundColor = [UIColor whiteColor]; [btn borderColor:kLineColor width:1 cornorRadios:3]; [btn target:self Tag:i + 1]; [scrollView addSubview:btn]; } y += (carTypeArray.count/num + 1) * 40 + 10; titleArray = @[@"场地地址:",@"备注:"]; for (int i = 0; i < titleArray.count; i ++) { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, y + i*h + 4, 100, h - 5)]; [label setText:titleArray[i] Font:Font17 TextColor:KTitleColor]; [scrollView addSubview:label]; [label addViewWithRect:CGRectMake(15, y + i*h + h - 1, kSize.width - 30, 1)]; UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(120, y + i*h + 4, kSize.width - 130, h - 5)]; tf.borderStyle = UITextBorderStyleNone; tf.textAlignment = NSTextAlignmentCenter; [scrollView addSubview:tf]; [fieldArray addObject:tf]; } y += titleArray.count*h + 30; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, y, kSize.width - 40, 40)]; [btn setTitle:@"下一步" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal]; btn.backgroundColor = defGreen; [btn borderCornorRadios:5]; [btn target:self Tag:20]; [scrollView addSubview:btn]; [scrollView setContentSize:CGSizeMake(kSize.width, y + 40 + 240 + 100 + SafeAreaBottomHeight)]; } - (void)btnClick:(UIButton *)sender { [self.view endEditing:YES]; UIButton *btn = (UIButton *)sender; if (btn.tag == 20) {//跳转至采集围栏 for (int i = 0; i < fieldArray.count - 1; i ++) { UITextField *tf = fieldArray[i]; if (tf.text.length < 1) { ShowMsg(@"请输入完整信息!"); return; } } if (selectCarType.count < 1) { ShowMsg(@"请选择培训车型!"); return; } //封装围栏信息 NSMutableDictionary *dic = [NSMutableDictionary dictionary]; NSArray *keyArray = @[@"name",@"area",@"totalvehnum",@"curvehnum",@"address",@"remark"]; for (int i = 0; i < fieldArray.count; i++) { UITextField *tf = fieldArray[i]; [dic setObject:tf.text forKey:keyArray[i]]; } NSString *allCarType = @""; for (NSString *carType in selectCarType) { allCarType = [allCarType stringByAppendingString:[NSString stringWithFormat:@"%@,",carType]]; } if (allCarType.length > 0) { allCarType = [allCarType substringToIndex:allCarType.length - 1]; } [dic setObject:allCarType forKey:@"vehicletype"]; NSLog(@"-------->>>>%@",dic); CollectRegionsVC *vc = [[CollectRegionsVC alloc] init]; vc.infoDic = dic; [self.navigationController pushViewController:vc animated:YES]; return; } //选择车型 NSString *carType = carTypeArray[btn.tag-1]; if ([selectCarType containsObject:carType]) { //删除车型 [selectCarType removeObject:carType]; [btn setTitleColor:KTitleColor forState:UIControlStateNormal]; btn.backgroundColor = [UIColor whiteColor]; }else { //增加车型 [selectCarType addObject:carType]; [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; btn.backgroundColor = defGreen; } } -(void)scrollViewDidScroll:(UIScrollView *)scrollView { [self.view endEditing:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end