ManagerViewController.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //
  2. // ManagerViewController.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 16/5/31.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "ManagerViewController.h"
  9. #import "managerModel.h"
  10. #import "FollowerTableViewCell.h"
  11. #import "SenderModel.h"
  12. @interface ManagerViewController ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (strong, nonatomic) NSMutableArray *dataArray;
  14. @property (strong, nonatomic) UITableView *tableView;
  15. @property (assign, nonatomic) int has_admin;
  16. @property (strong, nonatomic) UILabel *headLabel;
  17. @property (assign, nonatomic) int cur_num;
  18. @property (assign, nonatomic) int max_num;
  19. @end
  20. @implementation ManagerViewController
  21. - (void)viewDidLoad
  22. {
  23. [super viewDidLoad];
  24. }
  25. - (void)initFWUI
  26. {
  27. [super initFWUI];
  28. self.dataArray = [[NSMutableArray alloc]init];
  29. self.view.backgroundColor = kBackGroundColor;
  30. self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(buttonClick) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  31. self.navigationItem.title = ASLocalizedString(@"管理员列表");
  32. self.headLabel = [[UILabel alloc]initWithFrame:CGRectMake(kRealValue(15), 0, kScreenW, 40)];
  33. self.headLabel.backgroundColor = kBackGroundColor;
  34. // self.headLabel.textAlignment = NSTextAlignmentCe;
  35. self.headLabel.text = @"(0/0)";
  36. self.headLabel.font = [UIFont systemFontOfSize:14];
  37. self.headLabel.textColor = kAppGrayColor1;
  38. [self.view addSubview:self.headLabel];
  39. UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, self.headLabel.bottom, kScreenW, kRealValue(10))];
  40. line.backgroundColor = [UIColor groupTableViewBackgroundColor];
  41. [self.view addSubview:line];
  42. self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, line.bottom, kScreenW, kScreenH - line.bottom)];
  43. self.tableView.backgroundColor = kBackGroundColor;
  44. self.tableView.dataSource = self;
  45. self.tableView.delegate = self;
  46. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  47. [self.tableView registerNib:[UINib nibWithNibName:@"FollowerTableViewCell" bundle:nil] forCellReuseIdentifier:@"FollowerTableViewCell"];
  48. [self.view addSubview:self.tableView];
  49. [BGMJRefreshManager refresh:self.tableView target:self headerRereshAction:@selector(loadNetData) footerRereshAction:nil];
  50. }
  51. - (void)initFWData
  52. {
  53. [super initFWData];
  54. [self loadNetData];
  55. }
  56. - (void)loadNetData
  57. {
  58. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  59. [parmDict setObject:@"user" forKey:@"ctl"];
  60. [parmDict setObject:@"user_admin" forKey:@"act"];
  61. FWWeakify(self)
  62. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  63. {
  64. FWStrongify(self)
  65. if ([responseJson toInt:@"status"] == 1)
  66. {
  67. [self.dataArray removeAllObjects];
  68. self.cur_num = [responseJson toInt:@"cur_num"];
  69. self.max_num = [responseJson toInt:@"max_num"];
  70. self.headLabel.text = [NSString stringWithFormat:ASLocalizedString(@"当前管理员(%d/%d)"),self.cur_num,self.max_num];
  71. NSArray *array = [responseJson objectForKey:@"list"];
  72. if (array.count > 0)
  73. {
  74. for (NSMutableDictionary *dict in array)
  75. {
  76. SenderModel *sModel = [SenderModel mj_objectWithKeyValues:dict];
  77. [self.dataArray addObject:sModel];
  78. }
  79. }
  80. [self.tableView reloadData];
  81. }
  82. [BGMJRefreshManager endRefresh:self.tableView];
  83. } FailureBlock:^(NSError *error)
  84. {
  85. FWStrongify(self)
  86. [BGMJRefreshManager endRefresh:self.tableView];
  87. }];
  88. }
  89. - (void)buttonClick
  90. {
  91. [self.navigationController popViewControllerAnimated:YES];
  92. }
  93. #pragma mark -UITableViewDelegate&UITableViewDataSource
  94. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  95. {
  96. return 1;
  97. }
  98. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  99. {
  100. return self.dataArray.count;
  101. }
  102. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  103. {
  104. //通过复用id(reusedID)来寻找,只有同种类型的cell才能算找到
  105. FollowerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FollowerTableViewCell"];
  106. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  107. if (self.dataArray.count > 0)
  108. {
  109. SenderModel *model = self.dataArray[indexPath.section];
  110. [cell creatCellWithModel:model WithRow:(int)indexPath.section];
  111. // cell.rightImgView.hidden = YES;
  112. cell.joinBtn.hidden = YES;
  113. cell.lineView.hidden = NO;
  114. }
  115. if (self.dataArray.count-1 == indexPath.section)
  116. {
  117. cell.lineView.hidden = YES;
  118. }
  119. return cell;
  120. }
  121. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  122. {
  123. return 65*kAppRowHScale;
  124. }
  125. //删除操作,需要两个代理方法配合使用
  126. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  127. {
  128. if (editingStyle == UITableViewCellEditingStyleDelete)
  129. {
  130. SenderModel *model = self.dataArray[indexPath.section];
  131. NSMutableDictionary *dictM = [[NSMutableDictionary alloc]init];
  132. [dictM setObject:@"user" forKey:@"ctl"];
  133. [dictM setObject:@"set_admin" forKey:@"act"];
  134. if (model.user_id)
  135. {
  136. [dictM setObject:model.user_id forKey:@"to_user_id"];
  137. }
  138. FWWeakify(self)
  139. [self.httpsManager POSTWithParameters:dictM SuccessBlock:^(NSDictionary *responseJson)
  140. {
  141. FWStrongify(self)
  142. self.has_admin = [responseJson toInt:@"has_admin"];
  143. if ([responseJson toInt:@"status"] == 1)
  144. {
  145. if (self.has_admin == 0)
  146. {
  147. self.cur_num = self.cur_num-1;
  148. self.headLabel.text = [NSString stringWithFormat:ASLocalizedString(@"当前管理员(%d/%d)"),self.cur_num,self.max_num];
  149. [self.dataArray removeObjectAtIndex:indexPath.section];
  150. [self.tableView reloadData];
  151. [FanweMessage alert:ASLocalizedString(@"取消管理员成功")];
  152. }
  153. }
  154. } FailureBlock:^(NSError *error)
  155. {
  156. [FanweMessage alert:ASLocalizedString(@"管理员设置失败,请重新操作")];
  157. }];
  158. }
  159. }
  160. //返回编辑类型.是增加还是删除
  161. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  162. {
  163. return UITableViewCellEditingStyleDelete;
  164. }
  165. @end