CollectRegionsInfoVC.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // CollectRegionsInfoVC.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/12/8.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "CollectRegionsInfoVC.h"
  9. #import "CollectRegionsVC.h"
  10. @interface CollectRegionsInfoVC ()<UIScrollViewDelegate>
  11. {
  12. NSMutableArray *fieldArray;
  13. NSMutableArray *selectCarType;
  14. NSArray *carTypeArray;
  15. }
  16. @end
  17. @implementation CollectRegionsInfoVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.navigationItem.title = @"围栏信息采集";
  21. self.view.backgroundColor = [UIColor whiteColor];
  22. self.navigationController.navigationBar.translucent = NO;
  23. [self goBackByNavigation];
  24. fieldArray = [NSMutableArray array];
  25. selectCarType = [NSMutableArray array];
  26. carTypeArray = @[@"A1",@"A2",@"A3",@"B1",@"B2",@"C1",@"C2",@"C3",@"C4",@"C5",@"D",@"E",@"F",@"M",@"N",@"p"];
  27. UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:kFrame];
  28. scrollView.delegate = self;
  29. [self.view addSubview:scrollView];
  30. CGFloat y = 20;
  31. CGFloat h = 40;
  32. NSArray *titleArray = @[@"场地名称:",@"场地面积(㎡):",@"可容纳车辆:",@"已投放车辆:",];
  33. for (int i = 0; i < titleArray.count; i ++) {
  34. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, y + i*h + 4, 100, h - 5)];
  35. [label setText:titleArray[i] Font:Font17 TextColor:KTitleColor];
  36. [scrollView addSubview:label];
  37. [label addViewWithRect:CGRectMake(15, y + i*h + h - 1, kSize.width - 30, 1)];
  38. UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(120, y + i*h + 4, kSize.width - 130, h - 5)];
  39. tf.borderStyle = UITextBorderStyleNone;
  40. tf.textAlignment = NSTextAlignmentCenter;
  41. if (i != 0) {
  42. tf.keyboardType = UIKeyboardTypeNumberPad;
  43. }
  44. [scrollView addSubview:tf];
  45. [fieldArray addObject:tf];
  46. }
  47. y += titleArray.count*h + 10;
  48. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, y, kSize.width - 40, 30)];
  49. [label setText:@"培训车型:" Font:Font17 TextColor:KTitleColor];
  50. [scrollView addSubview:label];
  51. y += 30;
  52. NSInteger wid = kSize.width;
  53. NSInteger num = wid/40;
  54. if (wid%40 < 15) {
  55. num -= 1;
  56. }
  57. CGFloat x = (kSize.width - 40*num + 5)/2.0;
  58. for (int i = 0; i < carTypeArray.count; i ++) {
  59. int row = i/num;
  60. int column = i%num;
  61. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(x + column*40, y + row*40, 35, 35)];
  62. [btn setTitle:carTypeArray[i] textColor:KTitleColor font:Font17 fotState:UIControlStateNormal];
  63. btn.backgroundColor = [UIColor whiteColor];
  64. [btn borderColor:kLineColor width:1 cornorRadios:3];
  65. [btn target:self Tag:i + 1];
  66. [scrollView addSubview:btn];
  67. }
  68. y += (carTypeArray.count/num + 1) * 40 + 10;
  69. titleArray = @[@"场地地址:",@"备注:"];
  70. for (int i = 0; i < titleArray.count; i ++) {
  71. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, y + i*h + 4, 100, h - 5)];
  72. [label setText:titleArray[i] Font:Font17 TextColor:KTitleColor];
  73. [scrollView addSubview:label];
  74. [label addViewWithRect:CGRectMake(15, y + i*h + h - 1, kSize.width - 30, 1)];
  75. UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(120, y + i*h + 4, kSize.width - 130, h - 5)];
  76. tf.borderStyle = UITextBorderStyleNone;
  77. tf.textAlignment = NSTextAlignmentCenter;
  78. [scrollView addSubview:tf];
  79. [fieldArray addObject:tf];
  80. }
  81. y += titleArray.count*h + 30;
  82. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, y, kSize.width - 40, 40)];
  83. [btn setTitle:@"下一步" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  84. btn.backgroundColor = RQMianColor;
  85. [btn borderCornorRadios:5];
  86. [btn target:self Tag:20];
  87. [scrollView addSubview:btn];
  88. [scrollView setContentSize:CGSizeMake(kSize.width, y + 40 + 240 + 100 + kSafeAreaBottomHeight)];
  89. }
  90. - (void)btnClick:(UIButton *)sender {
  91. [self.view endEditing:YES];
  92. UIButton *btn = (UIButton *)sender;
  93. if (btn.tag == 20) {//跳转至采集围栏
  94. for (int i = 0; i < fieldArray.count - 1; i ++) {
  95. UITextField *tf = fieldArray[i];
  96. if (tf.text.length < 1) {
  97. ShowMsg(@"请输入完整信息!");
  98. return;
  99. }
  100. }
  101. if (selectCarType.count < 1) {
  102. ShowMsg(@"请选择培训车型!");
  103. return;
  104. }
  105. //封装围栏信息
  106. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  107. NSArray *keyArray = @[@"name",@"area",@"totalvehnum",@"curvehnum",@"address",@"remark"];
  108. for (int i = 0; i < fieldArray.count; i++) {
  109. UITextField *tf = fieldArray[i];
  110. [dic setObject:tf.text forKey:keyArray[i]];
  111. }
  112. NSString *allCarType = @"";
  113. for (NSString *carType in selectCarType) {
  114. allCarType = [allCarType stringByAppendingString:[NSString stringWithFormat:@"%@,",carType]];
  115. }
  116. if (allCarType.length > 0) {
  117. allCarType = [allCarType substringToIndex:allCarType.length - 1];
  118. }
  119. [dic setObject:allCarType forKey:@"vehicletype"];
  120. NSLog(@"-------->>>>%@",dic);
  121. CollectRegionsVC *vc = [[CollectRegionsVC alloc] init];
  122. vc.infoDic = dic;
  123. [self.navigationController pushViewController:vc animated:YES];
  124. return;
  125. }
  126. //选择车型
  127. NSString *carType = carTypeArray[btn.tag-1];
  128. if ([selectCarType containsObject:carType]) {
  129. //删除车型
  130. [selectCarType removeObject:carType];
  131. [btn setTitleColor:KTitleColor forState:UIControlStateNormal];
  132. btn.backgroundColor = [UIColor whiteColor];
  133. }else {
  134. //增加车型
  135. [selectCarType addObject:carType];
  136. [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  137. btn.backgroundColor = RQMianColor;
  138. }
  139. }
  140. -(void)scrollViewDidScroll:(UIScrollView *)scrollView {
  141. [self.view endEditing:YES];
  142. }
  143. - (void)didReceiveMemoryWarning {
  144. [super didReceiveMemoryWarning];
  145. }
  146. @end