123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //
- // RQChapterAndPointListViewModel.m
- // jiaPei
- //
- // Created by 张嵘 on 2022/7/26.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import "RQChapterAndPointListViewModel.h"
- @interface RQChapterAndPointListViewModel ()
- /// 数组
- @property (nonatomic, readwrite, copy) NSArray *items;
- @end
- @implementation RQChapterAndPointListViewModel
- #pragma mark - Public Method
- - (instancetype)initWithServices:(id<RQViewModelServices>)services params:(NSDictionary *)params {
- if (self = [super initWithServices:services params:params]) {
- self.title = params[RQViewModelTitleKey];
- }
- return self;
- }
- - (void)initialize {
- [super initialize];
- ///配置数据
- if ([self.title isEqualToString:@"章节练习"]) {
- [self rq_configureData_Chapter];
- } else {
- [self rq_configureData_Point];
- }
-
- }
- #pragma mark - PrivateMethod
- - (void)rq_configureData_Chapter {
- @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];
- }];
- }
- - (void)rq_configureData_Point {
- /// 数据源
- RAC(self, dataSource) = [RACObserve(self, items) map:^(NSArray * items) {
- return [items.rac_sequence.signal map:^id _Nullable(RQYDTPointModel *pointModel) {
- RQCommonGroupViewModel *group = [RQCommonGroupViewModel groupViewModel];
- RQCommonItemViewModel *commonItemViewModel = [RQCommonItemViewModel itemViewModelWithTitle:pointModel.name];
- NSArray *pointArr = [RQ_YDTQuestion_Module getPointQuestionWithPointID:pointModel.id];
- commonItemViewModel.subtitle = [NSString qmui_stringWithNSInteger:pointArr.count];
- commonItemViewModel.rowHeight = RQ_FIT_HORIZONTAL(54.f);
- commonItemViewModel.operation = ^{
- NSArray *arr = [pointArr.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_SequentialPractice),
- RQViewModelIDKey : pointModel.name,
- RQExerciseTypeKey : @(RQExerciseType_Point),
- RQViewModelUtilKey : arr,
- }];
- RQ_Exercise_Module.otherStr = pointModel.name;
- [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
- };
- group.itemViewModels = @[commonItemViewModel];
- return group;
- }].toArray;
- }];
- self.items = [RQ_YDTQuestion_Module getPoint];
- }
- /// 请求数据
- - (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];
- }];
- }
- #pragma mark - 辅助方法
- - (NSArray *)dataSourceWithItems:(NSArray *)items {
- NSArray *viewModels = [items.rac_sequence map:^(RQDictInfoModel *dictInfoModel) {
- RQCommonGroupViewModel *group = [RQCommonGroupViewModel groupViewModel];
- RQCommonItemViewModel *commonItemViewModel = [RQCommonItemViewModel itemViewModelWithTitle:dictInfoModel.dictValue];
- commonItemViewModel.subtitle = dictInfoModel.remark;
- commonItemViewModel.rowHeight = RQ_FIT_HORIZONTAL(54.f);
- NSArray *chapterArr = [RQ_YDTQuestion_Module getChapterQuestionWithChapterName:dictInfoModel.dictValue];
- commonItemViewModel.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_SequentialPractice),
- RQViewModelIDKey : dictInfoModel.dictValue,
- RQExerciseTypeKey : @(RQExerciseType_Chapter),
- RQViewModelUtilKey : arr,
- }];
- RQ_Exercise_Module.otherStr = dictInfoModel.dictValue;
- [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
- };
- group.itemViewModels = @[commonItemViewModel];
- return group;
- }].array;
-
- return viewModels ?: @[];
- }
- @end
|