123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- //
- // FaceColloectView.m
- // LN_School
- //
- // Created by apple on 2017/9/12.
- // Copyright © 2017年 Danson. All rights reserved.
- //
- #import "FaceColloectView.h"
- #import "PureCamera.h"
- #import "HKClipperHelper.h"
- static QMUIAlbumContentType const kAlbumContentType = QMUIAlbumContentTypeAll;
- @interface FaceColloectView () <QMUIAlbumViewControllerDelegate>
- @end
- @implementation FaceColloectView
- -(instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
-
- CGFloat y = 10;
- CGFloat w = frame.size.width - 20;
- _faceImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, y, w, w*3/4.0)];
- // [_faceImg borderColor:[UIColor grayColor] width:0.5 cornorRadios:3];
- [_faceImg borderCornorRadios:3];
- _faceImg.contentMode = UIViewContentModeScaleAspectFit;
- _faceImg.image = [UIImage imageNamed:@"NOImg"];
- [self addSubview:_faceImg];
-
-
- y += w*3/4.0 + 5;
- _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, y, w/2.0, 40)];
- _titleLabel.numberOfLines = 0;
- [_titleLabel setText:@"" Font:Font18 TextColor:KTitleColor Alignment:NSTextAlignmentCenter];
- [self addSubview:_titleLabel];
-
-
- _clickBtn = [UIButton buttonWithType:UIButtonTypeSystem];
- _clickBtn.frame = (CGRect){10 + w/2.0,y,w/2.0,40};
- [_clickBtn borderCornorRadios:7];
- _clickBtn.backgroundColor = defGreen;
- [_clickBtn setTitle:@"拍照" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
- [_clickBtn target:self Tag:1];
- [self addSubview:_clickBtn];
- }
- return self;
- }
- -(void)setDataDic:(NSDictionary *)dataDic {
-
- _dataDic = dataDic;
-
- if (dataDic == nil) {
- _faceImg.image = [UIImage imageNamed:@"NOImg"];
- [_clickBtn setTitle:@"拍照" forState:UIControlStateNormal];
- _clickBtn.tag = 1;
- return;
- }
-
- NSString *faceImgPath = dataDic[@"FACE"];
- if (!faceImgPath) {
- faceImgPath = @"";
- }
- [_faceImg sd_setImageWithURL:[NSURL URLWithString:faceImgPath] placeholderImage:[UIImage imageNamed:@"NOImg"]];
-
- [_clickBtn setTitle:@"拍照" forState:UIControlStateNormal];
- _clickBtn.tag = 1;
- //0不能修改 1可以修改 2审核中
- // if ([dataDic[@"STATE"] integerValue] == 0) {
- // [_clickBtn setTitle:@"申请修改" forState:UIControlStateNormal];
- // _clickBtn.tag = 3;
- // }else if([dataDic[@"STATE"] integerValue] == 1) {
- //
- // [_clickBtn setTitle:@"拍照" forState:UIControlStateNormal];
- // _clickBtn.tag = 1;
- // }else if([dataDic[@"STATE"] integerValue] == 2) {
- //
- // [_clickBtn setTitle:@"审核中" forState:UIControlStateNormal];
- // _clickBtn.tag = 4;
- // }
- }
- - (void)btnClick:(UIButton *)sender {
-
- switch (sender.tag) {
- case 1://拍照
- [self takePhoto];
- break;
-
- case 2://上传
- {
- //上传照片
- [self imgCropUpload];
- // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"照片上传成功后,需要向相关部门申请通过后方可更改,是否确认上传照片" preferredStyle:UIAlertControllerStyleAlert];
- //
- // UIAlertAction *againAction = [UIAlertAction actionWithTitle:@"重新拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // _faceImg.image = [UIImage imageNamed:@"NOImg"];
- //
- // _clickBtn.tag = 1;
- // [_clickBtn setTitle:@"拍照" forState:UIControlStateNormal];
- // }];
- // [alert addAction:againAction];
- //
- // UIAlertAction *downloadAction = [UIAlertAction actionWithTitle:@"继续上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // //上传照片
- // [self imgCropUpload];
- // }];
- // [alert addAction:downloadAction];
-
- // [_superVC presentViewController:alert animated:YES completion:nil];
- }
- break;
-
- case 3://申请修改
- [self updateApplyStuFace];
- break;
-
- case 4://审核中 不能操作
- {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"该照片已申请修改重拍,正在等待审核" preferredStyle:UIAlertControllerStyleAlert];
- [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
- [_superVC presentViewController:alert animated:YES completion:nil];
- }
- break;
-
- default:
- break;
- }
- }
- //拍照
- - (void)takePhoto {
-
- QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"拍照" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
- if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
- PureCamera *vc = [[PureCamera alloc] init];
- vc.fininshcapture = ^(UIImage *photo) {
- if (photo) {
- _faceImg.image = photo;
-
- _clickBtn.tag = 2;
- [_clickBtn setTitle:@"上传" forState:UIControlStateNormal];
- }
- };
- [_superVC presentViewController:vc
- animated:NO
- completion:nil];
-
- } else {
- NSLog(@"相机调用失败");
- }
- }];
- QMUIAlertAction *action2 = [QMUIAlertAction actionWithTitle:@"本地照片" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
- if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
-
- [HKClipperHelper shareManager].nav = _superVC.navigationController;
- [HKClipperHelper shareManager].clippedImgSize = _faceImg.frame.size;
- [HKClipperHelper shareManager].clippedImageHandler = ^(UIImage *photo) {
-
- _faceImg.image = photo;
- _clickBtn.tag = 2;
- [_clickBtn setTitle:@"上传" forState:UIControlStateNormal];
- };
-
- [HKClipperHelper shareManager].clipperType = ClipperTypeImgMove;
- [HKClipperHelper shareManager].systemEditing = NO;
- [HKClipperHelper shareManager].isSystemType = YES;
- [[HKClipperHelper shareManager] photoWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
- }else{
- NSLog(@"相册调用失败");
- }
- }];
- QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"人脸采集" message:@"请选择获取图片方式" preferredStyle:QMUIAlertControllerStyleAlert];
- [alertController addAction:action1];
- [alertController addAction:action2];
- [alertController showWithAnimated:YES];
- }
- //上传与修改照片
- - (void)imgCropUpload {
- //判断网络是否连接
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- UIImage *image = [UIImage fixOrientation:_faceImg.image];
- //处理照片
- NSData *data = UIImageJPEGRepresentation(image,1.0);
-
- if (data.length > 50*1024) {
- //如果图片大于50kb 就压缩
- data = UIImageJPEGRepresentation(image,0.5);
- }
-
- NSString *photoString = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
-
- // NSLog(@"原图---->>>>%f\n处理后---->>>>%f",[UIImageJPEGRepresentation(image,1.0) length]/1024.0,data.length/1024.0);
-
- //判断是否有模版ID
- NSString *faceId = @"";
- if (_dataDic) {
- faceId = _dataDic[@"ID"];
- }
-
- NSMutableDictionary * dic = [NSMutableDictionary new];
- [dic setValue:_type forKey:@"uploadType"];
- [dic setValue:_stuID forKey:@"stuId"];
- [dic setValue:photoString forKey:@"content"];
- [dic setValue:faceId forKey:@"faceId"];
-
- [MBProgressHUD showLoadToView:self];
- [NetManager requestAnythingWithURL:@"imgCropUpload" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
-
- [MBProgressHUD hideHUDForView:self];
-
- if (!root) {
- ShowMsg(@"上传失败,请重试!");
- return;
- }
- if ([root[@"code"] integerValue] == 1) {
- ShowMsg(root[@"msg"]);
- return;
- }
-
- ShowMsg(@"上传成功!");
-
- // [_clickBtn setTitle:@"申请修改" forState:UIControlStateNormal];
- // _clickBtn.tag = 3;
-
- [_clickBtn setTitle:@"拍照" forState:UIControlStateNormal];
- _clickBtn.tag = 1;
-
- }];
- }
- //申请修改
- - (void)updateApplyStuFace {
-
- //判断网络是否连接
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableDictionary * dic = [NSMutableDictionary new];
- [dic setValue:_dataDic[@"ID"] forKey:@"id"];
-
- [MBProgressHUD showLoadToView:self];
- [NetManager requestAnythingWithURL:@"updateApplyStuFace" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
-
- [MBProgressHUD hideHUDForView:self];
-
- if (!root) {
- ShowMsg(@"操作失败,请重试!");
- return;
- }
- if ([root[@"code"] integerValue] == 1) {
- ShowMsg(root[@"msg"]);
- return;
- }
-
- ShowMsg(@"申请修改成功!正在等待审核");
-
- [_clickBtn setTitle:@"审核中" forState:UIControlStateNormal];
- _clickBtn.tag = 4;
- }];
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|