CheckCourseVC.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. //
  2. // CheckCourseVC.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/4/12.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "CheckCourseVC.h"
  9. #import "CkeckCourceCell.h"
  10. @interface CheckCourseVC ()<UITableViewDelegate,UITableViewDataSource>
  11. {
  12. UITableView *maintableView;
  13. UIButton *allSelectBtn, *moreSelectBtn;
  14. UIView *bottomBar;
  15. UIView *examerView;
  16. UITableView *examertableView;
  17. NSArray *dataArray;
  18. NSArray *examDataArray;
  19. NSString *examerID;
  20. NSMutableArray *sendIdArray;
  21. NSString *subjectString;
  22. HolderView * holderV;
  23. }
  24. @end
  25. @implementation CheckCourseVC
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. self.title = @"学时送审";
  29. self.view.backgroundColor = KBackGroundColor;
  30. if (_isNotification == NO)
  31. {
  32. //正常状态
  33. [self goBackByNavigation];
  34. }
  35. else
  36. {
  37. //推送状态 要将根视图变回去
  38. UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
  39. [backBtn setTintColor:RQMianColor];
  40. [self.navigationItem setLeftBarButtonItem:backBtn];
  41. }
  42. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"选择阶段" style:UIBarButtonItemStyleDone target:self action:@selector(selectSubject)];
  43. self.navigationItem.rightBarButtonItem = item;
  44. [self.navigationItem.rightBarButtonItem setTintColor:RQMianColor];
  45. subjectString = @"1";
  46. dataArray = [NSArray array];
  47. sendIdArray = [NSMutableArray array];
  48. //tableView
  49. maintableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain];
  50. maintableView.height -= kNavOffSet;
  51. maintableView.delegate = self;
  52. maintableView.dataSource = self;
  53. maintableView.rowHeight = 100;
  54. maintableView.estimatedSectionFooterHeight = 0;
  55. [self.view addSubview:maintableView];
  56. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 50)];
  57. view.backgroundColor = KBackGroundColor;
  58. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width/2.0, 50)];
  59. [btn setImage:[UIImage imageNamed:@"pointMark"] withTitle:@"全选" textColor:KContentTextColor Font:Font17 forState:UIControlStateNormal];
  60. [btn setImage:[UIImage imageNamed:@"pointMark_h"] withTitle:@"全选" textColor:RQMianColor Font:Font17 forState:UIControlStateSelected];
  61. [btn target:self Tag:1];
  62. [view addSubview:btn];
  63. allSelectBtn = btn;
  64. btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0, 50)];
  65. [btn setImage:[UIImage imageNamed:@"pointMark"] withTitle:@"多选" textColor:KContentTextColor Font:Font17 forState:UIControlStateNormal];
  66. [btn setImage:[UIImage imageNamed:@"pointMark_h"] withTitle:@"多选" textColor:RQMianColor Font:Font17 forState:UIControlStateSelected];
  67. [btn target:self Tag:2];
  68. [view addSubview:btn];
  69. moreSelectBtn = btn;
  70. maintableView.tableHeaderView = view;
  71. [self setRefresh];
  72. //bottomBar
  73. bottomBar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - kNavOffSet - 50-kSafeAreaBottomHeight, kSize.width, 50)];
  74. bottomBar.backgroundColor = RQMianColor;
  75. [self.view addSubview:bottomBar];
  76. btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width/2.0, 50)];
  77. [btn setTitle:@"批量考核" textColor:KTitleColor font:Font18 fotState:UIControlStateNormal];
  78. [btn target:self Tag:3];
  79. [bottomBar addSubview:btn];
  80. [btn addViewWithRect:CGRectMake(kSize.width/2.0, 0, 1, 50)];
  81. btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0, 50)];
  82. [btn setTitle:@"批量送审" textColor:KTitleColor font:Font18 fotState:UIControlStateNormal];
  83. [btn target:self Tag:4];
  84. [bottomBar addSubview:btn];
  85. bottomBar.hidden = YES;
  86. [self trainTimes];
  87. holderV = [[HolderView alloc]initWithFrame:kFrame];
  88. [holderV freshBlock:^{
  89. [self trainTimes];
  90. }];
  91. [self.view addSubview:holderV];
  92. }
  93. -(void)setRefresh{
  94. __weak typeof(self) weakSelf = self;
  95. MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  96. [weakSelf trainTimes];
  97. }];
  98. maintableView.mj_header = mj_header;
  99. }
  100. -(void)dismissNavgation
  101. {
  102. [myDelegate initHomeVC];
  103. }
  104. - (void)setExamer {
  105. //懒加载 没有的时候就init一个
  106. if (!examerView) {
  107. examerView = [[UIView alloc] initWithFrame:kFrame];
  108. examerView.backgroundColor = windowBlockColor;
  109. examertableView = [[UITableView alloc] initWithFrame:CGRectMake(30, (kSize.height - kNavOffSet - 200)/2.0, kSize.width - 60, 200) style:UITableViewStylePlain];
  110. [examertableView borderCornorRadios:7];
  111. examertableView.backgroundColor = KBackGroundColor;
  112. examertableView.delegate = self;
  113. examertableView.dataSource = self;
  114. [examerView addSubview:examertableView];
  115. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width - 60, 50)];
  116. [label setText:@"请选择考核员" Font:Font18 TextColor:KSubTitleColor Alignment:NSTextAlignmentCenter];
  117. [label addSelfViewWithRect:CGRectMake(10, 48, kSize.width - 80, 2) Color:kLineColor];
  118. examertableView.tableHeaderView = label;
  119. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, examertableView.y + examertableView.height, kSize.width - 60, 40)];
  120. view.backgroundColor = KBackGroundColor;
  121. [examerView addSubview:view];
  122. [view borderCornorRadios:7];
  123. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width/2.0 - 30, 40)];
  124. [btn setTitle:@"取消" textColor:KTitleColor font:Font18 fotState:UIControlStateNormal];
  125. [btn target:self Tag:5];
  126. [view addSubview:btn];
  127. [btn addViewWithRect:CGRectMake(0, 0, kSize.width - 60, 1)];
  128. [btn addViewWithRect:CGRectMake(kSize.width/2.0 - 30, 0, 1, 40)];
  129. btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 - 30, 0, kSize.width/2.0 - 30, 40)];
  130. [btn setTitle:@"确定" textColor:RQMianColor font:Font18 fotState:UIControlStateNormal];
  131. [btn target:self Tag:6];
  132. [view addSubview:btn];
  133. }
  134. examerID = @"";
  135. [self.view addSubview:examerView];
  136. examDataArray = [NSArray array];
  137. [self getTrainExams];
  138. }
  139. #pragma mark Action
  140. - (void)selectSubject {
  141. [RQ_SHARE_FUNCTION showAlertWithTitle:@"请选择培训阶段" message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" otherButtonTitles:@[@"第一阶段",@"第二阶段",@"第三阶段",@"第四阶段"] otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) {
  142. if (selectedOtherButtonIndex != NSNotFound) {
  143. subjectString = [NSString stringWithFormat:@"%ld",(long)selectedOtherButtonIndex + 1];
  144. [self trainTimes];
  145. }
  146. }];
  147. }
  148. - (void)btnClick:(UIButton *)sender {
  149. if (sender.tag == 1) {
  150. allSelectBtn.selected = !allSelectBtn.selected;
  151. if (allSelectBtn.selected == NO) {
  152. [sendIdArray removeAllObjects];
  153. }else {
  154. for (NSDictionary *dic in dataArray) {
  155. if (![sendIdArray containsObject:dic[@"ID"]]) {
  156. [sendIdArray addObject:dic[@"ID"]];
  157. }
  158. }
  159. moreSelectBtn.selected = YES;
  160. [self showBottomBar];
  161. }
  162. [maintableView reloadData];
  163. return;
  164. }
  165. if (sender.tag == 2) {
  166. moreSelectBtn.selected = !moreSelectBtn.selected;
  167. if (moreSelectBtn.selected == NO) {
  168. [sendIdArray removeAllObjects];
  169. allSelectBtn.selected = NO;
  170. [self hideBottomBar];
  171. }else {
  172. [self showBottomBar];
  173. }
  174. [maintableView reloadData];
  175. return;
  176. }
  177. if (sender.tag == 3) {
  178. if (sendIdArray.count < 1) {
  179. ShowMsg(@"请选择待考核学时");
  180. return;
  181. }
  182. [self setExamer];
  183. return;
  184. }
  185. if (sender.tag == 4) {
  186. [self trainSend];
  187. return;
  188. }
  189. if (sender.tag == 5) {
  190. //取消选择考核人
  191. examerID = @"";
  192. [examerView removeFromSuperview];
  193. return;
  194. }
  195. if (sender.tag == 6) {
  196. //选择考核人
  197. if (examerID.length < 1) {
  198. ShowMsg(@"请选择考核人");
  199. return;
  200. }
  201. [examerView removeFromSuperview];
  202. [self trainExamWithExamer:examerID];
  203. return;
  204. }
  205. }
  206. - (void) showBottomBar {
  207. if (bottomBar.isHidden) {
  208. bottomBar.hidden = NO;
  209. maintableView.height -= bottomBar.height;
  210. }
  211. maintableView.mj_header = nil;
  212. }
  213. - (void)hideBottomBar {
  214. if (!bottomBar.isHidden) {
  215. bottomBar.hidden = YES;
  216. maintableView.height += bottomBar.height;
  217. }
  218. [self setRefresh];
  219. }
  220. #pragma mark tableView
  221. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  222. if (tableView == examertableView) {
  223. return examDataArray.count;
  224. }
  225. return dataArray.count;
  226. }
  227. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  228. if (tableView == examertableView) {
  229. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"examCell"];
  230. if (cell == nil) {
  231. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"examCell"];
  232. cell.backgroundColor = KBackGroundColor;
  233. [cell.textLabel setTextAlignment:NSTextAlignmentCenter];
  234. }
  235. NSDictionary *dic = examDataArray[indexPath.row];
  236. cell.textLabel.text = [NSString stringWithFormat:@"%@ %@",dic[@"DQMC"],dic[@"EI_NAME"]];
  237. return cell;
  238. }
  239. CkeckCourceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  240. if (cell == nil) {
  241. cell = [[CkeckCourceCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  242. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  243. }
  244. NSDictionary *dict = dataArray[indexPath.row];
  245. cell.dataDic = dict;
  246. [cell clickSendBtnWithBlock:^(NSString *cellString) {
  247. if (sendIdArray.count > 0) {
  248. [sendIdArray removeAllObjects];
  249. }
  250. [sendIdArray addObject:[[cellString componentsSeparatedByString:@"-"] lastObject]];
  251. NSString *cellType = [[cellString componentsSeparatedByString:@"-"] firstObject];
  252. if ([cellType isEqualToString:@"1"]) {
  253. //考核
  254. [self setExamer];
  255. }
  256. if ([cellType isEqualToString:@"2"]) {
  257. //送审
  258. [self trainSend];
  259. }
  260. }];
  261. if (moreSelectBtn.selected) {
  262. cell.isShowImg = YES;
  263. cell.checkBtn.userInteractionEnabled = NO;
  264. [cell.checkBtn setTitleColor:KContentTextColor forState:UIControlStateNormal];
  265. cell.checkBtn.layer.borderColor = KContentTextColor.CGColor;
  266. }else {
  267. cell.isShowImg = NO;
  268. cell.checkBtn.userInteractionEnabled = YES;
  269. [cell.checkBtn setTitleColor:RQMianColor forState:UIControlStateNormal];
  270. cell.checkBtn.layer.borderColor = RQMianColor.CGColor;
  271. }
  272. if (allSelectBtn.selected) {
  273. //全选
  274. cell.cellIsSelected = YES;
  275. }else {
  276. if (moreSelectBtn.selected) {
  277. if ([sendIdArray containsObject:[dict[@"STUDENT"] stringValue]]) {
  278. cell.cellIsSelected = YES;
  279. }else {
  280. cell.cellIsSelected = NO;
  281. }
  282. }else {
  283. cell.cellIsSelected = NO;
  284. }
  285. }
  286. return cell;
  287. }
  288. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  289. if (tableView == examertableView) {
  290. NSDictionary *dic = examDataArray[indexPath.row];
  291. examerID = [dic[@"EI_ID"] stringValue];
  292. return;
  293. }
  294. if (!moreSelectBtn.selected) {
  295. return;
  296. }
  297. NSDictionary *dict = dataArray[indexPath.row];
  298. CkeckCourceCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  299. if (cell.cellIsSelected) {
  300. cell.cellIsSelected = NO;
  301. if ([sendIdArray containsObject:[dict[@"STUDENT"] stringValue]]) {
  302. [sendIdArray removeObject:[dict[@"STUDENT"] stringValue]];
  303. }
  304. if (allSelectBtn.selected) {
  305. allSelectBtn.selected = NO;
  306. }
  307. }else {
  308. cell.cellIsSelected = YES;
  309. if (![sendIdArray containsObject:[dict[@"STUDENT"] stringValue]]) {
  310. [sendIdArray addObject:[dict[@"STUDENT"] stringValue]];
  311. }
  312. if (sendIdArray.count == dataArray.count) {
  313. allSelectBtn.selected = YES;
  314. }
  315. }
  316. }
  317. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  318. return 10;
  319. }
  320. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  321. return [UIView new];
  322. }
  323. #pragma mark 数据请求
  324. //送审列表
  325. - (void)trainTimes {
  326. if (![NetManager connectedToNetWork]) {
  327. [maintableView.mj_header endRefreshing];
  328. showMsgUnconnect();
  329. return;
  330. }
  331. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  332. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  333. [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"];
  334. [dic setObject:subjectString forKey:@"subject"];
  335. [dic setObject:@"0" forKey:@"isPage"];
  336. [dic setObject:@"" forKey:@"pageSize"];
  337. [dic setObject:@"" forKey:@"currentPage"];
  338. NSString *method = @"trainTimes";
  339. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  340. holderV.hidden = NO;
  341. [maintableView.mj_header endRefreshing];
  342. if (!root) {
  343. ShowMsg(@"获取数据错误");
  344. return;
  345. }
  346. if ([root[@"code"] integerValue] == 1) {
  347. ShowMsg(root[@"msg"]);
  348. return;
  349. }
  350. dataArray = root[@"body"];
  351. if (dataArray.count > 0) {
  352. holderV.hidden = YES;
  353. }
  354. [maintableView reloadData];
  355. }];
  356. }
  357. //考核员列表
  358. - (void)getTrainExams {
  359. if (![NetManager connectedToNetWork]) {
  360. showMsgUnconnect();
  361. return;
  362. }
  363. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  364. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  365. NSString *method = @"getTrainExams";
  366. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  367. if (!root) {
  368. ShowMsg(@"获取失败,请重试");
  369. return;
  370. }
  371. if ([root[@"code"] integerValue] == 1) {
  372. ShowMsg(root[@"msg"]);
  373. return;
  374. }
  375. examDataArray = root[@"body"];
  376. [examertableView reloadData];
  377. }];
  378. }
  379. //考核
  380. - (void)trainExamWithExamer:(NSString *)examerId {
  381. if (![NetManager connectedToNetWork]) {
  382. showMsgUnconnect();
  383. return;
  384. }
  385. if (sendIdArray.count < 1) {
  386. ShowMsg(@"请选择待考核学时");
  387. return;
  388. }
  389. NSString *ids = @"";
  390. for (NSString *str in sendIdArray) {
  391. for (NSDictionary *dict in dataArray) {
  392. if ([[dict[@"STUDENT"] stringValue] isEqualToString:str]) {
  393. if ([dict[@"EXAMERNAME"] length] < 1) {
  394. ids = [ids stringByAppendingString:[NSString stringWithFormat:@"%@,",str]];
  395. }
  396. break;
  397. }
  398. }
  399. }
  400. if (ids.length < 1) {
  401. ShowMsg(@"所选学时已考核");
  402. return;
  403. }
  404. ids = [ids substringToIndex:ids.length - 1];
  405. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  406. [dic setObject:examerId forKey:@"examerId"];
  407. [dic setObject:ids forKey:@"stuIds"];
  408. [dic setObject:subjectString forKey:@"subject"];
  409. NSString *method = @"trainExam";
  410. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  411. if (!root) {
  412. ShowMsg(@"考核学时失败,请重试");
  413. return;
  414. }
  415. if ([root[@"code"] integerValue] == 1) {
  416. ShowMsg(root[@"msg"]);
  417. return;
  418. }
  419. [sendIdArray removeAllObjects];
  420. allSelectBtn.selected = NO;
  421. moreSelectBtn.selected = NO;
  422. maintableView.height += bottomBar.height;
  423. bottomBar.hidden = YES;
  424. [self trainTimes];
  425. }];
  426. }
  427. //送审
  428. - (void)trainSend {
  429. if ([defUser.userDict[@"qz"] length] < 1) {
  430. ShowMsg(@"当前账户没有送审学时权限!");
  431. return;
  432. }
  433. if (![NetManager connectedToNetWork]) {
  434. showMsgUnconnect();
  435. return;
  436. }
  437. if (sendIdArray.count < 1) {
  438. ShowMsg(@"请选择待审核学时");
  439. return;
  440. }
  441. NSString *ids = @"";
  442. for (NSString *str in sendIdArray) {
  443. for (NSDictionary *dict in dataArray) {
  444. if ([[dict[@"STUDENT"] stringValue] isEqualToString:str]) {
  445. if ([dict[@"EXAMERNAME"] length] > 1) {
  446. ids = [ids stringByAppendingString:[NSString stringWithFormat:@"%@,",str]];
  447. }
  448. break;
  449. }
  450. }
  451. }
  452. if (ids.length < 1) {
  453. ShowMsg(@"所选学时已送审");
  454. return;
  455. }
  456. ids = [ids substringToIndex:ids.length - 1];
  457. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  458. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  459. [dic setObject:ids forKey:@"stuIds"];
  460. [dic setObject:subjectString forKey:@"subject"];
  461. NSString *method = @"trainSend";
  462. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  463. if (!root) {
  464. ShowMsg(@"审核学时失败,请重试");
  465. return;
  466. }
  467. if ([root[@"code"] integerValue] == 1) {
  468. ShowMsg(root[@"msg"]);
  469. return;
  470. }
  471. [sendIdArray removeAllObjects];
  472. allSelectBtn.selected = NO;
  473. moreSelectBtn.selected = NO;
  474. maintableView.height += bottomBar.height;
  475. bottomBar.hidden = YES;
  476. [self trainTimes];
  477. }];
  478. }
  479. - (void)didReceiveMemoryWarning {
  480. [super didReceiveMemoryWarning];
  481. }
  482. @end