MyPlanVC.m 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. //
  2. // MyPlanVC.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/3/27.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "MyPlanVC.h"
  9. #import "PlanCell.h"
  10. #import "MyPlanVCHeader.h"
  11. #import "CLWeeklyCalendarView.h"
  12. #import "STTButton.h"
  13. #import "ReplyCell.h"
  14. #import "DES3Util.h"
  15. #import "Tools.h"
  16. #import "SDSoundPlayer.h"
  17. //地图
  18. #import <BaiduMapAPI_Map/BMKMapComponent.h>
  19. #import <BMKLocationKit/BMKLocationComponent.h>
  20. @interface MyPlanVC ()<CLWeeklyCalendarViewDelegate,UITableViewDataSource,UITableViewDelegate,BMKLocationManagerDelegate,UIActionSheetDelegate,UIAlertViewDelegate>
  21. {
  22. //表的编辑 不包括计时
  23. UITableView *myTableView;
  24. HolderView *holderV;
  25. UIButton *selectedBtn;
  26. UIButton *editBtn;
  27. UIView *holderBar;
  28. NSArray *models;
  29. NSMutableArray *stts;
  30. NSMutableArray *selectedRowArray;
  31. NSInteger currentEditSection;
  32. NSInteger stateInt;
  33. NSInteger planViewType; //区头样式 0已同意 1待审核 2已拒绝
  34. NSString *dateString;
  35. BOOL isAllSelect;
  36. BOOL isOpen[40];
  37. //计时
  38. NSTimer *timer;
  39. UILabel *timerLabel;
  40. UIImageView *scanImgView;
  41. UIView *scanView;//二维码页面
  42. NSDictionary *coachSignInDic;
  43. //NSArray *stuListArray;
  44. NSDictionary *stuSignInDic;
  45. NSInteger scanTag;
  46. BOOL isAfterDelay;
  47. BOOL isOverScan;
  48. int timeI;
  49. //地图定位
  50. BMKLocationManager *_locService;
  51. CLLocationCoordinate2D myLocation;
  52. }
  53. @property (nonatomic, strong) CLWeeklyCalendarView* calendarView;
  54. @end
  55. @implementation MyPlanVC
  56. - (void)viewDidLoad {
  57. [super viewDidLoad];
  58. [self myInit];
  59. }
  60. -(void)viewWillDisappear:(BOOL)animated
  61. {
  62. [super viewWillDisappear:animated];
  63. if (timer) {
  64. //感觉是没用的下边有判断 这里保留吧 防止scanView不在 定时器还在跑的状况 目测是不会发生的 就当是保险吧
  65. [timer invalidate];
  66. timer = nil;
  67. }
  68. if (scanView) {
  69. [self removeScanView];
  70. }
  71. }
  72. -(void)viewDidDisappear:(BOOL)animated
  73. {
  74. [super viewDidDisappear:animated];
  75. RemoveHUD();
  76. }
  77. -(void)myInit
  78. {
  79. self.view.backgroundColor = backGroundColor;
  80. stateInt = 2;
  81. planViewType = 1;
  82. isAllSelect = NO;
  83. dateString = @"";
  84. currentEditSection = -1;
  85. selectedRowArray = [NSMutableArray array];
  86. stuSignInDic = [NSDictionary dictionary];
  87. [self.view addSubview:self.calendarView];
  88. self.calendarView.userInteractionEnabled = YES;
  89. CGFloat y = kNavOffSet + self.calendarView.height;
  90. //UITableView* tv = [[UITableView alloc] initWithFrame:kFrame];
  91. UITableView* tv = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStyleGrouped];
  92. tv.y = y;
  93. tv.height = kSize.height - tv.y - 50 -SafeAreaBottomHeight;
  94. [tv setDelegate:self];
  95. [tv setDataSource:self];
  96. [self addV:tv];
  97. myTableView = tv;
  98. myTableView.userInteractionEnabled = YES;
  99. [tv setTableFooterView:[UIView new]];
  100. holderV = [[HolderView alloc] initWithFrame:tv.frame];
  101. [self addV:holderV];
  102. y = kSize.height - 50 -SafeAreaBottomHeight;
  103. UIView *tabBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 50)];
  104. tabBar.backgroundColor = backGroundColor;
  105. [self.view addSubview:tabBar];
  106. [tabBar addSelfViewWithRect:CGRectMake(0, 0, kSize.width, 1)];
  107. CGFloat wid = kSize.width/3.0;
  108. NSArray *imageName = @[@"stt1.png",@"stt2.png",@"stt3.png"];
  109. NSArray *titles = @[@"已完成",@"待确认",@"已拒绝"];
  110. stts = [NSMutableArray array];
  111. for (int i = 0; i < 3; i ++) {
  112. STTButton *sttBtn = [[STTButton alloc] initWithFrame:CGRectMake(wid*i, 0, wid, 50)];
  113. [sttBtn setImage:[UIImage imageNamed:imageName[i]] forState:UIControlStateNormal];
  114. [sttBtn setTitle:titles[i] forState:UIControlStateNormal];
  115. //设置初始的状态颜色 默认已完成显示为绿色 其他为contentTextColor
  116. if (i == 1) {
  117. [sttBtn setImage:[[UIImage imageNamed:imageName[i]] tint:defGreen] forState:UIControlStateNormal];
  118. [sttBtn setTitleColor:defGreen forState:UIControlStateNormal];
  119. }else{
  120. [sttBtn setImage:[[UIImage imageNamed:imageName[i]] tint:contentTextColor] forState:UIControlStateNormal];
  121. [sttBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  122. }
  123. [sttBtn target:self Tag:i - 3];//-3 -2 -1
  124. [tabBar addSubview:sttBtn];
  125. [stts addObject:sttBtn];
  126. }
  127. holderBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 50)];
  128. holderBar.backgroundColor = backGroundColor;
  129. [self.view addSubview:holderBar];
  130. [holderBar setHidden:YES];
  131. STTButton *holderBtn = [[STTButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width/2.0, 50)];
  132. [holderBtn setTitle:@"批量同意" forState:UIControlStateNormal];
  133. [holderBtn setImage:[UIImage imageNamed:@"stt1.png"] forState:UIControlStateNormal];
  134. [holderBtn setImage:[[UIImage imageNamed:@"stt1.png"] tint:defGreen] forState:UIControlStateHighlighted];
  135. [holderBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  136. [holderBtn setTitleColor:defGreen forState:UIControlStateHighlighted];
  137. [holderBtn target:self Tag:-4];
  138. [holderBar addSubview:holderBtn];
  139. holderBtn = [[STTButton alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0, 50)];
  140. [holderBtn setTitle:@"批量拒绝" forState:UIControlStateNormal];
  141. [holderBtn setImage:[UIImage imageNamed:@"stt3.png"] forState:UIControlStateNormal];
  142. [holderBtn setImage:[[UIImage imageNamed:@"stt3.png"] tint:defGreen] forState:UIControlStateHighlighted];
  143. [holderBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  144. [holderBtn setTitleColor:defGreen forState:UIControlStateHighlighted];
  145. [holderBtn target:self Tag:-5];
  146. [holderBar addSubview:holderBtn];
  147. //初始化BMKLocationService
  148. if (![_locService isKindOfClass:[BMKLocationManager class]]) {
  149. _locService = [[BMKLocationManager alloc]init];
  150. _locService.desiredAccuracy = kCLLocationAccuracyBest;
  151. _locService.delegate = self;
  152. [_locService startUpdatingLocation];
  153. }
  154. [self getCoachSignForTrain];
  155. }
  156. //日历控件的初始化和点击回调
  157. -(CLWeeklyCalendarView *)calendarView
  158. {
  159. if(!_calendarView){
  160. _calendarView = [[CLWeeklyCalendarView alloc] initWithFrame:CGRectMake(0, kNavOffSet, kSize.width, 120)];
  161. _calendarView.delegate = self;
  162. }
  163. return _calendarView;
  164. }
  165. #pragma mark - CLWeeklyCalendarViewDelegate
  166. -(NSDictionary *)CLCalendarBehaviorAttributes
  167. {
  168. //CLCalendarSelectedDatePrintFormatDefault 显示选中日期格式
  169. return @{
  170. //CLCalendarWeekStartDay : @2, //Start Day of the week, from 1-7 Mon-Sun -- default 1
  171. // CLCalendarDayTitleTextColor : [UIColor yellowColor],
  172. // CLCalendarSelectedDatePrintColor : [UIColor greenColor],
  173. };
  174. }
  175. -(void)dailyCalendarViewDidSelect:(NSDate *)date
  176. {
  177. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  178. [formatter setDateFormat:@"yyyy-MM-dd"];
  179. if (![dateString isEqualToString:[formatter stringFromDate:date]]) {
  180. //改变日期 这里要将编辑的值全部置零
  181. [self setSelectToZero];
  182. [holderBar setHidden:YES];
  183. }
  184. dateString = [formatter stringFromDate:date];
  185. [self getPlanInfos];
  186. }
  187. #pragma mark 地图delegate
  188. /**用户拒绝开启定位服务等原因导致的定位失败会调用的方法
  189. */
  190. - (void)BMKLocationManager:(BMKLocationManager *)manager didFailWithError:(NSError *)error {
  191. UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请在iPhone的“设置”-“隐私”-“定位服务”功能中,找到“优易学车”打开位置访问权限" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
  192. [alert show];
  193. }
  194. //处理位置坐标更新
  195. - (void)BMKLocationManager:(BMKLocationManager *)manager didUpdateLocation:(BMKLocation *)location orError:(NSError *)error {
  196. if (location.location)
  197. {
  198. [_locService stopUpdatingLocation];
  199. //储存自己当前位置
  200. myLocation = location.location.coordinate;
  201. }
  202. }
  203. #pragma mark 触发方法
  204. //cell的按钮的回调方法
  205. -(void)btnClick:(UIButton *)sender
  206. {
  207. if (sender.tag > 3999) {
  208. //这里更改区是否展开状态
  209. isOpen[sender.tag - 4000] = !isOpen[sender.tag - 4000];
  210. [myTableView reloadData];
  211. return;
  212. }
  213. if (sender.tag == -11) {
  214. NSArray *array = [models[scanTag/100] objectForKey:@"reserveInfoList"];
  215. NSDate *effectiveDate = [NSDate dateWithTimeIntervalSinceNow:600];
  216. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  217. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  218. NSString *dateStr = [formatter stringFromDate:effectiveDate];
  219. 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 电话号码 终端设备号 有效时间
  220. if (isOverScan) {
  221. scanString = [NSString stringWithFormat:@"#LNJP#;planSignOut;%@;%@;%@",defUser.userDict[@"outId"],[array[scanTag%100] objectForKey:@"RI_USER"],dateStr];//参数分别是 type 教练outID 学生ID 有效时间
  222. }
  223. //NSLog(@"加密前---><>%@",scanString);
  224. scanString = [DES3Util encrypt:scanString];
  225. scanString = [NSString stringWithFormat:@"#DECODE#%@",scanString];
  226. //NSLog(@"加密后--><>%@",scanString);
  227. UIImage *qrcode = [self createNonInterpolatedUIImageFormCIImage:[self createQRForString:scanString] withSize:250.0f];
  228. qrcode = [self addIconToQRCodeImage:qrcode withIcon:[UIImage imageNamed:@"loginLogo"] withIconSize:CGSizeMake(40, 40)];
  229. scanImgView.image = qrcode;
  230. //倒计时 每隔5秒调服务器 然后看是否有学员签到 如果有 展示出来
  231. timeI = 600;
  232. timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
  233. return;
  234. }
  235. if (sender.tag < 0) {
  236. if (sender.tag == -5) {
  237. //NSLog(@"批量拒绝-->%@",selectedRowArray);
  238. [self betchUpdateReserveState:@"0"];
  239. return;
  240. }
  241. if (sender.tag == -4) {
  242. //NSLog(@"批量同意-->%@",selectedRowArray);
  243. [self betchUpdateReserveState:@"1"];
  244. return;
  245. }
  246. //如果选择和之前的一样 这里做return操作
  247. if (sender.tag == -3) {
  248. if (stateInt == 1) {
  249. return;
  250. }
  251. [self setOpenNo];
  252. planViewType = 0;
  253. stateInt = 1;//已同意
  254. }else if (sender.tag == -2){
  255. if (stateInt == 2) {
  256. return;
  257. }
  258. [self setOpenNo];
  259. planViewType = 1;
  260. stateInt = 2;//待审核
  261. }else{
  262. if (stateInt == 0) {
  263. return;
  264. }
  265. [self setOpenNo];
  266. planViewType = 2;
  267. stateInt = 0;//已拒绝
  268. }
  269. [self setOpenNo];
  270. [self setSelectToZero];
  271. //这里对按钮状态做个处理
  272. [self setColorWithSeleceIndedx:sender.tag];
  273. //这里更改预约状态 请求然后刷新UI
  274. [self getPlanInfos];
  275. return;
  276. }
  277. scanTag = sender.tag;
  278. if (!sender.selected) { //这里表示开始订单
  279. if (stuSignInDic.count > 0) { //当前有正在计时学员
  280. //说明当前有一个订单正在进行中,此时不能创建新的订单
  281. ShowMsg(@"当前有学员正在计时中,请先结束计时");
  282. return;
  283. }else{ //可以开始计时 然后判断登陆
  284. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  285. if (coachSignInDic) {
  286. if ([coachSignInDic[@"status"] isEqualToString:@"1"]) {
  287. //已登陆 状态写入本地 然后生成二维码
  288. if (isAfterDelay == YES) {
  289. isAfterDelay = NO;
  290. if (timer) {
  291. [timer invalidate];
  292. timer = nil;
  293. }
  294. }
  295. [userDefaults setValue:@"1" forKey:@"coachIsSignIn"];
  296. [self makeBeginScanView];
  297. }else{
  298. //还未登录 状态写入本地 然后调签到接口
  299. [userDefaults setValue:@"0" forKey:@"coachIsSignIn"];
  300. [self uploadAppSignInfoWithType:@"1"];
  301. }
  302. }else{
  303. ShowMsg(@"数据错误,请重试!");
  304. [self getCoachSignForTrain];
  305. }
  306. }
  307. }else{
  308. //NSLog(@"结束");
  309. if (isAfterDelay == YES) {
  310. isAfterDelay = NO;
  311. if (timer) {
  312. [timer invalidate];
  313. timer = nil;
  314. }
  315. }
  316. [self makeOverScanView];
  317. }
  318. }
  319. - (void)setOpenNo
  320. {
  321. for (int i = 0; i < 40; i ++) {
  322. if (isOpen[i] == YES) {
  323. isOpen[i] = NO;
  324. }
  325. }
  326. }
  327. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  328. {
  329. if (alertView.tag == 1) {
  330. if (buttonIndex == alertView.cancelButtonIndex) {
  331. }else{
  332. }
  333. }
  334. }
  335. -(void)setSelectToZero
  336. {
  337. isAllSelect = NO;
  338. currentEditSection = -1;
  339. [selectedRowArray removeAllObjects];
  340. }
  341. -(void)setColorWithSeleceIndedx:(NSInteger)index
  342. {
  343. //对btn状态做出反应
  344. NSArray *imageName = @[@"stt1.png",@"stt2.png",@"stt3.png"];
  345. for (STTButton *btn in stts) {
  346. if (btn.tag == index) {
  347. [btn setImage:[[UIImage imageNamed:imageName[btn.tag + 3]] tint:defGreen] forState:UIControlStateNormal];
  348. [btn setTitleColor:defGreen forState:UIControlStateNormal];
  349. }else{
  350. [btn setImage:[[UIImage imageNamed:imageName[btn.tag + 3]] tint:contentTextColor] forState:UIControlStateNormal];
  351. [btn setTitleColor:contentTextColor forState:UIControlStateNormal];
  352. }
  353. }
  354. }
  355. -(void)playAudioWithString:(NSString *)string
  356. {
  357. [Tools playAudioWithString:string];
  358. }
  359. #pragma mark 生成二维码
  360. -(void)makeBeginScanView
  361. {
  362. isOverScan = NO;
  363. CGFloat x,y,w,h;
  364. x = 20;
  365. if (kSize.width > 350) {
  366. x = 40;
  367. }
  368. y = 100;
  369. w = kSize.width - 2*x;
  370. h = kSize.width + 20;
  371. scanView = [[UIView alloc] setxywh];
  372. scanView.backgroundColor = [UIColor whiteColor];
  373. [scanView borderColor:lineColor width:1 cornorRadios:5];
  374. [self.view addSubview:scanView];
  375. NSArray *array = [models[scanTag/100] objectForKey:@"reserveInfoList"];
  376. NSDate *effectiveDate = [NSDate dateWithTimeIntervalSinceNow:600];
  377. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  378. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  379. NSString *dateStr = [formatter stringFromDate:effectiveDate];
  380. 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 电话号码 终端设备号 有效时间
  381. //NSLog(@"加密前---><>%@",scanString);
  382. scanString = [DES3Util encrypt:scanString];
  383. scanString = [NSString stringWithFormat:@"#DECODE#%@",scanString];
  384. //NSLog(@"加密后--><>%@",scanString);
  385. UIImage *qrcode = [self createNonInterpolatedUIImageFormCIImage:[self createQRForString:scanString] withSize:250.0f];
  386. qrcode = [self addIconToQRCodeImage:qrcode withIcon:[UIImage imageNamed:@"loginLogo"] withIconSize:CGSizeMake(40, 40)];
  387. x = (w - 250)/2.0;
  388. y = 20;
  389. w = h = 250;
  390. scanImgView = [[UIImageView alloc] setxywh];
  391. scanImgView.image = qrcode;
  392. [scanView addSubview:scanImgView];
  393. if (kSize.width > 350) {
  394. x = 40;
  395. }
  396. w = kSize.width - 2*x;
  397. x = 0;
  398. y += h + 10;
  399. h =30;
  400. UILabel *label = [[UILabel alloc] setxywh];
  401. [label setText:[NSString stringWithFormat:@"二维码有效时间:10:00"] Font:Font18 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  402. [scanView addSubview:label];
  403. timerLabel = label;
  404. UIImageView *cancelImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cancel"]];
  405. cancelImg.frame = CGRectMake(w - 25, 5, 20, 20);
  406. [scanView addSubview:cancelImg];
  407. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  408. btn.frame = CGRectMake(w - 50, 0, 50, 50);
  409. btn.backgroundColor = [UIColor clearColor];
  410. [btn addTarget:self action:@selector(removeScanViewAndIsCanTime) forControlEvents:UIControlEventTouchUpInside];
  411. [scanView addSubview:btn];
  412. myTableView.userInteractionEnabled = NO;
  413. self.calendarView.userInteractionEnabled = NO;
  414. //倒计时 每隔5秒调服务器 然后看是否有学员签到 如果有 展示出来
  415. timeI = 600;
  416. timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
  417. }
  418. //结束二维码
  419. -(void)makeOverScanView
  420. {
  421. isOverScan = YES;
  422. CGFloat x,y,w,h;
  423. x = 20;
  424. if (kSize.width > 320) {
  425. x = 40;
  426. }
  427. y = 100;
  428. w = kSize.width - 2*x;
  429. h = kSize.width + 20;
  430. scanView = [[UIView alloc] setxywh];
  431. scanView.backgroundColor = [UIColor whiteColor];
  432. [scanView borderColor:lineColor width:1 cornorRadios:5];
  433. [self.view addSubview:scanView];
  434. NSArray *array = [models[scanTag/100] objectForKey:@"reserveInfoList"];
  435. NSDate *effectiveDate = [NSDate dateWithTimeIntervalSinceNow:600];
  436. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  437. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  438. NSString *dateStr = [formatter stringFromDate:effectiveDate];
  439. NSString *scanString = [NSString stringWithFormat:@"#LNJP#;planSignOut;%@;%@;%@",defUser.userDict[@"outId"],[array[scanTag%100] objectForKey:@"RI_USER"],dateStr];//参数分别是 type 教练outID 学生userID 有效时间
  440. //NSLog(@"加密前---><>%@",scanString);
  441. scanString = [DES3Util encrypt:scanString];
  442. scanString = [NSString stringWithFormat:@"#DECODE#%@",scanString];
  443. //NSLog(@"加密后--><>%@",scanString);
  444. UIImage *qrcode = [self createNonInterpolatedUIImageFormCIImage:[self createQRForString:scanString] withSize:250.0f];
  445. qrcode = [self addIconToQRCodeImage:qrcode withIcon:[UIImage imageNamed:@"loginLogo"] withIconSize:CGSizeMake(40, 40)];
  446. x = (w - 250)/2.0;
  447. y = 20;
  448. w = h = 250;
  449. scanImgView = [[UIImageView alloc] setxywh];
  450. scanImgView.image = qrcode;
  451. [scanView addSubview:scanImgView];
  452. x = 20;
  453. if (kSize.width > 320) {
  454. x = 40;
  455. }
  456. w = kSize.width - 2*x;
  457. x = 20;
  458. y += h + 10;
  459. h =30;
  460. UILabel *label = [[UILabel alloc] setxywh];
  461. [label setText:[NSString stringWithFormat:@"二维码有效时间:10:00"] Font:Font18 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  462. [scanView addSubview:label];
  463. timerLabel = label;
  464. UIImageView *cancelImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cancel"]];
  465. cancelImg.frame = CGRectMake(w - 25, 5, 20, 20);
  466. [scanView addSubview:cancelImg];
  467. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  468. btn.frame = CGRectMake(w - 50, 0, 50, 50);
  469. btn.backgroundColor = [UIColor clearColor];
  470. [btn addTarget:self action:@selector(removeScanViewAndIsCanTime) forControlEvents:UIControlEventTouchUpInside];
  471. [scanView addSubview:btn];
  472. myTableView.userInteractionEnabled = NO;
  473. self.calendarView.userInteractionEnabled = NO;
  474. //倒计时 每隔5秒调服务器 然后看是否有学员签到 如果有 展示出来
  475. timeI = 600;
  476. timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
  477. }
  478. -(void)removeScanViewAndIsCanTime
  479. {
  480. //不要立即关闭定时器 做30秒的延迟
  481. if (scanView) {
  482. [scanView removeFromSuperview];
  483. scanView = nil;
  484. }
  485. myTableView.userInteractionEnabled = YES;
  486. self.calendarView.userInteractionEnabled = YES;
  487. isAfterDelay = YES;
  488. [self performSelector:@selector(closeTimer) withObject:nil afterDelay:30];
  489. }
  490. -(void)closeTimer
  491. {
  492. if (isAfterDelay == YES) {
  493. if (timer) {
  494. [timer invalidate];
  495. timer = nil;
  496. }
  497. isAfterDelay = NO;
  498. }
  499. }
  500. -(void)removeScanView
  501. {
  502. if (timer) {
  503. [timer invalidate];
  504. timer = nil;
  505. }
  506. [scanView removeFromSuperview];
  507. scanView = nil;
  508. myTableView.userInteractionEnabled = YES;
  509. self.calendarView.userInteractionEnabled = YES;
  510. }
  511. //二维码的验证
  512. -(void)timeRun
  513. {
  514. timeI --;
  515. if (timeI%5 == 0) {
  516. [self getCoachSignStuRecords];
  517. }
  518. timerLabel.text = [NSString stringWithFormat:@"二维码有效时间:%d:%d",timeI/60,timeI%60];
  519. if (timeI == 0) {
  520. NSString *textString = @"二维码已过期,请刷新(点击刷新)";
  521. NSString *titleString = @"刷新(点击刷新)";
  522. CGFloat w = [textString sizeForFont:Font18].width;
  523. CGFloat x = (kSize.width - w)/2.0;
  524. CGFloat y = timerLabel.y;
  525. CGFloat h = timerLabel.height;
  526. timerLabel.frame = setDIYFrame;
  527. [timerLabel setText:textString Font:Font18 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  528. w = [titleString sizeForFont:Font18].width;
  529. x += [textString sizeForFont:Font18].width - w;
  530. UIButton *btn = [[UIButton alloc] setxywh];
  531. btn.backgroundColor = [UIColor clearColor];
  532. [btn target:self Tag:-11];
  533. [scanView addSubview:btn];
  534. [btn addViewWithRect:CGRectMake(x, y + h -5, w, 1) Color:[UIColor orangeColor]];
  535. //关闭定时器
  536. [timer invalidate];
  537. timer = nil;
  538. timeI = 600;
  539. }
  540. }
  541. - (CIImage *)createQRForString:(NSString *)qrString {
  542. NSData *stringData = [qrString dataUsingEncoding:NSUTF8StringEncoding];
  543. // 创建filter
  544. CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
  545. // 设置内容和纠错级别
  546. [qrFilter setValue:stringData forKey:@"inputMessage"];
  547. [qrFilter setValue:@"M" forKey:@"inputCorrectionLevel"];
  548. // 返回CIImage
  549. return qrFilter.outputImage;
  550. }
  551. - (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat) size {
  552. CGRect extent = CGRectIntegral(image.extent);
  553. CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
  554. // 创建bitmap;
  555. size_t width = CGRectGetWidth(extent) * scale;
  556. size_t height = CGRectGetHeight(extent) * scale;
  557. CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
  558. CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
  559. CIContext *context = [CIContext contextWithOptions:nil];
  560. CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
  561. CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
  562. CGContextScaleCTM(bitmapRef, scale, scale);
  563. CGContextDrawImage(bitmapRef, extent, bitmapImage);
  564. // 保存bitmap到图片
  565. CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
  566. UIImage * img = [UIImage imageWithCGImage:scaledImage];
  567. CGImageRelease(scaledImage);
  568. CGContextRelease(bitmapRef);
  569. CGImageRelease(bitmapImage);
  570. CGColorSpaceRelease(cs);
  571. return img;
  572. }
  573. -(UIImage *)addIconToQRCodeImage:(UIImage *)image withIcon:(UIImage *)icon withIconSize:(CGSize)iconSize {
  574. UIGraphicsBeginImageContext(image.size);
  575. //通过两张图片进行位置和大小的绘制,实现两张图片的合并;其实此原理做法也可以用于多张图片的合并
  576. CGFloat widthOfImage = image.size.width;
  577. CGFloat heightOfImage = image.size.height;
  578. CGFloat widthOfIcon = iconSize.width;
  579. CGFloat heightOfIcon = iconSize.height;
  580. [image drawInRect:CGRectMake(0, 0, widthOfImage, heightOfImage)];
  581. [icon drawInRect:CGRectMake((widthOfImage-widthOfIcon)/2, (heightOfImage-heightOfIcon)/2,
  582. widthOfIcon, heightOfIcon)];
  583. UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
  584. UIGraphicsEndImageContext();
  585. return img;
  586. }
  587. #pragma mark - tableView
  588. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  589. {
  590. //NSLog(@"我的预约-----><>%d",(int)models.count);
  591. return models.count;
  592. }
  593. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  594. {
  595. NSArray *reply = [models[section] objectForKey:@"reserveInfoList"];
  596. //先看是否允许展开 如果展开,再判断是否有值
  597. if (isOpen[section]) {
  598. if (!reply) {
  599. return 0;
  600. }
  601. return reply.count;
  602. }else{
  603. return 0;
  604. }
  605. }
  606. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  607. {
  608. MyPlanVCHeader *planV = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"myPlanVCHeader"];
  609. if (planV == nil) {
  610. planV = [[MyPlanVCHeader alloc] initWithReuseIdentifier:@"myPlanVCHeader"];
  611. [planV.btnScan target:self];
  612. }
  613. planV.type = planViewType;
  614. //model里边依赖type 需先设置type
  615. [planV setModel:models[section]];
  616. planV.btnScan.tag = 4000 + section;
  617. planV.aTag = [NSString stringWithFormat:@"%d",(int)section];
  618. if (section == currentEditSection) {
  619. //NSLog(@"YES-----><>%d----><>%d",(int)currentEditSection,selectedBtn.selected);
  620. planV.btnAll.hidden = NO;
  621. if (selectedBtn) {
  622. planV.btnAll.selected = selectedBtn.selected;
  623. }
  624. selectedBtn = planV.btnAll;
  625. planV.btnEdit.selected = YES;
  626. [planV.btnEdit setTitle:@"取消" forState:UIControlStateNormal];
  627. }else{
  628. //NSLog(@"NO-----><>%d",(int)currentEditSection);
  629. planV.btnAll.hidden = YES;
  630. //planV.btnAll.selected = NO;
  631. planV.btnEdit.selected = NO;
  632. [planV.btnEdit setTitle:@"批量操作" forState:UIControlStateNormal];
  633. }
  634. //判断是否显示计费条
  635. // if (isCanBegin != -1 && section == isCanBegin/100) {
  636. // planV.stateLabel.text = @"订单计费中...";
  637. // }else{
  638. // planV.stateLabel.text = @"";
  639. // }
  640. [planV click:^(id currentString) {
  641. //全选是-1 不全选是-2
  642. NSInteger index = [currentString integerValue];
  643. if (index < 0) {
  644. NSArray *reply = [models[section] objectForKey:@"reserveInfoList"];
  645. //NSLog(@"点击全选按钮------><>%@",currentString);
  646. if (index == -1) {
  647. isAllSelect = YES;
  648. [selectedRowArray removeAllObjects];
  649. for (int i = 0; i < reply.count; i++) {
  650. [selectedRowArray addObject:[NSString stringWithFormat:@"%d",i]];
  651. }
  652. }else{
  653. isAllSelect = NO;
  654. [selectedRowArray removeAllObjects];
  655. }
  656. }else if (index > 499){
  657. //按下取消按钮的操作
  658. [self setSelectToZero];
  659. //这一步不写也行
  660. selectedBtn = nil;
  661. [holderBar setHidden:YES];
  662. }else{
  663. //这里要给这个区添加缩进(可多选状态) 判断是否有正在编辑的区 如果有 要先完成之前的编辑 或者提示不保存上一个计划的编辑
  664. if (currentEditSection == -1) {
  665. currentEditSection = index;
  666. selectedBtn = planV.btnAll;
  667. editBtn = planV.btnEdit;
  668. [holderBar setHidden:NO];
  669. //批量的时候 展开这个区
  670. isOpen[section] = YES;
  671. }else{
  672. //NSLog(@"有正在编辑的计划,请先完成!");
  673. ShowMsg(@"有批量操作正在进行,请先完成");
  674. }
  675. }
  676. [myTableView reloadData];
  677. }];
  678. if (isOpen[section]) {
  679. [planV.btnScan setImage:[UIImage imageNamed:@"location_more_arrow.png"] Tit:@"闭合" Font:Font14 State:UIControlStateNormal];
  680. }else{
  681. [planV.btnScan setImage:[UIImage imageNamed:@"location_more_arrow.png"] Tit:@"展开" Font:Font14 State:UIControlStateNormal];
  682. }
  683. [UIView animateWithDuration:0.4 animations:^{
  684. planV.btnScan.imageView.transform = isOpen[section] == YES?CGAffineTransformMakeRotation(M_PI):CGAffineTransformIdentity;
  685. } completion:^(BOOL finished) {
  686. }];
  687. return planV;
  688. }
  689. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  690. {
  691. NSArray *reply = [models[indexPath.section] objectForKey:@"reserveInfoList"];
  692. //如果是拒绝 或者未确认 用之前的UI
  693. if (stateInt == 0 || stateInt == 2) {
  694. ReplyCell* cell = [ReplyCell cellForTabelView:tableView];
  695. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  696. if (stateInt == 2) {
  697. [cell setStyle:0];
  698. }else{
  699. [cell setStyle:1];
  700. }
  701. [cell setModel:reply[indexPath.row]];
  702. if (indexPath.section == currentEditSection) {
  703. [cell setCanEdit];
  704. if (isAllSelect) {
  705. [cell.selectBtn setSelected:YES];
  706. }else{
  707. if ([selectedRowArray containsObject:[NSString stringWithFormat:@"%d",(int)indexPath.row]]) {
  708. [cell.selectBtn setSelected:YES];
  709. }else{
  710. [cell.selectBtn setSelected:NO];
  711. }
  712. }
  713. }else{
  714. [cell setCanNotEdit];
  715. }
  716. [cell click:^(NSString *isSelect) {
  717. if ([isSelect integerValue] == 0) {
  718. //取消选中 如果之前是全选状态 要将其改为非全选 还有按钮状态
  719. if (isAllSelect) {
  720. isAllSelect = NO;
  721. selectedBtn.selected = NO;
  722. }
  723. if ([selectedRowArray containsObject:[NSString stringWithFormat:@"%d",(int)indexPath.row]]) {
  724. [selectedRowArray removeObject:[NSString stringWithFormat:@"%d",(int)indexPath.row]];
  725. }
  726. }else{
  727. //选中
  728. [selectedRowArray addObject:[NSString stringWithFormat:@"%d",(int)indexPath.row]];
  729. if (selectedRowArray.count == reply.count) {
  730. isAllSelect = YES;
  731. selectedBtn.selected = YES;
  732. }
  733. }
  734. }];
  735. [cell setClickBlock:^{
  736. //判断是否还有批量同意/批量拒绝的bar 有就删掉
  737. if (currentEditSection != -1 && reply.count < 2) {
  738. //正在批量 且没有申请可以批量
  739. [self setSelectToZero];
  740. selectedBtn.hidden = YES;
  741. selectedBtn = nil;
  742. [holderBar setHidden:YES];
  743. [editBtn setTitle:@"批量" forState:UIControlStateNormal];
  744. }
  745. [self getPlanInfos];
  746. }];
  747. return cell;
  748. }
  749. //已同意页面cell
  750. //PlanCell *cell = [PlanCell cellForTabelView:tableView];
  751. PlanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PlanCell"];
  752. if (!cell) {
  753. cell = [[PlanCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"PlanCell"];
  754. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  755. [cell.on_offBtn target:self];
  756. }
  757. [cell setModel:reply[indexPath.row]];
  758. cell.on_offBtn.tag = indexPath.section*100 + indexPath.row;
  759. [cell.on_offBtn setTitle:@"未带教订单" forState:UIControlStateNormal];
  760. [cell.on_offBtn setBackgroundColor:defGreen];
  761. [cell.on_offBtn setSelected:NO];
  762. [cell.on_offBtn setUserInteractionEnabled:NO];
  763. //订单状态显示找到正在计时的单元格
  764. if ([[reply[indexPath.row] objectForKey:@"RO_STATUS"] length] > 0) {
  765. if ([[reply[indexPath.row] objectForKey:@"RO_STATUS"] isEqualToString:@"0"]) {
  766. [cell.on_offBtn setTitle:@"订单进行中" forState:UIControlStateNormal];
  767. [cell.on_offBtn setSelected:YES];
  768. }else{
  769. [cell.on_offBtn setTitle:@"订单已完成" forState:UIControlStateNormal];
  770. [cell.on_offBtn setBackgroundColor:[UIColor lightGrayColor]];
  771. }
  772. }
  773. return cell;
  774. }
  775. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  776. {
  777. //planViewType; //区头样式 0已同意 1待审核 2已拒绝
  778. if (planViewType == 1) {
  779. return 140;
  780. }else{
  781. return 110;
  782. }
  783. }
  784. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  785. {
  786. return .1;
  787. }
  788. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  789. {
  790. if (stateInt == 0 || stateInt == 2) {
  791. return 130;
  792. }
  793. return 100;
  794. }
  795. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  796. {
  797. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  798. }
  799. #pragma mark 数据请求
  800. //获取计划订单信息
  801. - (void)getPlanInfos
  802. {
  803. if (![Util connectedToNetWork]) {
  804. showMsgUnconnect();
  805. return;
  806. }
  807. NSMutableArray *arr=[NSMutableArray array];
  808. [arr addPro:@"userId" Value:defUser.sfzmhm];
  809. [arr addPro:@"time" Value:dateString];
  810. [arr addPro:@"isPage" Value:@""];
  811. [arr addPro:@"pageSize" Value:@""];
  812. [arr addPro:@"currentPage" Value:@""];
  813. [arr addPro:@"status" Value:[NSString stringWithFormat:@"%d",(int)stateInt]];
  814. NSString* method = @"getCoachReserveInfos";
  815. ShowHUD();
  816. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  817. RemoveHUD();
  818. //NSLog(@"我的预约-->%@---->%@",arr,root);
  819. if (!root) {
  820. return ;
  821. }
  822. if ([root[@"code"] isEqualToString:@"1"]) {
  823. ShowMsg(root[@"body"]);
  824. return;
  825. }
  826. models = root[@"body"];
  827. if (models.count >0) {
  828. [myTableView reloadData];
  829. [holderV setHidden:YES];
  830. }else{
  831. [holderV setHidden:NO];
  832. }
  833. }];
  834. }
  835. - (void)uploadAppSignInfoWithType:(NSString *)singType
  836. {
  837. [LoadingView showHUD];
  838. if (![Util connectedToNetWork]) {
  839. showMsgUnconnect();
  840. return;
  841. }
  842. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  843. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  844. NSString *timeString = [dateFormatter stringFromDate:[NSDate date]];
  845. NSMutableArray *arr=[NSMutableArray array];
  846. [arr addPro:@"sim" Value:defUser.userDict[@"mobile"]];
  847. [arr addPro:@"coachOutId" Value:defUser.userDict[@"outId"]];
  848. [arr addPro:@"gps" Value:[NSString stringWithFormat:@"%f,%f,%@,3",myLocation.longitude,myLocation.latitude,timeString]];
  849. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  850. NSString *method = @"saveCoachSignIn";
  851. if (![singType isEqualToString:@"1"]) {
  852. //签退
  853. method = @"saveCoachSignOut";
  854. }
  855. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  856. RemoveHUD();
  857. if (!root) {
  858. if ([singType isEqualToString:@"1"]) {
  859. ShowMsg(@"签到失败,请重试");
  860. }else{
  861. ShowMsg(@"签退失败,请重试");
  862. }
  863. return;
  864. }
  865. if (![root[@"code"] isEqualToString:@"0"]) {
  866. ShowMsg(root[@"body"]);
  867. return;
  868. }
  869. if ([singType isEqualToString:@"1"]) {
  870. if ([root[@"code"] isEqualToString:@"0"]) {
  871. //签到成功 生成二维码计时
  872. if (isAfterDelay == YES) {
  873. isAfterDelay = NO;
  874. if (timer) {
  875. //NSLog(@"时关闭定器");
  876. [timer invalidate];
  877. timer = nil;
  878. }
  879. }
  880. if ([defUser.userDict[@"devnum"] length] < 1) {
  881. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"终端注册号获取失败,请尝试重新登录" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  882. [alert show];
  883. }
  884. [self makeBeginScanView];
  885. }
  886. }else{
  887. //签退成功 刷新表吧
  888. [self getPlanInfos];
  889. }
  890. [self getCoachSignForTrain];
  891. }];
  892. }
  893. //获取当天签到详情 调前将coachSignInDic置为nil
  894. - (void)getCoachSignForTrain
  895. {
  896. coachSignInDic = nil;
  897. [LoadingView showHUD];
  898. if (![Util connectedToNetWork]) {
  899. showMsgUnconnect();
  900. return;
  901. }
  902. NSMutableArray *arr=[NSMutableArray array];
  903. [arr addPro:@"coachOutId" Value:defUser.userDict[@"outId"]];
  904. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  905. NSString* method = @"getCoachSignForTrain";
  906. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  907. RemoveHUD();
  908. if (!root) {
  909. return;
  910. }
  911. if ([root[@"code"] isEqualToString:@"0"]) {
  912. NSDictionary *dic = root[@"body"];
  913. if (![dic isKindOfClass:[NSDictionary class]]) {
  914. return;
  915. }
  916. coachSignInDic = [NSDictionary dictionaryWithDictionary:dic];
  917. //学员列表
  918. stuSignInDic = coachSignInDic[@"stuMaps"];
  919. //判断日期是否有问题
  920. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  921. [formatter setDateFormat:@"yyyy-MM-dd"];
  922. NSString *dateStr = [formatter stringFromDate:[NSDate date]];
  923. if (![dateStr isEqualToString:dic[@"currentTime"]]) {
  924. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的手机日期可能存在偏差,请核对" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  925. [alert show];
  926. }
  927. }
  928. }];
  929. }
  930. //获取学员签到列表
  931. - (void)getCoachSignStuRecords
  932. {
  933. if (![Util connectedToNetWork]) {
  934. showMsgUnconnect();
  935. return;
  936. }
  937. NSMutableArray *arr=[NSMutableArray array];
  938. [arr addPro:@"coachId" Value:defUser.userDict[@"outId"]];
  939. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  940. NSString* method = @"getCoachSignStuRecords";
  941. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  942. if (!root) {
  943. return;
  944. }
  945. if ([root[@"code"] isEqualToString:@"1"]) {
  946. return;
  947. }
  948. //代表扫码成功 做不同的处理
  949. stuSignInDic = root[@"body"];
  950. if (isOverScan) {
  951. //结束计时
  952. if (stuSignInDic.count < 1) {
  953. //获取到学员为空 就停止刷新 关闭二维码 刷新表
  954. [self playAudioWithString:@"扫描成功,学员计时结束"];
  955. [self removeScanView];
  956. //学员不再是计划计时状态
  957. [[NSUserDefaults standardUserDefaults] setValue:@"0" forKey:@"PeriodIsPlan"];
  958. //结束计时 关闭位置上传
  959. // [self.homeVC finishUploadCoachGPS];
  960. if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"coachIsSignIn"] isEqualToString:@"0"]) {
  961. //掉签退接口
  962. [self uploadAppSignInfoWithType:@"0"];
  963. }else{
  964. [self getPlanInfos];
  965. }
  966. }
  967. }else{
  968. //开始计时
  969. if (stuSignInDic.count > 0) {
  970. [self playAudioWithString:@"扫描成功,开始计时"];
  971. [self removeScanView];//获取到学员 就停止刷新 关闭二维码
  972. [self getPlanInfos];
  973. //将计划计时状态保存至本地
  974. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  975. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  976. NSString *timeString = [dateFormatter stringFromDate:[NSDate date]];
  977. NSUserDefaults *coachDefault = [NSUserDefaults standardUserDefaults];
  978. [coachDefault setValue:[NSString stringWithFormat:@"%@",timeString] forKey:@"PeriodIsPlan"];
  979. //开始计时 开启位置汇报
  980. // [self.homeVC beginUploadCoachGPS];
  981. }
  982. }
  983. }];
  984. }
  985. //批量操作
  986. - (void)betchUpdateReserveState:(NSString *)state
  987. {
  988. if (![Util connectedToNetWork]) {
  989. showMsgUnconnect();
  990. return;
  991. }
  992. if (currentEditSection > models.count - 1) {
  993. return;
  994. }
  995. NSArray *reply = [models[currentEditSection] objectForKey:@"reserveInfoList"];
  996. NSString *ids = @"";
  997. for (NSString *index in selectedRowArray) {
  998. NSDictionary *dic = reply[[index integerValue]];
  999. ids = [ids stringByAppendingString:[NSString stringWithFormat:@"%@,",dic[@"RI_ID"]]];
  1000. }
  1001. //NSLog(@"---->%@",selectedRowArray);
  1002. if (ids.length < 1) {
  1003. ShowMsg(@"请选择批量对象");
  1004. [self getPlanInfos];
  1005. [self setSelectToZero];
  1006. selectedBtn.hidden = YES;
  1007. selectedBtn = nil;
  1008. [holderBar setHidden:YES];
  1009. [editBtn setTitle:@"批量" forState:UIControlStateNormal];
  1010. return;
  1011. }
  1012. ids = [ids substringToIndex:ids.length - 1];
  1013. NSMutableArray *arr=[NSMutableArray array];
  1014. [arr addPro:@"ids" Value:ids];
  1015. [arr addPro:@"status" Value:state];
  1016. [arr addPro:@"reason" Value:@""];
  1017. NSString* method = @"betchUpdateReserveState";
  1018. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  1019. //NSLog(@"批量操作-->%@---->%@",arr,root);
  1020. if (!root) {
  1021. return ;
  1022. }
  1023. if ([root[@"code"] isEqualToString:@"1"]) {
  1024. ShowMsg(root[@"body"]);
  1025. return;
  1026. }
  1027. ShowMsg(@"操作成功");
  1028. [self getPlanInfos];
  1029. [self setSelectToZero];
  1030. selectedBtn.hidden = YES;
  1031. selectedBtn = nil;
  1032. [holderBar setHidden:YES];
  1033. [editBtn setTitle:@"批量" forState:UIControlStateNormal];
  1034. }];
  1035. }
  1036. -(void)dealloc
  1037. {
  1038. if (_locService) {
  1039. [_locService stopUpdatingLocation];
  1040. _locService.delegate = nil;
  1041. }
  1042. }
  1043. - (void)didReceiveMemoryWarning {
  1044. [super didReceiveMemoryWarning];
  1045. // Dispose of any resources that can be recreated.
  1046. }
  1047. @end