// // MyPlanVC.m // jiaPeiC // // Created by apple on 16/3/27. // Copyright © 2016年 JCZ. All rights reserved. // #import "MyPlanVC.h" #import "PlanCell.h" #import "MyPlanVCHeader.h" #import "CLWeeklyCalendarView.h" #import "STTButton.h" #import "ReplyCell.h" #import "DES3Util.h" #import "Tools.h" #import "SDSoundPlayer.h" //地图 #import #import @interface MyPlanVC () { //表的编辑 不包括计时 UITableView *myTableView; HolderView *holderV; UIButton *selectedBtn; UIButton *editBtn; UIView *holderBar; NSArray *models; NSMutableArray *stts; NSMutableArray *selectedRowArray; NSInteger currentEditSection; NSInteger stateInt; NSInteger planViewType; //区头样式 0已同意 1待审核 2已拒绝 NSString *dateString; BOOL isAllSelect; BOOL isOpen[40]; //计时 NSTimer *timer; UILabel *timerLabel; UIImageView *scanImgView; UIView *scanView;//二维码页面 NSDictionary *coachSignInDic; //NSArray *stuListArray; NSDictionary *stuSignInDic; NSInteger scanTag; BOOL isAfterDelay; BOOL isOverScan; int timeI; //地图定位 BMKLocationManager *_locService; CLLocationCoordinate2D myLocation; } @property (nonatomic, strong) CLWeeklyCalendarView* calendarView; @end @implementation MyPlanVC - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if (timer) { //感觉是没用的下边有判断 这里保留吧 防止scanView不在 定时器还在跑的状况 目测是不会发生的 就当是保险吧 [timer invalidate]; timer = nil; } if (scanView) { [self removeScanView]; } } -(void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; RemoveHUD(); } -(void)myInit { self.view.backgroundColor = backGroundColor; stateInt = 2; planViewType = 1; isAllSelect = NO; dateString = @""; currentEditSection = -1; selectedRowArray = [NSMutableArray array]; stuSignInDic = [NSDictionary dictionary]; [self.view addSubview:self.calendarView]; self.calendarView.userInteractionEnabled = YES; CGFloat y = kNavOffSet + self.calendarView.height; //UITableView* tv = [[UITableView alloc] initWithFrame:kFrame]; UITableView* tv = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStyleGrouped]; tv.y = y; tv.height = kSize.height - tv.y - 50 -SafeAreaBottomHeight; [tv setDelegate:self]; [tv setDataSource:self]; [self addV:tv]; myTableView = tv; myTableView.userInteractionEnabled = YES; [tv setTableFooterView:[UIView new]]; holderV = [[HolderView alloc] initWithFrame:tv.frame]; [self addV:holderV]; y = kSize.height - 50 -SafeAreaBottomHeight; UIView *tabBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 50)]; tabBar.backgroundColor = backGroundColor; [self.view addSubview:tabBar]; [tabBar addSelfViewWithRect:CGRectMake(0, 0, kSize.width, 1)]; CGFloat wid = kSize.width/3.0; NSArray *imageName = @[@"stt1.png",@"stt2.png",@"stt3.png"]; NSArray *titles = @[@"已完成",@"待确认",@"已拒绝"]; stts = [NSMutableArray array]; for (int i = 0; i < 3; i ++) { STTButton *sttBtn = [[STTButton alloc] initWithFrame:CGRectMake(wid*i, 0, wid, 50)]; [sttBtn setImage:[UIImage imageNamed:imageName[i]] forState:UIControlStateNormal]; [sttBtn setTitle:titles[i] forState:UIControlStateNormal]; //设置初始的状态颜色 默认已完成显示为绿色 其他为contentTextColor if (i == 1) { [sttBtn setImage:[[UIImage imageNamed:imageName[i]] tint:defGreen] forState:UIControlStateNormal]; [sttBtn setTitleColor:defGreen forState:UIControlStateNormal]; }else{ [sttBtn setImage:[[UIImage imageNamed:imageName[i]] tint:contentTextColor] forState:UIControlStateNormal]; [sttBtn setTitleColor:contentTextColor forState:UIControlStateNormal]; } [sttBtn target:self Tag:i - 3];//-3 -2 -1 [tabBar addSubview:sttBtn]; [stts addObject:sttBtn]; } holderBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 50)]; holderBar.backgroundColor = backGroundColor; [self.view addSubview:holderBar]; [holderBar setHidden:YES]; STTButton *holderBtn = [[STTButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width/2.0, 50)]; [holderBtn setTitle:@"批量同意" forState:UIControlStateNormal]; [holderBtn setImage:[UIImage imageNamed:@"stt1.png"] forState:UIControlStateNormal]; [holderBtn setImage:[[UIImage imageNamed:@"stt1.png"] tint:defGreen] forState:UIControlStateHighlighted]; [holderBtn setTitleColor:contentTextColor forState:UIControlStateNormal]; [holderBtn setTitleColor:defGreen forState:UIControlStateHighlighted]; [holderBtn target:self Tag:-4]; [holderBar addSubview:holderBtn]; holderBtn = [[STTButton alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0, 50)]; [holderBtn setTitle:@"批量拒绝" forState:UIControlStateNormal]; [holderBtn setImage:[UIImage imageNamed:@"stt3.png"] forState:UIControlStateNormal]; [holderBtn setImage:[[UIImage imageNamed:@"stt3.png"] tint:defGreen] forState:UIControlStateHighlighted]; [holderBtn setTitleColor:contentTextColor forState:UIControlStateNormal]; [holderBtn setTitleColor:defGreen forState:UIControlStateHighlighted]; [holderBtn target:self Tag:-5]; [holderBar addSubview:holderBtn]; //初始化BMKLocationService if (![_locService isKindOfClass:[BMKLocationManager class]]) { _locService = [[BMKLocationManager alloc]init]; _locService.desiredAccuracy = kCLLocationAccuracyBest; _locService.delegate = self; [_locService startUpdatingLocation]; } [self getCoachSignForTrain]; } //日历控件的初始化和点击回调 -(CLWeeklyCalendarView *)calendarView { if(!_calendarView){ _calendarView = [[CLWeeklyCalendarView alloc] initWithFrame:CGRectMake(0, kNavOffSet, kSize.width, 120)]; _calendarView.delegate = self; } return _calendarView; } #pragma mark - CLWeeklyCalendarViewDelegate -(NSDictionary *)CLCalendarBehaviorAttributes { //CLCalendarSelectedDatePrintFormatDefault 显示选中日期格式 return @{ //CLCalendarWeekStartDay : @2, //Start Day of the week, from 1-7 Mon-Sun -- default 1 // CLCalendarDayTitleTextColor : [UIColor yellowColor], // CLCalendarSelectedDatePrintColor : [UIColor greenColor], }; } -(void)dailyCalendarViewDidSelect:(NSDate *)date { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd"]; if (![dateString isEqualToString:[formatter stringFromDate:date]]) { //改变日期 这里要将编辑的值全部置零 [self setSelectToZero]; [holderBar setHidden:YES]; } dateString = [formatter stringFromDate:date]; [self getPlanInfos]; } #pragma mark 地图delegate /**用户拒绝开启定位服务等原因导致的定位失败会调用的方法 */ - (void)BMKLocationManager:(BMKLocationManager *)manager didFailWithError:(NSError *)error { UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请在iPhone的“设置”-“隐私”-“定位服务”功能中,找到“优易学车”打开位置访问权限" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alert show]; } //处理位置坐标更新 - (void)BMKLocationManager:(BMKLocationManager *)manager didUpdateLocation:(BMKLocation *)location orError:(NSError *)error { if (location.location) { [_locService stopUpdatingLocation]; //储存自己当前位置 myLocation = location.location.coordinate; } } #pragma mark 触发方法 //cell的按钮的回调方法 -(void)btnClick:(UIButton *)sender { if (sender.tag > 3999) { //这里更改区是否展开状态 isOpen[sender.tag - 4000] = !isOpen[sender.tag - 4000]; [myTableView reloadData]; return; } if (sender.tag == -11) { NSArray *array = [models[scanTag/100] objectForKey:@"reserveInfoList"]; NSDate *effectiveDate = [NSDate dateWithTimeIntervalSinceNow:600]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *dateStr = [formatter stringFromDate:effectiveDate]; NSString *scanString = [NSString stringWithFormat:@"#LNJP#;planSignIn;%@;%@;%@;%@;%@;%@;%@",defUser.userDict[@"outId"],defUser.userDict[@"name"],[array[scanTag%100] objectForKey:@"RI_USER"],[array[scanTag%100] objectForKey:@"RI_ID"],defUser.userDict[@"mobile"],defUser.userDict[@"devnum"],dateStr];//参数分别是 type 教练outID 教练姓名 学生ID 预约ID 电话号码 终端设备号 有效时间 if (isOverScan) { scanString = [NSString stringWithFormat:@"#LNJP#;planSignOut;%@;%@;%@",defUser.userDict[@"outId"],[array[scanTag%100] objectForKey:@"RI_USER"],dateStr];//参数分别是 type 教练outID 学生ID 有效时间 } //NSLog(@"加密前---><>%@",scanString); scanString = [DES3Util encrypt:scanString]; scanString = [NSString stringWithFormat:@"#DECODE#%@",scanString]; //NSLog(@"加密后--><>%@",scanString); UIImage *qrcode = [self createNonInterpolatedUIImageFormCIImage:[self createQRForString:scanString] withSize:250.0f]; qrcode = [self addIconToQRCodeImage:qrcode withIcon:[UIImage imageNamed:@"loginLogo"] withIconSize:CGSizeMake(40, 40)]; scanImgView.image = qrcode; //倒计时 每隔5秒调服务器 然后看是否有学员签到 如果有 展示出来 timeI = 600; timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES]; return; } if (sender.tag < 0) { if (sender.tag == -5) { //NSLog(@"批量拒绝-->%@",selectedRowArray); [self betchUpdateReserveState:@"0"]; return; } if (sender.tag == -4) { //NSLog(@"批量同意-->%@",selectedRowArray); [self betchUpdateReserveState:@"1"]; return; } //如果选择和之前的一样 这里做return操作 if (sender.tag == -3) { if (stateInt == 1) { return; } [self setOpenNo]; planViewType = 0; stateInt = 1;//已同意 }else if (sender.tag == -2){ if (stateInt == 2) { return; } [self setOpenNo]; planViewType = 1; stateInt = 2;//待审核 }else{ if (stateInt == 0) { return; } [self setOpenNo]; planViewType = 2; stateInt = 0;//已拒绝 } [self setOpenNo]; [self setSelectToZero]; //这里对按钮状态做个处理 [self setColorWithSeleceIndedx:sender.tag]; //这里更改预约状态 请求然后刷新UI [self getPlanInfos]; return; } scanTag = sender.tag; if (!sender.selected) { //这里表示开始订单 if (stuSignInDic.count > 0) { //当前有正在计时学员 //说明当前有一个订单正在进行中,此时不能创建新的订单 ShowMsg(@"当前有学员正在计时中,请先结束计时"); return; }else{ //可以开始计时 然后判断登陆 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; if (coachSignInDic) { if ([coachSignInDic[@"status"] isEqualToString:@"1"]) { //已登陆 状态写入本地 然后生成二维码 if (isAfterDelay == YES) { isAfterDelay = NO; if (timer) { [timer invalidate]; timer = nil; } } [userDefaults setValue:@"1" forKey:@"coachIsSignIn"]; [self makeBeginScanView]; }else{ //还未登录 状态写入本地 然后调签到接口 [userDefaults setValue:@"0" forKey:@"coachIsSignIn"]; [self uploadAppSignInfoWithType:@"1"]; } }else{ ShowMsg(@"数据错误,请重试!"); [self getCoachSignForTrain]; } } }else{ //NSLog(@"结束"); if (isAfterDelay == YES) { isAfterDelay = NO; if (timer) { [timer invalidate]; timer = nil; } } [self makeOverScanView]; } } - (void)setOpenNo { for (int i = 0; i < 40; i ++) { if (isOpen[i] == YES) { isOpen[i] = NO; } } } -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (alertView.tag == 1) { if (buttonIndex == alertView.cancelButtonIndex) { }else{ } } } -(void)setSelectToZero { isAllSelect = NO; currentEditSection = -1; [selectedRowArray removeAllObjects]; } -(void)setColorWithSeleceIndedx:(NSInteger)index { //对btn状态做出反应 NSArray *imageName = @[@"stt1.png",@"stt2.png",@"stt3.png"]; for (STTButton *btn in stts) { if (btn.tag == index) { [btn setImage:[[UIImage imageNamed:imageName[btn.tag + 3]] tint:defGreen] forState:UIControlStateNormal]; [btn setTitleColor:defGreen forState:UIControlStateNormal]; }else{ [btn setImage:[[UIImage imageNamed:imageName[btn.tag + 3]] tint:contentTextColor] forState:UIControlStateNormal]; [btn setTitleColor:contentTextColor forState:UIControlStateNormal]; } } } -(void)playAudioWithString:(NSString *)string { [Tools playAudioWithString:string]; } #pragma mark 生成二维码 -(void)makeBeginScanView { isOverScan = NO; CGFloat x,y,w,h; x = 20; if (kSize.width > 350) { x = 40; } y = 100; w = kSize.width - 2*x; h = kSize.width + 20; scanView = [[UIView alloc] setxywh]; scanView.backgroundColor = [UIColor whiteColor]; [scanView borderColor:lineColor width:1 cornorRadios:5]; [self.view addSubview:scanView]; NSArray *array = [models[scanTag/100] objectForKey:@"reserveInfoList"]; NSDate *effectiveDate = [NSDate dateWithTimeIntervalSinceNow:600]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *dateStr = [formatter stringFromDate:effectiveDate]; NSString *scanString = [NSString stringWithFormat:@"#LNJP#;planSignIn;%@;%@;%@;%@;%@;%@;%@",defUser.userDict[@"outId"],defUser.userDict[@"name"],[array[scanTag%100] objectForKey:@"RI_USER"],[array[scanTag%100] objectForKey:@"RI_ID"],defUser.userDict[@"mobile"],defUser.userDict[@"devnum"],dateStr];//参数分别是 type 教练outID 教练姓名 学生ID 预约ID 电话号码 终端设备号 有效时间 //NSLog(@"加密前---><>%@",scanString); scanString = [DES3Util encrypt:scanString]; scanString = [NSString stringWithFormat:@"#DECODE#%@",scanString]; //NSLog(@"加密后--><>%@",scanString); UIImage *qrcode = [self createNonInterpolatedUIImageFormCIImage:[self createQRForString:scanString] withSize:250.0f]; qrcode = [self addIconToQRCodeImage:qrcode withIcon:[UIImage imageNamed:@"loginLogo"] withIconSize:CGSizeMake(40, 40)]; x = (w - 250)/2.0; y = 20; w = h = 250; scanImgView = [[UIImageView alloc] setxywh]; scanImgView.image = qrcode; [scanView addSubview:scanImgView]; if (kSize.width > 350) { x = 40; } w = kSize.width - 2*x; x = 0; y += h + 10; h =30; UILabel *label = [[UILabel alloc] setxywh]; [label setText:[NSString stringWithFormat:@"二维码有效时间:10:00"] Font:Font18 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter]; [scanView addSubview:label]; timerLabel = label; UIImageView *cancelImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cancel"]]; cancelImg.frame = CGRectMake(w - 25, 5, 20, 20); [scanView addSubview:cancelImg]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(w - 50, 0, 50, 50); btn.backgroundColor = [UIColor clearColor]; [btn addTarget:self action:@selector(removeScanViewAndIsCanTime) forControlEvents:UIControlEventTouchUpInside]; [scanView addSubview:btn]; myTableView.userInteractionEnabled = NO; self.calendarView.userInteractionEnabled = NO; //倒计时 每隔5秒调服务器 然后看是否有学员签到 如果有 展示出来 timeI = 600; timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES]; } //结束二维码 -(void)makeOverScanView { isOverScan = YES; CGFloat x,y,w,h; x = 20; if (kSize.width > 320) { x = 40; } y = 100; w = kSize.width - 2*x; h = kSize.width + 20; scanView = [[UIView alloc] setxywh]; scanView.backgroundColor = [UIColor whiteColor]; [scanView borderColor:lineColor width:1 cornorRadios:5]; [self.view addSubview:scanView]; NSArray *array = [models[scanTag/100] objectForKey:@"reserveInfoList"]; NSDate *effectiveDate = [NSDate dateWithTimeIntervalSinceNow:600]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *dateStr = [formatter stringFromDate:effectiveDate]; NSString *scanString = [NSString stringWithFormat:@"#LNJP#;planSignOut;%@;%@;%@",defUser.userDict[@"outId"],[array[scanTag%100] objectForKey:@"RI_USER"],dateStr];//参数分别是 type 教练outID 学生userID 有效时间 //NSLog(@"加密前---><>%@",scanString); scanString = [DES3Util encrypt:scanString]; scanString = [NSString stringWithFormat:@"#DECODE#%@",scanString]; //NSLog(@"加密后--><>%@",scanString); UIImage *qrcode = [self createNonInterpolatedUIImageFormCIImage:[self createQRForString:scanString] withSize:250.0f]; qrcode = [self addIconToQRCodeImage:qrcode withIcon:[UIImage imageNamed:@"loginLogo"] withIconSize:CGSizeMake(40, 40)]; x = (w - 250)/2.0; y = 20; w = h = 250; scanImgView = [[UIImageView alloc] setxywh]; scanImgView.image = qrcode; [scanView addSubview:scanImgView]; x = 20; if (kSize.width > 320) { x = 40; } w = kSize.width - 2*x; x = 20; y += h + 10; h =30; UILabel *label = [[UILabel alloc] setxywh]; [label setText:[NSString stringWithFormat:@"二维码有效时间:10:00"] Font:Font18 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter]; [scanView addSubview:label]; timerLabel = label; UIImageView *cancelImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cancel"]]; cancelImg.frame = CGRectMake(w - 25, 5, 20, 20); [scanView addSubview:cancelImg]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(w - 50, 0, 50, 50); btn.backgroundColor = [UIColor clearColor]; [btn addTarget:self action:@selector(removeScanViewAndIsCanTime) forControlEvents:UIControlEventTouchUpInside]; [scanView addSubview:btn]; myTableView.userInteractionEnabled = NO; self.calendarView.userInteractionEnabled = NO; //倒计时 每隔5秒调服务器 然后看是否有学员签到 如果有 展示出来 timeI = 600; timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES]; } -(void)removeScanViewAndIsCanTime { //不要立即关闭定时器 做30秒的延迟 if (scanView) { [scanView removeFromSuperview]; scanView = nil; } myTableView.userInteractionEnabled = YES; self.calendarView.userInteractionEnabled = YES; isAfterDelay = YES; [self performSelector:@selector(closeTimer) withObject:nil afterDelay:30]; } -(void)closeTimer { if (isAfterDelay == YES) { if (timer) { [timer invalidate]; timer = nil; } isAfterDelay = NO; } } -(void)removeScanView { if (timer) { [timer invalidate]; timer = nil; } [scanView removeFromSuperview]; scanView = nil; myTableView.userInteractionEnabled = YES; self.calendarView.userInteractionEnabled = YES; } //二维码的验证 -(void)timeRun { timeI --; if (timeI%5 == 0) { [self getCoachSignStuRecords]; } timerLabel.text = [NSString stringWithFormat:@"二维码有效时间:%d:%d",timeI/60,timeI%60]; if (timeI == 0) { NSString *textString = @"二维码已过期,请刷新(点击刷新)"; NSString *titleString = @"刷新(点击刷新)"; CGFloat w = [textString sizeForFont:Font18].width; CGFloat x = (kSize.width - w)/2.0; CGFloat y = timerLabel.y; CGFloat h = timerLabel.height; timerLabel.frame = setDIYFrame; [timerLabel setText:textString Font:Font18 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter]; w = [titleString sizeForFont:Font18].width; x += [textString sizeForFont:Font18].width - w; UIButton *btn = [[UIButton alloc] setxywh]; btn.backgroundColor = [UIColor clearColor]; [btn target:self Tag:-11]; [scanView addSubview:btn]; [btn addViewWithRect:CGRectMake(x, y + h -5, w, 1) Color:[UIColor orangeColor]]; //关闭定时器 [timer invalidate]; timer = nil; timeI = 600; } } - (CIImage *)createQRForString:(NSString *)qrString { NSData *stringData = [qrString dataUsingEncoding:NSUTF8StringEncoding]; // 创建filter CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"]; // 设置内容和纠错级别 [qrFilter setValue:stringData forKey:@"inputMessage"]; [qrFilter setValue:@"M" forKey:@"inputCorrectionLevel"]; // 返回CIImage return qrFilter.outputImage; } - (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat) size { CGRect extent = CGRectIntegral(image.extent); CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent)); // 创建bitmap; size_t width = CGRectGetWidth(extent) * scale; size_t height = CGRectGetHeight(extent) * scale; CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray(); CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone); CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef bitmapImage = [context createCGImage:image fromRect:extent]; CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone); CGContextScaleCTM(bitmapRef, scale, scale); CGContextDrawImage(bitmapRef, extent, bitmapImage); // 保存bitmap到图片 CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef); UIImage * img = [UIImage imageWithCGImage:scaledImage]; CGImageRelease(scaledImage); CGContextRelease(bitmapRef); CGImageRelease(bitmapImage); CGColorSpaceRelease(cs); return img; } -(UIImage *)addIconToQRCodeImage:(UIImage *)image withIcon:(UIImage *)icon withIconSize:(CGSize)iconSize { UIGraphicsBeginImageContext(image.size); //通过两张图片进行位置和大小的绘制,实现两张图片的合并;其实此原理做法也可以用于多张图片的合并 CGFloat widthOfImage = image.size.width; CGFloat heightOfImage = image.size.height; CGFloat widthOfIcon = iconSize.width; CGFloat heightOfIcon = iconSize.height; [image drawInRect:CGRectMake(0, 0, widthOfImage, heightOfImage)]; [icon drawInRect:CGRectMake((widthOfImage-widthOfIcon)/2, (heightOfImage-heightOfIcon)/2, widthOfIcon, heightOfIcon)]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } #pragma mark - tableView -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { //NSLog(@"我的预约-----><>%d",(int)models.count); return models.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray *reply = [models[section] objectForKey:@"reserveInfoList"]; //先看是否允许展开 如果展开,再判断是否有值 if (isOpen[section]) { if (!reply) { return 0; } return reply.count; }else{ return 0; } } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { MyPlanVCHeader *planV = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"myPlanVCHeader"]; if (planV == nil) { planV = [[MyPlanVCHeader alloc] initWithReuseIdentifier:@"myPlanVCHeader"]; [planV.btnScan target:self]; } planV.type = planViewType; //model里边依赖type 需先设置type [planV setModel:models[section]]; planV.btnScan.tag = 4000 + section; planV.aTag = [NSString stringWithFormat:@"%d",(int)section]; if (section == currentEditSection) { //NSLog(@"YES-----><>%d----><>%d",(int)currentEditSection,selectedBtn.selected); planV.btnAll.hidden = NO; if (selectedBtn) { planV.btnAll.selected = selectedBtn.selected; } selectedBtn = planV.btnAll; planV.btnEdit.selected = YES; [planV.btnEdit setTitle:@"取消" forState:UIControlStateNormal]; }else{ //NSLog(@"NO-----><>%d",(int)currentEditSection); planV.btnAll.hidden = YES; //planV.btnAll.selected = NO; planV.btnEdit.selected = NO; [planV.btnEdit setTitle:@"批量操作" forState:UIControlStateNormal]; } //判断是否显示计费条 // if (isCanBegin != -1 && section == isCanBegin/100) { // planV.stateLabel.text = @"订单计费中..."; // }else{ // planV.stateLabel.text = @""; // } [planV click:^(id currentString) { //全选是-1 不全选是-2 NSInteger index = [currentString integerValue]; if (index < 0) { NSArray *reply = [models[section] objectForKey:@"reserveInfoList"]; //NSLog(@"点击全选按钮------><>%@",currentString); if (index == -1) { isAllSelect = YES; [selectedRowArray removeAllObjects]; for (int i = 0; i < reply.count; i++) { [selectedRowArray addObject:[NSString stringWithFormat:@"%d",i]]; } }else{ isAllSelect = NO; [selectedRowArray removeAllObjects]; } }else if (index > 499){ //按下取消按钮的操作 [self setSelectToZero]; //这一步不写也行 selectedBtn = nil; [holderBar setHidden:YES]; }else{ //这里要给这个区添加缩进(可多选状态) 判断是否有正在编辑的区 如果有 要先完成之前的编辑 或者提示不保存上一个计划的编辑 if (currentEditSection == -1) { currentEditSection = index; selectedBtn = planV.btnAll; editBtn = planV.btnEdit; [holderBar setHidden:NO]; //批量的时候 展开这个区 isOpen[section] = YES; }else{ //NSLog(@"有正在编辑的计划,请先完成!"); ShowMsg(@"有批量操作正在进行,请先完成"); } } [myTableView reloadData]; }]; if (isOpen[section]) { [planV.btnScan setImage:[UIImage imageNamed:@"location_more_arrow.png"] Tit:@"闭合" Font:Font14 State:UIControlStateNormal]; }else{ [planV.btnScan setImage:[UIImage imageNamed:@"location_more_arrow.png"] Tit:@"展开" Font:Font14 State:UIControlStateNormal]; } [UIView animateWithDuration:0.4 animations:^{ planV.btnScan.imageView.transform = isOpen[section] == YES?CGAffineTransformMakeRotation(M_PI):CGAffineTransformIdentity; } completion:^(BOOL finished) { }]; return planV; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSArray *reply = [models[indexPath.section] objectForKey:@"reserveInfoList"]; //如果是拒绝 或者未确认 用之前的UI if (stateInt == 0 || stateInt == 2) { ReplyCell* cell = [ReplyCell cellForTabelView:tableView]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; if (stateInt == 2) { [cell setStyle:0]; }else{ [cell setStyle:1]; } [cell setModel:reply[indexPath.row]]; if (indexPath.section == currentEditSection) { [cell setCanEdit]; if (isAllSelect) { [cell.selectBtn setSelected:YES]; }else{ if ([selectedRowArray containsObject:[NSString stringWithFormat:@"%d",(int)indexPath.row]]) { [cell.selectBtn setSelected:YES]; }else{ [cell.selectBtn setSelected:NO]; } } }else{ [cell setCanNotEdit]; } [cell click:^(NSString *isSelect) { if ([isSelect integerValue] == 0) { //取消选中 如果之前是全选状态 要将其改为非全选 还有按钮状态 if (isAllSelect) { isAllSelect = NO; selectedBtn.selected = NO; } if ([selectedRowArray containsObject:[NSString stringWithFormat:@"%d",(int)indexPath.row]]) { [selectedRowArray removeObject:[NSString stringWithFormat:@"%d",(int)indexPath.row]]; } }else{ //选中 [selectedRowArray addObject:[NSString stringWithFormat:@"%d",(int)indexPath.row]]; if (selectedRowArray.count == reply.count) { isAllSelect = YES; selectedBtn.selected = YES; } } }]; [cell setClickBlock:^{ //判断是否还有批量同意/批量拒绝的bar 有就删掉 if (currentEditSection != -1 && reply.count < 2) { //正在批量 且没有申请可以批量 [self setSelectToZero]; selectedBtn.hidden = YES; selectedBtn = nil; [holderBar setHidden:YES]; [editBtn setTitle:@"批量" forState:UIControlStateNormal]; } [self getPlanInfos]; }]; return cell; } //已同意页面cell //PlanCell *cell = [PlanCell cellForTabelView:tableView]; PlanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PlanCell"]; if (!cell) { cell = [[PlanCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"PlanCell"]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell.on_offBtn target:self]; } [cell setModel:reply[indexPath.row]]; cell.on_offBtn.tag = indexPath.section*100 + indexPath.row; [cell.on_offBtn setTitle:@"未带教订单" forState:UIControlStateNormal]; [cell.on_offBtn setBackgroundColor:defGreen]; [cell.on_offBtn setSelected:NO]; [cell.on_offBtn setUserInteractionEnabled:NO]; //订单状态显示找到正在计时的单元格 if ([[reply[indexPath.row] objectForKey:@"RO_STATUS"] length] > 0) { if ([[reply[indexPath.row] objectForKey:@"RO_STATUS"] isEqualToString:@"0"]) { [cell.on_offBtn setTitle:@"订单进行中" forState:UIControlStateNormal]; [cell.on_offBtn setSelected:YES]; }else{ [cell.on_offBtn setTitle:@"订单已完成" forState:UIControlStateNormal]; [cell.on_offBtn setBackgroundColor:[UIColor lightGrayColor]]; } } return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { //planViewType; //区头样式 0已同意 1待审核 2已拒绝 if (planViewType == 1) { return 140; }else{ return 110; } } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (stateInt == 0 || stateInt == 2) { return 130; } return 100; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; } #pragma mark 数据请求 //获取计划订单信息 - (void)getPlanInfos { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"userId" Value:defUser.sfzmhm]; [arr addPro:@"time" Value:dateString]; [arr addPro:@"isPage" Value:@""]; [arr addPro:@"pageSize" Value:@""]; [arr addPro:@"currentPage" Value:@""]; [arr addPro:@"status" Value:[NSString stringWithFormat:@"%d",(int)stateInt]]; NSString* method = @"getCoachReserveInfos"; ShowHUD(); [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { RemoveHUD(); //NSLog(@"我的预约-->%@---->%@",arr,root); if (!root) { return ; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } models = root[@"body"]; if (models.count >0) { [myTableView reloadData]; [holderV setHidden:YES]; }else{ [holderV setHidden:NO]; } }]; } - (void)uploadAppSignInfoWithType:(NSString *)singType { [LoadingView showHUD]; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *timeString = [dateFormatter stringFromDate:[NSDate date]]; NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"sim" Value:defUser.userDict[@"mobile"]]; [arr addPro:@"coachOutId" Value:defUser.userDict[@"outId"]]; [arr addPro:@"gps" Value:[NSString stringWithFormat:@"%f,%f,%@,3",myLocation.longitude,myLocation.latitude,timeString]]; [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]]; NSString *method = @"saveCoachSignIn"; if (![singType isEqualToString:@"1"]) { //签退 method = @"saveCoachSignOut"; } [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { RemoveHUD(); if (!root) { if ([singType isEqualToString:@"1"]) { ShowMsg(@"签到失败,请重试"); }else{ ShowMsg(@"签退失败,请重试"); } return; } if (![root[@"code"] isEqualToString:@"0"]) { ShowMsg(root[@"body"]); return; } if ([singType isEqualToString:@"1"]) { if ([root[@"code"] isEqualToString:@"0"]) { //签到成功 生成二维码计时 if (isAfterDelay == YES) { isAfterDelay = NO; if (timer) { //NSLog(@"时关闭定器"); [timer invalidate]; timer = nil; } } if ([defUser.userDict[@"devnum"] length] < 1) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"终端注册号获取失败,请尝试重新登录" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; } [self makeBeginScanView]; } }else{ //签退成功 刷新表吧 [self getPlanInfos]; } [self getCoachSignForTrain]; }]; } //获取当天签到详情 调前将coachSignInDic置为nil - (void)getCoachSignForTrain { coachSignInDic = nil; [LoadingView showHUD]; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"coachOutId" Value:defUser.userDict[@"outId"]]; [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]]; NSString* method = @"getCoachSignForTrain"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { RemoveHUD(); if (!root) { return; } if ([root[@"code"] isEqualToString:@"0"]) { NSDictionary *dic = root[@"body"]; if (![dic isKindOfClass:[NSDictionary class]]) { return; } coachSignInDic = [NSDictionary dictionaryWithDictionary:dic]; //学员列表 stuSignInDic = coachSignInDic[@"stuMaps"]; //判断日期是否有问题 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd"]; NSString *dateStr = [formatter stringFromDate:[NSDate date]]; if (![dateStr isEqualToString:dic[@"currentTime"]]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的手机日期可能存在偏差,请核对" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; } } }]; } //获取学员签到列表 - (void)getCoachSignStuRecords { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"coachId" Value:defUser.userDict[@"outId"]]; [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]]; NSString* method = @"getCoachSignStuRecords"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { if (!root) { return; } if ([root[@"code"] isEqualToString:@"1"]) { return; } //代表扫码成功 做不同的处理 stuSignInDic = root[@"body"]; if (isOverScan) { //结束计时 if (stuSignInDic.count < 1) { //获取到学员为空 就停止刷新 关闭二维码 刷新表 [self playAudioWithString:@"扫描成功,学员计时结束"]; [self removeScanView]; //学员不再是计划计时状态 [[NSUserDefaults standardUserDefaults] setValue:@"0" forKey:@"PeriodIsPlan"]; //结束计时 关闭位置上传 // [self.homeVC finishUploadCoachGPS]; if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"coachIsSignIn"] isEqualToString:@"0"]) { //掉签退接口 [self uploadAppSignInfoWithType:@"0"]; }else{ [self getPlanInfos]; } } }else{ //开始计时 if (stuSignInDic.count > 0) { [self playAudioWithString:@"扫描成功,开始计时"]; [self removeScanView];//获取到学员 就停止刷新 关闭二维码 [self getPlanInfos]; //将计划计时状态保存至本地 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *timeString = [dateFormatter stringFromDate:[NSDate date]]; NSUserDefaults *coachDefault = [NSUserDefaults standardUserDefaults]; [coachDefault setValue:[NSString stringWithFormat:@"%@",timeString] forKey:@"PeriodIsPlan"]; //开始计时 开启位置汇报 // [self.homeVC beginUploadCoachGPS]; } } }]; } //批量操作 - (void)betchUpdateReserveState:(NSString *)state { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } if (currentEditSection > models.count - 1) { return; } NSArray *reply = [models[currentEditSection] objectForKey:@"reserveInfoList"]; NSString *ids = @""; for (NSString *index in selectedRowArray) { NSDictionary *dic = reply[[index integerValue]]; ids = [ids stringByAppendingString:[NSString stringWithFormat:@"%@,",dic[@"RI_ID"]]]; } //NSLog(@"---->%@",selectedRowArray); if (ids.length < 1) { ShowMsg(@"请选择批量对象"); [self getPlanInfos]; [self setSelectToZero]; selectedBtn.hidden = YES; selectedBtn = nil; [holderBar setHidden:YES]; [editBtn setTitle:@"批量" forState:UIControlStateNormal]; return; } ids = [ids substringToIndex:ids.length - 1]; NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"ids" Value:ids]; [arr addPro:@"status" Value:state]; [arr addPro:@"reason" Value:@""]; NSString* method = @"betchUpdateReserveState"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { //NSLog(@"批量操作-->%@---->%@",arr,root); if (!root) { return ; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } ShowMsg(@"操作成功"); [self getPlanInfos]; [self setSelectToZero]; selectedBtn.hidden = YES; selectedBtn = nil; [holderBar setHidden:YES]; [editBtn setTitle:@"批量" forState:UIControlStateNormal]; }]; } -(void)dealloc { if (_locService) { [_locService stopUpdatingLocation]; _locService.delegate = nil; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end