YOUPAIHRAddManagementVC.m 12 KB

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