ImitatePeriodVC.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. //
  2. // ImitatePeriodVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2017/3/8.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #define dingColor [UIColor colorWithRed:236/255.0 green:190/255.0 blue:44/255.0 alpha:1]
  9. #import "ImitatePeriodVC.h"
  10. #import "ScanVC.h"
  11. #import "ProgressBarView.h"
  12. #import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
  13. #import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
  14. #import <BMKLocationkit/BMKLocationComponent.h>//引入定位功能所有的头文件
  15. @interface ImitatePeriodVC ()<BMKMapViewDelegate,BMKLocationManagerDelegate,BMKGeoCodeSearchDelegate,UITableViewDelegate,UITableViewDataSource>
  16. {
  17. BMKLocationManager *_locationManager ;
  18. BMKMapView *_mapView;
  19. BMKGeoCodeSearch *_searcher;
  20. UIButton *loctionBtn;
  21. UILabel *addressLabel,*detailAddressLabel;
  22. UIButton *on_offBtn;
  23. UITableView *mainTableView;
  24. //学习进度
  25. UITableView *learntableView;
  26. ProgressBarView *timeProgressView, *learnProgressView;
  27. NSArray *learnTimeArray;
  28. NSArray *poiInfos;
  29. NSArray *coachArray;
  30. CLLocationCoordinate2D myLocation;
  31. BOOL isPractice; //是否开启其他计时 eg:实操、集中理论
  32. BOOL SP_IS_MNQisTure;
  33. }
  34. @end
  35. @implementation ImitatePeriodVC
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. self.title = @"模拟计时";
  39. self.view.backgroundColor = backGroundColor;
  40. [self configNavigationBar];
  41. CGFloat x, y, w, h;
  42. x = 20;
  43. y = 10;
  44. w = (kSize.width - 40)/2.0;
  45. h = 60;
  46. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  47. formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  48. [formatter setDateFormat:@"yyyy.MM.dd-HH:mm-EEEE"];
  49. NSString *dateString = [formatter stringFromDate:[NSDate date]];
  50. //NSLog(@"dateString---->%@",dateString);
  51. NSArray *dateArray = [NSArray arrayWithObjects:@"暂无",@"暂无",@"暂无", nil];
  52. if (dateString.length > 0) {
  53. if ([dateString containsString:@"-"]) {
  54. dateArray = [dateString componentsSeparatedByString:@"-"];
  55. }
  56. }
  57. UILabel *label = [[UILabel alloc] setxywh];
  58. [label setText:[NSString stringWithFormat:@"%@:%@",[dateArray lastObject],[dateArray firstObject]] Font:FontTitle TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  59. [self.view addSubview:label];
  60. x += w;
  61. label = [[UILabel alloc] setxywh];
  62. [label setText:[NSString stringWithFormat:@"当前时间: %@",dateArray[1]] Font:FontTitle TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  63. [self.view addSubview:label];
  64. x = 20;
  65. y += h;
  66. w = kSize.width - 40;
  67. h = 100;
  68. UIView *mapBar = [[UIView alloc] setxywh];
  69. [mapBar borderColor:RQlineColor width:2 cornorRadius:0];
  70. mapBar.clipsToBounds = YES;;
  71. [self.view addSubview:mapBar];
  72. x = y = 0;
  73. w = 110;
  74. h = 122;
  75. //创建地图
  76. _mapView = [[BMKMapView alloc]setxywh];
  77. [mapBar addSubview:_mapView];
  78. [_mapView addViewWithRect:CGRectMake(x + w, y, 2, h)];
  79. _mapView.mapType = BMKMapTypeStandard;
  80. //这个设置重复是为了消除一个bug 记得
  81. _mapView.showsUserLocation = NO;
  82. _mapView.userTrackingMode = BMKUserTrackingModeNone;
  83. _mapView.zoomLevel = 16;
  84. _mapView.showsUserLocation = YES;
  85. BMKLocationViewDisplayParam *displayParam = [[BMKLocationViewDisplayParam alloc]init];
  86. displayParam.isRotateAngleValid = true;//跟随态旋转角度是否生效
  87. displayParam.isAccuracyCircleShow = false;//精度圈是否显示
  88. displayParam.locationViewOffsetX = 0;//定位偏移量(经度)
  89. displayParam.locationViewOffsetY = 0;//定位偏移量(纬度)
  90. [_mapView updateLocationViewWithParam:displayParam];
  91. x += w + 5;
  92. w = kSize.width - 40 - 115;
  93. h = 25;
  94. label = [[UILabel alloc] setxywh];
  95. [label setText:@"正在定位..." Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  96. [mapBar addSubview:label];
  97. addressLabel = label;
  98. y += h;
  99. h = 50;
  100. label = [[UILabel alloc] setxywh];
  101. [label setText:@"" Font:FontTitle TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  102. label.numberOfLines = 0;
  103. [mapBar addSubview:label];
  104. detailAddressLabel = label;
  105. y += h;
  106. h = 20;
  107. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  108. btn.frame = CGRectMake(x, y, w, h);
  109. [btn setTitle:@"地点微调" textColor:[UIColor blueColor] Font:FontTitle fotState:UIControlStateNormal];
  110. [btn setTitle:@"取消微调" forState:UIControlStateSelected];
  111. btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  112. [btn.titleLabel setTextAlignment:NSTextAlignmentLeft];
  113. [btn target:self tag:1];
  114. [mapBar addSubview:btn];
  115. loctionBtn = btn;
  116. for (ParamsItem *item in RQ_USER_MANAGER.currentUser.params) {
  117. if ([item.KEY isEqualToString:@"SP_IS_MNQ"]) {
  118. if ([item.VALUE isEqualToString:@"1"]) {
  119. SP_IS_MNQisTure = YES;
  120. } else {
  121. SP_IS_MNQisTure = NO;
  122. }
  123. }
  124. }
  125. y = mapBar.y +mapBar.height + 40;
  126. x = 20;
  127. w = kSize.width - 40.0;
  128. h = 40;
  129. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  130. btn.frame = CGRectMake(x, y, w, h);
  131. [btn setTitle:@"开始计时" textColor:RQlineColor Font:20 fotState:UIControlStateNormal];
  132. if (!SP_IS_MNQisTure) {
  133. [btn setTitle:@"结束计时" textColor:dingColor Font:20 fotState:UIControlStateSelected];
  134. }else{
  135. [btn setTitle:@"计时中..." textColor:dingColor Font:20 fotState:UIControlStateSelected];
  136. }
  137. [btn borderColor:RQlineColor width:1 cornorRadius:5];
  138. [btn target:self tag:2];
  139. btn.userInteractionEnabled = NO;
  140. [self.view addSubview:btn];
  141. on_offBtn = btn;
  142. if (!SP_IS_MNQisTure) {
  143. //教练手机模拟计时
  144. NSString *noticeString = @"模拟计时注意事项:\n模拟计时每天最多计时4个小时,若当日学习时间累计超过4小时,将按4小时计算。单次一次性产生4小时及以上学时的,系统将判断其为无效学时,自动清零,请知悉。";
  145. y += h + 30;
  146. h = [noticeString heightForWid:w Font:Font17] + 20;
  147. label = [[UILabel alloc] setxywh];
  148. [label setText:noticeString Font:Font17 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentLeft];
  149. label.numberOfLines = 0;
  150. [self.view addSubview:label];
  151. }else{
  152. //模拟器模拟计时 训练项目进度。 学时进度。 训练记录。
  153. if (myDelegate.isLogin) {
  154. [self getUserLearnRecord];
  155. }
  156. }
  157. y = mapBar.y +mapBar.height;
  158. h = kSize.height - y - kNavOffSet;
  159. mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, y, kSize.width, h) style:UITableViewStylePlain];
  160. mainTableView.delegate = self;
  161. mainTableView.dataSource = self;
  162. [self.view addSubview:mainTableView];
  163. mainTableView.hidden = YES;
  164. isPractice = NO;
  165. [self getStuSignFlag];
  166. //定位功能
  167. [self startLocation];
  168. }
  169. - (void)initLearnProgressWithDic:(NSDictionary *)dic {
  170. CGFloat y = on_offBtn.y + on_offBtn.height + 20;
  171. if (!timeProgressView) {
  172. timeProgressView = [[ProgressBarView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 50)];
  173. timeProgressView.titleString = @"学时进度:";
  174. [self.view addSubview:timeProgressView];
  175. }
  176. timeProgressView.allNeedTime = [dic[@"mnq_all_time"] integerValue];
  177. timeProgressView.finishTime = [dic[@"mnq_time"] integerValue];
  178. timeProgressView.RATIONKS = 60;
  179. y += 60;
  180. if (!learnProgressView) {
  181. learnProgressView = [[ProgressBarView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 25)];
  182. learnProgressView.titleString = @"训练进度:";
  183. [self.view addSubview:learnProgressView];
  184. }
  185. learnProgressView.allCount = [dic[@"mnq_total"] integerValue];
  186. learnProgressView.finishCount = [dic[@"mnq_num"] integerValue];
  187. learnProgressView.RATIONKS = 60;
  188. y += 40;
  189. if (!learntableView) {
  190. learnTimeArray = [NSArray array];
  191. learntableView = [[UITableView alloc] initWithFrame:CGRectMake(0, y, kSize.width, kSize.height - y - kNavOffSet) style:UITableViewStylePlain];
  192. learntableView.backgroundColor = backGroundColor;
  193. learntableView.delegate = self;
  194. learntableView.dataSource = self;
  195. [self.view addSubview:learntableView];
  196. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 30)];
  197. label.backgroundColor = backGroundColor;
  198. [label setText:@"学时记录" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  199. learntableView.tableHeaderView = label;
  200. }
  201. if ([dic[@"mnq_list"] isKindOfClass:[NSArray class]]) {
  202. learnTimeArray = dic[@"mnq_list"];
  203. }else {
  204. learnTimeArray = [NSArray array];
  205. }
  206. [learntableView reloadData];
  207. [self.view bringSubviewToFront:mainTableView];
  208. }
  209. -(void)viewWillAppear:(BOOL)animated
  210. {
  211. [super viewWillAppear:animated];
  212. [_mapView viewWillAppear];
  213. _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
  214. _searcher.delegate = self;
  215. _locationManager.delegate = self;
  216. }
  217. -(void)viewWillDisappear:(BOOL)animated
  218. {
  219. [super viewWillDisappear:animated];
  220. [_locationManager stopUpdatingLocation];
  221. [_mapView viewWillDisappear];
  222. _mapView.delegate = nil; // 不用时,置nil
  223. _searcher.delegate = nil;
  224. _locationManager.delegate = nil;
  225. }
  226. -(void)btnClick:(UIButton *)sender
  227. {
  228. if (sender.tag == 1) {
  229. //微调
  230. sender.selected = !sender.selected;
  231. if (sender.selected) {
  232. mainTableView.hidden = NO;
  233. [mainTableView reloadData];
  234. }else{
  235. mainTableView.hidden = YES;
  236. }
  237. }
  238. if (sender.tag == 2) {
  239. if (sender.selected) {
  240. //结束计时
  241. if (!SP_IS_MNQisTure) {
  242. [self uploadMnSignOut];
  243. }else{
  244. if (![Util connectedToNetWork]) {
  245. return;
  246. }
  247. NSMutableArray *arr=[NSMutableArray array];
  248. [arr addPro:@"stuId" Value:RQ_USER_MANAGER.currentUser.outId];
  249. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  250. NSString* method = @"getStuSignFlag";
  251. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  252. if (!root) {
  253. return;
  254. }
  255. if ([root[@"code"] isEqualToString:@"1"]) {
  256. return;
  257. }
  258. //这里接收服务器返回状态 当前训练培训训练状态 0 实操签退或模拟签退 1 实操签到 2 模拟签到 3 隔日训练
  259. switch ([[root[@"body"] objectForKey:@"status"] integerValue]) {
  260. case 0:
  261. //开始计时
  262. isPractice = NO;
  263. on_offBtn.selected = NO;
  264. break;
  265. case 1:
  266. //实操计时中
  267. isPractice = YES;
  268. break;
  269. case 2:
  270. //模拟计时中
  271. break;
  272. case 3:
  273. //隔日签到
  274. break;
  275. default:
  276. break;
  277. }
  278. }];
  279. }
  280. }else{
  281. //开始计时
  282. if (myDelegate.timer || isPractice) {
  283. ShowMsg(@"请先关闭其他计时");
  284. return;
  285. }
  286. [self getCurrentPXKWithComplete:^(NSString *pxkm) {
  287. [RQ_USER_MANAGER.currentUser updatePxjdWithPxjd:pxkm];
  288. [self showAlertForBeginOrEndPeriodWithString:@"请扫描设备二维码开始计时"];
  289. }];
  290. }
  291. }
  292. }
  293. - (void)showAlertForBeginOrEndPeriodWithString:(NSString *)aString {
  294. [RQ_SHARE_FUNCTION showAlertWithTitle:nil message:aString alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  295. if (selectedOtherButtonIndex == 0) {
  296. [self scanQRCode];
  297. }
  298. }];
  299. }
  300. - (void)scanQRCode {
  301. //调取相机扫描二维码
  302. ScanVC *scan = [[ScanVC alloc] init];
  303. scan.type = 2;
  304. [scan scanBlock:^(NSDictionary *dic) {
  305. //imitatePeriod 模拟器打模拟学时 imPeriod手机学时
  306. //教练outID 教练名字 教练经度 教练纬度 有效时间
  307. if ([dic[@"scanType"] isEqualToString:@"imPeriod"]) {
  308. if (![dic[@"dataString"] isKindOfClass:[NSString class]]) {
  309. ShowMsg(@"二维码数据错误,请重新扫描!");
  310. return;
  311. }
  312. coachArray = [dic[@"dataString"] componentsSeparatedByString:@";"];
  313. if (coachArray.count < 4) {
  314. ShowMsg(@"二维码数据错误,请重新扫描!");
  315. return;
  316. }
  317. [self uploadMnStuLoginWithType:1];//签到
  318. }else if ([dic[@"scanType"] isEqualToString:@"imitatePeriod"]) {
  319. //模拟器计时
  320. // devSn(序列号); dynamicCode(动态码);type(类型:1签到,2签退)
  321. if (![dic[@"dataString"] isKindOfClass:[NSString class]]) {
  322. ShowMsg(@"二维码数据错误,请重新扫描!");
  323. return;
  324. }
  325. coachArray = [dic[@"dataString"] componentsSeparatedByString:@";"];
  326. if (coachArray.count < 2) {
  327. ShowMsg(@"二维码数据错误,请重新扫描!");
  328. return;
  329. }
  330. [self uploadMnStuLoginWithType:2];//签到
  331. //重新扫码计时 刷新进度
  332. [self getUserLearnRecord];
  333. }else{
  334. [RQ_SHARE_FUNCTION showAlertWithTitle:nil message:@"请扫描模拟计时二维码" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  335. if (selectedOtherButtonIndex == 0) {
  336. [self scanQRCode];
  337. }
  338. }];
  339. }
  340. }];
  341. [self navPushHideTabbarToVC:scan];
  342. }
  343. - (void)getCurrentPXKWithComplete:(void(^)(NSString *pxkm))complete {
  344. ShowHUD();
  345. if (![Util connectedToNetWork]) {
  346. ShowMsg(@"请检查网络连接。");
  347. RemoveHUD();
  348. return;
  349. }
  350. NSMutableArray *arr = [NSMutableArray array];
  351. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuOutId"];
  352. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  353. NSString* method = @"getStudentStatusByStuOutId";
  354. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  355. RemoveHUD();
  356. if (!dict) {
  357. ShowMsgFailed();
  358. return;
  359. }
  360. if ( [dict[@"code"] isEqualToString:@"0"]) {
  361. if (complete) {
  362. complete(dict[@"body"]);
  363. }
  364. } else {
  365. ShowMsg(dict[@"body"]);
  366. }
  367. }];
  368. }
  369. #pragma mark 地图
  370. -(void)startLocation
  371. {
  372. if (!_locationManager) {
  373. //初始化实例
  374. _locationManager = [[BMKLocationManager alloc] init];
  375. //设置返回位置的坐标系类型 默认为国标
  376. _locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;//百度经纬度坐标
  377. }
  378. BOOL requestResult = [_locationManager requestLocationWithReGeocode:NO withNetworkState:NO completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {
  379. if (error)
  380. {
  381. ShowMsg([NSString stringWithFormat:@"定位失败:%@",error.description]);
  382. }else{
  383. myLocation = location.location.coordinate;
  384. _mapView.centerCoordinate = location.location.coordinate;
  385. //发起反向地理编码检索
  386. //发起反向地理编码检索
  387. _searcher =[[BMKGeoCodeSearch alloc]init];
  388. _searcher.delegate = self;
  389. BMKReverseGeoCodeSearchOption *reverseGeoCodeSearchOption = [[BMKReverseGeoCodeSearchOption alloc]init];
  390. reverseGeoCodeSearchOption.location = location.location.coordinate;
  391. BOOL flag = [_searcher reverseGeoCode:reverseGeoCodeSearchOption];;
  392. if (flag) {
  393. NSLog(@"反地理编码检索成功");
  394. } else {
  395. ShowMsg(@"反地理编码检索失败");
  396. }
  397. }
  398. }];
  399. if (requestResult == NO) {
  400. //
  401. ShowMsg(@"发起定位请求失败");
  402. }
  403. }
  404. /**
  405. 反向地理编码检索结果回调
  406. @param searcher 检索对象
  407. @param result 反向地理编码检索结果
  408. @param error 错误码,@see BMKCloudErrorCode
  409. */
  410. - (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeSearchResult *)result errorCode:(BMKSearchErrorCode)error {
  411. if (error == BMK_SEARCH_NO_ERROR)
  412. {
  413. //在此处理正常结果
  414. addressLabel.text = [NSString stringWithFormat:@"%@%@%@",result.addressDetail.district,result.addressDetail.streetName,result.addressDetail.streetNumber];
  415. //默认这个地址作为签到地址
  416. detailAddressLabel.text = result.address;
  417. //将周边存起来 微调的时候用
  418. poiInfos = result.poiList;
  419. //选择的位置加上标注
  420. BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
  421. annotation.coordinate = result.location;
  422. [_mapView addAnnotation:annotation];
  423. }
  424. else
  425. {
  426. [LoadingView showMsg:@"反向编码失败!"];
  427. }
  428. }
  429. //标注的代理
  430. -(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
  431. {
  432. if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
  433. BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
  434. newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
  435. // 设置该标注点动画显示
  436. newAnnotationView.animatesDrop = NO;
  437. return newAnnotationView;
  438. }
  439. return nil;
  440. }
  441. #pragma mark mainTableView
  442. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  443. {
  444. if (tableView == learntableView) {
  445. return learnTimeArray.count;
  446. }
  447. return poiInfos.count;
  448. }
  449. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  450. {
  451. if (tableView == learntableView) {
  452. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"learnCell"];
  453. if (cell == nil)
  454. {
  455. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"learnCell"];
  456. cell.contentView.backgroundColor = backGroundColor;
  457. cell.textLabel.font = [UIFont scaleSize:18];
  458. cell.detailTextLabel.font = [UIFont scaleSize:15];
  459. }
  460. NSDictionary *dic = learnTimeArray[indexPath.row];
  461. if ([dic[@"endDate"] length] > 10) {
  462. cell.textLabel.text = [NSString stringWithFormat:@"%@----%@",dic[@"userSignTime"],[dic[@"endDate"] substringFromIndex:10]];
  463. }else{
  464. cell.textLabel.text = [NSString stringWithFormat:@"%@----%@",dic[@"userSignTime"],dic[@"endDate"]];
  465. }
  466. int time = [dic[@"time"] intValue];
  467. int min = time%60;
  468. int hour = time/60;
  469. NSString *timeString = [NSString stringWithFormat:@"%d小时%d分钟",hour,min];
  470. if (hour == 0) {
  471. timeString = [NSString stringWithFormat:@"%d分钟",min];
  472. }
  473. cell.detailTextLabel.text = [NSString stringWithFormat:@"训练时间:%@ 设备号:%@",timeString,dic[@"devSn"]];
  474. return cell;
  475. }
  476. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  477. if (cell == nil)
  478. {
  479. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  480. cell.textLabel.textColor = kTitleColor;
  481. cell.textLabel.font = [UIFont scaleSize:FontTitle];
  482. cell.detailTextLabel.textColor = contentTextColor;
  483. cell.detailTextLabel.font = [UIFont scaleSize:FontTitle];
  484. }
  485. BMKPoiInfo *poiInfo = poiInfos[indexPath.row];
  486. cell.textLabel.text = poiInfo.name;
  487. cell.detailTextLabel.text = poiInfo.address;
  488. return cell;
  489. }
  490. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  491. {
  492. if (tableView == learntableView) {
  493. return;
  494. }
  495. BMKPoiInfo *info = poiInfos[indexPath.row];
  496. addressLabel.text = info.name;
  497. detailAddressLabel.text = info.address;
  498. _mapView.centerCoordinate = info.pt;
  499. myLocation = info.pt;
  500. //加标注之前要移除之前的
  501. if (_mapView.annotations.count > 0) {
  502. [_mapView removeAnnotations:_mapView.annotations];
  503. }
  504. //选择的位置加上标注
  505. BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
  506. annotation.coordinate = info.pt;
  507. [_mapView addAnnotation:annotation];
  508. mainTableView.hidden = YES;
  509. loctionBtn.selected = NO;
  510. }
  511. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  512. return [UIView new];
  513. }
  514. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  515. return .1;
  516. }
  517. #pragma mark 数据请求
  518. //获取当前学员签到状态
  519. - (void)getStuSignFlag
  520. {
  521. if (![Util connectedToNetWork]) {
  522. on_offBtn.userInteractionEnabled = YES;
  523. [on_offBtn setTitleColor:dingColor forState:UIControlStateNormal];
  524. on_offBtn.layer.borderColor = dingColor.CGColor;
  525. return;
  526. }
  527. NSMutableArray *arr=[NSMutableArray array];
  528. [arr addPro:@"stuId" Value:RQ_USER_MANAGER.currentUser.outId];
  529. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  530. NSString* method = @"getStuSignFlag";
  531. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  532. isPractice = NO;
  533. on_offBtn.userInteractionEnabled = YES;
  534. [on_offBtn setTitleColor:dingColor forState:UIControlStateNormal];
  535. on_offBtn.layer.borderColor = dingColor.CGColor;
  536. if (!root || [root[@"code"] isEqualToString:@"1"]) {
  537. return;
  538. }
  539. //这里接收服务器返回状态 当前训练培训训练状态 0 实操签退或模拟签退 1 实操签到 2 模拟签到 3 隔日训练 4集中理论 5终端实操
  540. switch ([[root[@"body"] objectForKey:@"status"] integerValue]) {
  541. case 0:
  542. //代表签退状态 看本地是否是签退状态 如果不是 置为签退状态
  543. on_offBtn.selected = NO;
  544. break;
  545. case 1:
  546. //实操计时中
  547. isPractice = YES;
  548. break;
  549. case 2:
  550. //模拟计时中
  551. on_offBtn.selected = YES;
  552. break;
  553. case 3:
  554. //隔日签到
  555. break;
  556. case 4:
  557. //集中理论
  558. isPractice = YES;
  559. break;
  560. case 5:
  561. //实操计时中
  562. isPractice = YES;
  563. break;
  564. default:
  565. break;
  566. }
  567. }];
  568. }
  569. /** 开始模拟计时
  570. @param type type 1:教练手机生成二维码。 2:设备生成二维码
  571. */
  572. - (void)uploadMnStuLoginWithType:(NSInteger)type
  573. {
  574. ShowHUD();
  575. if (![Util connectedToNetWork]) {
  576. showMsgUnconnect();
  577. return;
  578. }
  579. NSMutableArray *arr=[NSMutableArray array];
  580. NSString *method = @"uploadMnStuLogin";
  581. if (type == 1) {
  582. //教练outID 教练名字 教练经度 教练纬度 有效时间
  583. [arr addPro:@"stuOutId" Value:RQ_USER_MANAGER.currentUser.outId];
  584. [arr addPro:@"coachOutId" Value:[coachArray firstObject]];
  585. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  586. [arr addPro:@"stuLon" Value:[NSString stringWithFormat:@"%f",myLocation.longitude]];
  587. [arr addPro:@"stuLat" Value:[NSString stringWithFormat:@"%f",myLocation.latitude]];
  588. [arr addPro:@"coachLon" Value:coachArray[2]];
  589. [arr addPro:@"coachLat" Value:coachArray[3]];
  590. }else {
  591. //devSn(序列号);dynamicCode(动态码);type(类型:1签到,3签退)
  592. [arr addPro:@"loginCode" Value:RQ_USER_MANAGER.currentUser.loginCode];
  593. [arr addPro:@"devSn" Value:[coachArray firstObject]];
  594. [arr addPro:@"dynamicCode" Value:coachArray[1]];
  595. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  596. [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",myLocation.longitude]];
  597. [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",myLocation.latitude]];
  598. method = @"userLogin";
  599. }
  600. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  601. RemoveHUD();
  602. if (!root) {
  603. ShowMsg(@"开始计时失败,请重试!");
  604. [Tools playAudioWithString:@"开始计时失败,请重试"];
  605. return;
  606. }
  607. if ([root[@"code"] isEqualToString:@"1"]) {
  608. ShowMsg(root[@"body"]);
  609. [Tools playAudioWithString:root[@"body"]];
  610. return;
  611. }
  612. ShowMsg(@"开始计时成功");//@zhangrong
  613. [Tools playAudioWithString:@"开始计时成功"];
  614. on_offBtn.selected = YES;
  615. }];
  616. }
  617. /** 模拟签退
  618. */
  619. - (void)uploadMnSignOut
  620. {
  621. ShowHUD();
  622. if (![Util connectedToNetWork]) {
  623. showMsgUnconnect();
  624. return;
  625. }
  626. NSMutableArray *arr=[NSMutableArray array];
  627. [arr addPro:@"stuOutId" Value:RQ_USER_MANAGER.currentUser.outId];
  628. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  629. [arr addPro:@"pxkm" Value:RQ_USER_MANAGER.currentUser.pxjd];
  630. NSString *method = @"uploadMnSignOut";
  631. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  632. RemoveHUD();
  633. if (!root) {
  634. ShowMsg(@"结束计时失败,请重试!");
  635. return;
  636. }
  637. if ([root[@"code"] isEqualToString:@"1"]) {
  638. ShowMsg(root[@"body"]);
  639. return;
  640. }
  641. ShowMsg((root[@"body"] || ![root[@"body"] isEqualToString:@""])? root[@"body"] : @"本次模拟计时已结束!");
  642. on_offBtn.selected = NO;
  643. }];
  644. }
  645. //获取学习进度
  646. - (void)getUserLearnRecord
  647. {
  648. if (![Util connectedToNetWork]) {
  649. showMsgUnconnect();
  650. return;
  651. }
  652. NSMutableArray *arr=[NSMutableArray array];
  653. [arr addPro:@"loginCode" Value:RQ_USER_MANAGER.currentUser.loginCode];
  654. NSString *method = @"getUserLearnRecord";
  655. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  656. if (!root) {
  657. ShowMsg(@"获取学习进度失败");
  658. return;
  659. }
  660. if ([root[@"code"] isEqualToString:@"1"]) {
  661. ShowMsg(root[@"body"]);
  662. return;
  663. }
  664. [self initLearnProgressWithDic:root[@"body"]];
  665. }];
  666. }
  667. - (void)didReceiveMemoryWarning {
  668. [super didReceiveMemoryWarning];
  669. }
  670. @end