BGRoomManagerAddViewController.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. //
  2. // BGRoomManagerAddViewController.m
  3. // UniversalApp
  4. //
  5. // Created by bugu on 2020/3/24.
  6. // Copyright © 2020 voidcat. All rights reserved.
  7. //
  8. #import "BGRoomManagerAddViewController.h"
  9. #import "BGRoomManagerCell.h"
  10. #import "RoomModel.h"
  11. #import "RoomUserInfo.h"
  12. //#import "RoomViewController.h"
  13. //#import "BogoRoomViewController.h"
  14. #import "BGRoomManagerSearchViewController.h"
  15. @interface BGRoomManagerAddViewController ()
  16. @property(nonatomic, strong) NSMutableArray *dataArray;
  17. @property(nonatomic, strong) UILabel *titleLabel;
  18. @property(nonatomic, strong) QMUIButton *searchBtn;
  19. @property ( nonatomic,assign) int has_next;
  20. @property ( nonatomic,assign) int currentPage;
  21. @end
  22. @implementation BGRoomManagerAddViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. self.has_next = 1;
  27. self.title = ASLocalizedString(@"添加管理员");
  28. // self.title = [NSString stringWithFormat:ASLocalizedString(@"添加%@"),self.name];
  29. // [self addNavigationItemWithImageNames:@[@"seach_b"] isLeft:NO target:self action:@selector(rightBtnAction) tags:@[@(1001)]];
  30. [self setUpView];
  31. }
  32. - (void)backBtnClicked
  33. {
  34. [self.navigationController popViewControllerAnimated:YES];
  35. }
  36. - (void)viewWillAppear:(BOOL)animated {
  37. [super viewWillAppear:animated];
  38. [self requestDataWidthPage:_currentPage];
  39. }
  40. - (void)refreshHeader
  41. {
  42. _currentPage = 1;
  43. [self requestDataWidthPage:_currentPage];
  44. }
  45. - (void)refreshFooter
  46. {
  47. [self requestDataWidthPage:_currentPage];
  48. }
  49. - (void)rightBtnAction {
  50. BGRoomManagerSearchViewController * vc = [[BGRoomManagerSearchViewController alloc]init];
  51. vc.name = self.name;
  52. vc.model = self.model;
  53. [self.navigationController pushViewController:vc animated:YES];
  54. }
  55. - (void)searchBtnAction:(QMUIButton *)sender{
  56. [self rightBtnAction];
  57. }
  58. -(void)setUpView{
  59. self.tableView.dataSource = self;
  60. self.tableView.delegate = self;
  61. [self.view addSubview:self.tableView];
  62. self.tableView.frame = self.view.bounds;
  63. self.tableView.height = kScreenH - kTopHeight;
  64. self.tableView.backgroundColor = [UIColor clearColor];
  65. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  66. self.tableView.mj_header = nil;
  67. self.tableView.mj_footer = nil;
  68. [self.tableView registerClass:[BGRoomManagerCell class] forCellReuseIdentifier:NSStringFromClass([BGRoomManagerCell class])];
  69. UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 100)];
  70. self.tableView.tableHeaderView = view;
  71. [BGMJRefreshManager refresh:self.self.tableView target:self headerRereshAction:@selector(refreshHeader) footerRereshAction:@selector(refreshFooter)];
  72. UILabel * titleLabel = ({
  73. UILabel * label = [[UILabel alloc]init];
  74. label.textColor = kAppGrayColor2;
  75. label.font = [UIFont systemFontOfSize:15];
  76. // label.text = @"Title";
  77. label.textAlignment = NSTextAlignmentCenter;
  78. label;
  79. });
  80. [view addSubview:titleLabel];
  81. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.mas_equalTo(20);
  83. make.top.mas_equalTo(15);
  84. }];
  85. self.titleLabel = titleLabel;
  86. [self.view addSubview:self.searchBtn];
  87. [self.searchBtn setTitle:ASLocalizedString(@"搜索用户ID/昵称") forState:UIControlStateNormal];
  88. [self.searchBtn setTitleColor:[UIColor colorWithHexString:@"#CCCCCC"] forState:UIControlStateNormal];
  89. self.searchBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  90. [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.mas_equalTo(20);
  92. make.centerX.mas_equalTo(0);
  93. make.top.equalTo(titleLabel.mas_bottom).offset(18);
  94. make.height.mas_equalTo(33);
  95. }];
  96. }
  97. - (void)requestDataWidthPage:(int)page {
  98. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  99. [dict setValue:@"voice" forKey:@"ctl"];
  100. [dict setValue:@"audience_list_2405" forKey:@"act"];
  101. [dict setValue:SafeStr(self.model.room_id) forKey:@"room_id"];
  102. [dict setValue:@(page) forKey:@"page"];
  103. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  104. //搜索页面返回 应刷新数据源
  105. if(self.currentPage == 1)
  106. {
  107. [self.dataArray removeAllObjects];
  108. }
  109. NSArray *list = responseJson[@"data"][@"list"];
  110. if(list.count)
  111. {
  112. for (NSDictionary *dict in list) {
  113. RoomUserInfo *info = [RoomUserInfo mj_objectWithKeyValues:dict];
  114. if(info.is_room_administrator.intValue == 2)
  115. {
  116. //不需要添加房主
  117. }
  118. else
  119. {
  120. [self.dataArray addObject:info];
  121. }
  122. }
  123. [BGMJRefreshManager endRefresh:self.tableView];
  124. self.currentPage++;
  125. }
  126. else
  127. {
  128. [BGMJRefreshManager endRefresh:self.tableView];
  129. }
  130. [self.tableView reloadData];
  131. } FailureBlock:^(NSError *error) {
  132. }];
  133. }
  134. - (void)requestDataHost {
  135. __weak __typeof(self)weakSelf = self;
  136. //http://www.bogo.voice.broadcast/mapi/public/index.php/api/Voice_api/sel_voice_administrator
  137. // NSString *url = [[CYURLUtils sharedCYURLUtils] makeVoiceURLWithC:@"voice_additional_api" A:@"voice_user_list"];
  138. //
  139. // [CYNET POSTv2:url parameters:@{@"voice_id":self.model.voice.user_id} responseCache:^(id responseObject) {
  140. // //do nothing
  141. // } success:^(id responseObject) {
  142. // if ([[responseObject objectForKey:@"code"] integerValue] == 1) {
  143. // __strong __typeof(weakSelf)strongSelf = weakSelf;
  144. // //搜索页面返回 应刷新数据源
  145. // [strongSelf.dataArray removeAllObjects];
  146. // for (NSDictionary *dict in responseObject[@"userlist"]) {
  147. // RoomUserInfo *info = [RoomUserInfo mj_objectWithKeyValues:dict];
  148. // [strongSelf.dataArray addObject:info];
  149. // }
  150. // [strongSelf.titleLabel setText:[NSString stringWithFormat:ASLocalizedString(@"当前房间在线用户(%ld人)"),strongSelf.dataArray.count]];
  151. //
  152. // [strongSelf.tableView reloadData];
  153. // }
  154. // } failure:^(NSString *error) {
  155. // [[BGHUDHelper sharedInstance] tipMessage:error];
  156. // } hasCache:NO];
  157. }
  158. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  159. return 1;
  160. }
  161. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  162. return self.dataArray.count;
  163. }
  164. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  165. return 80;
  166. }
  167. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  168. BGRoomManagerCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([BGRoomManagerCell class]) forIndexPath:indexPath];
  169. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  170. RoomUserInfo *info = self.dataArray[indexPath.row];
  171. if(info.is_room_administrator.intValue == 1)
  172. {
  173. cell.cellType = RoomManagerCellTypeCancel;
  174. }
  175. else
  176. {
  177. cell.cellType = RoomManagerCellTypeAdd;
  178. }
  179. cell.info = info;
  180. __weak __typeof(self)weakSelf = self;
  181. cell.addActionBlock = ^{
  182. __strong __typeof(weakSelf)strongSelf = weakSelf;
  183. [strongSelf addManagerWithInfo:info];
  184. };
  185. cell.cancelActionBlock = ^{
  186. __strong __typeof(weakSelf)strongSelf = weakSelf;
  187. [strongSelf addManagerWithInfo:info];
  188. };
  189. return cell;
  190. }
  191. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  192. }
  193. - (void)addManagerWithInfo:(RoomUserInfo *)info {
  194. __weak __typeof(self)weakSelf = self;
  195. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  196. [dict setValue:@"user" forKey:@"ctl"];
  197. [dict setValue:@"set_admin" forKey:@"act"];
  198. [dict setValue:SafeStr(info.user_id) forKey:@"to_user_id"];
  199. //0用户,1管理员,2主播
  200. if(info.is_room_administrator.intValue == 1)
  201. {
  202. [dict setValue:@"2" forKey:@"status"];
  203. }
  204. else if(info.is_room_administrator.intValue == 0)
  205. {
  206. [dict setValue:@"1" forKey:@"status"];
  207. }
  208. else
  209. {
  210. return;
  211. }
  212. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  213. if ([responseJson toInt:@"status"] == 1)
  214. {
  215. [self refreshHeader];
  216. }
  217. else
  218. {
  219. [[BGHUDHelper sharedInstance] tipMessage:responseJson[@"error"]];
  220. }
  221. } FailureBlock:^(NSError *error) {
  222. }];
  223. }
  224. - (NSMutableArray *)dataArray{
  225. if (!_dataArray) {
  226. _dataArray = [NSMutableArray array];
  227. }
  228. return _dataArray;
  229. }
  230. - (QMUIButton *)searchBtn{
  231. if (!_searchBtn) {
  232. _searchBtn = [[QMUIButton alloc]initWithFrame:CGRectZero];
  233. _searchBtn.imagePosition = QMUIButtonImagePositionLeft;
  234. _searchBtn.backgroundColor = [UIColor colorWithHexString:@"#F0F0F0"];
  235. _searchBtn.spacingBetweenImageAndTitle = 30;
  236. [_searchBtn setImage:[UIImage imageNamed:@"seach_s"] forState:UIControlStateNormal];
  237. [_searchBtn setTitle:@"" forState:UIControlStateNormal];
  238. _searchBtn.layer.cornerRadius = 16.5;
  239. _searchBtn.clipsToBounds = YES;
  240. [_searchBtn addTarget:self action:@selector(searchBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  241. }
  242. return _searchBtn;
  243. }
  244. /*
  245. #pragma mark - Navigation
  246. // In a storyboard-based application, you will often want to do a little preparation before navigation
  247. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  248. // Get the new view controller using [segue destinationViewController].
  249. // Pass the selected object to the new view controller.
  250. }
  251. */
  252. @end