YOUPAILCBillDetailVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. //
  2. // YOUPAILCBillDetailVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/17.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCBillDetailVC.h"
  9. #import "YOUPAILCBillDetailCell.h"
  10. #import "PGDatePickManager.h"
  11. #import "UIViewController+TFPresent.h"
  12. @interface YOUPAILCBillDetailVC ()<UITableViewDelegate,UITableViewDataSource,PGDatePickerDelegate>
  13. @property(nonatomic,assign)NSInteger youpaipcurrentPage;
  14. @property(nonatomic,assign)NSInteger youpaiptotalPage;
  15. @property(nonatomic,strong)NSMutableArray* youpaipbillArray;
  16. @property(nonatomic,strong)UIButton *youpaipdateBtn;
  17. @property(nonatomic,assign)NSInteger youpaipyear;
  18. @property(nonatomic,assign) NSInteger youpaipmonth;
  19. @property(nonatomic,strong)NSString *youpaipdate;
  20. @end
  21. @implementation YOUPAILCBillDetailVC
  22. - (void)youpaifsetupTableView{
  23. self.tableView.frame = CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight);
  24. self.tableView.showsVerticalScrollIndicator = NO;
  25. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  26. self.tableView.estimatedRowHeight = 56;
  27. self.tableView.delegate = self;
  28. self.tableView.dataSource= self;
  29. self.tableView.backgroundColor = LCBkgColor;
  30. self.isAllowScroll = YES;
  31. [self.view addSubview:self.tableView];
  32. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadNewData)];
  33. MJRefreshAutoNormalFooter* normalFooter = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)];
  34. [normalFooter setTitle:@"正在加载..." forState:(MJRefreshStateRefreshing)];
  35. [normalFooter setTitle:@"" forState:(MJRefreshStateNoMoreData)];
  36. self.tableView.mj_footer = normalFooter;
  37. self.tableView.mj_footer.automaticallyHidden = YES;
  38. // self.tableView.tableHeaderView = [self tableHeaderView];
  39. }
  40. -(UIView *)youpaiftableHeaderView
  41. {
  42. UIView *tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0,0,KScreenWidth, 44)];
  43. tableHeaderView.backgroundColor = [UIColor whiteColor];
  44. UIButton *dateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  45. dateBtn.frame = CGRectMake(16, 12,85, 20);
  46. [dateBtn setTitle:[NSString stringWithFormat:@"%ld年%ld月",_youpaipyear,_youpaipmonth] forState:0];
  47. dateBtn.titleLabel.font = LCFont(14);
  48. [dateBtn setTitleColor:LCWhiteColor forState:0];
  49. [dateBtn setBackgroundColor:HexColorFromRGB(0xA7A9FD)];
  50. [dateBtn setImage:[UIImage imageNamed:@""] forState:0];
  51. dateBtn.layer.cornerRadius = 10;
  52. dateBtn.layer.masksToBounds = YES;
  53. [dateBtn setImage:[UIImage imageNamed:@"vqu_images_down"] forState:0];
  54. dateBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -dateBtn.imageView.frame.size.width - dateBtn.frame.size.width + dateBtn.titleLabel.frame.size.width+15, 0, 0);
  55. dateBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -dateBtn.titleLabel.frame.size.width - dateBtn.frame.size.width + dateBtn.imageView.frame.size.width+15);
  56. [dateBtn addTarget:self action:@selector(youpaifselectDateAction) forControlEvents:UIControlEventTouchUpInside];
  57. self.youpaipdateBtn = dateBtn;
  58. [tableHeaderView addSubview:dateBtn];
  59. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(KScreenWidth/2.0, 16,KScreenWidth/2.0-16, 12)];
  60. label.text = @"仅展示当月账单";
  61. label.textColor = HexColorFromRGB(0x999999);
  62. label.textAlignment = NSTextAlignmentRight;
  63. label.font = LCFont(10);
  64. [tableHeaderView addSubview:label];
  65. return tableHeaderView;
  66. }
  67. -(void)youpaifselectDateAction{
  68. PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
  69. datePickManager.isShadeBackground = true;
  70. datePickManager.cancelButtonFont = LCFont(15);
  71. datePickManager.confirmButtonFont = LCFont(15);
  72. datePickManager.cancelButtonTextColor = HexColorFromRGB(0x9F9DA5);
  73. datePickManager.confirmButtonTextColor = [UIColor whiteColor];
  74. datePickManager.headerViewBackgroundColor = LCBkgColor;
  75. datePickManager.headerHeight = 50;
  76. PGDatePicker *datePicker = datePickManager.datePicker;
  77. datePicker.backgroundColor = LCBkgColor;
  78. datePicker.rowHeight = 35;
  79. datePicker.middleTextColor = [UIColor whiteColor];
  80. datePicker.textColorOfSelectedRow = [UIColor whiteColor];
  81. datePicker.textColorOfOtherRow = [[UIColor whiteColor] colorWithAlphaComponent:0.2f];
  82. datePicker.textFontOfSelectedRow = LCFont(17);
  83. datePicker.textFontOfOtherRow = LCFont(17);
  84. datePicker.lineBackgroundColor = [UIColor clearColor];
  85. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  86. NSDate* currentDate = [NSDate date];
  87. [dateFormatter setDateFormat:@"yyyy"];
  88. NSString* currentYear=[dateFormatter stringFromDate:currentDate] ;
  89. [dateFormatter setDateFormat:@"MM"];
  90. NSString* currentMonth=[dateFormatter stringFromDate:currentDate];
  91. NSString* maxDateStr = [NSString stringWithFormat:@"%zd-%@",[currentYear integerValue],currentMonth];
  92. NSString* minDateStr = [NSString stringWithFormat:@"%zd-%@",[currentYear integerValue]-50,currentMonth];
  93. [dateFormatter setDateFormat:@"yyyy-MM"];
  94. NSString* defaultDateStr;
  95. NSDate *date = [dateFormatter dateFromString:defaultDateStr];//上次设置的日期
  96. [datePicker setDate:date];
  97. datePicker.maximumDate = [dateFormatter dateFromString:maxDateStr];
  98. datePicker.minimumDate = [dateFormatter dateFromString:minDateStr];
  99. datePicker.delegate = self;
  100. datePicker.datePickerType = PGDatePickerTypeLine;
  101. datePicker.isHiddenMiddleText = false;
  102. datePicker.datePickerMode = PGDatePickerModeYearAndMonth;
  103. [self presentViewController:datePickManager animated:false completion:nil];
  104. }
  105. - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents{
  106. NSLog(@"dateComponents = %@", dateComponents);
  107. NSInteger year=[dateComponents year];
  108. NSInteger month=[dateComponents month];
  109. NSString* date = [NSString stringWithFormat:@"%ld年%ld月",year,month];
  110. [self.youpaipdateBtn setTitle:date forState:0];
  111. self.youpaipdate = [NSString stringWithFormat:@"%ld-%ld",year,month];
  112. [self.tableView.mj_header beginRefreshing];
  113. }
  114. - (void)youpaifloadNewData{
  115. self.tableView.mj_footer.hidden = YES;
  116. [self.tableView.mj_footer endRefreshing];//先结束上拉,假如有的话
  117. self.youpaipcurrentPage = 1;
  118. [LCHttpHelper requestWithURLString:WalletBill parameters:@{@"type":@(self.youpaiptype),@"cate_id":@(self.youpaipcate_id),@"page":@(self.youpaipcurrentPage),@"date":self.youpaipdate} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  119. NSDictionary* dict = (NSDictionary*)responseObject;
  120. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  121. if (code==0) {//成功
  122. [self.youpaipbillArray removeAllObjects];
  123. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"];
  124. NSMutableArray* modelArray = [YOUPAILCBillDetailModel mj_objectArrayWithKeyValuesArray:array];
  125. [self.youpaipbillArray addObjectsFromArray:modelArray];
  126. self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  127. self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  128. [self.tableView reloadData];
  129. if (self.youpaipcurrentPage>=self.youpaiptotalPage) {
  130. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  131. self.tableView.mj_footer.hidden = YES;
  132. }
  133. if (self.youpaipbillArray.count != 0) {
  134. [self.tableView lz_hideEmptyView];
  135. }else{
  136. [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_recharge_data"] content:@"暂无充值记录"];
  137. }
  138. [self.tableView.mj_header endRefreshing];
  139. }else{
  140. [self.tableView.mj_header endRefreshing];
  141. }
  142. } failure:^(NSError *error) {
  143. [self.tableView.mj_header endRefreshing];
  144. }];
  145. }
  146. - (void)youpaifloadMoreData{
  147. [self.tableView.mj_header endRefreshing];
  148. self.tableView.mj_footer.hidden = YES;
  149. [self.tableView.mj_footer endRefreshing];
  150. self.youpaipcurrentPage+=1;
  151. [LCHttpHelper requestWithURLString:WalletBill parameters:@{@"type":@(self.youpaiptype),@"cate_id":@(self.youpaipcate_id),@"page":@(self.youpaipcurrentPage),@"date":self.youpaipdate} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  152. NSDictionary* dict = (NSDictionary*)responseObject;
  153. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  154. if (code==0) {//成功
  155. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"];
  156. NSMutableArray* modelArray = [YOUPAILCBillDetailModel mj_objectArrayWithKeyValuesArray:array];
  157. [self.youpaipbillArray addObjectsFromArray:modelArray];
  158. self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  159. self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  160. [self.tableView reloadData];
  161. if (self.youpaipcurrentPage>=self.youpaiptotalPage) {
  162. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  163. self.tableView.mj_footer.hidden = YES;
  164. }
  165. [self.tableView.mj_header endRefreshing];
  166. }else{
  167. [self.tableView.mj_header endRefreshing];
  168. }
  169. } failure:^(NSError *error) {
  170. [self.tableView.mj_header endRefreshing];
  171. }];
  172. }
  173. - (void)viewDidLoad {
  174. [super viewDidLoad];
  175. NSDate *date = [NSDate date];
  176. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
  177. NSDateComponents *comps = [[NSDateComponents alloc] init];
  178. NSInteger unitFlags = NSCalendarUnitYear |NSCalendarUnitMonth;
  179. comps = [calendar components:unitFlags fromDate:date];
  180. //星期 注意星期是从周日开始计算
  181. //年
  182. self.youpaipyear=[comps year];
  183. //月
  184. self.youpaipmonth = [comps month];
  185. NSLog(@"%ld----%ld",_youpaipyear,_youpaipmonth);
  186. self.youpaipdate = [NSString stringWithFormat:@"%ld-%ld",self.youpaipyear,self.youpaipmonth];
  187. if (![LCSaveData getIsspecial]&& self.youpaipnomore==NO) {
  188. // self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifmoreSelect) image:[UIImage imageNamed:@"vqu_images_nav_more_black"]];
  189. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifmoreSelect) title:@"筛选" font:[UIFont systemFontOfSize:16] titleColor:DecColorFromRGB(51,51,51) highlightedColor:DecColorFromRGB(51,51,51) titleEdgeInsets:UIEdgeInsetsZero];
  190. }else{
  191. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(selectDateAction) title:@"筛选" font:LCFont14 titleColor:HexColorFromRGB(0xffffff) highlightedColor:HexColorFromRGB(0xffffff) titleEdgeInsets:UIEdgeInsetsZero];
  192. }
  193. self.youpaipbillArray = [NSMutableArray array];
  194. [self youpaifsetupTableView];
  195. [self youpaifupdateCate];
  196. }
  197. #pragma mark - tableView代理
  198. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  199. return 99;
  200. }
  201. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  202. return self.youpaipbillArray.count;
  203. }
  204. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  205. YOUPAILCBillDetailCell* cell = [[YOUPAILCBillDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YOUPAILCBillDetailCell"];
  206. YOUPAILCBillDetailModel* model = self.youpaipbillArray[indexPath.row];
  207. cell.youpaipbillModel = model;
  208. // [cell bottomLineforViewHeight:68];
  209. return cell;
  210. }
  211. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  212. }
  213. - (void)youpaifupdateCate{
  214. [self.tableView.mj_header beginRefreshing];
  215. NSArray* titleArray = @[@"全部",@"充值",LCStr(word20),@"视频",@"礼物",@"系统",@"兑换",@"私信",LCStr(word21),@"守护",@"公会"];//提现 系统调账
  216. if (self.youpaipcate_id==0) {
  217. self.title = LCStr(word22);//我的账单
  218. }else if (self.youpaipcate_id==1) {
  219. if (self.youpaiptype==1) {
  220. self.title = LCStr(word23);//充值余额明细
  221. }else if (self.youpaiptype==3){
  222. self.title =LCStr(word5);// @"收支明细";
  223. }else{
  224. self.title = LCStr(word24);//支付明细
  225. }
  226. }else{
  227. self.title = [NSString stringWithFormat:@"%@明细",titleArray[self.youpaipcate_id]];
  228. }
  229. }
  230. - (void)youpaifmoreSelect{
  231. NSArray* titleArray =@[@"全部",@"充值",LCStr(word20),@"视频",@"礼物",@"系统",@"兑换",@"私信",LCStr(word21),@"守护",@"公会"];//提现 系统调账
  232. NSArray* typeArray = @[@0,@1,@2,@3,@4,@5,@6,@7,@8,@9,@10];
  233. NSMutableArray* actionArray = [NSMutableArray array];
  234. for (int i =0; i<titleArray.count; i++) {
  235. ZCAlertActionBtn* actionBtn = [ZCAlertActionBtn actionWithTitle:titleArray[i] type:[typeArray[i] integerValue] andblock:^(NSInteger type) {
  236. self.youpaipcate_id = type;
  237. [self youpaifupdateCate];
  238. }];
  239. [actionArray addObject:actionBtn];
  240. }
  241. ZCAlertSheetBtnView* alertSheet = [[ZCAlertSheetBtnView alloc]initWithTitle:LCStr(word25) andShowCancelButton:YES andAction:actionArray selectIndex:self.youpaipcate_id column:3];//选择账单类型
  242. //modify by leo --fix bug ios13 20191009
  243. //alertSheet.alertWindow.rootViewController = self;
  244. alertSheet.alertWindow.hidden = NO;
  245. [alertSheet show];
  246. }
  247. @end