JXTransferViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. //
  2. // JXTransferViewController.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2019/3/1.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXTransferViewController.h"
  9. #import "UIImage+Color.h"
  10. #import "JXVerifyPayVC.h"
  11. #import "JXPayPasswordVC.h"
  12. #define drawMarginX 25
  13. #define bgWidth JX_SCREEN_WIDTH-15*2
  14. #define drawHei 60
  15. @interface JXTransferViewController () <UITextFieldDelegate,UITextViewDelegate,UIScrollViewDelegate>
  16. @property (nonatomic, strong) UITextField * countTextField;
  17. @property (nonatomic, strong) UIButton *transferBtn;
  18. @property (nonatomic, strong) UILabel *addDscLab;
  19. @property (nonatomic, strong) UILabel *dscLab;
  20. @property (nonatomic, strong) NSString *desContent;
  21. @property (nonatomic, strong) JXVerifyPayVC *verVC;
  22. @property (nonatomic, strong) UIView *bigView;
  23. @property (nonatomic, strong) UIView *baseView;
  24. @property (nonatomic, strong) UIView *topView;
  25. @property (nonatomic, strong) UILabel *replayTitle;
  26. @property (nonatomic, strong) UITextField *replayTextField;
  27. @end
  28. @implementation JXTransferViewController
  29. - (instancetype)init {
  30. if (self = [super init]) {
  31. self.heightHeader = JX_SCREEN_TOP;
  32. self.heightFooter = 0;
  33. self.isGotoBack = YES;
  34. [self createHeadAndFoot];
  35. [self setupViews];
  36. [self setupReplayView];
  37. }
  38. return self;
  39. }
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. self.title = Localized(@"JX_Transfer");
  43. }
  44. - (void)setupViews {
  45. self.tableBody.backgroundColor = HEXCOLOR(0xF2F2F2);
  46. UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(15, 15, JX_SCREEN_WIDTH-30, 275)];
  47. baseView.backgroundColor = [UIColor whiteColor];
  48. baseView.layer.cornerRadius = 3.f;
  49. baseView.layer.masksToBounds = YES;
  50. [self.tableBody addSubview:baseView];
  51. UILabel *trLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 15, 60, 16)];
  52. trLab.text =@"转账给";
  53. trLab.font = SYSFONT(16);
  54. [baseView addSubview:trLab];
  55. UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(baseView.frame.size.width-20-20, 10, 20, 20)];
  56. icon.layer.masksToBounds = YES;
  57. icon.layer.cornerRadius = icon.frame.size.width/2;
  58. [baseView addSubview:icon];
  59. NSString *name = _user.remarkName.length > 0 ? _user.remarkName : _user.userNickname;
  60. [g_server getHeadImageLarge:_user.userId userName:name imageView:icon];
  61. CGSize size = [name sizeWithAttributes:@{NSFontAttributeName:SYSFONT(15)}];
  62. UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(baseView.frame.size.width-40-15-size.width, 12, size.width, size.height)];
  63. nameLabel.font = SYSFONT(15);
  64. nameLabel.text = name;
  65. [baseView addSubview:nameLabel];
  66. UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(trLab.frame)+15, baseView.frame.size.width-20, LINE_WH)];
  67. topLine.backgroundColor = THE_LINE_COLOR;
  68. [baseView addSubview:topLine];
  69. UILabel * cashTitle = [UIFactory createLabelWith:CGRectMake(20, CGRectGetMaxY(topLine.frame)+19, 120, 15) text:Localized(@"JX_TransferAmount")];
  70. cashTitle.font = SYSFONT(15);
  71. [baseView addSubview:cashTitle];
  72. UILabel * rmbLabel = [UIFactory createLabelWith:CGRectMake(20, CGRectGetMaxY(cashTitle.frame)+54, 17, 22) text:@"¥"];
  73. rmbLabel.font = SYSFONT(22);
  74. rmbLabel.textAlignment = NSTextAlignmentLeft;
  75. [baseView addSubview:rmbLabel];
  76. _countTextField = [UIFactory createTextFieldWithRect:CGRectMake(CGRectGetMaxX(rmbLabel.frame)+15, CGRectGetMaxY(cashTitle.frame)+46, JX_SCREEN_WIDTH-95, 32) keyboardType:UIKeyboardTypeDecimalPad secure:NO placeholder:nil font:[UIFont boldSystemFontOfSize:45] color:[UIColor blackColor] delegate:self];
  77. _countTextField.borderStyle = UITextBorderStyleNone;
  78. _countTextField.font = SYSFONT(30);
  79. [_countTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  80. [baseView addSubview:_countTextField];
  81. UIView * line = [[UIView alloc] init];
  82. line.frame = CGRectMake(drawMarginX, CGRectGetMaxY(_countTextField.frame)+5, bgWidth-drawMarginX*2, LINE_WH);
  83. line.backgroundColor = THE_LINE_COLOR;
  84. [baseView addSubview:line];
  85. _transferBtn = [UIFactory createButtonWithRect:CGRectZero title:Localized(@"JX_Transfer") titleFont:g_factory.font15 titleColor:[UIColor whiteColor] normal:nil selected:nil selector:@selector(transferBtnAction:) target:self];
  86. _transferBtn.tag = 1000;
  87. _transferBtn.frame = CGRectMake(20, CGRectGetMaxY(rmbLabel.frame)+30, baseView.frame.size.width-40, 43);
  88. [_transferBtn setBackgroundImage:[UIImage createImageWithColor:THEMECOLOR] forState:UIControlStateNormal];
  89. [_transferBtn setBackgroundImage:[UIImage createImageWithColor:[THEMECOLOR colorWithAlphaComponent:0.8f]] forState:UIControlStateDisabled];
  90. _transferBtn .layer.cornerRadius = 7;
  91. _transferBtn.clipsToBounds = YES;
  92. _transferBtn.enabled = NO;
  93. //转账说明内容
  94. _dscLab = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(_transferBtn.frame)+15, 0, 0)];
  95. _dscLab.font = SYSFONT(13);
  96. [baseView addSubview:_dscLab];
  97. // 添加转账说明
  98. _addDscLab = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(_transferBtn.frame)+15, 120, 18)];
  99. _addDscLab.text = Localized(@"JX_AddTransferInstructions");
  100. _addDscLab.textColor = HEXCOLOR(0x6E7B8F);
  101. _addDscLab.userInteractionEnabled = YES;
  102. _addDscLab.font = SYSFONT(13);
  103. [baseView addSubview:_addDscLab];
  104. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showSendTransferDsc)];
  105. [_addDscLab addGestureRecognizer:tap];
  106. [baseView addSubview:_transferBtn];
  107. }
  108. - (void)setupReplayView {
  109. int height = 44;
  110. self.bigView = [[UIView alloc] initWithFrame:self.view.bounds];
  111. self.bigView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
  112. self.bigView.hidden = YES;
  113. [g_App.window addSubview:self.bigView];
  114. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard)];
  115. [self.bigView addGestureRecognizer:tap];
  116. self.baseView = [[UIView alloc] initWithFrame:CGRectMake(40, JX_SCREEN_HEIGHT/4-.5, JX_SCREEN_WIDTH-80, 162.5)];
  117. self.baseView.backgroundColor = [UIColor whiteColor];
  118. self.baseView.layer.masksToBounds = YES;
  119. self. baseView.layer.cornerRadius = 4.0f;
  120. [self.bigView addSubview:self.baseView];
  121. int n = 20;
  122. _replayTitle = [[UILabel alloc] initWithFrame:CGRectMake(INSETS, n, self.baseView.frame.size.width - INSETS*2, 20)];
  123. _replayTitle.lineBreakMode = NSLineBreakByTruncatingTail;
  124. _replayTitle.textAlignment = NSTextAlignmentCenter;
  125. _replayTitle.textColor = HEXCOLOR(0x333333);
  126. _replayTitle.font = [UIFont boldSystemFontOfSize:17];
  127. _replayTitle.text = Localized(@"JX_TransferInstructions");
  128. [self.baseView addSubview:_replayTitle];
  129. n = n + height;
  130. self.replayTextField = [self createTextField:self.baseView default:nil hint:nil];
  131. self.replayTextField.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1];
  132. self.replayTextField.frame = CGRectMake(10, n, self.baseView.frame.size.width - INSETS*2, 35.5);
  133. self.replayTextField.delegate = self;
  134. self.replayTextField.textColor = HEXCOLOR(0x595959);
  135. self.replayTextField.placeholder = Localized(@"JX_Maximum10Words");
  136. [self.replayTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  137. n = n + INSETS + height;
  138. self.topView = [[UIView alloc] initWithFrame:CGRectMake(0, n, self.baseView.frame.size.width, 44)];
  139. [self.baseView addSubview:self.topView];
  140. // 两条线
  141. UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.baseView.frame.size.width, LINE_WH)];
  142. topLine.backgroundColor = THE_LINE_COLOR;
  143. [self.topView addSubview:topLine];
  144. UIView *botLine = [[UIView alloc] initWithFrame:CGRectMake(self.baseView.frame.size.width/2, 0, LINE_WH, self.topView.frame.size.height)];
  145. botLine.backgroundColor = THE_LINE_COLOR;
  146. [self.topView addSubview:botLine];
  147. // 取消
  148. UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(topLine.frame), self.baseView.frame.size.width/2, botLine.frame.size.height)];
  149. [cancelBtn setTitle:Localized(@"JX_Cencal") forState:UIControlStateNormal];
  150. [cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  151. [cancelBtn.titleLabel setFont:SYSFONT(15)];
  152. [cancelBtn addTarget:self action:@selector(hideBigView) forControlEvents:UIControlEventTouchUpInside];
  153. [self.topView addSubview:cancelBtn];
  154. // 确定
  155. UIButton *sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.baseView.frame.size.width/2, CGRectGetMaxY(topLine.frame), self.baseView.frame.size.width/2, botLine.frame.size.height)];
  156. [sureBtn setTitle:Localized(@"JX_Confirm") forState:UIControlStateNormal];
  157. [sureBtn setTitleColor:HEXCOLOR(0x55BEB8) forState:UIControlStateNormal];
  158. [sureBtn.titleLabel setFont:SYSFONT(15)];
  159. [sureBtn addTarget:self action:@selector(onRelease) forControlEvents:UIControlEventTouchUpInside];
  160. [self.topView addSubview:sureBtn];
  161. }
  162. - (void)hideBigView {
  163. [self resignKeyBoard];
  164. }
  165. - (void)onRelease {
  166. [self resignKeyBoard];
  167. self.desContent = _replayTextField.text;
  168. _dscLab.text = self.desContent;
  169. _addDscLab.text = self.desContent.length > 0 ? Localized(@"JX_Modify") : Localized(@"JX_AddTransferInstructions");
  170. CGSize size = [self.desContent sizeWithAttributes:@{NSFontAttributeName:SYSFONT(17)}];
  171. _dscLab.frame = CGRectMake(drawMarginX, _dscLab.frame.origin.y, size.width, 18);
  172. _addDscLab.frame = CGRectMake(CGRectGetMaxX(_dscLab.frame)+5, _addDscLab.frame.origin.y, 120, 18);
  173. }
  174. #pragma mark - 转账
  175. - (void)transferBtnAction:(UIButton *)button {
  176. // if ([_countTextField.text doubleValue] > g_App.myMoney) {
  177. // [g_App showAlert:Localized(@"CREDIT_LOW")];
  178. // return;
  179. // }
  180. if ([g_server.myself.isPayPassword boolValue]) {
  181. self.verVC = [JXVerifyPayVC alloc];
  182. self.verVC.type = JXVerifyTypeTransfer;
  183. self.verVC.RMB = self.countTextField.text;
  184. self.verVC.delegate = self;
  185. self.verVC.didDismissVC = @selector(dismissVerifyPayVC);
  186. self.verVC.didVerifyPay = @selector(didVerifyPay:);
  187. self.verVC = [self.verVC init];
  188. [self.view addSubview:self.verVC.view];
  189. } else {
  190. JXPayPasswordVC *payPswVC = [JXPayPasswordVC alloc];
  191. payPswVC.type = JXPayTypeSetupPassword;
  192. payPswVC.enterType = JXEnterTypeTransfer;
  193. payPswVC = [payPswVC init];
  194. [g_navigation pushViewController:payPswVC animated:YES];
  195. }
  196. }
  197. - (void)didVerifyPay:(NSString *)sender {
  198. long time = (long)[[NSDate date] timeIntervalSince1970];
  199. time = (time *1000 + g_server.timeDifference)/1000;
  200. NSString *secret = [self getSecretWithText:sender time:time];
  201. // 参数顺序不能变,先放key再放value
  202. NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"toUserId",_user.userId,@"money",_countTextField.text,@"remark",_replayTextField.text, nil];
  203. [g_payServer payServerWithAction:act_sendTransferV1 param:arr payPassword:sender time:time toView:self];
  204. // [g_server transferUserId:_user.userId money:_countTextField.text remark:_replayTextField.text time:time secret:secret toView:self];
  205. }
  206. - (void)dismissVerifyPayVC {
  207. [self.verVC.view removeFromSuperview];
  208. }
  209. - (void)showSendTransferDsc{
  210. self.bigView.hidden = NO;
  211. [self.replayTextField becomeFirstResponder];
  212. }
  213. - (void)textFieldDidChange:(UITextField *)textField {
  214. if (textField == _countTextField) {
  215. if ([textField.text doubleValue] > 0) {
  216. _transferBtn.enabled = YES;
  217. }else {
  218. _transferBtn.enabled = NO;
  219. }
  220. }
  221. // if (textField == _replayTextField) {
  222. // if (textField.text.length > 10) {
  223. // textField.text = [textField.text substringToIndex:10];
  224. // }
  225. // }
  226. }
  227. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  228. NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  229. if (textField == _countTextField) {
  230. // 首位不能输入 .
  231. if (IsStringNull(textField.text) && [string isEqualToString:@"."]) {
  232. return NO;
  233. }
  234. //限制.后面最多有两位,且不能再输入.
  235. if ([textField.text rangeOfString:@"."].location != NSNotFound) {
  236. //有.了 且.后面输入了两位 停止输入
  237. if (toBeString.length > [toBeString rangeOfString:@"."].location+3) {
  238. return NO;
  239. }
  240. //有.了,不允许再输入.
  241. if ([string isEqualToString:@"."]) {
  242. return NO;
  243. }
  244. }
  245. //限制首位0,后面只能输入. 和 删除
  246. if ([textField.text isEqualToString:@"0"]) {
  247. if (![string isEqualToString:@"."] && ![string isEqualToString:@""]) {
  248. return NO;
  249. }
  250. }
  251. //限制只能输入:1234567890.
  252. NSCharacterSet * characterSet = [[NSCharacterSet characterSetWithCharactersInString:@"1234567890."] invertedSet];
  253. NSString * filtered = [[string componentsSeparatedByCharactersInSet:characterSet] componentsJoinedByString:@""];
  254. return [string isEqualToString:filtered];
  255. }
  256. if (textField == self.replayTextField) {
  257. if (toBeString.length > 10) {
  258. return NO;
  259. }
  260. }
  261. return YES;
  262. }
  263. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  264. if( [aDownload.action isEqualToString:act_sendTransfer] || [aDownload.action isEqualToString:act_sendTransferV1]){
  265. [self dismissVerifyPayVC]; // 销毁支付密码界面
  266. if (self.delegate && [self.delegate respondsToSelector:@selector(transferToUser:)]) {
  267. [self.delegate performSelector:@selector(transferToUser:) withObject:dict];
  268. }
  269. [self actionQuit];
  270. }
  271. }
  272. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  273. [_wait stop];
  274. if ([aDownload.action isEqualToString:act_TransactionGetCode] || [aDownload.action isEqualToString:act_sendTransferV1]) {
  275. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  276. [self.verVC clearUpPassword];
  277. });
  278. }
  279. return show_error;
  280. }
  281. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  282. [_wait stop];
  283. return show_error;
  284. }
  285. -(void) didServerConnectStart:(JXConnection*)aDownload{
  286. [_wait start];
  287. }
  288. - (void)resignKeyBoard {
  289. self.bigView.hidden = YES;
  290. [self hideKeyBoard];
  291. [self resetBigView];
  292. }
  293. - (void)resetBigView {
  294. self.replayTextField.frame = CGRectMake(10, 64, self.baseView.frame.size.width - INSETS*2, 35.5);
  295. self.baseView.frame = CGRectMake(40, JX_SCREEN_HEIGHT/4-.5, JX_SCREEN_WIDTH-80, 162.5);
  296. self.topView.frame = CGRectMake(0, 118, self.baseView.frame.size.width, 40);
  297. }
  298. - (void)hideKeyBoard {
  299. if (self.replayTextField.isFirstResponder) {
  300. [self.replayTextField resignFirstResponder];
  301. }
  302. }
  303. -(UITextField*)createTextField:(UIView*)parent default:(NSString*)s hint:(NSString*)hint{
  304. UITextField* p = [[UITextField alloc] initWithFrame:CGRectMake(0,INSETS,JX_SCREEN_WIDTH,54)];
  305. p.delegate = self;
  306. p.autocorrectionType = UITextAutocorrectionTypeNo;
  307. p.autocapitalizationType = UITextAutocapitalizationTypeNone;
  308. p.enablesReturnKeyAutomatically = YES;
  309. p.textAlignment = NSTextAlignmentLeft;
  310. p.userInteractionEnabled = YES;
  311. p.backgroundColor = [UIColor whiteColor];
  312. p.text = s;
  313. p.font = g_factory.font16;
  314. [parent addSubview:p];
  315. return p;
  316. }
  317. - (NSString *)getSecretWithText:(NSString *)text time:(long)time {
  318. NSMutableString *str1 = [NSMutableString string];
  319. [str1 appendString:APIKEY];
  320. [str1 appendString:[NSString stringWithFormat:@"%ld",time]];
  321. [str1 appendString:[NSString stringWithFormat:@"%@",[NSNumber numberWithDouble:[_countTextField.text doubleValue]]]];
  322. str1 = [[g_server getMD5String:str1] mutableCopy];
  323. [str1 appendString:g_myself.userId];
  324. [str1 appendString:g_server.access_token];
  325. NSMutableString *str2 = [NSMutableString string];
  326. str2 = [[g_server getMD5String:text] mutableCopy];
  327. [str1 appendString:str2];
  328. str1 = [[g_server getMD5String:str1] mutableCopy];
  329. return [str1 copy];
  330. }
  331. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  332. if (scrollView == self.tableBody) {
  333. if ([self.countTextField isFirstResponder]) {
  334. [self.countTextField resignFirstResponder];
  335. }
  336. }
  337. }
  338. @end