MyPlanVC.m 49 KB

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