123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- //
- // SelectImgVC.m
- // jiaPeiC
- //
- // Created by apple on 16/6/30.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "SelectImgVC.h"
- #import "SelectCell.h"
- #import "HolderView.h"
- #import "STTButton.h"
- #import "UIImageView+WebCache.h"
- #import "MJPhotoBrowser.h"
- #import "MJPhoto.h"
- @interface SelectImgVC ()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
- {
- HolderView *holderV;
- UICollectionView *mainCollection;
- UIBarButtonItem *item;
- UIView *holderBar;
- UILabel *countLabel;
-
- NSMutableArray *dataArray;
- NSMutableArray *delArray;
- BOOL isEdit;
- }
- @end
- @implementation SelectImgVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- if (_skipType == 1) {
- self.title = [NSString stringWithFormat:@"%@的照片",_stuDic[@"STUNAME"]];
- }else {
- self.title = [NSString stringWithFormat:@"%@的照片",_stuDic[@"STU_NAME"]];
- }
- self.view.backgroundColor = backGroundColor;
- [self configNavBar];
-
-
- dataArray = [NSMutableArray array];
- delArray = [NSMutableArray array];
-
- // item = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStyleDone target:self action:@selector(clickToDelete)];
- // [item setTintColor:defGreen];
- // [self.navigationItem setRightBarButtonItem:item];
-
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- CGFloat width = (kSize.width - 30)/3.0;
-
- //小屏手机两列 大屏三列
- if (kSize.width == 320.0) {
- width = (kSize.width - 60)/2.0;
- [layout setItemSize:CGSizeMake(width, width + 40)];
- [layout setSectionInset:UIEdgeInsetsMake(10, 20, 20, 20)];
- }else {
- [layout setItemSize:CGSizeMake(width, width + 40)];
- [layout setSectionInset:UIEdgeInsetsMake(10, 5, 5, 5)];
- }
-
- mainCollection = [[UICollectionView alloc] initWithFrame:kFrame collectionViewLayout:layout];
- mainCollection.backgroundColor = backGroundColor;
- mainCollection.delegate = self;
- mainCollection.dataSource = self;
- [self.view addSubview:mainCollection];
-
- [mainCollection registerClass:[SelectCell class] forCellWithReuseIdentifier:@"SelectCell"];
-
- holderV = [[HolderView alloc] initWithFrame:mainCollection.frame];
- [holderV freshBlock:^{
- if (_skipType == 1) {
- [self getTrainFiles];
- }else {
- [self getStuPhotos];
- }
- }];
- [self addV:holderV];
-
- holderBar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - 50, kSize.width, 50)];
- holderBar.backgroundColor = backGroundColor;
- [self.view addSubview:holderBar];
- [holderBar setHidden:YES];
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, -2, kSize.width, 2)];
- label.backgroundColor = lineColor;
- [holderBar addSubview:label];
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 200, 50)];
- [label setText:@"您已选了0张照片噢" Font:20 TextColor:titleColor Alignment:NSTextAlignmentLeft];
- [holderBar addSubview:label];
- countLabel = label;
-
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(kSize.width - 100, 7, 90, 36);
- [btn setTitle:@"确认删除" textColor:[UIColor whiteColor] font:20 fotState:UIControlStateNormal];
- btn.layer.masksToBounds = YES;
- btn.layer.cornerRadius = 10;
- btn.backgroundColor = [UIColor orangeColor];
- [btn target:self];
- [holderBar addSubview:btn];
-
- if (_skipType == 1) {
- [self getTrainFiles];
- }else {
- [self getStuPhotos];
- }
- }
- -(void)clickToDelete
- {
- isEdit = !isEdit;
- if (isEdit) {
- //编辑 所有图片去掉交互
- item.title = @"取消";
- holderBar.hidden = NO;
- mainCollection.height -= 52;
- }else{
- //取消编辑 加上交互
- item.title = @"编辑";
- mainCollection.height += 52;
- holderBar.hidden = YES;
- }
-
- [mainCollection reloadData];
- }
- -(void)btnClick:(UIButton *)sender {
- [self delStuPhotos]; //隐藏功能 暂不开通
- }
- -(void)tapImage:(UITapGestureRecognizer *)tap
- {
- //通过dataArray获取urls
- NSMutableArray *photos = [NSMutableArray arrayWithCapacity:dataArray.count];
-
- for (int i = 0; i < dataArray.count; i ++) {
-
- NSDictionary *dic = dataArray[i];
- NSString *url = dic[@"FILEPATH"];
- NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
- NSString *str = [url stringByTrimmingCharactersInSet:whitespace];
-
- if (str.length > 0) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
- SelectCell *cell = (SelectCell *)[mainCollection cellForItemAtIndexPath:indexPath];
- MJPhoto *photo = [[MJPhoto alloc] init];
- photo.url = [NSURL URLWithString:str]; // 图片路径
- photo.srcImageView = cell.imageView; // 来源于哪个UIImageView
- [photos addObject:photo];
- }
- }
-
- // 2.显示相册
- MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
- browser.currentPhotoIndex = tap.view.tag; // 弹出相册时显示的第一张图片是?
- browser.photos = photos; // 设置所有的图片
- [browser show];
- }
- #pragma mark collection delegate
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return dataArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- /*
- 所有培训照片
- EVENT = 18;
- FILEPATH = "http://photo.lnjppt.com/syphoto/upload/12101000043/1801/12101000043_1516698197.jpg";
- ID = 38948;
- PTIME = 20180123170320;
- "STU_ID" = 2101000000021;
-
- 单条训练照片
- FACEJUDE PTIME FILEPATH
- */
- SelectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SelectCell" forIndexPath:indexPath];
- NSDictionary *dic = dataArray[indexPath.row];
- NSString *str = dic[@"FILEPATH"];
- if (!str) {
- str = @"";
- }
- [cell.imageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"noImg.png"]];
-
- NSString *timeStr = dic[@"PTIME"];
- // if (timeStr.length > 16) {
- // timeStr = [timeStr substringWithRange:NSMakeRange(5, 11)];
- // }
- cell.timeLabel.text = timeStr;
-
-
- NSString *typeString = @"";
- if (_skipType == 1) {
- typeString = [NSString stringWithFormat:@"相似度:%@%%",dic[@"FACEJUDE"]];
- }else {
- switch ([dic[@"EVENT"] integerValue]) {
- case 17:
- typeString = @"签到抓拍";
- break;
- case 18:
- typeString = @"签退抓拍";
- break;
- case 19:
- typeString = @"过程抓拍";
- break;
- default:
- break;
- }
- }
- cell.styleLabel.text = typeString;
-
- cell.imageView.tag = indexPath.row;
- if (isEdit) {
- cell.imageView.userInteractionEnabled = NO;
- }else{
- cell.imageView.userInteractionEnabled = YES;
- }
- // 事件监听
- [cell.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)]];
-
- return cell;
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (!isEdit) {
- return;
- }
- //如果手势没用的时候 再开这个用来选中删除
- SelectCell *cell = (SelectCell *)[mainCollection cellForItemAtIndexPath:indexPath];
- cell.isDelete = !cell.isDelete;
- if (cell.isDelete) {
- cell.selectView.hidden = NO;
- [delArray addObject:dataArray[indexPath.row]];
- }else{
- cell.selectView.hidden = YES;
-
- if ([delArray containsObject:dataArray[indexPath.row]]) {
- [delArray removeObject:dataArray[indexPath.row]];
- }
- }
-
- //NSLog(@"delArray-->%@",delArray);
- countLabel.text = [NSString stringWithFormat:@"您已选了%d张照片噢",(int)delArray.count];
- }
- #pragma mark 数据请求
- - (void)getTrainFiles
- {
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr = [NSMutableArray array];
- [arr addPro:@"classId" Value:_stuDic[@"CLASSID"]];
- [arr addPro:@"stuId" Value:_stuDic[@"STUID"]];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
-
- NSString* method = @"getTrainFiles";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- RemoveHUD();
- [holderV setHidden:NO];
- if (!root) {
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
-
- ShowMsg(root[@"body"]);
- return;
- }
- if ([root[@"body"] count] == 0) {
- return;
- }
-
- dataArray = root[@"body"];
-
- [holderV setHidden:YES];
- [mainCollection reloadData];
- }];
- }
- - (void)getStuPhotos
- {
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr = [NSMutableArray array];
-
- [arr addPro:@"stuId" Value:_stuDic[@"TSO_ID"]];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
-
- NSString* method = @"getStuPhotos";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- RemoveHUD();
- [holderV setHidden:NO];
- if (!root) {
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
-
- ShowMsg(root[@"body"]);
- return;
- }
- if ([root[@"body"] count] == 0) {
- return;
- }
-
- dataArray = root[@"body"];
-
- [holderV setHidden:YES];
- [mainCollection reloadData];
- }];
- }
- - (void)delStuPhotos
- {
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSString *delString = @"";
- for (NSDictionary *dic in delArray) {
-
- delString = [delString stringByAppendingString:[NSString stringWithFormat:@"%@,",dic[@"ID"]]];
- }
- if (delString.length > 0) {
- delString = [delString substringToIndex:delString.length - 1];
- }
- NSMutableArray *arr = [NSMutableArray array];
- [arr addPro:@"ids" Value:delString];
- [arr addPro:@"zjhm" Value:_stuDic[@"STU_SFZHM"]];
-
- NSString* method = @"delStuPhotos";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- RemoveHUD();
- if (!root) {
- ShowMsg(@"删除失败");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
-
- ShowMsg(root[@"body"]);
- return;
- }
- //成功要刷新
- [self getStuPhotos];
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|