YOUPAILZProfitListVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. //
  2. // YOUPAILZProfitListVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/7/30.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZProfitListVC.h"
  9. #import "YOUPAILZBillDetailCell.h"
  10. #import "PGDatePickManager.h"
  11. #import "UIViewController+TFPresent.h"
  12. #import "YOUPAILZBillSectionModel.h"
  13. @interface YOUPAILZProfitListVC ()<UITableViewDelegate,UITableViewDataSource,PGDatePickerDelegate>
  14. @property(nonatomic,assign)NSInteger youpaipcurrentPage;
  15. @property(nonatomic,assign)NSInteger youpaiptotalPage;
  16. @property(nonatomic,strong)NSMutableArray* youpaipbillArray;
  17. @property (nonatomic,strong)UITableView *youpaiptableView;
  18. @property(nonatomic,strong)NSString *youpaipdate;
  19. @end
  20. @implementation YOUPAILZProfitListVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.youpaipdate = @"";
  24. self.youpaipbillArray = [NSMutableArray array];
  25. self.title = LCStr(word5);//@"收支明细";
  26. [self youpaifinitUI];
  27. [self.youpaiptableView.mj_header beginRefreshing];
  28. }
  29. - (void)youpaifinitUI{
  30. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaiffilterAction) title:@"筛选" font:LCFont14 titleColor:HexColorFromRGB(0xffffff) highlightedColor:HexColorFromRGB(0xffffff) titleEdgeInsets:UIEdgeInsetsZero];
  31. self.youpaiptableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) style:UITableViewStylePlain];
  32. self.youpaiptableView.backgroundColor = [UIColor clearColor];
  33. self.youpaiptableView.showsVerticalScrollIndicator = NO;
  34. self.youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  35. self.youpaiptableView.estimatedRowHeight = 78.0f;
  36. self.youpaiptableView.rowHeight = 78.0f;
  37. self.youpaiptableView.delegate = self;
  38. self.youpaiptableView.dataSource= self;
  39. if (@available(iOS 15.0, *)) {
  40. self.youpaiptableView.sectionHeaderTopPadding = 0;
  41. }
  42. [self.view addSubview:self.youpaiptableView];
  43. self.youpaiptableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadNewData)];
  44. MJRefreshAutoNormalFooter* normalFooter = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)];
  45. [normalFooter setTitle:@"正在加载..." forState:(MJRefreshStateRefreshing)];
  46. [normalFooter setTitle:@"" forState:(MJRefreshStateNoMoreData)];
  47. self.youpaiptableView.mj_footer = normalFooter;
  48. self.youpaiptableView.mj_footer.automaticallyHidden = YES;
  49. }
  50. #pragma mark - tableView代理
  51. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  52. return self.youpaipbillArray.count;
  53. }
  54. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  55. YOUPAILZBillSectionModel *model = self.youpaipbillArray[section];
  56. return model.youpaiplist.count;
  57. }
  58. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  59. YOUPAILZBillSectionModel *sectionModel = self.youpaipbillArray[indexPath.section];
  60. YOUPAILZBillDetailCell* cell = [tableView dequeueReusableCellWithIdentifier:@"YOUPAILZBillDetailCell"];
  61. if (cell == nil) {
  62. cell = [[YOUPAILZBillDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YOUPAILZBillDetailCell"];
  63. }
  64. YOUPAILCBillDetailModel* model = [YOUPAILCBillDetailModel mj_objectWithKeyValues:sectionModel.youpaiplist[indexPath.row]];
  65. cell.youpaipbillModel = model;
  66. return cell;
  67. }
  68. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  69. }
  70. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  71. return 52.0f;
  72. }
  73. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  74. YOUPAILZBillSectionModel *sectionModel = self.youpaipbillArray[section];
  75. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 52.0f)];
  76. bgV.backgroundColor = LCBkgColor;
  77. NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
  78. [formatter setDateFormat:@"yyyy-MM"];//yyyy年MM月dd日
  79. NSString *dateString = sectionModel.youpaipdate;
  80. NSDate *date = [formatter dateFromString:dateString];
  81. [formatter setDateFormat:@"yyyy年MM月"];
  82. UILabel *dayL = [[UILabel alloc] init];
  83. dayL.text = [formatter stringFromDate:date];//@"2020年12月";
  84. dayL.font = LCFont12;
  85. dayL.textColor = HexColorFromRGB(0x9F9DA5);
  86. [bgV addSubview:dayL];
  87. [dayL mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.offset(14.0f);
  89. make.top.offset(9.0f);
  90. }];
  91. UILabel *enterL = [[UILabel alloc] init];
  92. enterL.font = LCFont12;
  93. enterL.textColor = [UIColor whiteColor];
  94. enterL.text = [NSString stringWithFormat:@"收入 %@钻石",sectionModel.youpaipincome];
  95. [bgV addSubview:enterL];
  96. [enterL mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.offset(14.0f);
  98. make.bottom.offset(-10.0f);
  99. }];
  100. UILabel *outL = [[UILabel alloc] init];
  101. outL.font = LCFont12;
  102. outL.textColor = [UIColor whiteColor];
  103. outL.text = [NSString stringWithFormat:@"支出 %@钻石",sectionModel.youpaipexpend];
  104. [bgV addSubview:outL];
  105. [outL mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.left.equalTo(enterL.mas_right).offset(15.0f);
  107. make.bottom.offset(-10.0f);
  108. }];
  109. return bgV;
  110. }
  111. - (void)youpaiffilterAction{
  112. PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
  113. datePickManager.isShadeBackground = true;
  114. datePickManager.cancelButtonFont = LCFont(15);
  115. datePickManager.confirmButtonFont = LCFont(15);
  116. datePickManager.cancelButtonTextColor = HexColorFromRGB(0x9F9DA5);
  117. datePickManager.confirmButtonTextColor = [UIColor whiteColor];
  118. datePickManager.headerViewBackgroundColor = LCBkgColor;
  119. datePickManager.headerHeight = 50;
  120. PGDatePicker *datePicker = datePickManager.datePicker;
  121. datePicker.backgroundColor = LCBkgColor;
  122. datePicker.rowHeight = 35;
  123. datePicker.middleTextColor = [UIColor whiteColor];
  124. datePicker.textColorOfSelectedRow = [UIColor whiteColor];
  125. datePicker.textColorOfOtherRow = [[UIColor whiteColor] colorWithAlphaComponent:0.2f];
  126. datePicker.textFontOfSelectedRow = LCFont(17);
  127. datePicker.textFontOfOtherRow = LCFont(17);
  128. datePicker.lineBackgroundColor = [UIColor clearColor];
  129. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  130. NSDate* currentDate = [NSDate date];
  131. [dateFormatter setDateFormat:@"yyyy"];
  132. NSString* currentYear=[dateFormatter stringFromDate:currentDate] ;
  133. [dateFormatter setDateFormat:@"MM"];
  134. NSString* currentMonth=[dateFormatter stringFromDate:currentDate];
  135. NSString* maxDateStr = [NSString stringWithFormat:@"%zd-%@",[currentYear integerValue],currentMonth];
  136. NSString* minDateStr = [NSString stringWithFormat:@"%zd-%@",[currentYear integerValue]-50,currentMonth];
  137. [dateFormatter setDateFormat:@"yyyy-MM"];
  138. NSString* defaultDateStr;
  139. NSDate *date = [dateFormatter dateFromString:defaultDateStr];//上次设置的日期
  140. [datePicker setDate:date];
  141. datePicker.maximumDate = [dateFormatter dateFromString:maxDateStr];
  142. datePicker.minimumDate = [dateFormatter dateFromString:minDateStr];
  143. datePicker.delegate = self;
  144. datePicker.datePickerType = PGDatePickerTypeLine;
  145. datePicker.isHiddenMiddleText = false;
  146. datePicker.datePickerMode = PGDatePickerModeYearAndMonth;
  147. [self presentViewController:datePickManager animated:false completion:nil];
  148. }
  149. - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents{
  150. NSLog(@"dateComponents = %@", dateComponents);
  151. NSInteger year=[dateComponents year];
  152. NSInteger month=[dateComponents month];
  153. self.youpaipdate = [NSString stringWithFormat:@"%ld-%ld",year,month];
  154. [self.youpaiptableView.mj_header beginRefreshing];
  155. }
  156. - (void)youpaifloadNewData{
  157. self.youpaiptableView.mj_footer.hidden = YES;
  158. [self.youpaiptableView.mj_footer endRefreshing];//先结束上拉,假如有的话
  159. self.youpaipcurrentPage = 1;
  160. [LCHttpHelper requestWithURLString:WalletBill parameters:@{@"page":@(self.youpaipcurrentPage),@"date":self.youpaipdate} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  161. NSDictionary* dict = (NSDictionary*)responseObject;
  162. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  163. if (code==0) {//成功
  164. [self.youpaipbillArray removeAllObjects];
  165. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"new_list"];
  166. NSMutableArray* modelArray = [YOUPAILZBillSectionModel mj_objectArrayWithKeyValuesArray:array];
  167. [self.youpaipbillArray addObjectsFromArray:modelArray];
  168. self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  169. self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  170. [self.youpaiptableView reloadData];
  171. if (self.youpaipcurrentPage>=self.youpaiptotalPage) {
  172. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  173. self.youpaiptableView.mj_footer.hidden = YES;
  174. }
  175. [self.youpaiptableView.mj_header endRefreshing];
  176. }else{
  177. [self.youpaiptableView.mj_header endRefreshing];
  178. }
  179. } failure:^(NSError *error) {
  180. [self.youpaiptableView.mj_header endRefreshing];
  181. }];
  182. }
  183. - (void)youpaifloadMoreData{
  184. [self.youpaiptableView.mj_header endRefreshing];
  185. self.youpaiptableView.mj_footer.hidden = YES;
  186. [self.youpaiptableView.mj_footer endRefreshing];
  187. self.youpaipcurrentPage+=1;
  188. [LCHttpHelper requestWithURLString:WalletBill parameters:@{@"page":@(self.youpaipcurrentPage),@"date":self.youpaipdate} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  189. NSDictionary* dict = (NSDictionary*)responseObject;
  190. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  191. if (code==0) {//成功
  192. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"new_list"];
  193. NSMutableArray* modelArray = [YOUPAILZBillSectionModel mj_objectArrayWithKeyValuesArray:array];
  194. if (modelArray.count != 0) {
  195. YOUPAILZBillSectionModel *firstModel = modelArray.firstObject;
  196. YOUPAILZBillSectionModel *lastModel = self.youpaipbillArray.lastObject;
  197. if ([firstModel.youpaipdate isEqual:lastModel.youpaipdate]) {
  198. [lastModel.youpaiplist addObjectsFromArray:firstModel.youpaiplist];
  199. }else{
  200. [self.youpaipbillArray addObject:firstModel];
  201. }
  202. for (NSInteger i = 1; i < modelArray.count; i ++) {
  203. [self.youpaipbillArray addObject:modelArray[i]];
  204. }
  205. }
  206. // [self.billArray addObjectsFromArray:modelArray];
  207. self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  208. self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  209. [self.youpaiptableView reloadData];
  210. if (self.youpaipcurrentPage>=self.youpaiptotalPage) {
  211. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  212. self.youpaiptableView.mj_footer.hidden = YES;
  213. }
  214. [self.youpaiptableView.mj_header endRefreshing];
  215. }else{
  216. [self.youpaiptableView.mj_header endRefreshing];
  217. }
  218. } failure:^(NSError *error) {
  219. [self.youpaiptableView.mj_header endRefreshing];
  220. }];
  221. }
  222. @end