RQHomePageViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. //
  2. // RQHomePageViewController.m
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/21.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. //
  8. #import "RQHomePageViewController.h"
  9. #import "MapManager.h"
  10. #import "RQQRCodeViewController.h"
  11. #import "ScanVC.h"
  12. #import "ScanPageVC.h"
  13. #import "DistenceTooLongMapVC.h"
  14. @interface RQHomePageViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate, SDCycleScrollViewDelegate>
  15. /// viewModel
  16. @property (nonatomic, readonly, strong) RQHomePageViewModel *viewModel;
  17. @property (nonatomic, readwrite, strong) RQHomePageTitleView *homePageTitleView;
  18. @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
  19. @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView;
  20. @property (nonatomic, readwrite, copy) NSArray <NSString *> *titles;
  21. //投诉建议入口-可共用
  22. @property (nonatomic, readwrite, strong) NYFloatingSuggestViewModel *floatingSuggestViewModel;
  23. @property (nonatomic, readwrite, strong) NYFloatingSuggestView *floatingSuggestView;
  24. //集中式理论
  25. @property (nonatomic, readwrite, assign) BOOL isNeedTest;
  26. @property (nonatomic, readwrite, assign) BOOL isCloseAudio;
  27. @property (nonatomic, readwrite, assign) NSInteger maxTime;
  28. @property (nonatomic, readwrite, copy) NSString *scanType;
  29. @property (nonatomic, readwrite, copy) NSString *scanData;
  30. @property (nonatomic, readwrite, assign) CLLocationCoordinate2D myLocation;
  31. @end
  32. @implementation RQHomePageViewController
  33. @dynamic viewModel;
  34. #pragma mark - SystemMethod
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. /// 初始化
  38. [self rq_setup];
  39. // if (myDelegate.isLogin) {
  40. // //更新登录信息 如果是登录状态的时候
  41. // reLogin(self);
  42. // }
  43. }
  44. - (void)viewDidAppear:(BOOL)animated {
  45. [super viewDidAppear:animated];
  46. if (RQ_COMMON_MANAGER.JSJP_APP_ICON_NEED_CHANGE) {
  47. [[UIApplication sharedApplication] setAlternateIconName:@"AppIcon_NewRule" completionHandler:^(NSError * _Nullable error) {
  48. if (error != nil) {
  49. NSLog(@"set alternative icon error:%@", error.localizedDescription);
  50. }
  51. }];
  52. } else {
  53. [[UIApplication sharedApplication] setAlternateIconName:@"AppIcon_Old" completionHandler:^(NSError * _Nullable error) {
  54. if (error != nil) {
  55. NSLog(@"set alternative icon error:%@", error.localizedDescription);
  56. }
  57. }];
  58. }
  59. }
  60. - (void)viewDidLayoutSubviews {
  61. [super viewDidLayoutSubviews];
  62. self.pagerView.frame = CGRectMake(0, (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT), RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT) - RQ_APPLICATION_TAB_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  63. }
  64. - (void)dealloc{
  65. //移除指定的通知,不然会造成内存泄露
  66. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"Tiku_Change" object:nil];
  67. }
  68. #pragma mark - PrivateMethods
  69. /// 初始化
  70. - (void)rq_setup {
  71. /// set up ...
  72. @weakify(self)
  73. [self.view addSubview:self.pagerView];
  74. [RACObserve(RQ_USER_MANAGER, currentUser) subscribeNext:^(RQUserModel *userModel) {
  75. @strongify(self)
  76. //头像
  77. CGFloat sBoader = (kNavBarHeight - 35)/2.0;
  78. UIButton *sideBtn = [[UIButton alloc] initWithFrame:CGRectMake(sBoader, kStatusHeight + sBoader, kNavBarHeight - sBoader*2, kNavBarHeight - sBoader*2)];
  79. [self.view addSubview:sideBtn];
  80. UIImageView *iv = [[UIImageView alloc] initWithFrame:sideBtn.bounds];
  81. [iv sd_setImageWithURL:[NSURL URLWithString:userModel.photo] placeholderImage:[UIImage imageNamed:@"头像"]];
  82. iv.contentMode = UIViewContentModeScaleAspectFill;
  83. [iv setBoardWid:1 Color:RQ_MAIN_COLOR CornerRadius:6];
  84. [iv setRound];
  85. [sideBtn addSubview:iv];
  86. [sideBtn addTarget:self action:@selector(showLeftViewAction) forControlEvents:UIControlEventTouchUpInside];
  87. UIBarButtonItem* bbi0 = [[UIBarButtonItem alloc] initWithCustomView:sideBtn];
  88. self.navigationItem.leftBarButtonItem = bbi0;
  89. }];
  90. if (myDelegate.isSyn) {
  91. myDelegate.isSyn = NO;
  92. if ([myDelegate.markQuestionTableData isKindOfClass:[NSMutableArray class]]) {
  93. if (myDelegate.markQuestionTableData.count == 0) {
  94. [DB_Que_Helper moveIsDoneToMarkQuestion];//移动已做题
  95. if (myDelegate.isLogin)//更新版本 先做一次同步
  96. {
  97. [self syncQuestion];
  98. }
  99. }
  100. }
  101. }
  102. //监听题库变化
  103. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction:) name:@"Tiku_Change" object:nil];
  104. // 注册手势驱动
  105. // __weak typeof(self)weakSelf = self;
  106. // [self cw_registerShowIntractiveWithEdgeGesture:YES transitionDirectionAutoBlock:^(CWDrawerTransitionDirection direction) {
  107. // if (direction == CWDrawerTransitionFromLeft) { // 左侧滑出
  108. // [weakSelf defaultAnimationFromLeft];
  109. // }
  110. // }];
  111. self.navigationItem.titleView = self.homePageTitleView;
  112. self.homePageTitleView.carTypeLabel.text = [RQ_YDTQuestion_Module getCarTypeCNNameWithCarType:RQ_YDTQuestion_Module.carType];
  113. if (RQ_COMMON_MANAGER.JSJP_APP_JSQ_ICON_OPEN) {//广告(福袋)-是否开启
  114. self.homePageTitleView.chad_layout_W.constant = 25;
  115. [self.homePageTitleView layoutIfNeeded];
  116. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  117. [NY_AD_MANAGER loadAdWithPosid:@"50164389" customView:self.homePageTitleView.chadView];
  118. });
  119. }
  120. [self.homePageTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH / 3.f, RQ_APPLICATION_NAV_BAR_HEIGHT));
  122. }];
  123. //二维码扫描登录网页
  124. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"erWeiMa.png"] originImageScaleToSize:CGSizeMake(22.5, 22.5)] style:UIBarButtonItemStyleDone target:self action:@selector(clickToScan)];
  125. item.tintColor = RQ_MAIN_COLOR;
  126. if (RQ_USER_MANAGER.currentUser.city && ![RQ_USER_MANAGER.currentUser.city isEqualToString:@""] && [RQ_USER_MANAGER.currentUser.city isEqualToString:@""]) {
  127. }
  128. [RACObserve(RQ_USER_MANAGER, currentUser) subscribeNext:^(RQUserModel *userModel) {
  129. @strongify(self)
  130. if ([RQ_USER_MANAGER.currentUser.isOpenScan boolValue]) {
  131. [self.navigationItem setRightBarButtonItem:item];
  132. } else {
  133. self.navigationItem.rightBarButtonItems = @[];
  134. }
  135. }];
  136. [[[[RQNotificationCenter rac_addObserverForName:RQCarTypeChangeNotification object:nil] takeUntil:self.rac_willDeallocSignal] deliverOnMainThread] subscribeNext:^(NSNotification * _Nullable x) {
  137. @strongify(self)
  138. self.pagerView.defaultSelectedIndex = 0;
  139. self.categoryView.defaultSelectedIndex = 0;
  140. [self.pagerView reloadData];
  141. [self.categoryView reloadData];
  142. self.pagerView.isListHorizontalScrollEnabled = ![RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"];
  143. self.homePageTitleView.carTypeLabel.text = [RQ_YDTQuestion_Module getCarTypeCNNameWithCarType:RQ_YDTQuestion_Module.carType];
  144. }];
  145. [[[[RACObserve(RQ_COMMON_MANAGER, APP_SWITCH) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable x) {
  146. @strongify(self)
  147. // self.pagerView.defaultSelectedIndex = 0;
  148. // self.categoryView.defaultSelectedIndex = 0;
  149. [self.pagerView reloadData];
  150. [self.categoryView reloadData];
  151. }];
  152. //投诉建议
  153. [self addFloatingSuggestView];
  154. }
  155. //添加到主窗口
  156. - (void)addFloatingSuggestView {
  157. NSInteger SP_COMPLAINT_DQBH = 0;
  158. for (ParamsItem *item in RQ_USER_MANAGER.currentUser.params) {
  159. if ([item.KEY isEqualToString:@"SP_COMPLAINT_DQBH"]) {
  160. SP_COMPLAINT_DQBH = [item.VALUE integerValue];
  161. }
  162. }
  163. if(SP_COMPLAINT_DQBH>0&&(SP_COMPLAINT_DQBH == [RQ_USER_MANAGER.currentUser.city intValue])){
  164. [self.view addSubview:self.floatingSuggestView];
  165. [self.floatingSuggestView mas_makeConstraints:^(MASConstraintMaker *make) {
  166. make.right.mas_equalTo(self.view).offset(-20.f);
  167. make.bottom.mas_equalTo(self.view).offset(-60.f);
  168. make.width.mas_equalTo(116.f);
  169. make.height.mas_equalTo(89.f);
  170. }];
  171. [self.floatingSuggestView bindViewModel:self.floatingSuggestViewModel];//绑定RAC
  172. }
  173. }
  174. - (void)notificationAction:(NSNotification *)notification{
  175. self.pagerView.defaultSelectedIndex = 0;
  176. self.categoryView.defaultSelectedIndex = 0;
  177. [self.pagerView reloadData];
  178. [self.categoryView reloadData];
  179. self.pagerView.isListHorizontalScrollEnabled = ![RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"];
  180. if ([notification.userInfo[@"zhigezhengChanged"] isEqualToString:@"NO"]) {
  181. return;
  182. }
  183. }
  184. /**显示左边抽屉
  185. */
  186. - (void)showLeftViewAction {
  187. [self defaultAnimationFromLeft];
  188. }
  189. - (void)clickToScan {
  190. @weakify(self)
  191. if (RQ_USER_MANAGER.isShouldLogin) {
  192. [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {
  193. @strongify(self)
  194. if (isSuccess) {
  195. if (activationModel.isShare) {
  196. if (activationModel.isActive == 1) {
  197. [self gotoPt];
  198. } else {
  199. [RQ_VIP_Module gotoVipViewWithDictType:RQ_USER_MANAGER.currentUser.city];
  200. }
  201. } else {
  202. [self gotoPt];
  203. }
  204. }
  205. }];
  206. }
  207. }
  208. - (void)gotoPt {
  209. @weakify(self)
  210. [QMUITips showLoadingInView:DefaultTipsParentView];
  211. RQQRCodeViewController *vc = [[RQQRCodeViewController alloc] init];
  212. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  213. [vc initBlock:^(NSString * _Nonnull result, BOOL isSuccess) {
  214. if (isSuccess) {
  215. [RQ_PT_Object_Module uploadScanCodeVerifyWithQRCodeResultStr:result resultBlock:^(BOOL isSuccess) {
  216. }];
  217. } else {
  218. ShowMsg(result);
  219. }
  220. }];
  221. [LOCATION_MANAGER updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location, BMKLocation * _Nullable bmkLocation) {
  222. @strongify(self)
  223. if (success) {
  224. if (RQ_USER_MANAGER.verifyLevel == 0) {
  225. [self presentViewController:vc animated:YES completion:^{
  226. [QMUITips hideAllTips];
  227. }];
  228. } else {
  229. if (bmkLocation.mockProbability <= RQ_USER_MANAGER.verifyLevel) {
  230. [self presentViewController:vc animated:YES completion:^{
  231. [QMUITips hideAllTips];
  232. }];
  233. } else {
  234. [RQ_SHARE_FUNCTION showAlertWithMessage:@"请勿篡改定位信息!" completion:^(NSUInteger selectedOtherButtonIndex) {
  235. [QMUITips hideAllTips];
  236. }];
  237. }
  238. }
  239. } else {
  240. [RQ_SHARE_FUNCTION showAlertWithMessage:@"定位失败!" completion:^(NSUInteger selectedOtherButtonIndex) {
  241. [QMUITips hideAllTips];
  242. }];
  243. }
  244. }];
  245. }
  246. - (void)getMyLocation {
  247. //定位功能
  248. [MBProgressHUD rq_showProgressHUD:@"正在获取当前位置..."];
  249. [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location, BMKLocation * _Nullable bmkLocation) {
  250. [MBProgressHUD rq_hideHUD];
  251. if (success) {
  252. _myLocation = location.coordinate;
  253. [self studentQrcode];
  254. }
  255. }];
  256. }
  257. /** 扫描二维码调取接口 */
  258. - (void)studentQrcode {
  259. if (![Util connectedToNetWork]) {
  260. showMsgUnconnect();
  261. return;
  262. }
  263. if (_myLocation.longitude == 0.0) {
  264. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"位置获取失败,请重新扫描二维码!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  265. return;
  266. }
  267. NSMutableArray *arr=[NSMutableArray array];
  268. [arr addPro:@"studentOutid" Value:RQ_USER_MANAGER.currentUser.outId];
  269. [arr addPro:@"qrcode" Value:_scanData];
  270. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  271. [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",_myLocation.longitude]];
  272. [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",_myLocation.latitude]];
  273. [arr addPro:@"type" Value:_scanType];
  274. [arr addPro:@"telType" Value:@"ios"];
  275. NSString *method = @"studentQrcode";
  276. NSString *str = [_scanType isEqualToString: @"1"] ? @"签到中...":@"签退中...";
  277. [MBProgressHUD rq_showProgressHUD:str];
  278. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  279. [MBProgressHUD rq_hideHUD];
  280. if (!root) {
  281. ShowMsg(@"操作失败,请重试!");
  282. [Tools playAudioWithString:@"操作失败,请重试!"];
  283. return;
  284. }
  285. if ([root[@"code"] integerValue] == 0) {//代表操作成功
  286. if ([_scanType isEqualToString:@"1"] || [_scanType isEqualToString:@"3"]) {
  287. myDelegate.trainStateLabel.text = @"理论学习中...";
  288. }
  289. if ([_scanType isEqualToString:@"2"]) {
  290. myDelegate.trainStateLabel.text = @"";
  291. }
  292. if (_isNeedTest) {
  293. switch ([_scanType integerValue]) { //1、签到 2、签退 3、过程验证
  294. case 1://签到成功
  295. if (_maxTime > 0) {
  296. [self setNotificationWithFireTime:_maxTime];
  297. }
  298. break;
  299. case 2://签退
  300. if ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] > 0) {
  301. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  302. }
  303. break;
  304. case 3://验证成功
  305. if (_maxTime > 0) {
  306. [self setNotificationWithFireTime:_maxTime];
  307. }
  308. break;
  309. default:
  310. break;
  311. }
  312. }
  313. }
  314. if ([root[@"code"] integerValue] == 2) {//距离理论教室位置较远
  315. NSString *str = root[@"msg"];
  316. if (str.length < 1) {
  317. return;
  318. }
  319. NSArray *mapArray = [str componentsSeparatedByString:@";"];
  320. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:[mapArray lastObject] preferredStyle:UIAlertControllerStyleAlert];
  321. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  322. [alert addAction:[UIAlertAction actionWithTitle:@"查看位置详情" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  323. //进入地图页面 传入两个点 一个距离 lng lat len
  324. if (mapArray.count > 3) {
  325. // lng = 123.467129,
  326. // lat = 41.813997
  327. //122.769684;41.515881;66822;您当前距离理论教室位置66822米,请到理论教室扫码!
  328. DistenceTooLongMapVC *mapVC = [[DistenceTooLongMapVC alloc] init];
  329. mapVC.lat1 = _myLocation.latitude;
  330. mapVC.lng1 = _myLocation.longitude;
  331. mapVC.lat2 = [mapArray[1] floatValue];
  332. mapVC.lng2 = [mapArray[0] floatValue];
  333. mapVC.distence = mapArray[2];
  334. mapVC.skipMspBlock = ^{
  335. _myLocation.longitude = 0.0;
  336. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"位置已重置,请重新扫描二维码!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  337. };
  338. [self navPushHideTabbarToVC:mapVC];
  339. }
  340. }]];
  341. [self presentViewController:alert animated:true completion:nil];
  342. return;
  343. }
  344. [Tools playAudioWithString:root[@"msg"]];
  345. ShowMsg(root[@"msg"]);
  346. }];
  347. }
  348. //语音播报或者推送
  349. - (void)setNotificationWithFireTime:(NSInteger)fireTime {
  350. //移除旧的通知
  351. if ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] > 0) {
  352. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  353. }
  354. //定义本地通知对象
  355. UILocalNotification *notification = [[UILocalNotification alloc]init];
  356. //设置调用时间
  357. notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:fireTime];
  358. //设置通知属性
  359. notification.alertBody = @"极速驾培提醒您"; //通知主体
  360. notification.applicationIconBadgeNumber = 1;//应用程序图标右上角显示的消息数
  361. notification.alertAction = @"打开应用"; //待机界面的滑动动作提示
  362. notification.soundName = @"TrainTest.mp3";//收到通知时播放的声音,默认消息声音
  363. // 通知参数
  364. NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:@"nothing",@"ShiCaoPeriodVC_reTakePhoto", nil];
  365. notification.userInfo = userDict;
  366. //调用通知
  367. [[UIApplication sharedApplication] scheduleLocalNotification:notification];
  368. }
  369. //更新第一次进入同步数据
  370. - (void)syncQuestion {
  371. if (![Util connectedToNetWork]) {
  372. return;
  373. }
  374. [self getMyQuestionType:@"" Subject:@""];
  375. }
  376. - (void)getMyQuestionType:(NSString*)type Subject:(NSString*)subject {
  377. NSMutableArray *arr = [NSMutableArray array];
  378. [arr addPro:@"user" Value:RQ_USER_MANAGER.currentUser._id];
  379. [arr addPro:@"type" Value:type];
  380. [arr addPro:@"subject" Value:subject];
  381. [arr addPro:@"carType" Value:RQ_YDTQuestion_Module.car_type];
  382. [arr addPro:@"isPage" Value:@"0"];
  383. [arr addPro:@"pageSize" Value:@"0"];
  384. [arr addPro:@"currentPage" Value:@"0"];
  385. NSString* method = @"getMyQuestionFavs";
  386. [MBProgressHUD rq_showProgressHUD:@"收藏、错题同步中,请稍后..."];
  387. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  388. //NSLog(@"同步错题收藏---->%@--->%@",arr,root);
  389. if (!root || [root[@"code"] integerValue] == 1) {
  390. [MBProgressHUD rq_hideHUD];
  391. ShowMsg(@"题库错题、收藏、排除同步失败,请在侧栏手动同步");
  392. return;
  393. }
  394. NSArray *body = [root objectForKey:@"body"];
  395. if (body.count > 0) {
  396. if ([DB_Que_Helper deleteAllMarkQuestion]) {
  397. [DB_Que_Helper setMarkQuestionWithArray:body];
  398. }
  399. }
  400. [MBProgressHUD rq_hideHUD];
  401. [MBProgressHUD rq_showTips:@"题库错题、收藏、排除已同步完毕"];
  402. }];
  403. }
  404. // 仿QQ从左侧划出
  405. - (void)defaultAnimationFromLeft {
  406. if (RQ_USER_MANAGER.isShouldLogin) {
  407. [RQ_APPDELEGATE.services pushViewModel:[[RQSettingViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil] animated:YES];
  408. }
  409. }
  410. #pragma mark - JXPagerViewDelegate
  411. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  412. return [UIView new];
  413. }
  414. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  415. return 0.f;
  416. }
  417. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  418. return [RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"]? 0.f : 49.f;
  419. }
  420. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  421. return self.categoryView;
  422. }
  423. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  424. //和categoryView的item数量一致
  425. return self.categoryView.titles.count;
  426. }
  427. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  428. myDelegate.subject = [NSString stringWithFormat:@"%d",(int)index + 1];
  429. NSInteger myIndex = index;
  430. RQ_YDTQuestion_Module.subject = myIndex;
  431. RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count;
  432. RQHomePageSubjectOneOrFourViewModel *homePageSubjectFourViewModel = [[RQHomePageSubjectOneOrFourViewModel alloc] initWithServices:self.viewModel.services params:@{RQHomePageCarTypeKey : @(RQHomePageCarType_Car), RQHomePageSubjectTypeKey : @(myIndex)}];
  433. RQHomePageSubjectOneOrFourViewController *homePageSubjectFourViewController = [[RQHomePageSubjectOneOrFourViewController alloc] initWithViewModel:homePageSubjectFourViewModel];
  434. return homePageSubjectFourViewController;
  435. }
  436. #pragma mark - JXCategoryViewDelegate
  437. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  438. RQ_YDTQuestion_Module.subject = index;
  439. RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count;
  440. myDelegate.subject = [NSString stringWithFormat:@"%d",(int)index + 1];
  441. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  442. }
  443. - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
  444. }
  445. - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
  446. }
  447. - (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
  448. // if (RQ_YDTQuestion_Module.subject == leftIndex) {
  449. // /// 向左滑 向右滚动
  450. // if (1.f - ratio > 0.7) {
  451. // RQ_YDTQuestion_Module.subject = rightIndex;
  452. // }
  453. // } else if (RQ_YDTQuestion_Module.subject == rightIndex) {
  454. // /// 向右滑 向左滚动
  455. // if (1.f - ratio > 0.3) {
  456. // RQ_YDTQuestion_Module.subject = leftIndex;
  457. // }
  458. // }
  459. }
  460. #pragma mark - JXPagerMainTableViewGestureDelegate
  461. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  462. if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) {
  463. //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应
  464. return NO;
  465. }
  466. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  467. }
  468. - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView {
  469. for (RQHomeSubPageViewController *list in self.pagerView.validListDict.allValues) {
  470. if (list.contentScrollView == scrollView) {
  471. return YES;
  472. }
  473. }
  474. return NO;
  475. }
  476. #pragma mark - SDCycleScrollViewDelegate
  477. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  478. }
  479. #pragma mark - LazyLoad
  480. - (JXPagerView *)pagerView {
  481. if (!_pagerView) {
  482. _pagerView = [[JXPagerView alloc] initWithDelegate:self];
  483. _pagerView.mainTableView.gestureDelegate = self;
  484. _pagerView.defaultSelectedIndex = 0;
  485. _pagerView.mainTableView.bounces = NO;
  486. _pagerView.isListHorizontalScrollEnabled = ![RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"];
  487. }
  488. return _pagerView;
  489. }
  490. - (JXCategoryTitleView *)categoryView {
  491. if (!_categoryView) {
  492. _categoryView = [[JXCategoryTitleView alloc] init];
  493. _categoryView.titles = self.titles;
  494. _categoryView.backgroundColor = [UIColor whiteColor];
  495. _categoryView.titleSelectedColor = RQ_MAIN_TEXT_COLOR_1;
  496. _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_2;
  497. _categoryView.titleFont = RQRegularFont(17);
  498. _categoryView.titleSelectedFont = RQSemiboldFont(22);
  499. _categoryView.titleColorGradientEnabled = YES;
  500. _categoryView.titleLabelZoomEnabled = YES;
  501. _categoryView.contentScrollViewClickTransitionAnimationEnabled = YES;
  502. _categoryView.titleLabelZoomSelectedVerticalOffset = 0.0f;
  503. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  504. lineView.indicatorColor = RQ_MAIN_COLOR;
  505. lineView.indicatorHeight = 4;
  506. lineView.verticalMargin = 0;
  507. _categoryView.indicators = @[lineView];
  508. _categoryView.defaultSelectedIndex = 0;
  509. _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  510. _categoryView.delegate = self;
  511. }
  512. return _categoryView;
  513. }
  514. - (NSArray<NSString *> *)titles {
  515. return @[@"科一", @"科二", @"科三", @"科四"];
  516. }
  517. - (RQHomePageTitleView *)homePageTitleView {
  518. if (!_homePageTitleView) {
  519. _homePageTitleView = [RQHomePageTitleView homePageTitleViewView];
  520. _homePageTitleView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH / 3.f, RQ_APPLICATION_NAV_BAR_HEIGHT);
  521. }
  522. return _homePageTitleView;
  523. }
  524. - (NYFloatingSuggestViewModel *)floatingSuggestViewModel {
  525. if(!_floatingSuggestViewModel){
  526. _floatingSuggestViewModel = [[NYFloatingSuggestViewModel alloc] init];
  527. }
  528. return _floatingSuggestViewModel;
  529. }
  530. - (NYFloatingSuggestView *)floatingSuggestView {
  531. if (!_floatingSuggestView) {
  532. _floatingSuggestView = [NYFloatingSuggestView floatingSuggestView];
  533. }
  534. return _floatingSuggestView;
  535. }
  536. @end