Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,15 @@
//
// CoastRecordViewController.h
// Ifish
//
// Created by imac on 2017/4/25.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "BaseVIewContorller.h"
@interface CoastRecordViewController : BaseVIewContorller
@property (nonatomic) BOOL fromDetailVC;
@end
@@ -0,0 +1,263 @@
//
// CoastRecordViewController.m
// Ifish
//
// Created by imac on 2017/4/25.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "CoastRecordViewController.h"
#import "GoldConvertRecordViewCell.h"
#import "DiscountCoupon.h"
#import "JHRefresh.h"
@interface CoastRecordViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArr;
@property(nonatomic)BOOL isLoadMore;
@property(nonatomic) CGFloat currentPage;
@property(nonatomic,copy) NSString *total;
@end
const float PageSize = 20.0f;
@implementation CoastRecordViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:@"兑换记录"];
_dataArr = [[NSMutableArray alloc] init];
_currentPage = 0;
[self creatTab];
[self loadDatas];
}
-(void)loadDatas{
[self loadDataWith:PageSize firstResult:0];
}
-(void)loadDataWith:(NSInteger )pageSize firstResult:(NSInteger)firstResult
{
__weak typeof (self)weakSelf = self;
NSString *userID = [dataContorl dataControlGetUserIdInfo];
[AFHttpTool couponRecords:userID pageSize:pageSize firstResult:firstResult success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result=reDic[@"result"];
NSLog(@"redic***:%@",reDic);
self.total =reDic[@"total"];
if ([result isEqualToString:@"100"]){
NSArray *dataArr =reDic[@"data"];
if (dataArr&&![dataArr isKindOfClass:[NSNull class]]){
if (dataArr.count!=0) {
for (NSDictionary *dic in dataArr) {
DiscountCoupon *model = [[DiscountCoupon alloc] initWithDict:dic];
[_dataArr addObject:model];
}
[weakSelf.tableView reloadData];
}else{
if (_currentPage==0) {
[weakSelf resetNoDataView];
}
}
}
}else{
[weakSelf.view makeToast:@"请求异常"];
}
} failure:^(NSError *err) {
[weakSelf.view makeToast:@"请求异常"];
}];
}
-(void)resetNoDataView{
[self.tableView removeFromSuperview];
self.view.backgroundColor =TABLE_BACKGROUD_COLOR;
UIImageView *backImg = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 98/2 ,self.view.frame.size.height/4, 108, 98)];
backImg.image = [UIImage imageNamed:@"nurse_empty_picture"];
[self.view addSubview:backImg];
UILabel *title=[[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(backImg.frame) + 30, self.view.frame.size.width,20)];
title.text = @"还里空空如也";
title.textAlignment = NSTextAlignmentCenter;
title.font =[UIFont systemFontOfSize:15];
title.textColor = RGB(51, 51, 51);
[self.view addSubview:title];
UILabel *title2=[[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(title.frame) + 7, self.view.frame.size.width,20)];
title2.text = @"还没有兑换记录~";
title2.font =[UIFont systemFontOfSize:12];
title2.textAlignment = NSTextAlignmentCenter;
title2.textColor = RGB(153, 153, 153);
[self.view addSubview:title2];
}
-(void)goBackAction{
if (_fromDetailVC) {
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}else{
[self.navigationController popViewControllerAnimated:YES];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)creatTab{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.scrollEnabled = YES;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = RGB(242, 242, 242);
[self.view addSubview:self.tableView];
[self creatReatRefreshView];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return _dataArr.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
GoldConvertRecordViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GoldConvertRecordViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"GoldConvertRecordViewCell" owner:self options:nil]lastObject];
}
DiscountCoupon *model = _dataArr[indexPath.section];
[cell loadCellwith:model];
[cell.fuzhiBtn addTarget:self action:@selector(fuzhiBtnAction:) forControlEvents:UIControlEventTouchUpInside];
cell.fuzhiBtn.tag = indexPath.section;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 170;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 10;
}
#pragma mark - 复制激活码
-(void)fuzhiBtnAction:(UIButton*)btn{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
DiscountCoupon *model = _dataArr[btn.tag];
UserModel *user = [dataContorl getUserInfo];
NSString *paste = [NSString stringWithFormat:@"我是爱鱼奇用户:%@,手机号:%@,激活码:%@",user.nickName,user.phoneNumber,model.activationCode];
pasteboard.string = paste;
[self.view makeToast:@"已成功复制到粘贴板"];
}
#pragma mark UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self thredshold:0.7f intemPerPage:PageSize currentPage:_currentPage scrollViewDidScroll:scrollView];
}
//当前页面已经划过了 70% 的时候,就请求新的资源,加载数据 thredshold 设置为70% 并不是单页 70%
//上拉预加载
-(void)thredshold:(CGFloat)thredshold intemPerPage:(CGFloat)pageSize currentPage:(CGFloat)currentPage
scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y<0) {
return;
}
CGFloat current = scrollView.contentOffset.y + scrollView.frame.size.height;
CGFloat total = scrollView.contentSize.height;
CGFloat ratio = current / total;
CGFloat needRead = pageSize * thredshold + currentPage * pageSize;
CGFloat totalItem = pageSize * (currentPage + 1);
CGFloat newThreshold = needRead / totalItem;
if (ratio >= newThreshold){
int pagecount =[self.total floatValue]/PageSize + 1;
if (_currentPage<pagecount) {
_currentPage += 1;
NSInteger firstSize = (currentPage +1)*pageSize;
[self loadmoredata:firstSize pageSize:pageSize];
NSLog(@"*****----*****%f",_currentPage);
}
}
}
#pragma mark -加载更多
-(void)loadmoredata:(NSInteger)firstResult pageSize:(NSInteger)pageSize{
[self loadDataWith:PageSize firstResult:firstResult];
}
#pragma mark 刷新 加载时更多
-(void)creatReatRefreshView{
__weak typeof (self)weskSelf=self;
//上拉加载更多
[weskSelf.tableView addRefreshFooterViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{
if (weskSelf.isLoadMore) {
return ;
}
weskSelf.isLoadMore=YES;
int pagecount =[self.total floatValue]/PageSize + 1;
NSLog(@"page:::::**** %d",pagecount);
if (_currentPage>=pagecount) {
[weskSelf.view makeToast:@"已经全部加载完毕"];
[weskSelf endRefreshing];
}
}];
}
-(void)endRefreshing{
if (self.isLoadMore) {
self.isLoadMore=NO;
[self.tableView footerEndRefreshing];
}
}
@end
@@ -0,0 +1,14 @@
//
// IfishGoldCoastDetailViewController.h
// Ifish
//
// Created by imac on 2017/4/25.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "BaseVIewContorller.h"
#import "DiscountCoupon.h"
@interface IfishGoldCoastDetailViewController : BaseVIewContorller
@property(nonatomic,strong) DiscountCoupon *convert;
@end
@@ -0,0 +1,170 @@
//
// IfishGoldCoastDetailViewController.m
// Ifish
//
// Created by imac on 2017/4/25.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "IfishGoldCoastDetailViewController.h"
#import "GoldConvertDetailViewCell.h"
#import "CoastRecordViewController.h"
@interface IfishGoldCoastDetailViewController ()<UITableViewDelegate,UITableViewDataSource,MBProgressHUDDelegate>
@property(nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong) MBProgressHUD *hud;
@end
@implementation IfishGoldCoastDetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:@"金币兑换详情"];
[self creatTab];
}
-(void)creatTab{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.scrollEnabled = YES;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = RGB(242, 242, 242);
[self.view addSubview:self.tableView];
UIButton *duiHuanBtn=[UIButton buttonWithType:UIButtonTypeCustom];
duiHuanBtn.frame = CGRectMake(0, self.view.frame.size.height -49, self.view.frame.size.width, 49);
[duiHuanBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"立即兑换"];
[title addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:13] range:NSMakeRange(0, title.length)];
[title addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, title.length)];
[duiHuanBtn setAttributedTitle:title forState:UIControlStateNormal];
[duiHuanBtn setBackgroundColor:RGB(67, 186, 255)];
[duiHuanBtn addTarget:self action:@selector(duihuanBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:duiHuanBtn];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
GoldConvertDetailViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GoldConvertDetailViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"GoldConvertDetailViewCell" owner:self options:nil]lastObject];
}
[cell loadCellDataWith:self.convert];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 470;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 10;
}
#pragma mark -金币兑换
-(void)duihuanBtnClick{
//判断金币是否足够
IfishUserAsset *asset =[dataContorl getAllIfishUserAsset];
if (asset.goldValue < self.convert.needGold) {
[self.view makeToast:@"金币不足"];
return;
}
__weak typeof (self)weakSelf = self;
//_hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
//_hud.delegate=self;
NSString *couponId = [NSString stringWithFormat:@"%d",self.convert.couponId];
NSString *userID =[dataContorl dataControlGetUserIdInfo];
[AFHttpTool exchangeCoupon:userID couponId:couponId success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result=reDic[@"result"];
if ([result isEqualToString:@"100"]){
[weakSelf.view makeToast:@"兑换成功"];
IfishUserAsset *asset =[dataContorl getAllIfishUserAsset];
NSDictionary *dataDic = reDic[@"data"];
asset.goldValue = [[dataDic objectForKey:@"goldValue"] integerValue];
[dataContorl resetUserAsset:asset];
weakSelf.convert.couponNumber = [dataDic objectForKey:@"couponNumber"];
weakSelf.convert.exchangeCount = [dataDic objectForKey:@"exchangeCount"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"quanChange" object:weakSelf.convert];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(pushJiluView) userInfo:nil repeats:NO];
}else if ([result isEqualToString:@"215"]){
[weakSelf.view makeToast:@"金币不足"];
}else{
[weakSelf.view makeToast:@"请求出错"];
}
// [_hud hide:YES afterDelay:0.5];
} failure:^(NSError *err) {
// [_hud hide:YES afterDelay:0.5];
[weakSelf.view makeToast:@"请求异常"];
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)pushJiluView{
CoastRecordViewController *recordV =[[CoastRecordViewController alloc] init];
recordV.fromDetailVC = YES;
[self.navigationController pushViewController:recordV animated:YES];
}
/*
#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
@@ -0,0 +1,13 @@
//
// IfishGoldCoastViewController.h
// Ifish
//
// Created by imac on 2017/4/25.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "BaseVIewContorller.h"
@interface IfishGoldCoastViewController : BaseVIewContorller
@end
@@ -0,0 +1,166 @@
//
// IfishGoldCoastViewController.m
// Ifish
//
// Created by imac on 2017/4/25.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "IfishGoldCoastViewController.h"
#import "GolaCoastListViewCell.h"
#import "CoastRecordViewController.h"
#import "IfishGoldCoastDetailViewController.h"
#import "DiscountCoupon.h"
@interface IfishGoldCoastViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArr;
@property (nonatomic) NSIndexPath *selectIndexPath;
@property (nonatomic) BOOL isChage;
@end
@implementation IfishGoldCoastViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:@"金币兑换"];
_dataArr =[[NSMutableArray alloc] init];
_isChage = NO;
[self creatTab];
UIBarButtonItem*rightItem= [[UIBarButtonItem alloc] initWithTitle:@"兑换记录" style:UIBarButtonItemStyleDone target:self action:@selector(duihuanjiluAction)];
self.navigationItem.rightBarButtonItem= rightItem;
[self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
[self loadDataS];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(quanChangeDidChange:) name:@"quanChange" object:nil];
}
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"quanChange" object:nil];
}
-(void)quanChangeDidChange:(NSNotification *)noty{
DiscountCoupon *model=[noty object];
_isChage = YES;
[self.dataArr replaceObjectAtIndex:self.selectIndexPath.section withObject:model];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if (_isChage ) {
[self.tableView reloadData];
}
}
-(void)creatTab{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.scrollEnabled = YES;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = RGB(242, 242, 242);
[self.view addSubview:self.tableView];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return _dataArr.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
GolaCoastListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GolaCoastListViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"GolaCoastListViewCell" owner:self options:nil]lastObject];
}
DiscountCoupon *model = _dataArr[indexPath.section];
[cell loadCellwith:model];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 130;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.1;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
_selectIndexPath = indexPath;
IfishGoldCoastDetailViewController *detail = [[IfishGoldCoastDetailViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
detail.convert = _dataArr[indexPath.section];
[self.navigationController pushViewController:detail animated:YES];
}
-(void)loadDataS{
__weak typeof (self)weakSelf = self;
[AFHttpTool getValidatingCouponsSuccess:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result=reDic[@"result"];
NSLog(@"redic***:%@",reDic);
if ([result isEqualToString:@"100"]){
NSArray *dataArr =reDic[@"data"];
for (NSDictionary *dic in dataArr) {
DiscountCoupon *model = [[DiscountCoupon alloc] initWithDict:dic];
[_dataArr addObject:model];
}
[weakSelf.tableView reloadData];
}else{
[weakSelf.view makeToast:@"请求异常"];
}
} failure:^(NSError *err) {
[weakSelf.view makeToast:@"请求异常"];
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - 兑换记录
-(void)duihuanjiluAction
{
CoastRecordViewController *recordVC= [[CoastRecordViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
recordVC.fromDetailVC = NO;
[self.navigationController pushViewController:recordVC animated:YES];
}
/*
#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