RQTimeSingleItemViewModel.m 12 KB

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