RebateDetailsViewController.m 7.7 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11
//
//  RebateDetailsViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/8/28.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "RebateDetailsViewController.h"
#import "RebateSuccessTableViewController.h"

曹云霄's avatar
曹云霄 committed
12
@interface RebateDetailsViewController ()<UITextFieldDelegate>
曹云霄's avatar
曹云霄 committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

/**
 *  输入提现金额
 */
@property (weak, nonatomic) IBOutlet UITextField *inputRebateTextField;

/**
 *  本次申请的UUID
 */
@property (nonatomic,copy) NSString *applyUUID;


@end

@implementation RebateDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];

曹云霄's avatar
曹云霄 committed
32
    self.inputRebateTextField.placeholder = [NSString stringWithFormat:@"当前可提现:%.2f",self.rebateAmount];
曹云霄's avatar
曹云霄 committed
33 34 35 36 37
}

- (IBAction)rebateButtonClickAction:(UIButton *)sender {
    
    WS(weakSelf);
38
    if ([[self class]isBlankString:self.inputRebateTextField.text]) {
曹云霄's avatar
曹云霄 committed
39
        [XBLoadingView showHUDViewWithText:@"请输入提现金额"];return;
曹云霄's avatar
曹云霄 committed
40
    }
曹云霄's avatar
曹云霄 committed
41
    if ([self.inputRebateTextField.text floatValue] > self.rebateAmount) {
曹云霄's avatar
曹云霄 committed
42
        [XBLoadingView showHUDViewWithText:@"当前账户余额不足"];return;
曹云霄's avatar
曹云霄 committed
43
    }
曹云霄's avatar
曹云霄 committed
44
    if ([self.inputRebateTextField.text floatValue] <= 0) {
曹云霄's avatar
曹云霄 committed
45
        [XBLoadingView showHUDViewWithText:@"格式不正确"];return;
曹云霄's avatar
曹云霄 committed
46 47
    }
    if ([self includeChinese:self.inputRebateTextField.text]) {
曹云霄's avatar
曹云霄 committed
48
        [XBLoadingView showHUDViewWithText:@"格式不正确"];return;
曹云霄's avatar
曹云霄 committed
49
    }
曹云霄's avatar
曹云霄 committed
50 51
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:[NSString stringWithFormat:@"请确认提现金额:%@元",self.inputRebateTextField.text] preferredStyle:UIAlertControllerStyleAlert];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
52
        
曹云霄's avatar
曹云霄 committed
53
        [XBLoadingView showHUDViewWithDefault];
54 55 56 57 58 59
        ApplyRequest *withdrawal = [[ApplyRequest alloc] init];
        withdrawal.amount = [NSNumber numberWithFloat:[self.inputRebateTextField.text floatValue]];
        withdrawal.billType = nil;
        withdrawal.bankCardNumber = @"";
        
        [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(WITHDRAWAL) WithRequestType:ZERO WithParameter:withdrawal WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
60
            [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
61 62 63 64 65
            if ([returnValue[@"code"] isEqualToNumber:@0]) {
                weakSelf.applyUUID = returnValue[@"data"];
                [weakSelf rebateApplySuccess];
            }else
            {
曹云霄's avatar
曹云霄 committed
66
                [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
曹云霄's avatar
曹云霄 committed
67
            }
68 69
            
        } WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
70 71
            [XBLoadingView hideHUDViewWithDefault];
            [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
72
        }];
73 74
        
        
曹云霄's avatar
曹云霄 committed
75 76 77 78 79 80 81 82 83 84
    }]];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }]];
    [self presentViewController:alertVC animated:YES completion:nil];
}

