JXAddDepartViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. //
  2. // JXAddDepartViewController.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 17/5/16.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "JXAddDepartViewController.h"
  9. //#import "selectTreeVC.h"
  10. //#import "selectValueVC.h"
  11. //#import "selectProvinceVC.h"
  12. //#import "ImageResize.h"
  13. //#import "roomData.h"
  14. //#import "JXUserInfoVC.h"
  15. //#import "JXSelFriendVC.h"
  16. //#import "JXRoomObject.h"
  17. //#import "JXChatViewController.h"
  18. //#import "JXRoomPool.h"
  19. //#import "DepartObject.h"
  20. #define HEIGHT 50
  21. #define IMGSIZE 170
  22. static NSString *cellID = @"SearchCellID";
  23. @interface JXAddDepartViewController ()<UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource>{
  24. UITextField* _desc;
  25. UILabel* _userName;
  26. UITextField* _roomName;
  27. UILabel* _size;
  28. // JXRoomObject *_chatRoom;
  29. roomData* _room;
  30. UIView *seekBackView;
  31. UITextField* _searchCompany;
  32. }
  33. //@property (nonatomic,strong) JXRoomObject* chatRoom;
  34. @property (nonatomic,strong) NSString* userNickname;
  35. @property (nonatomic,strong) JXTableView *searchTableView;
  36. @property (nonatomic,strong) NSMutableArray *companyArr;
  37. @property (nonatomic,strong) UIButton *creatBut;
  38. @end
  39. @implementation JXAddDepartViewController
  40. -(instancetype)init{
  41. self = [super init];
  42. if (self) {
  43. self.heightHeader = JX_SCREEN_TOP;
  44. self.heightFooter = 0;
  45. // self.title = Localized(@"JXAddDepartVC_AddDepart");
  46. self.tableBody.backgroundColor = THEMEBACKCOLOR;
  47. self.isFreeOnClose = YES;
  48. self.isGotoBack = YES;
  49. }
  50. return self;
  51. }
  52. - (void)viewDidLoad {
  53. [super viewDidLoad];
  54. self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  55. [self createHeadAndFoot];
  56. if (_type == OrganizAddDepartment) {
  57. [self createDepartmentView];
  58. }else if (_type == OrganizAddCompany) {
  59. [self createCompanyView];
  60. }else if (_type == OrganizUpdateDepartmentName) {
  61. [self updateDepartmentNameView];
  62. }else if (_type == OrganizSearchCompany){
  63. [self searchCompany];
  64. }else if (_type == OrganizUpdateCompanyName){
  65. [self updateCompanyNameView];
  66. }else if (_type == OrganizModifyEmployeePosition){
  67. [self modifyEmployeePosition];
  68. }
  69. // //iv = [self createButton:Localized(@"JX_RoomExplain") drawTop:NO drawBottom:YES must:NO click:nil];
  70. // iv = [self createButton:@"根部门名称" drawTop:NO drawBottom:YES must:NO click:nil];
  71. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  72. // //_desc = [self createTextField:iv default:_room.desc hint:Localized(@"JXNewRoomVC_InputExplain") type:0];
  73. // _desc = [self createTextField:iv default:_room.desc hint:@"请输入根部门名称" type:0];
  74. // h+=iv.frame.size.height;
  75. // iv = [self createButton:Localized(@"JXRoomMemberVC_CreatPer") drawTop:NO drawBottom:YES must:NO click:nil];
  76. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  77. // _userName = [self createLabel:iv default:g_myself.userNickname];
  78. // h+=iv.frame.size.height;
  79. // iv = [self createButton:@"请选择部门成员" drawTop:NO drawBottom:YES must:NO click:@selector(hideKeyboard)];
  80. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  81. // //_size = [self createLabel:iv default:[NSString stringWithFormat:@"%d/%d",_room.curCount,_room.maxCount]];
  82. // h+=iv.frame.size.height;
  83. // iv = [self createButton:@"请指定部门管理员" drawTop:NO drawBottom:YES must:NO click:@selector(hideKeyboard)];
  84. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  85. //
  86. // h+=iv.frame.size.height;
  87. }
  88. - (void)searchCompany{
  89. self.title = Localized(@"JXAddDepart_search");
  90. //搜索输入框
  91. seekBackView = [[UIView alloc] initWithFrame:CGRectMake(10, 5, self.tableHeader.frame.size.width-10-10, 31)];
  92. seekBackView.backgroundColor = [UIColor lightGrayColor];
  93. seekBackView.layer.masksToBounds = YES;
  94. seekBackView.layer.cornerRadius = 16;
  95. [self.tableBody addSubview:seekBackView];
  96. self.companyArr = [NSMutableArray array];
  97. _searchCompany = [[UITextField alloc] initWithFrame:CGRectMake(5, 1, seekBackView.frame.size.width-5-25-5, 29)];
  98. //_seekTextField.backgroundColor = [UIColor lightGrayColor];
  99. _searchCompany.placeholder = Localized(@"JX_EnterKeyword");
  100. _searchCompany.delegate = self;
  101. [_searchCompany setTextColor:[UIColor whiteColor]];
  102. [_searchCompany setFont:SYSFONT(14)];
  103. [_searchCompany setTintColor:[UIColor whiteColor]];
  104. _searchCompany.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  105. _searchCompany.returnKeyType = UIReturnKeyGoogle;
  106. [seekBackView addSubview:_searchCompany];
  107. UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
  108. but.frame = CGRectMake(seekBackView.frame.size.width-30, 4, 25, 25);
  109. [but setImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
  110. // [but setImage:[UIImage imageNamed:@"abc_ic_search_api_mtrl_alpha"] forState:UIControlStateHighlighted];
  111. [but addTarget:self action:@selector(onSearch) forControlEvents:UIControlEventTouchUpInside];
  112. [seekBackView addSubview:but];
  113. _creatBut = [UIButton buttonWithType:UIButtonTypeCustom];
  114. _creatBut.frame = CGRectMake((JX_SCREEN_WIDTH-100)/2, 41, 100, 25);
  115. [_creatBut setTitle:Localized(@"OrgaVC_CreateCompany") forState:UIControlStateNormal];
  116. [_creatBut setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  117. _creatBut.titleLabel.font = SYSFONT(14);
  118. [_creatBut addTarget:self action:@selector(creatBut:) forControlEvents:UIControlEventTouchUpInside];
  119. //_creatBut.hidden = YES;
  120. [self.tableBody addSubview:_creatBut];
  121. _searchTableView = [[JXTableView alloc]initWithFrame:CGRectMake(0, 71, JX_SCREEN_WIDTH, self.tableBody.frame.size.height-71)];
  122. _searchTableView.backgroundColor = [UIColor whiteColor];
  123. _searchTableView.alpha = 0.97;
  124. _searchTableView.delegate = self;
  125. _searchTableView.dataSource = self;
  126. _searchTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  127. _searchTableView.hidden = YES;
  128. [self.tableBody addSubview:_searchTableView];
  129. }
  130. - (void)onSearch{
  131. if ([self checkInput:_searchCompany.text]) {
  132. [g_server seachCompany:_searchCompany.text toView:self];
  133. }
  134. }
  135. - (void)creatBut:(UIButton *)but{
  136. seekBackView.hidden = YES;
  137. but.hidden = YES;
  138. _searchTableView.hidden = YES;
  139. [self createCompanyView];
  140. }
  141. -(void)createDepartmentView{
  142. self.title = Localized(@"JXAddDepartVC_AddDepart");
  143. int h = 0;
  144. JXImageView* iv;
  145. iv = [[JXImageView alloc]init];
  146. iv.frame = self.tableBody.bounds;
  147. iv.delegate = self;
  148. iv.didTouch = @selector(hideKeyboard);
  149. [self.tableBody addSubview:iv];
  150. iv = [self createButton:Localized(@"JXAddDepartVC_DepartName") drawTop:NO drawBottom:YES must:NO click:nil];
  151. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  152. _roomName = [self createTextField:iv default:nil hint:Localized(@"JXAddDepartVC_DepartPlacehold") type:1];
  153. h+=iv.frame.size.height;
  154. h+=INSETS;
  155. UIButton* _btn;
  156. _btn = [UIFactory createCommonButton:Localized(@"JXAddDepartVC_AddDepart") target:self action:@selector(onCreateDepartment)];
  157. _btn.layer.cornerRadius = 7;
  158. _btn.clipsToBounds = YES;
  159. _btn.titleLabel.font = SYSFONT(16);
  160. _btn.frame = CGRectMake(15,h+20,JX_SCREEN_WIDTH-30,40);
  161. [self.tableBody addSubview:_btn];
  162. }
  163. -(void)createCompanyView{
  164. self.title = Localized(@"JXAddDepartVC_AddCompany");
  165. int h = 0;
  166. JXImageView* iv;
  167. iv = [[JXImageView alloc]init];
  168. iv.frame = self.tableBody.bounds;
  169. iv.delegate = self;
  170. iv.didTouch = @selector(hideKeyboard);
  171. [self.tableBody addSubview:iv];
  172. iv = [self createButton:Localized(@"JXAddDepartVC_CompName") drawTop:NO drawBottom:YES must:NO click:nil];
  173. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  174. _roomName = [self createTextField:iv default:nil hint:Localized(@"JXAddDepartVC_CompPlacehold") type:1];
  175. h+=iv.frame.size.height;
  176. h+=INSETS;
  177. UIButton* _btn;
  178. _btn = [UIFactory createCommonButton:Localized(@"JXAddDepartVC_AddCompany") target:self action:@selector(onCreateCompany)];
  179. _btn.custom_acceptEventInterval = .25f;
  180. _btn.layer.cornerRadius = 7;
  181. _btn.clipsToBounds = YES;
  182. _btn.titleLabel.font = SYSFONT(16);
  183. _btn.frame = CGRectMake(15,h+20,JX_SCREEN_WIDTH-30,40);
  184. [self.tableBody addSubview:_btn];
  185. }
  186. -(void)updateDepartmentNameView{
  187. self.title = _oldName;
  188. int h = 0;
  189. JXImageView* iv;
  190. iv = [[JXImageView alloc]init];
  191. iv.frame = self.tableBody.bounds;
  192. iv.delegate = self;
  193. iv.didTouch = @selector(hideKeyboard);
  194. [self.tableBody addSubview:iv];
  195. iv = [self createButton:Localized(@"JXAddDepartVC_UpdateDepart") drawTop:NO drawBottom:YES must:NO click:nil];
  196. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  197. _roomName = [self createTextField:iv default:_oldName hint:nil type:1];
  198. h+=iv.frame.size.height;
  199. h+=INSETS;
  200. UIButton* _btn;
  201. _btn = [UIFactory createCommonButton:Localized(@"JXAddDepartVC_UpdateDepart") target:self action:@selector(onUpdateDepartmentName)];
  202. _btn.layer.cornerRadius = 7;
  203. _btn.clipsToBounds = YES;
  204. _btn.titleLabel.font = SYSFONT(16);
  205. _btn.frame = CGRectMake(15,h+20,JX_SCREEN_WIDTH-30,40);
  206. [self.tableBody addSubview:_btn];
  207. }
  208. -(void)updateCompanyNameView{
  209. self.title = _oldName;
  210. int h = 0;
  211. JXImageView* iv;
  212. iv = [[JXImageView alloc]init];
  213. iv.frame = self.tableBody.bounds;
  214. iv.delegate = self;
  215. iv.didTouch = @selector(hideKeyboard);
  216. [self.tableBody addSubview:iv];
  217. iv = [self createButton:Localized(@"JXAddDepartVC_UpdateCompany") drawTop:NO drawBottom:YES must:NO click:nil];
  218. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  219. _roomName = [self createTextField:iv default:_oldName hint:nil type:1];
  220. h+=iv.frame.size.height;
  221. h+=INSETS;
  222. UIButton* _btn;
  223. _btn = [UIFactory createCommonButton:Localized(@"JXAddDepartVC_UpdateCompany") target:self action:@selector(onUpdateCompanyName)];
  224. _btn.layer.cornerRadius = 7;
  225. _btn.clipsToBounds = YES;
  226. _btn.titleLabel.font = SYSFONT(16);
  227. _btn.frame = CGRectMake(15,h+20,JX_SCREEN_WIDTH-30,40);
  228. [self.tableBody addSubview:_btn];
  229. }
  230. -(void)modifyEmployeePosition{
  231. self.title = _oldName;
  232. int h = 0;
  233. JXImageView* iv;
  234. iv = [[JXImageView alloc]init];
  235. iv.frame = self.tableBody.bounds;
  236. iv.delegate = self;
  237. iv.didTouch = @selector(hideKeyboard);
  238. [self.tableBody addSubview:iv];
  239. iv = [self createButton:Localized(@"OrgaVC_ModifyEmployeePosition") drawTop:NO drawBottom:YES must:NO click:nil];
  240. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  241. _roomName = [self createTextField:iv default:_oldName hint:nil type:1];
  242. h+=iv.frame.size.height;
  243. h+=INSETS;
  244. UIButton* _btn;
  245. _btn = [UIFactory createCommonButton:Localized(@"OrgaVC_ModifyEmployeePosition") target:self action:@selector(onUpdateCompanyName)];
  246. _btn.layer.cornerRadius = 7;
  247. _btn.clipsToBounds = YES;
  248. _btn.titleLabel.font = SYSFONT(16);
  249. _btn.frame = CGRectMake(15,h+20,JX_SCREEN_WIDTH-30,40);
  250. [self.tableBody addSubview:_btn];
  251. }
  252. #pragma mark - action
  253. -(BOOL)hideKeyboard{
  254. BOOL b = _roomName.editing || _desc.editing;
  255. [self.view endEditing:YES];
  256. return b;
  257. }
  258. -(void)onCreateDepartment{
  259. if ([_roomName.text isEqualToString:@""]) {
  260. [g_App showAlert:Localized(@"JX_InputRoomName")];
  261. }else if ([_desc.text isEqualToString:@""]){
  262. [g_App showAlert:Localized(@"JXNewRoomVC_InputExplain")];
  263. }else{
  264. _roomName.text = [_roomName.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  265. if (_roomName.text.length <= 0) {
  266. [JXMyTools showTipView:@"请输入有效部门名"];
  267. return;
  268. }
  269. if(self.delegate != nil && [self.delegate respondsToSelector:@selector(inputDelegateType:text:)])
  270. [self.delegate inputDelegateType:_type text:_roomName.text];
  271. [self actionQuit];
  272. }
  273. }
  274. -(void)onCreateCompany{
  275. if (_roomName.text.length <= 0) {
  276. [g_App showAlert:Localized(@"JXAddDepartVC_CompPlacehold")];
  277. return;
  278. }
  279. _roomName.text = [_roomName.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  280. if (_roomName.text.length <= 0) {
  281. [JXMyTools showTipView:@"请输入有效公司名"];
  282. return;
  283. }
  284. if(self.delegate != nil && [self.delegate respondsToSelector:@selector(inputDelegateType:text:)])
  285. [self.delegate inputDelegateType:_type text:_roomName.text];
  286. [self actionQuit];
  287. }
  288. -(void)onUpdateDepartmentName{
  289. if(self.delegate != nil && [self.delegate respondsToSelector:@selector(inputDelegateType:text:)])
  290. [self.delegate inputDelegateType:_type text:_roomName.text];
  291. [self actionQuit];
  292. }
  293. -(void)onUpdateCompanyName{
  294. if(self.delegate != nil && [self.delegate respondsToSelector:@selector(inputDelegateType:text:)])
  295. [self.delegate inputDelegateType:_type text:_roomName.text];
  296. [self actionQuit];
  297. }
  298. - (void)didReceiveMemoryWarning {
  299. [super didReceiveMemoryWarning];
  300. // Dispose of any resources that can be recreated.
  301. }
  302. -(JXImageView*)createButton:(NSString*)title drawTop:(BOOL)drawTop drawBottom:(BOOL)drawBottom must:(BOOL)must click:(SEL)click{
  303. JXImageView* btn = [[JXImageView alloc] init];
  304. btn.backgroundColor = [UIColor whiteColor];
  305. btn.userInteractionEnabled = YES;
  306. if(click)
  307. btn.didTouch = click;
  308. else
  309. btn.didTouch = @selector(hideKeyboard);
  310. btn.delegate = self;
  311. [self.tableBody addSubview:btn];
  312. // [btn release];
  313. if(must){
  314. UILabel* p = [[UILabel alloc] initWithFrame:CGRectMake(INSETS, 5, 20, HEIGHT-5)];
  315. p.text = @"*";
  316. p.font = g_factory.font18;
  317. p.backgroundColor = [UIColor clearColor];
  318. p.textColor = [UIColor redColor];
  319. p.textAlignment = NSTextAlignmentCenter;
  320. [btn addSubview:p];
  321. // [p release];
  322. }
  323. JXLabel* p = [[JXLabel alloc] initWithFrame:CGRectMake(15, 0, 130, HEIGHT)];
  324. p.text = title;
  325. p.font = g_factory.font15;
  326. p.backgroundColor = [UIColor clearColor];
  327. p.textColor = [UIColor blackColor];
  328. [btn addSubview:p];
  329. // [p release];
  330. if(drawTop){
  331. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(0,0,JX_SCREEN_WIDTH,LINE_WH)];
  332. line.backgroundColor = THE_LINE_COLOR;
  333. [btn addSubview:line];
  334. // [line release];
  335. }
  336. if(drawBottom){
  337. UIView* line = [[UIView alloc]initWithFrame:CGRectMake(0,HEIGHT-0.5,JX_SCREEN_WIDTH,LINE_WH)];
  338. line.backgroundColor = THE_LINE_COLOR;
  339. [btn addSubview:line];
  340. // [line release];
  341. }
  342. if(click){
  343. UIImageView* iv;
  344. iv = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-15-7, (HEIGHT-13)/2, 7, 13)];
  345. iv.image = [UIImage imageNamed:@"new_icon_>"];
  346. [btn addSubview:iv];
  347. // [iv release];
  348. }
  349. return btn;
  350. }
  351. -(UITextField*)createTextField:(UIView*)parent default:(NSString*)s hint:(NSString*)hint type:(BOOL)name{
  352. UITextField* p = [[UITextField alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2,INSETS,JX_SCREEN_WIDTH/2-15,HEIGHT-INSETS*2)];
  353. p.delegate = self;
  354. p.autocorrectionType = UITextAutocorrectionTypeNo;
  355. p.autocapitalizationType = UITextAutocapitalizationTypeNone;
  356. p.enablesReturnKeyAutomatically = YES;
  357. p.borderStyle = UITextBorderStyleNone;
  358. p.returnKeyType = UIReturnKeyDone;
  359. p.clearButtonMode = UITextFieldViewModeWhileEditing;
  360. p.textAlignment = NSTextAlignmentRight;
  361. p.userInteractionEnabled = YES;
  362. if (s)
  363. p.text = s;
  364. if (hint)
  365. p.placeholder = hint;
  366. p.font = g_factory.font14;
  367. if (name) {
  368. [p addTarget:self action:@selector(textLong12:) forControlEvents:UIControlEventEditingChanged];
  369. }else{
  370. [p addTarget:self action:@selector(textLong32:) forControlEvents:UIControlEventEditingChanged];
  371. }
  372. [parent addSubview:p];
  373. // [p release];
  374. return p;
  375. }
  376. - (void)textLong12:(UITextField *)textField
  377. {
  378. [self validationText:textField length:12];
  379. }
  380. - (void)textLong32:(UITextField *)textField
  381. {
  382. [self validationText:textField length:32];
  383. }
  384. //过滤非法字符
  385. - (NSString *)disable_Text:(NSString *)text
  386. {
  387. NSLog(@"过滤--->%@",text);
  388. text = [text stringByReplacingOccurrencesOfString:@" " withString:@""];
  389. text = [text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  390. //过滤emoji表情
  391. return [self disable_emoji:text];
  392. }
  393. //过滤emoj表情
  394. - (NSString *)disable_emoji:(NSString *)text
  395. {
  396. NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]" options:NSRegularExpressionCaseInsensitive error:nil];
  397. NSString *modifiedString = [regex stringByReplacingMatchesInString:text
  398. options:0
  399. range:NSMakeRange(0, [text length])
  400. withTemplate:@""];
  401. return modifiedString;
  402. }
  403. - (NSString *)validationText:(UITextField *)textField length:(int)length
  404. {
  405. //不论中文英文,如果有空格,回车,都要过滤掉
  406. NSString *toBeString = [self disable_Text:textField.text];
  407. NSString *lang = [textField.textInputMode primaryLanguage];
  408. NSLog(@"%@",lang);
  409. //判断输入法
  410. if ([lang isEqualToString:@"zh-Hans"]) {
  411. UITextRange *selectedRange = [textField markedTextRange];
  412. UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
  413. if (!position) {
  414. if (toBeString.length>=length) {
  415. NSString *strNew = [NSString stringWithString:toBeString];
  416. [textField setText:[strNew substringToIndex:length]];
  417. }else{
  418. [textField setText:toBeString];
  419. }
  420. }
  421. else
  422. {
  423. NSLog(@"输入的英文还没有转化为汉字的状态");
  424. }
  425. }
  426. else{
  427. if (toBeString.length > length) {
  428. textField.text = [toBeString substringToIndex:length];
  429. }else{
  430. textField.text = toBeString;
  431. }
  432. }
  433. return textField.text;
  434. }
  435. -(UILabel*)createLabel:(UIView*)parent default:(NSString*)s{
  436. UILabel* p = [[UILabel alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2,INSETS,JX_SCREEN_WIDTH/2 - INSETS,HEIGHT-INSETS*2)];
  437. p.userInteractionEnabled = NO;
  438. p.text = s;
  439. p.font = g_factory.font14;
  440. p.textAlignment = NSTextAlignmentRight;
  441. [parent addSubview:p];
  442. // [p release];
  443. return p;
  444. }
  445. #pragma mark----UITableViewDelegate
  446. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  447. return 1;
  448. }
  449. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  450. return self.companyArr.count;
  451. }
  452. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  453. UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  454. if (cell == nil) {
  455. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  456. }
  457. NSDictionary *dic = _companyArr[indexPath.row];
  458. cell.textLabel.text = [dic objectForKey:@"companyName"];
  459. return cell;
  460. }
  461. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  462. return 40;
  463. }
  464. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  465. }
  466. #pragma mark----UITextFieldDelegate
  467. - (void)textFieldDidBeginEditing:(UITextField *)textField{
  468. //键盘弹出
  469. self.searchTableView.hidden = YES;
  470. }
  471. - (BOOL)textFieldShouldReturn:(UITextField *)textField{
  472. //[self hideKeBoard:nil];
  473. [textField resignFirstResponder];
  474. if (textField == _searchCompany) {
  475. [self onSearch];
  476. }
  477. return YES;
  478. }
  479. - (BOOL)checkInput:(NSString *)name{
  480. if ([name length] <= 0) {
  481. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:Localized(@"JX_ContentEmpty") delegate:self cancelButtonTitle:Localized(@"OK") otherButtonTitles: nil];
  482. [alertView show];
  483. // [alertView release];
  484. return NO;
  485. }
  486. return YES;
  487. }
  488. #pragma mark -数据请求
  489. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  490. [_wait stop];
  491. if ([aDownload.action isEqualToString:act_seachCompany]) {
  492. if (array1) {
  493. self.searchTableView.hidden = NO;
  494. [_companyArr addObjectsFromArray:array1];
  495. [_searchTableView reloadData];
  496. }else{
  497. [g_App showAlert:Localized(@"JXAddDepart_notFind")];
  498. }
  499. }
  500. }
  501. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  502. [_wait hide];
  503. return show_error;
  504. }
  505. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  506. [_wait hide];
  507. return show_error;
  508. }
  509. -(void) didServerConnectStart:(JXConnection*)aDownload{
  510. [_wait start];
  511. }
  512. @end