create
This commit is contained in:
283
ShenQi/EditBankViewController.m
Normal file
283
ShenQi/EditBankViewController.m
Normal file
@@ -0,0 +1,283 @@
|
||||
//
|
||||
// EditBankViewController.m
|
||||
// ShenQi
|
||||
//
|
||||
// Created by Yao on 2024/11/8.
|
||||
//
|
||||
|
||||
#import "EditBankViewController.h"
|
||||
|
||||
#import <SVProgressHUD.h>
|
||||
#import <AdSupport/AdSupport.h>
|
||||
#import <AppTrackingTransparency/AppTrackingTransparency.h>
|
||||
|
||||
#import "DSTextField.h"
|
||||
#import "MacroDefine.h"
|
||||
#import "BankView.h"
|
||||
|
||||
#import "ViewController.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "DataModels.h"
|
||||
|
||||
@interface EditBankViewController () <UITextFieldDelegate>
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *realNameLabel;
|
||||
@property (weak, nonatomic) IBOutlet DSTextField *realNameTextField;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *bankCodeTitleLabel;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *bankCodeBtn;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *bankNameBtn;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *bankNOLabel;
|
||||
@property (weak, nonatomic) IBOutlet DSTextField *bankNOTextField;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray <BankModelData *>*bankArray;
|
||||
@property (nonatomic, strong) BankModelData *currentBank;
|
||||
@property (nonatomic, strong) NSString *inviteCode;
|
||||
|
||||
@property (nonatomic, strong) NSDictionary *bankdic;
|
||||
@property (nonatomic, strong) NSArray *codeArray;
|
||||
@property (nonatomic, strong) NSString *currentBankCode;
|
||||
|
||||
@end
|
||||
|
||||
@implementation EditBankViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
self.titleLabel.text = NSLocalizedString(@"EditBank", nil);
|
||||
self.realNameLabel.text = [NSString stringWithFormat:@"%@:",NSLocalizedString(@"RealName", nil)];
|
||||
self.bankCodeTitleLabel.text = [NSString stringWithFormat:@"%@:",NSLocalizedString(@"Area", nil)];
|
||||
self.bankNOLabel.text = [NSString stringWithFormat:@"%@:",NSLocalizedString(@"BankNO", nil)];
|
||||
|
||||
self.realNameTextField.delegate = self;
|
||||
self.realNameTextField.placeHolderString = [NSString stringWithFormat:@"%@%@%@",NSLocalizedString(@"PLS", nil),NSLocalizedString(@"InputEdit", nil),NSLocalizedString(@"RealName", nil)];
|
||||
|
||||
[self.bankCodeBtn addTarget:self action:@selector(chooseBankCodeAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||||
|
||||
[self.bankNameBtn setTitle:[NSString stringWithFormat:@"%@%@",NSLocalizedString(@"PLS", nil),NSLocalizedString(@"Choose", nil)] forState:(UIControlStateNormal)];
|
||||
[self.bankNameBtn addTarget:self action:@selector(chooseBankNameAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||||
|
||||
self.bankNOTextField.delegate = self;
|
||||
self.bankNOTextField.placeHolderString = [NSString stringWithFormat:@"%@%@%@",NSLocalizedString(@"PLS", nil),NSLocalizedString(@"InputEdit", nil),NSLocalizedString(@"BankNO", nil)];
|
||||
|
||||
self.confirmBtn.layer.cornerRadius = 20.f;
|
||||
self.confirmBtn.layer.masksToBounds = YES;
|
||||
[self.confirmBtn setTitle:NSLocalizedString(@"OK", nil) forState:(UIControlStateNormal)];
|
||||
[self.confirmBtn addTarget:self action:@selector(submitAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||||
|
||||
[self chooseBankName];
|
||||
|
||||
[self setupInviteCode];
|
||||
}
|
||||
|
||||
-(void)submitAction
|
||||
{
|
||||
NSString *realName = self.realNameTextField.text;
|
||||
NSString *bankName = self.bankNameBtn.titleLabel.text;
|
||||
NSString *bankNO = self.bankNOTextField.text;
|
||||
if (ISNULLSTR(realName)) {
|
||||
[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@%@%@",NSLocalizedString(@"PLS", nil),NSLocalizedString(@"InputEdit", nil),NSLocalizedString(@"RealName", nil)]];
|
||||
return;
|
||||
}else if (ISNULLSTR(bankName)) {
|
||||
[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@%@%@",NSLocalizedString(@"PLS", nil),NSLocalizedString(@"InputEdit", nil),NSLocalizedString(@"ReaBankNamelName", nil)]];
|
||||
return;
|
||||
}else if (ISNULLSTR(bankNO)) {
|
||||
[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@%@%@",NSLocalizedString(@"PLS", nil),NSLocalizedString(@"InputEdit", nil),NSLocalizedString(@"BankNO", nil)]];
|
||||
return;
|
||||
}
|
||||
[self setupWithDrawWithInviteCode:self.inviteCode];
|
||||
}
|
||||
|
||||
- (IBAction)dismissAction:(id)sender
|
||||
{
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
-(void)setupInviteCode
|
||||
{
|
||||
// 我的邀请码
|
||||
__block NSString *advertisingId = nil;
|
||||
if (@available(iOS 14, *)) {
|
||||
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
|
||||
advertisingId = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
|
||||
[self getCodeWithAdvertisingId:advertisingId];
|
||||
}];
|
||||
} else {
|
||||
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
|
||||
[self getCodeWithAdvertisingId:advertisingId];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)getCodeWithAdvertisingId:(NSString *)advertisingId
|
||||
{
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:InviteCodeURL]];
|
||||
request.HTTPMethod = @"POST";
|
||||
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
||||
|
||||
NSDictionary *parmas = @{@"userId":[NSNumber numberWithInteger:[VV88AUUserID integerValue]],@"deviceCode":advertisingId};
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parmas options:NSJSONWritingPrettyPrinted error:nil];
|
||||
request.HTTPBody = jsonData;
|
||||
|
||||
NSURLSession *session = [NSURLSession sharedSession];
|
||||
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (error == nil) {
|
||||
NSError *error;
|
||||
NSMutableDictionary *responseObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
|
||||
if (error == nil) {
|
||||
if (ISNULL(error) && !ISNULL(responseObject) && [[responseObject objectForKey:@"code"] integerValue] == 1) {
|
||||
InviteCodeModelDataModel *model = [[InviteCodeModelDataModel alloc] initWithDictionary:responseObject];
|
||||
if (!ISNULLSTR(model.data.inviteCode)) {
|
||||
self.inviteCode = model.data.inviteCode;
|
||||
self.realNameTextField.text = model.data.name;
|
||||
[self.bankNameBtn setTitle:model.data.bankName forState:(UIControlStateNormal)];
|
||||
self.bankNOTextField.text = model.data.bankNo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}];
|
||||
[dataTask resume];
|
||||
}
|
||||
|
||||
-(void)setupWithDrawWithInviteCode:(NSString *)inviteCode
|
||||
{
|
||||
NSString *realName = self.realNameTextField.text;
|
||||
NSString *bankName = self.bankNameBtn.titleLabel.text;
|
||||
NSString *bankNO = self.bankNOTextField.text;
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:WithdrawURL]];
|
||||
request.HTTPMethod = @"POST";
|
||||
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
||||
|
||||
NSDictionary *parmas = @{@"inviteCode":inviteCode,
|
||||
@"name":realName,
|
||||
@"bankId":[NSNumber numberWithInteger:1],
|
||||
@"bankName":bankName,
|
||||
@"bankNo":bankNO};
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parmas options:NSJSONWritingPrettyPrinted error:nil];
|
||||
request.HTTPBody = jsonData;
|
||||
|
||||
NSURLSession *session = [NSURLSession sharedSession];
|
||||
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (error == nil) {
|
||||
NSError *error;
|
||||
NSMutableDictionary *responseObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
|
||||
if (error == nil) {
|
||||
if (ISNULL(error) && !ISNULL(responseObject) && [[responseObject objectForKey:@"code"] integerValue] == 1) {
|
||||
[SVProgressHUD showSuccessWithStatus:nil];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self dismissAction:nil];
|
||||
});
|
||||
}else{
|
||||
NSString *errmsg = [responseObject objectForKey:@"error"];
|
||||
[SVProgressHUD showInfoWithStatus:errmsg];
|
||||
}
|
||||
}else{
|
||||
NSString *errmsg = [responseObject objectForKey:@"message"];
|
||||
[SVProgressHUD showInfoWithStatus:errmsg];
|
||||
}
|
||||
}
|
||||
});
|
||||
}];
|
||||
[dataTask resume];
|
||||
}
|
||||
|
||||
-(void)chooseBankCodeAction
|
||||
{
|
||||
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||||
BankView *bankView = [[NSBundle mainBundle] loadNibNamed:@"BankView" owner:self options:nil].firstObject;
|
||||
bankView.frame = appdelegate.window.bounds;
|
||||
bankView.chooseType = 0;
|
||||
bankView.bankdic = self.bankdic;
|
||||
bankView.currentBankCode = self.currentBankCode;
|
||||
bankView.selectedCompleteBlock = ^(id _Nonnull code) {
|
||||
self.currentBankCode = code;
|
||||
[self.bankCodeBtn setTitle:[NSString stringWithFormat:@"%@",self.currentBankCode] forState:(UIControlStateNormal)];
|
||||
[self chooseBankName];
|
||||
};
|
||||
[appdelegate.window addSubview:bankView];
|
||||
}
|
||||
|
||||
-(void)chooseBankNameAction
|
||||
{
|
||||
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||||
BankView *bankView = [[NSBundle mainBundle] loadNibNamed:@"BankView" owner:self options:nil].firstObject;
|
||||
bankView.frame = appdelegate.window.bounds;
|
||||
bankView.chooseType = 1;
|
||||
bankView.bankdic = self.bankdic;
|
||||
bankView.currentBankCode = self.currentBankCode;
|
||||
bankView.selectedCompleteBlock = ^(id _Nonnull code) {
|
||||
self.currentBank = code;
|
||||
[self.bankNameBtn setTitle:self.currentBank.bankName forState:(UIControlStateNormal)];
|
||||
};
|
||||
[appdelegate.window addSubview:bankView];
|
||||
}
|
||||
|
||||
-(void)chooseBankName
|
||||
{
|
||||
if (ISNULL(self.bankdic)) {
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?code=%@",WithdrawBanksURL,self.currentBankCode]]];
|
||||
request.HTTPMethod = @"GET";
|
||||
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
||||
|
||||
NSURLSession *session = [NSURLSession sharedSession];
|
||||
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (error) {
|
||||
[SVProgressHUD showInfoWithStatus:error.localizedDescription];
|
||||
}else{
|
||||
NSError *error;
|
||||
NSMutableDictionary *responseObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
|
||||
if (error) {
|
||||
[SVProgressHUD showInfoWithStatus:error.localizedDescription];
|
||||
}else{
|
||||
if (ISNULL(error) && !ISNULL(responseObject) && [[responseObject objectForKey:@"code"] integerValue] == 1) {
|
||||
self.bankdic = [responseObject objectForKey:@"data"];
|
||||
if (!ISNULL(self.bankdic)) {
|
||||
self.codeArray = [NSArray arrayWithArray:self.bankdic.allKeys];
|
||||
if (!ISNULLARRAY(self.codeArray)) {
|
||||
self.currentBankCode = self.codeArray.firstObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}];
|
||||
[dataTask resume];
|
||||
}else{
|
||||
self.bankArray = @[].mutableCopy;
|
||||
NSArray *bankArray = [self.bankdic objectForKey:self.currentBankCode];
|
||||
for (NSDictionary *bankdic in bankArray) {
|
||||
BankModelData *bank = [[BankModelData alloc] initWithDictionary:bankdic];
|
||||
[self.bankArray addObject:bank];
|
||||
}
|
||||
if (!ISNULLARRAY(self.bankArray)) {
|
||||
self.currentBank = self.bankArray.firstObject;
|
||||
[self.bankNameBtn setTitle:self.currentBank.bankName forState:(UIControlStateNormal)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
[self.view endEditing:YES];
|
||||
}
|
||||
|
||||
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
|
||||
{
|
||||
textField.clearButtonMode = UITextFieldViewModeAlways;
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(void)textFieldDidEndEditing:(UITextField *)textField
|
||||
{
|
||||
textField.clearButtonMode = UITextFieldViewModeNever;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user