// // NYFailSpecialExerciseDetailsViewModel.m // jiaPei // // Created by Ning.ge on 2024/12/12. // Copyright © 2024 JCZ. All rights reserved. // #import "NYFailSpecialExerciseDetailsViewModel.h" #import "RQVideoModule.h" @interface NYFailSpecialExerciseDetailsViewModel () @property (nonatomic, readwrite, assign) RQHomePageSubjectType homePageSubjectType; @property (nonatomic, readwrite, strong) NSDictionary *dataDicts; @property (nonatomic, readwrite, strong) NSDictionary *titleDict; @property (nonatomic, readwrite, strong) NSMutableDictionary *datakeyDicts; @end @implementation NYFailSpecialExerciseDetailsViewModel #pragma mark - Public Method - (instancetype)initWithServices:(id)services params:(NSDictionary *)params { if (self = [super initWithServices:services params:params]) { self.homePageSubjectType = [params[RQHomePageSubjectTypeKey] integerValue]; self.title = params[RQHomePageSpTitleKey]; } return self; } - (void)initialize { [super initialize]; [self loadPointData]; [self loadKeyDicts]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self rq_configureData]; }); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self postVideoDate]; }); } - (void)postVideoDate { NYFailSpecialVideoGroupViewModel *model = [self.dataSource firstObject]; if(model.videoDate.vipPublicityMediumUrl.length>0){ VideosItem *videosItem = [[VideosItem alloc ] init]; videosItem.video_url = model.videoDate.vipPublicityMediumUrl; videosItem.coverFileUrl = model.videoDate.poster; videosItem.title = model.videoDate.endButtonText; videosItem.videoDescribe = model.videoDate.endButtonText; videosItem.videoType = RQVideoType_Default; videosItem.permission = 1; videosItem.subject = 0;//科目一 [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{ RQPlayVideoItemKey : videosItem, RQPlayVideoItemArrKey : @[videosItem], }]; } } #pragma mark - ConfigureData - (void)rq_configureData { /// 数据源 RAC(self, dataSource) = [RACSignal combineLatest:@[RACObserve(RQ_USER_MANAGER, isCykh)] reduce:^(NSNumber *isCykh) { NYFailSpecialVideoGroupViewModel *group0 = [NYFailSpecialVideoGroupViewModel groupViewModel]; NSString *keyStr = self.titleDict[self.title]; NYFailGroupPointDataModel *model = self.datakeyDicts[keyStr]; group0.videoDate = model.videoDate; if(model.videoDate.vipPublicityMediumUrl.length>0){ group0.headerHeight = RQ_FIT_HORIZONTAL(218); }else{ group0.headerHeight = 0; } //[NYFailGroupPointDataModel modelWithDictionary:self.dataDicts[keyStr]]; NSMutableArray *mt_array = @[].mutableCopy;//解析json 数据daocell if(model){ int indx = 1; for (NYFailItemPointDataModel *item in model.pointData) { NYFailSpecialExerciseDetailItemModel *itemModel = [[NYFailSpecialExerciseDetailItemModel alloc] initWithTitle:keyStr dataModel:item]; itemModel.itemPointTitle = [NSString stringWithFormat:@"考点%d",indx]; [mt_array addObject:itemModel]; indx++; } } group0.itemViewModels = mt_array; return @[group0]; }]; } - (void)loadKeyDicts { // @weakify(self) if(self.datakeyDicts.count>0)return; self.datakeyDicts = [NSMutableDictionary dictionary]; for (NSString *key in self.titleDict.allKeys) { NSString *key_value = self.titleDict[key]; NYFailGroupPointDataModel *model = [NYFailGroupPointDataModel modelWithDictionary:self.dataDicts[key_value]]; for (NYFailItemPointDataModel *item in model.pointData) { if(item.showType.intValue == 1) continue; if(item.con.count>0){//手势 __block CGFloat itop_yOffset = 0; // 初始偏移量 __block CGFloat yOffset = 0; // 初始偏移量 __block CGFloat cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整) CGFloat imgW = (RQ_SCREEN_WIDTH-22*2); for (int i= 0; i0){ __block CGSize imageSize = CGSizeMake(imgW,cellHeight); dispatch_async(dispatch_get_global_queue(0, 0), ^{ // 处理耗时操作的代码块... imageSize = [UIImage getImageSizeWithURL:img_url]; //通知主线程刷新 dispatch_async(dispatch_get_main_queue(), ^{ //回调或者说是通知主线程刷新, if (imageSize.width == 0 || imageSize.height == 0) { cellHeight = imgW * (175.f / 345.f); } else { cellHeight = imgW * (imageSize.height / imageSize.width); } yOffset += cellHeight; item.imgsH = yOffset; }); }); item.imgsH = yOffset; } } if(con.questions.count>0){ CGFloat cellH = 0.f; for(int z = 0; z0){ cellH +=35.f; } if(img_url.length>0){ __block CGSize imageSize = CGSizeMake(imgW,cellHeight); dispatch_async(dispatch_get_global_queue(0, 0), ^{ // 处理耗时操作的代码块... imageSize = [UIImage getImageSizeWithURL:img_url]; //通知主线程刷新 dispatch_async(dispatch_get_main_queue(), ^{ //回调或者说是通知主线程刷新, if (imageSize.width == 0 || imageSize.height == 0) { cellHeight = imgW * (175.f / 345.f); } else { cellHeight = imgW * (imageSize.height / imageSize.width); } yOffset += cellHeight+12.f; item.imgsH = yOffset+60.f; }); }); item.imgsH = yOffset; } } // item.iviewH = cellH + 45.f; } } } if(item.tagquestions.count>0){//拘留 CGFloat cellH = 0.f; for (int i= 0; icellH){ cellH += str_size.height + 12.f; }else{ cellH +=35.f; } if(texts.quesItem.count>0){ cellH += 22.f*texts.quesItem.count; } } } item.iviewH = cellH + 45.f+45.f*item.tagquestions.count; } if(item.iquestions.count>0){//拘留 __block CGFloat yOffset = 0; // 初始偏移量 __block CGFloat cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整) CGFloat imgW = (RQ_SCREEN_WIDTH-22*2); for (int i= 0; i0){//罚款//周期 CGFloat cellH = 0.f; for (int i= 0; icellH){ cellH += str_size.height + 12.f; }else{ cellH +=35.f; } if(texts.quesItem.count>0){ cellH += 22.f*texts.quesItem.count; } } item.iviewH = cellH + 20.f; } if(item.questions.quesTexts.count>0){ CGFloat cellH = 0.f; for (int i= 0; icellH){ cellH += str_size.height + 12.f; }else{ cellH +=35.f; } if(texts.quesItem.count>0){ cellH += 22.f*texts.quesItem.count; } } item.iviewH = cellH + 20.f; } if(item.questions.images.count > 0){ __block CGFloat yOffset = 0; // 初始偏移量 __block CGFloat cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整) CGFloat imgW = (RQ_SCREEN_WIDTH-22*2); for (int i= 0; i