单军华
2018-07-11 a8297afeff989f07a0d54dadfec7b34799a9c5dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
//  DynamicService.m
//  screendisplay
//
//  Created by 单军华 on 2018/7/9.
//  Copyright © 2018年 单军华. All rights reserved.
//
 
#import "DynamicService.h"
#import "PPInterfacedConst.h"
 
@implementation DynamicService
 
/** 获取详情列表*/
- (NSURLSessionTask *)getDynamicListWithParameters:(id)parameters dataCount:(int)getCount completion:(void(^)(NSString *desc,int code))completion{
    // 将请求前缀与请求路径拼接成一个完整的URL
    NSString *url = [NSString stringWithFormat:@"%@%@",kApiPrefix,kHistory];
    
    return [self requestGETWithURL:url parameters:parameters success:^(id responseObject)
            {
                BaseResModel * resModel = [Global toBaseModel:responseObject];
                if(resModel.code == 1)
                {
                    if(!TWIsEmpty(resModel.content))
                    {
                        // 成功处理
                        if (getCount > 1)
                        {
                           self.dynamicViewModels = [DynamicModel mj_objectArrayWithKeyValuesArray:resModel.content];
                        }
                        else if(getCount == 1)
                        {
                            self.dynamicViewModel = [DynamicModel mj_objectWithKeyValues:resModel.content];
                            
                            //[self.dynamicViewModels replaceObjectAtIndex:self.dynamicViewModels.count-1 withObject:model];
                        }
                    }
                    else
                    {
                        // 出错处理
                        resModel.code = -5;
                        completion(@"返回数据错误,数据为空!",resModel.code);
                    }
                }
                
                // 在这里你可以根据项目自定义其他一些重复操作,比如加载页面时候的等待效果, 提醒弹窗....
                completion(resModel.desc,resModel.code);
                
            } failure:^(NSError *error) {
                // 同上
                completion(error.localizedDescription,-1);
            }];
}
 
- (NSMutableArray<DynamicModel *> *)dynamicViewModels
{
    if(_dynamicViewModels == nil)
    {
        _dynamicViewModels = [NSMutableArray array];
    }
    return _dynamicViewModels;
}
 
- (DynamicModel *)dynamicViewModel
{
    if(_dynamicViewModel == nil)
    {
        _dynamicViewModel = [DynamicModel new];
    }
    return _dynamicViewModel;
}
 
@end