SelPeopleV.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. //
  2. // SelPeopleV.m
  3. // YBVideo
  4. //
  5. // Created by YunBao on 2018/7/25.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "SelPeopleV.h"
  9. #import "SelPeopleCell.h"
  10. #import "MessageListModel.h"
  11. @interface SelPeopleV()<UISearchBarDelegate,UITableViewDelegate,UITableViewDataSource>
  12. {
  13. NSString *_pubUrl;
  14. NSString *_showType; //1-选择联系人 2召唤好友
  15. BOOL _haveSection; //用户未搜索时默认显示 关注的人 并且有 header 得到搜索结果后隐藏header
  16. int _paging; //
  17. NSString *_key; //关键词
  18. NSString *_noData2;
  19. NSString *_noData1;
  20. }
  21. @property(nonatomic,strong)UIView *topMix; //搜索背景
  22. @property(nonatomic,strong)UIButton *closeBtn; //关闭
  23. @property(nonatomic,strong)UILabel *midTitle; //标题
  24. @property(nonatomic,strong)UISearchBar *searchBar; //搜索
  25. @property(nonatomic,strong)UITableView *tableView;
  26. @property(nonatomic,strong)NSMutableArray *dataArray;
  27. @end
  28. @implementation SelPeopleV
  29. - (instancetype)initWithFrame:(CGRect)frame showType:(NSString *)showtype selUser:(SelBlockEvent)event {
  30. self = [super initWithFrame:frame];
  31. if (self) {
  32. self.backgroundColor = UIColor.whiteColor;
  33. _showType = showtype;
  34. self.selEvent = event;
  35. _haveSection = YES;
  36. _paging = 1;
  37. _noData2 = YZMsg(@"赶快去关注自己感兴趣的人吧");
  38. _noData1 = YZMsg(@"你还没有关注任何人");
  39. _key = @"";
  40. _dataArray = [NSMutableArray array];
  41. [self pullFollow];
  42. [self addSubview:self.topMix];
  43. [self addSubview:self.tableView];
  44. if (@available(iOS 11.0,*)) {
  45. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  46. }
  47. }
  48. return self;
  49. }
  50. -(void)pullFollow {
  51. _pubUrl = [NSString stringWithFormat:@"User.getFollowsList&uid=%@&touid=%@&p=%d&key=%@",[Config getOwnID],[Config getOwnID],_paging,_key];
  52. [self pullData];
  53. }
  54. -(void)pullSearch {
  55. _pubUrl = [NSString stringWithFormat:@"Home.search&key=%@&uid=%@&token=%@&p=%d",_key,[Config getOwnID],[Config getOwnToken],_paging];
  56. [self pullData];
  57. }
  58. -(void)pullData {
  59. _pubUrl = [_pubUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  60. [YBNetworking postWithUrl:_pubUrl Dic:nil Suc:^(int code, id info, NSString *msg) {
  61. [_tableView.mj_header endRefreshing];
  62. [_tableView.mj_footer endRefreshing];
  63. if (code == 0) {
  64. NSArray *infoA = [NSArray arrayWithArray:info];
  65. if (_paging==1) {
  66. [_dataArray removeAllObjects];
  67. }
  68. if (infoA.count == 0) {
  69. [_tableView.mj_footer endRefreshingWithNoMoreData];
  70. }else {
  71. [_dataArray addObjectsFromArray:infoA];
  72. }
  73. if (_dataArray.count<=0) {
  74. [PublicView showTextNoData:_tableView text1:_noData1 text2:_noData2 centerY:0.8];
  75. }else {
  76. [PublicView hiddenTextNoData:_tableView];
  77. }
  78. [_tableView reloadData];
  79. }else{
  80. [MBProgressHUD showPop:msg];
  81. }
  82. } Fail:^(id fail) {
  83. [_tableView.mj_header endRefreshing];
  84. [_tableView.mj_footer endRefreshing];
  85. if (_dataArray.count<=0) {
  86. [PublicView showTextNoData:_tableView text1:_noData1 text2:_noData2 centerY:0.8];
  87. }else {
  88. [PublicView hiddenTextNoData:_tableView];
  89. }
  90. [_tableView reloadData];
  91. }];
  92. }
  93. #pragma mark - 点击事件
  94. -(void)clickCloseBtn {
  95. _key = @"";
  96. _paging = 1;
  97. _haveSection = YES;
  98. self.selEvent(@"关闭", nil);
  99. }
  100. #pragma mark - UISearchBarDelegate
  101. -(void)clickClearBtn {
  102. _key = @"";
  103. _paging = 1;
  104. _haveSection = YES;
  105. [self pullFollow];
  106. }
  107. -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
  108. _paging = 1;
  109. _key = searchText;
  110. //一个一个字清空搜索框的时候
  111. if (searchText.length==0) {
  112. _noData2 = YZMsg(@"赶快去关注自己感兴趣的人吧");
  113. _noData1 = YZMsg(@"你还没有关注任何人");
  114. _haveSection = YES;
  115. [self pullFollow];
  116. }else{
  117. _noData2 = YZMsg(@"搜索为空");
  118. _noData1 = @"";
  119. _haveSection = NO;
  120. if ([_showType isEqual:@"1"]) {
  121. [self pullFollow];
  122. }else{
  123. [self pullSearch];
  124. }
  125. }
  126. }
  127. -(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
  128. if (searchBar.text.length == 0 ) {
  129. }
  130. }
  131. -(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
  132. [searchBar resignFirstResponder];
  133. }
  134. -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  135. _key = searchBar.text;
  136. _paging = 1;
  137. if ([_showType isEqual:@"1"]) {
  138. [self pullFollow];
  139. }else{
  140. [self pullSearch];
  141. }
  142. }
  143. -(void)scrollViewDidScroll:(UIScrollView *)scrollView {
  144. [self endEditing:YES];
  145. }
  146. #pragma mark - UITableViewDelegate、UITableViewDataSource
  147. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  148. /**
  149. * 1019 前后出了一张效果图 把header去掉了
  150. * 暂时未更改 _haveSection 属性,
  151. * 20-6-20 又加回来了
  152. */
  153. if (_haveSection==YES) {
  154. return 40;
  155. }
  156. return 0.0;
  157. }
  158. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  159. if (_haveSection==YES) {
  160. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, 40)];
  161. view.backgroundColor = UIColor.whiteColor;
  162. UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, 200, 40)];
  163. title.textColor = GrayText;
  164. title.font = SYS_Font(15);
  165. title.text = YZMsg(@"我关注的人");
  166. [view addSubview:title];
  167. // UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake(15, 39.5, self.width-30, 0.5)];
  168. // line.backgroundColor =UIColor.whiteColor;
  169. // [view addSubview:line];
  170. return view;
  171. }
  172. return nil;
  173. }
  174. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  175. return 0.0;
  176. }
  177. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  178. return nil;
  179. }
  180. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  181. return 80;
  182. }
  183. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  184. return _dataArray.count;
  185. }
  186. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  187. SelPeopleCell *cell = [SelPeopleCell cellWithTab:tableView andIndexPath:indexPath];
  188. cell.backgroundColor = UIColor.whiteColor;
  189. NSDictionary *dic = _dataArray[indexPath.row];
  190. NSString *icon_path = [NSString stringWithFormat:@"%@",[dic valueForKey:@"avatar"]];
  191. [cell.iconBtn sd_setImageWithURL:[NSURL URLWithString:icon_path] forState:0];
  192. cell.nameL.text = [NSString stringWithFormat:@"%@",[dic valueForKey:@"user_nickname"]];
  193. cell.signatureL.text = [NSString stringWithFormat:@"%@",[dic valueForKey:@"signature"]];
  194. cell.selectedBackgroundView = [[UIImageView alloc]initWithImage:[PublicObj getImgWithColor:UIColor.whiteColor]];
  195. return cell;
  196. }
  197. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  198. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  199. NSDictionary *dic = _dataArray[indexPath.row];
  200. MessageListModel *model = [[MessageListModel alloc]init];
  201. NSString *uid = [NSString stringWithFormat:@"%@",[dic valueForKey:@"id"]];
  202. NSString *uname = [NSString stringWithFormat:@"%@",[dic valueForKey:@"user_nickname"]];
  203. NSString *icon = [NSString stringWithFormat:@"%@",[dic valueForKey:@"avatar"]];
  204. NSString *isAtt = minstr([dic valueForKey:@"isattention"]);
  205. model.uidStr = uid;
  206. model.unameStr = uname;
  207. model.iconStr = icon;
  208. model.isAtt = isAtt;
  209. /* 创建聊天只用到 uid、name、icon*/
  210. self.selEvent(@"", model);
  211. }
  212. #pragma mark - set/get
  213. -(UITableView *)tableView {
  214. if (!_tableView) {
  215. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,_topMix.bottom, self.width,self.height-_topMix.height-20-statusbarHeight-ShowDiff)style:UITableViewStyleGrouped];
  216. _tableView.delegate = self;
  217. _tableView.dataSource = self;
  218. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  219. _tableView.backgroundColor =RGB(245, 245, 245);// UIColor.whiteColor;
  220. YBWeakSelf;
  221. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  222. _paging = 1;
  223. if ([_showType isEqual:@"2"]&&_key.length>0) {
  224. [weakSelf pullSearch];
  225. }else{
  226. [weakSelf pullFollow];
  227. }
  228. }];
  229. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  230. _paging +=1;
  231. if ([_showType isEqual:@"2"]&&_key.length>0) {
  232. [weakSelf pullSearch];
  233. }else{
  234. [weakSelf pullFollow];
  235. }
  236. }];
  237. // _tableView.contentInset = UIEdgeInsetsMake(0, 0, ShowDiff, 0);
  238. }
  239. return _tableView;
  240. }
  241. - (UIView *)topMix {
  242. if (!_topMix) {
  243. _topMix = [[UIView alloc]initWithFrame:CGRectMake(0, 20+statusbarHeight, self.width, 44+44+10)];//标题+搜索框+空白
  244. _topMix.backgroundColor = UIColor.whiteColor;
  245. UIView *bg_v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, 44+44+5)];
  246. bg_v.backgroundColor = UIColor.whiteColor;
  247. [_topMix addSubview:bg_v];
  248. //关闭
  249. _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  250. _closeBtn.frame = CGRectMake(0, 0, 44, 44);
  251. _closeBtn.imageEdgeInsets = UIEdgeInsetsMake(13, 13, 13, 13);
  252. [_closeBtn setImage:[UIImage imageNamed:@"left_back"] forState:0];//@"gray_close"
  253. [_closeBtn addTarget:self action:@selector(clickCloseBtn) forControlEvents:UIControlEventTouchUpInside];
  254. [bg_v addSubview:_closeBtn];
  255. //标题
  256. _midTitle = [[UILabel alloc]initWithFrame:CGRectMake(self.width/2-100, 0, 200, 44)];
  257. if ([_showType isEqual:@"1"]) {
  258. _midTitle.text = YZMsg(@"选择联系人");
  259. }else{
  260. _midTitle.text = YZMsg(@"召唤好友");
  261. }
  262. _midTitle.font = SYS_Font(17);
  263. _midTitle.textAlignment = NSTextAlignmentCenter;
  264. _midTitle.textColor = [UIColor blackColor];
  265. [bg_v addSubview:_midTitle];
  266. _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,44, self.width,44)];
  267. _searchBar.backgroundImage = [PublicObj getImgWithColor:UIColor.whiteColor];
  268. // if ([_showType isEqual:@"1"]) {
  269. _searchBar.placeholder = YZMsg(@"搜索用户昵称");
  270. // }else{
  271. // _searchBar.placeholder = YZMsg(@"输入您要@的好友昵称");
  272. // }
  273. _searchBar.delegate = self;
  274. UITextField *textField ;
  275. if (@available(iOS 13.0,*)) {
  276. textField = _searchBar.searchTextField;
  277. }else {
  278. textField = [_searchBar valueForKey:@"_searchField"];
  279. }
  280. [textField setBackgroundColor:RGB(235, 235, 235)];
  281. // [textField setValue:GrayText forKeyPath:@"_placeholderLabel.textColor"];
  282. // [textField setValue:[UIFont systemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
  283. UIButton *clearBtn = [textField valueForKey:@"_clearButton"];
  284. [clearBtn addTarget:self action:@selector(clickClearBtn) forControlEvents:UIControlEventTouchUpInside];
  285. textField.textColor = GrayText;
  286. textField.layer.cornerRadius = 18;
  287. textField.layer.masksToBounds = YES;
  288. [bg_v addSubview:_searchBar];
  289. }
  290. return _topMix;
  291. }
  292. @end