SearchViewController.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // SearchViewController.m
  3. // RedAnt Mobile
  4. //
  5. // Created by Ray on 10/11/2017.
  6. // Copyright © 2017 Ray. All rights reserved.
  7. //
  8. #import "SearchViewController.h"
  9. #import "RANetwork.h"
  10. #import "RAUtils.h"
  11. #import "RAResultViewController.h"
  12. #import "RAConvertor.h"
  13. @interface SearchViewController ()
  14. @end
  15. @implementation SearchViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. self.params[ @"_action"]=@"ant_mobile";
  20. self.params[ @"_operate"]=@"getCondition";
  21. self.automaticallyAdjustsScrollViewInsets = NO;
  22. [self setupNavigationBar];
  23. }
  24. - (void)didReceiveMemoryWarning {
  25. [super didReceiveMemoryWarning];
  26. // Dispose of any resources that can be recreated.
  27. }
  28. - (void)viewWillAppear:(BOOL)animated {
  29. [super viewWillAppear:animated];
  30. // 解决Items按钮灰色
  31. self.navigationItem.rightBarButtonItem.enabled = false;
  32. self.navigationItem.rightBarButtonItem.enabled = true;
  33. }
  34. #pragma mark - customize editor
  35. - (UIView*)get_tableHeader
  36. {
  37. UILabel * headerview = [UILabel new];
  38. headerview.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, 44);
  39. headerview.numberOfLines = 0;
  40. headerview.textAlignment = NSTextAlignmentCenter;
  41. // headerview.lineBreakMode=
  42. headerview.text = @"";
  43. return headerview;
  44. }
  45. -(void) resize_tableHeader
  46. {
  47. //利用systemLayoutSizeFittingSize:计算出真实高度
  48. // CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)
  49. // self.editorTable.tableHeaderView.frame= CGRectMake(self.editorTable.tableHeaderView.frame.origin.x, self.editorTable.tableHeaderView.frame.origin.y, self.editorTable.tableHeaderView.frame.size.width, 10000);
  50. CGFloat height = [self.editorTable.tableHeaderView systemLayoutSizeFittingSize:CGSizeMake(self.editorTable.tableHeaderView.frame.size.width, 10000)].height;
  51. CGRect headerFrame = self.editorTable.tableHeaderView.frame;
  52. headerFrame.size.height = height+20;//20是留的上下边距
  53. //修改tableHeaderView的frame
  54. self.editorTable.tableHeaderView.frame = headerFrame;
  55. }
  56. #pragma mark - Setup UI
  57. - (void)setupNavigationBar {
  58. // UIBarButtonItem *saveItem = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveItemClick:)];
  59. UIBarButtonItem *searchItem = [[UIBarButtonItem alloc] initWithTitle:@"Search" style:UIBarButtonItemStylePlain target:self action:@selector(searchItemClick:)];
  60. self.navigationItem.rightBarButtonItems = @[searchItem];
  61. }
  62. #pragma mark - Action
  63. - (void)searchItemClick:(UIBarButtonItem *)item {
  64. // self.content_data_download[@"hidden_params"];
  65. NSMutableDictionary* upparams = [self check_cancommit:false];
  66. [upparams addEntriesFromDictionary:self.content_data_download[@"hidden_params"]];
  67. NSArray* criteria = [RAConvertor Dict2KVArray:upparams trim:true];
  68. NSMutableDictionary* result_params = [NSMutableDictionary new];
  69. result_params[@"criteria"] = [RAConvertor dict2string:criteria];//criteria;
  70. result_params[@"query_id"]=self.params[@"query_id"];
  71. result_params[@"title"]=self.params[@"title"];
  72. // ResultViewController *preQueryVC = [[UIStoryboard storyboardWithName:@"Result" bundle:nil] instantiateViewControllerWithIdentifier:@"ResultViewController"];
  73. // [preQueryVC setQueryParams: result_params];
  74. RAResultViewController *preQueryVC = [RAResultViewController buildInstanceWithParams:result_params];
  75. [self.navigationController pushViewController:preQueryVC animated:YES];
  76. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Searching"];
  77. // __weak typeof(self) weakSelf = self;
  78. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  79. // NSDictionary *contentDic = [RANetwork query:dic];
  80. // NSInteger result = [[contentDic objectForKey:@"result"] integerValue];
  81. // dispatch_async(dispatch_get_main_queue(), ^{
  82. // if (weakSelf) {
  83. // __strong typeof(weakSelf) strongSelf = weakSelf;
  84. // if (result == RESULT_TRUE) {
  85. // strongSelf.content_layout = [contentDic objectForKey:@"layout"];
  86. // strongSelf.content_action = [contentDic objectForKey:@"row_action"];
  87. // strongSelf.content_menu = [[contentDic objectForKey:@"menu"] mutableCopy];
  88. // strongSelf.content_data = [contentDic objectForKey:@"data"];
  89. // [strongSelf updateTableFrame];
  90. // [strongSelf.tableview reloadData];
  91. // } else {
  92. // [RAUtils message_alert:[contentDic objectForKey:@"err_msg"] title:@"Warning" controller:strongSelf];
  93. // }
  94. //
  95. // if (finish) {
  96. // finish((int)result,(int)[self resultItemCount]);
  97. // }
  98. //
  99. // }
  100. //
  101. // });
  102. // });
  103. }
  104. - (void)saveItemClick:(UIBarButtonItem *)item {
  105. }
  106. #pragma mark Request Editor
  107. -(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  108. {
  109. NSAssert(true, @"request_editor");
  110. return nil;
  111. // NSDictionary* ret =[RANetwork require_query_ui:request_url params:params];
  112. // dispatch_async(dispatch_get_main_queue(), ^{
  113. // UILabel * headerview=(UILabel *)self.editorTable.tableHeaderView;
  114. // headerview.text = ret[@"table_title"];
  115. // [self resize_tableHeader];
  116. // });
  117. // return ret;
  118. }
  119. #pragma mark- autocomplete
  120. -( NSArray* )sync_loadCadidate:( NSString*)str //search_id:(NSString*) search_id
  121. {
  122. NSAssert(true, @"sync_loadCadidate");
  123. return nil;
  124. // NSIndexPath * indexPath = [self.editorTable indexPathForCell:self.editingcell];
  125. // NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  126. //
  127. // NSMutableDictionary* params = [NSMutableDictionary new];
  128. // params[@"query_id"]=self.params[@"query_id"];
  129. // params[@"name"]=item_json[@"name"];
  130. // params[@"keyword"]=str;
  131. //// params[@"request_id"]
  132. // NSMutableDictionary* json = [RANetwork queryAutoComplete:params];
  133. ////
  134. // NSMutableArray* ret= json[@"cadedate"];
  135. //// if(ret==nil)
  136. //// ret = [NSMutableArray new];
  137. //// // NSMutableArray* ret = [NSMutableArray new];
  138. //// // [ret addObject:@"autocomplete"];
  139. //// // [ret addObject:@"datasource"];
  140. //// // [ret addObject:@"loadCadidate"];
  141. //// // [ret addObject:@"does"];
  142. //// // [ret addObject:@"not"];
  143. //// // [ret addObject:@"impl"];
  144. // return ret;
  145. }
  146. @end