123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- //
- // CoursewareViewModel.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/11/15.
- //
- #import "CoursewareViewModel.h"
- #import "CoursewareListModel.h"
- @interface CoursewareViewModel ()
- @property (nonatomic, assign) NSInteger pages; // 页数
- @property (nonatomic, assign) NSInteger rows; // 每页条数
- @property (nonatomic, strong) NSMutableArray *sourceArray;
- @end
- @implementation CoursewareViewModel
- - (void)resetParamenter {
- self.pages = 1;
- self.rows = 10;
- self.isLoadMore = YES;
- self.sourceArray = [NSMutableArray array];
- }
- - (void)refreshAndRequest {
- [self resetParamenter];
- [self requestData];
- }
- - (void)requestData {
- [LOADING_MANAGER showHUD];
- [KSNetworkingManager courseCoursewareRequest:KS_POST status:0 searchKey:self.searchKey page:self.pages rows:self.rows success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeHUD];
- [self endRefresh];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *dataArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
- for (NSDictionary *parm in dataArray) {
- CoursewareListModel *model = [[CoursewareListModel alloc] initWithDictionary:parm];
- [self.sourceArray addObject:model];
- }
- if (dataArray.count < self.rows) {
- self.isLoadMore = NO;
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
-
- if (self.delegate && [self.delegate respondsToSelector:@selector(loadSourceSuccess:)]) {
- NSArray *array = [self.sourceArray copy];
- [self.delegate loadSourceSuccess:array];
- }
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeHUD];
- [self endRefresh];
- }];
-
-
-
-
-
- }
- - (void)endRefresh {
- if (self.delegate && [self.delegate respondsToSelector:@selector(endRefresh)]) {
- [self.delegate endRefresh];
- }
- }
- - (void)loadNextPage {
- if (self.isLoadMore) {
- self.pages++;
- [self requestData];
- }
- }
- - (void)removeCoursewareAction {
- NSMutableArray *arrayList = [NSMutableArray array];
-
- for (CoursewareListModel *model in self.sourceArray) {
- if (model.isChoose) {
- [arrayList addObject:[NSString stringWithFormat:@"%@",model.internalBaseClassIdentifier]];
- }
- }
- if (arrayList.count == 0) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请选择课件"];
- return;
- }
- NSString *ids = [arrayList componentsJoinedByString:@","];
- [LOADING_MANAGER showHUD];
- [KSNetworkingManager courseCoursewareRemoveRequest:KS_POST ids:ids success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeHUD];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- [LOADING_MANAGER KSShowMsg:@"删除成功" promptCompletion:^{
- [self refreshAndRequest];
- }];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
-
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeHUD];
- }];
- }
- - (void)resetAllChooseStatus {
- for (CoursewareListModel *model in self.sourceArray) {
- model.isChoose = NO;
- }
- if (self.delegate && [self.delegate respondsToSelector:@selector(loadSourceSuccess:)]) {
- NSArray *array = [self.sourceArray copy];
- [self.delegate loadSourceSuccess:array];
- }
- }
- - (void)chooseAllMusic {
- for (CoursewareListModel *model in self.sourceArray) {
- model.isChoose = YES;
- }
- if (self.delegate && [self.delegate respondsToSelector:@selector(loadSourceSuccess:)]) {
- NSArray *array = [self.sourceArray copy];
- [self.delegate loadSourceSuccess:array];
- }
- }
- - (void)setSearchKey:(NSString *)searchKey {
- _searchKey = searchKey;
- }
- - (NSMutableArray *)sourceArray {
- if (!_sourceArray) {
- _sourceArray = [NSMutableArray array];
- }
- return _sourceArray;
- }
- @end
|