PositionNumberViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. //
  2. // PositionNumberViewController.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2019/9/4.
  6. // Copyright © 2019 elongtian. All rights reserved.
  7. //
  8. #import "PositionNumberViewController.h"
  9. @interface PositionNumberViewController ()
  10. @end
  11. @implementation PositionNumberViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. //是否是dismissViewController
  15. if (_isPresentViewFlg) {
  16. UIView *vTitle = [[UIView alloc]init];
  17. vTitle.frame = CGRectMake(0, 0, Screen_Width, 44 + rectStatusHeight);
  18. vTitle.backgroundColor = NavigationBarTintColor;
  19. [self.view addSubview:vTitle];
  20. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  21. [button setImage:[UIImage imageNamed:@"icon_back"]
  22. forState:UIControlStateNormal];
  23. [button addTarget:self action:@selector(gotoBack)
  24. forControlEvents:UIControlEventTouchUpInside];
  25. button.frame = CGRectMake(20, rectStatusHeight + 13, 9, 15);
  26. [vTitle addSubview:button];
  27. UILabel *lblTitle = [[UILabel alloc]init];
  28. lblTitle.frame = CGRectMake(9, rectStatusHeight + 13, Screen_Width-2*9 - 20, 15);
  29. lblTitle.textColor = [UIColor whiteColor];
  30. lblTitle.text = @"请选择";
  31. lblTitle.textAlignment = NSTextAlignmentCenter;
  32. [vTitle addSubview:lblTitle];
  33. }else{
  34. self.navigationItem.title = @"请选择";
  35. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  36. [button setImage:[UIImage imageNamed:@"icon_back"]
  37. forState:UIControlStateNormal];
  38. [button addTarget:self action:@selector(gotoBack)
  39. forControlEvents:UIControlEventTouchUpInside];
  40. button.frame = CGRectMake(0, 0,45,22);
  41. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  42. self.navigationItem.leftBarButtonItem = menuButton;
  43. [self.navigationController setNavigationBarHidden:NO];
  44. }
  45. _tableView = [UITableView new];
  46. _tableView.delegate=self;
  47. _tableView.dataSource=self;
  48. //是否是dismissViewController
  49. if (_isPresentViewFlg) {
  50. self.tableView.frame = CGRectMake(0, 44 + rectStatusHeight, self.view.bounds.size.width, self.view.bounds.size.height - 44 - rectStatusHeight - 1) ;
  51. }
  52. else{
  53. self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-rectNavHeight - rectStatusHeight - 1) ;
  54. }
  55. [self.view addSubview:_tableView];
  56. //搜索框
  57. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
  58. _searchBar.delegate=self;
  59. self.tableView.tableHeaderView=_searchBar;
  60. }
  61. /**
  62. viewWillAppear
  63. @param animated <#animated description#>
  64. */
  65. - (void)viewWillAppear:(BOOL)animated
  66. {
  67. self.arrSearch = [[NSMutableArray alloc] init] ;
  68. self.arrFilter = [[NSMutableArray alloc] init] ;
  69. _downManager = [[ASIDownManager alloc] init];
  70. _downManager.delegate = self;
  71. _downManager.onRequestSuccess = @selector(onLoadFinish:);
  72. _downManager.onRequestFail = @selector(onLoadFail:);
  73. [self reloadData];
  74. }
  75. /**
  76. 加载库存列表数据
  77. */
  78. - (void)reloadData
  79. {
  80. [self startLoading];
  81. NSString *urlStr = ServerURL;
  82. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  83. [dict setObject:@"GetPositionNumber" forKey:@"Action"];
  84. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  85. [dict setObject:kkUserCode forKey:@"UserCode"];
  86. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  87. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  88. [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  89. }
  90. #pragma mark - searchbar回调
  91. /**
  92. 数据加载成功回调
  93. @param sender <#sender description#>
  94. */
  95. - (void)onLoadFinish:(ASIDownManager *)sender{
  96. /// 取消进度条
  97. [self cancel];
  98. // 服务器返回数据
  99. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  100. // 服务器返回数据状态值
  101. int iStatus = resultModel.status;
  102. // 服务器返回数据消息
  103. NSString *message = resultModel.message;
  104. // 服务器返回数据状态值正确
  105. if (iStatus == 0)
  106. {
  107. NSDictionary * approveDic = (NSDictionary *)resultModel.result;
  108. NSArray *approvArr= [approveDic objectForKey:@"Table"];
  109. if(approvArr != nil)
  110. {
  111. _arrSearch = [[NSMutableArray alloc]initWithArray:approvArr];
  112. self.arrFilter = [[NSMutableArray alloc] initWithArray:_arrSearch];
  113. if(!_arrSearch || _arrSearch.count == 0){
  114. [self showAlertViewText:@"未找到匹配结果"];
  115. }
  116. [self.tableView reloadData];
  117. }
  118. }
  119. // 服务器返回数据状态值异常
  120. else if(iStatus == ActionResultStatusAuthError
  121. ||iStatus == ActionResultStatusNoLogin
  122. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  123. [self showReLoginDialog:message];
  124. }
  125. else {
  126. [self.tableView reloadData];
  127. [self showAlertViewText:message];
  128. }
  129. }
  130. /**
  131. 加载失败
  132. @param sender <#sender description#>
  133. */
  134. - (void)onLoadFail:(ASIDownManager *)sender {
  135. [self cancel];
  136. [self.tableView reloadData];
  137. [self showAlertViewText:@"网络异常"];
  138. }
  139. #pragma mark - tableView回调
  140. /**
  141. Section
  142. @param tableView <#tableView description#>
  143. @return <#return value description#>
  144. */
  145. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  146. {
  147. return 1;
  148. }
  149. /**
  150. 单元格个数
  151. @param tableView <#tableView description#>
  152. @param section <#section description#>
  153. @return <#return value description#>
  154. */
  155. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  156. {
  157. return self.arrFilter.count;
  158. }
  159. /**
  160. 每个单元格
  161. @param tableView <#tableView description#>
  162. @param indexPath <#indexPath description#>
  163. @return <#return value description#>
  164. */
  165. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  166. {
  167. static NSString *CellIdentifier = @"Cell";
  168. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
  169. if(cell == nil)
  170. {
  171. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  172. }
  173. NSDictionary *dic = self.arrFilter[indexPath.row];
  174. cell.textLabel.text = [dic objectForKey:@"DictionaryValue"];
  175. cell.textLabel.textAlignment = NSTextAlignmentCenter;
  176. cell.textLabel.font = [UIFont systemFontOfSize:TextFontOfSize];
  177. return cell;
  178. }
  179. /**
  180. 单元格点击事件
  181. @param tableView <#tableView description#>
  182. @param indexPath <#indexPath description#>
  183. */
  184. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  185. NSDictionary *dic=self.arrFilter[indexPath.row];
  186. BaseIDAndNameModel *model = [BaseIDAndNameModel new];
  187. model.id = [dic objectForKey:@"DictionaryID"];
  188. model.name = [dic objectForKey:@"DictionaryValue"];
  189. if ([self.bDelegate respondsToSelector:@selector(baseIDAndNameDoneDatas : BaseIDAndName:)]){
  190. [self.bDelegate baseIDAndNameDoneDatas:model BaseIDAndName:self.showDialogViewTag];
  191. }
  192. //是否是dismissViewController
  193. if (_isPresentViewFlg) {
  194. [self dismissViewControllerAnimated:YES completion:nil];
  195. }else{
  196. [self.navigationController popViewControllerAnimated:YES];
  197. }
  198. }
  199. /**
  200. 开始编辑
  201. @param searchBar <#searchBar description#>
  202. @return <#return value description#>
  203. */
  204. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
  205. {
  206. [self addCancelButton];
  207. return YES;
  208. }
  209. /**
  210. 是否可以查询
  211. @param searchBar <#searchBar description#>
  212. @param range <#range description#>
  213. @param text <#text description#>
  214. @return <#return value description#>
  215. */
  216. - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  217. {
  218. return YES;
  219. }
  220. /**
  221. 文本变化
  222. @param searchBar <#searchBar description#>
  223. @param searchText <#searchText description#>
  224. */
  225. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  226. {
  227. if ([searchText isEqualToString:@""]) {
  228. self.arrFilter = _arrSearch;
  229. [_tableView reloadData];
  230. return;
  231. }
  232. NSString *keyName = @"DictionaryValue";
  233. //< 模糊查找
  234. NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K contains[cd] %@", keyName, searchText];
  235. NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearch filteredArrayUsingPredicate:predicateString]];
  236. self.arrFilter = filteredArray;
  237. [_tableView reloadData];
  238. }
  239. /**
  240. 查询点击事件
  241. @param searchBar <#searchBar description#>
  242. */
  243. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  244. {
  245. [searchBar resignFirstResponder];
  246. [self cancelSearch];
  247. }
  248. /**
  249. 开始拖动
  250. @param scrollView <#scrollView description#>
  251. */
  252. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  253. {
  254. [_searchBar resignFirstResponder];
  255. [self cancelSearch];
  256. }
  257. #pragma mark - 私有函数
  258. /**
  259. 进度条隐藏
  260. */
  261. - (void)cancel {
  262. [self stopLoading];
  263. }
  264. /**
  265. 添加取消按钮
  266. */
  267. - (void)addCancelButton
  268. {
  269. //添加取消按钮
  270. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  271. [button addTarget:self action:@selector(cancelSearch)
  272. forControlEvents:UIControlEventTouchUpInside];
  273. button.frame = CGRectMake(0, 0, 40, 24);
  274. [button setTitle:@"取消" forState:UIControlStateNormal];
  275. [button setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  276. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  277. self.navigationItem.rightBarButtonItem = menuButton;
  278. }
  279. /**
  280. 取消查询
  281. */
  282. - (void)cancelSearch
  283. {
  284. [_searchBar resignFirstResponder];
  285. [self removeCancel];
  286. }
  287. /**
  288. 取消按钮隐藏
  289. */
  290. - (void) removeCancel
  291. {
  292. self.navigationItem.rightBarButtonItem = nil;
  293. }
  294. /**
  295. 返回父界面
  296. */
  297. - (void)gotoBack
  298. {
  299. //是否是dismissViewController
  300. if (_isPresentViewFlg) {
  301. [self dismissViewControllerAnimated:YES completion:nil];
  302. }else{
  303. [self.navigationController popViewControllerAnimated:YES];
  304. }
  305. }
  306. @end