FaceColloectVC.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. @interface FaceColloectVC ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
  11. {
  12. UITextField *searchTF;
  13. UIScrollView *mainScroll;
  14. UITableView *stuListTableView;
  15. FaceColloectView *face0,*face1,*face2,*face3,*face4,*face5;
  16. NSMutableArray *faceArrray;
  17. NSArray *stuListArray;
  18. }
  19. @property (nonatomic, strong) UIView *stuListView;
  20. @end
  21. @implementation FaceColloectVC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.view.backgroundColor = [UIColor whiteColor];
  25. self.navigationItem.title = @"人脸采集";
  26. [self goBackByNavigation];
  27. UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10, kSize.width - 100, 40)];
  28. textField.borderStyle = UITextBorderStyleRoundedRect;
  29. textField.placeholder = @"请输入学员证件或手机号";
  30. [self.view addSubview:textField];
  31. searchTF = textField;
  32. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  33. btn.frame = CGRectMake(kSize.width - 70, 10, 50, 40);
  34. [btn borderCornorRadios:7];
  35. btn.backgroundColor = defGreen;
  36. [btn setTitle:@"查找" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  37. [btn target:self Tag:1];
  38. [self.view addSubview:btn];
  39. if (_keyWord.length > 0) {
  40. searchTF.text = _keyWord;
  41. [self getStudentData];
  42. }
  43. }
  44. //学员列表
  45. - (void)initStuList {
  46. [[UIApplication sharedApplication].keyWindow addSubview:self.stuListView];
  47. [stuListTableView reloadData];
  48. }
  49. -(UIView *)stuListView {
  50. if (!_stuListView) {
  51. _stuListView = [[UIView alloc] initWithFrame:kFrame];
  52. _stuListView.backgroundColor = windowBlockColor;
  53. stuListTableView = [[UITableView alloc] initWithFrame:CGRectMake(20, kSize.height/2.0 - 150, kSize.width - 40, 260) style:UITableViewStylePlain];
  54. [stuListTableView borderCornorRadios:5];
  55. stuListTableView.delegate = self;
  56. stuListTableView.dataSource = self;
  57. stuListTableView.rowHeight = 50;
  58. stuListTableView.estimatedSectionFooterHeight = 0;
  59. [_stuListView addSubview:stuListTableView];
  60. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake( 0, 0, kSize.width - 40, 50)];
  61. [label addSelfViewWithRect:CGRectMake(10, 49, kSize.width - 60, 1) Color:kLineColor];
  62. [label setText:@"选择学员" Font:Font21 TextColor:KTitleColor Alignment:NSTextAlignmentCenter];
  63. [stuListTableView setTableHeaderView:label];
  64. }
  65. return _stuListView;
  66. }
  67. //显示照片
  68. - (void)setMainScrollWithNSDictionary:(NSDictionary *)dic {
  69. if (!mainScroll) {
  70. mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 60, kSize.width, kSize.height - 60 - kNavOffSet)];
  71. mainScroll.delegate = self;
  72. [self.view addSubview:mainScroll];
  73. NSArray *titleArray = @[@"证件照",@"正脸照"];//,@"左侧脸照",@"右侧脸照",@"抬头照",@"低头照"
  74. //计算一个相片的高度
  75. CGFloat h = (kSize.width/2.0 - 20)*3/4.0 + 40 + 25;
  76. faceArrray = [NSMutableArray arrayWithCapacity:6];
  77. for (int i = 0; i < titleArray.count; i ++) {
  78. int column = i%2;
  79. int row = i/2;
  80. FaceColloectView *face = [[FaceColloectView alloc] initWithFrame:CGRectMake(column*kSize.width/2.0, row*h, kSize.width/2.0, h)];
  81. [face borderColor:kLineColor width:0.7 cornorRadios:1];
  82. face.titleLabel.text = titleArray[i];
  83. face.superVC = self;
  84. face.type = [NSString stringWithFormat:@"%d",i];
  85. [mainScroll addSubview:face];
  86. [faceArrray addObject:face];
  87. }
  88. if (faceArrray.count > 1) {
  89. face0 = faceArrray[0];
  90. face1 = faceArrray[1];
  91. // face2 = faceArrray[2];
  92. // face3 = faceArrray[3];
  93. // face4 = faceArrray[4];
  94. // face5 = faceArrray[5];
  95. }
  96. [mainScroll setContentSize:CGSizeMake(kSize.width, CGRectGetMaxY(face1.frame) + 100)];
  97. face0.clickBtn.hidden = YES;
  98. face0.titleLabel.width += face0.titleLabel.width;
  99. }
  100. face0.titleLabel.text = [NSString stringWithFormat:@"%@\n证件照",dic[@"TSO_NAME"]];
  101. NSString *faceImgPath = dic[@"TSO_PHOTO_PATH"];
  102. if (!faceImgPath) {
  103. faceImgPath = @"";
  104. }
  105. faceImgPath = [faceImgPath stringByReplacingOccurrencesOfString:@"//tms" withString:@"/tms"];
  106. // [SDWebImageDownloader.sharedDownloader setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
  107. // forHTTPHeaderField:@"Accept"];
  108. [face0.faceImg sd_setImageWithURL:[NSURL URLWithString:faceImgPath] placeholderImage:[UIImage imageNamed:@"NOImg"]];
  109. //有新的数据就清除之前的数据 并更新学员的ID
  110. for (FaceColloectView *faceView in faceArrray) {
  111. // faceView.dataDic = nil;
  112. faceView.stuID = dic[@"TSO_ID"];
  113. }
  114. //说明模版不够
  115. // if (faceArrray.count < 6) {
  116. // return;
  117. // }
  118. //添加模版数据
  119. NSArray *faceList = dic[@"FACELIST"];
  120. if (faceList.count > 0) {
  121. for (NSDictionary *faceDic in faceList) {
  122. if ([faceDic[@"TYPE"] integerValue] == 0 || [faceDic[@"TYPE"] integerValue] == 1) {
  123. FaceColloectView *faceView = faceArrray[[faceDic[@"TYPE"] integerValue]];
  124. faceView.dataDic = faceDic;
  125. }
  126. // FaceColloectView *faceView = faceArrray[[faceDic[@"TYPE"] integerValue]];
  127. // faceView.dataDic = faceDic;
  128. }
  129. }
  130. }
  131. - (void)btnClick:(UIButton *)sender {
  132. if (searchTF.text.length < 1) {
  133. ShowMsg(@"请输入学员信息!");
  134. return;
  135. }
  136. [self.view endEditing:YES];
  137. _keyWord = searchTF.text;
  138. [self getStudentData];
  139. }
  140. #pragma mark tableView
  141. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  142. return stuListArray.count;
  143. }
  144. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  145. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  146. if (cell == nil) {
  147. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  148. [cell.imageView borderCornorRadios:3];
  149. cell.imageView.frame = (CGRect){10,5,40,40};
  150. cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
  151. }
  152. NSDictionary *dic = stuListArray[indexPath.row];
  153. NSString *faceImgPath = dic[@"TSO_PHOTO_PATH"];
  154. if (!faceImgPath) {
  155. faceImgPath = @"";
  156. }
  157. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:faceImgPath] placeholderImage:[UIImage imageNamed:@"NOImg"]];
  158. cell.textLabel.text = dic[@"TSO_NAME"];
  159. cell.detailTextLabel.text = dic[@"TSO_IDCARD"];
  160. return cell;
  161. }
  162. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  163. [self.stuListView removeFromSuperview];
  164. [self setMainScrollWithNSDictionary:stuListArray[indexPath.row]];
  165. }
  166. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  167. return 0.1;
  168. }
  169. #pragma mark 数据请求
  170. -(void)getStudentData{
  171. //判断网络是否连接
  172. if (![NetManager connectedToNetWork]) {
  173. showMsgUnconnect();
  174. return;
  175. }
  176. NSMutableDictionary * mdic = [NSMutableDictionary new];
  177. [mdic setValue:_keyWord forKey:@"keyWord"];
  178. [MBProgressHUD showLoadToView:self.view];
  179. [NetManager requestAnythingWithURL:@"getStudentList" dictionary:mdic dataArray:nil completion:^(NSDictionary *root) {
  180. [MBProgressHUD hideHUDForView:self.view];
  181. if (!root) {
  182. ShowMsg(@"学员信息查询失败,请重试");
  183. return;
  184. }
  185. if ([root[@"code"] integerValue] == 1) {
  186. ShowMsg(root[@"msg"]);
  187. return;
  188. }
  189. if ([root[@"body"] count] < 1) {
  190. ShowMsg(@"查询不到该学员,请确认查询条件");
  191. return;
  192. }else if ([root[@"body"] count] == 1) {
  193. //查询到单独学员 直接显示
  194. [self setMainScrollWithNSDictionary:[root[@"body"] firstObject]];
  195. }else {
  196. //查询到多个学员 展示列表
  197. stuListArray = root[@"body"];
  198. [self initStuList];
  199. }
  200. }];
  201. }
  202. -(void)scrollViewDidScroll:(UIScrollView *)scrollView {
  203. [self.view endEditing:YES];
  204. }
  205. - (void)didReceiveMemoryWarning {
  206. [super didReceiveMemoryWarning];
  207. }
  208. @end