// // RQPlaceBuyItemViewModel.m // JiaPei // // Created by 张嵘 on 2023/4/19. // #import "RQPlaceBuyItemViewModel.h" #import "NYWPViewModel.h" @interface RQPlaceBuyItemViewModel () @property (nonatomic, readwrite, strong) RQPlaceListModel *placeListModel; @property (nonatomic, readwrite, assign) BOOL isBuy; @property (nonatomic, readwrite, assign) BOOL chooseAgree; @property (nonatomic, strong) NYWPViewModel *wpviewModel; @end @implementation RQPlaceBuyItemViewModel - (instancetype)initWithPlaceListModel:(RQPlaceListModel *)placeListModel { if (self = [super init]) { @weakify(self) self.wpviewModel = nil; /// 清除缓存 NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes]; NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0]; [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{ }]; [self.wpviewModel.wView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) { NSLog(@"navigator.userAgent.result is ++++ %@", result); }]; if(!isOfficial){ [self.wpviewModel wkvPL:NYPiapphkc_test]; }else{ [self.wpviewModel wkvPL:NYPiapphkc]; } self.placeListModel = placeListModel; CGFloat width = RQ_SCREEN_WIDTH - 32.f; self.rowHeight = (width * (56.f / 345.f)) + 16 + 20 + 16; RAC(self, isBuy) = [[RACObserve(placeListModel, isCheckVip) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal]; [[[[RACObserve(RQ_COMMON_MANAGER, vipListArr) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] skip:1] subscribeNext:^(id _Nullable x) { BOOL isBuy = [RQ_COMMON_MANAGER.vipListArr containsObject:placeListModel.name]; placeListModel.isCheckVip = isBuy; }]; self.operation = ^{ @strongify(self) if (self.isAgree) { if (self.isBuy) { } else { [self.wpviewModel wwvPLJS:placeListModel.id goodType:1]; } } else { [[RACScheduler mainThreadScheduler] schedule:^{ [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请阅读用户协议!才能购买考场会员哦!" confirmTitle:@"立即阅读" cancelTitle:@"取消" confirmAction:^{ @strongify(self) self.chooseAgree = YES; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://ys.zzxcx.net/jsjp-sf.html"]]; RQWebViewModel *viewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey : request,RQViewModelWebViewTypeKey:@(RQWebViewType_VIP)}]; RQWebViewViewController *viewController = [[RQWebViewViewController alloc] initWithViewModel:viewModel]; RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:viewController]; [RQControllerHelper.currentViewController presentViewController:nav animated:YES completion:nil]; } cancelAction:nil]; }]; } }; } return self; } - (NSString *)itemClassName { return @"RQPlaceBuyCell"; } - (NYWPViewModel *)wpviewModel{ if(!_wpviewModel){ _wpviewModel = [[NYWPViewModel alloc] init]; } return _wpviewModel; } @end