//
|
// 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];
|
for (int i = 0; i < self.dynamicViewModels.count; i++) {
|
DynamicModel * dynamicViewModel = [self.dynamicViewModels objectAtIndex:i];
|
if([StringUtil isPureFloat:dynamicViewModel.value] && ![StringUtil isPureInt:dynamicViewModel.value])
|
{
|
dynamicViewModel.value = [NSString stringWithFormat:@"%.2f",[dynamicViewModel.value floatValue]];
|
}
|
}
|
}
|
else if(getCount == 1)
|
{
|
NSMutableArray<DynamicModel *> *dynamicTempViewModels = [DynamicModel mj_objectArrayWithKeyValuesArray:resModel.content];
|
if(self.dynamicViewModels.count > 0)
|
{
|
// for (int i = 0; i < self.dynamicViewModels.count-1; i++)
|
// {
|
// if(self.dynamicViewModels.count-1 < i + 1) continue;
|
// [self.dynamicViewModels exchangeObjectAtIndex:i withObjectAtIndex:i+1];
|
// }
|
[self.dynamicViewModels removeObjectAtIndex:0];
|
if(dynamicTempViewModels.count==1)
|
{
|
DynamicModel * dynamicViewModel = [dynamicTempViewModels objectAtIndex:0];
|
if(!TWIsEmpty(dynamicViewModel))
|
{
|
if([StringUtil isPureFloat:dynamicViewModel.value]&& ![StringUtil isPureInt:dynamicViewModel.value])
|
{
|
dynamicViewModel.value = [NSString stringWithFormat:@"%.2f",[dynamicViewModel.value floatValue]];
|
}
|
|
[self.dynamicViewModels addObject:dynamicViewModel];
|
}
|
//[self.dynamicViewModels replaceObjectAtIndex:(self.dynamicViewModels.count-1) withObject:dynamicViewModel];
|
}
|
|
}
|
}
|
}
|
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;
|
}
|
|
@end
|