| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- //
- // DailyQuestTablView.m
- // PopupViewWindow
- //
- // Created by 杨仁伟 on 2017/5/22.
- // Copyright © 2017年 yrw. All rights reserved.
- #import "DailyQuestTablView.h"
- #import "DailyQuestCell.h"
- #import "BMListModel.h"
- @interface DailyQuestTablView () <UITableViewDelegate, UITableViewDataSource>
- @property (nonatomic, strong) NSMutableArray *imgArray; //放图片
- @property (nonatomic, strong) NSMutableArray *taskArray; //放任务
- @property (nonatomic, strong) NetHttpsManager *httpsManager;
- @end
- @implementation DailyQuestTablView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- if (self = [super initWithFrame:frame]) {
-
- self = [[DailyQuestTablView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
- self.delegate = self;
- self.dataSource = self;
- self.backgroundColor = kWhiteColor;
- self.separatorColor = [UIColor clearColor];
- [self headRefresh];
- [self loadNetDailyData];
- }
- return self;
- }
- - (void)headRefresh
- {
- [BGMJRefreshManager refresh:self target:self headerRereshAction:@selector(loadNetDailyData) footerRereshAction:nil];
- }
- - (void)loadNetDailyData
- {
- self.httpsManager = [NetHttpsManager manager];
- NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
- [parmDict setObject:@"mission" forKey:@"ctl"];
- [parmDict setObject:@"getMissionList" forKey:@"act"];
- FWWeakify(self)
- [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
- {
- FWStrongify(self)
- if ([responseJson toInt:@"status"] == 1)
- {
- [self.imgArray removeAllObjects];
- NSArray *listArr = [responseJson objectForKey:@"list"];
- if (listArr && [listArr isKindOfClass:[NSArray class]])
- {
- if (listArr.count)
- {
- for (NSDictionary *listDict in listArr)
- {
- BMListModel *lModel = [BMListModel mj_objectWithKeyValues:listDict];
- [self.imgArray addObject:lModel];
- }
- }
- }
- [self reloadData];
- }
- [BGMJRefreshManager endRefresh:self];
- } FailureBlock:^(NSError *error)
- {
- FWStrongify(self)
- [BGMJRefreshManager endRefresh:self];
- }];
- }
- - (NSMutableArray *)imgArray
- {
- if (!_imgArray)
- {
- _imgArray = [[NSMutableArray alloc]init];
- }
- return _imgArray;
- }
- - (NSMutableArray *)taskArray
- {
- if (!_taskArray)
- {
- _taskArray = [[NSMutableArray alloc]init];
- }
- return _taskArray;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.imgArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *flag = @"DailyQuest";
- DailyQuestCell *cell = [tableView dequeueReusableCellWithIdentifier:flag];
-
- if (!cell)
- {
- cell = [[NSBundle mainBundle] loadNibNamed:@"DailyQuestCell" owner:nil options:nil].firstObject;
- }
- if (self.imgArray.count)
- {
- BMListModel *lModel = _imgArray[indexPath.row];
- [cell creatCellWithModel:lModel andRow:(int)indexPath.row];
- [cell setTaskBlock:^(int btnCount){
- NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
- [parmDict setObject:@"mission" forKey:@"ctl"];
- [parmDict setObject:@"commitMission" forKey:@"act"];
- BMListModel *model = _imgArray[btnCount];
- [parmDict setObject:model.type forKey:@"type"];
- [_httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
- {
- if ([responseJson toInt:@"status"] == 1)
- {
- // if ([responseJson toInt:@"open_daily_task"] == 0)
- // {
- // [[NSNotificationCenter defaultCenter]postNotificationName:@"closeEverydayTask" object:nil];
- // }
- NSDictionary *missionDict = [responseJson objectForKey:@"mission"];
- if (missionDict && [missionDict isKindOfClass:[NSDictionary class]])
- {
- if (missionDict.count)
- {
- BMListModel *newModel = [BMListModel mj_objectWithKeyValues:missionDict];
- [self.imgArray replaceObjectAtIndex:btnCount withObject:newModel];
- }
- }
- [self reloadData];
- }else
- {
- [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
- }
- } FailureBlock:^(NSError *error)
- {
-
- }];
- }];
- }
- return cell;
- }
- //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- //{
- // UILabel *headLbl = [UILabel quickLabelWithFrame:CGRectMake(0, 0, self.frame.size.width, 47*kScaleHeight) color:kWhiteColor font:18 text:ASLocalizedString(@"每日任务")superView:nil];
- // headLbl.textAlignment = NSTextAlignmentCenter;
- // headLbl.backgroundColor = kClearColor;
- // return headLbl;
- //}
- //
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return kRealValue(10);
- // 47*kAppRowHScale;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return kRealValue(64);
- }
- @end
|