RoomMicUserListView.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. //
  2. // RoomMicUserListView.m
  3. // UniversalApp
  4. //
  5. // Created by bogokj on 2019/8/8.
  6. // Copyright © 2019 voidcat. All rights reserved.
  7. //
  8. #import "RoomMicUserListView.h"
  9. //#import "RoomMicManageCell.h"
  10. #import "RoomModel.h"
  11. #import "RoomUserInfo.h"
  12. #import "BGRoomMicManageCell.h"
  13. #import "HTSegmentedScrollView.h"
  14. #import "VoiceHTTPManger.h"
  15. @interface RoomMicUserListView ()<UITableViewDelegate,UITableViewDataSource,RoomMicManageCellDelegate>
  16. @property(nonatomic, strong) UIButton *backBtn;
  17. @property(nonatomic, strong) UILabel *applyLabel;
  18. @property(nonatomic, strong) UIView *shadowView;
  19. @property(nonatomic, strong) UITableView *tableView;
  20. @property(nonatomic, strong) UITableView *tableView2;
  21. @property(nonatomic, strong) QMUIButton *searchBtn;
  22. @end
  23. @implementation RoomMicUserListView
  24. - (instancetype)initWithFrame:(CGRect)frame{
  25. if (self = [super initWithFrame:frame]) {
  26. HTSegmentedScrollView *segView = [[HTSegmentedScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, self.height)];
  27. [self addSubview:segView];
  28. [segView addSegmentedItems:@[ASLocalizedString(@"上麦申请"), ASLocalizedString(@"麦位管理")]];
  29. self.backgroundColor = kWhiteColor;
  30. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.width, 50)];
  31. titleLabel.textColor = kAppGrayColor1;
  32. titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
  33. titleLabel.textAlignment = NSTextAlignmentCenter;
  34. titleLabel.text = ASLocalizedString(@"抱人上麦");
  35. titleLabel.hidden = YES;
  36. [self addSubview:titleLabel];
  37. [self addSubview:self.searchBtn];
  38. self.searchBtn.hidden = YES;
  39. [self addSubview:self.backBtn];
  40. // [self addSubview:self.tableView];
  41. [segView addScrollViews:@[self.tableView, self.tableView2]];
  42. }
  43. return self;
  44. }
  45. - (void)searchBtnAction:(QMUIButton *)sender{
  46. // if (self.delegate && [self.delegate respondsToSelector:@selector(userListView:didClicSearchBtn:)]) {
  47. // [self.delegate userListView:self didClicSearchBtn:sender];
  48. // }
  49. [self addSearchTF];
  50. }
  51. -(void)request
  52. {
  53. }
  54. - (void)addSearchTF {
  55. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:ASLocalizedString(@"请输入用户ID:") message:nil preferredStyle:UIAlertControllerStyleAlert];
  56. //增加确定按钮;
  57. [alertController addAction:[UIAlertAction actionWithTitle:ASLocalizedString(@"抱TA上麦") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  58. //获取第1个输入框;
  59. UITextField *userNameTextField = alertController.textFields.firstObject;
  60. //获取第2个输入框;
  61. // UITextField *passwordTextField = alertController.textFields.lastObject;
  62. NSLog(@"用户ID = %@",userNameTextField.text);
  63. if (StrValid(userNameTextField.text)) {
  64. [self searchID:userNameTextField.text];
  65. }
  66. }]];
  67. //增加取消按钮;
  68. [alertController addAction:[UIAlertAction actionWithTitle:ASLocalizedString(@"取消") style:UIAlertActionStyleDefault handler:nil]];
  69. //定义第一个输入框;
  70. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  71. textField.placeholder = ASLocalizedString(@"请输入用户ID");
  72. textField.keyboardType = UIKeyboardTypeNumberPad;
  73. }];
  74. // //定义第二个输入框;
  75. // [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  76. // textField.placeholder = @"请输入密码";
  77. // }];
  78. [self.vc presentViewController:alertController animated:true completion:nil];
  79. }
  80. - (void)searchID:(NSString *)ID {
  81. BOOL ret = NO;
  82. for (RoomUserInfo *model in self.dataArray) {
  83. if ([model.user_id isEqualToString:ID]) {
  84. ret = YES;
  85. // RoomMicManageCell * messageCell = [[RoomMicManageCell alloc]init];
  86. BGRoomMicManageCell * messageCell = [[BGRoomMicManageCell alloc]init];
  87. messageCell.model = model;
  88. if (self.delegate && [self.delegate respondsToSelector:@selector(userListView:manageCell:didClickManageBtn:)]) {
  89. [self.delegate userListView:self manageCell:messageCell didClickManageBtn:nil];
  90. }
  91. }
  92. }
  93. if (ret == NO) {
  94. }
  95. }
  96. - (void)reqeustData {
  97. [self.voiceApi requestWheatListType:@"0" block:^(NSDictionary *selfPtr) {
  98. NSMutableArray *dataArr = [NSMutableArray modelArrayWithClass:RoomUserInfo.class json:selfPtr[@"data"]];
  99. self.dataArray = dataArr;
  100. [self.tableView reloadData];
  101. }];
  102. [self.voiceApi requestWheatListType:@"1" block:^(NSDictionary *selfPtr) {
  103. NSMutableArray *dataArr = [NSMutableArray modelArrayWithClass:RoomUserInfo.class json:selfPtr[@"data"]];
  104. self.dataArray2 = dataArr;
  105. [self.tableView2 reloadData];
  106. }];
  107. }
  108. - (void)setModel:(RoomModel *)model{
  109. _model = model;
  110. [self requestData];
  111. }
  112. - (void)requestData{
  113. __weak __typeof(self)weakSelf = self;
  114. //http://www.bogo.voice.broadcast/mapi/public/index.php/api/Voice_Additional_api/voice_up_list
  115. /*
  116. NSString *url = [[CYURLUtils sharedCYURLUtils] makeVoiceURLWithC:@"Voice_Additional_api" A:@"voice_up_list"];
  117. [CYNET POSTv2:url parameters:@{@"voice_id":self.model.voice.user_id} responseCache:^(id responseObject) {
  118. //do nothing
  119. } success:^(id responseObject) {
  120. __strong __typeof(weakSelf)strongSelf = weakSelf;
  121. if ([[responseObject objectForKey:@"code"] integerValue] == 1) {
  122. [strongSelf.dataArray removeAllObjects];
  123. for (NSDictionary *dict in responseObject[@"list"]) {
  124. RoomUserInfo *model = [RoomUserInfo mj_objectWithKeyValues:dict];
  125. model.user_name = model.user_nickname;
  126. model.user_img = model.avatar;
  127. [strongSelf.dataArray addObject:model];
  128. }
  129. [strongSelf.applyLabel setText:[NSString stringWithFormat:ASLocalizedString(@" 房间在线 (%ld人)"),strongSelf.dataArray.count]];
  130. [strongSelf.tableView reloadData];
  131. }
  132. } failure:^(NSString *error) {
  133. [[HUDHelper sharedInstance] tipMessage:error];
  134. } hasCache:NO];
  135. */
  136. }
  137. - (void)backBtnAction:(UIButton *)sender{
  138. [self hide];
  139. }
  140. - (void)manageCell:(RoomMicManageCell *)messageCell didClickManageBtn:(UIButton *)sender{
  141. if (self.delegate && [self.delegate respondsToSelector:@selector(userListView:manageCell:didClickManageBtn:)]) {
  142. [self.delegate userListView:self manageCell:messageCell didClickManageBtn:sender];
  143. }
  144. }
  145. - (void)show:(UIView *)superView{
  146. [superView addSubview:self.shadowView];
  147. [superView addSubview:self];
  148. [self reqeustData];
  149. __weak __typeof(self)weakSelf = self;
  150. [UIView animateWithDuration:0.25 animations:^{
  151. __strong __typeof(weakSelf)strongSelf = weakSelf;
  152. strongSelf.frame = CGRectMake(0, kScreenH - strongSelf.height, strongSelf.width, strongSelf.height);
  153. }];
  154. }
  155. - (void)hide{
  156. __weak __typeof(self)weakSelf = self;
  157. [UIView animateWithDuration:0.25 animations:^{
  158. __strong __typeof(weakSelf)strongSelf = weakSelf;
  159. strongSelf.frame = CGRectMake(0, kScreenH, strongSelf.width, strongSelf.height);
  160. } completion:^(BOOL finished) {
  161. __strong __typeof(weakSelf)strongSelf = weakSelf;
  162. [strongSelf.shadowView removeFromSuperview];
  163. [strongSelf removeFromSuperview];
  164. }];
  165. }
  166. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  167. return 1;
  168. }
  169. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  170. if(tableView == self.tableView)
  171. {
  172. return self.dataArray.count;
  173. }
  174. else
  175. {
  176. return self.dataArray2.count;
  177. }
  178. }
  179. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  180. // RoomMicManageCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([RoomMicManageCell class]) forIndexPath:indexPath];
  181. BGRoomMicManageCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([BGRoomMicManageCell class]) forIndexPath:indexPath];
  182. cell.delegate = self;
  183. if(tableView == self.tableView)
  184. {
  185. [cell setType:RoomMicManageCellTypeApplyList];
  186. [cell setModel:self.dataArray[indexPath.row]];
  187. }
  188. else
  189. {
  190. [cell setType:RoomMicManageCellTypeManageView];
  191. [cell setModel:self.dataArray2[indexPath.row]];
  192. }
  193. return cell;
  194. }
  195. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  196. return 60;
  197. }
  198. //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  199. // return self.applyLabel;
  200. //}
  201. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  202. return 0.01;
  203. }
  204. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  205. return 0.01;
  206. }
  207. - (UIButton *)backBtn{
  208. if (!_backBtn) {
  209. _backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 70, 50)];
  210. [_backBtn setImage:[UIImage imageNamed:@"back_b"] forState:UIControlStateNormal];
  211. // [_backBtn setTitle:@"返回" forState:UIControlStateNormal];
  212. // [_backBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
  213. // [_backBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  214. [_backBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  215. }
  216. return _backBtn;
  217. }
  218. - (UITableView *)tableView{
  219. if (!_tableView) {
  220. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height - 50) style:UITableViewStylePlain];
  221. // [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([RoomMicManageCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:NSStringFromClass([RoomMicManageCell class])];
  222. [_tableView registerClass:[BGRoomMicManageCell class] forCellReuseIdentifier:NSStringFromClass([BGRoomMicManageCell class])];
  223. _tableView.delegate = self;
  224. _tableView.dataSource = self;
  225. _tableView.backgroundColor = kClearColor;
  226. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  227. }
  228. return _tableView;
  229. }
  230. - (UITableView *)tableView2{
  231. if (!_tableView2) {
  232. _tableView2 = [[UITableView alloc]initWithFrame:CGRectMake(0, 50, self.width, self.height - 50) style:UITableViewStylePlain];
  233. // [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([RoomMicManageCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:NSStringFromClass([RoomMicManageCell class])];
  234. [_tableView2 registerClass:[BGRoomMicManageCell class] forCellReuseIdentifier:NSStringFromClass([BGRoomMicManageCell class])];
  235. _tableView2.delegate = self;
  236. _tableView2.dataSource = self;
  237. _tableView2.backgroundColor = kClearColor;
  238. _tableView2.separatorStyle = UITableViewCellSeparatorStyleNone;
  239. }
  240. return _tableView2;
  241. }
  242. - (NSMutableArray *)dataArray{
  243. if (!_dataArray) {
  244. _dataArray = [NSMutableArray array];
  245. }
  246. return _dataArray;
  247. }
  248. - (NSMutableArray *)dataArray2{
  249. if (!_dataArray2) {
  250. _dataArray2 = [NSMutableArray array];
  251. }
  252. return _dataArray2;
  253. }
  254. - (UIView *)shadowView{
  255. if (!_shadowView) {
  256. _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  257. _shadowView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.4];
  258. _shadowView.userInteractionEnabled = YES;
  259. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
  260. [_shadowView addGestureRecognizer:tap];
  261. }
  262. return _shadowView;
  263. }
  264. - (QMUIButton *)searchBtn{
  265. if (!_searchBtn) {
  266. _searchBtn = [[QMUIButton alloc]initWithFrame:CGRectMake(self.width- 80, 0, 70, 50)];
  267. _searchBtn.imagePosition = QMUIButtonImagePositionRight;
  268. // _searchBtn.backgroundColor = [UIColor colorWithHexString:@"#EDEDED"];
  269. _searchBtn.spacingBetweenImageAndTitle = 30;
  270. [_searchBtn setImage:[UIImage imageNamed:@"seach"] forState:UIControlStateNormal];
  271. [_searchBtn setTitle:@"" forState:UIControlStateNormal];
  272. // _searchBtn.layer.cornerRadius = 17;
  273. _searchBtn.clipsToBounds = YES;
  274. [_searchBtn addTarget:self action:@selector(searchBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  275. }
  276. return _searchBtn;
  277. }
  278. @end