#pragma mark - 提现申请成功
- (void)rebateApplySuccess
{
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
85
    RebateSuccessTableViewController *success = [[[self class]getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"RebateSuccessTableViewController"];
曹云霄's avatar
曹云霄 committed
86
    success.titleArray = @[@"提现申请已提交,审核中",@"查看详情",@"返回账户"];
曹云霄's avatar
曹云霄 committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    [success setClickEvent:^(NSIndexPath *indexPath) {
        if (indexPath.row == 1) {
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }else if (indexPath.row == 0)
        {
            [weakSelf queryDetails];
        }
    }];
    success.preferredContentSize = CGSizeMake(315, 320);
    success.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = success.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = success.view;
    [self presentViewController:success animated:YES completion:nil];
}

#pragma mark - 查询详情
- (void)queryDetails
{
曹云霄's avatar
曹云霄 committed
106
    [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
107 108
    WS(weakSelf);
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",WITHDRAWALPROGRESSDETAILS,self.applyUUID];
109
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:SERVERREQUESTURL(urlString)  WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
110
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
111 112 113 114 115 116 117 118
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            TOApplyBillEntity *result = [[TOApplyBillEntity alloc]initWithDictionary:returnValue[@"data"] error:nil];
            [weakSelf.navigationController popViewControllerAnimated:NO];
            if (weakSelf.showApplyDetails) {
                weakSelf.showApplyDetails(result);
            }
        }else
        {
曹云霄's avatar
曹云霄 committed
119
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
曹云霄's avatar
曹云霄 committed
120
        }
121
    }WithFailureBlock:^(NSError *error) {
122
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
123
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
124 125 126
    }];
}

曹云霄's avatar
曹云霄 committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
#pragma mark - <UITextFieldDelegate>
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSScanner      *scanner    = [NSScanner scannerWithString:string];
    NSCharacterSet *numbers;
    NSRange         pointRange = [textField.text rangeOfString:@"."];
    if ( (pointRange.length > 0) && (pointRange.location < range.location  || pointRange.location > range.location + range.length) ){
        numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    }else{
        numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
    }
    if ( [textField.text isEqualToString:@""] && [string isEqualToString:@"."] ){
        return NO;
    }
    short remain = 2; //保留 number位小数
    NSString *tempStr = [textField.text stringByAppendingString:string];
    NSUInteger strlen = [tempStr length];
    if(pointRange.length > 0 && pointRange.location > 0){ //判断输入框内是否含有“.”。
        if([string isEqualToString:@"."]){ //当输入框内已经含有“.”时,如果再输入“.”则被视为无效。
            return NO;
        }
        if(strlen > 0 && (strlen - pointRange.location) > remain+1){ //当输入框内已经含有“.”,当字符串长度减去小数点前面的字符串长度大于需要要保留的小数点位数,则视当次输入无效。
            return NO;
        }
    }
152 153
    NSRange ZERORange = [textField.text rangeOfString:@"0"];
    if(ZERORange.length == 1 && ZERORange.location == 0){ //判断输入框第一个字符是否为“0”
曹云霄's avatar
曹云霄 committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
        if(![string isEqualToString:@"0"] && ![string isEqualToString:@"."] && [textField.text length] == 1){ //当输入框只有一个字符并且字符为“0”时,再输入不为“0”或者“.”的字符时,则将此输入替换输入框的这唯一字符。
            textField.text = string;
            return NO;
        }else{
            if(pointRange.length == 0 && pointRange.location > 0){ //当输入框第一个字符为“0”时,并且没有“.”字符时,如果当此输入的字符为“0”,则视当此输入无效。
                if([string isEqualToString:@"0"]){
                    return NO;
                }
            }
        }
    }
    NSString *buffer;
    if ( ![scanner scanCharactersFromSet:numbers intoString:&buffer] && ([string length] != 0) ){
        return NO;
    }else{
        return YES;
    }
}

#pragma mark - 判断是否是汉字
- (BOOL)includeChinese:(NSString *)string
{
    for(int i=0; i< [string length];i++)
    {
        int a =[string characterAtIndex:i];
        if( a >0x4e00&& a <0x9fff){
            return YES;
        }
    }
    return NO;
}

曹云霄's avatar
曹云霄 committed
186
@end