SettlementTypeVC.m 10 KB

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