InvoiceStyleViewController.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. //
  2. // InvoiceStyleViewController.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2020/4/30.
  6. // Copyright © 2020 elongtian. All rights reserved.
  7. //
  8. #import "InvoiceStyleViewController.h"
  9. @interface InvoiceStyleViewController ()
  10. @end
  11. @implementation InvoiceStyleViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. self.navigationItem.title = @"请选择";
  15. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  16. [button setImage:[UIImage imageNamed:@"icon_back.png"] forState:UIControlStateNormal];
  17. [button addTarget:self action:@selector(goBack)
  18. forControlEvents:UIControlEventTouchUpInside];
  19. button.frame = CGRectMake(0, 0,45,22);
  20. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  21. self.navigationItem.leftBarButtonItem = menuButton;
  22. self.navigationController.navigationBar.barTintColor = NavigationBarTintColor;
  23. self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:16]};
  24. _tableView = [UITableView new];
  25. _tableView.delegate=self;
  26. _tableView.dataSource=self;
  27. _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
  28. _tableView.frame=CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height) ;
  29. [self.view addSubview:_tableView];
  30. //搜索框
  31. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, 44)];
  32. _searchBar.delegate=self;
  33. self.tableView.tableHeaderView=_searchBar;
  34. }
  35. /**
  36. viewWillAppear函数
  37. */
  38. - (void)viewWillAppear:(BOOL)animated {
  39. _arrSearch = [[NSMutableArray alloc]init];
  40. _arrFilter = [[NSMutableArray alloc]init];
  41. [self reloadData];
  42. }
  43. -(void)reloadData
  44. {
  45. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  46. [dict setObject:@"GetInvoiceLayout" forKey:@"Action"];
  47. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  48. [dict setObject:kkUserCode forKey:@"UserCode"];
  49. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  50. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  51. _mDownManager = [[ASIDownManager alloc] init];
  52. [self startLoading];
  53. _mDownManager.delegate = self;
  54. _mDownManager.onRequestSuccess = @selector(onInvoiceStyleLoadFinish:);
  55. _mDownManager.onRequestFail = @selector(onInvoiceStyleLoadFail:);
  56. [_mDownManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  57. }
  58. -(void)onInvoiceStyleLoadFinish:(ASIDownManager*)sender {
  59. [self cancel];
  60. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  61. int iStatus = resultModel.status;
  62. NSString *message=resultModel.message;
  63. if(iStatus==0)
  64. {
  65. NSDictionary *resultDic= (NSDictionary*)resultModel.result;
  66. NSArray *resultArray= [resultDic objectForKey:@"Table"];
  67. if(resultArray!=nil&&resultArray.count>0)
  68. {
  69. _arrSearch = [[NSMutableArray alloc]initWithArray:resultArray];
  70. _arrFilter = [[NSMutableArray alloc] initWithArray:_arrSearch];
  71. if(_arrSearch.count == 0){
  72. [self showAlertViewText:@"未找到匹配结果"];
  73. }
  74. [self.tableView reloadData];
  75. }
  76. }
  77. else if(iStatus == ActionResultStatusAuthError
  78. ||iStatus == ActionResultStatusNoLogin
  79. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  80. [self showReLoginDialog:message];
  81. return;
  82. }else {
  83. [self.tableView reloadData];
  84. [self showAlertViewText:message];
  85. }
  86. }
  87. -(void)onInvoiceStyleLoadFail:(ASIDownManager *)sender
  88. {
  89. [self cancel];
  90. [self showAlertViewText:@"网络异常"];
  91. }
  92. /**
  93. 取消进度条
  94. */
  95. - (void)cancel {
  96. [self stopLoading];
  97. }
  98. /**
  99. tableview的分区数
  100. @param tableView tableView description
  101. @return return value description
  102. */
  103. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  104. return 1;
  105. }
  106. /**
  107. tableview每个分区的行数
  108. @param tableView <#tableView description#>
  109. @param section <#section description#>
  110. @return <#return value description#>
  111. */
  112. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  113. return _arrFilter.count;
  114. }
  115. /**
  116. 获取tableviewcell
  117. @param tableView <#tableView description#>
  118. @param indexPath <#indexPath description#>
  119. @return <#return value description#>
  120. */
  121. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  122. static NSString *cellIdentifier = @"Cell";
  123. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  124. if(cell == nil) {
  125. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  126. }
  127. NSDictionary *dic=_arrFilter[indexPath.row];
  128. NSString *name = [dic objectForKey:@"InvoiceLayoutName"];
  129. cell.textLabel.textAlignment = NSTextAlignmentCenter;
  130. cell.textLabel.font=textFont;
  131. cell.textLabel.text=name;
  132. return cell;
  133. }
  134. /**
  135. 增加取消按钮
  136. */
  137. - (void)addCancelButton {
  138. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
  139. [button2 addTarget:self action:@selector(cancelSearch)
  140. forControlEvents:UIControlEventTouchUpInside];
  141. button2.frame = CGRectMake(0, 0, 40, 24);
  142. [button2 setTitle:@"取消" forState:UIControlStateNormal];
  143. [button2 setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  144. UIBarButtonItem *menuButton2 = [[UIBarButtonItem alloc] initWithCustomView:button2];
  145. self.navigationItem.rightBarButtonItem = menuButton2;
  146. }
  147. /**
  148. 取消查询按钮
  149. */
  150. - (void)cancelSearch {
  151. [_searchBar resignFirstResponder];
  152. [self removeCancel];
  153. }
  154. /**
  155. 移除取消按钮
  156. */
  157. - (void) removeCancel {
  158. self.navigationItem.rightBarButtonItem = nil;
  159. }
  160. /**
  161. 点击tableview的每一行
  162. @param tableView <#tableView description#>
  163. @param indexPath <#indexPath description#>
  164. */
  165. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  166. NSDictionary *dic=_arrFilter[indexPath.row];
  167. NSString *styleName = [dic objectForKey:@"InvoiceLayoutName"];
  168. NSString *styleId = [dic objectForKey:@"InvoiceLayoutID"];
  169. if([self.inventoryDelegate respondsToSelector:@selector(getInvoiceStyle:name:)]){
  170. [self.inventoryDelegate getInvoiceStyle:styleId name:styleName];
  171. }
  172. [self.navigationController popViewControllerAnimated:YES];
  173. }
  174. /**
  175. 搜索栏开始编辑
  176. @param searchBar <#searchBar description#>
  177. @return <#return value description#>
  178. */
  179. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
  180. {
  181. [self addCancelButton];
  182. return YES;
  183. }
  184. /**
  185. searchbar委托函数
  186. @param searchBar <#searchBar description#>
  187. @param range <#range description#>
  188. @param text <#text description#>
  189. @return <#return value description#>
  190. */
  191. - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  192. return YES;
  193. }
  194. /**
  195. searchBar文本变化完成
  196. @param searchBar <#searchBar description#>
  197. @param searchText <#searchText description#>
  198. */
  199. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
  200. if ([searchText isEqualToString:@""]) {
  201. self.arrFilter = _arrSearch;
  202. [_tableView reloadData];
  203. return;
  204. }
  205. NSString *keyName = @"";
  206. keyName = @"InvoiceLayoutName";
  207. NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K contains[cd] %@ Or %K contains[cd] %@", keyName, searchText,@"InvoiceLayoutName",searchText];
  208. NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearch filteredArrayUsingPredicate:predicateString]];
  209. self.arrFilter = filteredArray;
  210. [_tableView reloadData];
  211. }
  212. /**
  213. 取消按钮点击函数
  214. @param searchBar <#searchBar description#>
  215. */
  216. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
  217. [searchBar resignFirstResponder];
  218. [self cancelSearch];
  219. }
  220. /**
  221. scrollview回调事件
  222. @param scrollView <#scrollView description#>
  223. */
  224. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  225. [_searchBar resignFirstResponder];
  226. [self cancelSearch];
  227. }
  228. @end