SManageFriendVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. //
  2. // SManageFriendVC.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/9/11.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "SManageFriendVC.h"
  9. #import "SenderModel.h"
  10. #import "managerFriendTableViewCell.h"
  11. #import "FDUIKitObjC.h"
  12. @interface SManageFriendVC ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (strong, nonatomic) UITableView *myTableView;
  14. @property (strong, nonatomic) UIButton *backButton; //取消,邀请或者踢出好友
  15. @property(nonatomic, strong) UIButton *navBackBtn;
  16. @property (strong, nonatomic) UILabel *headLabel; //头部提示的label
  17. @property (strong, nonatomic) NSMutableArray *dataArray;
  18. @property (strong, nonatomic) NSMutableDictionary *Mdict; //装选中了多少个好友的字典
  19. @property (strong, nonatomic) NSMutableArray *idArray; //id的数组
  20. @property (copy, nonatomic) NSString *allIdString; //选中好友的id
  21. @property (strong, nonatomic) UIView *backView;
  22. @property (assign, nonatomic) int currentPage;
  23. @property (assign, nonatomic) int has_next;
  24. @end
  25. @implementation SManageFriendVC
  26. - (void)viewDidLoad
  27. {
  28. [super viewDidLoad];
  29. self.view.backgroundColor = kBackGroundColor;
  30. SUS_WINDOW.window_Tap_Ges.enabled = NO;
  31. SUS_WINDOW.window_Pan_Ges.enabled = NO;
  32. }
  33. - (void)initFWUI
  34. {
  35. [super initFWUI];
  36. self.dataArray = [[NSMutableArray alloc]init];
  37. self.idArray = [[NSMutableArray alloc]init];
  38. self.Mdict = [[NSMutableDictionary alloc]init];
  39. [self creatMainView];
  40. }
  41. - (void)viewWillAppear:(BOOL)animated
  42. {
  43. [super viewWillAppear:animated];
  44. [self.navigationController setNavigationBarHidden:YES];
  45. }
  46. - (void)viewWillDisappear:(BOOL)animated
  47. {
  48. [super viewWillDisappear:animated];
  49. [self.navigationController setNavigationBarHidden:NO];
  50. }
  51. - (void)creatMainView
  52. {
  53. self.headLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, kStatusBarHeight, kScreenW / 3 * 2, 44)];
  54. self.headLabel.backgroundColor = kWhiteColor;
  55. self.headLabel.textColor = kAppGrayColor2;
  56. if (self.type == 0)
  57. {
  58. self.headLabel.text = ASLocalizedString(@"请选择要踢出的观众");
  59. }else
  60. {
  61. self.headLabel.text = ASLocalizedString(@"请选择要邀请的好友");
  62. }
  63. self.headLabel.textAlignment = NSTextAlignmentCenter;
  64. self.headLabel.font = [UIFont systemFontOfSize:14];
  65. self.headLabel.centerX = kScreenW / 2;
  66. [self.view addSubview:self.headLabel];
  67. self.navBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  68. [self.navBackBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
  69. self.navBackBtn.frame = CGRectMake(10, kStatusBarHeight, kRealValue(35), kRealValue(35));
  70. [self.navBackBtn addTarget:self action:@selector(clickBack:) forControlEvents:UIControlEventTouchUpInside];
  71. [self.view addSubview:self.navBackBtn];
  72. self.myTableView = [[UITableView alloc]init];
  73. self.myTableView.frame = CGRectMake(0, 74, kScreenW, kScreenH-134);
  74. self.myTableView.dataSource = self;
  75. self.myTableView.delegate = self;
  76. self.myTableView.backgroundColor = kWhiteColor;
  77. self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  78. [self.myTableView registerNib:[UINib nibWithNibName:@"managerFriendTableViewCell" bundle:nil] forCellReuseIdentifier:@"managerFriendTableViewCell"];
  79. [self.view addSubview:self.myTableView];
  80. [BGMJRefreshManager refresh:self.myTableView target:self headerRereshAction:@selector(headerReresh) footerRereshAction:@selector(footerReresh)];
  81. self.backView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenH-60- FD_Bottom_SafeArea_Height, kScreenW, 60)];
  82. self.backView.backgroundColor = kWhiteColor;
  83. [self.view addSubview:self.backView];
  84. self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
  85. self.backButton.frame = CGRectMake(20,10, kScreenW-40, 40);
  86. [self.backButton setTitle:ASLocalizedString(@"取消")forState:UIControlStateNormal];
  87. self.backButton.backgroundColor = kBlackColor;
  88. [self.backButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
  89. self.backButton.titleLabel.font = [UIFont systemFontOfSize:14];
  90. self.backButton.layer.cornerRadius = self.backButton.frame.size.height/2;
  91. [self.backButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  92. [self.backView addSubview:self.backButton];
  93. [self.view addSubview:self.backView];
  94. }
  95. -(void)clickBack:(UIButton *)sender{
  96. [self dismissViewControllerAnimated:YES completion:nil];
  97. }
  98. - (void)initFWData
  99. {
  100. [super initFWData];
  101. [self loadNetDataWithPage:1];
  102. }
  103. - (void)headerReresh
  104. {
  105. [self loadNetDataWithPage:1];
  106. }
  107. - (void)footerReresh
  108. {
  109. if (self.has_next == 1)
  110. {
  111. self.currentPage ++;
  112. [self loadNetDataWithPage:self.currentPage];
  113. }
  114. else
  115. {
  116. [BGMJRefreshManager endRefresh:self.myTableView];
  117. }
  118. }
  119. - (void)loadNetDataWithPage:(int)page
  120. {
  121. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  122. if (self.type == 0)//踢人列表
  123. {
  124. [parmDict setObject:@"video" forKey:@"ctl"];
  125. [parmDict setObject:@"private_room_friends" forKey:@"act"];
  126. [parmDict setObject:_chatAVRoomId forKey:@"group_id"];
  127. }
  128. else if (self.type == 1)
  129. {
  130. [parmDict setObject:@"user" forKey:@"ctl"];
  131. [parmDict setObject:@"friends" forKey:@"act"];
  132. }
  133. if (_liveAVRoomId && ![_liveAVRoomId isEqualToString:@""])
  134. {
  135. [parmDict setObject:_liveAVRoomId forKey:@"room_id"];
  136. }
  137. [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"page"];
  138. FWWeakify(self)
  139. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  140. {
  141. FWStrongify(self)
  142. if ([responseJson toInt:@"status"] == 1)
  143. {
  144. self.currentPage = [responseJson toInt:@"page"];
  145. if (self.currentPage == 1)
  146. {
  147. [self.dataArray removeAllObjects];
  148. }
  149. self.has_next = [responseJson toInt:@"has_next"];
  150. NSArray *listArray = [responseJson objectForKey:@"list"];
  151. if (listArray && [listArray isKindOfClass:[NSArray class]])
  152. {
  153. if (listArray.count > 0)
  154. {
  155. for (NSDictionary *dict in listArray)
  156. {
  157. SenderModel *sModel = [SenderModel mj_objectWithKeyValues:dict];
  158. [self.dataArray addObject:sModel];
  159. }
  160. }
  161. }
  162. if (self.dataArray.count)
  163. {
  164. [self hideNoContentView];
  165. }else
  166. {
  167. [self showNoContentView];
  168. }
  169. [self.myTableView reloadData];
  170. }
  171. [BGMJRefreshManager endRefresh:self.myTableView];
  172. } FailureBlock:^(NSError *error) {
  173. FWStrongify(self)
  174. [BGMJRefreshManager endRefresh:self.myTableView];
  175. }];
  176. }
  177. #pragma mark -UITableViewDelegate&UITableViewDataSource
  178. //返回行数
  179. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  180. {
  181. return 1;
  182. }
  183. //返回段数
  184. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  185. {
  186. return self.dataArray.count;
  187. }
  188. //返回单元格
  189. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  190. {
  191. //通过复用id(reusedID)来寻找,只有同种类型的cell才能算找到
  192. managerFriendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"managerFriendTableViewCell"];
  193. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  194. SenderModel *model = self.dataArray[indexPath.section];
  195. [cell creatCellWithModel:model];
  196. if (self.idArray.count)
  197. {
  198. if ([self.idArray containsObject:model.user_id])
  199. {
  200. cell.rightImgView.image = [UIImage imageNamed:@"com_radio_selected_2"];
  201. }else
  202. {
  203. cell.rightImgView.image = [UIImage imageNamed:@"com_radio_normal_2"];
  204. }
  205. }else
  206. {
  207. cell.rightImgView.image = [UIImage imageNamed:@"com_radio_normal_2"];
  208. }
  209. // if (indexPath.section == self.dataArray.count-1)
  210. // {
  211. // cell.lineView.hidden = YES;
  212. // }
  213. return cell;
  214. }
  215. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  216. {
  217. return 70*kAppRowHScale;
  218. }
  219. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  220. {
  221. SenderModel *model = self.dataArray[indexPath.section];
  222. if (self.idArray.count)
  223. {
  224. if ([self.idArray containsObject:model.user_id])
  225. {
  226. [self.idArray removeObject:model.user_id];
  227. }else
  228. {
  229. [self.idArray addObject:model.user_id];
  230. }
  231. }else
  232. {
  233. [self.idArray addObject:model.user_id];
  234. }
  235. if (self.idArray.count)
  236. {
  237. if (self.type == 0)//踢出好友
  238. {
  239. [self.backButton setTitle:ASLocalizedString(@"踢出观众")forState:UIControlStateNormal];
  240. }else
  241. {
  242. [self.backButton setTitle:ASLocalizedString(@"邀请好友")forState:UIControlStateNormal];
  243. }
  244. }else
  245. {
  246. [self.backButton setTitle:ASLocalizedString(@"取消")forState:UIControlStateNormal];
  247. }
  248. [self.myTableView reloadData];
  249. }
  250. //button的点击事件
  251. - (void)buttonClick:(UIButton *)button
  252. {
  253. self.allIdString = @"";
  254. for (NSString *idString in self.idArray)
  255. {
  256. if (self.allIdString.length)
  257. {
  258. self.allIdString = [NSString stringWithFormat:@"%@,%@",self.allIdString,idString];
  259. }else
  260. {
  261. self.allIdString = [NSString stringWithFormat:@"%@",idString];
  262. }
  263. }
  264. if (self.allIdString.length)
  265. {
  266. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  267. if (self.type == 0)//踢人列表
  268. {
  269. [parmDict setObject:@"video" forKey:@"ctl"];
  270. [parmDict setObject:@"private_drop_user" forKey:@"act"];
  271. }else if (self.type == 1)
  272. {
  273. [parmDict setObject:@"video" forKey:@"ctl"];
  274. [parmDict setObject:@"private_push_user" forKey:@"act"];
  275. }
  276. if (_liveAVRoomId && ![_liveAVRoomId isEqualToString:@""])
  277. {
  278. [parmDict setObject:_liveAVRoomId forKey:@"room_id"];
  279. }
  280. [parmDict setObject:self.allIdString forKey:@"user_ids"];
  281. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  282. {
  283. if ([responseJson toInt:@"status"] == 1)
  284. {
  285. [self.navigationController popViewControllerAnimated:NO];
  286. }
  287. } FailureBlock:^(NSError *error)
  288. {
  289. NSLog(@"error===%@",error);
  290. }];
  291. }else
  292. {
  293. [self dismissViewControllerAnimated:YES completion:nil];
  294. }
  295. }
  296. @end