YOUPAIHRBillSubDetailVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 "YOUPAIHRBillSubDetailVC.h"
  9. #import "YOUPAILZBillDetailCell.h"
  10. #import "PGDatePickManager.h"
  11. #import "UIViewController+TFPresent.h"
  12. #import "YOUPAILZBillSectionModel.h"
  13. @interface YOUPAIHRBillSubDetailVC ()<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 YOUPAIHRBillSubDetailVC
  21. -(void)dealloc{
  22. [[NSNotificationCenter defaultCenter]removeObserver:self];
  23. }
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.youpaipdate = @"";
  27. self.youpaipbillArray = [NSMutableArray array];
  28. self.view.backgroundColor = [UIColor whiteColor];
  29. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifchangSelectDate:) name:@"changSelectDate" object:nil];
  30. [self youpaifinitUI];
  31. [self.youpaiptableView.mj_header beginRefreshing];
  32. }
  33. -(void)youpaifchangSelectDate:(NSNotification*)notic{
  34. NSDictionary *dict = notic.userInfo;
  35. NSString *date =dict[@"date"];
  36. self.youpaipdate = date;
  37. [self.youpaiptableView.mj_header beginRefreshing];
  38. }
  39. - (void)youpaifinitUI{
  40. self.youpaiptableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  41. [self.view addSubview:self.youpaiptableView];
  42. [self.youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.top.mas_equalTo(0);
  44. make.left.mas_equalTo(0);
  45. make.right.mas_equalTo(0);
  46. make.bottom.mas_equalTo(0);
  47. }];
  48. self.youpaiptableView.backgroundColor = [UIColor clearColor];
  49. self.youpaiptableView.showsVerticalScrollIndicator = NO;
  50. self.youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  51. self.youpaiptableView.estimatedRowHeight = 78.0f;
  52. self.youpaiptableView.rowHeight = 78.0f;
  53. self.youpaiptableView.delegate = self;
  54. self.youpaiptableView.dataSource= self;
  55. if (@available(iOS 15.0, *)) {
  56. self.youpaiptableView.sectionHeaderTopPadding = 0;
  57. }
  58. self.youpaiptableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadNewData)];
  59. MJRefreshAutoNormalFooter* normalFooter = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)];
  60. [normalFooter setTitle:@"正在加载..." forState:(MJRefreshStateRefreshing)];
  61. [normalFooter setTitle:@"" forState:(MJRefreshStateNoMoreData)];
  62. self.youpaiptableView.mj_footer = normalFooter;
  63. self.youpaiptableView.mj_footer.automaticallyHidden = YES;
  64. }
  65. #pragma mark - tableView代理
  66. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  67. return self.youpaipbillArray.count;
  68. }
  69. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  70. YOUPAILZBillSectionModel *model = self.youpaipbillArray[section];
  71. return model.youpaiplist.count;
  72. }
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  74. YOUPAILZBillSectionModel *sectionModel = self.youpaipbillArray[indexPath.section];
  75. YOUPAILZBillDetailCell* cell = [tableView dequeueReusableCellWithIdentifier:@"YOUPAILZBillDetailCell"];
  76. if (cell == nil) {
  77. cell = [[YOUPAILZBillDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YOUPAILZBillDetailCell"];
  78. }
  79. YOUPAILCBillDetailModel* model = [YOUPAILCBillDetailModel mj_objectWithKeyValues:sectionModel.youpaiplist[indexPath.row]];
  80. model.newtype = self.newtype;
  81. cell.youpaipbillModel = model;
  82. return cell;
  83. }
  84. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  85. }
  86. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  87. return 52.0f;
  88. }
  89. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  90. YOUPAILZBillSectionModel *sectionModel = self.youpaipbillArray[section];
  91. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 52.0f)];
  92. bgV.backgroundColor = [UIColor whiteColor];
  93. NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
  94. [formatter setDateFormat:@"yyyy-MM"];//yyyy年MM月dd日
  95. NSString *dateString = sectionModel.youpaipdate;
  96. NSDate *date = [formatter dateFromString:dateString];
  97. [formatter setDateFormat:@"yyyy年MM月"];
  98. UILabel *dayL = [[UILabel alloc] init];
  99. dayL.text = [formatter stringFromDate:date];//@"2020年12月";
  100. dayL.font = LCFont12;
  101. dayL.textColor = LZA3AABEColor;
  102. [bgV addSubview:dayL];
  103. [dayL mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.left.offset(14.0f);
  105. make.centerY.mas_equalTo(0.0f);
  106. }];
  107. // UILabel *enterL = [[UILabel alloc] init];
  108. // enterL.font = LCFont12;
  109. // enterL.textColor = [UIColor whiteColor];
  110. // enterL.text = [NSString stringWithFormat:@"收入 %@钻石",sectionModel.income];
  111. // [bgV addSubview:enterL];
  112. // [enterL mas_makeConstraints:^(MASConstraintMaker *make) {
  113. // make.left.offset(14.0f);
  114. // make.bottom.offset(-10.0f);
  115. // }];
  116. //
  117. // UILabel *outL = [[UILabel alloc] init];
  118. // outL.font = LCFont12;
  119. // outL.textColor = [UIColor whiteColor];
  120. // outL.text = [NSString stringWithFormat:@"支出 %@钻石",sectionModel.expend];
  121. // [bgV addSubview:outL];
  122. // [outL mas_makeConstraints:^(MASConstraintMaker *make) {
  123. // make.left.equalTo(enterL.mas_right).offset(15.0f);
  124. // make.bottom.offset(-10.0f);
  125. // }];
  126. return bgV;
  127. }
  128. - (void)youpaiffilterAction{
  129. PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
  130. datePickManager.isShadeBackground = true;
  131. datePickManager.cancelButtonFont = LCFont(15);
  132. datePickManager.confirmButtonFont = LCFont(15);
  133. datePickManager.cancelButtonTextColor = LZA3AABEColor;
  134. datePickManager.confirmButtonTextColor = LZ273145Color;
  135. datePickManager.headerViewBackgroundColor = [UIColor whiteColor];
  136. datePickManager.headerHeight = 50;
  137. PGDatePicker *datePicker = datePickManager.datePicker;
  138. datePicker.backgroundColor = [UIColor whiteColor];
  139. datePicker.rowHeight = 35;
  140. datePicker.middleTextColor = LZ273145Color;
  141. datePicker.textColorOfSelectedRow = LZ273145Color;
  142. datePicker.textColorOfOtherRow = LZD3D1D7Color;
  143. datePicker.textFontOfSelectedRow = LCFont(17);
  144. datePicker.textFontOfOtherRow = LCFont(17);
  145. datePicker.lineBackgroundColor = [UIColor clearColor];
  146. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  147. NSDate* currentDate = [NSDate date];
  148. [dateFormatter setDateFormat:@"yyyy"];
  149. NSString* currentYear=[dateFormatter stringFromDate:currentDate] ;
  150. [dateFormatter setDateFormat:@"MM"];
  151. NSString* currentMonth=[dateFormatter stringFromDate:currentDate];
  152. NSString* maxDateStr = [NSString stringWithFormat:@"%zd-%@",[currentYear integerValue],currentMonth];
  153. NSString* minDateStr = [NSString stringWithFormat:@"%zd-%@",[currentYear integerValue]-50,currentMonth];
  154. [dateFormatter setDateFormat:@"yyyy-MM"];
  155. NSString* defaultDateStr;
  156. NSDate *date = [dateFormatter dateFromString:defaultDateStr];//上次设置的日期
  157. [datePicker setDate:date];
  158. datePicker.maximumDate = [dateFormatter dateFromString:maxDateStr];
  159. datePicker.minimumDate = [dateFormatter dateFromString:minDateStr];
  160. datePicker.delegate = self;
  161. datePicker.datePickerType = PGDatePickerTypeLine;
  162. datePicker.isHiddenMiddleText = false;
  163. datePicker.datePickerMode = PGDatePickerModeYearAndMonth;
  164. [self presentViewController:datePickManager animated:false completion:nil];
  165. }
  166. - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents{
  167. NSLog(@"dateComponents = %@", dateComponents);
  168. NSInteger year=[dateComponents year];
  169. NSInteger month=[dateComponents month];
  170. self.youpaipdate = [NSString stringWithFormat:@"%ld-%ld",year,month];
  171. [self.youpaiptableView.mj_header beginRefreshing];
  172. }
  173. - (void)youpaifloadNewData{
  174. self.youpaiptableView.mj_footer.hidden = YES;
  175. [self.youpaiptableView.mj_footer endRefreshing];//先结束上拉,假如有的话
  176. self.youpaipcurrentPage = 1;
  177. [LCHttpHelper requestWithURLString:WalletBill parameters:@{@"page":@(self.youpaipcurrentPage),@"date":self.youpaipdate,@"category":self.youpaiptype,@"cate_id":@"",@"new_type":self.newtype} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  178. NSDictionary* dict = (NSDictionary*)responseObject;
  179. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  180. if (code==0) {//成功
  181. [self.youpaipbillArray removeAllObjects];
  182. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"new_list"];
  183. NSMutableArray* modelArray = [YOUPAILZBillSectionModel mj_objectArrayWithKeyValuesArray:array];
  184. [self.youpaipbillArray addObjectsFromArray:modelArray];
  185. self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  186. self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  187. [self.youpaiptableView reloadData];
  188. if (self.youpaipcurrentPage>=self.youpaiptotalPage) {
  189. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  190. self.youpaiptableView.mj_footer.hidden = YES;
  191. }
  192. [self.youpaiptableView lz_hideEmptyView];
  193. if (self.youpaipbillArray.count == 0) {
  194. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无记录"];
  195. }
  196. [self.youpaiptableView.mj_header endRefreshing];
  197. }else{
  198. [self.youpaiptableView.mj_header endRefreshing];
  199. }
  200. } failure:^(NSError *error) {
  201. [self.youpaiptableView.mj_header endRefreshing];
  202. }];
  203. }
  204. - (void)youpaifloadMoreData{
  205. [self.youpaiptableView.mj_header endRefreshing];
  206. self.youpaiptableView.mj_footer.hidden = YES;
  207. [self.youpaiptableView.mj_footer endRefreshing];
  208. self.youpaipcurrentPage+=1;
  209. [LCHttpHelper requestWithURLString:WalletBill parameters:@{@"page":@(self.youpaipcurrentPage),@"date":self.youpaipdate,@"category":self.youpaiptype,@"cate_id":@"",@"new_type":self.newtype} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  210. NSDictionary* dict = (NSDictionary*)responseObject;
  211. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  212. if (code==0) {//成功
  213. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"new_list"];
  214. NSMutableArray* modelArray = [YOUPAILZBillSectionModel mj_objectArrayWithKeyValuesArray:array];
  215. if (modelArray.count != 0) {
  216. YOUPAILZBillSectionModel *firstModel = modelArray.firstObject;
  217. YOUPAILZBillSectionModel *lastModel = self.youpaipbillArray.lastObject;
  218. if ([firstModel.youpaipdate isEqual:lastModel.youpaipdate]) {
  219. [lastModel.youpaiplist addObjectsFromArray:firstModel.youpaiplist];
  220. }else{
  221. [self.youpaipbillArray addObject:firstModel];
  222. }
  223. for (NSInteger i = 1; i < modelArray.count; i ++) {
  224. [self.youpaipbillArray addObject:modelArray[i]];
  225. }
  226. }
  227. // [self.billArray addObjectsFromArray:modelArray];
  228. self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  229. self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  230. [self.youpaiptableView reloadData];
  231. if (self.youpaipcurrentPage>=self.youpaiptotalPage) {
  232. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  233. self.youpaiptableView.mj_footer.hidden = YES;
  234. }
  235. [self.youpaiptableView.mj_header endRefreshing];
  236. }else{
  237. [self.youpaiptableView.mj_header endRefreshing];
  238. }
  239. } failure:^(NSError *error) {
  240. [self.youpaiptableView.mj_header endRefreshing];
  241. }];
  242. }
  243. #pragma mark - JXCategoryListContainerView
  244. - (UIView *)listView{
  245. return self.view;
  246. }
  247. @end