YOUPAIHRPersonnelManagementVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. //
  2. // YOUPAIHRGuildCenterSearchVC.m
  3. // VQU
  4. //
  5. // Created by xiaohaoran on 2021/11/3.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRPersonnelManagementVC.h"
  9. #import "YOUPAIHRPersonnelManagementCell.h"
  10. #import "YOUPAIHRGuildCenterDetailVC.h"
  11. #import "UIScrollView+LZRefresh.h"
  12. #import "YOUPAIHRPersonnelManagementModel.h"
  13. #import "YOUPAIHRAddManagementVC.h"
  14. #import "BRPickerView.h"
  15. @interface YOUPAIHRPersonnelManagementVC ()<UISearchBarDelegate,UITableViewDelegate,UITableViewDataSource>
  16. @property(nonatomic,strong)UISearchBar* youpaipsearchBar;
  17. @property(nonatomic,strong)UITableView *youpaiptableView;
  18. @property (nonatomic, strong) NSMutableArray *youpaipdataSource;
  19. @property (nonatomic, assign) NSInteger youpaipselectIndex;
  20. @end
  21. @implementation YOUPAIHRPersonnelManagementVC
  22. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  23. [self.view endEditing:YES];
  24. }
  25. -(void)viewWillAppear:(BOOL)animated{
  26. [super viewWillAppear:animated];
  27. [self youpaifgetData];
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. self.title = @"人员管理";
  32. [self youpaifsetSearchUI];
  33. [self youpaiptableView];
  34. [self youpaifsetRightBtn];
  35. }
  36. -(void)youpaifgetData{
  37. @weakify(self);
  38. [LCHttpHelper requestWithURLString:ChatRoom_ManManagementList parameters:@{@"usercode":self.youpaipsearchBar.text,@"room_id":@(self.youpaiproom_id)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  39. @strongify(self);
  40. NSDictionary* dict = (NSDictionary*)responseObject;
  41. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  42. if (code == 0) {//成功
  43. if (self.youpaipdataSource!= nil) {
  44. [self.youpaipdataSource removeAllObjects];
  45. }
  46. NSArray <YOUPAIHRPersonnelManagementModel *>*list = [YOUPAIHRPersonnelManagementModel mj_objectArrayWithKeyValuesArray:dict[@"data"]];
  47. [self.youpaipdataSource addObjectsFromArray:list];
  48. [self.youpaiptableView reloadData];
  49. if (self.youpaipdataSource.count != 0) {
  50. [self.youpaiptableView lz_hideEmptyView];
  51. }else{
  52. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"未搜索到相关结果~"];
  53. }
  54. }
  55. } failure:^(NSError *error) {
  56. }];
  57. }
  58. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  59. [searchBar resignFirstResponder];
  60. //判断空格
  61. if ([[searchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]length]==0) {
  62. searchBar.text = @"";
  63. }else{
  64. @weakify(self);
  65. [LCHttpHelper requestWithURLString:ChatRoom_ManManagementList parameters:@{@"usercode":searchBar.text,@"room_id":@(self.youpaiproom_id)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  66. @strongify(self);
  67. NSDictionary* dict = (NSDictionary*)responseObject;
  68. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  69. if (code == 0) {//成功
  70. if (self.youpaipdataSource!= nil) {
  71. [self.youpaipdataSource removeAllObjects];
  72. }
  73. NSArray <YOUPAIHRPersonnelManagementModel *>*list = [YOUPAIHRPersonnelManagementModel mj_objectArrayWithKeyValuesArray:dict[@"data"]];
  74. [self.youpaipdataSource addObjectsFromArray:list];
  75. [self.youpaiptableView reloadData];
  76. if (self.youpaipdataSource.count != 0) {
  77. [self.youpaiptableView lz_hideEmptyView];
  78. }else{
  79. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"];
  80. }
  81. }
  82. } failure:^(NSError *error) {
  83. }];
  84. }
  85. }
  86. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
  87. NSLog(@"%@",searchText);
  88. NSLog(@"%@",searchBar.text);
  89. if ([searchBar.text isEqualToString:@""]) {
  90. [self youpaifgetData];
  91. }else{
  92. NSLog(@"aaa");
  93. }
  94. }
  95. -(void)youpaifsetRightBtn{
  96. // 退出
  97. UIButton *rightBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
  98. rightBtn.frame = CGRectMake(0, 0, 60, 22);
  99. UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
  100. [rightBtn setTitle:@"添加管理" forState:UIControlStateNormal];
  101. [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  102. [rightBtn addTarget:self action:@selector(addManageAction) forControlEvents:(UIControlEventTouchUpInside)];
  103. self.navigationItem.rightBarButtonItem = right;
  104. rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  105. }
  106. -(void)addManageAction{
  107. YOUPAIHRAddManagementVC *vc = [YOUPAIHRAddManagementVC new];
  108. vc.youpaiproom_id = self.youpaiproom_id;
  109. [self.navigationController pushViewController:vc animated:YES];
  110. }
  111. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  112. }
  113. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  114. return 68;
  115. }
  116. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  117. return self.youpaipdataSource.count;
  118. }
  119. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  120. YOUPAIHRPersonnelManagementCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HRPersonnelManagementID" forIndexPath:indexPath];;
  121. if (cell == nil) {
  122. cell = [[YOUPAIHRPersonnelManagementCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HRPersonnelManagementID"];
  123. }
  124. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  125. cell.backgroundColor = LCBkgColor;
  126. YOUPAIHRPersonnelManagementModel *model = self.youpaipdataSource[indexPath.row];
  127. cell.youpaipmodel = model;
  128. @weakify(self);
  129. [cell setYoupaipdidClickBlock:^(YOUPAIHRPersonnelManagementModel * _Nonnull model) {
  130. @strongify(self);
  131. [self youpaifclearStatus:model];
  132. }];
  133. return cell;
  134. }
  135. //解除
  136. -(void)youpaifclearStatus:(YOUPAIHRPersonnelManagementModel*)model{
  137. NSString *youpaipIDStr;
  138. if ([model.youpaipidentity isEqualToString:@"host"]) {
  139. youpaipIDStr = @"主持";
  140. }else if ([model.youpaipidentity isEqualToString:@"manager"]){
  141. youpaipIDStr = @"管理";
  142. }
  143. NSMutableArray *actionArray = [NSMutableArray new];
  144. @weakify(self);
  145. ZCAlertAction* action = [ZCAlertAction actionWithTitle:[NSString stringWithFormat:@"解除%@身份",youpaipIDStr] andblock:^{//删除动态
  146. @strongify(self);
  147. [LCHttpHelper requestWithURLString:ChatRoom_UpdateManManagement parameters:@{@"usercode":model.youpaipusercode,@"room_id":@(self.youpaiproom_id),@"is_set":@(1),@"identity":model.youpaipidentity} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  148. NSDictionary* dict = (NSDictionary*)responseObject;
  149. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  150. if (code == 0) {//成功
  151. [self youpaifgetData];
  152. }
  153. } failure:^(NSError *error) {
  154. }];
  155. }];
  156. [actionArray addObject:action];
  157. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:actionArray];
  158. alertSheet.alertWindow.hidden = NO;
  159. [alertSheet show];
  160. }
  161. - (void)youpaifsetSearchUI{
  162. UIView *bgSearchView = [UIView new];
  163. [self.view addSubview:bgSearchView];
  164. [bgSearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  165. make.left.mas_equalTo(0);
  166. make.right.mas_equalTo(0);
  167. make.top.mas_equalTo(NavBarHeight+8);
  168. make.height.mas_equalTo(44);
  169. }];
  170. bgSearchView.backgroundColor = LCBkgColor;
  171. UISearchBar* search = [[UISearchBar alloc]initWithFrame:CGRectZero];
  172. [bgSearchView addSubview:search];
  173. [search mas_makeConstraints:^(MASConstraintMaker *make) {
  174. make.left.mas_equalTo(0);
  175. make.width.mas_equalTo(KScreenWidth-70);
  176. make.top.mas_equalTo(0);
  177. make.bottom.mas_equalTo(0);
  178. }];
  179. [search setImage:[UIImage imageNamed:@"vqu_images_H_search_icon"]
  180. forSearchBarIcon:UISearchBarIconSearch
  181. state:UIControlStateNormal];
  182. // search.tintColor = ZYPinkColor;
  183. search.backgroundImage = [UIImage imageWithColor:LCBkgColor size:CGSizeMake(KScreenWidth-70, 44)];
  184. [search setSearchFieldBackgroundImage:[UIImage imageWithColor:HexColorFromRGB(0x4F4B5B) size:CGSizeMake(KScreenWidth-70, 38.0f)] forState:UIControlStateNormal];
  185. // search.searchTextField.clearButtonMode = UITextFieldViewModeAlways;
  186. UITextField *searchField = [search valueForKey:@"searchField"];
  187. if (searchField) {
  188. searchField.frame = CGRectMake(16,8,search.frame.size.width-16,38);
  189. [searchField setBackgroundColor:HexColorFromRGB(0x4F4B5B)];
  190. searchField.layer.cornerRadius = 19.0f;
  191. searchField.layer.masksToBounds = YES;
  192. searchField.font = LCFont(14);
  193. searchField.textColor = [UIColor whiteColor];
  194. NSMutableAttributedString* placeholder = [[NSMutableAttributedString alloc]initWithString:@"搜索管理&主持ID"];
  195. [placeholder addAttribute:NSFontAttributeName value:LCFont(14) range:NSMakeRange(0, placeholder.length)];
  196. [placeholder addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x6C6B70) range:NSMakeRange(0, placeholder.length)];
  197. searchField.attributedPlaceholder = placeholder;
  198. searchField.clearButtonMode = UITextFieldViewModeAlways;
  199. }
  200. search.delegate = self;
  201. self.youpaipsearchBar = search;
  202. //取消
  203. UIButton *cancelBtn = [UIButton new];
  204. [bgSearchView addSubview:cancelBtn];
  205. [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  206. make.left.mas_equalTo(search.mas_right);
  207. make.right.mas_equalTo(0);
  208. make.top.mas_equalTo(0);
  209. make.bottom.mas_equalTo(0);
  210. }];
  211. [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
  212. [cancelBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal];
  213. [cancelBtn addTarget:self action:@selector(youpaifcancelButtonClick) forControlEvents:UIControlEventTouchUpInside];
  214. }
  215. -(UITableView *)youpaiptableView{
  216. if (_youpaiptableView == nil) {
  217. _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  218. [self.view addSubview:_youpaiptableView];
  219. [_youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) {
  220. make.top.mas_equalTo(44+8+NavBarHeight);
  221. make.left.mas_equalTo(0);
  222. make.right.mas_equalTo(0);
  223. make.bottom.mas_equalTo(-SafeHeight);
  224. }];
  225. _youpaiptableView.delegate = self;
  226. _youpaiptableView.dataSource = self;
  227. _youpaiptableView.backgroundColor = [UIColor clearColor];
  228. _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  229. _youpaiptableView.showsVerticalScrollIndicator = NO;
  230. _youpaiptableView.showsHorizontalScrollIndicator = NO;
  231. if (@available(iOS 15.0, *)) {
  232. _youpaiptableView.sectionHeaderTopPadding = 0;
  233. }
  234. [_youpaiptableView registerClass:[YOUPAIHRPersonnelManagementCell class] forCellReuseIdentifier:@"HRPersonnelManagementID"];
  235. }
  236. return _youpaiptableView;
  237. }
  238. -(void)youpaifcancelButtonClick{
  239. [self.youpaipsearchBar resignFirstResponder];
  240. if (self.youpaipsearchBar.text.length>0) {
  241. self.youpaipsearchBar.text = @"";
  242. }else{
  243. [self.navigationController popViewControllerAnimated:YES];
  244. }
  245. }
  246. -(NSMutableArray *)youpaipdataSource{
  247. if (_youpaipdataSource == nil) {
  248. _youpaipdataSource = [NSMutableArray new];
  249. }
  250. return _youpaipdataSource;
  251. }
  252. @end