123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- //
- // RQErrorViewModel.m
- // jiaPei
- //
- // Created by 张嵘 on 2022/8/3.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import "RQErrorViewModel.h"
- @interface RQErrorViewModel ()
- /// 数组
- @property (nonatomic, readwrite, copy) NSArray *items;
- @end
- @implementation RQErrorViewModel
- #pragma mark - Public Method
- - (instancetype)initWithServices:(id<RQViewModelServices>)services params:(NSDictionary *)params {
- if (self = [super initWithServices:services params:params]) {
-
- }
- return self;
- }
- - (void)initialize {
- [super initialize];
- @weakify(self);
- self.title = @"";
- self.prefersNavigationBarBottomLineHidden = YES;
- ///配置数据
- [self rq_configureData];
-
- [[[RQNotificationCenter rac_addObserverForName:RQCancelWrongNotification object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * _Nullable x) {
- @strongify(self);
- [self.requestRemoteDataCommand execute:nil];
- }];
- }
- #pragma mark - PrivateMethod
- - (void)rq_configureData {
- @weakify(self);
- /// 列表
- RAC(self, items) = self.requestRemoteDataCommand.executionSignals.switchToLatest;
- /// 数据源
- RAC(self, dataSource) = [RACObserve(self, items) map:^(NSArray * items) {
- @strongify(self)
- return RQObjectIsNil(items)? @[] : [self dataSourceWithItems:items];
- }];
- }
- /// 请求数据
- - (RACSignal *)requestRemoteDataSignalWithPage:(NSUInteger)page {
- NSArray * (^itemsBlock)(NSArray *) = ^(NSArray *products) {
- if (page == 1 || page == 0) {
- /// 下拉刷新
- } else {
- /// 上拉加载
- products = @[(self.items ?: @[]).rac_sequence, products.rac_sequence].rac_sequence.flatten.array;
- }
- return products;
- };
- ///
- return [[[RQ_HTTP_Service getChapterList] map:itemsBlock] doError:^(NSError * _Nonnull error) {
- [MBProgressHUD rq_showErrorTips:error];
- }];
- }
- - (NSArray *)dataSourceWithItems:(NSArray *)items {
- __block NSInteger index = 1;
- NSArray *viewModels = [[items.rac_sequence filter:^BOOL(RQDictInfoModel *dictInfoModel) {
- return [RQ_YDTQuestion_Module getChapterQuestionWithChapterName:dictInfoModel.dictValue exerciseType:RQExerciseType_Wrong].count > 0;
- }].array.rac_sequence map:^(RQDictInfoModel *dictInfoModel) {
- RQCommonGroupViewModel *group = [RQCommonGroupViewModel groupViewModel];
- NSArray *chapterArr = [RQ_YDTQuestion_Module getChapterQuestionWithChapterName:dictInfoModel.dictValue exerciseType:RQExerciseType_Wrong];
- RQErrorAndCollectItemViewModel *errorAndCollectItemViewModel = [[RQErrorAndCollectItemViewModel alloc] initWithNumStr:[NSString qmui_stringWithNSInteger:index] titleStr:dictInfoModel.dictValue countStr:[NSString qmui_stringWithNSInteger:chapterArr.count]];
- index ++;
- errorAndCollectItemViewModel.operation = ^{
- NSArray *arr = [chapterArr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
- return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
- }].toArray;
- RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
- RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType),
- RQHomePageSubjectTypeKey : @(RQ_YDTQuestion_Module.subject),
- RQHomeSubPageTypeKey : @(RQHomeSubPageType_WrongTopicAndCollection),
- RQViewModelIDKey : dictInfoModel.dictValue,
- RQExerciseTypeKey : @(RQExerciseType_Wrong),
- RQViewModelUtilKey : arr,
- }];
- [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
- };
- group.itemViewModels = @[errorAndCollectItemViewModel];
- return group;
- }].array;
-
- return viewModels ?: @[];
- }
- @end
|