StudentList.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. //
  2. // StudentList.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/8.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "StudentList.h"
  9. #import "StudentDetail.h"
  10. #import "StudentListCell.h"
  11. #import "DateView.h"
  12. @interface StudentList ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
  13. {
  14. UITableView *mainTableView;
  15. HolderView *holderView;
  16. NSInteger currentPage;
  17. //查询条件
  18. UIView *backView;
  19. UIButton *item;
  20. UIButton *subjectBtn,*trainTypeBtn,*oldStuBtn,*beginTimeBtn,*endTimeBtn;
  21. UITextField *nameField,*identityNumField,*telPhoneField;
  22. UITableView *carTypeTable;
  23. NSMutableArray *dataArray;
  24. NSArray *carTypeArray;
  25. NSMutableArray *selectCarTypeArray;
  26. NSString *subject;
  27. NSString *trainType;
  28. NSString *oldStu;
  29. NSString *beginTime;
  30. NSString *endTime;
  31. NSString *name;
  32. NSString *identityNum;
  33. NSString *telPhone;
  34. }
  35. @end
  36. @implementation StudentList
  37. - (void)viewDidLoad {
  38. [super viewDidLoad];
  39. self.navigationItem.title = @"学员列表";
  40. [self goBackByNavigation];
  41. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  42. item = btn;
  43. btn.frame = CGRectMake(0, 0, 43, 44);
  44. btn.titleLabel.font = [UIFont systemFontOfSize:17];
  45. [btn setTitle:@"筛选" forState:UIControlStateNormal];
  46. [btn setTitleColor:defGreen forState:UIControlStateNormal];
  47. [btn addTarget:self action:@selector(clickToSearch) forControlEvents:UIControlEventTouchUpInside];
  48. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  49. currentPage = 1;
  50. dataArray = [NSMutableArray array];
  51. selectCarTypeArray = [NSMutableArray array];
  52. carTypeArray = @[@"A1",@"A2",@"A3",@"B1",@"B2",@"C1",@"C2",@"C3",@"C4",@"C5",@"D",@"E",@"F",@"M",@"N",@"p"];
  53. subject = trainType = oldStu = beginTime = endTime = name = identityNum = telPhone = @"";
  54. mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain];
  55. mainTableView.height -= kNavOffSet + SafeAreaBottomHeight;
  56. mainTableView.delegate = self;
  57. mainTableView.dataSource = self;
  58. mainTableView.tableFooterView = [UIView new];
  59. // UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 50)];
  60. // headerView.backgroundColor = [UIColor whiteColor];
  61. // CGFloat wid = kSize.width/4.0 - 4.0;
  62. // NSArray *titleArray = @[@"姓名",@"性别",@"车型",@"报名日期"];
  63. // for (int i = 0; i < 4; i ++) {
  64. // UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(wid * i, 0, wid, 50)];
  65. // label.font = [UIFont systemFontOfSize:18 weight:14];
  66. // label.textAlignment = NSTextAlignmentCenter;
  67. // label.text = titleArray[i];
  68. // label.textColor = KTitleColor;
  69. // [headerView addSubview:label];
  70. // }
  71. // mainTableView.tableHeaderView = headerView;
  72. mainTableView.rowHeight = 44;
  73. [self.view addSubview:mainTableView];
  74. // [mainTableView registerNib:[UINib nibWithNibName:@"StudentListCell" bundle:nil] forCellReuseIdentifier:@"studentListCell"];
  75. __weak typeof(self) weakSelf = self;
  76. MJRefreshBackNormalFooter *mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  77. //加载数据
  78. [weakSelf getData];
  79. [mainTableView.mj_footer endRefreshing];
  80. }];
  81. mainTableView.mj_footer = mj_footer;
  82. holderView = [[HolderView alloc] initWithFrame:mainTableView.frame];
  83. [holderView freshBlock:^{
  84. [self getData];
  85. }];
  86. [self.view addSubview:holderView];
  87. [self getData];
  88. }
  89. - (void)clickToSearch {
  90. item.enabled = NO;
  91. backView = [[UIView alloc] initWithFrame:kFrame];
  92. backView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.5];
  93. [self.view addSubview:backView];
  94. CGFloat x, y, w, h, bd;
  95. x = 20;
  96. w = kSize.width - 2*x;
  97. h = 460;
  98. y = (kSize.height - h - kNavOffSet)/2.0;
  99. UIView *searchView = [[UIView alloc] KSetxywh];
  100. searchView.backgroundColor = KBackGroundColor;
  101. [searchView borderCornorRadios:5];
  102. [backView addSubview:searchView];
  103. x = y = bd = 10;
  104. w = searchView.width - 30;
  105. h = 40;
  106. NSArray *titles = @[@"学员姓名:",@"证件号:",@"手机号:",@"培训科目:",@"培训车型",@"历史学员",@"开始时间:",@"结束时间:"];
  107. NSArray *textArray = @[name,identityNum,telPhone];
  108. NSString *nameStr = @"输入学员姓名查找";
  109. NSString *identityStr = @"输入学员证件号查找";
  110. NSString *telStr = @"输入学员手机号查找";
  111. NSString *subjectStr = @"请选择培训科目";
  112. switch ([subject integerValue]) {
  113. case 1:
  114. subjectStr = @"科目一";
  115. break;
  116. case 2:
  117. subjectStr = @"科目二";
  118. break;
  119. case 3:
  120. subjectStr = @"科目三";
  121. break;
  122. case 4:
  123. subjectStr = @"科目四";
  124. break;
  125. default:
  126. break;
  127. }
  128. NSString *carTypeStr = @"请选择培训车型";
  129. if (trainType.length > 0) {
  130. carTypeStr = trainType;
  131. }
  132. NSString *oldStuStr = @"查看全部学员";
  133. if ([oldStu isEqualToString:@"0"]) {
  134. oldStuStr = @"查看新增学员";
  135. }
  136. if ([oldStu isEqualToString:@"1"]) {
  137. oldStuStr = @"查看历史学员";
  138. }
  139. NSString *beginStr = beginTime;
  140. if (beginStr.length < 1) {
  141. beginStr = @"请选择开始时间";
  142. }
  143. NSString *endStr = endTime;
  144. if (endStr.length < 1) {
  145. endStr = @"请选择结束时间";
  146. }
  147. NSArray *btnTitles = @[nameStr,identityStr,telStr,subjectStr,carTypeStr,oldStuStr,beginStr,endStr];
  148. NSMutableArray *btns = [NSMutableArray array];
  149. for (int i = 0; i < btnTitles.count; i ++) {
  150. UIView *backV = [[UIView alloc] initWithFrame:CGRectMake(x, y + i*(h + bd) , w, h)];
  151. [backV borderColor:kLineColor width:2 cornorRadios:5];
  152. [searchView addSubview:backV];
  153. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + bd, y + i*(h + bd) , 100, h)];
  154. [label setText:titles[i] Font:Font16 TextColor:KContentTextColor Alignment:NSTextAlignmentLeft];
  155. [searchView addSubview:label];
  156. if (i < 3) {
  157. UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(x + bd + 110, y + i*(h + bd) , w - x - bd - 110, h)];
  158. tf.font = [UIFont scaleSize:Font16];
  159. [tf setReturnKeyType:UIReturnKeyDone];
  160. tf.placeholder = btnTitles[i];
  161. NSString *str = textArray[i];
  162. if (str.length > 0) {
  163. tf.text = str;
  164. }
  165. tf.delegate = self;
  166. [searchView addSubview:tf];
  167. [btns addObject:tf];
  168. [tf addViewWithRect:CGRectMake(x + bd + 100, y + i*(h + bd) + 30 , w - x - bd - 100, 1.5) Color:kLineColor];
  169. }else{
  170. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + bd + 100, y + i*(h + bd) , w - x - bd - 100, h)];
  171. [button setTitle:btnTitles[i] textColor:KContentTextColor font:Font16 fotState:UIControlStateNormal];
  172. button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  173. [button target:self Tag:i - 2];
  174. [searchView addSubview:button];
  175. [btns addObject:button];
  176. }
  177. }
  178. nameField = btns[0];
  179. identityNumField = btns[1];
  180. telPhoneField = btns[2];
  181. subjectBtn = btns[3];
  182. trainTypeBtn = btns[4];
  183. oldStuBtn = btns[5];
  184. beginTimeBtn = btns[6];
  185. endTimeBtn = btns[7];
  186. y += titles.count*(h + bd);
  187. w = (w - 2*bd)/2.0;
  188. NSArray *titleArrays = @[@"取消",@"查询"];
  189. for (int i = 0; i < 2; i ++) {
  190. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + i*(w + 2*bd), y , w, h)];
  191. [button setTitle:titleArrays[i] textColor:defGreen font:Font16 fotState:UIControlStateNormal];
  192. [button borderColor:kLineColor width:2 cornorRadios:5];
  193. [button target:self Tag:i + titles.count - 2];//6 7
  194. [searchView addSubview:button];
  195. }
  196. }
  197. - (void)btnClick:(UIButton *)sender {
  198. [backView endEditing:YES];
  199. UIButton *btn = (UIButton *)sender;
  200. switch (btn.tag) {
  201. case 1://科目
  202. {
  203. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择培训科目" message:nil preferredStyle:UIAlertControllerStyleAlert];
  204. UIAlertAction * oneAction = [UIAlertAction actionWithTitle:@"科目一" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  205. subject = @"1";
  206. [btn setTitle:@"科目一" forState:UIControlStateNormal];
  207. }];
  208. UIAlertAction * twoAction = [UIAlertAction actionWithTitle:@"科目二" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  209. subject = @"2";
  210. [btn setTitle:@"科目二" forState:UIControlStateNormal];
  211. }];
  212. UIAlertAction * threeAction = [UIAlertAction actionWithTitle:@"科目三" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  213. subject = @"3";
  214. [btn setTitle:@"科目三" forState:UIControlStateNormal];
  215. }];
  216. UIAlertAction * fourAction = [UIAlertAction actionWithTitle:@"科目四" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  217. subject = @"4";
  218. [btn setTitle:@"科目四" forState:UIControlStateNormal];
  219. }];
  220. UIAlertAction * allAction = [UIAlertAction actionWithTitle:@"全部科目" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  221. subject = @"";
  222. [btn setTitle:@"全部科目" forState:UIControlStateNormal];
  223. }];
  224. [alert addAction:oneAction];
  225. [alert addAction:twoAction];
  226. [alert addAction:threeAction];
  227. [alert addAction:fourAction];
  228. [alert addAction:allAction];
  229. [self presentViewController:alert animated:YES completion:nil];
  230. }
  231. break;
  232. case 2://车型
  233. {
  234. if (!carTypeTable) {
  235. carTypeTable = [[UITableView alloc] initWithFrame:CGRectMake(20, (kSize.height - 460 - kNavOffSet)/2.0, kSize.width - 40, 460) style:UITableViewStylePlain];
  236. carTypeTable.delegate = self;
  237. carTypeTable.dataSource = self;
  238. carTypeTable.rowHeight = 44;
  239. //[carTypeTable setEditing:YES];
  240. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width - 40, 50)];
  241. carTypeTable.tableHeaderView = view;
  242. UILabel *label = [[UILabel alloc] initWithFrame:view.frame];
  243. [label setText:@"车型选择" Font:Font18 TextColor:KTitleColor Alignment:NSTextAlignmentCenter];
  244. [view addSubview:label];
  245. // UIButton *doneBtn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width - 40 - 100, 0, 100, 50)];
  246. // [doneBtn setTitle:@"完成" textColor:defGreen font:Font16 fotState:UIControlStateNormal];
  247. // [doneBtn target:self Tag:10];
  248. // [view addSubview:doneBtn];
  249. }
  250. [backView addSubview:carTypeTable];
  251. }
  252. break;
  253. case 3://历史学员
  254. {
  255. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否历史学员" message:nil preferredStyle:UIAlertControllerStyleAlert];
  256. UIAlertAction * oneAction = [UIAlertAction actionWithTitle:@"查看新增学员" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  257. oldStu = @"0";
  258. [btn setTitle:@"查看新增学员" forState:UIControlStateNormal];
  259. }];
  260. UIAlertAction * twoAction = [UIAlertAction actionWithTitle:@"查看历史学员" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  261. oldStu = @"1";
  262. [btn setTitle:@"查看历史学员" forState:UIControlStateNormal];
  263. }];
  264. UIAlertAction * threeAction = [UIAlertAction actionWithTitle:@"查看全部学员" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  265. oldStu = @"";
  266. [btn setTitle:@"查看全部学员" forState:UIControlStateNormal];
  267. }];
  268. [alert addAction:oneAction];
  269. [alert addAction:twoAction];
  270. [alert addAction:threeAction];
  271. [self presentViewController:alert animated:YES completion:nil];
  272. }
  273. break;
  274. case 4://开始时间
  275. {
  276. DateView *dateV = [[DateView alloc] init];
  277. [dateV setStyle:0];
  278. [dateV showWithComplete:^(NSString * result) {
  279. beginTime = result;
  280. [beginTimeBtn setTitle:beginTime forState:UIControlStateNormal];
  281. }];
  282. }
  283. break;
  284. case 5://结束时间
  285. {
  286. DateView *dateV = [[DateView alloc] init];
  287. [dateV setStyle:0];
  288. [dateV showWithComplete:^(NSString * result) {
  289. endTime = result;
  290. [endTimeBtn setTitle:endTime forState:UIControlStateNormal];
  291. }];
  292. }
  293. break;
  294. case 6://取消
  295. {
  296. if (backView) {
  297. [backView removeFromSuperview];
  298. }
  299. item.enabled = YES;
  300. }
  301. break;
  302. case 7://查询
  303. {
  304. if (backView) {
  305. [backView removeFromSuperview];
  306. }
  307. item.enabled = YES;
  308. currentPage = 1;
  309. [dataArray removeAllObjects];
  310. [self getData];
  311. }
  312. break;
  313. case 10://完成车型选择
  314. {
  315. [carTypeTable removeFromSuperview];
  316. trainType = @"";
  317. for (NSString *carType in selectCarTypeArray) {
  318. trainType = [trainType stringByAppendingString:[NSString stringWithFormat:@"%@,",carType]];
  319. }
  320. if (trainType.length > 0) {
  321. trainType = [trainType substringToIndex:trainType.length - 1];
  322. }
  323. [trainTypeBtn setTitle:trainType forState:UIControlStateNormal];
  324. }
  325. break;
  326. default:
  327. break;
  328. }
  329. }
  330. #pragma mark 数据
  331. -(void)getData{
  332. NSMutableDictionary * mdic = [NSMutableDictionary new];
  333. if (nameField.text.length > 0) {
  334. name = nameField.text;
  335. }else{
  336. name = @"";
  337. }
  338. if (identityNumField.text.length > 0) {
  339. identityNum = identityNumField.text;
  340. }else{
  341. identityNum = @"";
  342. }
  343. if (telPhoneField.text.length > 0) {
  344. telPhone = telPhoneField.text;
  345. }else{
  346. telPhone = @"";
  347. }
  348. [mdic setValue:@"1" forKey:@"isPage"];
  349. [mdic setValue:@"20" forKey:@"pageSize"];
  350. [mdic setValue:[NSString stringWithFormat:@"%d",(int)currentPage] forKey:@"currentPage"];
  351. [mdic setValue:defUser.userDict[@"id"] forKey:@"userId"];
  352. [mdic setValue:defUser.userDict[@"dqbh"] forKey:@"dqbh"];
  353. [mdic setValue:defUser.userDict[@"qxbh"] forKey:@"qxbh"];
  354. [mdic setValue:defUser.userDict[@"school"] forKey:@"school"];
  355. [mdic setValue:@"" forKey:@"isActive"];
  356. [mdic setValue:@"" forKey:@"logout"];
  357. [mdic setValue:@"" forKey:@"sex"];
  358. [mdic setValue:subject forKey:@"subject"];
  359. [mdic setValue:trainType forKey:@"trainType"];
  360. [mdic setValue:name forKey:@"name"];
  361. [mdic setValue:identityNum forKey:@"idcard"];
  362. [mdic setValue:telPhone forKey:@"phone"];
  363. [mdic setValue:beginTime forKey:@"startTime"];
  364. [mdic setValue:endTime forKey:@"endTime"];
  365. [mdic setValue:oldStu forKey:@"historyStu"];
  366. [MBProgressHUD showLoadToView:self.view];
  367. [NetManager requestAnythingWithURL:@"students" dictionary:mdic dataArray:nil completion:^(NSDictionary *root) {
  368. [MBProgressHUD hideHUDForView:self.view];
  369. if (!root) {
  370. ShowMsg(@"获取学员列表失败,请重试!");
  371. return;
  372. }
  373. if ([root[@"code"] integerValue] == 1) {
  374. ShowMsg(root[@"msg"]);
  375. return;
  376. }
  377. if ([root[@"body"] count] < 1) {
  378. if (currentPage > 1) {
  379. ShowMsg(@"没有更多数据");
  380. }else {
  381. holderView.hidden = NO;
  382. }
  383. return;
  384. }
  385. holderView.hidden = YES;
  386. currentPage += 1;
  387. [dataArray addObjectsFromArray:root[@"body"]];
  388. [mainTableView reloadData];
  389. }];
  390. }
  391. #pragma mark tf delegate
  392. -(BOOL)textFieldShouldReturn:(UITextField *)textField {
  393. [backView endEditing:YES];
  394. return YES;
  395. }
  396. #pragma mark tableView delegate
  397. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  398. return UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;
  399. }
  400. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  401. if (tableView == carTypeTable) {
  402. return carTypeArray.count;
  403. }
  404. return dataArray.count;
  405. }
  406. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  407. {
  408. if (tableView == carTypeTable) {
  409. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  410. if (cell == nil) {
  411. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  412. cell.textLabel.textAlignment = NSTextAlignmentCenter;
  413. }
  414. cell.textLabel.text = carTypeArray[indexPath.row];
  415. return cell;
  416. }
  417. // StudentListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"studentListCell" forIndexPath:indexPath];
  418. // cell.dataDic = dataArray[indexPath.row];
  419. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  420. if (!cell) {
  421. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
  422. }
  423. cell.textLabel.text = [NSString stringWithFormat:@"%@",dataArray[indexPath.row][@"TSO_NAME"]];
  424. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",dataArray[indexPath.row][@"TSO_IDCARD"]];
  425. return cell;
  426. }
  427. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  428. if (tableView == carTypeTable) {//选中
  429. // if (![selectCarTypeArray containsObject:carTypeArray[indexPath.row]]) {
  430. // [selectCarTypeArray addObject:carTypeArray[indexPath.row]];
  431. // }
  432. trainType = carTypeArray[indexPath.row];
  433. [trainTypeBtn setTitle:trainType forState:UIControlStateNormal];
  434. [carTypeTable removeFromSuperview];
  435. return;
  436. }
  437. StudentDetail * vc = [[StudentDetail alloc]init];
  438. vc.dataSource = dataArray[indexPath.row];//传入不再请求数据
  439. [self navPushHideTabbarToVC:vc];
  440. }
  441. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
  442. if (tableView == carTypeTable) {//移除
  443. if ([selectCarTypeArray containsObject:carTypeArray[indexPath.row]]) {
  444. [selectCarTypeArray removeObject:carTypeArray[indexPath.row]];
  445. }
  446. return;
  447. }
  448. }
  449. - (void)didReceiveMemoryWarning {
  450. [super didReceiveMemoryWarning];
  451. // Dispose of any resources that can be recreated.
  452. }
  453. /*
  454. #pragma mark - Navigation
  455. // In a storyboard-based application, you will often want to do a little preparation before navigation
  456. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  457. // Get the new view controller using [segue destinationViewController].
  458. // Pass the selected object to the new view controller.
  459. }
  460. */
  461. @end