WD_DetailVC.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. //
  2. // WD_Detail_baseVC.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/6/6.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "WD_DetailVC.h"
  9. #import "WD_DetailCell.h"
  10. #import "MJRefresh.h"
  11. #import "NSArray+ex.h"
  12. #import "NSString+ex.h"
  13. #import "WD_Detail_ShenHe.h"
  14. #import "WD_DetailSchCell.h"
  15. #import "WD_DetailCoaCell.h"
  16. #import "WD_DetailCarCell.h"
  17. #import "WD_DetailDevCell.h"
  18. #import "WD_DetailChangeCell.h"
  19. #import "SchoolDetail.h"
  20. #import "CoachDetail.h"
  21. #import "CarDetail.h"
  22. @interface WD_DetailVC ()
  23. {
  24. //记录页书
  25. NSInteger _currentPageNum;
  26. //加载数据的类型
  27. MyGetDataType _getDataType;
  28. //缓存高度
  29. NSMutableArray * _heightArr;
  30. //审核驾校
  31. NSMutableArray *_selectedIndexPathes;//记录选中的cell
  32. UIButton * _notifyBtn;
  33. UIButton *_allBtn;
  34. UIButton *_cancelBtn;
  35. }
  36. @end
  37. @implementation WD_DetailVC
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  41. CGRect frame = self.tableView.frame;
  42. self.tableView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
  43. _currentPageNum = 0;
  44. _getDataType = MyGetDataTypeNomal;
  45. _selectedIndexPathes = [[NSMutableArray alloc] init];
  46. //审核按钮
  47. NSArray * shenheArr = @[@"3",@"4",@"5",@"6"];
  48. if ([shenheArr containsObject:self.type]) {
  49. [self createSelectBtn];
  50. [self setRefreshAction];//设置刷新
  51. }
  52. [self getData];
  53. __weak typeof(self) weakSelf = self;
  54. self.block = ^{
  55. _currentPageNum = 0;
  56. [weakSelf getData];
  57. };
  58. }
  59. #pragma mark - 审核相关
  60. -(void)createSelectBtn{
  61. _notifyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  62. _notifyBtn.backgroundColor = COLOR_THEME;
  63. _notifyBtn.frame = CGRectMake(kSize.width-80, kSize.height-90-kNavOffSet, 60, 60);
  64. [_notifyBtn setTitle:@"审核" forState:UIControlStateNormal];
  65. [_notifyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  66. _notifyBtn.titleLabel.numberOfLines = 0;
  67. _notifyBtn.layer.masksToBounds = YES;
  68. _notifyBtn.layer.cornerRadius = 30;
  69. [_notifyBtn addTarget:self action:@selector(notifiBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  70. _notifyBtn.hidden = YES;
  71. [self.view addSubview:_notifyBtn];
  72. [self.view bringSubviewToFront:self.holderV];
  73. }
  74. -(void)notifiBtnClick:(UIButton *)sender{
  75. if (self.dataurce.count == 0) {
  76. return;
  77. }
  78. if (!self.tableView.editing) {
  79. [self.tableView setEditing:YES];//进入编辑模式
  80. [self removeRefreshAction];
  81. [sender setTitle:@"提交\n审核" forState:UIControlStateNormal];
  82. CGRect frame = sender.frame;;
  83. _allBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  84. _allBtn.backgroundColor = [UIColor lightGrayColor];
  85. //_allBtn.backgroundColor = COLOR_THEME;
  86. _allBtn.frame = CGRectMake(frame.origin.x + 30, frame.origin.y, 0, 30);
  87. [_allBtn setTitle:@"全选" forState:UIControlStateNormal];
  88. [_allBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  89. [_allBtn setTitleColor:COLOR_THEME forState:UIControlStateSelected];
  90. [_allBtn addTarget:self action:@selector(allClick:) forControlEvents:UIControlEventTouchUpInside];
  91. [self.view addSubview:_allBtn];
  92. _cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  93. _cancelBtn.backgroundColor = [UIColor lightGrayColor];
  94. _cancelBtn.frame = CGRectMake(frame.origin.x + 30, frame.origin.y + 30, 0, 30);
  95. [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
  96. [_cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  97. [_cancelBtn addTarget:self action:@selector(cancelClick:) forControlEvents:UIControlEventTouchUpInside];
  98. [self.view addSubview:_cancelBtn];
  99. [UIView animateWithDuration:.4 animations:^{
  100. _allBtn.frame = CGRectMake(frame.origin.x-100, frame.origin.y - 5, 80, 30);
  101. _cancelBtn.frame = CGRectMake(frame.origin.x-100, frame.origin.y + 35, 80, 30);
  102. }];
  103. return;
  104. }
  105. NSMutableArray * allId = [NSMutableArray new];
  106. for (NSIndexPath *indexPath in _selectedIndexPathes) {
  107. NSString *theKey = @"";
  108. switch ([self.type integerValue]) {
  109. case 3:
  110. theKey = @"TSI_ID";
  111. break;
  112. case 4:
  113. theKey = @"CI_ID";
  114. break;
  115. case 5:
  116. theKey = @"TCO_ID";
  117. break;
  118. case 6:
  119. theKey = @"ID";
  120. break;
  121. default:
  122. break;
  123. }
  124. [allId addObject:self.dataurce[indexPath.row][theKey]];
  125. }
  126. if (allId.count > 0) {
  127. [self.tableView setEditing:NO];
  128. [self setRefreshAction];
  129. [sender setTitle:@"审核" forState:UIControlStateNormal];
  130. [_allBtn removeFromSuperview];
  131. [_cancelBtn removeFromSuperview];
  132. [_selectedIndexPathes removeAllObjects];
  133. [self shenheWithIds:allId];
  134. }else{
  135. [self showMsgByAlertVCWithString:@"请选择驾校"];
  136. }
  137. }
  138. -(void)allClick:(UIButton *)button{
  139. button.selected = !button.selected;
  140. //获取表格视图内容的尺寸
  141. CGSize size = self.tableView.contentSize;
  142. CGRect rect = CGRectMake(0, 0, size.width, size.height);
  143. //获取指定区域的cell的indexPath
  144. NSArray *indexPathes = [self.tableView indexPathsForRowsInRect:rect];
  145. if (button.selected) {
  146. for (NSIndexPath *indexPath in indexPathes) {
  147. //使用代码方式选中一行
  148. [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
  149. }
  150. //更新选中数组
  151. _selectedIndexPathes.array = indexPathes;
  152. } else {
  153. for (NSIndexPath *indexPath in indexPathes) {
  154. //使用代码方式取消选中一行
  155. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  156. }
  157. //清空选中cell的记录数组
  158. [_selectedIndexPathes removeAllObjects];
  159. }
  160. }
  161. - (void)cancelClick:(UIButton *)sender {
  162. [self.tableView setEditing:NO];
  163. [self setRefreshAction];
  164. [_notifyBtn setTitle:@"审核" forState:UIControlStateNormal];
  165. [_allBtn removeFromSuperview];
  166. [_cancelBtn removeFromSuperview];
  167. [_selectedIndexPathes removeAllObjects];
  168. }
  169. -(void)shenheWithIds:(NSArray *)ids{
  170. NSInteger typeId = [self.type integerValue] - 2;
  171. //当前vc self.type
  172. // 1.系统升级公告
  173. // 2电子围栏审核
  174. // 3驾校审核通知
  175. // 4教练审核通知
  176. // 5教练车审核通知
  177. // 6终端审核通知
  178. // 7管理部门下发通知
  179. /* 审核界面 WD_Detail_ShenHe vc.shenheType
  180. 1驾校审核通知
  181. 2教练审核通知
  182. 3教练车审核通知
  183. 4终端审核通知
  184. */
  185. NSString * shenheType = [NSString stringWithFormat:@"%ld",(long)typeId];
  186. WD_Detail_ShenHe *vc = [[WD_Detail_ShenHe alloc]init];
  187. vc.shenheType = shenheType;
  188. vc.ids = ids;
  189. vc.block = ^{
  190. [self headerRefresh];
  191. };
  192. [self.navigationController pushViewController:vc animated:YES];
  193. }
  194. #pragma mark - 下拉刷新,上拉加载 -
  195. -(void)setRefreshAction{
  196. // 下拉加载更多
  197. __weak typeof(self) weakSelf = self;
  198. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  199. [weakSelf headerRefresh];
  200. }];
  201. self.tableView.mj_header = header;
  202. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  203. [weakSelf footerRefresh];
  204. }];
  205. self.tableView.mj_footer = footer;
  206. }
  207. -(void)headerRefresh{
  208. //设置获取数据的方式
  209. _getDataType=MyGetDataTypeHeaderRefresh;
  210. //加载数据
  211. [self getData];
  212. [self.tableView.mj_header endRefreshing];
  213. }
  214. -(void)footerRefresh{
  215. //设置获取数据的方式
  216. _getDataType=MyGetDataTypeFooterRefresh;
  217. //加载数据
  218. [self getData];
  219. [self.tableView.mj_footer endRefreshing];
  220. }
  221. -(void)removeRefreshAction{
  222. self.tableView.mj_header = nil;
  223. self.tableView.mj_footer = nil;
  224. }
  225. -(void)getData{
  226. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  227. if (_IS_LOADING) {
  228. return;
  229. }
  230. _IS_LOADING=YES;
  231. //获取第一页数据
  232. NSInteger needLoadPage;
  233. needLoadPage=_currentPageNum+1;
  234. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  235. needLoadPage=1;
  236. }
  237. //对需要审核的做不同的数据请求
  238. NSArray * questArr = [self getQuestDicAndMethodWithType:self.type page:needLoadPage];
  239. __weak typeof(self) weakSelf = self;
  240. [self getDataWithDic:questArr[0] method:questArr[1] block:^(NSDictionary *successDic) {
  241. //处理数据
  242. if (_getDataType==MyGetDataTypeHeaderRefresh){
  243. [weakSelf.dataurce removeAllObjects];
  244. }
  245. [weakSelf.dataurce addObjectsFromArray:successDic[@"body"]];
  246. if (weakSelf.dataurce.count != 0) {
  247. weakSelf.holderV.hidden = YES;
  248. _notifyBtn.hidden = NO;
  249. }
  250. _currentPageNum=needLoadPage;
  251. [weakSelf.tableView reloadData];
  252. _getDataType=MyGetDataTypeNomal;
  253. }];
  254. }
  255. -(NSArray *)getQuestDicAndMethodWithType:(NSString *)type page:(NSInteger)page{
  256. NSMutableDictionary * mDic = [NSMutableDictionary new];
  257. NSString * method = @"";
  258. // NSString *needLoadPage = [NSString stringWithFormat:@"%ld",(long)page];
  259. switch ([type integerValue]) {
  260. case 3:
  261. {
  262. [mDic setValue:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"];
  263. [mDic setValue:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"];
  264. [mDic setValue:@"" forKey:@"inscode"];//驾校编号
  265. [mDic setValue:@"" forKey:@"jxmc"];
  266. [mDic setValue:@"1" forKey:@"isPage"];
  267. [mDic setValue:@"10" forKey:@"pageSize"];
  268. [mDic setValue:[NSString stringWithFormat:@"%ld",page] forKey:@"currentPage"];
  269. [mDic setValue:@"0" forKey:@"auditStatus"];
  270. method = @"schools";
  271. }
  272. break;
  273. case 4:
  274. {
  275. [mDic setValue:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"];
  276. [mDic setValue:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"];
  277. [mDic setValue:@"" forKey:@"inscode"];
  278. [mDic setValue:@"" forKey:@"coachName"];
  279. [mDic setValue:@"" forKey:@"idcard"];
  280. [mDic setValue:@"1" forKey:@"isPage"];
  281. [mDic setValue:@"10" forKey:@"pageSize"];
  282. [mDic setValue:[NSString stringWithFormat:@"%ld",page] forKey:@"currentPage"];
  283. [mDic setValue:@"0" forKey:@"auditStatus"];
  284. [mDic setValue:@"" forKey:@"phone"];
  285. method = @"coachs";
  286. }
  287. break;
  288. case 5:
  289. {
  290. [mDic setValue:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"];
  291. [mDic setValue:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"];
  292. [mDic setValue:@"" forKey:@"inscode"];
  293. [mDic setValue:@"" forKey:@"licNum"];
  294. [mDic setValue:@"1" forKey:@"isPage"];
  295. [mDic setValue:@"10" forKey:@"pageSize"];
  296. [mDic setValue:[NSString stringWithFormat:@"%ld",page] forKey:@"currentPage"];
  297. [mDic setValue:@"0" forKey:@"auditStatus"];
  298. method = @"cars";
  299. }
  300. break;
  301. case 6:
  302. {
  303. [mDic setValue:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"];
  304. [mDic setValue:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"];
  305. [mDic setValue:@"" forKey:@"inscode"];
  306. [mDic setValue:@"0" forKey:@"auditStatus"];
  307. [mDic setValue:@"1" forKey:@"isPage"];
  308. [mDic setValue:@"10" forKey:@"pageSize"];
  309. [mDic setValue:[NSString stringWithFormat:@"%ld",(long)page] forKey:@"currentPage"];
  310. method = @"devs";
  311. }
  312. break;
  313. default:
  314. {
  315. if ([self.type integerValue] == 1) {
  316. self.type = @"0";
  317. }else if ([self.type integerValue] == 7) {
  318. self.type = @"8";
  319. }
  320. [mDic setObject:MYAPPDELEGATE.userDic[@"id"] forKey:@"userId"];
  321. [mDic setObject:self.type forKey:@"type"];
  322. method = @"getMsgs";
  323. }
  324. break;
  325. }
  326. return @[mDic,method];
  327. }
  328. #pragma mark tableView代理方法
  329. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  330. return self.dataurce.count;
  331. }
  332. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  333. switch ([self.type integerValue]) {
  334. case 3:
  335. {
  336. //驾校
  337. WD_DetailSchCell *cell = [WD_DetailSchCell cellForTableView:tableView];
  338. cell.dic = self.dataurce[indexPath.row];
  339. return cell;
  340. }
  341. break;
  342. case 4:
  343. {
  344. //教练
  345. WD_DetailCoaCell *cell = [WD_DetailCoaCell cellForTableView:tableView];
  346. cell.dic = self.dataurce[indexPath.row];
  347. return cell;
  348. }
  349. break;
  350. case 5:
  351. {
  352. //车辆
  353. WD_DetailCarCell *cell = [WD_DetailCarCell cellForTableView:tableView];
  354. cell.dic = self.dataurce[indexPath.row];
  355. return cell;
  356. }
  357. break;
  358. case 6:
  359. {
  360. //终端
  361. WD_DetailDevCell *cell = [WD_DetailDevCell cellForTableView:tableView];
  362. cell.dic = self.dataurce[indexPath.row];
  363. return cell;
  364. }
  365. break;
  366. default:
  367. {
  368. WD_DetailCell *cell = [WD_DetailCell cellForTableView:tableView];
  369. cell.dic = self.dataurce[indexPath.row];
  370. return cell;
  371. }
  372. break;
  373. }
  374. }
  375. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  376. //需要审核的消息
  377. switch ([self.type integerValue]) {
  378. case 3:
  379. return 140;
  380. break;
  381. case 4:
  382. return 165;
  383. break;
  384. case 5:
  385. return 138;
  386. break;
  387. case 6:
  388. return 165;
  389. break;
  390. default:
  391. break;
  392. }
  393. //不需要审核的消息
  394. //缓存高度
  395. NSNumber *cellHeight = [_heightArr h_safeObjectAtIndex:indexPath.row];
  396. if (cellHeight) {
  397. return [cellHeight floatValue];
  398. }else{
  399. NSDictionary * dic = self.dataurce[indexPath.row];
  400. CGFloat w = self.tableView.frame.size.width-60;
  401. NSString *str = [NSString stringWithFormat:@"%@",dic[@"MI_CONTENT"]];
  402. CGFloat h1 = [str heightForWid:w Font:14] + 5;
  403. NSString *str2 = [NSString stringWithFormat:@"%@",dic[@"MI_TITLE"]];
  404. CGFloat h2 = [str2 heightForWid:w Font:17] + 5;
  405. CGFloat H = 46+h1+h2;//46为其它固定高度
  406. [_heightArr addObject:@(H)];
  407. return H;
  408. }
  409. }
  410. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  411. //普通消息
  412. NSArray * shenheArr = @[@"3",@"4",@"5",@"6"];
  413. if (![shenheArr containsObject:self.type]) {
  414. return;
  415. }
  416. //审核消息
  417. if (self.tableView.editing) {
  418. //当选中cell时,记录其indexPath
  419. if (![_selectedIndexPathes containsObject:indexPath]) {
  420. [_selectedIndexPathes addObject:indexPath];
  421. }
  422. return;
  423. }
  424. switch ([self.type integerValue]) {
  425. case 3:
  426. {
  427. SchoolDetail * vc = [[SchoolDetail alloc]init];
  428. vc.byWillDo = YES;
  429. vc.dataSource = self.dataurce[indexPath.row];
  430. vc.shenheBLock = ^{
  431. [self shenheWithIds:@[self.dataurce[indexPath.row][@"TSI_ID"]]];
  432. };
  433. [self.navigationController pushViewController:vc animated:YES];
  434. }
  435. break;
  436. case 4:
  437. {
  438. CoachDetail * vc = [[CoachDetail alloc]init];
  439. vc.byWillDo = YES;
  440. vc.dataSource = self.dataurce[indexPath.row];
  441. vc.shenheBLock = ^{
  442. [self shenheWithIds:@[self.dataurce[indexPath.row][@"CI_ID"]]];
  443. };
  444. [self.navigationController pushViewController:vc animated:YES];
  445. }
  446. break;
  447. case 5:
  448. {
  449. CarDetail * vc = [[CarDetail alloc]init];
  450. vc.byWillDo = YES;
  451. vc.dataSource = self.dataurce[indexPath.row];
  452. vc.shenheBLock = ^{
  453. [self shenheWithIds:@[self.dataurce[indexPath.row][@"TCO_ID"]]];
  454. };
  455. [self.navigationController pushViewController:vc animated:YES];
  456. }
  457. break;
  458. case 6:
  459. {
  460. [self showMsgByAlertVCWithString:@"点击右下角图标,选择终端进行审核"];
  461. }
  462. break;
  463. default:
  464. break;
  465. }
  466. }
  467. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
  468. //当取消选中cell时,从记录的数组中删除其indexPath
  469. if ([_selectedIndexPathes containsObject:indexPath] && self.tableView.editing) {
  470. [_selectedIndexPathes removeObject:indexPath];
  471. if (_allBtn.selected) {
  472. _allBtn.selected = NO;
  473. }
  474. }
  475. }
  476. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  477. return UITableViewCellEditingStyleInsert |UITableViewCellEditingStyleDelete;
  478. }
  479. - (void)didReceiveMemoryWarning {
  480. [super didReceiveMemoryWarning];
  481. // Dispose of any resources that can be recreated.
  482. }
  483. /*
  484. #pragma mark - Navigation
  485. // In a storyboard-based application, you will often want to do a little preparation before navigation
  486. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  487. // Get the new view controller using [segue destinationViewController].
  488. // Pass the selected object to the new view controller.
  489. }
  490. */
  491. @end