RQVipViewController.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. //
  2. // RQVipViewController.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/3/1.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQVipViewController.h"
  9. @interface RQVipViewController ()
  10. /// viewModel
  11. @property (nonatomic, readonly, strong) RQVipViewModel *viewModel;
  12. @property (nonatomic, readwrite, strong) RQVipBuyView *vipBuyView;
  13. @property (nonatomic, readwrite, strong) RQVipBuyNewView *vipBuyNewView;
  14. @property (nonatomic, readwrite, strong) RQTypeModel *chooseTypeModel;
  15. @property (nonatomic, readwrite, strong) IAPManager *iapManager;
  16. @property (nonatomic, readwrite, strong) RQPayViewController *payViewController;
  17. @end
  18. @implementation RQVipViewController
  19. @dynamic viewModel;
  20. #pragma mark - SystemMethod
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. /// 初始化
  24. [self rq_setup];
  25. }
  26. - (void)dealloc {
  27. RQ_VIP_Module.chooseTypeModel = nil;
  28. [[NSNotificationCenter defaultCenter] removeObserver:self];
  29. }
  30. - (void)viewDidLayoutSubviews {
  31. [super viewDidLayoutSubviews];
  32. CGFloat customHeight = (self.viewModel.vipPageType == RQVIPPageType_Alert)? self.view.rq_height : RQ_SCREEN_HEIGHT;
  33. self.collectionView.size = CGSizeMake(RQ_SCREEN_WIDTH, self.view.rq_height - RQ_FIT_HORIZONTAL(110.f) - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  34. // self.vipBuyView.frame = CGRectMake(0, customHeight - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - RQ_FIT_HORIZONTAL(93.f), RQ_SCREEN_WIDTH, RQ_FIT_HORIZONTAL(93.f) + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  35. self.vipBuyNewView.frame = CGRectMake(0, customHeight - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - RQ_FIT_HORIZONTAL(110.f), RQ_SCREEN_WIDTH, RQ_FIT_HORIZONTAL(110.f) + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  36. }
  37. #pragma mark - PrivateMethods
  38. /// 初始化
  39. - (void)rq_setup {
  40. /// set up ...
  41. @weakify(self)
  42. self.collectionView.bounces = NO;
  43. self.flowLayout.sectionHeadersPinToVisibleBounds = (self.viewModel.vipPageType == RQVIPPageType_Alert);
  44. // [self.collectionView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  45. // @strongify(self)
  46. // graColor.fromColor = (self.viewModel.vipPageType == RQVIPPageType_Alert)? [UIColor qmui_colorWithHexString:@"#FFFFFF"] : [UIColor qmui_colorWithHexString:@"#2C2D3C"];
  47. // graColor.toColor = (self.viewModel.vipPageType == RQVIPPageType_Alert)? [UIColor qmui_colorWithHexString:@"#FEEEDF"] : [UIColor qmui_colorWithHexString:@"#2C2D3C"];
  48. // graColor.type = QQGradualChangeTypeLeftToRight;
  49. // } size:CGSizeMake(RQ_SCREEN_WIDTH, self.view.rq_height) cornerRadius:QQRadiusZero]]];
  50. self.collectionView.backgroundColor = RQ_MAIN_TEXT_COLOR_WHITE;
  51. // [self.view addSubview:self.vipBuyView];
  52. [self.view addSubview:self.vipBuyNewView];
  53. [[[RACObserve(self.viewModel, dataSource) distinctUntilChanged] deliverOnMainThread] subscribeNext:^(id _Nullable x) {
  54. @strongify(self)
  55. if (self.viewModel.dataSource.count > 0) {
  56. RQVipHeaderImageViewNewGroupViewModel *vipHeaderImageViewGroupViewModel = self.viewModel.dataSource.firstObject;
  57. if (vipHeaderImageViewGroupViewModel.itemViewModels.count > 0) {
  58. NSArray *currentArr = [vipHeaderImageViewGroupViewModel.itemViewModels.rac_sequence filter:^BOOL(RQVipSinglePriceItemViewModel *vipSinglePriceItemViewModel) {
  59. return ![vipSinglePriceItemViewModel.typeModel.dictLabel containsString:@"理论实操计时"];
  60. }].array;
  61. RQVipSinglePriceItemViewModel *vipSinglePriceItemViewModel;
  62. if (currentArr.count > 0) {
  63. vipSinglePriceItemViewModel = currentArr.firstObject;
  64. } else {
  65. vipSinglePriceItemViewModel = vipHeaderImageViewGroupViewModel.itemViewModels.firstObject;
  66. }
  67. if (RQObjectIsNil(RQ_VIP_Module.chooseTypeModel)) {
  68. RQ_VIP_Module.chooseTypeModel = vipSinglePriceItemViewModel.typeModel;
  69. } else {
  70. }
  71. }
  72. }
  73. }];
  74. [self initPayNoti];
  75. [self.vipBuyView.buyBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  76. @strongify(self)
  77. if (!self.vipBuyView.userAgreeBtn.selected) {
  78. [[RACScheduler mainThreadScheduler] schedule:^{
  79. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请阅读用户协议!才能开通会员哦!" confirmTitle:@"立即阅读" cancelTitle:@"取消" confirmAction:^{
  80. @strongify(self)
  81. self.vipBuyView.userAgreeBtn.selected = YES;
  82. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://ys.zzxcx.net/jsjp-sf.html"]];
  83. RQWebViewModel *viewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey : request,RQViewModelWebViewTypeKey:@(RQWebViewType_VIP)}];
  84. RQWebViewViewController *viewController = [[RQWebViewViewController alloc] initWithViewModel:viewModel];
  85. RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:viewController];
  86. [RQControllerHelper.currentViewController presentViewController:nav animated:YES completion:nil];
  87. } cancelAction:nil];
  88. }];
  89. return;
  90. }
  91. if (RQObjectIsNil(RQ_VIP_Module.chooseTypeModel)) {
  92. [MBProgressHUD rq_showTips:@"暂无可用VIP套餐"];
  93. } else {
  94. NSString *message = @"即将购买VIP";
  95. NSString *confirmTitle = @"购买";
  96. message = [NSString stringWithFormat:@"即将购买%@",RQ_VIP_Module.chooseTypeModel.dictLabel];
  97. [[RACScheduler mainThreadScheduler] schedule:^{
  98. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:message confirmTitle:confirmTitle cancelTitle:@"取消" confirmAction:^{
  99. [[RACScheduler mainThreadScheduler] schedule:^{
  100. if ([RQ_USER_MANAGER.currentUser.loginCode isEqualToString:@"350881199205290949"]) {
  101. /// 调起苹果内购
  102. [MBProgressHUD rq_showProgressHUD:@"购买中..."];
  103. NSString *idStr = [NSString stringWithFormat:@"com.kestrel.JSJPStudent.vip.%ld",RQ_VIP_Module.chooseTypeModel.dictCode];
  104. [[IAPManager shareIAPManager] startPurchaseWithID:idStr completeHandle:^(IAPPurchType type, NSData * _Nonnull data, NSString * _Nonnull transactionIdentifier, BOOL isTest) {
  105. if (type == IAPPurchSuccess) {
  106. [[RQ_HTTP_Service postApplePayWithReceiptData:data transactionIdentifier:transactionIdentifier type:YES] subscribeNext:^(id _Nullable x) {
  107. [MBProgressHUD rq_hideHUD];
  108. [[NSNotificationCenter defaultCenter] postNotificationName:RQUserNotificationAlipayOrWechatSuccess object:nil userInfo:nil];
  109. } error:^(NSError * _Nullable error) {
  110. [MBProgressHUD rq_hideHUD];
  111. [MBProgressHUD rq_showErrorTips:error];
  112. }];
  113. } else {
  114. [MBProgressHUD rq_hideHUD];
  115. }
  116. }];
  117. } else {
  118. /// 其他
  119. RQPayViewModel *payViewModel = [[RQPayViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  120. RQViewModelUtilKey : RQ_VIP_Module.chooseTypeModel,
  121. }];
  122. self.payViewController = [[RQPayViewController alloc] initWithViewModel:payViewModel];
  123. [RQControllerHelper.currentViewController presentPanModal:self.payViewController];
  124. }
  125. }];
  126. } cancelAction:^{
  127. }];
  128. }];
  129. }
  130. }];
  131. [self.vipBuyNewView.buyBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  132. @strongify(self)
  133. if (!self.vipBuyNewView.userAgreeBtn.selected) {
  134. [[RACScheduler mainThreadScheduler] schedule:^{
  135. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请阅读用户协议!才能开通会员哦!" confirmTitle:@"立即阅读" cancelTitle:@"取消" confirmAction:^{
  136. @strongify(self)
  137. self.vipBuyNewView.userAgreeBtn.selected = YES;
  138. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://ys.zzxcx.net/jsjp-sf.html"]];
  139. RQWebViewModel *viewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey : request,RQViewModelWebViewTypeKey:@(RQWebViewType_VIP)}];
  140. RQWebViewViewController *viewController = [[RQWebViewViewController alloc] initWithViewModel:viewModel];
  141. RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:viewController];
  142. [RQControllerHelper.currentViewController presentViewController:nav animated:YES completion:nil];
  143. } cancelAction:nil];
  144. }];
  145. return;
  146. }
  147. if (RQObjectIsNil(RQ_VIP_Module.chooseTypeModel)) {
  148. [MBProgressHUD rq_showTips:@"暂无可用VIP套餐"];
  149. } else {
  150. NSString *message = @"即将购买VIP";
  151. NSString *confirmTitle = @"购买";
  152. message = [NSString stringWithFormat:@"即将购买%@",RQ_VIP_Module.chooseTypeModel.dictLabel];
  153. [[RACScheduler mainThreadScheduler] schedule:^{
  154. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:message confirmTitle:confirmTitle cancelTitle:@"取消" confirmAction:^{
  155. [[RACScheduler mainThreadScheduler] schedule:^{
  156. if ([RQ_USER_MANAGER.currentUser.loginCode isEqualToString:@"350881199205290949"]) {
  157. /// 调起苹果内购
  158. [MBProgressHUD rq_showProgressHUD:@"购买中..."];
  159. NSString *idStr = [NSString stringWithFormat:@"com.kestrel.JSJPStudent.vip.%ld",RQ_VIP_Module.chooseTypeModel.dictCode];
  160. [[IAPManager shareIAPManager] startPurchaseWithID:idStr completeHandle:^(IAPPurchType type, NSData * _Nonnull data, NSString * _Nonnull transactionIdentifier, BOOL isTest) {
  161. if (type == IAPPurchSuccess) {
  162. [[RQ_HTTP_Service postApplePayWithReceiptData:data transactionIdentifier:transactionIdentifier type:YES] subscribeNext:^(id _Nullable x) {
  163. [MBProgressHUD rq_hideHUD];
  164. [[NSNotificationCenter defaultCenter] postNotificationName:RQUserNotificationAlipayOrWechatSuccess object:nil userInfo:nil];
  165. } error:^(NSError * _Nullable error) {
  166. [MBProgressHUD rq_hideHUD];
  167. [MBProgressHUD rq_showErrorTips:error];
  168. }];
  169. } else {
  170. [MBProgressHUD rq_hideHUD];
  171. }
  172. }];
  173. } else {
  174. /// 其他
  175. RQPayViewModel *payViewModel = [[RQPayViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  176. RQViewModelUtilKey : RQ_VIP_Module.chooseTypeModel,
  177. }];
  178. self.payViewController = [[RQPayViewController alloc] initWithViewModel:payViewModel];
  179. [RQControllerHelper.currentViewController presentPanModal:self.payViewController];
  180. }
  181. }];
  182. } cancelAction:^{
  183. }];
  184. }];
  185. }
  186. }];
  187. }
  188. - (void)initPayNoti {
  189. [[NSNotificationCenter defaultCenter] addObserver:self
  190. selector:@selector(ailyPayOrWechatSuccessAction)
  191. name:RQUserNotificationAlipayOrWechatSuccess
  192. object:nil];
  193. [[NSNotificationCenter defaultCenter] addObserver:self
  194. selector:@selector(ailyPayOrWechatFailAction)
  195. name:RQUserNotificationAlipayOrWechatFail
  196. object:nil];
  197. }
  198. // 支付成功
  199. - (void)ailyPayOrWechatSuccessAction {
  200. @weakify(self)
  201. RQVideoVipModel *historyVideoVipModel = RQ_VIP_Module.videoVipModel;
  202. [MBProgressHUD rq_showProgressHUD:@"更新VIP信息..."];
  203. // 处理支付结果
  204. NSLog(@"处理支付成功结果");
  205. [[[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
  206. [subscriber sendNext:@"延时3.f秒"];
  207. return nil;
  208. }] delay:3.f] subscribeNext:^(id x) {
  209. [RQ_VIP_Module isVipWithSubject:0 complete:^(BOOL isVip) {
  210. @strongify(self)
  211. [MBProgressHUD rq_hideHUD];
  212. if ([RQ_VIP_Module.chooseTypeModel.dictLabel containsString:@"科一"]) {
  213. if (RQStringIsNotEmpty(historyVideoVipModel.subject1)) {
  214. /// 续费
  215. if ([historyVideoVipModel.subject1 isEqualToString:RQ_VIP_Module.videoVipModel.subject1]) {
  216. /// 续费未查询到结果
  217. [self checkVipFail];
  218. } else {
  219. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已续费成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  220. @strongify(self)
  221. if (self.payViewController) {
  222. [self.payViewController dismissViewControllerAnimated:YES completion:nil];
  223. }
  224. }];
  225. }
  226. } else {
  227. /// 购买
  228. if (RQStringIsEmpty(RQ_VIP_Module.videoVipModel.subject1)) {
  229. /// 购买未查询到结果
  230. [self checkVipFail];
  231. } else {
  232. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已购买成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  233. @strongify(self)
  234. if (self.payViewController) {
  235. [self.payViewController dismissViewControllerAnimated:YES completion:nil];
  236. }
  237. }];
  238. }
  239. }
  240. } else if ([RQ_VIP_Module.chooseTypeModel.dictLabel containsString:@"科二"]) {
  241. if (RQStringIsNotEmpty(historyVideoVipModel.subject2)) {
  242. /// 续费
  243. if ([historyVideoVipModel.subject2 isEqualToString:RQ_VIP_Module.videoVipModel.subject2]) {
  244. /// 续费未查询到结果
  245. [self checkVipFail];
  246. } else {
  247. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已续费成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  248. @strongify(self)
  249. if (self.payViewController) {
  250. [self.payViewController dismissViewControllerAnimated:YES completion:nil];
  251. }
  252. }];
  253. }
  254. } else {
  255. /// 购买
  256. if (RQStringIsEmpty(RQ_VIP_Module.videoVipModel.subject2)) {
  257. /// 购买未查询到结果
  258. [self checkVipFail];
  259. } else {
  260. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已购买成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  261. @strongify(self)
  262. if (self.payViewController) {
  263. [self.payViewController dismissViewControllerAnimated:YES completion:nil];
  264. }
  265. }];
  266. }
  267. }
  268. } else if ([RQ_VIP_Module.chooseTypeModel.dictLabel containsString:@"科三"]) {
  269. if (RQStringIsNotEmpty(historyVideoVipModel.subject3)) {
  270. /// 续费
  271. if ([historyVideoVipModel.subject3 isEqualToString:RQ_VIP_Module.videoVipModel.subject3]) {
  272. /// 续费未查询到结果
  273. [self checkVipFail];
  274. } else {
  275. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已续费成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  276. @strongify(self)
  277. if (self.payViewController) {
  278. [self.payViewController dismissViewControllerAnimated:YES completion:nil];
  279. }
  280. }];
  281. }
  282. } else {
  283. /// 购买
  284. if (RQStringIsEmpty(RQ_VIP_Module.videoVipModel.subject3)) {
  285. /// 购买未查询到结果
  286. [self checkVipFail];
  287. } else {
  288. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已购买成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  289. @strongify(self)
  290. if (self.payViewController) {
  291. [self.payViewController dismissViewControllerAnimated:YES completion:nil];
  292. }
  293. }];
  294. }
  295. }
  296. } else if ([RQ_VIP_Module.chooseTypeModel.dictLabel containsString:@"科四"]) {
  297. if (RQStringIsNotEmpty(historyVideoVipModel.subject4)) {
  298. /// 续费
  299. if ([historyVideoVipModel.subject4 isEqualToString:RQ_VIP_Module.videoVipModel.subject4]) {
  300. /// 续费未查询到结果
  301. [self checkVipFail];
  302. } else {
  303. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已续费成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  304. @strongify(self)
  305. if (self.payViewController) {
  306. [self.payViewController dismissViewControllerAnimated:YES completion:nil];
  307. }
  308. }];
  309. }
  310. } else {
  311. /// 购买
  312. if (RQStringIsEmpty(RQ_VIP_Module.videoVipModel.subject4)) {
  313. /// 购买未查询到结果
  314. [self checkVipFail];
  315. } else {
  316. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已购买成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  317. @strongify(self)
  318. if (self.payViewController) {
  319. [self.payViewController dismissViewControllerAnimated:YES completion:nil];
  320. }
  321. }];
  322. }
  323. }
  324. } else if ([RQ_VIP_Module.chooseTypeModel.dictLabel containsString:@"理论实操计时"]) {
  325. [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {
  326. @strongify(self)
  327. if (isSuccess) {
  328. if (activationModel.isShare && activationModel.isActive == 1) {
  329. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已购买成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  330. @strongify(self)
  331. if (self.payViewController) {
  332. [self.payViewController dismissViewControllerAnimated:YES completion:nil];
  333. }
  334. }];
  335. } else {
  336. [self checkVipFail];
  337. }
  338. } else {
  339. [self checkVipFail];
  340. }
  341. }];
  342. } else {
  343. if ([historyVideoVipModel.subject1 isEqualToString:RQ_VIP_Module.videoVipModel.subject1] && [historyVideoVipModel.subject2 isEqualToString:RQ_VIP_Module.videoVipModel.subject2] &&
  344. [historyVideoVipModel.subject3 isEqualToString:RQ_VIP_Module.videoVipModel.subject3] && [historyVideoVipModel.subject4 isEqualToString:RQ_VIP_Module.videoVipModel.subject4]) {
  345. /// 续费未查询到结果
  346. [self checkVipFail];
  347. } else {
  348. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已购买成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  349. @strongify(self)
  350. if (self.payViewController) {
  351. [self.payViewController dismissViewControllerAnimated:YES completion:nil];
  352. }
  353. }];
  354. }
  355. }
  356. }];
  357. }];
  358. }
  359. - (void)checkVipFail {
  360. @weakify(self)
  361. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"更新VIP信息失败" confirmTitle:@"继续更新" cancelTitle:@"取消" confirmAction:^{
  362. @strongify(self)
  363. [self ailyPayOrWechatSuccessAction];
  364. } cancelAction:nil];
  365. }
  366. // 支付失败
  367. - (void)ailyPayOrWechatFailAction {
  368. NSLog(@"处理支付失败结果");
  369. }
  370. #pragma mark - OverrideMethods
  371. /// 配置collectionView的区域
  372. - (UIEdgeInsets)contentInset {
  373. return UIEdgeInsetsMake((self.viewModel.vipPageType == RQVIPPageType_Alert)? 0 : (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT), 0, 0, 0);
  374. }
  375. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  376. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  377. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  378. return [NSClassFromString(itemViewModel.itemClassName) cellWithCollectionView:collectionView forIndexPath:indexPath];
  379. }
  380. - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  381. [cell bindViewModel:object];
  382. }
  383. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  384. switch (section) {
  385. case 0: {
  386. return UIEdgeInsetsMake(0, 16, 0, 16);
  387. }
  388. case 1: {
  389. return UIEdgeInsetsMake(0, 16, 0, 16);
  390. }
  391. case 2: {
  392. return UIEdgeInsetsMake(0, 16, 0, 16);
  393. }
  394. case 3: {
  395. return UIEdgeInsetsMake(0, 16, 0, 16);
  396. }
  397. case 4: {
  398. return UIEdgeInsetsMake(0, 16, 0, 16);
  399. }
  400. case 5: {
  401. return UIEdgeInsetsMake(0, 16, 0, 16);
  402. }
  403. case 6: {
  404. return UIEdgeInsetsMake(0, 16, 0, 16);
  405. }
  406. default: {
  407. return UIEdgeInsetsZero;
  408. }
  409. }
  410. }
  411. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  412. switch (section) {
  413. case 0:
  414. case 1:
  415. return 16;
  416. default:
  417. return 8;
  418. }
  419. }
  420. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  421. switch (section) {
  422. case 1:
  423. return 0;
  424. default:
  425. return 8;
  426. }
  427. }
  428. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  429. @weakify(self)
  430. // 如果是头视图
  431. if (kind == UICollectionElementKindSectionHeader) {
  432. if (indexPath.section == 0) {
  433. if (self.viewModel.vipPageType == RQVIPPageType_Alert) {
  434. RQVipAlertHeaderCollectionReusableView *headerView = [RQVipAlertHeaderCollectionReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  435. [headerView.closeBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  436. @strongify(self)
  437. [self dismissViewControllerAnimated:YES completion:nil];
  438. }];
  439. return headerView;
  440. } else {
  441. RQVipHeaderImageViewNewReusableView *vipHeaderImageViewReusableView = [RQVipHeaderImageViewNewReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  442. RQVipHeaderImageViewNewGroupViewModel *vipHeaderImageViewGroupViewModel = self.viewModel.dataSource[indexPath.section];
  443. [vipHeaderImageViewReusableView bindViewModel:vipHeaderImageViewGroupViewModel];
  444. return vipHeaderImageViewReusableView;
  445. }
  446. } else {
  447. RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  448. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  449. [headerView bindViewModel:groupViewModel];
  450. headerView.headerContentLabel.hidden = YES;
  451. headerView.footerContentLabel.hidden = YES;
  452. if (indexPath.section == 1 && self.viewModel.vipPageType == RQVIPPageType_Alert) {
  453. headerView.backgroundColor = UIColor.clearColor;
  454. }
  455. headerView.backgroundColor = UIColor.clearColor;
  456. return headerView;
  457. }
  458. } else {
  459. RQCommonReusableView *footerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  460. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  461. [footerView bindViewModel:groupViewModel];
  462. footerView.headerContentLabel.hidden = YES;
  463. footerView.footerContentLabel.hidden = YES;
  464. footerView.backgroundColor = UIColor.clearColor;
  465. return footerView;
  466. }
  467. }
  468. - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  469. switch (indexPath.section) {
  470. case 0:
  471. case 1:{
  472. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  473. if ([groupViewModel.itemViewModels[indexPath.row] isKindOfClass:[RQVipTrainPriceItemViewModel class]]) {
  474. return (!RQObjectIsNil(RQ_VIP_Module.activationModel) && RQ_VIP_Module.activationModel.isShare && !(RQ_VIP_Module.activationModel.isActive == 1));
  475. } else {
  476. return YES;
  477. }
  478. }
  479. default:
  480. return NO;
  481. }
  482. }
  483. #pragma mark - HWPanModalPresentable
  484. - (UIScrollView *)panScrollable {
  485. return self.collectionView;
  486. }
  487. - (PanModalHeight)longFormHeight {
  488. return PanModalHeightMake(PanModalHeightTypeContent, RQ_SCREEN_HEIGHT * (459.f / 812.f));
  489. }
  490. - (CGFloat)cornerRadius {
  491. return 0.0;
  492. }
  493. - (BOOL)allowsTapBackgroundToDismiss {
  494. return NO;
  495. }
  496. - (BOOL)showDragIndicator {
  497. return NO;
  498. }
  499. #pragma mark - LazyLoad
  500. - (RQVipBuyView *)vipBuyView {
  501. if (!_vipBuyView) {
  502. _vipBuyView = [RQVipBuyView vipBuyView];
  503. RAC(_vipBuyView, typeModel) = [[RACObserve(RQ_VIP_Module, chooseTypeModel) distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
  504. }
  505. return _vipBuyView;
  506. }
  507. - (RQVipBuyNewView *)vipBuyNewView {
  508. if (!_vipBuyNewView) {
  509. _vipBuyNewView = [RQVipBuyNewView vipBuyNewView];
  510. RAC(_vipBuyNewView, typeModel) = [[RACObserve(RQ_VIP_Module, chooseTypeModel) distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
  511. }
  512. return _vipBuyNewView;
  513. }
  514. @end