PayTypeVC.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. //
  2. // PayTypeVC.m
  3. // IBOSS
  4. //
  5. // Created by Dongke on 16/1/20.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:收款方式控制器
  9. #import "PayTypeVC.h"
  10. #import "PayTypeModel.h"
  11. #import "TypeViewCell.h"
  12. @implementation PayTypeVC
  13. NSInteger row;
  14. #pragma mark - 公共函数
  15. /**
  16. 视图加载完成函数
  17. */
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.arrFilterData = [[NSMutableArray alloc]init];
  21. self.arrSearchData = [[NSMutableArray alloc]init];
  22. row = 0;
  23. self.navigationItem.title = @"请选择";
  24. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  25. [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
  26. [button addTarget:self action:@selector(goBack)
  27. forControlEvents:UIControlEventTouchUpInside];
  28. button.frame = CGRectMake(0, 0,45,22);
  29. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  30. self.navigationItem.leftBarButtonItem = menuButton;
  31. self.tableView = [UITableView new];
  32. self.tableView.dataSource=self;
  33. self.tableView.delegate=self;
  34. self.tableView.frame=CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 44 - 20 - 4) ;
  35. [self.view addSubview:self.tableView];
  36. //搜索框
  37. self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
  38. self.searchBar.delegate=self;
  39. self.tableView.tableHeaderView=self.searchBar;
  40. }
  41. /**
  42. 视图将出现函数
  43. @param animated <#animated description#>
  44. */
  45. - (void)viewWillAppear:(BOOL)animated{
  46. if(!_arrFilterData){
  47. _arrFilterData = [[NSMutableArray alloc]init];
  48. }
  49. if(!_arrSearchData){
  50. _arrSearchData = [[NSMutableArray alloc]init];
  51. }
  52. self.arrTextModels = [[NSMutableArray alloc]init];
  53. self.mDownManager = [[ASIDownManager alloc] init];
  54. self.mDownManager.delegate = self;
  55. self.mDownManager.onRequestSuccess = @selector(onRequestSuccess:);
  56. self.mDownManager.onRequestFail = @selector(onRequestFail:);
  57. [self reloadData];
  58. }
  59. #pragma mark - 委托函数
  60. /**
  61. 数据加载成功函数
  62. @param sender <#sender description#>
  63. */
  64. - (void)onRequestSuccess:(ASIDownManager *)sender {
  65. // 取消进度条
  66. [self cancel];
  67. // 服务器返回数据转换model
  68. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  69. // 服务器返回数据状态值
  70. int iStatus = resultModel.status;
  71. // 服务器返回数据消息
  72. NSString *message = resultModel.message;
  73. // 服务器返回数据状态值正确
  74. if (iStatus == 0) {
  75. // 服务器返回数据结果
  76. NSArray *approvArr = (NSArray *)resultModel.result;
  77. if(approvArr != nil)
  78. {
  79. [_arrSearchData removeAllObjects];
  80. [_arrSearchData addObjectsFromArray:approvArr];
  81. [_arrFilterData removeAllObjects];
  82. [_arrFilterData addObjectsFromArray:_arrSearchData];
  83. if(_arrSearchData.count == 0)
  84. {
  85. [self showAlertViewText:@"未找到匹配结果"];
  86. }
  87. [self changeArrToModel:_arrFilterData];
  88. [self.tableView reloadData];
  89. }
  90. }
  91. else if(iStatus == ActionResultStatusAuthError
  92. ||iStatus == ActionResultStatusNoLogin
  93. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  94. [self showReLoginDialog:message];
  95. return;
  96. }
  97. else {
  98. [self.tableView reloadData];
  99. [self showAlertViewText:message];
  100. }
  101. }
  102. /**
  103. 数据加载失败函数
  104. @param sender <#sender description#>
  105. */
  106. - (void)onRequestFail:(ASIDownManager *)sender {
  107. [self.tableView reloadData];
  108. [self showAlertViewText:@"网络异常"];
  109. }
  110. /**
  111. 获取table view的cell
  112. @param tableView <#tableView description#>
  113. @param indexPath <#indexPath description#>
  114. @return <#return value description#>
  115. */
  116. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  117. static NSString *CellIdentifier = @"TypeViewCell";
  118. TypeViewCell *cell =(TypeViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  119. if(cell == nil){
  120. NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TypeViewCell" owner:self options:nil];
  121. cell = [nib objectAtIndex:0];
  122. }
  123. PayTypeModel* infoModel = self.arrTextModels[indexPath.row];
  124. [cell parseInfoModel:infoModel];
  125. return cell;
  126. }
  127. /**
  128. table view的点击事件
  129. @param tableView <#tableView description#>
  130. @param indexPath <#indexPath description#>
  131. */
  132. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  133. row = indexPath.row;
  134. [self.payDelegate setPayTypeModel:self.arrTextModels[indexPath.row]];
  135. [self.navigationController popViewControllerAnimated:YES];
  136. }
  137. /**
  138. 获取table view的行数
  139. @param tableView <#tableView description#>
  140. @param section <#section description#>
  141. @return <#return value description#>
  142. */
  143. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  144. return _arrFilterData.count;
  145. }
  146. /**
  147. 获取table view的高度
  148. @param tableView <#tableView description#>
  149. @param indexPath <#indexPath description#>
  150. @return <#return value description#>
  151. */
  152. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  153. return 148.0f;
  154. }
  155. /**
  156. search bar开始编辑函数
  157. @param searchBar <#searchBar description#>
  158. @return <#return value description#>
  159. */
  160. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
  161. {
  162. [self addCancelButton];
  163. return YES;
  164. }
  165. /**
  166. search bar是否允许替换文本
  167. @param searchBar <#searchBar description#>
  168. @param range <#range description#>
  169. @param text <#text description#>
  170. @return <#return value description#>
  171. */
  172. - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  173. {
  174. return YES;
  175. }
  176. /**
  177. search bar文本变化回调
  178. @param searchBar <#searchBar description#>
  179. @param searchText <#searchText description#>
  180. */
  181. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  182. {
  183. if ([searchText isEqualToString:@""]) {
  184. self.arrFilterData = _arrSearchData;
  185. [self changeArrToModel:_arrFilterData];
  186. [_tableView reloadData];
  187. return;
  188. }
  189. NSString *keyName = @"SettlementTypeName";
  190. //< 模糊查找
  191. NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", keyName, searchText];
  192. NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearchData filteredArrayUsingPredicate:predicateString]];
  193. self.arrFilterData = filteredArray;
  194. [self changeArrToModel:_arrFilterData];
  195. [_tableView reloadData];
  196. }
  197. /**
  198. search bar搜索按钮点击
  199. @param searchBar <#searchBar description#>
  200. */
  201. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  202. {
  203. [searchBar resignFirstResponder];
  204. [self cancelSearch];
  205. }
  206. /**
  207. scroll view的回调
  208. @param scrollView <#scrollView description#>
  209. */
  210. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  211. {
  212. [_searchBar resignFirstResponder];
  213. [self cancelSearch];
  214. }
  215. #pragma mark - 私有函数
  216. /**
  217. 返回函数
  218. */
  219. - (void)goBack
  220. {
  221. [self.navigationController popViewControllerAnimated:YES];
  222. }
  223. /**
  224. 加载数据函数
  225. */
  226. - (void)reloadData
  227. {
  228. [self startLoading];
  229. NSString *urlStr = ServerURL;
  230. NSMutableDictionary *dict = [NSMutableDictionary new];
  231. [dict setObject:@"GetReceivableWayIphone" forKey:@"Action"];
  232. [dict setObject:kkAccountCode forKey:@"AccountCode"];
  233. [dict setObject:kkUserCode forKey:@"UserCode"];
  234. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  235. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  236. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  237. }
  238. /**
  239. 保存数组数据
  240. @param arr <#arr description#>
  241. */
  242. - (void)changeArrToModel:(NSArray* )arr{
  243. if(arr != nil){
  244. [_arrTextModels removeAllObjects];
  245. for(int i = 0;i < arr.count;i++)
  246. {
  247. PayTypeModel * info = [PayTypeModel new];
  248. NSDictionary * dic = arr[i];
  249. info.settlementType = [NSString stringWithFormat:@"%@",[dic objectForKey:@"SettlementType"]];
  250. info.settlementTypeName = [dic objectForKey:@"SettlementTypeName"];
  251. info.receivableSum = [NSString stringWithFormat:@"%@",[dic objectForKey:@"ReceivableSum"]];
  252. info.existsHandlingFee = [NSString stringWithFormat:@"%@",[dic objectForKey:@"ExistsHandlingFee"]];
  253. info.earnestFee = [NSString stringWithFormat:@"%@",[dic objectForKey:@"EarnestFee"]];
  254. info.remarks = [NSString stringWithFormat:@"%@",[dic objectForKey:@"Remarks"]];
  255. info.salesID = [NSString stringWithFormat:@"%@",[dic objectForKey:@"SalesID"]];
  256. info.valueFlag = [NSString stringWithFormat:@"%@",[dic objectForKey:@"ValueFlag"]];
  257. [_arrTextModels addObject:info];
  258. }
  259. }
  260. }
  261. /**
  262. 添加取消按钮
  263. */
  264. - (void)addCancelButton
  265. {
  266. //添加取消按钮
  267. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
  268. [button2 addTarget:self action:@selector(cancelSearch)
  269. forControlEvents:UIControlEventTouchUpInside];
  270. button2.frame = CGRectMake(0, 0, 40, 24);
  271. [button2 setTitle:@"取消" forState:UIControlStateNormal];
  272. [button2 setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  273. UIBarButtonItem *menuButton2 = [[UIBarButtonItem alloc] initWithCustomView:button2];
  274. self.navigationItem.rightBarButtonItem = menuButton2;
  275. }
  276. /**
  277. 取消查询
  278. */
  279. - (void)cancelSearch
  280. {
  281. [_searchBar resignFirstResponder];
  282. [self removeCancel];
  283. }
  284. /**
  285. 移除取消按钮
  286. */
  287. - (void) removeCancel
  288. {
  289. self.navigationItem.rightBarButtonItem = nil;
  290. }
  291. /**
  292. 取消进度条加载
  293. */
  294. - (void)cancel {
  295. [self stopLoading];
  296. }
  297. @end