RQTimeSingleItemViewModel.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. //
  2. // RQTimeSingleItemViewModel.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/11/25.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQTimeSingleItemViewModel.h"
  9. #import "TrainInfoVC.h"//我的学时
  10. #import "RQCustomWebViewViewController.h"
  11. #import "ScanVC.h"
  12. #import "NYTheoryTimeViewModel.h"
  13. #import "NYGetjobTimeViewModel.h"
  14. #import "NYClassRoomViewModel.h"
  15. #import "NYTcarStudentLiveModel.h"
  16. #import "NYKaoMockExaminationModel.h"
  17. @interface RQTimeSingleItemViewModel () {
  18. // PeriodVC *KVOPeriodVC;
  19. NYBasetjTimeVC *KVOPeriodVC;
  20. // NYBasetjTimeVC *KVOCYPeriodVC;//从业
  21. ShiCaoPeriodVC *KVOSCPeriodVC;
  22. NSString *orderId; // 订单ID
  23. NSString *classCode; // 课程编码
  24. NSString *subject; // 科目
  25. NSString *coachOrderId; // 教练订单ID
  26. NSDictionary *coachQRCodeDic;
  27. }
  28. @property (nonatomic,strong) NYTcarStudentLiveModel *tcarStudentLiveModel;
  29. @property (nonatomic,strong) NYKaoMockExaminationModel *kaoMockExaminationModel;
  30. @end
  31. @implementation RQTimeSingleItemViewModel
  32. - (instancetype)init {
  33. if (self = [super init]) {
  34. @weakify(self)
  35. self.itemSize = CGSizeMake(RQ_FIT_HORIZONTAL(90.f), RQ_FIT_HORIZONTAL(120.f) - 8.f);
  36. self.operation = ^{
  37. if (RQ_USER_MANAGER.isShouldLogin) {
  38. [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {
  39. @strongify(self)
  40. if (isSuccess) {
  41. if (activationModel.isShare) {
  42. if (activationModel.isActive == 1||[RQ_COMMON_MANAGER.JSJP_SHARE_CITY rangeOfString:RQ_USER_MANAGER.currentUser.city].location != NSNotFound) {//2108 不判断
  43. [self gotoVCWithStr:self.title];
  44. } else {
  45. [RQ_VIP_Module gotoVipViewWithDictType:RQ_USER_MANAGER.currentUser.city];
  46. }
  47. } else {
  48. [self gotoVCWithStr:self.title];
  49. }
  50. }
  51. }];
  52. }
  53. };
  54. }
  55. return self;
  56. }
  57. - (NSString *)itemClassName {
  58. return @"RQTimeSingleCell";
  59. }
  60. - (void)gotoVCWithStr:(NSString *)str {
  61. if([RQ_USER_MANAGER.currentUser.userName containsString:@"游客"]){//游客特殊处理
  62. ShowMsg(@"您是游客身份,无法使用计时");
  63. return;
  64. }
  65. if ([str isEqualToString:@"理论计时"]) {
  66. [self gotoPeriod:0];
  67. } else if ([str isEqualToString:@"从业考核"]||[str isEqualToString:@"从业计时"]) {
  68. [self gotoPeriod:1];
  69. } else if ([str isEqualToString:@"我的学时"]) {
  70. [self gotoTrainInfo];
  71. } else if ([str isEqualToString:@"课堂培训"]) {
  72. [self gotoPeriod:2];
  73. } else if ([str isEqualToString:@"模拟培训"]) {
  74. [self gotoPeriod:3];
  75. } else if ([str isEqualToString:@"实车认证"]) {
  76. [self gotoTcarStudentLive];
  77. } else if ([str isEqualToString:@"科一考核"]) {
  78. [self gotoKaoMockExamination];
  79. }
  80. }
  81. - (void)gotoPeriod:(int)type {
  82. NYBasetjTimeVC *vc = nil;
  83. if(type==0){
  84. if(RQ_USER_MANAGER.isCykh&&(RQ_USER_MANAGER.busitype == 11 || RQ_USER_MANAGER.busitype == 12)){
  85. ShowMsg(@"您是从业资格人员,请点击从业计时");
  86. return;
  87. }
  88. if ([myDelegate.tPeriodVC isKindOfClass:[NYTheoryTimeVC class]]||
  89. [myDelegate.tPeriodVC isKindOfClass:[NYGetjobTimeVC class]]) {
  90. vc = myDelegate.tPeriodVC;
  91. }else {
  92. if(myDelegate.timer){
  93. ShowMsg(@"请先关闭理论计时");
  94. return;
  95. }
  96. //判断-是否是 辽宁-并且当前是科目一时
  97. NSString *citystr = @"yntms,2101,2108";
  98. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  99. NSLog(@"pxkm=%@",pxkm);
  100. if(pxkm==nil) pxkm=@"1";
  101. if ([citystr rangeOfString:RQ_USER_MANAGER.currentUser.city].location != NSNotFound) {
  102. if(pxkm.intValue==1){
  103. KVOPeriodVC = [self getNYGetLNTimeVC:1];
  104. vc = KVOPeriodVC;
  105. }else{
  106. RQ_USER_MANAGER.cykhPxkmStr = @"4"; //如果学员信息阶段是234的时候就直接默认科目四学时, 不用选择
  107. KVOPeriodVC = [self getNYGetLNTimeVC:4];
  108. vc = KVOPeriodVC;
  109. }
  110. }else{
  111. KVOPeriodVC = [self getNYTheoryTimeVC];
  112. vc = KVOPeriodVC;
  113. }
  114. }
  115. }else if(type==1){
  116. if ([myDelegate.tPeriodVC isKindOfClass:[NYGetjobTimeVC class]]) {
  117. vc = myDelegate.tPeriodVC;
  118. }else {
  119. if(myDelegate.timer){
  120. ShowMsg(@"请先关闭理论计时");
  121. return;
  122. }
  123. KVOPeriodVC = [self getNYGetjobTimeVC];
  124. vc = KVOPeriodVC;
  125. }
  126. }else if(type==2){
  127. NYClassRoomViewModel *viewModel = [[NYClassRoomViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil];
  128. NYClassRoomVC *classViewController = [[NYClassRoomVC alloc] initWithViewModel:viewModel];
  129. //timeViewController.vcType = TimeVCTypeAJob;
  130. [self navPushHideTabbarToVC:classViewController];
  131. return;
  132. }else if(type==3){
  133. NYClassRoomViewModel *viewModel = [[NYClassRoomViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil];
  134. viewModel.isSimulationRoom = YES;
  135. viewModel.title = @"模拟训练";
  136. NYClassRoomVC *classViewController = [[NYClassRoomVC alloc] initWithViewModel:viewModel];
  137. //timeViewController.vcType = TimeVCTypeAJob;
  138. [self navPushHideTabbarToVC:classViewController];
  139. return;
  140. }
  141. if(vc)[self navPushHideTabbarToVC:vc];
  142. // PeriodVC *vc = nil;
  143. // if (myDelegate.tPeriodVC) {
  144. // vc = myDelegate.tPeriodVC;
  145. // }else {
  146. // KVOPeriodVC = [[PeriodVC alloc] init];
  147. // vc = KVOPeriodVC;
  148. // }
  149. // [self navPushHideTabbarToVC:vc];
  150. }
  151. - (NYBasetjTimeVC *)getNYTheoryTimeVC{
  152. NYTheoryTimeViewModel *viewModel = [[NYTheoryTimeViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil];
  153. NYTheoryTimeVC *timeViewController = [[NYTheoryTimeVC alloc] initWithViewModel:viewModel];
  154. timeViewController.vcType = TimeVCTypeTheory;
  155. return timeViewController;
  156. }
  157. - (NYBasetjTimeVC *)getNYGetjobTimeVC{
  158. NYGetjobTimeViewModel *viewModel = [[NYGetjobTimeViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil];
  159. NYGetjobTimeVC *timeViewController = [[NYGetjobTimeVC alloc] initWithViewModel:viewModel];
  160. timeViewController.vcType = TimeVCTypeAJob;
  161. return timeViewController;
  162. }
  163. //辽宁 只有 1,4
  164. - (NYBasetjTimeVC *)getNYGetLNTimeVC:(int)type{
  165. NYGetjobTimeViewModel *viewModel = [[NYGetjobTimeViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil];
  166. viewModel.subject_array = type==4?@[@"2"] :@[@"0",@"2"];
  167. [viewModel setNavTitle: type==4? @"理论计时(科四)":@"理论计时(科一)"];
  168. NYGetjobTimeVC *timeViewController = [[NYGetjobTimeVC alloc] initWithViewModel:viewModel];
  169. timeViewController.vcType = TimeVCTypeAJob;
  170. return timeViewController;
  171. }
  172. - (void)gotoTimi {
  173. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 32];
  174. alert.backgroundViewColor = backGroundColor;
  175. alert.customViewColor = RQ_MAIN_COLOR;
  176. UITextView *view = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH - 64, RQ_SCREEN_HEIGHT * 0.5)];
  177. view.font = [UIFont systemFontOfSize:15];
  178. NSMutableString *content = [NSMutableString string];
  179. content.string = @"请注意:\n\n 本系统是按照2016驾驶员培训新国标要求,严格照规范设计,终端上传分钟学时来计算,在计时过程中请注意以下几点: \n\n1、如果所在地市有开启围栏,请注意确保您当前的位置在规定的围栏内训练,否则分钟学时无效 \n\n2、如果所在地市有开启培训时段,请确保您当前训练时间符合规定,比如早上6:00-20:00 \n\n3、确保教练手机是正常联网且安装支持3G以上的移动,联通和电信的SIM,否则无法采集到手机终端的位置,系统会判定分钟学时无效 \n\n4、系统为防止特殊情况,教练带教过程接到电话,允许断网一段时间,默认15分钟,如果超过15分钟,所带教学员的分钟学时无效 \n\n5、学员和教练的有效距离不能超过规定距离,否则分钟学时无效,详情请咨询教练或您所在的驾校 \n\n6、系统默认在2分钟及以上时间段内,如果移动距离为0米,视为无效分钟学时 \n\n7、根据规定,学员科目二和科目三1分钟内移动距离不能低于规定的数值,否则分钟学时无效,具体询问驾校或教练 \n\n8、如果您选择计时收费训练,您可以在训练结束且支付完成后对教练进行评价和投诉,如果训练完成后不支付,您的学时将无效且无法进行下一次训练 \n\n 为了保证您的合法利益,请遵守规定,同时也请提醒您的教练,手机不能断网或在带教过程中长时间接听电话,否则会影响您的学时有效性判断,导致学时无效";
  180. view.text = content.mutableCopy;
  181. view.backgroundColor = backGroundColor;
  182. CGFloat textHeight = [view.text heightForWid:view.width Font:15];
  183. view.height = (textHeight > RQ_SCREEN_HEIGHT/2)? RQ_SCREEN_HEIGHT/2 : textHeight;
  184. [alert addCustomView:view];
  185. [alert addButton:@"不再显示" actionBlock:^(void) {
  186. [[NSUserDefaults standardUserDefaults] setValue:@"doNotShowNotice" forKey:@"isShowNotice"];
  187. [self gotoScanVCAction];
  188. }];
  189. [alert addButton:@"同意" actionBlock:^(void) {
  190. [self gotoScanVCAction];
  191. }];
  192. if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isShowNotice"] isKindOfClass:[NSString class]] && [[[NSUserDefaults standardUserDefaults] objectForKey:@"isShowNotice"] isEqualToString:@"doNotShowNotice"]) {
  193. [self gotoScanVCAction];
  194. }else {
  195. [alert showInfo:RQControllerHelper.currentViewController title:@"" subTitle:@"" closeButtonTitle:@"不同意" duration:0.0f];
  196. }
  197. }
  198. //实车认证
  199. - (void)gotoTcarStudentLive{
  200. [self.tcarStudentLiveModel tcarStudentLivedo];
  201. }
  202. //科一考核
  203. - (void)gotoKaoMockExamination{
  204. [self.kaoMockExaminationModel studentKaoMockExaminationdo];
  205. }
  206. - (void)gotoTrainInfo {
  207. // //是否开启活体检测 0-不开启 1-开启 活体检测比对动作数量
  208. // if (RQ_USER_MANAGER.isycbd == 1 && RQ_USER_MANAGER.ycbdFaceCount == 0) {
  209. //开头有35进入H5 - 修改登录下发匹配
  210. NSString *citystr = [RQ_USER_MANAGER getParamsKey:@"SP_QUERY_TRAIN_CLASS_DQBH"];
  211. if ([citystr rangeOfString:RQ_USER_MANAGER.currentUser.city].location != NSNotFound) {
  212. NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://fj.jppt.com.cn/jsjp/wechat/toClassHourQueryByStuId.html?stuId=%@&dqbh=%@&app=ios",RQ_USER_MANAGER.currentUser.outId, RQ_USER_MANAGER.currentUser.city]];
  213. RQCustomWebViewViewController *vc = [[RQCustomWebViewViewController alloc] init];
  214. vc.url = URL.absoluteString;
  215. vc.webView.scrollView.bounces = NO;
  216. RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:vc];
  217. [RQControllerHelper.topViewController presentViewController:nav animated:YES completion:nil];
  218. } else {
  219. TrainInfoVC * tvc = [[TrainInfoVC alloc]init];
  220. [self navPushHideTabbarToVC:tvc];
  221. }
  222. }
  223. // 跳转至扫码页面
  224. - (void)gotoScanVCAction {
  225. ScanVC *scan = [[ScanVC alloc] init];
  226. scan.type = 1;
  227. scan.homeVC = RQControllerHelper.currentViewController;
  228. [scan scanBlock:^(NSDictionary *scanQRCodeResultDic) {
  229. coachQRCodeDic = scanQRCodeResultDic;
  230. if ([scanQRCodeResultDic[@"scanType"] isEqualToString:@"allSignOut"]) {
  231. [self updateReserveEnd];
  232. }else if ([scanQRCodeResultDic[@"scanType"] isEqualToString:@"jhPeriod"]) {
  233. [self uploadReserveOrder];
  234. }
  235. }];
  236. [self navPushHideTabbarToVC:scan];
  237. }
  238. - (void)navPushHideTabbarToVC:(UIViewController*)vc {
  239. //判断是否是homebase的子视图控制器(它的子视图控制器直接设置self.hidesBottomBarWhenPushed = YES;会无效)
  240. dispatch_async(dispatch_get_main_queue(), ^{
  241. UIViewController *mVc = RQControllerHelper.currentViewController;
  242. mVc.hidesBottomBarWhenPushed = YES;
  243. [mVc.navigationController pushViewController:vc animated:YES];
  244. if (!mVc.navigationController.tabBarController.tabBar.isHidden) {
  245. mVc.hidesBottomBarWhenPushed = NO;
  246. }
  247. });
  248. }
  249. #pragma mark - Net Methodds
  250. //生成订单
  251. - (void)uploadReserveOrder {
  252. [LoadingView showHUD];
  253. if (![Util connectedToNetWork]) {
  254. showMsgUnconnect();
  255. return;
  256. }
  257. NSMutableArray *arr=[NSMutableArray array];
  258. [arr addPro:@"reserveId" Value:[coachQRCodeDic[@"dataString"] componentsSeparatedByString:@";"][3]];
  259. [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser._id];
  260. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  261. [arr addPro:@"coachId" Value:[coachQRCodeDic[@"dataString"] componentsSeparatedByString:@";"].lastObject];
  262. [arr addPro:@"sim" Value:RQ_USER_MANAGER.currentUser.telphone];
  263. [arr addPro:@"stuOutId" Value:RQ_USER_MANAGER.currentUser.outId];
  264. [arr addPro:@"coachOutId" Value:[coachQRCodeDic[@"dataString"] componentsSeparatedByString:@";"][0]];
  265. NSString* method = @"uploadReserveOrder";
  266. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  267. RemoveHUD();
  268. if (!root) {
  269. ShowMsg(@"开始计时失败,请重试!");
  270. [Tools playAudioWithString:@"开始计时失败,请崇试!"];
  271. return;
  272. }
  273. if ([root[@"code"] isEqualToString:@"1"]) {
  274. ShowMsg(root[@"body"]);
  275. [Tools playAudioWithString:root[@"body"]];
  276. return;
  277. }
  278. orderId = [root[@"body"] objectForKey:@"id"];
  279. subject = [root[@"body"] objectForKey:@"subject"];
  280. ShowMsg(@"签到成功!");
  281. [Tools playAudioWithString:@"签到成功,开始实操计时,请系好安全带"];
  282. }];
  283. }
  284. - (void)updateReserveEnd {
  285. [LoadingView showHUD];
  286. if (![Util connectedToNetWork]) {
  287. showMsgUnconnect();
  288. return;
  289. }
  290. NSMutableArray *arr = [NSMutableArray array];
  291. [arr addPro:@"orderId" Value:[coachQRCodeDic[@"dataString"] componentsSeparatedByString:@";"].lastObject];
  292. [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser._id];
  293. [arr addPro:@"coachId" Value:[coachQRCodeDic[@"dataString"] componentsSeparatedByString:@";"][0]];
  294. NSString* method = @"updateReserveEnd";
  295. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  296. RemoveHUD();
  297. if (!root) {
  298. ShowMsg(@"签退失败!");
  299. [Tools playAudioWithString:@"签退失败!"];
  300. return;
  301. }
  302. if ([root[@"code"] isEqualToString:@"1"]) {
  303. ShowMsg(root[@"body"]);
  304. [Tools playAudioWithString:root[@"body"]];
  305. return;
  306. }
  307. ShowMsg(@"签退成功!");
  308. [Tools playAudioWithString:@"签退成功!"];
  309. }];
  310. }
  311. /// property
  312. - (NYTcarStudentLiveModel *)tcarStudentLiveModel{
  313. if(!_tcarStudentLiveModel){
  314. _tcarStudentLiveModel = [NYTcarStudentLiveModel new];
  315. }
  316. return _tcarStudentLiveModel;
  317. }
  318. - (NYKaoMockExaminationModel *)kaoMockExaminationModel{
  319. if(!_kaoMockExaminationModel){
  320. _kaoMockExaminationModel = [NYKaoMockExaminationModel new];
  321. //注册-通知
  322. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(examinationPostNotif:) name:RQHomeSubPageTypeKHModeKey object:nil];
  323. }
  324. return _kaoMockExaminationModel;
  325. }
  326. - (void)examinationPostNotif: (NSNotification *)notification {
  327. int score = [notification.object intValue];
  328. [self.kaoMockExaminationModel signOutHandledo:score];
  329. }
  330. @end