// // WalletDetailsController.m // model // // Created by zuxiukuan on 2018/7/17. // Copyright © 2018年 Mine. All rights reserved. // 钱包明细 #import "WalletDetailsController.h" #import "RemindingView.h" #import "MyWalletDetailListCell.h" #import "PGDatePicker.h" #import "PGDatePickManager.h" #import "IncomeListModel.h" #import "WithdrawListModel.h" #import "WithdrawalDetailController.h" @interface WalletDetailsController () { NSInteger index; NSString *totalIncome; NSString *monthIncom; NSString *yearString; NSString *monthString; } @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray *dataArray; @property (nonatomic, strong) UILabel *allIncomeLabel; @end @implementation WalletDetailsController - (void)viewDidLoad { [super viewDidLoad]; index = 1; totalIncome = @""; monthIncom = @""; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; dateFormatter.dateFormat = @"yyyy-MM"; NSDate *datenow = [NSDate date]; NSString *time = [dateFormatter stringFromDate:datenow]; yearString = [time substringToIndex:4]; monthString = [time substringFromIndex:5]; self.dataArray = [[NSMutableArray alloc]init]; self.view.backgroundColor = [UIColor whiteColor]; [self creatNavBar]; [self creatTableView]; if ([self.detailsIndex isEqualToString:@"1"]) { self.title = @"收入明细"; [self getIncomeDataFromNetworking]; }else{ self.title = @"提现明细"; [self getWithdrawDataFromNetworking]; } } - (void)creatNavBar { //返回按钮 UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(0, 0, 40, 40); [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal]; btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; //nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整 self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem]; } - (void)backClick { [self.navigationController popViewControllerAnimated:YES]; } #pragma mark -- 网络请求 - (void)getIncomeDataFromNetworking { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; NSString *indexStr = [NSString stringWithFormat:@"%zd",index]; ModelUser *modelUser = [ModelUser user]; NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:modelUser.pk,@"memberpk",yearString,@"year",monthString,@"month",indexStr,@"index",@"10",@"size", nil]; [YanCNetWorkManager requestPostWithURLStr:Url_getIncomeDetails(PublicUrl) parameters:dic finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { NSDictionary *dic = dataDic[@"data"]; NSArray *data = dic[@"data"]; NSArray * array = [IncomeListModel arrayOfModelsFromDictionaries:data]; [self.dataArray addObjectsFromArray:array]; totalIncome = dataDic[@"allcoin"]; monthIncom = dataDic[@"incomecoin"]; self.allIncomeLabel.text = [NSString stringWithFormat:@"累计收入 %@元",totalIncome]; NSString *number = dic[@"count"]; NSInteger num = [number integerValue]; [self.tableView.mj_header endRefreshing]; [self.tableView reloadData]; if (num == self.dataArray.count || num == 0) { [self.tableView.mj_footer endRefreshingWithNoMoreData]; }else{ [self.tableView.mj_footer endRefreshing]; } } else { [MBProgressHUD showInfo:@"请求失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } - (void)getWithdrawDataFromNetworking { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; NSString *indexStr = [NSString stringWithFormat:@"%zd",index]; ModelUser *modelUser = [ModelUser user]; NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:modelUser.pk,@"memberpk",yearString,@"year",monthString,@"month",indexStr,@"index",@"10",@"size", nil]; [YanCNetWorkManager requestPostWithURLStr:Url_getWithdrawList(PublicUrl) parameters:dic finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { NSDictionary *dic = dataDic[@"data"]; NSArray *data = dic[@"data"]; NSArray * array = [WithdrawListModel arrayOfModelsFromDictionaries:data]; [self.dataArray addObjectsFromArray:array]; totalIncome = dataDic[@"allcoin"]; monthIncom = dataDic[@"outcashcoin"]; self.allIncomeLabel.text = [NSString stringWithFormat:@"累计收入 %@元",totalIncome]; NSString *number = dic[@"count"]; NSInteger num = [number integerValue]; [self.tableView.mj_header endRefreshing]; [self.tableView reloadData]; if (num == self.dataArray.count || num == 0) { [self.tableView.mj_footer endRefreshingWithNoMoreData]; }else{ [self.tableView.mj_footer endRefreshing]; } } else { [MBProgressHUD showInfo:@"请求失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } -(void)creatRemindingView{ RemindingView *remindingView = [[RemindingView alloc] initWithFrame:self.view.bounds]; [self.view addSubview:remindingView]; if ([self.detailsIndex isEqualToString:@"1"]) { self.title = @"收入明细"; remindingView.remindView.image = [UIImage imageNamed:@"shourumingxi-1"]; remindingView.remindLabel.text = @"还没有任何收入明细记录"; }else if ([self.detailsIndex isEqualToString:@"2"]) { self.title = @"提现明细"; remindingView.remindView.image = [UIImage imageNamed:@"shourumingxi-1"]; remindingView.remindLabel.text = @"还没有任何提现明细记录"; } } - (void)creatTableView { //tableView头部视图 UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)]; headerView.backgroundColor = [UIColor whiteColor]; self.allIncomeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, ScreenWidth-40, 30)]; self.allIncomeLabel.text = [NSString stringWithFormat:@"累计收入 %@元",totalIncome]; self.allIncomeLabel.textAlignment = NSTextAlignmentLeft; self.allIncomeLabel.font = [UIFont systemFontOfSize:16]; self.allIncomeLabel.textColor = RGBValueColor(0x333333, 1.0); [headerView addSubview:self.allIncomeLabel]; //加载tableView self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-(Height_NaviBar)) style:UITableViewStylePlain]; self.tableView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0); self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.showsVerticalScrollIndicator = NO; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.tableHeaderView = headerView; self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshList)]; self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; [self.view addSubview:self.tableView]; [self.tableView registerClass:[MyWalletDetailListCell class] forCellReuseIdentifier:@"MyWalletDetailListCell"]; } -(void)refreshList{ index = 1; [self.dataArray removeAllObjects]; if ([self.detailsIndex isEqualToString:@"1"]) { [self getIncomeDataFromNetworking]; }else{ [self getWithdrawDataFromNetworking]; } } - (void)loadMoreData{ index++; if ([self.detailsIndex isEqualToString:@"1"]) { [self getIncomeDataFromNetworking]; }else{ [self getWithdrawDataFromNetworking]; } } #pragma mark -- UITableViewDelegate, UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 80; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 50; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0; } - (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)]; headerView.backgroundColor = RGBValueColor(0xf5f5f5, 1.0); UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 80, 30)]; dateLabel.text = [NSString stringWithFormat:@"%@年%@月",yearString,monthString]; dateLabel.textAlignment = NSTextAlignmentLeft; dateLabel.font = [UIFont systemFontOfSize:14]; dateLabel.textColor = RGBValueColor(0x333333, 1.0); [headerView addSubview:dateLabel]; UILabel *monthIncomLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 10, ScreenWidth-180, 30)]; monthIncomLabel.text = [NSString stringWithFormat:@"收入 %@元",monthIncom]; monthIncomLabel.textAlignment = NSTextAlignmentLeft; monthIncomLabel.font = [UIFont systemFontOfSize:14]; monthIncomLabel.textColor = RGBValueColor(0x999999, 1.0); [headerView addSubview:monthIncomLabel]; UIButton *dateButton = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-50, 5, 40, 40)]; [dateButton setImage:[UIImage imageNamed:@"rili"] forState:UIControlStateNormal]; [dateButton addTarget:self action:@selector(clickSelectDate) forControlEvents:UIControlEventTouchUpInside]; [headerView addSubview:dateButton]; return headerView; } - (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.01)]; footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0); return footerView; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"MyWalletDetailListCell"; MyWalletDetailListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[MyWalletDetailListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } NSString *imageName = @"shipin"; NSString *title = @""; NSString *time = @""; NSString *amount = @""; if ([self.detailsIndex isEqualToString:@"1"]) { IncomeListModel *model = self.dataArray[indexPath.row]; if ([model.stype isEqualToString:@"聊天"]) { imageName = @"shipin"; }else if ([model.stype isEqualToString:@"订单"]){ imageName = @"jineng-1"; }else if ([model.stype isEqualToString:@"红包"]){ imageName = @"hongbaoshouru"; } title = [NSString stringWithFormat:@"%@",model.atype]; time = model.adate; amount = [NSString stringWithFormat:@"+%@",model.coin]; }else{ WithdrawListModel *model = self.dataArray[indexPath.row]; if ([model.ptype isEqualToString:@"支付宝"]) { imageName = @"zhifubao-1"; }else{ imageName = @"weixin"; } title = [NSString stringWithFormat:@"%@",model.ptype]; time = model.feedate; amount = [NSString stringWithFormat:@"%@",model.fee]; } cell.iconImageView.image = [UIImage imageNamed:imageName]; cell.titleLabel.text = title; cell.timeLabel.text = time; cell.amountLabel.text = amount; if ([[ModelUser user].modelpk isEqualToString:@"51"]) { cell.iconImageView.image = [UIImage imageNamed:@"jineng-1"]; cell.titleLabel.text = @"服务收入"; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([self.detailsIndex isEqualToString:@"2"]) { WithdrawListModel *model = self.dataArray[indexPath.row]; WithdrawalDetailController *vc = [[WithdrawalDetailController alloc]init]; vc.withdrawPk = model.pk; [self.navigationController pushViewController:vc animated:YES]; } } -(void)clickSelectDate{ PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init]; PGDatePicker *datePicker = datePickManager.datePicker; datePicker.delegate = self; datePicker.datePickerMode = PGDatePickerModeYearAndMonth; [self presentViewController:datePickManager animated:false completion:nil]; NSDate *datenow = [NSDate date]; NSDate *datemin = [NSDate dateWithTimeInterval:-24*60*60*30*12 sinceDate:datenow]; datePicker.minimumDate = datemin; datePicker.maximumDate = datenow; datePickManager.titleLabel.text = @"选择开始时间"; //设置半透明的背景颜色 datePickManager.isShadeBackgroud = true; //设置头部的背景颜色 datePickManager.headerViewBackgroundColor = [UIColor whiteColor]; //设置线条的颜色 datePicker.lineBackgroundColor = [UIColor colorWithHexString:@"#FE4086"]; //设置选中行的字体颜色 datePicker.textColorOfSelectedRow = [UIColor colorWithHexString:@"#FE4086"]; //设置未选中行的字体颜色 datePicker.textColorOfOtherRow = [UIColor blackColor]; //设置取消按钮的字体颜色 datePickManager.cancelButtonTextColor = [UIColor blackColor]; //设置取消按钮的字 datePickManager.cancelButtonText = @"取消"; //设置取消按钮的字体大小 datePickManager.cancelButtonFont = [UIFont boldSystemFontOfSize:17]; //设置确定按钮的字体颜色 datePickManager.confirmButtonTextColor = [UIColor colorWithHexString:@"#FE4086"]; //设置确定按钮的字 datePickManager.confirmButtonText = @"确定"; //设置确定按钮的字体大小 datePickManager.confirmButtonFont = [UIFont boldSystemFontOfSize:17]; } #pragma PGDatePickerDelegate - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents { NSLog(@"dateComponents = %@", dateComponents); yearString = [NSString stringWithFormat:@"%d",(int)[dateComponents year]]; monthString = [NSString stringWithFormat:@"%d",(int)[dateComponents month]]; index = 1; [self.dataArray removeAllObjects]; if ([self.detailsIndex isEqualToString:@"1"]) { [self getIncomeDataFromNetworking]; }else{ [self getWithdrawDataFromNetworking]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end