RQPlaceBuyItemViewModel.m 2.7 KB

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