RQTimeSingleItemViewModel.m 12 KB

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