|
@@ -0,0 +1,257 @@
|
|
1
|
+//
|
|
2
|
+// ORCHMoneyRecord2ChildViewController.m
|
|
3
|
+// KXCardHelp
|
|
4
|
+//
|
|
5
|
+// Created by jcymac on 2018/9/7.
|
|
6
|
+// Copyright © 2018年 jcymac. All rights reserved.
|
|
7
|
+//
|
|
8
|
+
|
|
9
|
+#import "ORCHMoneyRecord2ChildViewController.h"
|
|
10
|
+#import "NewHomeModel.h"
|
|
11
|
+@interface ORCHMoneyRecord2ChildViewController ()
|
|
12
|
+<
|
|
13
|
+UITableViewDelegate,
|
|
14
|
+UITableViewDataSource,
|
|
15
|
+UITextFieldDelegate
|
|
16
|
+>
|
|
17
|
+@property(nonatomic,strong)UIButton *addBtn;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+@property(nonatomic,strong)UITableView *tableView;
|
|
21
|
+@end
|
|
22
|
+
|
|
23
|
+@implementation ORCHMoneyRecord2ChildViewController
|
|
24
|
+
|
|
25
|
+- (void)viewDidLoad {
|
|
26
|
+ [super viewDidLoad];
|
|
27
|
+ [self.navigationBar setNavTitle:@"信用卡管理"];
|
|
28
|
+ self.navigationBar.showNavigationBarBottomLine=YES;
|
|
29
|
+ [self initUI];
|
|
30
|
+ [self adjustUI];
|
|
31
|
+}
|
|
32
|
+
|
|
33
|
+-(void)viewWillAppear:(BOOL)animated{
|
|
34
|
+ [super viewWillAppear:animated];
|
|
35
|
+ NSArray *arr=[[YDFMDB sharedInstance]selectDataByConditionString:nil withSelectStringArray:@[@"cardBankName",@"cardCode",@"dayStr"] withTableName:@"homeTable" limit:-1 descID:YES];
|
|
36
|
+ [self.dataArray removeAllObjects];
|
|
37
|
+ for (NSDictionary *dic in arr) {
|
|
38
|
+ NSLog(@"dic--%@",dic);
|
|
39
|
+ NewHomeModel *model=[[NewHomeModel alloc]init];
|
|
40
|
+ model.cardBankName=dic[@"cardBankName"];
|
|
41
|
+ model.cardCode=dic[@"cardCode"];
|
|
42
|
+ model.dayStr=dic[@"dayStr"];
|
|
43
|
+ [self.dataArray addObject:model];
|
|
44
|
+ }
|
|
45
|
+ [self.tableView reloadData];
|
|
46
|
+}
|
|
47
|
+
|
|
48
|
+-(void)initUI{
|
|
49
|
+
|
|
50
|
+ [self.view addSubview:self.addBtn];
|
|
51
|
+ [self.view addSubview:self.tableView];
|
|
52
|
+}
|
|
53
|
+
|
|
54
|
+-(void)setChildType:(ChildType)childType{
|
|
55
|
+ self.addBtn.hidden=NO;
|
|
56
|
+
|
|
57
|
+}
|
|
58
|
+
|
|
59
|
+-(void)adjustUI{
|
|
60
|
+ [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
61
|
+ make.left.mas_equalTo(FITSIZE(12));
|
|
62
|
+ make.right.mas_equalTo((-FITSIZE(12)));
|
|
63
|
+ make.top.mas_equalTo(10+NavBarHeight);
|
|
64
|
+ make.height.mas_equalTo(44);
|
|
65
|
+ }];
|
|
66
|
+
|
|
67
|
+ UIButton *btn=[self.addBtn viewWithTag:10001];
|
|
68
|
+ [btn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
69
|
+ make.centerY.equalTo(self.addBtn.mas_centerY);
|
|
70
|
+ make.width.height.mas_equalTo(self.addBtn.mas_height);
|
|
71
|
+ make.right.mas_equalTo(0);
|
|
72
|
+ }];
|
|
73
|
+}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
79
|
+ NSInteger sum=self.dataArray.count<1?1:self.dataArray.count;
|
|
80
|
+ return sum;
|
|
81
|
+}
|
|
82
|
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
83
|
+ UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"NewHomeTableViewCell"];
|
|
84
|
+ cell.contentView.backgroundColor=self.view.backgroundColor;
|
|
85
|
+ if (self.dataArray.count>indexPath.row) {
|
|
86
|
+ @try{
|
|
87
|
+ [cell setValue:self.dataArray[indexPath.row] forKey:@"model"];
|
|
88
|
+ }@catch(NSException *e){
|
|
89
|
+ };
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ return cell;
|
|
93
|
+}
|
|
94
|
+
|
|
95
|
+-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
96
|
+ return 120;
|
|
97
|
+}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+#pragma mark -代理 UITextFieldDelegate
|
|
101
|
+- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
|
|
102
|
+
|
|
103
|
+ if ([@"" isEqualToString:string]) {
|
|
104
|
+ return YES;
|
|
105
|
+ }
|
|
106
|
+ if ([@"0123456789" rangeOfString:string].location!= NSNotFound) {
|
|
107
|
+ return YES;
|
|
108
|
+ }
|
|
109
|
+ if ([@"." isEqualToString:string]) {
|
|
110
|
+ if ([textField.text rangeOfString:@"."].location==NSNotFound) {
|
|
111
|
+ return YES;
|
|
112
|
+ }
|
|
113
|
+ }
|
|
114
|
+ return NO;
|
|
115
|
+}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+#pragma mark -懒加载
|
|
120
|
+-(UIButton *)addBtn{
|
|
121
|
+ if (!_addBtn) {
|
|
122
|
+ _addBtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
|
123
|
+ _addBtn.layer.cornerRadius=8;
|
|
124
|
+ _addBtn.layer.masksToBounds=YES;
|
|
125
|
+ _addBtn.backgroundColor=[UIColor whiteColor];
|
|
126
|
+// _addBtn.layer.borderWidth=1;
|
|
127
|
+// _addBtn.layer.borderColor=[UIColor baseColor].CGColor;
|
|
128
|
+ _addBtn.titleLabel.font=[UIFont systemFontOfSize:15];
|
|
129
|
+ [_addBtn setTitle:@"+添加信用卡还款记录" forState:UIControlStateNormal];
|
|
130
|
+ [_addBtn setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
|
|
131
|
+ WeakSelf(weakSelf)
|
|
132
|
+ [[_addBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id x) {
|
|
133
|
+ [weakSelf showBankCard:@"" bank:@"" weakSelf:weakSelf];
|
|
134
|
+ }];
|
|
135
|
+ UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
|
|
136
|
+ btn.tag=10001;
|
|
137
|
+ [btn setImage:[UIImage imageNamed:@"camera_orange"] forState:UIControlStateNormal];
|
|
138
|
+ [[btn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id x) {
|
|
139
|
+ [self bankCardOCROnline];
|
|
140
|
+ }];
|
|
141
|
+ btn.backgroundColor=[UIColor clearColor];
|
|
142
|
+ [_addBtn addSubview:btn];
|
|
143
|
+ }
|
|
144
|
+ return _addBtn;
|
|
145
|
+}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+-(void)showBankCard:(NSString *)bankCard bank:(NSString *)bank weakSelf:(ORCHMoneyRecord2ChildViewController *)weakSelf{
|
|
149
|
+ NSLog(@"+添加信用卡还款记录");
|
|
150
|
+ UIAlertController *addAlertVC = [UIAlertController alertControllerWithTitle:@"添加信用卡" message:@"" preferredStyle:UIAlertControllerStyleAlert];
|
|
151
|
+ [addAlertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
|
|
152
|
+ textField.placeholder = @"请输入信用卡所属银行";
|
|
153
|
+ textField.text=bank;
|
|
154
|
+ }];
|
|
155
|
+ [addAlertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
|
|
156
|
+ textField.placeholder = @"请输入卡号";
|
|
157
|
+ textField.delegate=weakSelf;
|
|
158
|
+ textField.text=bankCard;
|
|
159
|
+ textField.keyboardType=UIKeyboardTypeDecimalPad;
|
|
160
|
+ }];
|
|
161
|
+ [addAlertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
|
|
162
|
+ textField.placeholder = @"请输入还款日(0~28)";
|
|
163
|
+ textField.keyboardType=UIKeyboardTypeNumberPad;
|
|
164
|
+ }];
|
|
165
|
+
|
|
166
|
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
|
|
167
|
+ UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
168
|
+ NSString *cardBank=addAlertVC.textFields.firstObject.text;
|
|
169
|
+ NSString *cardCode=addAlertVC.textFields[1].text;
|
|
170
|
+ NSString *day=addAlertVC.textFields[2].text;
|
|
171
|
+ NSInteger dayInt=[day integerValue];
|
|
172
|
+ if (cardBank.length==0) {
|
|
173
|
+ [weakSelf homeShowMessage:@"您没有输入银行"];
|
|
174
|
+ }else if(cardCode.length<4){
|
|
175
|
+ [weakSelf homeShowMessage:@"卡号必须大于4位"];
|
|
176
|
+ }else if (dayInt<0||dayInt>28) {
|
|
177
|
+ [weakSelf homeShowMessage:@"还款日只能是数字,并且介于0~28之间"];
|
|
178
|
+ }else{
|
|
179
|
+ [weakSelf homeShowMessage:@"添加完成"];
|
|
180
|
+ NewHomeModel *model=[[NewHomeModel alloc]init];
|
|
181
|
+ model.cardBankName=cardBank;
|
|
182
|
+ model.cardCode=cardCode;
|
|
183
|
+ model.dayStr=[@(dayInt) stringValue];
|
|
184
|
+ [[YDFMDB sharedInstance]addSingleDataStringDictionary:@{@"cardBankName":model.cardBankName,@"cardCode":model.cardCode,@"dayStr":model.dayStr} withTableName:@"homeTable"];
|
|
185
|
+ [weakSelf.dataArray insertObject:model atIndex:0];
|
|
186
|
+ [weakSelf.tableView reloadData];
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ }];
|
|
190
|
+ //添加 取消事件 到 弹窗界面
|
|
191
|
+ [addAlertVC addAction:cancelAction];
|
|
192
|
+ [addAlertVC addAction:okAction];
|
|
193
|
+ [weakSelf.navigationController presentViewController:addAlertVC animated:NO completion:nil];
|
|
194
|
+}
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+#pragma mark -百度ocr
|
|
198
|
+- (void)bankCardOCROnline{
|
|
199
|
+ if(![PublicFunction isCanUseCamera]){
|
|
200
|
+ [self showMessage:@"没有相机权限,请前往设置开启"];
|
|
201
|
+ return;
|
|
202
|
+ }
|
|
203
|
+ WeakSelf(weakSelf)
|
|
204
|
+ UIViewController * vc =
|
|
205
|
+ [AipCaptureCardVC ViewControllerWithCardType:CardTypeBankCard andImageHandler:^(UIImage *image) {
|
|
206
|
+ [self dismissViewControllerAnimated:YES completion:nil];
|
|
207
|
+ [[AipOcrService shardService] detectBankCardFromImage:image successHandler:^(id result) {
|
|
208
|
+ if ([NSThread currentThread]!=[NSThread mainThread]) {
|
|
209
|
+ dispatch_sync(dispatch_get_main_queue(), ^{
|
|
210
|
+ if (result[@"result"]) {
|
|
211
|
+ if (result[@"result"][@"bank_name"]&&result[@"result"][@"bank_card_number"]) {
|
|
212
|
+ //银行名称
|
|
213
|
+ [weakSelf showBankCard:result[@"result"][@"bank_card_number"] bank:result[@"result"][@"bank_name"] weakSelf:weakSelf];
|
|
214
|
+ }
|
|
215
|
+ }
|
|
216
|
+
|
|
217
|
+ });
|
|
218
|
+ }else{
|
|
219
|
+ if (result[@"result"]) {
|
|
220
|
+ if (result[@"result"][@"bank_name"]&&result[@"result"][@"bank_card_number"]) {
|
|
221
|
+ //银行名称
|
|
222
|
+ [weakSelf showBankCard:result[@"result"][@"bank_card_number"] bank:result[@"result"][@"bank_name"] weakSelf:weakSelf];
|
|
223
|
+ }
|
|
224
|
+ }
|
|
225
|
+ }
|
|
226
|
+ } failHandler:^(NSError *err) {
|
|
227
|
+ [self showMessage:@"识别失败"];
|
|
228
|
+ }];
|
|
229
|
+ }];
|
|
230
|
+ [self presentViewController:vc animated:YES completion:nil];
|
|
231
|
+
|
|
232
|
+}
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+-(void)homeShowMessage:(NSString *)msg{
|
|
236
|
+ [MBProgressHUD showMessage:msg toView:self.view];
|
|
237
|
+}
|
|
238
|
+
|
|
239
|
+-(UITableView *)tableView{
|
|
240
|
+ if (!_tableView) {
|
|
241
|
+ _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64+NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-safeBottomHeight-NavBarHeight-64-50-NavBarHeight)];
|
|
242
|
+ _tableView.delegate=self;
|
|
243
|
+ _tableView.dataSource=self;
|
|
244
|
+ _tableView.backgroundColor=[UIColor CHColorWithHex:0xF6F7F9];
|
|
245
|
+ [_tableView registerNib:[UINib nibWithNibName:@"NewHomeTableViewCell" bundle:nil] forCellReuseIdentifier:@"NewHomeTableViewCell"];
|
|
246
|
+ _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
247
|
+ }
|
|
248
|
+ return _tableView;
|
|
249
|
+}
|
|
250
|
+
|
|
251
|
+-(NSMutableArray *)dataArray{
|
|
252
|
+ if (!_dataArray) {
|
|
253
|
+ _dataArray=[NSMutableArray array];
|
|
254
|
+ }
|
|
255
|
+ return _dataArray;
|
|
256
|
+}
|
|
257
|
+@end
|