RQVipViewController.m 29 KB

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