AddClientInputVC.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. //
  2. // AddClientInputVC.m
  3. // shiku_im
  4. //
  5. // Created by huangyp-pc on 16/7/26.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "AddClientInputVC.h"
  9. #import "AFNetworking.h"
  10. #import "SalemanSelectVC.h"
  11. #import "PaymentsVC.h"
  12. #import "ClientKindVC.h"
  13. #import "CurrencyVC.h"
  14. #import "ShareSelectVC.h"
  15. @interface AddClientInputVC ()<UITextFieldDelegate,UITextViewDelegate,UIScrollViewDelegate>
  16. @property (nonatomic,strong) UIScrollView *scrollV;
  17. @property (nonatomic,assign) NSInteger rows;
  18. @end
  19. @implementation AddClientInputVC
  20. {
  21. UITextField *_clientCode; //客户编号
  22. UITextField *_clientName; //客户名称
  23. UITextField *_shortName; //简称
  24. UITextField *_addressName; //客户地址
  25. UITextField *_clientKind; //客户类型
  26. UITextField *_belongWhere; //所属地区
  27. UITextField *_getMoneyKind; //收款方式
  28. UITextField *_saleMan; //业务员
  29. UITextField *_contactMan; //联系人
  30. UITextField *_position; //岗位
  31. UITextField *_contactTel; //电话
  32. UITextField *_email; //邮箱
  33. UITextView *_remark;//备注
  34. NSString *_code; //单据编号
  35. NSString *_cuid; //单据id
  36. NSMutableArray *_clientKindArr;//客户类型
  37. NSArray *_whereArr; //所属地区
  38. NSMutableArray *_payments; //收款方式
  39. NSMutableArray *_salemanArr; //业务员
  40. NSMutableArray *_paymentsCode; //收款方式编号
  41. NSString *_pmCode;//选择的收款方式编号
  42. UITextField *_currentTF;
  43. int _isTF;
  44. NSString *_sellerCode; //业务员编号
  45. }
  46. - (void)viewDidLoad {
  47. [super viewDidLoad];
  48. // Do any additional setup after loading the view.
  49. self.view.backgroundColor = BGKJ_COLOR;
  50. self.title = @"客户预录入";
  51. UIBarButtonItem *bbi1 = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveAction)];
  52. self.navigationItem.rightBarButtonItem = bbi1;
  53. [self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
  54. UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
  55. btn2.frame = CGRectMake(0, 5, 22, 22);
  56. UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, iOS11?5:0, 22, 22)];
  57. image.image = [UIImage imageNamed:@"icon_back_nor3"];
  58. [btn2 addSubview:image];
  59. [btn2 addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  60. UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
  61. self.navigationItem.leftBarButtonItems = @[bbi2];
  62. self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:151/255.0 blue:215/255.0 alpha:1.0];
  63. _scrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  64. _scrollV.showsHorizontalScrollIndicator = NO;
  65. _scrollV.showsVerticalScrollIndicator = NO;
  66. // 点击状态栏时自动滑动到顶部
  67. _scrollV.scrollsToTop = YES;
  68. _scrollV.delegate = self;
  69. _scrollV.tag = 1000;
  70. _scrollV.backgroundColor = BGKJ_COLOR;
  71. [self.view addSubview:_scrollV];
  72. [_scrollV mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.top.left.bottom.right.equalTo(self.view);
  74. }];
  75. _whereArr = @[@"华东地区",@"华南地区",@"华北地区",@"华中地区",@"西南地区",@"西北地区",@"东北地区",@"港澳台地区",@"海外地区",@"其它地区"];
  76. _payments = [[NSMutableArray alloc]init];
  77. _salemanArr = [[NSMutableArray alloc]init];
  78. _salemanArr = [[NSMutableArray alloc]init];
  79. _clientKindArr = [[NSMutableArray alloc]init];
  80. _sellerCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
  81. _cuid = @"";
  82. _pmCode = @"";
  83. _rows = 1;
  84. [self getCode];
  85. [self getId];
  86. [self buildMainUI];
  87. //增加通知中心监听,当键盘出现或消失时收出消息
  88. [[NSNotificationCenter defaultCenter] addObserver:self
  89. selector:@selector(keyboardWillShow:)
  90. name:UIKeyboardWillShowNotification
  91. object:nil];
  92. [[NSNotificationCenter defaultCenter] addObserver:self
  93. selector:@selector(keyboardWillHide:)
  94. name:UIKeyboardWillHideNotification
  95. object:nil];
  96. // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFiledEditChanged:)name:@"UITextFieldTextDidChangeNotification"
  97. // object:nil];
  98. }
  99. -(void)getCode //获取单据编号
  100. {
  101. NSString *sessionId=[[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
  102. NSString *ip=[UASUserInfo shareManager].urlIp;
  103. NSString *master = [[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_user"];
  104. NSString *sessionUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
  105. NSString *url = [NSString stringWithFormat:@"%@common/getCodeString.action?type=2&caller=PreCustomer&master=%@&sessionUser=%@&sessionId=%@",ip,master,sessionUser,sessionId];
  106. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  107. UASNetworkManager *manager = [UASNetworkManager shareManager];
  108. manager.responseSerializer = [AFJSONResponseSerializer serializer];
  109. //拼接sessionID
  110. NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
  111. //设置cookie
  112. [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
  113. [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  114. DLog(@"adfssadvfad:%@",responseObject);
  115. _code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
  116. // DLog(@"aaaaaaa:%@",_code);
  117. _clientCode.text = _code;
  118. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  119. [JOShowMessageFromNavi showDropViewWithMessage:@"编号获取失败" ToNavi:self.navigationController withColor:nil];
  120. }];
  121. }
  122. -(void)getId
  123. {
  124. NSString *sessionId=[[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
  125. NSString *ip=[UASUserInfo shareManager].urlIp;
  126. NSString *master = [[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_user"];
  127. NSString *sessionUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
  128. NSString *url = [NSString stringWithFormat:@"%@common/getId.action?seq=PRECUSTOMER_SEQ&master=%@&sessionUser=%@&sessionId=%@",ip,master,sessionUser,sessionId];
  129. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  130. UASNetworkManager *manager = [UASNetworkManager shareManager];
  131. manager.responseSerializer = [AFJSONResponseSerializer serializer];
  132. //拼接sessionID
  133. NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
  134. //设置cookie
  135. [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
  136. [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  137. _cuid = [NSString stringWithFormat:@"%@",responseObject[@"id"]];
  138. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  139. [JOShowMessageFromNavi showDropViewWithMessage:@"单据id获取失败" ToNavi:self.navigationController withColor:nil];
  140. }];
  141. }
  142. -(void)getPaymentscodeData //获取收款方式数据
  143. {
  144. NSString *sessionId=[[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
  145. NSString *ip=[UASUserInfo shareManager].urlIp;
  146. NSString *url = [NSString stringWithFormat:@"%@mobile/common/getDbfind.action?which=form&caller=Customer!Base&field=cu_paymentscode&sessionId=%@",ip,sessionId];
  147. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  148. UASNetworkManager *manager = [UASNetworkManager shareManager];
  149. manager.responseSerializer = [AFJSONResponseSerializer serializer];
  150. //拼接sessionID
  151. NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
  152. //设置cookie
  153. [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
  154. [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  155. for (id obj in responseObject[@"datas"]) {
  156. [_payments addObject:obj[@"pa_name"]];
  157. }
  158. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  159. DLog(@"请求失败:%@",error);
  160. [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlert:@"币别数据请求失败"];
  161. }];
  162. }
  163. -(void)buildMainUI
  164. {
  165. NSArray *titleArr = @[@"客户编号",@"客户名称",@"简称",@"客户地址",@"客户类型",@"所属地区",@"收款方式",@"业务员",@"联系人",@"岗位",@"电话",@"邮箱",@"备注"];
  166. for (int i =0; i< titleArr.count; i++)
  167. {
  168. UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 10+40*i, 75, 30)];
  169. title.font = FONT_SIZE(13);
  170. title.text = titleArr[i];
  171. [_scrollV addSubview:title];
  172. if (i==0 || i==1 || i==3 || i==4 || i==5 || i==6 || i==7 || i==8 || i==9 || i==10 || i==11) {
  173. UILabel *xingxing = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(title.frame)+5, title.frame.origin.y, 30, 30)];
  174. xingxing.text = @"*";
  175. xingxing.textColor = [UIColor redColor];
  176. xingxing.font = FONT_SIZE(15);
  177. [_scrollV addSubview:xingxing];
  178. }
  179. }
  180. _clientCode = [self creatTextFieldwith:0 plach:@"请输入"];
  181. _clientCode.userInteractionEnabled = NO;
  182. _clientName = [self creatTextFieldwith:1 plach:@"请输入"];
  183. _clientName.text = _kehumingcheng;
  184. _shortName = [self creatTextFieldwith:2 plach:@"请输入"];
  185. _addressName = [self creatTextFieldwith:3 plach:@"请输入"];
  186. _addressName.text = _kehudizhi;
  187. _clientKind = [self creatTextFieldwith:4 plach:@"请选择"];
  188. _belongWhere = [self creatTextFieldwith:5 plach:@"请选择"];
  189. _getMoneyKind = [self creatTextFieldwith:6 plach:@"请选择"];
  190. _saleMan = [self creatTextFieldwith:7 plach:@"请选择"];
  191. _saleMan.text = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] stringForKey:@"personName"]];
  192. _contactMan = [self creatTextFieldwith:8 plach:@"请输入"];
  193. _contactMan.text = _lianxiren;
  194. _position = [self creatTextFieldwith:9 plach:@"请输入"];
  195. _position.text = _gangwei;
  196. _contactTel = [self creatTextFieldwith:10 plach:@"请输入"];
  197. _contactTel.text = _dianhua;
  198. _contactTel.keyboardType = UIKeyboardTypeNumberPad;
  199. _email = [self creatTextFieldwith:11 plach:@"请输入"];
  200. _remark = [[UITextView alloc]initWithFrame:CGRectMake(115, 10+40*12, _scrollV.frame.size.width-105-5-10, 30)];
  201. _remark.delegate = self;
  202. _remark.layer.borderWidth = 0.5;
  203. _remark.layer.borderColor = [[UIColor lightGrayColor]colorWithAlphaComponent:0.5].CGColor;
  204. _remark.layer.masksToBounds = YES;
  205. _remark.layer.cornerRadius = 5;
  206. _remark.returnKeyType = UIReturnKeyDone;
  207. _remark.tag = 12;
  208. _remark.backgroundColor = [UIColor clearColor];
  209. [_scrollV addSubview:_remark];
  210. _scrollV.contentSize = CGSizeMake(SCREEN_WIDTH, CGRectGetMaxY(_remark.frame)+40);
  211. }
  212. -(void)saveAction
  213. {
  214. NSString *sessionId=[[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
  215. NSString *ip=[UASUserInfo shareManager].urlIp;
  216. NSString *master = [[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_user"];
  217. NSString *sessionUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
  218. NSDate *senddate = [NSDate date];
  219. NSDateFormatter *f=[[NSDateFormatter alloc]init];
  220. f.dateFormat = @"yyyy-MM-dd HH:mm:ss";
  221. NSString *dateString = [NSString stringWithFormat:@"%@",[f stringFromDate:senddate]];
  222. NSDictionary *params;
  223. /*
  224. cu_code客户编号
  225. cu_name客户名称
  226. cu_source客户来源
  227. cu_defaultlevel所属行业
  228. cu_tel客户级别
  229. cu_lastdate联系电话
  230. cu_add1最后跟进时间
  231. cu_remark备注
  232. */
  233. if ([_clientName.text isEqualToString:@""]||[_addressName.text isEqualToString:@""]||[_clientKind.text isEqualToString:@""]||[_belongWhere.text isEqualToString:@""]||[_getMoneyKind.text isEqualToString:@""]||[_saleMan.text isEqualToString:@""]||[_contactMan.text isEqualToString:@""]||[_position.text isEqualToString:@""]||[_contactTel.text isEqualToString:@""]||[_email.text isEqualToString:@""]) {
  234. [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlert:@"对不起,未填完此单!"];
  235. }else{
  236. params = @{@"cu_code":_code,
  237. @"cu_name":_clientName.text,
  238. @"cu_shortname":_shortName.text,
  239. @"cu_add1":_addressName.text,
  240. @"cu_kind":_clientKind.text,
  241. @"cu_district":_belongWhere.text,
  242. @"cu_payments":_getMoneyKind.text,
  243. @"cu_sellername":_saleMan.text,
  244. @"cu_contact":_contactMan.text,
  245. @"cu_degree":_position.text,
  246. @"cu_mobile":_contactTel.text,
  247. @"cu_email":_email.text,
  248. @"cu_remark":_remark.text,
  249. @"cu_sellercode":_sellerCode,
  250. @"cu_paymentscode":_pmCode,
  251. @"cu_id":_cuid,
  252. @"cu_recordman":[[NSUserDefaults standardUserDefaults] stringForKey:@"personName"],
  253. @"cu_recorddate":dateString,
  254. @"cu_auditstatus":@"在录入",
  255. @"cu_auditstatuscode":@"ENTERING",
  256. @"cu_status":@"长期"};
  257. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
  258. NSString *str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  259. // plm/task/saveFormTask.action
  260. NSString *url = [NSString stringWithFormat:@"%@scm/sale/savePreCustomer.action?formStore=%@&caller=PreCustomer&master=%@&sessionUser=%@&sessionId=%@",ip,str,master,sessionUser,sessionId];
  261. // DLog(@"aaaaaaaa:%@",url);
  262. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  263. UASNetworkManager *manager = [UASNetworkManager shareManager];
  264. //拼接sessionID
  265. NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
  266. //设置cookie
  267. [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
  268. [manager.requestSerializer setValue:[NSString stringWithFormat:@"%@",g_sessionUser] forHTTPHeaderField:@"sessionUser"];
  269. [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  270. if (responseObject[@"success"]) {
  271. [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlert:Localized(@"UU_custom_saveSuccess")];
  272. [self.navigationController popViewControllerAnimated:YES];
  273. }else{
  274. [UASAlertView showWithTitle:nil content:@"保存失败!" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
  275. }];
  276. }
  277. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  278. NSData *returnData = [[error userInfo] objectForKey:@"com.alamofire.serialization.response.error.data"];
  279. if (returnData) {
  280. NSDictionary *content = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];//转换数据格式
  281. NSString *errorStr = [NSString stringWithFormat:@"%@",[content objectForKey:@"exceptionInfo"]];
  282. DLog(@"错误的原因:%@",errorStr);
  283. [JOShowMessageFromNavi showDropViewWithMessage:errorStr ToNavi:self.navigationController withColor:nil];
  284. }
  285. else{
  286. [JOShowMessageFromNavi showDropViewWithMessage:@"请检查网络情况" ToNavi:self.navigationController withColor:nil];
  287. }
  288. }];
  289. }
  290. }
  291. #pragma mark - UITextViewDelegate
  292. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
  293. if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车,即按下return
  294. //在这里做你响应return键的代码
  295. return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行
  296. }
  297. return YES;
  298. }
  299. -(BOOL)textViewShouldBeginEditing:(UITextView *)textView
  300. {
  301. _isTF = 0;
  302. return YES;
  303. }
  304. -(BOOL)textViewShouldEndEditing:(UITextView *)textView
  305. {
  306. return YES;
  307. }
  308. - (void)textViewDidChange:(UITextView *)textView{
  309. // numberlines用来控制输入的行数
  310. NSInteger numberLines = textView.contentSize.height / textView.font.lineHeight;
  311. if (numberLines != _rows) {
  312. // DLog(@"text = %@", _remark.text);
  313. _rows = numberLines;
  314. if (_rows < 5){
  315. [self changeFrame:textView.contentSize.height];
  316. }else{
  317. _remark.scrollEnabled = YES;
  318. }
  319. [textView setContentOffset:CGPointZero animated:YES];
  320. }
  321. // if (textView.text.length > 50)
  322. // {
  323. // textView.text = [textView.text substringToIndex:50];
  324. // // [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlert:@"不能超过50个字"];
  325. // [self.view endEditing:YES];
  326. // [KPromptBox showKPromptBoxWithMassage:@"不能超过50个字符!"];
  327. // }
  328. }
  329. - (void)changeFrame:(CGFloat)height{
  330. CGRect textViewFrame = _remark.frame;
  331. textViewFrame.size.height = height;
  332. [UIView animateWithDuration:0.3 animations:^{
  333. _remark.frame = textViewFrame;
  334. }];
  335. }
  336. #pragma mark - UITextField Delegate
  337. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  338. {
  339. // 辞去TextField响应,来隐藏键盘
  340. [textField resignFirstResponder];
  341. return YES;
  342. }
  343. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
  344. _isTF = 1;
  345. _currentTF = textField;
  346. if (textField.tag == 1004 || textField.tag == 1005 || textField.tag == 1006) {
  347. [_clientName resignFirstResponder];
  348. [_shortName resignFirstResponder];
  349. [_addressName resignFirstResponder];
  350. [_contactMan resignFirstResponder];
  351. [_position resignFirstResponder];
  352. [_contactTel resignFirstResponder];
  353. [_email resignFirstResponder];
  354. }
  355. if (textField.tag == 1004)
  356. {
  357. ClientKindVC *ckVC = [[ClientKindVC alloc]init];
  358. ckVC.block = ^(NSString *nameStr){
  359. _clientKind.text = nameStr;
  360. };
  361. [self.navigationController pushViewController:ckVC animated:YES];
  362. return NO;
  363. }
  364. if (textField.tag == 1005)
  365. {
  366. ShareSelectVC *shareSelectVC = [[ShareSelectVC alloc]init];
  367. shareSelectVC.titleStr = @"所属地区";
  368. shareSelectVC.block = ^(NSDictionary *listData){
  369. DLog(@"返回来的数据是什么:%@",listData);
  370. _belongWhere.text = [NSString stringWithFormat:@"%@",listData];
  371. };
  372. [self.navigationController pushViewController:shareSelectVC animated:YES];
  373. return NO;
  374. }
  375. if (textField.tag == 1006)
  376. {
  377. PaymentsVC *pmVC = [[PaymentsVC alloc]init];
  378. pmVC.block = ^(NSString *payments,NSString *paymentCode){
  379. _getMoneyKind.text = payments;
  380. _pmCode = paymentCode;
  381. };
  382. [self.navigationController pushViewController:pmVC animated:YES];
  383. [textField resignFirstResponder];
  384. return NO;
  385. }
  386. if (textField.tag == 1007)
  387. {
  388. SalemanSelectVC *saleVC = [[SalemanSelectVC alloc]init];
  389. saleVC.block = ^(NSString *nameStr){
  390. _saleMan.text = nameStr;
  391. };
  392. saleVC.block2 = ^(NSString *codeStr){
  393. _sellerCode = codeStr;
  394. };
  395. [self.navigationController pushViewController:saleVC animated:YES];
  396. return NO;
  397. }
  398. return YES;
  399. }
  400. /*
  401. -(void)textFiledEditChanged:(NSNotification *)obj{
  402. UITextField *textField = (UITextField *)obj.object;
  403. NSString *toBeString = textField.text;
  404. NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage]; // 键盘输入模式
  405. if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写
  406. UITextRange *selectedRange = [textField markedTextRange];
  407. //获取高亮部分
  408. UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
  409. // 没有高亮选择的字,则对已输入的文字进行字数统计和限制
  410. if (!position) {
  411. if (textField.tag == 1001)
  412. {
  413. if (toBeString.length > 16)
  414. {
  415. textField.text = [toBeString substringToIndex:16];
  416. [self.view endEditing: YES];
  417. [KPromptBox showKPromptBoxWithMassage:@"不能超过16个字符"];
  418. }
  419. }
  420. else if (textField.tag == 1002)
  421. {
  422. if (toBeString.length > 16)
  423. {
  424. textField.text = [toBeString substringToIndex:16];
  425. [self.view endEditing: YES];
  426. [KPromptBox showKPromptBoxWithMassage:@"不能超过16个字符"];
  427. }
  428. }
  429. else if (textField.tag == 1003)
  430. {
  431. if (toBeString.length > 16)
  432. {
  433. textField.text = [toBeString substringToIndex:16];
  434. [self.view endEditing: YES];
  435. [KPromptBox showKPromptBoxWithMassage:@"不能超过16个字符"];
  436. }
  437. }
  438. else if (textField.tag == 1008)
  439. {
  440. if (toBeString.length > 6)
  441. {
  442. textField.text = [toBeString substringToIndex:6];
  443. [self.view endEditing: YES];
  444. [KPromptBox showKPromptBoxWithMassage:@"不能超过6个字符"];
  445. }
  446. }
  447. else if (textField.tag == 1009)
  448. {
  449. if (toBeString.length > 33)
  450. {
  451. textField.text = [toBeString substringToIndex:33];
  452. [self.view endEditing: YES];
  453. [KPromptBox showKPromptBoxWithMassage:@"不能超过33个字符"];
  454. }
  455. }
  456. else if (textField.tag == 1010)
  457. {
  458. if (toBeString.length > 33)
  459. {
  460. textField.text = [toBeString substringToIndex:33];
  461. [self.view endEditing: YES];
  462. [KPromptBox showKPromptBoxWithMassage:@"不能超过33个字符"];
  463. }
  464. }
  465. else if (textField.tag == 1011)
  466. {
  467. if (toBeString.length > 66)
  468. {
  469. textField.text = [toBeString substringToIndex:66];
  470. [self.view endEditing: YES];
  471. [KPromptBox showKPromptBoxWithMassage:@"不能超过66个字符"];
  472. }
  473. }
  474. }
  475. // 有高亮选择的字符串,则暂不对文字进行统计和限制
  476. else
  477. {
  478. }
  479. }
  480. // 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况
  481. else
  482. {
  483. if (textField.tag == 1001)
  484. {
  485. if (toBeString.length > 50)
  486. {
  487. textField.text = [toBeString substringToIndex:50];
  488. [self.view endEditing: YES];
  489. [KPromptBox showKPromptBoxWithMassage:@"不能超过50个字符"];
  490. }
  491. }
  492. else if (textField.tag == 1002)
  493. {
  494. if (toBeString.length > 50)
  495. {
  496. textField.text = [toBeString substringToIndex:50];
  497. [self.view endEditing: YES];
  498. [KPromptBox showKPromptBoxWithMassage:@"不能超过50个字符"];
  499. }
  500. }
  501. else if (textField.tag == 1003)
  502. {
  503. if (toBeString.length > 50)
  504. {
  505. textField.text = [toBeString substringToIndex:50];
  506. [self.view endEditing: YES];
  507. [KPromptBox showKPromptBoxWithMassage:@"不能超过50个字符"];
  508. }
  509. }
  510. else if (textField.tag == 1008)
  511. {
  512. if (toBeString.length > 100)
  513. {
  514. textField.text = [toBeString substringToIndex:100];
  515. [self.view endEditing: YES];
  516. [KPromptBox showKPromptBoxWithMassage:@"不能超过100个字符"];
  517. }
  518. }
  519. else if (textField.tag == 1009)
  520. {
  521. if (toBeString.length > 100)
  522. {
  523. textField.text = [toBeString substringToIndex:100];
  524. [self.view endEditing: YES];
  525. [KPromptBox showKPromptBoxWithMassage:@"不能超过100个字符"];
  526. }
  527. }
  528. else if (textField.tag == 1010)
  529. {
  530. if (toBeString.length > 100)
  531. {
  532. textField.text = [toBeString substringToIndex:100];
  533. [self.view endEditing: YES];
  534. [KPromptBox showKPromptBoxWithMassage:@"不能超过100个字符"];
  535. }
  536. }
  537. else if (textField.tag == 1011)
  538. {
  539. if (toBeString.length > 200)
  540. {
  541. textField.text = [toBeString substringToIndex:200];
  542. [self.view endEditing: YES];
  543. [KPromptBox showKPromptBoxWithMassage:@"不能超过200个字符"];
  544. }
  545. }
  546. }
  547. }
  548. */
  549. -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
  550. {
  551. // self.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  552. return YES;
  553. }
  554. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  555. if (textField.tag == 1010){
  556. return [self validateNumber2:string];
  557. }
  558. else{
  559. if ([string isEqualToString:@" "]) {
  560. return NO;
  561. }
  562. else
  563. return YES;
  564. }
  565. }
  566. //只能输入数字 -- 电话
  567. - (BOOL)validateNumber2:(NSString*)number {
  568. BOOL res = YES;
  569. NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789-"];
  570. int i = 0;
  571. while (i < number.length) {
  572. NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
  573. NSRange range = [string rangeOfCharacterFromSet:tmpSet];
  574. if (range.length == 0) {
  575. res = NO;
  576. break;
  577. }
  578. i++;
  579. }
  580. return res;
  581. }
  582. -(UITextField *)creatTextFieldwith:(int)num plach:(NSString *)title
  583. {
  584. int width = _scrollV.frame.size.width-105-5;
  585. UITextField *tf = [[UITextField alloc]init];
  586. tf.frame = CGRectMake(115, 10+40*num, width-10, 30);
  587. tf.tag = 1000+num;
  588. tf.returnKeyType = UIReturnKeyDone;
  589. tf.borderStyle = UITextBorderStyleRoundedRect;
  590. tf.backgroundColor = [UIColor clearColor];
  591. tf.delegate = self;
  592. tf.placeholder = title;
  593. tf.font = FONT_SIZE(13);
  594. [_scrollV addSubview:tf];
  595. return tf;
  596. }
  597. #pragma mark - 键盘显示隐藏
  598. #pragma mark 键盘显示
  599. - (void)keyboardWillShow:(NSNotification *)notification{
  600. // 1.取得键盘最后的frame
  601. CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  602. CGFloat height = keyboardFrame.origin.y;
  603. //2.计算控制器的view需要移动的距离
  604. //这里设定tableView的一个cell的高度是50
  605. CGFloat textField_maxY;
  606. if (_isTF == 0) {
  607. textField_maxY = (_remark.tag + 1) * 40 + 30;
  608. }else {
  609. textField_maxY = (_currentTF.tag-1000 + 1) * 45 +10;
  610. }
  611. //考虑tableView已经滚动位置
  612. CGFloat space = - _scrollV.contentOffset.y + textField_maxY;
  613. //得出键盘距离输入框的间距
  614. CGFloat transformY = height - space;
  615. DLog(@"%f",transformY);
  616. //3.当键盘会挡到输入框的时候就开始移动,不然不移动。有时候要考虑导航栏要+64
  617. if (transformY < 0) {
  618. transformY -= 70;
  619. [_scrollV mas_updateConstraints:^(MASConstraintMaker *make) {
  620. make.left.bottom.right.equalTo(self.view);
  621. make.top.equalTo(self.view).offset(transformY);
  622. }];
  623. }
  624. }
  625. #pragma mark 键盘隐藏
  626. - (void)keyboardWillHide:(NSNotification *)notification {
  627. [_scrollV mas_updateConstraints:^(MASConstraintMaker *make) {
  628. make.top.left.bottom.right.equalTo(self.view);
  629. }];
  630. }
  631. - (void)didReceiveMemoryWarning {
  632. [super didReceiveMemoryWarning];
  633. // Dispose of any resources that can be recreated.
  634. }
  635. -(void)viewWillAppear:(BOOL)animated
  636. {
  637. [[NSNotificationCenter defaultCenter] postNotificationName:@"hideBottomView" object:nil];
  638. }
  639. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  640. {
  641. if (scrollView.tag == 1000) {
  642. [self.view endEditing:YES];
  643. }
  644. }
  645. -(void)backAction
  646. {
  647. [self.navigationController popViewControllerAnimated:YES];
  648. }
  649. @end