| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760 |
- //
- // AddClientInputVC.m
- // shiku_im
- //
- // Created by huangyp-pc on 16/7/26.
- // Copyright © 2016年 Reese. All rights reserved.
- //
- #import "AddClientInputVC.h"
- #import "AFNetworking.h"
- #import "SalemanSelectVC.h"
- #import "PaymentsVC.h"
- #import "ClientKindVC.h"
- #import "CurrencyVC.h"
- #import "ShareSelectVC.h"
- @interface AddClientInputVC ()<UITextFieldDelegate,UITextViewDelegate,UIScrollViewDelegate>
- @property (nonatomic,strong) UIScrollView *scrollV;
- @property (nonatomic,assign) NSInteger rows;
- @end
- @implementation AddClientInputVC
- {
- UITextField *_clientCode; //客户编号
- UITextField *_clientName; //客户名称
- UITextField *_shortName; //简称
- UITextField *_addressName; //客户地址
- UITextField *_clientKind; //客户类型
- UITextField *_belongWhere; //所属地区
- UITextField *_getMoneyKind; //收款方式
- UITextField *_saleMan; //业务员
- UITextField *_contactMan; //联系人
- UITextField *_position; //岗位
- UITextField *_contactTel; //电话
- UITextField *_email; //邮箱
-
- UITextView *_remark;//备注
-
- NSString *_code; //单据编号
- NSString *_cuid; //单据id
-
- NSMutableArray *_clientKindArr;//客户类型
- NSArray *_whereArr; //所属地区
- NSMutableArray *_payments; //收款方式
- NSMutableArray *_salemanArr; //业务员
-
- NSMutableArray *_paymentsCode; //收款方式编号
- NSString *_pmCode;//选择的收款方式编号
-
- UITextField *_currentTF;
- int _isTF;
-
- NSString *_sellerCode; //业务员编号
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.view.backgroundColor = BGKJ_COLOR;
- self.title = @"客户预录入";
- UIBarButtonItem *bbi1 = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveAction)];
- self.navigationItem.rightBarButtonItem = bbi1;
- [self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
-
- UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
- btn2.frame = CGRectMake(0, 5, 22, 22);
- UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, iOS11?5:0, 22, 22)];
- image.image = [UIImage imageNamed:@"icon_back_nor3"];
- [btn2 addSubview:image];
- [btn2 addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
- self.navigationItem.leftBarButtonItems = @[bbi2];
-
- self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:151/255.0 blue:215/255.0 alpha:1.0];
-
- _scrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- _scrollV.showsHorizontalScrollIndicator = NO;
- _scrollV.showsVerticalScrollIndicator = NO;
- // 点击状态栏时自动滑动到顶部
- _scrollV.scrollsToTop = YES;
- _scrollV.delegate = self;
- _scrollV.tag = 1000;
- _scrollV.backgroundColor = BGKJ_COLOR;
- [self.view addSubview:_scrollV];
-
- [_scrollV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.bottom.right.equalTo(self.view);
- }];
-
-
- _whereArr = @[@"华东地区",@"华南地区",@"华北地区",@"华中地区",@"西南地区",@"西北地区",@"东北地区",@"港澳台地区",@"海外地区",@"其它地区"];
- _payments = [[NSMutableArray alloc]init];
- _salemanArr = [[NSMutableArray alloc]init];
- _salemanArr = [[NSMutableArray alloc]init];
- _clientKindArr = [[NSMutableArray alloc]init];
-
- _sellerCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
-
- _cuid = @"";
- _pmCode = @"";
- _rows = 1;
- [self getCode];
- [self getId];
- [self buildMainUI];
-
- //增加通知中心监听,当键盘出现或消失时收出消息
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(keyboardWillShow:)
- name:UIKeyboardWillShowNotification
- object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(keyboardWillHide:)
- name:UIKeyboardWillHideNotification
- object:nil];
-
- // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFiledEditChanged:)name:@"UITextFieldTextDidChangeNotification"
- // object:nil];
- }
- -(void)getCode //获取单据编号
- {
- NSString *sessionId=[[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
- NSString *ip=[UASUserInfo shareManager].urlIp;
- NSString *master = [[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_user"];
- NSString *sessionUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
-
- NSString *url = [NSString stringWithFormat:@"%@common/getCodeString.action?type=2&caller=PreCustomer&master=%@&sessionUser=%@&sessionId=%@",ip,master,sessionUser,sessionId];
-
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- UASNetworkManager *manager = [UASNetworkManager shareManager];
- manager.responseSerializer = [AFJSONResponseSerializer serializer];
-
- //拼接sessionID
- NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
- //设置cookie
- [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
- [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- DLog(@"adfssadvfad:%@",responseObject);
- _code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
- // DLog(@"aaaaaaa:%@",_code);
- _clientCode.text = _code;
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
-
- [JOShowMessageFromNavi showDropViewWithMessage:@"编号获取失败" ToNavi:self.navigationController withColor:nil];
- }];
-
- }
- -(void)getId
- {
- NSString *sessionId=[[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
- NSString *ip=[UASUserInfo shareManager].urlIp;
- NSString *master = [[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_user"];
- NSString *sessionUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
-
- NSString *url = [NSString stringWithFormat:@"%@common/getId.action?seq=PRECUSTOMER_SEQ&master=%@&sessionUser=%@&sessionId=%@",ip,master,sessionUser,sessionId];
-
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- UASNetworkManager *manager = [UASNetworkManager shareManager];
- manager.responseSerializer = [AFJSONResponseSerializer serializer];
-
- //拼接sessionID
- NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
- //设置cookie
- [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
- [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
-
- _cuid = [NSString stringWithFormat:@"%@",responseObject[@"id"]];
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
-
- [JOShowMessageFromNavi showDropViewWithMessage:@"单据id获取失败" ToNavi:self.navigationController withColor:nil];
- }];
- }
- -(void)getPaymentscodeData //获取收款方式数据
- {
- NSString *sessionId=[[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
- NSString *ip=[UASUserInfo shareManager].urlIp;
-
- NSString *url = [NSString stringWithFormat:@"%@mobile/common/getDbfind.action?which=form&caller=Customer!Base&field=cu_paymentscode&sessionId=%@",ip,sessionId];
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
-
-
- UASNetworkManager *manager = [UASNetworkManager shareManager];
- manager.responseSerializer = [AFJSONResponseSerializer serializer];
- //拼接sessionID
- NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
- //设置cookie
- [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
- [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- for (id obj in responseObject[@"datas"]) {
- [_payments addObject:obj[@"pa_name"]];
- }
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- DLog(@"请求失败:%@",error);
- [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlert:@"币别数据请求失败"];
- }];
- }
- -(void)buildMainUI
- {
- NSArray *titleArr = @[@"客户编号",@"客户名称",@"简称",@"客户地址",@"客户类型",@"所属地区",@"收款方式",@"业务员",@"联系人",@"岗位",@"电话",@"邮箱",@"备注"];
- for (int i =0; i< titleArr.count; i++)
- {
- UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 10+40*i, 75, 30)];
- title.font = FONT_SIZE(13);
- title.text = titleArr[i];
- [_scrollV addSubview:title];
-
- if (i==0 || i==1 || i==3 || i==4 || i==5 || i==6 || i==7 || i==8 || i==9 || i==10 || i==11) {
- UILabel *xingxing = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(title.frame)+5, title.frame.origin.y, 30, 30)];
- xingxing.text = @"*";
- xingxing.textColor = [UIColor redColor];
- xingxing.font = FONT_SIZE(15);
- [_scrollV addSubview:xingxing];
- }
-
- }
-
- _clientCode = [self creatTextFieldwith:0 plach:@"请输入"];
- _clientCode.userInteractionEnabled = NO;
-
- _clientName = [self creatTextFieldwith:1 plach:@"请输入"];
- _clientName.text = _kehumingcheng;
-
- _shortName = [self creatTextFieldwith:2 plach:@"请输入"];
- _addressName = [self creatTextFieldwith:3 plach:@"请输入"];
- _addressName.text = _kehudizhi;
-
- _clientKind = [self creatTextFieldwith:4 plach:@"请选择"];
- _belongWhere = [self creatTextFieldwith:5 plach:@"请选择"];
- _getMoneyKind = [self creatTextFieldwith:6 plach:@"请选择"];
- _saleMan = [self creatTextFieldwith:7 plach:@"请选择"];
- _saleMan.text = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] stringForKey:@"personName"]];
-
- _contactMan = [self creatTextFieldwith:8 plach:@"请输入"];
- _contactMan.text = _lianxiren;
-
- _position = [self creatTextFieldwith:9 plach:@"请输入"];
- _position.text = _gangwei;
-
- _contactTel = [self creatTextFieldwith:10 plach:@"请输入"];
- _contactTel.text = _dianhua;
- _contactTel.keyboardType = UIKeyboardTypeNumberPad;
-
- _email = [self creatTextFieldwith:11 plach:@"请输入"];
-
- _remark = [[UITextView alloc]initWithFrame:CGRectMake(115, 10+40*12, _scrollV.frame.size.width-105-5-10, 30)];
- _remark.delegate = self;
- _remark.layer.borderWidth = 0.5;
- _remark.layer.borderColor = [[UIColor lightGrayColor]colorWithAlphaComponent:0.5].CGColor;
- _remark.layer.masksToBounds = YES;
- _remark.layer.cornerRadius = 5;
- _remark.returnKeyType = UIReturnKeyDone;
- _remark.tag = 12;
- _remark.backgroundColor = [UIColor clearColor];
- [_scrollV addSubview:_remark];
-
- _scrollV.contentSize = CGSizeMake(SCREEN_WIDTH, CGRectGetMaxY(_remark.frame)+40);
-
- }
- -(void)saveAction
- {
- NSString *sessionId=[[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
- NSString *ip=[UASUserInfo shareManager].urlIp;
- NSString *master = [[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_user"];
- NSString *sessionUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
-
- NSDate *senddate = [NSDate date];
- NSDateFormatter *f=[[NSDateFormatter alloc]init];
- f.dateFormat = @"yyyy-MM-dd HH:mm:ss";
- NSString *dateString = [NSString stringWithFormat:@"%@",[f stringFromDate:senddate]];
-
- NSDictionary *params;
-
- /*
- cu_code客户编号
- cu_name客户名称
- cu_source客户来源
- cu_defaultlevel所属行业
- cu_tel客户级别
- cu_lastdate联系电话
- cu_add1最后跟进时间
- cu_remark备注
- */
- 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:@""]) {
- [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlert:@"对不起,未填完此单!"];
- }else{
- params = @{@"cu_code":_code,
- @"cu_name":_clientName.text,
- @"cu_shortname":_shortName.text,
- @"cu_add1":_addressName.text,
- @"cu_kind":_clientKind.text,
- @"cu_district":_belongWhere.text,
- @"cu_payments":_getMoneyKind.text,
- @"cu_sellername":_saleMan.text,
- @"cu_contact":_contactMan.text,
- @"cu_degree":_position.text,
- @"cu_mobile":_contactTel.text,
- @"cu_email":_email.text,
- @"cu_remark":_remark.text,
- @"cu_sellercode":_sellerCode,
- @"cu_paymentscode":_pmCode,
- @"cu_id":_cuid,
- @"cu_recordman":[[NSUserDefaults standardUserDefaults] stringForKey:@"personName"],
- @"cu_recorddate":dateString,
- @"cu_auditstatus":@"在录入",
- @"cu_auditstatuscode":@"ENTERING",
- @"cu_status":@"长期"};
-
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
- NSString *str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- // plm/task/saveFormTask.action
- NSString *url = [NSString stringWithFormat:@"%@scm/sale/savePreCustomer.action?formStore=%@&caller=PreCustomer&master=%@&sessionUser=%@&sessionId=%@",ip,str,master,sessionUser,sessionId];
-
- // DLog(@"aaaaaaaa:%@",url);
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- UASNetworkManager *manager = [UASNetworkManager shareManager];
- //拼接sessionID
- NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
- //设置cookie
- [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
- [manager.requestSerializer setValue:[NSString stringWithFormat:@"%@",g_sessionUser] forHTTPHeaderField:@"sessionUser"];
- [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
-
- if (responseObject[@"success"]) {
- [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlert:Localized(@"UU_custom_saveSuccess")];
- [self.navigationController popViewControllerAnimated:YES];
- }else{
-
- [UASAlertView showWithTitle:nil content:@"保存失败!" sureTitle:Localized(@"UU_custom_sure") cancelTitle:nil click:^(NSInteger index) {
-
- }];
- }
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- NSData *returnData = [[error userInfo] objectForKey:@"com.alamofire.serialization.response.error.data"];
- if (returnData) {
- NSDictionary *content = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];//转换数据格式
-
- NSString *errorStr = [NSString stringWithFormat:@"%@",[content objectForKey:@"exceptionInfo"]];
-
- DLog(@"错误的原因:%@",errorStr);
- [JOShowMessageFromNavi showDropViewWithMessage:errorStr ToNavi:self.navigationController withColor:nil];
- }
- else{
- [JOShowMessageFromNavi showDropViewWithMessage:@"请检查网络情况" ToNavi:self.navigationController withColor:nil];
- }
- }];
- }
-
- }
- #pragma mark - UITextViewDelegate
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
- if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车,即按下return
- //在这里做你响应return键的代码
- return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行
-
- }
-
- return YES;
- }
- -(BOOL)textViewShouldBeginEditing:(UITextView *)textView
- {
- _isTF = 0;
- return YES;
- }
- -(BOOL)textViewShouldEndEditing:(UITextView *)textView
- {
- return YES;
- }
- - (void)textViewDidChange:(UITextView *)textView{
- // numberlines用来控制输入的行数
- NSInteger numberLines = textView.contentSize.height / textView.font.lineHeight;
- if (numberLines != _rows) {
- // DLog(@"text = %@", _remark.text);
- _rows = numberLines;
- if (_rows < 5){
- [self changeFrame:textView.contentSize.height];
- }else{
- _remark.scrollEnabled = YES;
- }
- [textView setContentOffset:CGPointZero animated:YES];
- }
- // if (textView.text.length > 50)
- // {
- // textView.text = [textView.text substringToIndex:50];
- // // [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlert:@"不能超过50个字"];
- // [self.view endEditing:YES];
- // [KPromptBox showKPromptBoxWithMassage:@"不能超过50个字符!"];
- // }
-
- }
- - (void)changeFrame:(CGFloat)height{
- CGRect textViewFrame = _remark.frame;
- textViewFrame.size.height = height;
-
- [UIView animateWithDuration:0.3 animations:^{
-
- _remark.frame = textViewFrame;
-
- }];
- }
- #pragma mark - UITextField Delegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- // 辞去TextField响应,来隐藏键盘
- [textField resignFirstResponder];
- return YES;
- }
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
- _isTF = 1;
- _currentTF = textField;
-
- if (textField.tag == 1004 || textField.tag == 1005 || textField.tag == 1006) {
- [_clientName resignFirstResponder];
- [_shortName resignFirstResponder];
- [_addressName resignFirstResponder];
- [_contactMan resignFirstResponder];
- [_position resignFirstResponder];
- [_contactTel resignFirstResponder];
- [_email resignFirstResponder];
- }
-
- if (textField.tag == 1004)
- {
- ClientKindVC *ckVC = [[ClientKindVC alloc]init];
- ckVC.block = ^(NSString *nameStr){
- _clientKind.text = nameStr;
- };
- [self.navigationController pushViewController:ckVC animated:YES];
- return NO;
- }
- if (textField.tag == 1005)
- {
- ShareSelectVC *shareSelectVC = [[ShareSelectVC alloc]init];
- shareSelectVC.titleStr = @"所属地区";
- shareSelectVC.block = ^(NSDictionary *listData){
- DLog(@"返回来的数据是什么:%@",listData);
- _belongWhere.text = [NSString stringWithFormat:@"%@",listData];
- };
- [self.navigationController pushViewController:shareSelectVC animated:YES];
- return NO;
- }
- if (textField.tag == 1006)
- {
- PaymentsVC *pmVC = [[PaymentsVC alloc]init];
- pmVC.block = ^(NSString *payments,NSString *paymentCode){
- _getMoneyKind.text = payments;
- _pmCode = paymentCode;
- };
- [self.navigationController pushViewController:pmVC animated:YES];
- [textField resignFirstResponder];
- return NO;
- }
- if (textField.tag == 1007)
- {
- SalemanSelectVC *saleVC = [[SalemanSelectVC alloc]init];
- saleVC.block = ^(NSString *nameStr){
- _saleMan.text = nameStr;
- };
- saleVC.block2 = ^(NSString *codeStr){
- _sellerCode = codeStr;
- };
- [self.navigationController pushViewController:saleVC animated:YES];
- return NO;
- }
-
- return YES;
- }
- /*
- -(void)textFiledEditChanged:(NSNotification *)obj{
- UITextField *textField = (UITextField *)obj.object;
-
- NSString *toBeString = textField.text;
- NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage]; // 键盘输入模式
- if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写
- UITextRange *selectedRange = [textField markedTextRange];
- //获取高亮部分
- UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
- // 没有高亮选择的字,则对已输入的文字进行字数统计和限制
- if (!position) {
- if (textField.tag == 1001)
- {
- if (toBeString.length > 16)
- {
- textField.text = [toBeString substringToIndex:16];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过16个字符"];
- }
- }
- else if (textField.tag == 1002)
- {
- if (toBeString.length > 16)
- {
- textField.text = [toBeString substringToIndex:16];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过16个字符"];
- }
- }
- else if (textField.tag == 1003)
- {
- if (toBeString.length > 16)
- {
- textField.text = [toBeString substringToIndex:16];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过16个字符"];
- }
- }
- else if (textField.tag == 1008)
- {
- if (toBeString.length > 6)
- {
- textField.text = [toBeString substringToIndex:6];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过6个字符"];
- }
- }
- else if (textField.tag == 1009)
- {
- if (toBeString.length > 33)
- {
- textField.text = [toBeString substringToIndex:33];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过33个字符"];
- }
- }
- else if (textField.tag == 1010)
- {
- if (toBeString.length > 33)
- {
- textField.text = [toBeString substringToIndex:33];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过33个字符"];
- }
- }
- else if (textField.tag == 1011)
- {
- if (toBeString.length > 66)
- {
- textField.text = [toBeString substringToIndex:66];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过66个字符"];
- }
- }
- }
- // 有高亮选择的字符串,则暂不对文字进行统计和限制
- else
- {
- }
- }
- // 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况
- else
- {
- if (textField.tag == 1001)
- {
- if (toBeString.length > 50)
- {
- textField.text = [toBeString substringToIndex:50];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过50个字符"];
- }
- }
- else if (textField.tag == 1002)
- {
- if (toBeString.length > 50)
- {
- textField.text = [toBeString substringToIndex:50];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过50个字符"];
- }
- }
- else if (textField.tag == 1003)
- {
- if (toBeString.length > 50)
- {
- textField.text = [toBeString substringToIndex:50];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过50个字符"];
- }
- }
- else if (textField.tag == 1008)
- {
- if (toBeString.length > 100)
- {
- textField.text = [toBeString substringToIndex:100];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过100个字符"];
- }
- }
- else if (textField.tag == 1009)
- {
- if (toBeString.length > 100)
- {
- textField.text = [toBeString substringToIndex:100];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过100个字符"];
- }
- }
- else if (textField.tag == 1010)
- {
- if (toBeString.length > 100)
- {
- textField.text = [toBeString substringToIndex:100];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过100个字符"];
- }
- }
- else if (textField.tag == 1011)
- {
- if (toBeString.length > 200)
- {
- textField.text = [toBeString substringToIndex:200];
- [self.view endEditing: YES];
- [KPromptBox showKPromptBoxWithMassage:@"不能超过200个字符"];
- }
- }
- }
- }
- */
-
- -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
- {
- // self.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
- return YES;
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
-
- if (textField.tag == 1010){
- return [self validateNumber2:string];
- }
- else{
- if ([string isEqualToString:@" "]) {
- return NO;
- }
- else
- return YES;
- }
- }
- //只能输入数字 -- 电话
- - (BOOL)validateNumber2:(NSString*)number {
- BOOL res = YES;
- NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789-"];
- int i = 0;
- while (i < number.length) {
- NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
- NSRange range = [string rangeOfCharacterFromSet:tmpSet];
- if (range.length == 0) {
- res = NO;
- break;
- }
- i++;
- }
- return res;
- }
- -(UITextField *)creatTextFieldwith:(int)num plach:(NSString *)title
- {
- int width = _scrollV.frame.size.width-105-5;
- UITextField *tf = [[UITextField alloc]init];
-
- tf.frame = CGRectMake(115, 10+40*num, width-10, 30);
-
- tf.tag = 1000+num;
- tf.returnKeyType = UIReturnKeyDone;
- tf.borderStyle = UITextBorderStyleRoundedRect;
- tf.backgroundColor = [UIColor clearColor];
- tf.delegate = self;
- tf.placeholder = title;
- tf.font = FONT_SIZE(13);
- [_scrollV addSubview:tf];
- return tf;
- }
- #pragma mark - 键盘显示隐藏
- #pragma mark 键盘显示
- - (void)keyboardWillShow:(NSNotification *)notification{
-
- // 1.取得键盘最后的frame
- CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
- CGFloat height = keyboardFrame.origin.y;
- //2.计算控制器的view需要移动的距离
- //这里设定tableView的一个cell的高度是50
- CGFloat textField_maxY;
- if (_isTF == 0) {
- textField_maxY = (_remark.tag + 1) * 40 + 30;
- }else {
- textField_maxY = (_currentTF.tag-1000 + 1) * 45 +10;
-
- }
- //考虑tableView已经滚动位置
- CGFloat space = - _scrollV.contentOffset.y + textField_maxY;
- //得出键盘距离输入框的间距
- CGFloat transformY = height - space;
-
- DLog(@"%f",transformY);
- //3.当键盘会挡到输入框的时候就开始移动,不然不移动。有时候要考虑导航栏要+64
- if (transformY < 0) {
- transformY -= 70;
- [_scrollV mas_updateConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.equalTo(self.view);
- make.top.equalTo(self.view).offset(transformY);
- }];
- }
- }
- #pragma mark 键盘隐藏
- - (void)keyboardWillHide:(NSNotification *)notification {
- [_scrollV mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.left.bottom.right.equalTo(self.view);
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:@"hideBottomView" object:nil];
- }
- -(void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- if (scrollView.tag == 1000) {
- [self.view endEditing:YES];
- }
- }
- -(void)backAction
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- @end
|