RQTimeSingleItemViewModel.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. @interface RQTimeSingleItemViewModel () {
  15. // PeriodVC *KVOPeriodVC;
  16. NYBasetjTimeVC *KVOPeriodVC;
  17. ShiCaoPeriodVC *KVOSCPeriodVC;
  18. NSString *orderId; // 订单ID
  19. NSString *classCode; // 课程编码
  20. NSString *subject; // 科目
  21. NSString *coachOrderId; // 教练订单ID
  22. NSDictionary *coachQRCodeDic;
  23. }
  24. @end
  25. @implementation RQTimeSingleItemViewModel
  26. - (instancetype)init {
  27. if (self = [super init]) {
  28. @weakify(self)
  29. self.itemSize = CGSizeMake(RQ_FIT_HORIZONTAL(90.f), RQ_FIT_HORIZONTAL(120.f) - 8.f);
  30. self.operation = ^{
  31. if (RQ_USER_MANAGER.isShouldLogin) {
  32. [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {
  33. @strongify(self)
  34. if (isSuccess) {
  35. if (activationModel.isShare) {
  36. if (activationModel.isActive == 1) {
  37. [self gotoVCWithStr:self.title];
  38. } else {
  39. [RQ_VIP_Module gotoVipViewWithDictType:RQ_USER_MANAGER.currentUser.city];
  40. }
  41. } else {
  42. [self gotoVCWithStr:self.title];
  43. }
  44. }
  45. }];
  46. }
  47. };
  48. }
  49. return self;
  50. }
  51. - (NSString *)itemClassName {
  52. return @"RQTimeSingleCell";
  53. }
  54. - (void)gotoVCWithStr:(NSString *)str {
  55. if ([str isEqualToString:@"理论计时"]) {
  56. [self gotoPeriod:0];
  57. } else if ([str isEqualToString:@"从业考核"]||[str isEqualToString:@"从业计时"]) {
  58. [self gotoPeriod:1];
  59. } else if ([str isEqualToString:@"我的学时"]) {
  60. [self gotoTrainInfo];
  61. } else {
  62. }
  63. }
  64. - (void)gotoPeriod:(int)type {
  65. NYBasetjTimeVC *vc = nil;
  66. if(type==0){
  67. if ([myDelegate.tPeriodVC isKindOfClass:[NYTheoryTimeVC class]]) {
  68. vc = myDelegate.tPeriodVC;
  69. }else {
  70. KVOPeriodVC = [self getNYTheoryTimeVC] ;
  71. vc = KVOPeriodVC;
  72. }
  73. }else if(type==1){
  74. if ([myDelegate.tPeriodVC isKindOfClass:[NYGetjobTimeVC class]]) {
  75. vc = myDelegate.tPeriodVC;
  76. }else {
  77. KVOPeriodVC = [self getNYGetjobTimeVC];
  78. vc = KVOPeriodVC;
  79. }
  80. }
  81. if(vc)[self navPushHideTabbarToVC:vc];
  82. // PeriodVC *vc = nil;
  83. // if (myDelegate.tPeriodVC) {
  84. // vc = myDelegate.tPeriodVC;
  85. // }else {
  86. // KVOPeriodVC = [[PeriodVC alloc] init];
  87. // vc = KVOPeriodVC;
  88. // }
  89. // [self navPushHideTabbarToVC:vc];
  90. }
  91. - (NYBasetjTimeVC *)getNYTheoryTimeVC{
  92. NYTheoryTimeViewModel *viewModel = [[NYTheoryTimeViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil];
  93. NYTheoryTimeVC *timeViewController = [[NYTheoryTimeVC alloc] initWithViewModel:viewModel];
  94. return timeViewController;
  95. }
  96. - (NYBasetjTimeVC *)getNYGetjobTimeVC{
  97. NYGetjobTimeViewModel *viewModel = [[NYGetjobTimeViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil];
  98. NYGetjobTimeVC *timeViewController = [[NYGetjobTimeVC alloc] initWithViewModel:viewModel];
  99. return timeViewController;
  100. }
  101. - (void)gotoTimi {
  102. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 32];
  103. alert.backgroundViewColor = backGroundColor;
  104. alert.customViewColor = RQ_MAIN_COLOR;
  105. UITextView *view = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH - 64, RQ_SCREEN_HEIGHT * 0.5)];
  106. view.font = [UIFont systemFontOfSize:15];
  107. NSMutableString *content = [NSMutableString string];
  108. 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 为了保证您的合法利益,请遵守规定,同时也请提醒您的教练,手机不能断网或在带教过程中长时间接听电话,否则会影响您的学时有效性判断,导致学时无效";
  109. view.text = content.mutableCopy;
  110. view.backgroundColor = backGroundColor;
  111. CGFloat textHeight = [view.text heightForWid:view.width Font:15];
  112. view.height = (textHeight > RQ_SCREEN_HEIGHT/2)? RQ_SCREEN_HEIGHT/2 : textHeight;
  113. [alert addCustomView:view];
  114. [alert addButton:@"不再显示" actionBlock:^(void) {
  115. [[NSUserDefaults standardUserDefaults] setValue:@"doNotShowNotice" forKey:@"isShowNotice"];
  116. [self gotoScanVCAction];
  117. }];
  118. [alert addButton:@"同意" actionBlock:^(void) {
  119. [self gotoScanVCAction];
  120. }];
  121. if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isShowNotice"] isKindOfClass:[NSString class]] && [[[NSUserDefaults standardUserDefaults] objectForKey:@"isShowNotice"] isEqualToString:@"doNotShowNotice"]) {
  122. [self gotoScanVCAction];
  123. }else {
  124. [alert showInfo:RQControllerHelper.currentViewController title:@"" subTitle:@"" closeButtonTitle:@"不同意" duration:0.0f];
  125. }
  126. }
  127. - (void)gotoTrainInfo {
  128. if (RQ_USER_MANAGER.isycbd == 1 && RQ_USER_MANAGER.ycbdFaceCount == 0) {
  129. 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]];
  130. RQCustomWebViewViewController *vc = [[RQCustomWebViewViewController alloc] init];
  131. vc.url = URL.absoluteString;
  132. vc.webView.scrollView.bounces = NO;
  133. RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:vc];
  134. [RQControllerHelper.topViewController presentViewController:nav animated:YES completion:nil];
  135. } else {
  136. TrainInfoVC * tvc = [[TrainInfoVC alloc]init];
  137. [self navPushHideTabbarToVC:tvc];
  138. }
  139. }
  140. // 跳转至扫码页面
  141. - (void)gotoScanVCAction {
  142. ScanVC *scan = [[ScanVC alloc] init];
  143. scan.type = 1;
  144. scan.homeVC = RQControllerHelper.currentViewController;
  145. [scan scanBlock:^(NSDictionary *scanQRCodeResultDic) {
  146. coachQRCodeDic = scanQRCodeResultDic;
  147. if ([scanQRCodeResultDic[@"scanType"] isEqualToString:@"allSignOut"]) {
  148. [self updateReserveEnd];
  149. }else if ([scanQRCodeResultDic[@"scanType"] isEqualToString:@"jhPeriod"]) {
  150. [self uploadReserveOrder];
  151. }
  152. }];
  153. [self navPushHideTabbarToVC:scan];
  154. }
  155. - (void)navPushHideTabbarToVC:(UIViewController*)vc {
  156. //判断是否是homebase的子视图控制器(它的子视图控制器直接设置self.hidesBottomBarWhenPushed = YES;会无效)
  157. dispatch_async(dispatch_get_main_queue(), ^{
  158. UIViewController *mVc = RQControllerHelper.currentViewController;
  159. mVc.hidesBottomBarWhenPushed = YES;
  160. [mVc.navigationController pushViewController:vc animated:YES];
  161. if (!mVc.navigationController.tabBarController.tabBar.isHidden) {
  162. mVc.hidesBottomBarWhenPushed = NO;
  163. }
  164. });
  165. }
  166. #pragma mark - Net Methodds
  167. //生成订单
  168. - (void)uploadReserveOrder {
  169. [LoadingView showHUD];
  170. if (![Util connectedToNetWork]) {
  171. showMsgUnconnect();
  172. return;
  173. }
  174. NSMutableArray *arr=[NSMutableArray array];
  175. [arr addPro:@"reserveId" Value:[coachQRCodeDic[@"dataString"] componentsSeparatedByString:@";"][3]];
  176. [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser._id];
  177. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  178. [arr addPro:@"coachId" Value:[coachQRCodeDic[@"dataString"] componentsSeparatedByString:@";"].lastObject];
  179. [arr addPro:@"sim" Value:RQ_USER_MANAGER.currentUser.telphone];
  180. [arr addPro:@"stuOutId" Value:RQ_USER_MANAGER.currentUser.outId];
  181. [arr addPro:@"coachOutId" Value:[coachQRCodeDic[@"dataString"] componentsSeparatedByString:@";"][0]];
  182. NSString* method = @"uploadReserveOrder";
  183. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  184. RemoveHUD();
  185. if (!root) {
  186. ShowMsg(@"开始计时失败,请重试!");
  187. [Tools playAudioWithString:@"开始计时失败,请崇试!"];
  188. return;
  189. }
  190. if ([root[@"code"] isEqualToString:@"1"]) {
  191. ShowMsg(root[@"body"]);
  192. [Tools playAudioWithString:root[@"body"]];
  193. return;
  194. }
  195. orderId = [root[@"body"] objectForKey:@"id"];
  196. subject = [root[@"body"] objectForKey:@"subject"];
  197. ShowMsg(@"签到成功!");
  198. [Tools playAudioWithString:@"签到成功,开始实操计时,请系好安全带"];
  199. }];
  200. }
  201. - (void)updateReserveEnd {
  202. [LoadingView showHUD];
  203. if (![Util connectedToNetWork]) {
  204. showMsgUnconnect();
  205. return;
  206. }
  207. NSMutableArray *arr = [NSMutableArray array];
  208. [arr addPro:@"orderId" Value:[coachQRCodeDic[@"dataString"] componentsSeparatedByString:@";"].lastObject];
  209. [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser._id];
  210. [arr addPro:@"coachId" Value:[coachQRCodeDic[@"dataString"] componentsSeparatedByString:@";"][0]];
  211. NSString* method = @"updateReserveEnd";
  212. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  213. RemoveHUD();
  214. if (!root) {
  215. ShowMsg(@"签退失败!");
  216. [Tools playAudioWithString:@"签退失败!"];
  217. return;
  218. }
  219. if ([root[@"code"] isEqualToString:@"1"]) {
  220. ShowMsg(root[@"body"]);
  221. [Tools playAudioWithString:root[@"body"]];
  222. return;
  223. }
  224. ShowMsg(@"签退成功!");
  225. [Tools playAudioWithString:@"签退成功!"];
  226. }];
  227. }
  228. @end