DailyQuestTablView.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // DailyQuestTablView.m
  3. // PopupViewWindow
  4. //
  5. // Created by 杨仁伟 on 2017/5/22.
  6. // Copyright © 2017年 yrw. All rights reserved.
  7. #import "DailyQuestTablView.h"
  8. #import "DailyQuestCell.h"
  9. #import "BMListModel.h"
  10. @interface DailyQuestTablView () <UITableViewDelegate, UITableViewDataSource>
  11. @property (nonatomic, strong) NSMutableArray *imgArray; //放图片
  12. @property (nonatomic, strong) NSMutableArray *taskArray; //放任务
  13. @property (nonatomic, strong) NetHttpsManager *httpsManager;
  14. @end
  15. @implementation DailyQuestTablView
  16. - (instancetype)initWithFrame:(CGRect)frame
  17. {
  18. if (self = [super initWithFrame:frame]) {
  19. self = [[DailyQuestTablView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
  20. self.delegate = self;
  21. self.dataSource = self;
  22. self.backgroundColor = kWhiteColor;
  23. self.separatorColor = [UIColor clearColor];
  24. [self headRefresh];
  25. [self loadNetDailyData];
  26. }
  27. return self;
  28. }
  29. - (void)headRefresh
  30. {
  31. [BGMJRefreshManager refresh:self target:self headerRereshAction:@selector(loadNetDailyData) footerRereshAction:nil];
  32. }
  33. - (void)loadNetDailyData
  34. {
  35. self.httpsManager = [NetHttpsManager manager];
  36. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  37. [parmDict setObject:@"mission" forKey:@"ctl"];
  38. [parmDict setObject:@"getMissionList" forKey:@"act"];
  39. FWWeakify(self)
  40. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  41. {
  42. FWStrongify(self)
  43. if ([responseJson toInt:@"status"] == 1)
  44. {
  45. [self.imgArray removeAllObjects];
  46. NSArray *listArr = [responseJson objectForKey:@"list"];
  47. if (listArr && [listArr isKindOfClass:[NSArray class]])
  48. {
  49. if (listArr.count)
  50. {
  51. for (NSDictionary *listDict in listArr)
  52. {
  53. BMListModel *lModel = [BMListModel mj_objectWithKeyValues:listDict];
  54. [self.imgArray addObject:lModel];
  55. }
  56. }
  57. }
  58. [self reloadData];
  59. }
  60. [BGMJRefreshManager endRefresh:self];
  61. } FailureBlock:^(NSError *error)
  62. {
  63. FWStrongify(self)
  64. [BGMJRefreshManager endRefresh:self];
  65. }];
  66. }
  67. - (NSMutableArray *)imgArray
  68. {
  69. if (!_imgArray)
  70. {
  71. _imgArray = [[NSMutableArray alloc]init];
  72. }
  73. return _imgArray;
  74. }
  75. - (NSMutableArray *)taskArray
  76. {
  77. if (!_taskArray)
  78. {
  79. _taskArray = [[NSMutableArray alloc]init];
  80. }
  81. return _taskArray;
  82. }
  83. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  84. {
  85. return self.imgArray.count;
  86. }
  87. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  88. {
  89. static NSString *flag = @"DailyQuest";
  90. DailyQuestCell *cell = [tableView dequeueReusableCellWithIdentifier:flag];
  91. if (!cell)
  92. {
  93. cell = [[NSBundle mainBundle] loadNibNamed:@"DailyQuestCell" owner:nil options:nil].firstObject;
  94. }
  95. if (self.imgArray.count)
  96. {
  97. BMListModel *lModel = _imgArray[indexPath.row];
  98. [cell creatCellWithModel:lModel andRow:(int)indexPath.row];
  99. [cell setTaskBlock:^(int btnCount){
  100. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  101. [parmDict setObject:@"mission" forKey:@"ctl"];
  102. [parmDict setObject:@"commitMission" forKey:@"act"];
  103. BMListModel *model = _imgArray[btnCount];
  104. [parmDict setObject:model.type forKey:@"type"];
  105. [_httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  106. {
  107. if ([responseJson toInt:@"status"] == 1)
  108. {
  109. // if ([responseJson toInt:@"open_daily_task"] == 0)
  110. // {
  111. // [[NSNotificationCenter defaultCenter]postNotificationName:@"closeEverydayTask" object:nil];
  112. // }
  113. NSDictionary *missionDict = [responseJson objectForKey:@"mission"];
  114. if (missionDict && [missionDict isKindOfClass:[NSDictionary class]])
  115. {
  116. if (missionDict.count)
  117. {
  118. BMListModel *newModel = [BMListModel mj_objectWithKeyValues:missionDict];
  119. [self.imgArray replaceObjectAtIndex:btnCount withObject:newModel];
  120. }
  121. }
  122. [self reloadData];
  123. }else
  124. {
  125. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  126. }
  127. } FailureBlock:^(NSError *error)
  128. {
  129. }];
  130. }];
  131. }
  132. return cell;
  133. }
  134. //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  135. //{
  136. // UILabel *headLbl = [UILabel quickLabelWithFrame:CGRectMake(0, 0, self.frame.size.width, 47*kScaleHeight) color:kWhiteColor font:18 text:ASLocalizedString(@"每日任务")superView:nil];
  137. // headLbl.textAlignment = NSTextAlignmentCenter;
  138. // headLbl.backgroundColor = kClearColor;
  139. // return headLbl;
  140. //}
  141. //
  142. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  143. {
  144. return kRealValue(10);
  145. // 47*kAppRowHScale;
  146. }
  147. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  148. {
  149. return kRealValue(64);
  150. }
  151. @end