FaceColloectVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. //
  2. // FaceColloectVC.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/9/11.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "FaceColloectVC.h"
  9. #import "FaceColloectView.h"
  10. #import "UIImageView+WebCache.h"
  11. @interface FaceColloectVC ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource, THDatePickerDelegate>
  12. {
  13. UITextField *searchTF;
  14. UIScrollView *mainScroll;
  15. UITableView *stuListTableView;
  16. FaceColloectView *face0,*face1,*face2,*face3,*face4,*face5;
  17. NSMutableArray *faceArrray;
  18. NSArray *stuListArray;
  19. }
  20. @property (nonatomic, strong) UIView *stuListView;
  21. @property (nonatomic, strong) THDatePickerViewController * datePicker;
  22. @property (nonatomic, retain) NSDate * curDate;
  23. @property (nonatomic, retain) NSDateFormatter * formatter;
  24. @end
  25. @implementation FaceColloectVC
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. self.view.backgroundColor = [UIColor whiteColor];
  29. self.navigationItem.title = @"人脸采集";
  30. [self goBackByNavigation];
  31. UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10, kSize.width - 100, 40)];
  32. textField.borderStyle = UITextBorderStyleRoundedRect;
  33. textField.placeholder = @"请输入学员证件或姓名";
  34. [self.view addSubview:textField];
  35. searchTF = textField;
  36. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  37. btn.frame = CGRectMake(kSize.width - 70, 10, 50, 40);
  38. [btn borderCornorRadios:7];
  39. btn.backgroundColor = RQMianColor;
  40. [btn setTitle:@"查找" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  41. [btn target:self Tag:1];
  42. [self.view addSubview:btn];
  43. if (_keyWord.length > 0) {
  44. searchTF.text = _keyWord;
  45. [self getStudentData];
  46. }
  47. if (!_currentDate) [self creatRightNavigationItem];
  48. }
  49. //学员列表
  50. - (void)initStuList {
  51. [[UIApplication sharedApplication].keyWindow addSubview:self.stuListView];
  52. [stuListTableView reloadData];
  53. }
  54. -(UIView *)stuListView {
  55. if (!_stuListView) {
  56. _stuListView = [[UIView alloc] initWithFrame:kFrame];
  57. _stuListView.backgroundColor = windowBlockColor;
  58. stuListTableView = [[UITableView alloc] initWithFrame:CGRectMake(20, kSize.height/2.0 - 150, kSize.width - 40, 260) style:UITableViewStylePlain];
  59. [stuListTableView borderCornorRadios:5];
  60. stuListTableView.delegate = self;
  61. stuListTableView.dataSource = self;
  62. stuListTableView.rowHeight = 50;
  63. stuListTableView.estimatedSectionFooterHeight = 0;
  64. [_stuListView addSubview:stuListTableView];
  65. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake( 0, 0, kSize.width - 40, 50)];
  66. [label addSelfViewWithRect:CGRectMake(10, 49, kSize.width - 60, 1) Color:kLineColor];
  67. [label setText:@"选择学员" Font:Font21 TextColor:KTitleColor Alignment:NSTextAlignmentCenter];
  68. [stuListTableView setTableHeaderView:label];
  69. }
  70. return _stuListView;
  71. }
  72. //显示照片
  73. - (void)setMainScrollWithNSDictionary:(NSDictionary *)dic {
  74. if (!mainScroll) {
  75. mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 60, kSize.width, kSize.height - 60 - kNavOffSet)];
  76. mainScroll.delegate = self;
  77. [self.view addSubview:mainScroll];
  78. //@RQ-MARK 1.0.2修改:“人脸采集”详情模块中移除其他侧面照等四处照片并修改上传照片方式(去除审核等多种状态)
  79. NSArray *titleArray = @[@"证件照",@"正脸照"];
  80. //计算一个相片的高度
  81. CGFloat h = (kSize.width/2.0 - 20)*3/4.0 + 40 + 25;
  82. faceArrray = [NSMutableArray arrayWithCapacity:titleArray.count];
  83. for (int i = 0; i < titleArray.count; i ++) {
  84. int column = i%2;
  85. int row = i/2;
  86. FaceColloectView *face = [[FaceColloectView alloc] initWithFrame:CGRectMake(column*kSize.width/2.0, row*h, kSize.width/2.0, h)];
  87. [face borderColor:kLineColor width:0.7 cornorRadios:1];
  88. face.titleLabel.text = titleArray[i];
  89. face.superVC = self;
  90. face.type = [NSString stringWithFormat:@"%d",i];
  91. [mainScroll addSubview:face];
  92. [faceArrray addObject:face];
  93. }
  94. if (faceArrray.count > 1) {
  95. face0 = faceArrray[0];
  96. face1 = faceArrray[1];
  97. }
  98. [mainScroll setContentSize:CGSizeMake(kSize.width, CGRectGetMaxY(face1.frame) + 100)];
  99. face0.clickBtn.hidden = YES;
  100. face0.titleLabel.width += face0.titleLabel.width;
  101. }
  102. face0.titleLabel.text = [NSString stringWithFormat:@"%@\n证件照",dic[@"TSO_NAME"]];
  103. NSString *faceImgPath = dic[@"TSO_PHOTO_PATH"];
  104. if (!faceImgPath) {
  105. faceImgPath = @"";
  106. }
  107. faceImgPath = [faceImgPath stringByReplacingOccurrencesOfString:@"//tms" withString:@"/tms"];
  108. // [SDWebImageDownloader.sharedDownloader setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
  109. // forHTTPHeaderField:@"Accept"];
  110. [face0.faceImg sd_setImageWithURL:[NSURL URLWithString:faceImgPath] placeholderImage:[UIImage imageNamed:@"NOImg"]];
  111. //有新的数据就清楚之前的数据 并更新学员的ID
  112. for (FaceColloectView *faceView in faceArrray) {
  113. // faceView.dataDic = nil;
  114. faceView.stuID = dic[@"TSO_ID"];
  115. }
  116. //添加模版数据
  117. NSArray *faceList = dic[@"FACELIST"];
  118. if (faceList.count > 0) {
  119. for (NSDictionary *faceDic in faceList) {
  120. if ([faceDic[@"TYPE"] integerValue] == 0 || [faceDic[@"TYPE"] integerValue] == 1) {
  121. FaceColloectView *faceView = faceArrray[[faceDic[@"TYPE"] integerValue]];
  122. faceView.dataDic = faceDic;
  123. }
  124. // FaceColloectView *faceView = faceArrray[[faceDic[@"TYPE"] integerValue]];
  125. // faceView.dataDic = faceDic;
  126. }
  127. }
  128. }
  129. - (void)btnClick:(UIButton *)sender {
  130. if (searchTF.text.length < 1) {
  131. ShowMsg(@"请输入学员信息!");
  132. return;
  133. }
  134. [self.view endEditing:YES];
  135. _keyWord = searchTF.text;
  136. [self getStudentData];
  137. }
  138. - (void)creatRightNavigationItem {
  139. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"选择日期" style:UIBarButtonItemStylePlain target:self action:@selector(rightNavigationItemClick)];
  140. [self.navigationItem.rightBarButtonItem setTintColor:RQMianColor];
  141. }
  142. - (void)rightNavigationItemClick {
  143. [self.view endEditing:YES];
  144. self.datePicker.date = self.curDate;
  145. [self presentSemiViewController:self.datePicker withOptions:@{
  146. KNSemiModalOptionKeys.pushParentBack : @(NO),
  147. KNSemiModalOptionKeys.animationDuration : @(0.3),
  148. KNSemiModalOptionKeys.shadowOpacity : @(0.3),
  149. }];
  150. }
  151. #pragma mark tableView
  152. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  153. return stuListArray.count;
  154. }
  155. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  156. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  157. if (cell == nil) {
  158. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  159. [cell.imageView borderCornorRadios:3];
  160. cell.imageView.frame = (CGRect){10,5,40,40};
  161. cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
  162. }
  163. NSDictionary *dic = stuListArray[indexPath.row];
  164. NSString *faceImgPath = dic[@"TSO_PHOTO_PATH"];
  165. if (!faceImgPath) {
  166. faceImgPath = @"";
  167. }
  168. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:faceImgPath] placeholderImage:[UIImage imageNamed:@"NOImg"]];
  169. cell.textLabel.text = dic[@"TSO_NAME"];
  170. cell.detailTextLabel.text = dic[@"TSO_IDCARD"];
  171. return cell;
  172. }
  173. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  174. [self.stuListView removeFromSuperview];
  175. [self setMainScrollWithNSDictionary:stuListArray[indexPath.row]];
  176. }
  177. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  178. return 0.1;
  179. }
  180. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  181. return [UIView new];
  182. }
  183. #pragma mark 数据请求
  184. -(void)getStudentData{
  185. //判断网络是否连接
  186. if (![NetManager connectedToNetWork]) {
  187. showMsgUnconnect();
  188. return;
  189. }
  190. NSMutableDictionary * mdic = [NSMutableDictionary new];
  191. [mdic setValue:_keyWord forKey:@"keyWord"];
  192. //@RQ-MARK 1.0.2修改:“人脸采集”模块展示单天报名学员(可进行人脸采集)
  193. [mdic setValue:_currentDate? [self.formatter stringFromDate:_currentDate] : [self.formatter stringFromDate:self.curDate] forKey:@"applyTime"];
  194. [NetManager requestAnythingWithURL:@"getStudentList" dictionary:mdic dataArray:nil completion:^(NSDictionary *root) {
  195. if (!root) {
  196. ShowMsg(@"学员信息查询失败,请重试");
  197. return;
  198. }
  199. if ([root[@"code"] integerValue] == 1) {
  200. ShowMsg(root[@"msg"]);
  201. return;
  202. }
  203. if ([root[@"body"] count] < 1) {
  204. ShowMsg(@"查询不到该学员,请确认查询条件");
  205. return;
  206. }else if ([root[@"body"] count] == 1) {
  207. //查询到单独学员 直接显示
  208. [self setMainScrollWithNSDictionary:[root[@"body"] firstObject]];
  209. }else {
  210. //查询到多个学员 展示列表
  211. self->stuListArray = root[@"body"];
  212. [self initStuList];
  213. }
  214. }];
  215. }
  216. -(void)scrollViewDidScroll:(UIScrollView *)scrollView {
  217. [self.view endEditing:YES];
  218. }
  219. - (void)didReceiveMemoryWarning {
  220. [super didReceiveMemoryWarning];
  221. }
  222. #pragma mark - THDatePickerDelegate
  223. - (void)datePickerDonePressed:(THDatePickerViewController *)datePicker {
  224. self.curDate = datePicker.date;
  225. [self getStudentData];
  226. [self dismissSemiModalView];
  227. }
  228. - (void)datePickerCancelPressed:(THDatePickerViewController *)datePicker {
  229. [self dismissSemiModalView];
  230. }
  231. - (void)datePicker:(THDatePickerViewController *)datePicker selectedDate:(NSDate *)selectedDate {
  232. NSLog(@"Date selected: %@",[self.formatter stringFromDate:selectedDate]);
  233. }
  234. #pragma mark - Lazy Loading
  235. - (THDatePickerViewController *)datePicker {
  236. if (!_datePicker) {
  237. _datePicker = [THDatePickerViewController datePicker];
  238. _datePicker.delegate = self;
  239. _datePicker.currentDateColorSelected = RQMianColor;//当前日期被选中颜色
  240. _datePicker.currentDateColor = [UIColor redColor];//当前日期颜色
  241. _datePicker.selectedBackgroundColor = [UIColor lightGrayColor];//选中日期背景色
  242. [_datePicker setDisableYearSwitch:YES];//关闭左右滑动切换年
  243. [_datePicker setAllowClearDate:NO];
  244. [_datePicker setClearAsToday:YES];
  245. [_datePicker setAutoCloseOnSelectDate:NO];
  246. [_datePicker setAllowSelectionOfSelectedDate:YES];
  247. [_datePicker setDaysInHistorySelection:0];
  248. [_datePicker setDaysInFutureSelection:0];
  249. _datePicker.rounded = YES;
  250. }
  251. return _datePicker;
  252. }
  253. - (NSDateFormatter *)formatter {
  254. if (!_formatter) {
  255. _formatter = [[NSDateFormatter alloc] init];
  256. [_formatter setDateFormat:@"yyyy-MM-dd"];
  257. }
  258. return _formatter;
  259. }
  260. - (NSDate *)curDate {
  261. if (!_curDate) {
  262. _curDate = [NSDate date];
  263. }
  264. return _curDate;
  265. }
  266. @end