SocietyListViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. //
  2. // SocietyListViewController.m
  3. // BuguLive
  4. //
  5. // Created by 王珂 on 17/1/22.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "SocietyListViewController.h"
  9. #import "SocietyListCell.h"
  10. #import "SHomePageVC.h"
  11. #import "SocietyListModel.h"
  12. #import "SocietyDesViewController.h"
  13. @interface SocietyListViewController ()<UISearchBarDelegate,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,SocietyListCellDelegate>
  14. {
  15. NSString *_searchString;
  16. UIView *_searchHeaderView;
  17. UIButton *_rightButton;
  18. UIImageView *_searchImgView;
  19. }
  20. @property (nonatomic, strong) UISearchBar *SearchBar;
  21. @property (nonatomic, strong) UIView * displayView;
  22. @property (nonatomic, strong) UIView * slideLineView;
  23. @property (nonatomic, strong) NSMutableArray *userDataArray;
  24. @property (nonatomic, strong) UITableView *displayTabel;
  25. @property (nonatomic, assign) int has_next;
  26. @property (nonatomic, assign) int currentPage;;
  27. @property (nonatomic, assign) int state;;
  28. @property (nonatomic, strong) UITextField *textFiled;
  29. @end
  30. @implementation SocietyListViewController
  31. - (void)viewWillAppear:(BOOL)animated
  32. {
  33. [super viewWillAppear:animated];
  34. UIApplication *application = [UIApplication sharedApplication];
  35. [application setStatusBarHidden:NO];
  36. [IQKeyboardManager sharedManager].enable = YES;
  37. [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
  38. _rightButton.hidden = NO;
  39. _textFiled.hidden = NO;
  40. _searchImgView.hidden = NO;
  41. _searchHeaderView.hidden = NO;
  42. [self loadNetDataWithPage:1];
  43. }
  44. - (void)viewDidLoad
  45. {
  46. [super viewDidLoad];
  47. self.view.backgroundColor = [UIColor whiteColor];
  48. _userDataArray = [[NSMutableArray alloc]initWithCapacity:0];
  49. [self searchbarDisplay];
  50. _currentPage = 1;
  51. [self creatTabelView];
  52. }
  53. - (void)searchbarDisplay
  54. {
  55. self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(comeBack) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  56. self.navigationItem.title = ASLocalizedString(@"公会列表");
  57. //画线
  58. UILabel * lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 0.5)];
  59. lineLabel.backgroundColor = kAppGrayColor4;
  60. lineLabel.alpha = 0.5;
  61. [self.view addSubview:lineLabel];
  62. _searchHeaderView = [[UIView alloc] initWithFrame:CGRectMake(10, 6, kScreenW-80, 30)];
  63. [_searchHeaderView setBackgroundColor:[UIColor whiteColor]];
  64. _searchHeaderView.layer.cornerRadius = 5;
  65. _searchHeaderView.layer.borderWidth = 1;
  66. _searchHeaderView.layer.borderColor = kAppMainColor.CGColor;
  67. [self.view addSubview:_searchHeaderView];
  68. _searchImgView = [[UIImageView alloc]initWithFrame:CGRectMake(4, 7, 16, 16)];
  69. _searchImgView.backgroundColor = [UIColor whiteColor];
  70. _searchImgView.image = [UIImage imageNamed:@"ic_edit_search_gray"];
  71. [_searchHeaderView addSubview:_searchImgView];
  72. _textFiled = [[UITextField alloc]initWithFrame:CGRectMake(22, 0, kScreenW -110, 30)];
  73. _textFiled.backgroundColor = [UIColor whiteColor];
  74. _textFiled.textAlignment = NSTextAlignmentLeft;
  75. _textFiled.font = [UIFont systemFontOfSize:14];
  76. _textFiled.delegate = self;
  77. [_textFiled addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  78. _textFiled.clearsOnBeginEditing = YES;
  79. _textFiled.clearsContextBeforeDrawing = YES;
  80. _textFiled.clearButtonMode = UITextFieldViewModeWhileEditing;
  81. _textFiled.placeholder = ASLocalizedString(@"请输入您想要加入的公会");
  82. [_searchHeaderView addSubview:_textFiled];
  83. _rightButton = [[UIButton alloc]initWithFrame:CGRectMake(kScreenW-70, 6, 60, 30)];
  84. [_rightButton setTitle:ASLocalizedString(@"取消")forState:0];
  85. [_rightButton setTitleColor:kAppMainColor forState:0];
  86. [_rightButton addTarget:self action:@selector(cancelButtonAction) forControlEvents:UIControlEventTouchUpInside];
  87. [self.view addSubview:_rightButton];
  88. self.view.backgroundColor = [UIColor whiteColor];
  89. UIView * blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 40, kScreenW, 10)];
  90. blackView.backgroundColor = kFamilyBackGroundColor;
  91. blackView.alpha = 0.5;
  92. [self.view addSubview:blackView];
  93. }
  94. - (void)cancelButtonAction
  95. {
  96. [_textFiled resignFirstResponder];
  97. [self.navigationController popViewControllerAnimated:NO];
  98. }
  99. - (void)comeBack
  100. {
  101. [_textFiled resignFirstResponder];
  102. [self.navigationController popViewControllerAnimated:NO];
  103. }
  104. - (void)viewWillDisappear:(BOOL)animated
  105. {
  106. [super viewWillDisappear:animated];
  107. _rightButton.hidden = YES;
  108. _textFiled.hidden = YES;
  109. _searchImgView.hidden = YES;
  110. _searchHeaderView.hidden = YES;
  111. [IQKeyboardManager sharedManager].enable = NO;
  112. [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
  113. }
  114. #pragma mark展示数据的表格创建
  115. - (void)creatTabelView
  116. {
  117. _displayTabel = [[UITableView alloc] initWithFrame:CGRectMake(0,50,kScreenW, kScreenH-110) style:UITableViewStylePlain];
  118. _displayTabel.delegate =self;
  119. _displayTabel.dataSource =self;
  120. _displayTabel.separatorStyle = UITableViewCellSeparatorStyleNone;
  121. [self.view addSubview:_displayTabel];
  122. [BGMJRefreshManager refresh:_displayTabel target:self headerRereshAction:@selector(headerReresh) shouldHeaderBeginRefresh:NO footerRereshAction:@selector(footerReresh)];
  123. }
  124. - (void)headerReresh
  125. {
  126. [self loadNetDataWithPage:1];
  127. }
  128. - (void)footerReresh
  129. {
  130. if (_has_next == 1)
  131. {
  132. _currentPage ++;
  133. [self loadNetDataWithPage:_currentPage];
  134. }
  135. else
  136. {
  137. [BGMJRefreshManager endRefresh:_displayTabel];
  138. }
  139. }
  140. #pragma mark 请求数据
  141. - (void)loadNetDataWithPage:(int)page
  142. {
  143. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  144. [parmDict setObject:@"society" forKey:@"ctl"];
  145. [parmDict setObject:@"society_list" forKey:@"act"];
  146. if (_textFiled.text.length > 0)
  147. {
  148. [parmDict setObject:_textFiled.text forKey:@"society_name"];
  149. }
  150. else
  151. {
  152. [parmDict setObject:@"" forKey:@"society_name"];
  153. }
  154. [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"page"];
  155. FWWeakify(self)
  156. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  157. {
  158. FWStrongify(self)
  159. self.state = [responseJson toInt:@"status"];
  160. if (self.state == 1)
  161. {
  162. NSDictionary * dic = [responseJson objectForKey:@"page"];
  163. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  164. self.currentPage = [dic toInt:@"page"];
  165. if (self.currentPage == 1 || self.currentPage == 0)
  166. {
  167. [self.userDataArray removeAllObjects];
  168. }
  169. self.has_next = [dic toInt:@"has_next"];
  170. }
  171. NSArray *listArray = [responseJson objectForKey:@"list"];
  172. if (listArray && [listArray isKindOfClass:[NSArray class]]&& listArray.count>0)
  173. {
  174. for (NSDictionary *dict in listArray)
  175. {
  176. SocietyListModel * model = [SocietyListModel mj_objectWithKeyValues:dict];
  177. [self.userDataArray addObject:model];
  178. }
  179. }
  180. }
  181. [self.displayTabel reloadData];
  182. [BGMJRefreshManager endRefresh:self.displayTabel];
  183. } FailureBlock:^(NSError *error) {
  184. FWStrongify(self)
  185. [BGMJRefreshManager endRefresh:self.displayTabel];
  186. }];
  187. }
  188. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  189. {
  190. return 1;
  191. }
  192. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  193. {
  194. if (_userDataArray.count>0) {
  195. return _userDataArray.count;
  196. }
  197. else
  198. return 0;
  199. }
  200. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  201. {
  202. return 60;
  203. }
  204. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  205. {
  206. static NSString * cellID = @"SocietyCellID";
  207. SocietyListCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  208. if (cell== nil) {
  209. cell = [[SocietyListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  210. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  211. }
  212. cell.model = _userDataArray[indexPath.row];
  213. cell.delegate = self;
  214. return cell;
  215. }
  216. //点击cell跳转到公会详情
  217. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  218. {
  219. SocietyListModel * model = _userDataArray[indexPath.row];
  220. SocietyDesViewController * societyDesVC = [[SocietyDesViewController alloc] init];
  221. societyDesVC.isSocietyHeder = 2;
  222. societyDesVC.society_id = model.society_id;
  223. societyDesVC.is_apply = model.is_apply;
  224. societyDesVC.listModel = model;
  225. [self.navigationController pushViewController:societyDesVC animated:YES];
  226. }
  227. // 监听改变按钮
  228. - (void)textFieldDidChange:(UITextField*) sender
  229. {
  230. NSLog(@"_SearchBarField.text==%@",_textFiled.text);
  231. [self loadNetDataWithPage:1];
  232. }
  233. //当用户按下ruturn,把焦点从textField移开那么键盘就会消失了
  234. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  235. {
  236. [textField resignFirstResponder];
  237. // [self loadNetDataWithPage:1];
  238. return YES;
  239. }
  240. - (void)textFieldDidEndEditing:(UITextField *)textField
  241. {
  242. [self loadNetDataWithPage:1];
  243. }
  244. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  245. {
  246. // [_textFiled becomeFirstResponder];
  247. return YES;
  248. }
  249. //滑动键盘下落
  250. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  251. {
  252. [_textFiled resignFirstResponder];
  253. }
  254. //申请加入公会
  255. - (void)applyWithSocietyListCell:(SocietyListCell *)cell
  256. {
  257. for (SocietyListModel * model in _userDataArray)
  258. {
  259. if ([model.is_apply isEqualToString:@"2"])
  260. {
  261. return;
  262. }
  263. }
  264. FWWeakify(self)
  265. [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"是否申请加入该公会")destructiveAction:^{
  266. FWStrongify(self)
  267. NSIndexPath * indexPath = [_displayTabel indexPathForCell:cell];
  268. SocietyListModel * model = _userDataArray[indexPath.row];
  269. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  270. [parmDict setObject:@"society_user" forKey:@"ctl"];
  271. [parmDict setObject:@"join" forKey:@"act"];
  272. [parmDict setObject:model.society_id forKey:@"society_id"];
  273. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  274. if ([responseJson toInt:@"status"]==1)
  275. {
  276. model.is_apply = @"1";
  277. self.userDataArray[indexPath.row] = model;
  278. [self.displayTabel reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  279. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"申请已提交")];
  280. }
  281. } FailureBlock:^(NSError *error) {
  282. }];
  283. } cancelAction:^{
  284. }];
  285. }
  286. @end