FaceColloectView.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. //
  2. // FaceColloectView.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/9/12.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "FaceColloectView.h"
  9. #import "PureCamera.h"
  10. #import "HKClipperHelper.h"
  11. static QMUIAlbumContentType const kAlbumContentType = QMUIAlbumContentTypeAll;
  12. @interface FaceColloectView () <QMUIAlbumViewControllerDelegate>
  13. @end
  14. @implementation FaceColloectView
  15. -(instancetype)initWithFrame:(CGRect)frame {
  16. self = [super initWithFrame:frame];
  17. if (self) {
  18. CGFloat y = 10;
  19. CGFloat w = frame.size.width - 20;
  20. _faceImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, y, w, w*3/4.0)];
  21. // [_faceImg borderColor:[UIColor grayColor] width:0.5 cornorRadios:3];
  22. [_faceImg borderCornorRadios:3];
  23. _faceImg.contentMode = UIViewContentModeScaleAspectFit;
  24. _faceImg.image = [UIImage imageNamed:@"NOImg"];
  25. [self addSubview:_faceImg];
  26. y += w*3/4.0 + 5;
  27. _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, y, w/2.0, 40)];
  28. _titleLabel.numberOfLines = 0;
  29. [_titleLabel setText:@"" Font:Font18 TextColor:KTitleColor Alignment:NSTextAlignmentCenter];
  30. [self addSubview:_titleLabel];
  31. _clickBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  32. _clickBtn.frame = (CGRect){10 + w/2.0,y,w/2.0,40};
  33. [_clickBtn borderCornorRadios:7];
  34. _clickBtn.backgroundColor = defGreen;
  35. [_clickBtn setTitle:@"拍照" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  36. [_clickBtn target:self Tag:1];
  37. [self addSubview:_clickBtn];
  38. }
  39. return self;
  40. }
  41. -(void)setDataDic:(NSDictionary *)dataDic {
  42. _dataDic = dataDic;
  43. if (dataDic == nil) {
  44. _faceImg.image = [UIImage imageNamed:@"NOImg"];
  45. [_clickBtn setTitle:@"拍照" forState:UIControlStateNormal];
  46. _clickBtn.tag = 1;
  47. return;
  48. }
  49. NSString *faceImgPath = dataDic[@"FACE"];
  50. if (!faceImgPath) {
  51. faceImgPath = @"";
  52. }
  53. [_faceImg sd_setImageWithURL:[NSURL URLWithString:faceImgPath] placeholderImage:[UIImage imageNamed:@"NOImg"]];
  54. [_clickBtn setTitle:@"拍照" forState:UIControlStateNormal];
  55. _clickBtn.tag = 1;
  56. //0不能修改 1可以修改 2审核中
  57. // if ([dataDic[@"STATE"] integerValue] == 0) {
  58. // [_clickBtn setTitle:@"申请修改" forState:UIControlStateNormal];
  59. // _clickBtn.tag = 3;
  60. // }else if([dataDic[@"STATE"] integerValue] == 1) {
  61. //
  62. // [_clickBtn setTitle:@"拍照" forState:UIControlStateNormal];
  63. // _clickBtn.tag = 1;
  64. // }else if([dataDic[@"STATE"] integerValue] == 2) {
  65. //
  66. // [_clickBtn setTitle:@"审核中" forState:UIControlStateNormal];
  67. // _clickBtn.tag = 4;
  68. // }
  69. }
  70. - (void)btnClick:(UIButton *)sender {
  71. switch (sender.tag) {
  72. case 1://拍照
  73. [self takePhoto];
  74. break;
  75. case 2://上传
  76. {
  77. //上传照片
  78. [self imgCropUpload];
  79. // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"照片上传成功后,需要向相关部门申请通过后方可更改,是否确认上传照片" preferredStyle:UIAlertControllerStyleAlert];
  80. //
  81. // UIAlertAction *againAction = [UIAlertAction actionWithTitle:@"重新拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  82. // _faceImg.image = [UIImage imageNamed:@"NOImg"];
  83. //
  84. // _clickBtn.tag = 1;
  85. // [_clickBtn setTitle:@"拍照" forState:UIControlStateNormal];
  86. // }];
  87. // [alert addAction:againAction];
  88. //
  89. // UIAlertAction *downloadAction = [UIAlertAction actionWithTitle:@"继续上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  90. // //上传照片
  91. // [self imgCropUpload];
  92. // }];
  93. // [alert addAction:downloadAction];
  94. // [_superVC presentViewController:alert animated:YES completion:nil];
  95. }
  96. break;
  97. case 3://申请修改
  98. [self updateApplyStuFace];
  99. break;
  100. case 4://审核中 不能操作
  101. {
  102. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"该照片已申请修改重拍,正在等待审核" preferredStyle:UIAlertControllerStyleAlert];
  103. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  104. [_superVC presentViewController:alert animated:YES completion:nil];
  105. }
  106. break;
  107. default:
  108. break;
  109. }
  110. }
  111. //拍照
  112. - (void)takePhoto {
  113. QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"拍照" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
  114. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  115. PureCamera *vc = [[PureCamera alloc] init];
  116. vc.fininshcapture = ^(UIImage *photo) {
  117. if (photo) {
  118. _faceImg.image = photo;
  119. _clickBtn.tag = 2;
  120. [_clickBtn setTitle:@"上传" forState:UIControlStateNormal];
  121. }
  122. };
  123. [_superVC presentViewController:vc
  124. animated:NO
  125. completion:nil];
  126. } else {
  127. NSLog(@"相机调用失败");
  128. }
  129. }];
  130. QMUIAlertAction *action2 = [QMUIAlertAction actionWithTitle:@"本地照片" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
  131. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
  132. [HKClipperHelper shareManager].nav = _superVC.navigationController;
  133. [HKClipperHelper shareManager].clippedImgSize = _faceImg.frame.size;
  134. [HKClipperHelper shareManager].clippedImageHandler = ^(UIImage *photo) {
  135. _faceImg.image = photo;
  136. _clickBtn.tag = 2;
  137. [_clickBtn setTitle:@"上传" forState:UIControlStateNormal];
  138. };
  139. [HKClipperHelper shareManager].clipperType = ClipperTypeImgMove;
  140. [HKClipperHelper shareManager].systemEditing = NO;
  141. [HKClipperHelper shareManager].isSystemType = YES;
  142. [[HKClipperHelper shareManager] photoWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
  143. }else{
  144. NSLog(@"相册调用失败");
  145. }
  146. }];
  147. QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"人脸采集" message:@"请选择获取图片方式" preferredStyle:QMUIAlertControllerStyleAlert];
  148. [alertController addAction:action1];
  149. [alertController addAction:action2];
  150. [alertController showWithAnimated:YES];
  151. }
  152. //上传与修改照片
  153. - (void)imgCropUpload {
  154. //判断网络是否连接
  155. if (![NetManager connectedToNetWork]) {
  156. showMsgUnconnect();
  157. return;
  158. }
  159. UIImage *image = [UIImage fixOrientation:_faceImg.image];
  160. //处理照片
  161. NSData *data = UIImageJPEGRepresentation(image,1.0);
  162. if (data.length > 50*1024) {
  163. //如果图片大于50kb 就压缩
  164. data = UIImageJPEGRepresentation(image,0.5);
  165. }
  166. NSString *photoString = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
  167. // NSLog(@"原图---->>>>%f\n处理后---->>>>%f",[UIImageJPEGRepresentation(image,1.0) length]/1024.0,data.length/1024.0);
  168. //判断是否有模版ID
  169. NSString *faceId = @"";
  170. if (_dataDic) {
  171. faceId = _dataDic[@"ID"];
  172. }
  173. NSMutableDictionary * dic = [NSMutableDictionary new];
  174. [dic setValue:_type forKey:@"uploadType"];
  175. [dic setValue:_stuID forKey:@"stuId"];
  176. [dic setValue:photoString forKey:@"content"];
  177. [dic setValue:faceId forKey:@"faceId"];
  178. [MBProgressHUD showLoadToView:self];
  179. [NetManager requestAnythingWithURL:@"imgCropUpload" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  180. [MBProgressHUD hideHUDForView:self];
  181. if (!root) {
  182. ShowMsg(@"上传失败,请重试!");
  183. return;
  184. }
  185. if ([root[@"code"] integerValue] == 1) {
  186. ShowMsg(root[@"msg"]);
  187. return;
  188. }
  189. ShowMsg(@"上传成功!");
  190. // [_clickBtn setTitle:@"申请修改" forState:UIControlStateNormal];
  191. // _clickBtn.tag = 3;
  192. [_clickBtn setTitle:@"拍照" forState:UIControlStateNormal];
  193. _clickBtn.tag = 1;
  194. }];
  195. }
  196. //申请修改
  197. - (void)updateApplyStuFace {
  198. //判断网络是否连接
  199. if (![NetManager connectedToNetWork]) {
  200. showMsgUnconnect();
  201. return;
  202. }
  203. NSMutableDictionary * dic = [NSMutableDictionary new];
  204. [dic setValue:_dataDic[@"ID"] forKey:@"id"];
  205. [MBProgressHUD showLoadToView:self];
  206. [NetManager requestAnythingWithURL:@"updateApplyStuFace" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  207. [MBProgressHUD hideHUDForView:self];
  208. if (!root) {
  209. ShowMsg(@"操作失败,请重试!");
  210. return;
  211. }
  212. if ([root[@"code"] integerValue] == 1) {
  213. ShowMsg(root[@"msg"]);
  214. return;
  215. }
  216. ShowMsg(@"申请修改成功!正在等待审核");
  217. [_clickBtn setTitle:@"审核中" forState:UIControlStateNormal];
  218. _clickBtn.tag = 4;
  219. }];
  220. }
  221. /*
  222. // Only override drawRect: if you perform custom drawing.
  223. // An empty implementation adversely affects performance during animation.
  224. - (void)drawRect:(CGRect)rect {
  225. // Drawing code
  226. }
  227. */
  228. @end