1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417 |
- //
- // 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 "ViewController.h"
- #import "MyUINavigationController.h"
- #import "DES3Util.h"
- #import "Tools.h"
- #import "SDSoundPlayer.h"
- //地图
- #import <BaiduMapAPI_Map/BMKMapComponent.h>
- #import <BMKLocationkit/BMKLocationComponent.h>
- @interface MyPlanVC ()<CLWeeklyCalendarViewDelegate,UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate,UIAlertViewDelegate>
- {
- //表的编辑 不包括计时
- 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 *_locationManager;
- CLLocationCoordinate2D myLocation;
-
-
- NSString *serverDateStr; // 服务器时间
- }
- @property (nonatomic, strong) CLWeeklyCalendarView* calendarView;
- @end
- @implementation MyPlanVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self myInit];
- [self getDateTime];
- }
- -(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;
- if (_isNotification == YES){
- //推送状态 要将根视图变回去
- UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
- [backBtn setTintColor:defGreen];
- // self.navigationController.navigationBar.translucent = NO;
- [self.navigationItem setLeftBarButtonItem:backBtn];
- }
-
- 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 -kSafeAreaBottomHeight;
- [tv setDelegate:self];
- [tv setDataSource:self];
- tv.estimatedSectionFooterHeight = 0;
- [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 -kSafeAreaBottomHeight;
- 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];
-
- [self getCoachSignForTrain];
- }
- -(void)dismissNavgation
- {
- //推送过来 返回主页面 不晓得能不能行--推送 待测试 dansonmark
- ViewController *vc = [ViewController new];
- MyUINavigationController *nav = [[MyUINavigationController alloc] initWithRootViewController:vc];
- [UIApplication sharedApplication].delegate.window.rootViewController = nav;
- }
- //日历控件的初始化和点击回调
- -(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 触发方法
- //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:@"#JSDTMO#;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:@"#JSDTMO#;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:@"#JSDTMO#;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:@"#JSDTMO#;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];
- //订单状态显示找到正在计时的单元格
- NSDictionary *dic = reply[indexPath.row];
- if ([[dic 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]];
- }
- }
-
- [cell.temperatureBtn setTitle:@"输入体温" forState:UIControlStateNormal];
- [cell.temperatureBtn setBackgroundColor:defGreen];
- if ([dic.allKeys containsObject:@"RI_TEMPERATURE"]) {
- NSLog(@"服务器日期:%@",[serverDateStr componentsSeparatedByString:@" "].firstObject);
- [cell.temperatureBtn setTitle:[[dic objectForKey:@"RI_TEMPERATURE"] isEqualToString:@""]? @"输入体温" : [NSString stringWithFormat:@"%.1f°C",[dic[@"RI_TEMPERATURE"] floatValue]] forState:UIControlStateNormal];
- }
- @weakify(cell);
- [cell.temperatureBtn addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
- @strongify(cell);
- if (!serverDateStr) {
- ShowMsg(@"未获取到服务器时间!");
- return;
- }
- NSInteger serverDateSp = [self timeSwitchTimestamp:serverDateStr andFormatter:serverDateStr.length>10? @"YYYY-MM-DD HH:mm:ss" : @"YYYY-MM-DD"];
- NSInteger currentDateSp = [self timeSwitchTimestamp:serverDateStr.length>10? [NSString stringWithFormat:@"%@ 23:59:59", dateString] : dateString andFormatter:serverDateStr.length>10? @"YYYY-MM-DD HH:mm:ss" : @"YYYY-MM-DD"];
- NSInteger sp = currentDateSp - serverDateSp;
- if (![[dic objectForKey:@"RI_TEMPERATURE"] isEqualToString:@""]) {
- ShowMsg(@"已输入的体温无法修改!");
- } else if (sp < 0 || sp > 86400) {
- ShowMsg(@"只能填写当天学员的体温");
- } else {
- SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow];
-
- SCLTextView *textField = [alert addTextField:@"请输入学员当前体温"];
- textField.keyboardType = UIKeyboardTypeDecimalPad;
- [RACObserve(cell.temperatureBtn.titleLabel, text) subscribeNext:^(NSString *str) {
- if (![str isEqualToString:@"输入体温"]) {
- if ([str containsString:@"°C"]) {
- str = [str stringByReplacingOccurrencesOfString:@"°C" withString:@""];
- }
- textField.text = str;
- }
- }];
- alert.customViewColor = defGreen;
- [alert addButton:@"确定" actionBlock:^(void) {
- CGFloat temperature = textField.text.floatValue;
- if ([textField.text isEqualToString:@""]) {
- ShowMsg(@"请输入学员当前体温");
- return;
- } else if (temperature >= 35.0 && temperature <= 37.2) {
- [cell.temperatureBtn setTitle:[NSString stringWithFormat:@"%@°C",textField.text] forState:UIControlStateNormal];
- [self updateReserveTemperatureWithId:dic[@"RI_ID"] temperature:[NSString stringWithFormat:@"%f",temperature]];
-
- } else {
- ShowMsg(@"学员当前体温异常");
- }
- }];
-
- [alert showEdit:self title:@"温馨提示" subTitle:@"请输入学员当前体温(体温只允许输入一次,请谨慎填写!)" closeButtonTitle:@"取消" duration:0.0f];
- }
- }];
- 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)getDateTime
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"systemType" Value:@"iOS"];
- NSString* method = @"getDateTime";
- 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;
- }
-
- serverDateStr = root[@"body"];
- }];
- }
- - (void)updateReserveTemperatureWithId:(NSString *)idStr temperature:(NSString *)temperature {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"id" Value:idStr];
- [arr addPro:@"temperature" Value:temperature];
- NSString* method = @"updateReserveTemperature";
- 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;
- }
- [self getPlanInfos];
- }];
- }
- - (void)uploadAppSignInfoWithType:(NSString *)singType
- {
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- if (!_locationManager) {
- //初始化实例
- _locationManager = [[BMKLocationManager alloc] init];
- //设置返回位置的坐标系类型 默认为国标
- _locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;//百度经纬度坐标
- }
-
- BOOL requestResult = [_locationManager requestLocationWithReGeocode:NO withNetworkState:NO completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {
- if (error)
- {
- ShowMsg([NSString stringWithFormat:@"定位失败:%@",error.description]);
- }else{
- myLocation = location.location.coordinate;
- [self reallyUploadAppSignInfoWithType:singType];
- }
- }];
- if (requestResult == NO) {
- //
- ShowMsg(@"发起定位请求失败");
- }
- }
- - (void)reallyUploadAppSignInfoWithType:(NSString *)singType
- {
- 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)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (NSInteger)timeSwitchTimestamp:(NSString *)formatTime andFormatter:(NSString *)format{
-
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
-
- [formatter setDateStyle:NSDateFormatterMediumStyle];
-
- [formatter setTimeStyle:NSDateFormatterShortStyle];
-
- [formatter setDateFormat:format]; //(@"YYYY-MM-dd hh:mm:ss") ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
- NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
-
- [formatter setTimeZone:timeZone];
- NSDate* date = [formatter dateFromString:formatTime]; //------------将字符串按formatter转成nsdate
-
- //时间转时间戳的方法:
-
- NSInteger timeSp = [[NSNumber numberWithDouble:[date timeIntervalSince1970]] integerValue];
- return timeSp;
- }
- @end
|