BGRoomManagerViewController.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //
  2. // BGRoomManagerViewController.m
  3. // UniversalApp
  4. //
  5. // Created by bugu on 2020/3/24.
  6. // Copyright © 2020 voidcat. All rights reserved.
  7. //
  8. #import "BGRoomManagerViewController.h"
  9. #import "BGRoomManagerCell.h"
  10. #import "RoomModel.h"
  11. #import "RoomUserInfo.h"
  12. #import "BGRoomManagerAddViewController.h"
  13. #import "UIViewController+Bogo.h"
  14. //#import "BogoRoomViewController.h"
  15. @interface BGRoomManagerViewController ()
  16. @property(nonatomic, strong) UILabel *titleLabel;
  17. @property(nonatomic, strong) NSMutableArray *dataArray;
  18. @end
  19. @implementation BGRoomManagerViewController
  20. - (void)viewWillAppear:(BOOL)animated {
  21. [super viewWillAppear:animated];
  22. [self requestData];
  23. }
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view.
  27. self.title = ASLocalizedString(@"管理员");
  28. //返回按钮
  29. [self addBackButton];
  30. //添加添加按钮
  31. [self addRightButton];
  32. [self setUpView];
  33. }
  34. - (void)addRightButton {
  35. UIBarButtonItem * rightItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"add1 (1)"] style:UIBarButtonItemStylePlain target:self action:@selector(rightBtnAction)];
  36. self.navigationItem.rightBarButtonItem = rightItem;
  37. }
  38. - (void)rightBtnAction {
  39. BGRoomManagerAddViewController * vc = [[BGRoomManagerAddViewController alloc]init];
  40. vc.name = self.name;
  41. vc.model = self.model;
  42. [self.navigationController pushViewController:vc animated:YES];
  43. }
  44. -(void)setUpView{
  45. self.tableView.dataSource = self;
  46. self.tableView.delegate = self;
  47. [self.view addSubview:self.tableView];
  48. self.tableView.frame = self.view.bounds;
  49. self.tableView.height = kScreenH - kTopHeight;
  50. self.tableView.backgroundColor = [UIColor clearColor];
  51. [self.tableView registerClass:[BGRoomManagerCell class] forCellReuseIdentifier:NSStringFromClass([BGRoomManagerCell class])];
  52. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  53. self.tableView.mj_header = nil;
  54. self.tableView.mj_footer = nil;
  55. UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 50)];
  56. // self.tableView.tableHeaderView = view;
  57. UILabel * titleLabel = ({
  58. UILabel * label = [[UILabel alloc]init];
  59. label.textColor = kAppGrayColor2;
  60. label.font = [UIFont systemFontOfSize:15];
  61. // label.text = @"Title";
  62. label.textAlignment = NSTextAlignmentCenter;
  63. label;
  64. });
  65. [view addSubview:titleLabel];
  66. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.mas_equalTo(20);
  68. make.centerY.mas_equalTo(0);
  69. }];
  70. self.titleLabel = titleLabel;
  71. }
  72. - (void)requestData{
  73. __weak __typeof(self)weakSelf = self;
  74. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  75. [dict setValue:@"user" forKey:@"ctl"];
  76. [dict setValue:@"user_admin" forKey:@"act"];
  77. [dict setValue:SafeStr(self.model.room_id) forKey:@"room_id"];
  78. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  79. if ([responseJson toInt:@"status"] == 1)
  80. {
  81. __strong __typeof(weakSelf)strongSelf = weakSelf;
  82. [self.dataArray removeAllObjects];
  83. for (NSDictionary *dict in responseJson[@"list"]) {
  84. RoomUserInfo *info = [RoomUserInfo mj_objectWithKeyValues:dict];
  85. [strongSelf.dataArray addObject:info];
  86. }
  87. // [strongSelf.titleLabel setText:[NSString stringWithFormat:ASLocalizedString(@"%@(%ld人)"),strongSelf.name,strongSelf.dataArray.count ]];
  88. [strongSelf.tableView reloadData];
  89. }
  90. else
  91. {
  92. [[BGHUDHelper sharedInstance] tipMessage:responseJson[@"error"]];
  93. }
  94. } FailureBlock:^(NSError *error) {
  95. }];
  96. //http://www.bogo.voice.broadcast/mapi/public/index.php/api/Voice_api/voice_administrator
  97. // NSString *url = [[CYURLUtils sharedCYURLUtils] makeVoiceURLWithC:@"Voice_api" A:@"voice_administrator"];
  98. //
  99. // if ([self.name isEqualToString:@"主持人"]) {
  100. // url = [[CYURLUtils sharedCYURLUtils] makeVoiceURLWithC:@"voice_additional_api" A:@"voice_host_list"];
  101. //
  102. // }
  103. // [CYNET POSTv2:url parameters:@{@"voice_id":self.model.voice.user_id} responseCache:^(id responseObject) {
  104. // //do nothing
  105. // } success:^(id responseObject) {
  106. // if ([[responseObject objectForKey:@"code"] integerValue] == 1) {
  107. // __strong __typeof(weakSelf)strongSelf = weakSelf;
  108. // [strongSelf.dataArray removeAllObjects];
  109. //
  110. // for (NSDictionary *dict in responseObject[@"list"]) {
  111. // RoomUserInfo *info = [RoomUserInfo mj_objectWithKeyValues:dict];
  112. // [strongSelf.dataArray addObject:info];
  113. // }
  114. //// RoomUserInfo *addInfo = [[RoomUserInfo alloc]init];
  115. //// addInfo.avatar = @"http://temp.fandong.me/add@2x.png";
  116. //// addInfo.user_nickname = @"添加管理员";
  117. //// addInfo.user_id = @"0";
  118. //// [strongSelf.dataArray addObject:addInfo];
  119. //
  120. // [strongSelf.titleLabel setText:[NSString stringWithFormat:ASLocalizedString(@"%@(%ld人)"),strongSelf.name,strongSelf.dataArray.count ]];
  121. //
  122. // [strongSelf.tableView reloadData];
  123. // }
  124. // } failure:^(NSString *error) {
  125. // [[BGHUDHelper sharedInstance] tipMessage:error];
  126. // } hasCache:NO];
  127. }
  128. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  129. return 1;
  130. }
  131. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  132. return self.dataArray.count;
  133. }
  134. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  135. return 80;
  136. }
  137. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  138. BGRoomManagerCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([BGRoomManagerCell class]) forIndexPath:indexPath];
  139. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  140. cell.cellType = RoomManagerCellTypeCancel;
  141. RoomUserInfo *info = self.dataArray[indexPath.row];
  142. cell.info = info;
  143. __weak __typeof(self)weakSelf = self;
  144. cell.cancelActionBlock = ^{
  145. __strong __typeof(weakSelf)strongSelf = weakSelf;
  146. [strongSelf deleteManagerWithInfo:info];
  147. };
  148. return cell;
  149. }
  150. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  151. }
  152. - (void)deleteManagerWithInfo:(RoomUserInfo *)info {
  153. __weak __typeof(self)weakSelf = self;
  154. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  155. [dict setValue:@"user" forKey:@"ctl"];
  156. [dict setValue:@"set_admin" forKey:@"act"];
  157. [dict setValue:SafeStr(info.user_id) forKey:@"to_user_id"];
  158. [dict setValue:@"2" forKey:@"status"];
  159. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  160. if ([responseJson toInt:@"status"] == 1)
  161. {
  162. [self requestData];
  163. }
  164. else
  165. {
  166. [[BGHUDHelper sharedInstance] tipMessage:responseJson[@"error"]];
  167. }
  168. } FailureBlock:^(NSError *error) {
  169. }];
  170. }
  171. - (NSMutableArray *)dataArray{
  172. if (!_dataArray) {
  173. _dataArray = [NSMutableArray array];
  174. }
  175. return _dataArray;
  176. }
  177. /*
  178. #pragma mark - Navigation
  179. // In a storyboard-based application, you will often want to do a little preparation before navigation
  180. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  181. // Get the new view controller using [segue destinationViewController].
  182. // Pass the selected object to the new view controller.
  183. }
  184. */
  185. @end