RQHomePageViewController.m 28 KB

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