RQPlaceBuyItemViewModel.m 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // RQPlaceBuyItemViewModel.m
  3. // JiaPei
  4. //
  5. // Created by 张嵘 on 2023/4/19.
  6. //
  7. #import "RQPlaceBuyItemViewModel.h"
  8. #import "NYWPViewModel.h"
  9. @interface RQPlaceBuyItemViewModel ()
  10. @property (nonatomic, readwrite, strong) RQPlaceListModel *placeListModel;
  11. @property (nonatomic, readwrite, assign) BOOL isBuy;
  12. @property (nonatomic, readwrite, assign) BOOL chooseAgree;
  13. @property (nonatomic, strong) NYWPViewModel *wpviewModel;
  14. @end
  15. @implementation RQPlaceBuyItemViewModel
  16. - (instancetype)initWithPlaceListModel:(RQPlaceListModel *)placeListModel {
  17. if (self = [super init]) {
  18. @weakify(self)
  19. self.wpviewModel = nil;
  20. /// 清除缓存
  21. NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
  22. NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
  23. [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
  24. }];
  25. [self.wpviewModel.wView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
  26. NSLog(@"navigator.userAgent.result is ++++ %@", result);
  27. }];
  28. [self.wpviewModel wkvPL:NYPiapphkc];
  29. self.placeListModel = placeListModel;
  30. CGFloat width = RQ_SCREEN_WIDTH - 32.f;
  31. self.rowHeight = (width * (56.f / 345.f)) + 16 + 20 + 16;
  32. RAC(self, isBuy) = [[RACObserve(placeListModel, isCheckVip) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal];
  33. [[[[RACObserve(RQ_COMMON_MANAGER, vipListArr) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] skip:1] subscribeNext:^(id _Nullable x) {
  34. BOOL isBuy = [RQ_COMMON_MANAGER.vipListArr containsObject:placeListModel.name];
  35. placeListModel.isCheckVip = isBuy;
  36. }];
  37. self.operation = ^{
  38. @strongify(self)
  39. if (self.isAgree) {
  40. if (self.isBuy) {
  41. } else {
  42. [self.wpviewModel wwvPLJS:placeListModel.id];
  43. }
  44. } else {
  45. [[RACScheduler mainThreadScheduler] schedule:^{
  46. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请阅读用户协议!才能购买考场会员哦!" confirmTitle:@"立即阅读" cancelTitle:@"取消" confirmAction:^{
  47. @strongify(self)
  48. self.chooseAgree = YES;
  49. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://ys.zzxcx.net/jsjp-sf.html"]];
  50. RQWebViewModel *viewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey : request,RQViewModelWebViewTypeKey:@(RQWebViewType_VIP)}];
  51. RQWebViewViewController *viewController = [[RQWebViewViewController alloc] initWithViewModel:viewModel];
  52. RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:viewController];
  53. [RQControllerHelper.currentViewController presentViewController:nav animated:YES completion:nil];
  54. } cancelAction:nil];
  55. }];
  56. }
  57. };
  58. }
  59. return self;
  60. }
  61. - (NSString *)itemClassName {
  62. return @"RQPlaceBuyCell";
  63. }
  64. - (NYWPViewModel *)wpviewModel{
  65. if(!_wpviewModel){
  66. _wpviewModel = [[NYWPViewModel alloc] init];
  67. }
  68. return _wpviewModel;
  69. }
  70. @end