171 lines
5.8 KiB
Objective-C
171 lines
5.8 KiB
Objective-C
//
|
|
// 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
|