//
// BankCarfController.m
// DoctorProject
//
// Created by Apple on 15/9/25.
// Copyright (c) 2015年 sy. All rights reserved.
//
#import "BankCarfController.h"
#import "ChoseBankViewController.h"
#import "addBankModel.h"
@interface BankCarfController (){
NSIndexPath * indexPathd;
UIImageView * imageV;
UILabel * la;
NSIndexPath *gzIndespath;
}
@end
#define Redcolor [UIColor colorWithRed:118/255.0 green:24/255.0 blue:19/255.0 alpha:1.0f];
#define greyColor [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1.0f];
@implementation BankCarfController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"常用银行卡";
self.TvArray = [[NSMutableArray alloc]init];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"gdback3"] originalImage] style:UIBarButtonItemStylePlain target:self action:@selector(buttonIterm)];
self.navigationItem.leftBarButtonItem=backItem;
//自定义后退按钮后,手势返回上一级控制器的功能恢复
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
self.view.backgroundColor = [UIColor whiteColor];
UIImageView *imageBim = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"jianbian5"]];
imageBim.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[self.view addSubview:imageBim];
[self makeTV];
[self tianjiaCard];
}
- (void)buttonIterm{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)setextraCellLineHidden:(UITableView *)tableView{
UIView *view = [UIView new];
view.backgroundColor = [UIColor clearColor];
[_bankTV addSubview:view];
}
- (void)makeTV{
_bankTV = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
_bankTV.delegate = self;
_bankTV.dataSource = self;
_bankTV.backgroundColor = [UIColor clearColor];
// _bankTV.backgroundColor = [UIColor redColor];
_bankTV.separatorStyle = UITableViewCellSeparatorStyleNone;
[self setextraCellLineHidden:_bankTV];
[self.view addSubview:_bankTV];
UIView * Headview = [[UIView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 50)];
Headview.backgroundColor = [UIColor whiteColor];
UIImageView *image1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 12.5, 25, 25)];
image1.image = [UIImage imageNamed:@"typeselectbtnnorr.png"];
[Headview addSubview:image1];
UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(40, 10, 140, 30)];
lable.text = @"添加常用银行卡";
lable.font = [UIFont systemFontOfSize:18.0f];
lable.textColor = RGB(60, 191, 191);
[Headview addSubview:lable];
UIImageView *image2 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 30,15, 10, 20)];
image2.image = [UIImage imageNamed:@"返回键-拷贝-23"];
[Headview addSubview:image2];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(turnToAddVC)];
[Headview addGestureRecognizer:tap];
_bankTV.tableHeaderView = Headview;
// UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
//gzz0802
//
// [_bankTV addGestureRecognizer:longPress];
}
- (void)tianjiaCard{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSString *bank = [NSString stringWithFormat:MYBANKLIST];
bank = [bank stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"text/json",@"application/json", nil];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSString * ownerUuidStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"MyUuid"];
NSDictionary *dic = [[NSDictionary alloc]init];
dic = @{@"uuid":ownerUuidStr};
MCLog(@"====%@===",dic);
[manager POST: bank parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
MCLog(@"===================%@===================================",responseObject);
// MCLog(@"%@",[responseObject objectForKey:@"message"]);
NSDictionary *ditflo = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
// NSString *string = [NSString stringWithFormat:@"%@",[responseObject objectForKey:@"code"]];
NSString *string = [NSString stringWithFormat:@"%@",[ditflo objectForKey:@"code"]];
MCLog(@"%@",string);
if ([string isEqualToString:@"1"]) {
[self.TvArray removeAllObjects];
NSArray * arr = [ditflo objectForKey:@"data"];
MCLog(@"===%lu",(unsigned long)arr.count);
if (arr.count > 0) {
[imageV removeFromSuperview];
[la removeFromSuperview];
for (NSDictionary *item in arr) {
addBankModel * model = [[addBankModel alloc]initWithDic:item];
[self.TvArray addObject:model];
}
MCLog(@"申请成功");
}else{
imageV = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-75, SCREEN_HEIGHT/2-40, 150, 100)];
imageV.image = [UIImage imageNamed:@"iconfont-yinxingqia-(1)(2)"];
la = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-90, SCREEN_HEIGHT/2 +40+25, 180, 20)];
la.text = @"使用常用卡,支付更快捷";
la.textAlignment = YES;
la.textColor = RGB(188, 188, 188);
[self.view addSubview:la];
[self.view addSubview:imageV];
[self.view bringSubviewToFront:la];
[self.view bringSubviewToFront:imageV];
}
[_bankTV reloadData];
}else{
[self showHint:[responseObject objectForKey:@"message"]];
}
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
MCLog(@"%@",error);
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.TvArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 90;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
// cell.backgroundColor = [UIColor colorWithRed:226/255.0 green:227/255.0 blue:228/255.0 alpha:1.0];
}
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
addBankModel * model = self.TvArray[indexPath.row];
// MCLog(@"self.TvArray=====%@",self.TvArray);
// MCLog(@"%@",model.bankName);
// MCLog(@"%@",model.cardNum);
UILabel * bankNameLB = [[UILabel alloc]initWithFrame:CGRectMake(70, 15, 150, 30)];
[bankNameLB setFont:[UIFont boldSystemFontOfSize:17]];
bankNameLB.text = model.bankName;
UILabel * cardNumLB = [[UILabel alloc]initWithFrame:CGRectMake(75, 50, SCREEN_WIDTH-70, 30)];
NSString * str = [model.cardNum substringFromIndex:model.cardNum.length-4];
MCLog(@"%@",str);
NSMutableString * mulStr = [NSMutableString stringWithFormat:@"**** **** **** %@",str];
cardNumLB.text = mulStr;
[cardNumLB setFont:[UIFont boldSystemFontOfSize:19]];
NSArray * titleArr = @[@"中国银行",@"中国邮政",@"交通银行",@"中国民生银行",@"上海浦东发展银行",@"中信实业银行",@"中国农业银行",@"招商银行",@"中国建设银行",@"华夏银行",@"北京银行",@"兴业银行",@"中国工商银行"];
NSArray * imageArr = @[@"1.png",@"2.png",@"3.png",@"4.png",@"5.png",@"6.png",@"7.png",@"8.png",@"9.png",@"10.png",@"11.png",@"12.png",@"13.png"];
//暂时为空
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 50, 50)];
for (int i =0; i<titleArr.count; i++) {
if ([bankNameLB.text isEqualToString:titleArr[i]]) {
imageView.image = [UIImage imageNamed:imageArr[i]];
}
}
// [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://spic-108tian-com.alikunlun.com/pic/%@",model.bankImg]]];
UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, 80)];
view.tag = 718+indexPath.row;
view.backgroundColor = [UIColor whiteColor];
// view.backgroundColor = [UIColor yellowColor];
[cell.contentView addSubview:view];
[cell.contentView addSubview:imageView];
[cell.contentView addSubview:bankNameLB];
[cell.contentView addSubview:cardNumLB];
// cell.backgroundColor = [UIColor colorWithRed:226/255.0 green:227/255.0 blue:228/255.0 alpha:1.0];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
gzIndespath = indexPath;
// UIView * view = [self.view viewWithTag:718+indexPath.row];
// view.backgroundColor = RGB(63, 199, 190);
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{//gzz0802
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
UIAlertView *alview = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您确定要删除该张银行卡!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alview show];
}
-(void)turnToAddVC{
ChoseBankViewController *vc = [[ChoseBankViewController alloc]init];
vc.myBlock = ^(){
[self tianjiaCard];
};
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark -长按弹出删除银行卡提示框-
-(void)longPressAction:(UILongPressGestureRecognizer*)longTap{
UIView * view = [self.view viewWithTag:718+gzIndespath.row];
view.backgroundColor = RGB(63, 199, 190);
if(longTap.state == UIGestureRecognizerStateEnded)
{
CGPoint point = [longTap locationInView:_bankTV];
indexPathd = [_bankTV indexPathForRowAtPoint:point];
// UITableViewCell *cell = [_bankTV cellForRowAtIndexPath:indexPathd];
// cell.backgroundColor = [UIColor yellowColor];//gzz0718
// UIView *selectedView = [[UIView alloc] init];
// selectedView.backgroundColor = [UIColor blueColor];
// cell.selectedBackgroundView = selectedView;
// UIView * view = [self.view viewWithTag:718+indexPathd.row];
// view.backgroundColor = RGB(63, 199, 190);
if(indexPathd == nil)
return ;
UIAlertView * alteView =[[ UIAlertView alloc]initWithTitle:@"提示" message:@"您确定要删除该张银行卡!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alteView show];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
MCLog(@"fff");
// UIView * view = [self.view viewWithTag:718+indexPathd.row];
//
// view.backgroundColor = WHITECOLORS;
}else{
// UIView * view = [self.view viewWithTag:718+indexPathd.row];
//
// view.backgroundColor = WHITECOLORS;
[self removeBankCard];
}
}
-(void)removeBankCard{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
addBankModel * model = self.TvArray[indexPathd.row];
NSString * str = model.uuid;
MCLog(@"%@",str);
NSDictionary * Dic = [[NSDictionary alloc]init];
// Dic = @{@"page":[NSString stringWithFormat:@"%d",hospitalPage],@"searchType":@"2",@"countyID":_threeShowZoneStr};
Dic = @{@"uuid":str};
// MCLog(@"Dic==%@==",Dic);/gzz0617aft
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"text/json",@"application/json", nil];
// manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSString *LoginStr = [NSString stringWithFormat:DELBANKCARD];
LoginStr =[LoginStr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
MCLog(@"%@",LoginStr);
[manager POST: LoginStr parameters:Dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
{
MCLog(@"-------%@-------------",responseObject);
MCLog(@"1111");
if ([[responseObject objectForKey:@"code"] isEqualToString:@"1"]) {
[self showHint:[responseObject objectForKey:@"message"]];
[self tianjiaCard];
}else{
[self showHint:@"操作未成功!"];
}
}
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}];
}
- (NSDictionary *)clearBankData:(NSMutableDictionary *)dictionary{
NSMutableDictionary *bank = [[NSMutableDictionary alloc]initWithDictionary:dictionary];
NSArray *allay = [bank allKeys];
for (int i = 0; i < [allay count]; i ++) {
NSString *key = [allay objectAtIndex:i];
if ([[bank objectForKey:key]isKindOfClass:[NSNull class]]) {
bank[key]= @"";
}
}
return bank;
}
@end