StuRecordVC.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. //
  2. // StuRecordVC.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/8/30.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "StuRecordVC.h"
  9. #import "HolderView.h"
  10. #import "DateView.h"
  11. #import "MyGradeVC.h"
  12. @interface StuRecordVC ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate,UIPickerViewDataSource,UIPickerViewDelegate,UISearchDisplayDelegate,UISearchResultsUpdating>
  13. {
  14. UITableView *_contactTable;
  15. HolderView *holderV;
  16. UIBarButtonItem *item;
  17. UIView *backView;
  18. UITextField *scoreField,*countField;
  19. UIButton *scoreBtn,*countBtn,*isTestBtn,*beginDateBtn,*endDateBtn,*kemuBtn;
  20. UIPickerView *picker;
  21. UIView *bgView;
  22. NSArray *pickDataArray;
  23. NSInteger whichPicker;
  24. NSString *scoreString;
  25. NSString *countString;
  26. NSString *isTestString;
  27. NSString *beginDate;
  28. NSString *endDate;
  29. NSString *kemuString;
  30. //添加索引加的参数
  31. UISearchController *_searchController;
  32. UISearchBar *_searchBar;
  33. NSMutableArray *_tableSourceArray;
  34. NSMutableArray *_letterArray;
  35. NSMutableArray *_resultArray;
  36. NSMutableArray *models;
  37. NSMutableDictionary *groupDic;
  38. }
  39. @end
  40. @implementation StuRecordVC
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. self.title = @"学员预考成绩";
  44. //self.view.backgroundColor = backGroundColor;
  45. //[self configNavBar];
  46. _tableSourceArray = [[NSMutableArray alloc] init];
  47. _letterArray = [[NSMutableArray alloc] init];
  48. _resultArray = [[NSMutableArray alloc] init];
  49. groupDic = [[NSMutableDictionary alloc] init];
  50. models = [[NSMutableArray alloc] init];
  51. pickDataArray = @[@[@"90",@"91",@"92",@"93",@"94",@"95",@"96",@"97",@"98",@"99",@"100"],@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10"]];
  52. scoreString = @"90";
  53. countString = @"1";
  54. isTestString = @"";
  55. beginDate = @"";
  56. endDate = @"";
  57. kemuString = @"1";//科一和科四
  58. //获取26个大写字母
  59. for (int i = 65; i < 91; i ++)
  60. {
  61. NSString * letter = [[NSString alloc] initWithBytes:&i length:1 encoding:NSUTF8StringEncoding];
  62. [_letterArray addObject:letter];
  63. }
  64. item = [[UIBarButtonItem alloc] initWithTitle:@"条件搜索" style:UIBarButtonItemStyleDone target:self action:@selector(clickToSearch)];
  65. [item setTintColor:defGreen];
  66. [self.navigationItem setRightBarButtonItem:item];
  67. _contactTable = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain];
  68. // _contactTable.y += kNavOffSet;
  69. // _contactTable.height -= kNavOffSet;
  70. _contactTable.delegate = self;
  71. _contactTable.dataSource = self;
  72. //设置sectionIndex
  73. [_contactTable setSectionIndexBackgroundColor:[UIColor clearColor]];
  74. [_contactTable setSectionIndexColor:[UIColor redColor]];
  75. [self.view addSubview:_contactTable];
  76. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
  77. {
  78. _searchController =[[UISearchController alloc]initWithSearchResultsController:nil];
  79. [_searchController.searchBar sizeToFit];
  80. _searchController.searchResultsUpdater = self;
  81. //这个是在搜索时候将之前的隐藏 包括表 无法点击 适合弹出新的tableviewcontroller 默认yes
  82. _searchController.dimsBackgroundDuringPresentation = NO;
  83. //这个是搜索时候隐藏导航栏
  84. _searchController.hidesNavigationBarDuringPresentation = NO;
  85. _searchController.searchBar.placeholder=@"请输入学员姓名或者电话";
  86. _contactTable.sectionIndexColor = [UIColor blueColor];
  87. _contactTable.tableHeaderView=_searchController.searchBar;
  88. //[self searchBarTextDidBeginEditing:_searchController.searchBar];
  89. //不用弹出 因为没有单独的tableviewcontroller
  90. //[self presentViewController:_searchController animated:YES completion:nil];
  91. }
  92. else
  93. {
  94. //实例化一个搜索框
  95. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
  96. //设置背景色
  97. [_searchBar setBarTintColor:[UIColor grayColor]];
  98. //设置搜索框风格
  99. [_searchBar setSearchBarStyle:UISearchBarStyleProminent];
  100. [_searchBar setPlaceholder:@"请输入学员姓名或者电话"];
  101. //设置显示取消按钮
  102. [_searchBar setShowsCancelButton:YES animated:YES];
  103. //设置类型的标题
  104. //[_searchBar setScopeButtonTitles:@[@"按姓名查找",@"按电话查找"]];
  105. //改变索引的颜色
  106. _contactTable.sectionIndexColor = [UIColor blueColor];
  107. //改变索引选中的背景颜色
  108. //设置表的表头
  109. [_contactTable setTableHeaderView:_searchBar];
  110. //搜索显示器 Display显示
  111. UISearchDisplayController * displayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
  112. [displayController setDelegate:self];
  113. [displayController setSearchResultsDataSource:self];
  114. [displayController setSearchResultsDelegate:self];
  115. }
  116. holderV = [[HolderView alloc] initWithFrame:_contactTable.frame];
  117. [holderV freshBlock:^{
  118. [self getMyStudentByScore];
  119. }];
  120. [self.view addSubview:holderV];
  121. [self getMyStudentByScore];
  122. }
  123. -(void)viewWillDisappear:(BOOL)animated
  124. {
  125. [super viewWillDisappear:animated];
  126. [self.view endEditing:YES];
  127. //NSLog(@"这个一直执行");
  128. RemoveHUD();
  129. //这个一定要写 要不然会在退出去下一个页面时候 搜索栏有一定时间的存留
  130. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
  131. if (_searchController.active) {
  132. _searchController.active = NO;
  133. if (_searchController.searchBar && _searchController.searchBar.superview) {
  134. //NSLog(@"这个也一直执行");
  135. [_searchController.searchBar removeFromSuperview];
  136. }
  137. }
  138. }else{
  139. if (_searchBar && _searchBar.superview) {
  140. [_searchBar removeFromSuperview];
  141. }
  142. }
  143. }
  144. #pragma mark maintableview delegate (索引)
  145. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  146. {
  147. return _letterArray;
  148. }
  149. //响应点击索引时的委托方法
  150. -(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  151. {
  152. NSInteger count = 0;
  153. //NSLog(@"%@-%d",title,(int)index);
  154. NSArray *array = [[groupDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
  155. //为了找到索引中没有字目的前一个字母 也是醉了
  156. if (![array containsObject:title]) {
  157. int index = (int)[_letterArray indexOfObject:title];
  158. for (int i = index; i > 0; i --) {
  159. if ([array containsObject:_letterArray[i]]) {
  160. title = _letterArray[i];
  161. break;
  162. }
  163. }
  164. }
  165. for(NSString *character in array)
  166. {
  167. if([character isEqualToString:title])
  168. {
  169. return count;
  170. }
  171. count ++;
  172. }
  173. return 0;
  174. }
  175. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  176. {
  177. if (tableView == _contactTable)
  178. {
  179. if (_searchController.searchBar.text.length > 0) {
  180. if (_resultArray.count > 0) {
  181. NSString *str = [[_resultArray firstObject] substringToIndex:1];
  182. for (NSDictionary *dic in models) {
  183. if ([dic[@"XM"] hasPrefix:str]) {
  184. return dic[@"PY_FIRST"];
  185. }
  186. }
  187. }
  188. //这个永远不会返回 因为 result为空 就不会有这个
  189. return @"A";
  190. }else{
  191. NSArray * array = [[groupDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
  192. return [array objectAtIndex:section];
  193. }
  194. }
  195. else
  196. {
  197. NSString *str = [[_resultArray firstObject] substringToIndex:1];
  198. for (NSDictionary *dic in models) {
  199. if ([dic[@"XM"] hasPrefix:str]) {
  200. return dic[@"PY_FIRST"];
  201. }
  202. }
  203. }
  204. //这个永远不会返回 因为 result为空 就不会有这个
  205. return @"A";
  206. }
  207. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  208. {
  209. //最外层else 相当于对版本适配了 只有iOS8以下 才会进的方法
  210. if (tableView == _contactTable)
  211. {
  212. if (_searchController.searchBar.text.length > 0) {
  213. if (_resultArray.count > 0) {
  214. return 1;
  215. }else{
  216. return 0;
  217. }
  218. }
  219. return [[groupDic allKeys] count];
  220. }
  221. else
  222. {
  223. if (_resultArray.count > 0) {
  224. return 1;
  225. }else{
  226. return 0;
  227. }
  228. }
  229. }
  230. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  231. {
  232. if (tableView == _contactTable)
  233. {
  234. //sortedArrayUsingSelector 排序
  235. if (_searchController.searchBar.text.length > 0) {
  236. return _resultArray.count;
  237. }
  238. NSArray * array = [[groupDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
  239. return [[groupDic objectForKey:array[section]] count];
  240. }
  241. else
  242. {
  243. //显示搜索的结果
  244. return _resultArray.count;
  245. }
  246. }
  247. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  248. {
  249. static NSString * Identifier = @"cell";
  250. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
  251. if (cell == nil)
  252. {
  253. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Identifier];
  254. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  255. }
  256. NSString *p;
  257. if (tableView == _contactTable)
  258. {
  259. if (_searchController.searchBar.text.length > 0) {
  260. p = _resultArray[indexPath.row];
  261. }else{
  262. NSArray * array = [[groupDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
  263. p = [[groupDic objectForKey:[array objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  264. }
  265. }
  266. else
  267. {
  268. p = _resultArray[indexPath.row];
  269. }
  270. [cell.textLabel setText:p];
  271. // //如果有休学 用不同颜色标注出来
  272. // if ([p hasSuffix:@"已休学"]) {
  273. // NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:p];
  274. // NSRange sufRange = [p rangeOfString:@"已休学"];
  275. // [str addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:sufRange];
  276. // cell.textLabel.attributedText = str;
  277. // }else{
  278. // [cell.textLabel setText:p];
  279. // }
  280. return cell;
  281. }
  282. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  283. {
  284. NSString *showString;
  285. if (tableView == _contactTable)
  286. {
  287. if (_searchController.searchBar.text.length > 0) {
  288. showString = _resultArray[indexPath.row];
  289. }else{
  290. NSArray * array = [[groupDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
  291. showString = [[groupDic objectForKey:[array objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  292. }
  293. }else{
  294. showString = _resultArray[indexPath.row];
  295. }
  296. for (NSDictionary *dic in models) {
  297. BOOL isHas;
  298. if (kSize.width > 350.0){
  299. isHas = [showString hasPrefix:[NSString stringWithFormat:@"%@ %@",dic[@"XM"],dic[@"SJHM"]]];
  300. }else{
  301. isHas = [showString hasPrefix:[NSString stringWithFormat:@"%@ %@",dic[@"XM"],dic[@"SJHM"]]];
  302. }
  303. if (isHas) {
  304. //从这个地方去学员成绩
  305. MyGradeVC *gradeVC = [[MyGradeVC alloc] init];
  306. gradeVC.kmString = kemuString;
  307. gradeVC.identifyNum = dic[@"USERID"];
  308. gradeVC.stuName = dic[@"XM"];
  309. [self.navigationController pushViewController:gradeVC animated:YES];
  310. return;
  311. }
  312. }
  313. }
  314. #pragma mark UISearchDisplayController 代理方法
  315. //iOS7搜索的时候 会调用这个方法
  316. - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
  317. {
  318. //NSLog(@"searchString====%@",searchString);
  319. [_resultArray removeAllObjects];
  320. //按名字查找 _tableSourceArray里边有电话和名字信息 所以查一次就好 要不然 会重复的
  321. for (NSString * info in _tableSourceArray)
  322. {
  323. if ([info rangeOfString:searchString].location != NSNotFound)
  324. {
  325. [_resultArray addObject:info];
  326. }
  327. }
  328. [_contactTable reloadData];
  329. return YES;
  330. }
  331. //点击不同的选择范围的时候调用
  332. -(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
  333. {
  334. [self searchDisplayController:controller shouldReloadTableForSearchString:_searchBar.text];
  335. return YES;
  336. }
  337. //iOS8搜索调用的方法
  338. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  339. {
  340. //[self searchBarTextDidBeginEditing:_searchController.searchBar];
  341. NSString *searchString = _searchController.searchBar.text;
  342. //NSLog(@"searchString-->%@",searchString);
  343. [_resultArray removeAllObjects];
  344. for (NSString * name in _tableSourceArray)
  345. {
  346. if ([name rangeOfString:searchString].location != NSNotFound)
  347. {
  348. [_resultArray addObject:name];
  349. }
  350. }
  351. //NSLog(@"_resultArray-->%@",_resultArray);
  352. [_contactTable reloadData];
  353. }
  354. #pragma mark pickerView
  355. -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
  356. {
  357. return 1;
  358. }
  359. //每列对应多少行
  360. -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
  361. {
  362. //1.获取当前的列
  363. NSArray *arayM = pickDataArray[whichPicker];
  364. //2.返回当前列对应的行数
  365. return arayM.count;
  366. }
  367. //每列每行对应显示的数据是什么
  368. -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
  369. {
  370. //1.获取当前的列
  371. NSArray *arayM = pickDataArray[whichPicker];
  372. //2.获取当前列对应的行的数据
  373. return arayM[row];
  374. }
  375. -(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
  376. {
  377. return 40;
  378. }
  379. //选中
  380. -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
  381. {
  382. //获取对应列,对应行的数据
  383. NSString *exceptValue = pickDataArray[whichPicker][row];
  384. //赋值
  385. if (whichPicker == 0) {
  386. [scoreBtn setTitle:exceptValue forState:UIControlStateNormal];
  387. scoreString = exceptValue;
  388. }
  389. if (whichPicker == 1) {
  390. [countBtn setTitle:exceptValue forState:UIControlStateNormal];
  391. countString = exceptValue;
  392. }
  393. }
  394. #pragma mark --触发事件
  395. -(void)clickToSearch
  396. {
  397. item.enabled = NO;
  398. backView = [[UIView alloc] initWithFrame:kFrame];
  399. backView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.5];
  400. [self addV:backView];
  401. CGFloat x, y, w, h, bd;
  402. x = 20;
  403. w = kSize.width - 2*x;
  404. h = 360;
  405. y = (kSize.height - h)/2.0;
  406. UIView *searchView = [[UIView alloc] setxywh];
  407. searchView.backgroundColor = backGroundColor;
  408. [searchView borderCornorRadios:5];
  409. [backView addSubview:searchView];
  410. x = y = bd = 10;
  411. w = searchView.width - 30;
  412. h = 40;
  413. NSArray *titles = @[@"学员成绩:",@"连续次数:",@"是否预考:",@"开始时间:",@"结束时间:",@"考试科目:"];
  414. NSString *testStr = @"全部";
  415. if ([isTestString isEqualToString:@"0"]) {
  416. testStr = @"未预考";
  417. }
  418. if ([isTestString isEqualToString:@"1"]) {
  419. testStr = @"已预考";
  420. }
  421. NSString *beginStr = beginDate;
  422. if (beginStr.length < 1) {
  423. beginStr = @"请选择开始时间";
  424. }
  425. NSString *endStr = endDate;
  426. if (endStr.length < 1) {
  427. endStr = @"请选择结束时间";
  428. }
  429. NSString *kemuStr = @"科目一";
  430. if ([kemuString isEqualToString:@"4"]) {
  431. kemuStr = @"科目四";
  432. }
  433. NSArray *btnTitles = @[scoreString,countString,testStr,beginStr,endStr,kemuStr];
  434. NSArray *describes = @[@"分以上",@"次以上"];
  435. NSMutableArray *btns = [NSMutableArray arrayWithCapacity:6];
  436. for (int i = 0; i < 6; i ++) {
  437. UIView *backV = [[UIView alloc] initWithFrame:CGRectMake(x, y + i*(h + bd) , w, h)];
  438. [backV borderColor:lineColor width:2 cornorRadios:5];
  439. [searchView addSubview:backV];
  440. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + bd, y + i*(h + bd) , 100, h)];
  441. [label setText:titles[i] Font:Font16 TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  442. [searchView addSubview:label];
  443. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + bd + 110, y + i*(h + bd) , w - x - bd - 110, h)];
  444. [button setTitle:btnTitles[i] textColor:contentTextColor font:Font16 fotState:UIControlStateNormal];
  445. button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  446. [button target:self Tag:i + 1];
  447. [searchView addSubview:button];
  448. [btns addObject:button];
  449. if (i < 2) {
  450. [button addViewWithRect:CGRectMake(x + bd + 100, y + i*(h + bd) + 30 , 35, 1.5) Color:contentTextColor];
  451. label = [[UILabel alloc] initWithFrame:CGRectMake(x + bd + 150, y + i*(h + bd) , w - x - bd - 150, h)];
  452. [label setText:describes[i] Font:Font16 TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  453. [searchView addSubview:label];
  454. }else{
  455. button.x -= 10;
  456. button.width += 10;
  457. }
  458. }
  459. scoreBtn = btns[0];
  460. countBtn = btns[1];
  461. isTestBtn = btns[2];
  462. beginDateBtn = btns[3];
  463. endDateBtn = btns[4];
  464. kemuBtn = btns[5];
  465. y += 6*(h + bd);
  466. w = (w - 2*bd)/2.0;
  467. NSArray *titleArrays = @[@"取消",@"查询"];
  468. for (int i = 0; i < 2; i ++) {
  469. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + i*(w + 2*bd), y , w, h)];
  470. [button setTitle:titleArrays[i] textColor:defGreen font:Font16 fotState:UIControlStateNormal];
  471. [button borderColor:lineColor width:2 cornorRadios:5];
  472. [button target:self Tag:i + 7];//7 8
  473. [searchView addSubview:button];
  474. }
  475. }
  476. -(void)btnClick:(UIButton *)sender
  477. {
  478. if (bgView && sender.tag < 4) {
  479. ShowMsg(@"请先选择分数或者连续次数");
  480. return;
  481. }
  482. switch (sender.tag) {
  483. case 1:
  484. {
  485. whichPicker = 0;
  486. bgView = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - 180, kSize.width, 180)];
  487. bgView.backgroundColor = [UIColor whiteColor];
  488. [self.view addSubview:bgView];
  489. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 - 20, 0, kSize.width/2.0, 35)];
  490. [btn setTitle:@"完成" textColor:defGreen font:Font18 fotState:UIControlStateNormal];
  491. btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  492. [btn target:self Tag:9];
  493. [bgView addSubview:btn];
  494. picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 30, kSize.width, 150)];
  495. picker.delegate = self;
  496. picker.dataSource = self;
  497. [bgView addSubview:picker];
  498. [btn addViewWithRect:CGRectMake(0, 35, kSize.width, 1.5) Color:contentTextColor];
  499. }
  500. break;
  501. case 2:
  502. {
  503. whichPicker = 1;
  504. bgView = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - 180, kSize.width, 180)];
  505. bgView.backgroundColor = [UIColor whiteColor];
  506. [self.view addSubview:bgView];
  507. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 - 20, 0, kSize.width/2.0, 35)];
  508. [btn setTitle:@"完成" textColor:defGreen font:Font18 fotState:UIControlStateNormal];
  509. btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  510. [btn target:self Tag:9];
  511. [bgView addSubview:btn];
  512. picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 30, kSize.width, 150)];
  513. picker.delegate = self;
  514. picker.dataSource = self;
  515. [bgView addSubview:picker];
  516. [btn addViewWithRect:CGRectMake(0, 35, kSize.width, 1.5) Color:contentTextColor];
  517. }
  518. break;
  519. case 3:
  520. {
  521. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"是否已预考" delegate:self cancelButtonTitle:@"全部" otherButtonTitles:@"已预考",@"未预考", nil];
  522. alert.tag = 1;
  523. [alert show];
  524. }
  525. break;
  526. case 4:
  527. {
  528. DateView *dateV = [[DateView alloc] init];
  529. [dateV setStyle:0];
  530. [dateV showWithComplete:^(NSString * result) {
  531. beginDate = result;
  532. [beginDateBtn setTitle:beginDate forState:UIControlStateNormal];
  533. }];
  534. }
  535. break;
  536. case 5:
  537. {
  538. DateView *dateV = [[DateView alloc] init];
  539. [dateV setStyle:0];
  540. [dateV showWithComplete:^(NSString * result) {
  541. endDate = result;
  542. [endDateBtn setTitle:endDate forState:UIControlStateNormal];
  543. }];
  544. }
  545. break;
  546. case 6:
  547. {
  548. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"请选择科目" delegate:self cancelButtonTitle:@"科目一" otherButtonTitles:@"科目四", nil];
  549. alert.tag = 2;
  550. [alert show];
  551. }
  552. break;
  553. case 7:
  554. {
  555. if (backView) {
  556. //取消的时候 如果picker还在 要移除了
  557. if (bgView) {
  558. [bgView removeFromSuperview];
  559. bgView = nil;
  560. }
  561. [backView removeFromSuperview];
  562. }
  563. item.enabled = YES;
  564. }
  565. break;
  566. case 8:
  567. {
  568. if (backView) {
  569. //取消的时候 如果picker还在 要移除了
  570. if (bgView) {
  571. [bgView removeFromSuperview];
  572. bgView = nil;
  573. }
  574. [backView removeFromSuperview];
  575. }
  576. item.enabled = YES;
  577. [self getMyStudentByScore];
  578. }
  579. break;
  580. case 9:
  581. {
  582. if (bgView) {
  583. [bgView removeFromSuperview];
  584. bgView = nil;
  585. }
  586. }
  587. break;
  588. default:
  589. break;
  590. }
  591. }
  592. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  593. {
  594. if (alertView.tag == 1) {
  595. if (buttonIndex == 0) {
  596. //取消 全部
  597. isTestString = @"";
  598. [isTestBtn setTitle:@"全部" forState:UIControlStateNormal];
  599. }else if (buttonIndex == 1) {
  600. isTestString = @"1";
  601. [isTestBtn setTitle:@"已预考" forState:UIControlStateNormal];
  602. }else{
  603. isTestString = @"0";
  604. [isTestBtn setTitle:@"未预考" forState:UIControlStateNormal];
  605. }
  606. }else if (alertView.tag == 2){
  607. if (buttonIndex == 0) {
  608. //取消 科目一
  609. kemuString = @"1";
  610. [kemuBtn setTitle:@"科目一" forState:UIControlStateNormal];
  611. }else if (buttonIndex == 1){
  612. kemuString = @"4";
  613. [kemuBtn setTitle:@"科目四" forState:UIControlStateNormal];
  614. }
  615. }
  616. }
  617. #pragma mark 数据请求
  618. /**
  619. * 根据连续次数和成绩查询满足的学员
  620. * @param String score 满足考试分数
  621. * @param String count 连续次数
  622. * @param String isYk 是否已预考
  623. * @param String zjhm 教练证件号码
  624. * */
  625. //String getMyStudentByScore(String serviceName, String key,String score,String count,String isYk,String zjhm);
  626. //考试成绩
  627. - (void)getMyStudentByScore
  628. {
  629. [LoadingView showHUD];
  630. if (![Util connectedToNetWork]) {
  631. showMsgUnconnect();
  632. return;
  633. }
  634. NSMutableArray *arr=[NSMutableArray array];
  635. [arr addPro:@"score" Value:scoreString];
  636. [arr addPro:@"count" Value:countString];
  637. [arr addPro:@"zjhm" Value:defUser.sfzmhm];
  638. [arr addPro:@"startTime" Value:beginDate];
  639. [arr addPro:@"endTime" Value:endDate];
  640. [arr addPro:@"kskm" Value:kemuString];
  641. // [arr addPro:@"isNotice" Value:isTestString];
  642. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  643. NSString* method = @"getMyStudentByScore";
  644. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  645. RemoveHUD();
  646. [holderV setHidden:NO];
  647. if (!root) {
  648. [LoadingView showMsg:@"查询失败"];
  649. return;
  650. }
  651. NSString* code = root[@"code"];
  652. if (code.intValue >0)
  653. {
  654. [LoadingView showMsg:root[@"body"]];
  655. return;
  656. }
  657. if ([root[@"body"] count] < 1) {
  658. [LoadingView showMsg:@"已加载全部数据"];
  659. return;
  660. }
  661. [holderV setHidden:YES];
  662. models = root[@"body"];
  663. [self acceptData];
  664. }];
  665. }
  666. -(void)acceptData
  667. {
  668. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
  669. {
  670. _searchController.searchBar.placeholder=[NSString stringWithFormat:@"请输入学员姓名或电话(当前共%d人)",(int)models.count];
  671. }else{
  672. [_searchBar setPlaceholder:[NSString stringWithFormat:@"请输入学员姓名或电话(当前共%d人)",(int)models.count]];
  673. }
  674. [groupDic removeAllObjects];
  675. [_tableSourceArray removeAllObjects];
  676. /**
  677. * LLJLMC = 陈恺声,
  678. CRDATE = 2016-02-17 10:26:14,
  679. ZJHM = 130425198104097711,
  680. SJHM = 15272271043,
  681. LXDH = 15272271043,
  682. XM = 张运奇,
  683. CX = C1,
  684. PY_FIRST = Z,
  685. XB = 男,
  686. ID = 776976
  687. */
  688. NSString *keMuString;
  689. for (NSDictionary *dic in models) {
  690. keMuString = @"科目一";
  691. if ([kemuString isEqualToString:@"4"]) {
  692. keMuString = @"科目四";
  693. }
  694. NSString *letter = dic[@"PY_FIRST"];
  695. if (![groupDic objectForKey:letter]) {
  696. [groupDic setObject:[NSMutableArray array] forKey:letter];
  697. }
  698. if (kSize.width > 350.0){
  699. [_tableSourceArray addObject:[NSString stringWithFormat:@"%@ %@ %@",dic[@"XM"],dic[@"SJHM"],keMuString]];
  700. [[groupDic objectForKey:letter] addObject:[NSString stringWithFormat:@"%@ %@ %@",dic[@"XM"],dic[@"SJHM"],keMuString]];
  701. }else{
  702. [_tableSourceArray addObject:[NSString stringWithFormat:@"%@ %@ %@",dic[@"XM"],dic[@"SJHM"],keMuString]];
  703. [[groupDic objectForKey:letter] addObject:[NSString stringWithFormat:@"%@ %@ %@",dic[@"XM"],dic[@"SJHM"],keMuString]];
  704. }
  705. }
  706. [_contactTable reloadData];
  707. }
  708. - (void)didReceiveMemoryWarning {
  709. [super didReceiveMemoryWarning];
  710. }
  711. @end