RQPlaceBuyItemViewModel.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. if(!isOfficial){
  29. [self.wpviewModel wkvPL:NYPiapphkc_test];
  30. }else{
  31. [self.wpviewModel wkvPL:NYPiapphkc];
  32. }
  33. self.placeListModel = placeListModel;
  34. CGFloat width = RQ_SCREEN_WIDTH - 32.f;
  35. self.rowHeight = (width * (56.f / 345.f)) + 16 + 20 + 16;
  36. RAC(self, isBuy) = [[RACObserve(placeListModel, isCheckVip) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal];
  37. [[[[RACObserve(RQ_COMMON_MANAGER, vipListArr) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] skip:1] subscribeNext:^(id _Nullable x) {
  38. BOOL isBuy = [RQ_COMMON_MANAGER.vipListArr containsObject:placeListModel.name];
  39. placeListModel.isCheckVip = isBuy;
  40. }];
  41. self.operation = ^{
  42. @strongify(self)
  43. if (self.isAgree) {
  44. if (self.isBuy) {
  45. } else {
  46. [self.wpviewModel wwvPLJS:placeListModel.id goodType:1];
  47. }
  48. } else {
  49. [[RACScheduler mainThreadScheduler] schedule:^{
  50. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请阅读用户协议!才能购买考场会员哦!" confirmTitle:@"立即阅读" cancelTitle:@"取消" confirmAction:^{
  51. @strongify(self)
  52. self.chooseAgree = YES;
  53. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://ys.zzxcx.net/jsjp-sf.html"]];
  54. RQWebViewModel *viewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey : request,RQViewModelWebViewTypeKey:@(RQWebViewType_VIP)}];
  55. RQWebViewViewController *viewController = [[RQWebViewViewController alloc] initWithViewModel:viewModel];
  56. RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:viewController];
  57. [RQControllerHelper.currentViewController presentViewController:nav animated:YES completion:nil];
  58. } cancelAction:nil];
  59. }];
  60. }
  61. };
  62. }
  63. return self;
  64. }
  65. - (NSString *)itemClassName {
  66. return @"RQPlaceBuyCell";
  67. }
  68. - (NYWPViewModel *)wpviewModel{
  69. if(!_wpviewModel){
  70. _wpviewModel = [[NYWPViewModel alloc] init];
  71. }
  72. return _wpviewModel;
  73. }
  74. @end