EditLocationVC.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. //
  2. // EditLocationVC.m
  3. // Haishenghai-master
  4. //
  5. // Created by GG on 2019/1/20.
  6. // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
  7. //
  8. #import "EditLocationVC.h"
  9. #import "Header.h"
  10. #import <QuartzCore/QuartzCore.h>
  11. @interface EditLocationVC ()<UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource>
  12. {
  13. UIButton *selectBtn;
  14. }
  15. @property(nonatomic,strong)UITextField *locationTF;
  16. @property(nonatomic,strong)UITextField *siteTF;
  17. @property(nonatomic,strong)NSMutableArray *dataArray;
  18. @property(nonatomic,strong)UITableView *tableView;
  19. @property(nonatomic,copy)NSString *selectID;
  20. @end
  21. @implementation EditLocationVC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. self.view.backgroundColor = [UIColor whiteColor];
  26. self.navigationItem.title = @"添加设备";
  27. self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
  28. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
  29. //设置导航栏左侧按钮
  30. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  31. [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal];
  32. backBtn.frame = CGRectMake(0, 0, 44, 44);
  33. [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  34. backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  35. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
  36. // JJOptionView *view1 = [[JJOptionView alloc] initWithFrame:CGRectMake(110, 190, WIDTH-130, 40)];
  37. // view1.dataSource = @[@"1",@"2",@"3",@"4",@"5"];
  38. // view1.delegate = self;
  39. // [self.view addSubview:view1];
  40. [self setupUI];
  41. [self showListView];
  42. //查询场所
  43. [DataSourceManager getSiteWithUrlPagesize:100 Page:1 completionBlock:^(NSMutableArray *array) {
  44. _dataArray = array;
  45. [_tableView reloadData];
  46. }];
  47. //键盘监听
  48. // 添加通知监听见键盘弹出/退出
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardAction:) name:UIKeyboardWillShowNotification object:nil];
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardAction:) name:UIKeyboardWillHideNotification object:nil];
  51. }
  52. -(void)backClick{
  53. [self.navigationController popViewControllerAnimated:YES];
  54. }
  55. //- (void)optionView:(JJOptionView *)optionView selectedIndex:(NSInteger)selectedIndex {
  56. // NSLog(@"%@",optionView);
  57. // NSLog(@"%ld",selectedIndex);
  58. //}
  59. -(void)setupUI{
  60. for (int i =0; i<4; i++) {
  61. NSArray *titleArray =@[@"设备编号:",@"设备名称:",@"安装位置:",@"所属场所:"];
  62. UILabel *deveceLabel = [[UILabel alloc]init];
  63. deveceLabel.text = [titleArray objectAtIndex:i];
  64. deveceLabel.frame = CGRectMake(20+(100)*(i/4), kTopHeight+(40)*(i%4), 100, 40);
  65. deveceLabel.textAlignment = NSTextAlignmentLeft;
  66. deveceLabel.font = [UIFont systemFontOfSize:18];
  67. deveceLabel.textColor = [UIColor blackColor];
  68. [self.view addSubview:deveceLabel];
  69. }
  70. for (int i =0; i<2; i++) {
  71. UILabel *detailLabel = [[UILabel alloc]init];
  72. detailLabel.frame = CGRectMake(110+(200)*(i/2), kTopHeight+(40)*(i%2), WIDTH-130, 40);
  73. detailLabel.tag = i;
  74. if (i==0) {
  75. detailLabel.text = _deveceNumber;
  76. }else{
  77. detailLabel.text = _deveceName;
  78. }
  79. detailLabel.textAlignment = NSTextAlignmentLeft;
  80. detailLabel.font = [UIFont systemFontOfSize:18];
  81. detailLabel.textColor = [UIColor blackColor];
  82. [self.view addSubview:detailLabel];
  83. }
  84. _locationTF = [[UITextField alloc]init];
  85. _locationTF.frame = CGRectMake(110, kTopHeight+80, WIDTH-130, 40);
  86. _locationTF.delegate = self;
  87. _locationTF.textAlignment = NSTextAlignmentLeft;
  88. _locationTF.font = [UIFont systemFontOfSize:18];
  89. _locationTF.textColor = [UIColor blackColor];
  90. [self.view addSubview:_locationTF];
  91. _siteTF = [[UITextField alloc]init];
  92. _siteTF.userInteractionEnabled =YES;
  93. _siteTF.frame = CGRectMake(110, kTopHeight+120, WIDTH-130, 40);
  94. _siteTF.textAlignment = NSTextAlignmentLeft;
  95. _siteTF.font = [UIFont systemFontOfSize:18];
  96. _siteTF.delegate =self;
  97. _siteTF.textColor = [UIColor blackColor];
  98. [self.view addSubview:_siteTF];
  99. selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  100. selectBtn.frame = CGRectMake(_siteTF.frame.size.width-40, 0, 40, 40);
  101. [selectBtn setImage:[UIImage imageNamed:@"hsh_login_drop-up"] forState:UIControlStateNormal];
  102. [selectBtn setImage:[UIImage imageNamed:@"hsh_login_drop-down"] forState:UIControlStateSelected];
  103. [selectBtn addTarget:self action:@selector(selectedBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  104. [_siteTF addSubview:selectBtn];
  105. for (int i =0; i<2; i++) {
  106. UIView *line = [[UIView alloc]init];
  107. line.frame = CGRectMake(110+200*(i/2), (kTopHeight+119)+(39)*(i%2), WIDTH-130, 1);
  108. line.backgroundColor = [UIColor lightGrayColor];
  109. [self.view addSubview:line];
  110. }
  111. //提交按钮
  112. /** 退出登录 */
  113. UIButton *comitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  114. comitBtn.frame = CGRectMake(20, HEIGHT-49-50, self.view.frame.size.width-40, 44);
  115. comitBtn.layer.cornerRadius = 18;
  116. [comitBtn setBackgroundImage:[UIImage imageNamed:@"blue"] forState:UIControlStateNormal];
  117. [comitBtn setTitle:@"提交" forState:UIControlStateNormal];
  118. [comitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  119. comitBtn.titleLabel.font = [UIFont systemFontOfSize:18];
  120. comitBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
  121. // self.loginButton.clipsToBounds = YES;
  122. [comitBtn addTarget:self action:@selector(comitBtnClick) forControlEvents:UIControlEventTouchUpInside];
  123. [self.view addSubview:comitBtn];
  124. }
  125. - (void)didReceiveMemoryWarning {
  126. [super didReceiveMemoryWarning];
  127. // Dispose of any resources that can be recreated.
  128. }
  129. -(void)comitBtnClick{
  130. NSLog(@"点击了%d",_typeID);
  131. NSString *inputText = [_locationTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  132. if (inputText.length==0) {
  133. ALERTSHOW(@"安装位置不能为空");
  134. return;
  135. }
  136. NSString *str = [NSString stringWithFormat:@"%@",_deveceNumber];
  137. [DataSourceManager addDeveceWithUrlDeveceID:_deveceNumber dLongtitude:@"120" dLatitude:@"120" dLocation:_locationTF.text siteid:_selectID completionBlock:^(NSDictionary *dic) {
  138. //导航栏返回特定视图
  139. for (UIViewController *controller in self.navigationController.viewControllers) {
  140. if ([controller isKindOfClass:[ViewController class]]) {
  141. [self.navigationController popToViewController:controller animated:YES];
  142. }
  143. }
  144. }];
  145. }
  146. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  147. [self.view endEditing:YES];
  148. }
  149. -(void)selectedBtnClick:(UIButton *)btn{
  150. [_locationTF resignFirstResponder];
  151. btn.selected =!btn.selected;
  152. if (btn.selected) {
  153. _tableView.hidden = NO;
  154. }else{
  155. _tableView.hidden = YES;
  156. }
  157. }
  158. -(void)showListView{
  159. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(_siteTF.frame.origin.x, _siteTF.frame.origin.y+40, _siteTF.frame.size.width, 200) style:UITableViewStylePlain];
  160. _tableView.delegate = self;
  161. _tableView.dataSource = self;
  162. _tableView.hidden =YES;
  163. [self.view addSubview:_tableView];
  164. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  165. self.tableView.layer.borderWidth = 1;
  166. self.tableView.layer.borderColor = [[UIColor lightGrayColor] CGColor];//设置列表边框
  167. }
  168. #pragma mark---tableviewDelegate
  169. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  170. return _dataArray.count;
  171. }
  172. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  173. return 40;
  174. }
  175. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  176. static NSString *cellId = @"cellID";
  177. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  178. if (!cell) {
  179. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  180. }
  181. PlaceModel *place = self.dataArray[indexPath.row];
  182. cell.textLabel.text =place.deployment;
  183. _selectID = place.Id;
  184. return cell;
  185. }
  186. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  187. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  188. _siteTF.text = cell.textLabel.text;
  189. PlaceModel *place = self.dataArray[indexPath.row];
  190. _selectID = place.Id;
  191. [_tableView removeFromSuperview];
  192. }
  193. -(BOOL)textFieldShouldReturn:(UITextField *)textField{
  194. [_locationTF resignFirstResponder];
  195. return YES;
  196. }
  197. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  198. if (textField ==_siteTF) {
  199. return NO;
  200. }
  201. return YES;
  202. }
  203. -(void)keyboardAction:(NSNotification *)sender{
  204. NSString *nameStr = sender.name;
  205. //判断是哪个通知,做出相应的处理
  206. //键盘弹出
  207. if ([nameStr isEqualToString:UIKeyboardWillShowNotification]) {
  208. _tableView.hidden =YES;
  209. selectBtn.selected = NO;
  210. }
  211. }
  212. /*
  213. #pragma mark - Navigation
  214. // In a storyboard-based application, you will often want to do a little preparation before navigation
  215. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  216. // Get the new view controller using [segue destinationViewController].
  217. // Pass the selected object to the new view controller.
  218. }
  219. */
  220. @end