PromotionTypeVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. //
  2. // SalesOrderKindVC.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2020/9/8.
  6. // Copyright © 2020 elongtian. All rights reserved.
  7. //
  8. #import "PromotionTypeVC.h"
  9. @interface PromotionTypeVC ()<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 PromotionTypeVC
  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:@"PromotionsTypeName"];
  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:@"PromotionsTypeID"];
  145. model.name = [dic objectForKey:@"PromotionsTypeName"];
  146. if ([self.bDelegate respondsToSelector:@selector(baseIDAndNameDoneDatas : BaseIDAndName:)]){
  147. [self.bDelegate baseIDAndNameDoneDatas:model BaseIDAndName:self.showDialogViewTag];
  148. }
  149. //是否是dismissViewController
  150. if (_isPresentViewFlag) {
  151. [self dismissViewControllerAnimated:YES completion:nil];
  152. }else{
  153. [self.navigationController popViewControllerAnimated:YES];
  154. }
  155. }
  156. #pragma mark - 数据回调
  157. /**
  158. 数据加载成功回调
  159. @param sender <#sender description#>
  160. */
  161. - (void)onLoadFinish:(ASIDownManager *)sender
  162. {
  163. // 取消进度条
  164. [self cancel];
  165. // 服务器返回数据
  166. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  167. // 服务器返回数据状态值
  168. int iStatus = resultModel.status;
  169. // 服务器返回数据消息
  170. NSString *message = resultModel.message;
  171. // 服务器返回数据状态值正确
  172. if (iStatus == 0)
  173. {
  174. NSArray *approvArr = (NSArray *)resultModel.result;
  175. if(approvArr != nil)
  176. {
  177. _arrSearch = [[NSMutableArray alloc] initWithArray:approvArr];
  178. _arrFilter = [[NSMutableArray alloc] initWithArray:_arrSearch];
  179. if(_arrSearch.count == 0)
  180. {
  181. [self showAlertViewText:@"未找到匹配结果"];
  182. }
  183. [self.tableView reloadData];
  184. }
  185. }
  186. // 服务器返回数据状态值异常
  187. else if(iStatus == ActionResultStatusAuthError
  188. ||iStatus == ActionResultStatusNoLogin
  189. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  190. [self showReLoginDialog:message];
  191. }
  192. else {
  193. [self.tableView reloadData];
  194. [self showAlertViewText:message];
  195. }
  196. }
  197. /**
  198. 加载失败
  199. @param sender <#sender description#>
  200. */
  201. - (void)onLoadFail:(ASIDownManager *)sender {
  202. [self cancel];
  203. [self.tableView reloadData];
  204. [self showAlertViewText:@"网络异常"];
  205. }
  206. #pragma mark - searchbar回调
  207. /**
  208. 开始编辑文件
  209. @param searchBar <#searchBar description#>
  210. @return <#return value description#>
  211. */
  212. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
  213. {
  214. [self addCancelButton];
  215. return YES;
  216. }
  217. /**
  218. 是否可以查询
  219. @param searchBar <#searchBar description#>
  220. @param range <#range description#>
  221. @param text <#text description#>
  222. @return <#return value description#>
  223. */
  224. - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  225. {
  226. return YES;
  227. }
  228. /**
  229. 文本变化
  230. @param searchBar <#searchBar description#>
  231. @param searchText <#searchText description#>
  232. */
  233. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  234. {
  235. if ([searchText isEqualToString:@""]) {
  236. self.arrFilter = _arrSearch;
  237. [_tableView reloadData];
  238. return;
  239. }
  240. NSString *keyName = @"PromotionsTypeName";
  241. //< 模糊查找
  242. NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K contains[cd] %@", keyName, searchText];
  243. NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearch filteredArrayUsingPredicate:predicateString]];
  244. self.arrFilter = filteredArray;
  245. [_tableView reloadData];
  246. }
  247. /**
  248. 查询按钮点击
  249. @param searchBar <#searchBar description#>
  250. */
  251. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  252. {
  253. [searchBar resignFirstResponder];
  254. [self cancelSearch];
  255. }
  256. /**
  257. 开始拖拽
  258. @param scrollView <#scrollView description#>
  259. */
  260. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  261. {
  262. [_searchBar resignFirstResponder];
  263. [self cancelSearch];
  264. }
  265. #pragma mark - 私有函数
  266. /**
  267. 进度条隐藏
  268. */
  269. - (void)cancel {
  270. [self stopLoading];
  271. }
  272. /**
  273. 添加取消按钮
  274. */
  275. - (void)addCancelButton
  276. {
  277. //添加取消按钮
  278. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  279. [button addTarget:self action:@selector(cancelSearch)
  280. forControlEvents:UIControlEventTouchUpInside];
  281. button.frame = CGRectMake(0, 0, 40, 24);
  282. [button setTitle:@"取消" forState:UIControlStateNormal];
  283. [button setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  284. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  285. self.navigationItem.rightBarButtonItem = menuButton;
  286. }
  287. /**
  288. 取消查询
  289. */
  290. - (void)cancelSearch
  291. {
  292. [_searchBar resignFirstResponder];
  293. [self removeCancel];
  294. }
  295. /**
  296. 取消按钮隐藏
  297. */
  298. - (void) removeCancel
  299. {
  300. self.navigationItem.rightBarButtonItem = nil;
  301. }
  302. /**
  303. 加载数据
  304. */
  305. - (void)reloadData
  306. {
  307. [self startLoading];
  308. NSString *urlStr = ServerURL;
  309. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  310. [dict setObject:@"GetPromotionsTypeDataSource" forKey:@"Action"];
  311. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  312. [dict setObject:kkUserCode forKey:@"UserCode"];
  313. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  314. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  315. [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  316. }
  317. /**
  318. 返回父界面
  319. */
  320. - (void)goBack
  321. {
  322. //是否是dismissViewController
  323. if (_isPresentViewFlag) {
  324. [self dismissViewControllerAnimated:YES completion:nil];
  325. }else{
  326. [self.navigationController popViewControllerAnimated:YES];
  327. }
  328. }
  329. @end