SalesOrderKindVC.m 11 KB

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