LogShareVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. //
  2. // LogShareVC.m
  3. // IBOSS
  4. //
  5. // Created by Dongke on 15/11/4.
  6. // Copyright © 2015年 elongtian. All rights reserved.
  7. //
  8. #import "LogShareVC.h"
  9. #import "LogShareTableViewCell.h"
  10. #import "LogShareAndCommentModel.h"
  11. #import "LogShareAndCommentInfoModel.h"
  12. @interface LogShareVC ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>
  13. @property(nonatomic,strong) ASIDownManager *mDownManager;
  14. @property(strong) UISearchBar *searchBar;
  15. @property(strong) UITableView *tableView;
  16. @property (nonatomic,assign)DataSearchState* searchState;
  17. @property(nonatomic,strong) LogShareAndCommentModel *model;
  18. @property(nonatomic,strong) UIBarButtonItem *menuButtonOk;
  19. @property(nonatomic,strong) UIButton *btnOk;
  20. @end
  21. @implementation LogShareVC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.filterArr=[[NSMutableArray alloc]init];
  25. self.searchArr=[[NSMutableArray alloc]init];
  26. self.model=[LogShareAndCommentModel new];
  27. [self.navigationController setNavigationBarHidden:NO];
  28. if (_isPresentViewFlg) {
  29. UIView *vTitle = [[UIView alloc]init];
  30. vTitle.frame = CGRectMake(0, 0, Screen_Width, 44 + rectStatusHeight);
  31. vTitle.backgroundColor = [UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1];
  32. [self.view addSubview:vTitle];
  33. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  34. [button setImage:[UIImage imageNamed:@"icon_back"]
  35. forState:UIControlStateNormal];
  36. [button addTarget:self action:@selector(goBack)
  37. forControlEvents:UIControlEventTouchUpInside];
  38. button.frame = CGRectMake(20, rectStatusHeight + 13, 9, 15);
  39. [vTitle addSubview:button];
  40. UILabel *lblTitle = [[UILabel alloc]init];
  41. lblTitle.frame = CGRectMake(9, rectStatusHeight + 13, Screen_Width-2*9 - 20, 15);
  42. lblTitle.textColor = [UIColor whiteColor];
  43. lblTitle.text = @"请选择";
  44. lblTitle.textAlignment = NSTextAlignmentCenter;
  45. [vTitle addSubview:lblTitle];
  46. _btnOk = [UIButton buttonWithType:UIButtonTypeCustom];
  47. _btnOk.frame = CGRectMake(vTitle.frame.size.width-64, rectStatusHeight + 13,44, 20);
  48. [_btnOk addTarget:self action:@selector(saveData)
  49. forControlEvents:UIControlEventTouchUpInside];
  50. [_btnOk setTitle:@"确定" forState:UIControlStateNormal];
  51. [_btnOk setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  52. _btnOk.enabled=NO;
  53. [vTitle addSubview:_btnOk];
  54. }
  55. else{
  56. self.navigationItem.title=@"请选择";
  57. self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:16]};
  58. self.navigationController.navigationBar.barTintColor = NavigationBarTintColor; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  59. [button setImage:[UIImage imageNamed:@"icon_back"]
  60. forState:UIControlStateNormal];
  61. [button addTarget:self action:@selector(goBack)
  62. forControlEvents:UIControlEventTouchUpInside];
  63. button.frame = CGRectMake(0, 0, 15, 18);
  64. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  65. self.navigationItem.leftBarButtonItem = menuButton;
  66. //保存
  67. _btnOk = [UIButton buttonWithType:UIButtonTypeCustom];
  68. [_btnOk addTarget:self action:@selector(saveData)
  69. forControlEvents:UIControlEventTouchUpInside];
  70. _btnOk.frame = CGRectMake(0, 0, 44, 20);
  71. [_btnOk setTitle:@"确定" forState:UIControlStateNormal];
  72. [_btnOk setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  73. _btnOk.enabled=NO;
  74. _menuButtonOk = [[UIBarButtonItem alloc] initWithCustomView:_btnOk];
  75. self.navigationItem.rightBarButtonItem = _menuButtonOk;
  76. }
  77. self.tableView=[UITableView new];
  78. self.tableView.dataSource=self;
  79. self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  80. self.tableView.delegate=self;
  81. //是否是dismissViewController
  82. if (_isPresentViewFlg) {
  83. self.tableView.frame = CGRectMake(0, 44 + rectStatusHeight, self.view.bounds.size.width, self.view.bounds.size.height - 44 - rectStatusHeight - 1) ;
  84. }
  85. else{
  86. self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-rectNavHeight - rectStatusHeight - 1) ;
  87. }
  88. [self.view addSubview:self.tableView];
  89. //搜索框
  90. self.searchBar=[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
  91. self.searchBar.delegate=self;
  92. self.tableView.tableHeaderView=self.searchBar;
  93. if(_model){
  94. if(![_model isSelectAtLeastOne])
  95. { _btnOk.enabled=NO;
  96. }
  97. else {
  98. _btnOk.enabled=YES;
  99. }
  100. }
  101. self.mDownManager=[[ASIDownManager alloc] init];
  102. self.mDownManager.delegate=self;
  103. self.mDownManager.OnImageDown=@selector(onLoadFinish:);
  104. self.mDownManager.OnImageFail=@selector(onLoadFail:);
  105. [self reloadData];
  106. }
  107. -(void)viewWillAppear:(BOOL)animated{
  108. }
  109. - (void)didReceiveMemoryWarning {
  110. [super didReceiveMemoryWarning];
  111. }
  112. -(void)dealloc{
  113. [self cancel];
  114. }
  115. /**
  116. 高度
  117. @return <#return value description#>
  118. */
  119. - (NSMutableDictionary *)heights{
  120. if (_heights == nil){
  121. _heights = [NSMutableDictionary dictionary];
  122. }
  123. return _heights;
  124. }
  125. #pragma mark - Table view data source cell
  126. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  127. static NSString *CellIdentifier = @"LogShareTableViewCell";
  128. LogShareTableViewCell* cell=(LogShareTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  129. cell=[[LogShareTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  130. LogShareAndCommentInfoModel* infoModel=self.model.shareCommentArr[indexPath.row];
  131. [cell parseInfoModel:infoModel];
  132. cell.delegate=self;
  133. cell.cellIndex= (int)indexPath.row;
  134. BOOL ischeck=infoModel.isChecked;
  135. [cell setCheckBackground:ischeck];
  136. self.heights[@(indexPath.row)]=@(cell.height);
  137. return cell;
  138. }
  139. #pragma mark -Table view data source number
  140. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  141. return _filterArr.count;
  142. }
  143. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
  144. return 200.0;
  145. }
  146. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  147. return [self.heights[@(indexPath.row)] doubleValue];
  148. }
  149. #pragma mark 保存完成
  150. - (void)onLoadFinish:(ASIDownManager *)sender {
  151. NSDictionary *dic = [sender.mWebStr JSONValue];
  152. [self cancel];
  153. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  154. int iStatus = [[dic objectForKey:@"Status"] intValue];
  155. NSString *message=[dic objectForKey:@"Message"];
  156. if (iStatus == 0) {
  157. NSArray * approvArr=[dic objectForKey:@"Result"];
  158. if(approvArr!=nil)
  159. {
  160. [_searchArr removeAllObjects];
  161. [_searchArr addObjectsFromArray:approvArr];
  162. [_filterArr removeAllObjects];
  163. [_filterArr addObjectsFromArray:_searchArr];
  164. if(_searchArr.count==0)
  165. {
  166. [self showAlertViewText:@"未找到匹配结果"];
  167. }
  168. [_model parseShareAndCommentArr:_filterArr ];
  169. [self.tableView reloadData];
  170. }
  171. }
  172. else if(iStatus==ActionResultStatusAuthError
  173. ||iStatus==ActionResultStatusNoLogin
  174. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  175. [self showReLoginDialog:message];
  176. return;
  177. }
  178. else {
  179. [self.tableView reloadData];
  180. [self showAlertViewText:message];
  181. }
  182. }
  183. }
  184. #pragma mark 保存失败
  185. - (void)onLoadFail:(ASIDownManager *)sender {
  186. [self cancel];
  187. [self.tableView reloadData];
  188. [self showAlertViewText:@"加载失败"];
  189. }
  190. #pragma mark 保存完成后
  191. - (void)cancel {
  192. [self stopLoading];
  193. }
  194. #pragma mark 加载数据
  195. -(void)reloadData
  196. {
  197. [self startLoading];
  198. NSString *urlStr = ServerURL;
  199. NSMutableDictionary *dict=[NSMutableDictionary new];
  200. [dict setObject:@"GetDailyRecordReplyAndComment" forKey:@"Action"];
  201. [dict setObject:kkAccountCode forKey:@"AccountCode"];
  202. [dict setObject:kkUserCode forKey:@"UserCode"];
  203. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  204. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  205. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  206. }
  207. #pragma mark 返回
  208. -(void)goBack
  209. {
  210. if (_isPresentViewFlg) {
  211. [self dismissViewControllerAnimated:YES completion:nil];
  212. }else{
  213. [self.navigationController popViewControllerAnimated:YES];
  214. }
  215. }
  216. #pragma mark 保存
  217. -(void)saveData{
  218. if(![_model isSelectAtLeastOne])
  219. {
  220. [self showAlertViewText:@"请选择分享人范围"];
  221. return;
  222. }
  223. if([_tag isEqualToString:@"logAdd"]){
  224. if([self.shareDelegate respondsToSelector:@selector(reShareData:)]){
  225. [self.shareDelegate reShareData:self.model.checkedArr];
  226. }
  227. }
  228. else if([_tag isEqualToString:@"logList"]){
  229. if ([self.shareDelegate respondsToSelector:@selector(selectListItem:)]) {
  230. [self.shareDelegate selectListItem:[self.model checkedArr]];
  231. }
  232. [self.navigationController setNavigationBarHidden:YES];
  233. }
  234. //是否是dismissViewController
  235. if (_isPresentViewFlg) {
  236. [self dismissViewControllerAnimated:YES completion:nil];
  237. }else{
  238. [self.navigationController popViewControllerAnimated:YES];
  239. }
  240. }
  241. #pragma mark cell 回調方法
  242. -(void) btnCheckPressed:(LogShareTableViewCell *)cell
  243. {
  244. BOOL checked = [self.model updateCellChecked:cell.userId];
  245. [cell setCheckBackground:checked];
  246. if(![_model isSelectAtLeastOne])
  247. {
  248. _btnOk.enabled=NO;
  249. }
  250. else {
  251. _btnOk.enabled=YES;
  252. }
  253. }
  254. #pragma mark search bar delegate
  255. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
  256. {
  257. return YES;
  258. }
  259. - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  260. {
  261. return YES;
  262. }
  263. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  264. {
  265. if ([searchText isEqualToString:@""]) {
  266. self.filterArr = _searchArr;
  267. [_model parseShareAndCommentArr:_filterArr ];
  268. [_tableView reloadData];
  269. return;
  270. }
  271. NSString *keyName = @"UserName";
  272. //< 模糊查找
  273. NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", keyName, searchText];
  274. //< 精确查找
  275. // NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K == %@", keyName, searchText];
  276. NSLog(@"predicate %@",predicateString);
  277. NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_searchArr filteredArrayUsingPredicate:predicateString]];
  278. self.filterArr = filteredArray;
  279. [_model parseShareAndCommentArr:_filterArr ];
  280. [_tableView reloadData];
  281. }
  282. @end