ifish/Ifish/controllers/IfishTabControllers/设备/QianDao/WodeTask/ViewControlller/WoDeRenWuViewController.m

257 lines
8.3 KiB
Objective-C

//
// WoDeRenWuViewController.m
// Ifish
//
// Created by imac on 17/3/9.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "WoDeRenWuViewController.h"
#import "TaskHeadViewCell.h"
#import "TaskKindViewCell.h"
#import "IfishTaskViewCell.h"
#import "IfishTaskModel.h"
#import "IfishTaskRuletype.h"
@interface WoDeRenWuViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *everyDayTask;
@property (nonatomic,strong) NSArray *doneTasks;
@property (nonatomic,strong) NSMutableArray *chosenTask;
@property (nonatomic) NSInteger everyDayDoneTaskCount;
@property (nonatomic) NSInteger chosenDoneTaskCount;
@end
@implementation WoDeRenWuViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:@"我的任务"];
_everyDayTask = [[NSMutableArray alloc] init];
_chosenTask = [[NSMutableArray alloc] init];
_doneTasks = [[NSArray alloc] init];
_everyDayDoneTaskCount = 0;
_chosenDoneTaskCount = 0;
[self creatTab];
//走网络 体验不好 换静态页面 app端处理任务完成数据
//[self getData];
[self initData];
}
-(void)initData
{
_doneTasks =[[DataCenter defaultDtacenter] valueForKey:IFISHTASK_ARR];
if ([_doneTasks count]!=0) {
for (IfishTaskModel *mode in _doneTasks) {
if ([mode.addType isEqualToString:@"everyDay"]) {
if (mode.isDone) {
_everyDayDoneTaskCount ++;
}
}else{
if (mode.isDone) {
_chosenDoneTaskCount ++;
}
}
}
}
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"IfishTask" ofType:@"plist"];
NSArray *data = [[NSArray alloc] initWithContentsOfFile:plistPath];
for (NSDictionary *listDic in data[0]) {
IfishTaskRuletype *model=[[IfishTaskRuletype alloc] initWithDict:listDic];
if ([model.addType isEqualToString:@"everyDay"]){
[_everyDayTask addObject:model];
}else{
[_chosenTask addObject:model];
}
}
//数组排序
// NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"taskId" ascending:YES];
// NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];
// [_everyDayTask sortUsingDescriptors:sortDescriptors];
//
//数组排序
// NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"taskId" ascending:YES];
//NSArray *sortDescriptors2 = [[NSArray alloc] initWithObjects:sortDescriptor2,nil];
//_everyDayTask = (NSMutableArray*) [_everyDayTask sortedArrayUsingDescriptors:sortDescriptors2];
[self.tableView reloadData];
}
-(void)getData{
//请求 获取规则金币信息接口
__weak typeof (self) weakSelf =self;
NSString *userId = [dataContorl dataControlGetUserIdInfo];
[AFHttpTool getgGoldRuleInfo:userId success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
if ([reDic[@"result"] isEqualToString:@"100"]){
NSDictionary *dataDic = reDic[@"data"];
NSArray *goldRules = dataDic[@"goldRules"];
if (![goldRules isKindOfClass:[NSNull class]]&&goldRules) {
for (NSDictionary *dic in goldRules) {
IfishTaskModel *model = [[IfishTaskModel alloc] initWithDict:dic];
if ([model.addType isEqualToString:@"everyDay"]) {
[_everyDayTask addObject:model];
if (model.isDone) {
_everyDayDoneTaskCount ++;
}
}else{
if (model.isDone) {
_chosenDoneTaskCount ++;
}
[_chosenTask addObject:model];
}
}
[weakSelf.tableView reloadData];
}else{
[self.view makeToast:@"暂无任务"];
}
}else{
[self.view makeToast:@"请求失败"];
}
} failure:^(NSError *err) {
[self.view makeToast:@"请求异常"];
}];
}
-(void)creatTab{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = JWUIColorFromRGB(0xf2f2f2);
[self.view addSubview:self.tableView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 2) {
//return [_everyDayTask count];
return [_everyDayTask count];
}else if (section == 4)
{
return [_chosenTask count];
}
return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
TaskHeadViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TaskHeadViewCell"];
if(cell==nil){
cell = [[[NSBundle mainBundle]loadNibNamed:@"TaskHeadViewCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}else if (indexPath.section==1||indexPath.section ==3){
TaskKindViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TaskKindViewCell"];
if(cell==nil){
cell = [[[NSBundle mainBundle]loadNibNamed:@"TaskKindViewCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setCellDataAt:indexPath];
if (indexPath.section ==1) {
cell.doneTask.text =[NSString stringWithFormat:@"%ld/%ld",(long)_everyDayDoneTaskCount,(unsigned long)[_everyDayTask count]];
}else if (indexPath.section ==3){
cell.doneTask.text =[NSString stringWithFormat:@"%ld/%ld",(long)_chosenDoneTaskCount,(unsigned long)[_chosenTask count]];
}
return cell;
}else{
IfishTaskViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IfishTaskViewCell"];
if(cell==nil){
cell = [[[NSBundle mainBundle]loadNibNamed:@"IfishTaskViewCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.section ==2) {
IfishTaskRuletype * model =_everyDayTask[indexPath.row];
[cell loadEveryDayDataWith:model doneTaskArr:_doneTasks];
}else{;
IfishTaskRuletype * model =_chosenTask[indexPath.row];
[cell loadChioceDataWith:model doneTaskArr:_doneTasks];
}
return cell;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
return 35*KWidth_Scale;
}else if (indexPath.section==1||indexPath.section ==3){
return 44*KWidth_Scale;
}else{
return 60*KWidth_Scale;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.01f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if(section ==1){
return 5.0f;
}
return 0.01f;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end