OrganizTreeViewController.m 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  1. //
  2. // OrganizTreeViewController.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 17/5/11.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "OrganizTreeViewController.h"
  9. #import "DepartObject.h"
  10. #import "EmployeObject.h"
  11. #import "RATreeView.h"
  12. #import "OrganizTableViewCell.h"
  13. #import "EmployeeTableViewCell.h"
  14. #import "JX_DownListView.h"
  15. #import "JXAddDepartViewController.h"
  16. #import "JXSelFriendVC.h"
  17. #import "JXSelectFriendsVC.h"
  18. #import "JXUserInfoVC.h"
  19. #import "JXSelDepartViewController.h"
  20. @interface OrganizTreeViewController ()<RATreeViewDelegate, RATreeViewDataSource,AddDepartDelegate,SelDepartDelegate,UIAlertViewDelegate,UITextFieldDelegate,UITextViewDelegate>
  21. @property (nonatomic, strong) NSMutableArray<DepartObject *> * dataArray;
  22. @property (nonatomic, weak) RATreeView * treeView;
  23. @property (nonatomic, strong) UIButton * moreButton;
  24. @property (atomic, strong) id currentOrgObj;
  25. @property (nonatomic, assign) BOOL afterDelCompany;
  26. @property (nonatomic, strong) UIControl * control;
  27. @property (nonatomic, strong) NSMutableDictionary * allDataDict;
  28. @property (nonatomic, strong) NSMutableDictionary * employeesDict;
  29. @property (nonatomic, strong) NSMutableDictionary * companyDict;
  30. @property (nonatomic, strong) NSMutableDictionary * noticeDict;
  31. @property (nonatomic, copy) NSString * companyId;
  32. @property (nonatomic, copy) NSString * companyName;
  33. @property (nonatomic, copy) void (^rowActionAfterRequestBlock)(id sender);
  34. @property (nonatomic, strong) UIView * noCompanyView;
  35. @property (atomic, strong) id item;
  36. @property (nonatomic, assign) BOOL isNotDele;
  37. @property (nonatomic, strong) UIView *bigView;
  38. @property (nonatomic, strong) UIView *baseView;
  39. @property (nonatomic, strong) UIView *topView;
  40. @property (nonatomic, strong) UILabel *replayTitle;
  41. @property (nonatomic, strong) UITextView *replayTextView;
  42. @property (nonatomic, strong) NSMutableDictionary *curAddDepObj;
  43. @end
  44. @implementation OrganizTreeViewController
  45. - (id)init
  46. {
  47. self = [super init];
  48. if (self) {
  49. self.heightHeader = JX_SCREEN_TOP;
  50. self.heightFooter = 0;
  51. self.title = Localized(@"OrganizVC_Organiz");
  52. self.isFreeOnClose = YES;
  53. self.isGotoBack = YES;
  54. #ifdef Live_Version
  55. self.isGotoBack = YES;
  56. self.heightFooter = 0;
  57. #endif
  58. _dataArray = [NSMutableArray new];
  59. _allDataDict = [NSMutableDictionary new];
  60. _employeesDict = [NSMutableDictionary new];
  61. _companyDict = [NSMutableDictionary new];
  62. [self createTreeView];
  63. [self setupReplayView];
  64. [g_server getCompanyAuto:self];
  65. }
  66. return self;
  67. }
  68. - (void)viewDidLoad {
  69. [super viewDidLoad];
  70. [self createHeadAndFoot];
  71. _moreButton = [UIFactory createButtonWithImage:@"msg_right_icon" highlight:nil target:self selector:@selector(onMore:)];
  72. _moreButton.frame = CGRectMake(JX_SCREEN_WIDTH-18-15, JX_SCREEN_TOP -15-18, 18, 18);
  73. [self.tableHeader addSubview:_moreButton];
  74. }
  75. - (void)viewWillAppear:(BOOL)animated {
  76. [super viewWillAppear:animated];
  77. [_treeView reloadRows];
  78. }
  79. - (void)setupReplayView {
  80. int height = 44;
  81. self.bigView = [[UIView alloc] initWithFrame:self.view.bounds];
  82. self.bigView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
  83. self.bigView.hidden = YES;
  84. [g_App.window addSubview:self.bigView];
  85. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard)];
  86. [self.bigView addGestureRecognizer:tap];
  87. self.baseView = [[UIView alloc] initWithFrame:CGRectMake(40, JX_SCREEN_HEIGHT/4-.5, JX_SCREEN_WIDTH-80, 162.5)];
  88. self.baseView.backgroundColor = [UIColor whiteColor];
  89. self.baseView.layer.masksToBounds = YES;
  90. self. baseView.layer.cornerRadius = 4.0f;
  91. [self.bigView addSubview:self.baseView];
  92. int n = 20;
  93. _replayTitle = [[UILabel alloc] initWithFrame:CGRectMake(INSETS, n, self.baseView.frame.size.width - INSETS*2, 20)];
  94. _replayTitle.lineBreakMode = NSLineBreakByTruncatingTail;
  95. _replayTitle.textColor = HEXCOLOR(0x333333);
  96. _replayTitle.font = SYSFONT(16);
  97. _replayTitle.text = @"公司公告";
  98. [self.baseView addSubview:_replayTitle];
  99. n = n + height;
  100. self.replayTextView = [self createTextField:self.baseView default:nil hint:nil];
  101. self.replayTextView.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1];
  102. self.replayTextView.frame = CGRectMake(10, n, self.baseView.frame.size.width - INSETS*2, 35.5);
  103. self.replayTextView.delegate = self;
  104. self.replayTextView.textColor = HEXCOLOR(0x595959);
  105. n = n + INSETS + height;
  106. self.topView = [[UIView alloc] initWithFrame:CGRectMake(0, n, self.baseView.frame.size.width, 44)];
  107. [self.baseView addSubview:self.topView];
  108. // 两条线
  109. UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.baseView.frame.size.width, LINE_WH)];
  110. topLine.backgroundColor = THE_LINE_COLOR;
  111. [self.topView addSubview:topLine];
  112. UIView *botLine = [[UIView alloc] initWithFrame:CGRectMake(self.baseView.frame.size.width/2, 0, LINE_WH, self.topView.frame.size.height)];
  113. botLine.backgroundColor = THE_LINE_COLOR;
  114. [self.topView addSubview:botLine];
  115. // 取消
  116. UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(topLine.frame), self.baseView.frame.size.width/2, botLine.frame.size.height)];
  117. [cancelBtn setTitle:Localized(@"JX_Cencal") forState:UIControlStateNormal];
  118. [cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  119. [cancelBtn.titleLabel setFont:SYSFONT(15)];
  120. [cancelBtn addTarget:self action:@selector(hideBigView) forControlEvents:UIControlEventTouchUpInside];
  121. [self.topView addSubview:cancelBtn];
  122. // 发送
  123. 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)];
  124. [sureBtn setTitle:Localized(@"JX_Send") forState:UIControlStateNormal];
  125. [sureBtn setTitleColor:HEXCOLOR(0x55BEB8) forState:UIControlStateNormal];
  126. [sureBtn.titleLabel setFont:SYSFONT(15)];
  127. [sureBtn addTarget:self action:@selector(onRelease) forControlEvents:UIControlEventTouchUpInside];
  128. [self.topView addSubview:sureBtn];
  129. }
  130. - (void)resignKeyBoard {
  131. self.bigView.hidden = YES;
  132. [self hideKeyBoard];
  133. [self resetBigView];
  134. }
  135. - (void)resetBigView {
  136. self.replayTextView.frame = CGRectMake(10, 64, self.baseView.frame.size.width - INSETS*2, 35.5);
  137. self.baseView.frame = CGRectMake(40, JX_SCREEN_HEIGHT/4-.5, JX_SCREEN_WIDTH-80, 162.5);
  138. self.topView.frame = CGRectMake(0, 118, self.baseView.frame.size.width, 40);
  139. }
  140. - (void)hideKeyBoard {
  141. if (self.replayTextView.isFirstResponder) {
  142. [self.replayTextView resignFirstResponder];
  143. }
  144. }
  145. -(UITextView*)createTextField:(UIView*)parent default:(NSString*)s hint:(NSString*)hint{
  146. UITextView* p = [[UITextView alloc] initWithFrame:CGRectMake(0,INSETS,JX_SCREEN_WIDTH,54)];
  147. p.delegate = self;
  148. p.autocorrectionType = UITextAutocorrectionTypeNo;
  149. p.autocapitalizationType = UITextAutocapitalizationTypeNone;
  150. p.enablesReturnKeyAutomatically = YES;
  151. p.scrollEnabled = NO;
  152. p.showsVerticalScrollIndicator = NO;
  153. p.showsHorizontalScrollIndicator = NO;
  154. p.textAlignment = NSTextAlignmentLeft;
  155. p.userInteractionEnabled = YES;
  156. p.backgroundColor = [UIColor whiteColor];
  157. p.text = s;
  158. p.font = g_factory.font16;
  159. [parent addSubview:p];
  160. return p;
  161. }
  162. - (void)textViewDidChange:(UITextView *)textView {
  163. static CGFloat maxHeight =66.0f;
  164. //防止输入时在中文后输入英文过长直接中文和英文换行
  165. if ([textView.text isEqualToString:@""]) {
  166. textView.textColor = [UIColor lightGrayColor];
  167. }
  168. CGRect frame = textView.frame;
  169. CGSize constraintSize = CGSizeMake(JX_SCREEN_WIDTH-80-INSETS*2, MAXFLOAT);
  170. CGSize size = [textView sizeThatFits:constraintSize];
  171. if (size.height >= maxHeight)
  172. {
  173. size.height = maxHeight;
  174. textView.scrollEnabled = YES; // 允许滚动
  175. }
  176. else
  177. {
  178. textView.scrollEnabled = NO; // 不允许滚动
  179. }
  180. textView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, size.height);
  181. NSLog(@"--------%@",NSStringFromCGRect(self.baseView.frame));
  182. self.baseView.frame = CGRectMake(40, JX_SCREEN_HEIGHT/4+35-size.height, JX_SCREEN_WIDTH-80, 162-35+size.height);
  183. self.topView.frame = CGRectMake(0, 118-35+size.height, self.baseView.frame.size.width, 40);
  184. }
  185. - (void)hideBigView {
  186. [self resignKeyBoard];
  187. }
  188. - (void)onRelease {
  189. if (_replayTextView.text.length <= 0) {
  190. [JXMyTools showTipView:@"公告不能为空"];
  191. return;
  192. }
  193. DepartObject * departObj = _currentOrgObj;
  194. __weak typeof(self) weakSelf = self;
  195. self.rowActionAfterRequestBlock = ^(id sender) {
  196. // departObj.noticeContent = weakSelf.replayTextView.text;
  197. [(NSMutableDictionary *)[weakSelf.companyDict objectForKey:departObj.companyId] setObject:weakSelf.replayTextView.text forKey:@"noticeContent"];
  198. [weakSelf.treeView reloadRowsForItems:@[departObj] withRowAnimation:RATreeViewRowAnimationNone];
  199. [weakSelf hideBigView];
  200. };
  201. [g_server updataCompanyName:nil noticeContent:self.replayTextView.text companyId:departObj.companyId toView:self];
  202. }
  203. -(void)createTreeView{
  204. self.tableBody.backgroundColor = HEXCOLOR(0xF2F2F2);
  205. RATreeView *treeView = [[RATreeView alloc] initWithFrame:self.view.bounds style:RATreeViewStylePlain];
  206. treeView.delegate = self;
  207. treeView.dataSource = self;
  208. treeView.treeFooterView = [UIView new];
  209. treeView.separatorStyle = RATreeViewCellSeparatorStyleNone;
  210. treeView.estimatedRowHeight = 0;
  211. treeView.estimatedSectionHeaderHeight = 0;
  212. treeView.estimatedSectionFooterHeight = 0;
  213. UIRefreshControl *refreshControl = [UIRefreshControl new];
  214. [refreshControl addTarget:self action:@selector(refreshControlChanged:) forControlEvents:UIControlEventValueChanged];
  215. [treeView.scrollView addSubview:refreshControl];
  216. [treeView reloadData];
  217. [treeView setBackgroundColor:[UIColor clearColor]];
  218. self.treeView = treeView;
  219. treeView.frame = self.tableBody.bounds;
  220. treeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  221. [self.tableBody addSubview:treeView];
  222. [treeView registerClass:[OrganizTableViewCell class] forCellReuseIdentifier:NSStringFromClass([OrganizTableViewCell class])];
  223. [treeView registerClass:[EmployeeTableViewCell class] forCellReuseIdentifier:NSStringFromClass([EmployeeTableViewCell class])];
  224. }
  225. #pragma mark TreeView Delegate methods
  226. - (CGFloat)treeView:(RATreeView *)treeView heightForRowForItem:(id)item
  227. {
  228. if ([item isMemberOfClass:[EmployeObject class]]) {
  229. return 60;
  230. }
  231. return 44;
  232. }
  233. //-(BOOL)treeView:(RATreeView *)treeView shouldExpandRowForItem:(id)item
  234. //{
  235. //
  236. // return YES;
  237. //}
  238. - (void)treeView:(RATreeView *)treeView willExpandRowForItem:(id)item
  239. {
  240. if ([item isMemberOfClass:[DepartObject class]]) {
  241. OrganizTableViewCell * cell = (OrganizTableViewCell *)[self.treeView cellForItem:item];
  242. cell.arrowExpand = YES;
  243. }
  244. }
  245. //- (void)treeView:(RATreeView *)treeView didExpandRowForItem:(id)item{
  246. //
  247. //}
  248. - (void)treeView:(RATreeView *)treeView willCollapseRowForItem:(id)item
  249. {
  250. if ([item isMemberOfClass:[DepartObject class]]) {
  251. OrganizTableViewCell * cell = (OrganizTableViewCell *)[self.treeView cellForItem:item];
  252. cell.arrowExpand = NO;
  253. }
  254. }
  255. #pragma mark 左划手势 -删除
  256. - (BOOL)treeView:(RATreeView *)treeView canEditRowForItem:(id)item
  257. {
  258. return NO;
  259. // NSInteger level = [self.treeView levelForCellForItem:item];
  260. // if (level == 0)
  261. // return NO;
  262. // else
  263. // return YES;
  264. }
  265. -(UITableViewCellEditingStyle)treeView:(RATreeView *)treeView editingStyleForRowForItem:(id)item{
  266. if (treeView.editing)
  267. return UITableViewCellEditingStyleNone;
  268. else
  269. return UITableViewCellEditingStyleDelete;
  270. }
  271. - (void)treeView:(RATreeView *)treeView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowForItem:(id)item
  272. {
  273. if (editingStyle != UITableViewCellEditingStyleDelete) {
  274. return;
  275. }
  276. [self deleteNodeWithItem:item];
  277. }
  278. //-(NSArray *)treeView:(RATreeView *)treeView editActionsForItem:(id)item{
  279. // DepartObject *parent = [self.treeView parentForItem:item];
  280. //
  281. // UITableViewRowAction *deleteRoWAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  282. //
  283. // if ([item isMemberOfClass:[EmployeObject class]]) {
  284. // EmployeObject * employee = item;
  285. // [g_server deleteEmployee:employee.departmentId userId:employee.userId toView:self];
  286. // }else if ([item isMemberOfClass:[DepartObject class]]) {
  287. // DepartObject * depart = item;
  288. // [g_server deleteDepartment:depart.departId toView:self];
  289. // }
  290. //
  291. // __weak typeof(self) weakSelf = self;
  292. // self.rowActionAfterRequestBlock = ^(id sender) {
  293. // NSInteger index = 0;
  294. // if (parent == nil) {
  295. // index = [self.dataArray indexOfObject:item];
  296. // NSMutableArray *children = [weakSelf.dataArray mutableCopy];
  297. // [children removeObject:item];
  298. // weakSelf.dataArray = [children copy];
  299. // } else {
  300. // index = [parent.children indexOfObject:item];
  301. // [parent removeChild:item];
  302. // }
  303. //
  304. // [weakSelf.treeView deleteItemsAtIndexes:[NSIndexSet indexSetWithIndex:index] inParent:parent withAnimation:RATreeViewRowAnimationRight];
  305. // if (parent) {
  306. // [weakSelf.treeView reloadRowsForItems:@[parent] withRowAnimation:RATreeViewRowAnimationNone];
  307. // }
  308. // };
  309. //
  310. // }];//此处是iOS8.0以后苹果最新推出的api,
  311. // UITableViewRowAction *editRowAction;
  312. // if ([item isMemberOfClass:[DepartObject class]]) {
  313. // UITableViewRowAction *changeRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"改名" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  314. // //改名
  315. // _currentOrgObj = item;
  316. // [self inputViewController:OrganizUpdateDepartmentName];
  317. //
  318. // __weak typeof(self) weakSelf = self;
  319. // self.rowActionAfterRequestBlock = ^(id sender) {
  320. // NSDictionary * dataDict = sender;
  321. // if (dataDict[@"departName"] != nil && [dataDict[@"departName"] length] >0) {
  322. // DepartObject * depart = item;
  323. // depart.departName = dataDict[@"departName"];
  324. // [weakSelf.treeView reloadRowsForItems:@[depart] withRowAnimation:RATreeViewRowAnimationNone];
  325. // }
  326. // };
  327. // }];
  328. // changeRowAction.backgroundColor = [UIColor colorWithRed:0 green:124/255.0 blue:223/255.0 alpha:1];
  329. // editRowAction = changeRowAction;
  330. // }
  331. //
  332. // if ([item isMemberOfClass:[EmployeObject class]]) {
  333. // UITableViewRowAction *modifyDpartRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"改部门" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  334. // //改部门
  335. // _currentOrgObj = item;
  336. // self.treeView.editing = YES;
  337. //
  338. //// [self inputViewController:OrganizUpdateDepartmentName];
  339. ////
  340. //// __weak typeof(self) weakSelf = self;
  341. //// self.rowActionAfterRequestBlock = ^(id sender) {
  342. //// NSDictionary * dataDict = sender;
  343. //// if (dataDict[@"departName"] != nil && [dataDict[@"departName"] length] >0) {
  344. //// DepartObject * depart = item;
  345. //// depart.departName = dataDict[@"departName"];
  346. //// [weakSelf.treeView reloadRowsForItems:@[depart] withRowAnimation:RATreeViewRowAnimationNone];
  347. //// }
  348. //// };
  349. //
  350. // }];
  351. // modifyDpartRowAction.backgroundColor = [UIColor colorWithRed:0 green:124/255.0 blue:223/255.0 alpha:1];
  352. // editRowAction = modifyDpartRowAction;
  353. // }
  354. //
  355. //
  356. // UITableViewRowAction *moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"详情" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  357. // //详情
  358. // _currentOrgObj = item;
  359. //
  360. // }];
  361. // moreRowAction.backgroundColor = [UIColor orangeColor];
  362. // return @[deleteRoWAction, editRowAction,moreRowAction];
  363. //
  364. //}
  365. -(void)treeView:(RATreeView *)treeView didSelectRowForItem:(id)item{
  366. if ([item isMemberOfClass:[EmployeObject class]]){
  367. [self showEmployeeDownListView:item];
  368. }else{
  369. DepartObject * depart = item;
  370. if (depart.children.count == 0)
  371. [JXMyTools showTipView:Localized(@"OrgaVC_DepartNoChild")];
  372. }
  373. }
  374. #pragma mark TreeView Data Source
  375. - (UITableViewCell *)treeView:(RATreeView *)treeView cellForItem:(id)item
  376. {
  377. // OrganizObject *dataObject = item;
  378. NSInteger level = [self.treeView levelForCellForItem:item];
  379. // NSInteger numberOfChildren = [dataObject.children count];
  380. // NSString *detailText = [NSString localizedStringWithFormat:@"Number of children %@", [@(numberOfChildren) stringValue]];
  381. // BOOL expanded = [self.treeView isCellForItemExpanded:item];
  382. if ([item isMemberOfClass:[DepartObject class]]) {
  383. DepartObject * dataObject = item;
  384. BOOL expanded = [self.treeView isCellForItemExpanded:item];
  385. OrganizTableViewCell * cell = [self.treeView dequeueReusableCellWithIdentifier:NSStringFromClass([OrganizTableViewCell class])];
  386. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  387. [cell setupWithData:dataObject level:level expand:expanded];
  388. cell.noticeLab.text = @"暂无公告";
  389. NSDictionary * dataObj = [_companyDict objectForKey:dataObject.companyId];
  390. if (!IsObjectNull(dataObj[@"noticeContent"])) {
  391. NSString *str = [NSString stringWithFormat:@"%@",dataObj[@"noticeContent"]];
  392. if (str.length > 0) {
  393. cell.noticeLab.text = str;
  394. }
  395. }
  396. __weak typeof(self) weakSelf = self;
  397. cell.additionButtonTapAction = ^(id sender){
  398. if (weakSelf.treeView.isEditing) {
  399. return;
  400. }
  401. [weakSelf showDepartDownListView:dataObject];
  402. };
  403. cell.noticeLabTapAction = ^(DepartObject *dataObj) {
  404. if (weakSelf.treeView.isEditing) {
  405. return;
  406. }
  407. _currentOrgObj = dataObj;
  408. weakSelf.bigView.hidden = NO;
  409. [weakSelf.replayTextView becomeFirstResponder];
  410. };
  411. return cell;
  412. }else if ([item isMemberOfClass:[EmployeObject class]]) {
  413. EmployeObject * dataObject = item;
  414. EmployeeTableViewCell * cell = [self.treeView dequeueReusableCellWithIdentifier:NSStringFromClass([EmployeeTableViewCell class])];
  415. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  416. [cell setupWithData:dataObject level:level];
  417. return cell;
  418. }
  419. return nil;
  420. }
  421. - (NSInteger)treeView:(RATreeView *)treeView numberOfChildrenOfItem:(id)item
  422. {
  423. if (item == nil) {
  424. return [self.dataArray count];
  425. }
  426. if ([item isMemberOfClass:[EmployeObject class]]) {
  427. return 0;
  428. }else{
  429. DepartObject * dataObject = item;
  430. return [dataObject.children count];
  431. }
  432. }
  433. - (id)treeView:(RATreeView *)treeView child:(NSInteger)index ofItem:(id)item
  434. {
  435. if (item == nil) {
  436. return [self.dataArray objectAtIndex:index];
  437. }
  438. if ([item isMemberOfClass:[EmployeObject class]]) {
  439. return nil;
  440. }else{
  441. DepartObject * dataObject = item;
  442. return dataObject.children[index];
  443. }
  444. }
  445. - (void)didReceiveMemoryWarning {
  446. [super didReceiveMemoryWarning];
  447. // Dispose of any resources that can be recreated.
  448. }
  449. -(void)dealloc{
  450. self.rowActionAfterRequestBlock = nil;
  451. }
  452. #pragma mark - Actions
  453. - (void)refreshControlChanged:(UIRefreshControl *)refreshControl
  454. {
  455. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  456. [refreshControl endRefreshing];
  457. });
  458. }
  459. #pragma mark 右上角更多
  460. -(void)onMore:(UIButton *)sender{
  461. // _control.hidden = YES;
  462. UIWindow *window = [[UIApplication sharedApplication].delegate window];
  463. CGRect moreFrame = [self.tableHeader convertRect:_moreButton.frame toView:window];
  464. JX_DownListView * downListView = [[JX_DownListView alloc] initWithFrame:self.view.bounds];
  465. downListView.listContents = @[Localized(@"OrgaVC_CreateNewCompany")];
  466. downListView.listImages = @[@"organize_add"];
  467. downListView.textColor = HEXCOLOR(0x333333);
  468. downListView.color = [UIColor whiteColor];
  469. __weak typeof(self) weakSelf = self;
  470. [downListView downlistPopOption:^(NSInteger index, NSString *content) {
  471. if (index == 0) {
  472. [weakSelf showAddCompanyView];
  473. }
  474. } whichFrame:moreFrame animate:YES];
  475. [downListView show];
  476. // self.treeView.editing = !self.treeView.editing;
  477. }
  478. -(void)showNoCompanyView{
  479. _noCompanyView = [[UIView alloc] initWithFrame:CGRectMake(20, 0, JX_SCREEN_WIDTH-40, 200)];
  480. [self.tableBody addSubview:_noCompanyView];
  481. UILabel * noCompanyLabel = [[UILabel alloc] init];
  482. noCompanyLabel.frame = CGRectMake(0, 20, CGRectGetWidth(_noCompanyView.frame), 30);
  483. noCompanyLabel.textAlignment = NSTextAlignmentCenter;
  484. noCompanyLabel.center = CGPointMake(CGRectGetWidth(_noCompanyView.frame)/2, noCompanyLabel.center.y);
  485. noCompanyLabel.text = Localized(@"OrgaVC_NoCompanyAlert");
  486. [_noCompanyView addSubview:noCompanyLabel];
  487. UIButton * createButton = [UIButton buttonWithType:UIButtonTypeSystem];
  488. createButton.frame = CGRectMake(0, 70, 150, 45);
  489. createButton.center = CGPointMake(CGRectGetWidth(_noCompanyView.frame)/2, createButton.center.y);
  490. [createButton setTitle:Localized(@"OrgaVC_GotoCreateCompany") forState:UIControlStateNormal];
  491. [createButton setBackgroundColor:THEMECOLOR];
  492. [createButton addTarget:self action:@selector(showAddCompanyView) forControlEvents:UIControlEventTouchUpInside];
  493. [_noCompanyView addSubview:createButton];
  494. }
  495. -(void)showAddCompanyView{
  496. [self inputViewController:OrganizAddCompany oldName:nil];
  497. }
  498. #pragma mark - 显示部门下拉列表
  499. -(void)showDepartDownListView:(DepartObject *)orgObject{
  500. _currentOrgObj = orgObject;
  501. NSInteger level = [self.treeView levelForCellForItem:orgObject];
  502. OrganizTableViewCell * cell = (OrganizTableViewCell *)[self.treeView cellForItem:orgObject];
  503. UIWindow *window = [[UIApplication sharedApplication].delegate window];
  504. // CGRect moreFrame = [self.treeView convertRect:cell.additionButton.frame toView:window];
  505. CGRect moreFrame = [window convertRect:cell.additionButton.frame fromView:cell];
  506. NSDictionary * theCompany = _companyDict[orgObject.companyId];
  507. NSString * creatUserId = [NSString stringWithFormat:@"%@",theCompany[@"createUserId"]];
  508. BOOL permissions = [creatUserId isEqualToString:g_myself.userId] ? YES : NO;
  509. NSNumber * isCanOperate = [NSNumber numberWithBool:permissions];
  510. NSNumber * canOperate = [NSNumber numberWithBool:YES];
  511. JX_DownListView * downListView = [[JX_DownListView alloc] initWithFrame:self.view.bounds];
  512. downListView.textColor = HEXCOLOR(0x333333);
  513. downListView.color = [UIColor whiteColor];
  514. if (level == 0) {
  515. // downListView.listContents = @[@"加部门",@"修改公司名",@"退出公司"];
  516. downListView.listContents = @[Localized(@"OrgaVC_CreateDepart"),Localized(@"OrgaVC_UpdateCompany"),Localized(@"OrgaVC_QuitCompany"),@"删除公司"];
  517. downListView.listEnables = @[isCanOperate,isCanOperate,canOperate,isCanOperate];
  518. downListView.listImages = @[@"organize_add",@"organize_change",@"organize_exit",@"organize_delete"];
  519. } else {
  520. // downListView.listContents = @[@"加部门",@"加员工",@"改部门名",@"删除"];
  521. downListView.listContents = @[Localized(@"OrgaVC_CreateDepart"),Localized(@"OrgaVC_CreateEmployee"),Localized(@"OrgaVC_UpdaeDepart"),Localized(@"JX_Delete")];
  522. downListView.listEnables = @[isCanOperate,canOperate,isCanOperate,isCanOperate];
  523. downListView.listImages = @[@"organize_add",@"organize_change",@"organize_exit",@"organize_delete"];
  524. }
  525. __weak typeof(self) weakSelf = self;
  526. [downListView downlistPopOption:^(NSInteger index, NSString *content) {
  527. if (level == 0) {
  528. if (index == 0) {
  529. [weakSelf addDepartWithParent:orgObject];
  530. }else if (index == 1) {
  531. [weakSelf modifyCompanyNameWith:orgObject];
  532. }else if (index == 2) {
  533. [weakSelf quitCompanyWith:orgObject];
  534. }else if (index == 3) {
  535. [weakSelf deleteCompanyWith:orgObject];
  536. }
  537. }else{
  538. switch (index) {
  539. case 0:{
  540. [weakSelf addDepartWithParent:orgObject];
  541. break;
  542. }
  543. case 1:{
  544. [weakSelf chooseEmployeeWithParent:orgObject];
  545. break;
  546. }
  547. case 2:{
  548. [weakSelf changeDepartNameWithParent:orgObject];
  549. break;
  550. }
  551. case 3:{
  552. [weakSelf deleteNodeWithItem:orgObject];
  553. break;
  554. }
  555. default:
  556. break;
  557. }
  558. }
  559. } whichFrame:moreFrame animate:YES];
  560. [downListView show];
  561. }
  562. #pragma mark - 显示员工下拉列表
  563. -(void)showEmployeeDownListView:(EmployeObject *)empObject{
  564. _currentOrgObj = empObject;
  565. // NSInteger level = [self.treeView levelForCellForItem:empObject];
  566. EmployeeTableViewCell * cell = (EmployeeTableViewCell *)[self.treeView cellForItem:empObject];
  567. UIWindow *window = [[UIApplication sharedApplication].delegate window];
  568. // CGRect moreFrame = [self.treeView convertRect:cell.additionButton.frame toView:window];
  569. CGRect cellFrame = [window convertRect:cell.contentView.frame fromView:cell];
  570. CGRect listFrame = CGRectMake(cellFrame.size.width-20-22, cellFrame.origin.y +20, 22, 22);
  571. NSDictionary * theCompany = _companyDict[empObject.companyId];
  572. NSString * creatUserId = [NSString stringWithFormat:@"%@",theCompany[@"createUserId"]];
  573. BOOL permissions = [creatUserId isEqualToString:g_myself.userId] ? YES : NO;
  574. NSNumber * isCanOperate = [NSNumber numberWithBool:permissions];
  575. NSNumber * canOperate = [NSNumber numberWithBool:YES];
  576. BOOL employeeSelf = [empObject.userId isEqualToString:g_myself.userId] ? YES : NO;
  577. BOOL isCanModifyPosition = (permissions || employeeSelf);
  578. JX_DownListView * downListView = [[JX_DownListView alloc] initWithFrame:self.view.bounds];
  579. downListView.textColor = HEXCOLOR(0x333333);
  580. downListView.color = [UIColor whiteColor];
  581. downListView.listContents = @[Localized(@"OrgaVC_EmployeeDetail"),Localized(@"OrgaVC_EmployeeChangeDepart"),Localized(@"OrgaVC_ModifyEmployeePosition"),Localized(@"JX_Delete")];
  582. if ([empObject.userId isEqualToString:g_myself.userId]) {
  583. downListView.listEnables = @[canOperate,isCanOperate,[NSNumber numberWithBool:isCanModifyPosition],isCanOperate];
  584. }else {
  585. downListView.listEnables = @[canOperate,isCanOperate,[NSNumber numberWithBool:employeeSelf],isCanOperate];
  586. }
  587. downListView.listImages = @[@"organize_add",@"organize_change",@"organize_exit",@"organize_delete"];
  588. __weak typeof(self) weakSelf = self;
  589. [downListView downlistPopOption:^(NSInteger index, NSString *content) {
  590. switch (index) {
  591. case 0:{
  592. [weakSelf employeeDetailWith:empObject];
  593. break;
  594. }
  595. case 1:{
  596. [weakSelf employChangeDepartWith:empObject];
  597. break;
  598. }
  599. case 2:{
  600. [weakSelf modifyEmployeePositionWith:empObject];
  601. break;
  602. }
  603. case 3:{
  604. [weakSelf deleteNodeWithItem:empObject];
  605. break;
  606. }
  607. default:
  608. break;
  609. }
  610. } whichFrame:listFrame animate:YES];
  611. [downListView show];
  612. }
  613. //-(void)addChooseTypeView:(DepartObject *)orgObject
  614. //{//原下拉
  615. // _currentOrgObj = orgObject;
  616. // NSInteger level = [self.treeView levelForCellForItem:orgObject];
  617. //
  618. // OrganizTableViewCell * cell = (OrganizTableViewCell *)[self.treeView cellForItem:orgObject];
  619. // CGRect frame = [self.treeView convertRect:cell.additionButton.frame fromView:cell];
  620. //
  621. // _control = [[UIControl alloc] initWithFrame:self.treeView.frame];
  622. // [_control addTarget:self action:@selector(hiddenAddView:) forControlEvents:UIControlEventAllEvents];
  623. // [self.treeView addSubview:_control];
  624. //
  625. // UIView * departView = [[UIView alloc] initWithFrame:CGRectMake(frame.origin.x-60, CGRectGetMaxY(frame), 70, 35)];
  626. // departView.backgroundColor = [UIColor orangeColor];
  627. // departView.tag = 10;
  628. // [_control addSubview:departView];
  629. // if (level != 0) {
  630. // UIView * employeeView = [[UIView alloc] initWithFrame:CGRectMake(frame.origin.x-60, CGRectGetMaxY(departView.frame), 70, 35)];
  631. // employeeView.backgroundColor = [UIColor redColor];
  632. // employeeView.tag = 11;
  633. // [_control addSubview:employeeView];
  634. //
  635. // UILabel * employeeLabel = [UIFactory createLabelWith:CGRectMake(0, 0, CGRectGetWidth(employeeView.frame), CGRectGetHeight(employeeView.frame)) text:@"+员工" font:g_factory.font17 textColor:[UIColor blackColor] backgroundColor:nil];
  636. // [employeeView addSubview:employeeLabel];
  637. // UITapGestureRecognizer * empGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseType:)];
  638. // [employeeView addGestureRecognizer:empGes];
  639. // }
  640. //
  641. // UILabel * departLabel = [UIFactory createLabelWith:CGRectMake(0, 0, CGRectGetWidth(departView.frame), CGRectGetHeight(departView.frame)) text:@"+部门" font:g_factory.font17 textColor:[UIColor blackColor] backgroundColor:nil];
  642. // [departView addSubview:departLabel];
  643. //
  644. // UITapGestureRecognizer * depGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseType:)];
  645. //
  646. // [departView addGestureRecognizer:depGes];
  647. //
  648. //}
  649. //
  650. //-(void)hiddenAddView:(UIControl *) control{
  651. // if (control == _control) {
  652. // _control.hidden = YES;
  653. // }
  654. //
  655. //}
  656. //-(void)chooseType:(UIGestureRecognizer *)ges{
  657. // UIView * view = ges.view;
  658. // NSInteger i = view.tag;
  659. // _control.hidden = YES;
  660. // switch (i) {
  661. // case 10:{
  662. // //新部门
  663. // [self inputViewController:OrganizAddDepartment];
  664. // break;
  665. // }
  666. // case 11:{
  667. // //新员工
  668. // JXSelFriendVC * addEmployeeVC = [[JXSelFriendVC alloc] init];
  669. // addEmployeeVC.delegate = self;
  670. // addEmployeeVC.didSelect = @selector(addEmployee:);
  671. // [g_window addSubview:addEmployeeVC.view];
  672. // break;
  673. // }
  674. // default:
  675. // break;
  676. // }
  677. //}
  678. #pragma mark - Row下拉列表操作
  679. /** 加部门 */
  680. -(void)addDepartWithParent:(DepartObject *)orgObject{
  681. OrganizTableViewCell * cell = (OrganizTableViewCell *)[self.treeView cellForItem:orgObject];
  682. if (!cell.arrowExpand) {
  683. cell.arrowExpand = YES;
  684. [self.treeView expandRowForItem:orgObject expandChildren:NO withRowAnimation:RATreeViewRowAnimationNone];
  685. }
  686. [self inputViewController:OrganizAddDepartment oldName:nil];
  687. __weak typeof(self) weakSelf = self;
  688. self.rowActionAfterRequestBlock = ^(id sender) {
  689. NSDictionary * departData = sender;
  690. DepartObject * childDepart = [DepartObject departmentObjectWith:departData allData:nil];
  691. [orgObject addChild:childDepart];
  692. [weakSelf.treeView insertItemsAtIndexes:[NSIndexSet indexSetWithIndex:0] inParent:orgObject withAnimation:RATreeViewRowAnimationLeft];
  693. [weakSelf.treeView reloadRowsForItems:@[orgObject] withRowAnimation:RATreeViewRowAnimationNone];
  694. };
  695. }
  696. /** 改部门名 */
  697. -(void)changeDepartNameWithParent:(DepartObject *)orgObject{
  698. [self inputViewController:OrganizUpdateDepartmentName oldName:orgObject.departName];
  699. __weak typeof(self) weakSelf = self;
  700. self.rowActionAfterRequestBlock = ^(id sender) {
  701. NSDictionary * dataDict = sender;
  702. if (dataDict[@"departName"] != nil && [dataDict[@"departName"] length] >0) {
  703. orgObject.departName = dataDict[@"departName"];
  704. [weakSelf.treeView reloadRowsForItems:@[orgObject] withRowAnimation:RATreeViewRowAnimationNone];
  705. }
  706. };
  707. }
  708. /** 加员工 */
  709. -(void)chooseEmployeeWithParent:(DepartObject *)orgObject{
  710. OrganizTableViewCell * cell = (OrganizTableViewCell *)[self.treeView cellForItem:orgObject];
  711. if (!cell.arrowExpand) {
  712. cell.arrowExpand = YES;
  713. [self.treeView expandRowForItem:orgObject expandChildren:NO withRowAnimation:RATreeViewRowAnimationNone];
  714. }
  715. JXSelectFriendsVC * addEmployeeVC = [[JXSelectFriendsVC alloc] init];
  716. addEmployeeVC.delegate = self;
  717. addEmployeeVC.didSelect = @selector(addEmployeeDelegate:);
  718. NSMutableSet * existSet = _employeesDict[orgObject.companyId];
  719. addEmployeeVC.existSet = existSet;
  720. // [g_window addSubview:addEmployeeVC.view];
  721. [g_navigation pushViewController:addEmployeeVC animated:YES];
  722. __weak typeof(self) weakSelf = self;
  723. self.rowActionAfterRequestBlock = ^(id sender) {
  724. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  725. // DepartObject *recorObj = orgObject;
  726. // if (weakSelf.curAddDepObj) {
  727. // recorObj = weakSelf.curAddDepObj;
  728. // }
  729. // 获取部门下所有用户(不含子部门)
  730. NSArray * dataArray = sender;
  731. NSMutableArray * employeeObjArr = [NSMutableArray array];
  732. for (NSDictionary * child in dataArray) {
  733. if (child[@"userId"] != nil) {
  734. EmployeObject * employ = [EmployeObject employWithDict:child];
  735. [employeeObjArr addObject:employ];
  736. }
  737. }
  738. // 获取上次增加用户的列表
  739. // if ([weakSelf.curAddDepObj objectForKey:orgObject.companyId]) {
  740. // orgObject.employees = [weakSelf.curAddDepObj objectForKey:orgObject.companyId];
  741. // }
  742. //
  743. // // 保存当前部门用户的列表
  744. // [weakSelf.curAddDepObj setObject:[employeeObjArr copy] forKey:orgObject.companyId];
  745. // 获取当前已存在用户的userId列表
  746. NSMutableSet * existSet = weakSelf.employeesDict[orgObject.companyId];
  747. NSMutableArray *addUserArr = [NSMutableArray array];
  748. NSMutableArray *haveUserArr = [NSMutableArray array];
  749. for (int i = 0; i<employeeObjArr.count; i++) {
  750. EmployeObject * allEmp = employeeObjArr[i];
  751. if (![existSet containsObject:allEmp.userId]) {
  752. // 获取新增用户列表
  753. [addUserArr addObject:allEmp];
  754. }else {
  755. // 已存在的用户列表
  756. [haveUserArr addObject:allEmp];
  757. }
  758. }
  759. // 如果新增用户数量为0,则不处理
  760. if (addUserArr.count <= 0) {
  761. return;
  762. }
  763. NSMutableIndexSet * addRowIndex = [NSMutableIndexSet indexSet];
  764. // for (int i = 0; i<employeeObjArr.count; i++) {
  765. // EmployeObject * allEmp = employeeObjArr[i];
  766. // BOOL isAdd = NO;
  767. // for (int j = 0; j<orgObject.employees.count; j++) {
  768. // EmployeObject * oldEmp = orgObject.employees[j];
  769. // if ([oldEmp isKindOfClass:[EmployeObject class]]) {
  770. // if ([oldEmp.userId intValue] == [allEmp.userId intValue]) {
  771. // isAdd = YES;
  772. // }
  773. // }
  774. // }
  775. // if (!isAdd){
  776. // [addRowIndex addIndex:i];
  777. // NSMutableSet * existSet = weakSelf.employeesDict[orgObject.companyId];
  778. // [existSet addObject:allEmp.userId];
  779. // }
  780. // }
  781. // 获取已增加用户的index
  782. for (int i = 0; i<addUserArr.count; i++) {
  783. [addRowIndex addIndex:i+orgObject.children.count];
  784. }
  785. // 添加已增加用户的userId
  786. for (EmployeObject * employ in addUserArr) {
  787. if (![existSet containsObject:employ.userId]) {
  788. [existSet addObject:employ.userId];
  789. }
  790. }
  791. // 更新列表
  792. dispatch_async(dispatch_get_main_queue(), ^{
  793. // NSInteger oldCount = orgObject.employees.count;
  794. NSMutableArray *arr = [orgObject.children mutableCopy];
  795. [arr addObjectsFromArray:addUserArr];
  796. // orgObject.departes = arr;
  797. // [weakSelf.treeView beginUpdates];
  798. orgObject.employees = addUserArr;
  799. orgObject.children = arr;
  800. [weakSelf.treeView insertItemsAtIndexes:addRowIndex inParent:orgObject withAnimation:RATreeViewRowAnimationRight];
  801. // [weakSelf.treeView insertItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(orgObject.departes.count, employeeObjArr.count)] inParent:orgObject withAnimation:RATreeViewRowAnimationLeft];
  802. [weakSelf.treeView reloadRowsForItems:@[orgObject] withRowAnimation:RATreeViewRowAnimationRight];
  803. // [weakSelf.treeView endUpdates];
  804. });
  805. });
  806. };
  807. }
  808. /** 删除节点 */
  809. -(void)deleteNodeWithItem:(id)item{
  810. self.isNotDele = NO;
  811. self.item = item;
  812. DepartObject *parent = [self.treeView parentForItem:item];
  813. NSUInteger index = 0;
  814. if ([item isKindOfClass:[EmployeObject class]]) {
  815. for (id obj in parent.children) {
  816. EmployeObject *employe = (EmployeObject *)obj;
  817. EmployeObject *employeItem = (EmployeObject *)item;
  818. if ([employe isKindOfClass:[EmployeObject class]]) {
  819. if ([employe.userId intValue] == [employeItem.userId intValue]) {
  820. index = [parent.children indexOfObject:employe];
  821. }
  822. }
  823. }
  824. }else {
  825. index = [parent.children indexOfObject:item];
  826. }
  827. // if ([[[parent.children valueForKey:@"empNum"] objectAtIndex:index] intValue] > 0) {
  828. if (index < parent.children.count) {
  829. if ([[parent.children objectAtIndex:index] isKindOfClass:[DepartObject class]]) {
  830. DepartObject *dPar = (DepartObject *)[parent.children objectAtIndex:index];
  831. if (dPar.children.count > 0) {
  832. [self deleteObject:dPar parent:parent];
  833. if (self.isNotDele) {
  834. //不能删除公司创建人所在部门
  835. [JXMyTools showTipView:Localized(@"JX_YouCannotDelete")];
  836. return;
  837. }
  838. }
  839. if (dPar.empNum > 0) {
  840. //该部门有成员,确认要删除
  841. [g_App showAlert:Localized(@"JX_ConfirmToBeDeleted") delegate:self tag:2001 onlyConfirm:NO];
  842. }else {
  843. [self deleNode];
  844. }
  845. }else {
  846. EmployeObject *emObj = (EmployeObject *)[parent.children objectAtIndex:index];
  847. if ([emObj.userId intValue] == [parent.createUserId intValue]) {
  848. //不能删除公司创建人
  849. [JXMyTools showTipView:Localized(@"JX_Can'tDelete")];
  850. return;
  851. }
  852. [self deleNode];
  853. }
  854. }
  855. }
  856. - (void)deleteObject:(DepartObject *)dPar parent:(DepartObject *)parent {
  857. for (id obj in dPar.children) {
  858. if ([obj isKindOfClass:[EmployeObject class]]) {
  859. EmployeObject *employe = (EmployeObject *)obj;
  860. if ([employe.userId intValue] == [parent.createUserId intValue]) {
  861. self.isNotDele = YES;
  862. }
  863. }else if ([obj isKindOfClass:[DepartObject class]]){
  864. DepartObject *depart = (DepartObject *)obj;
  865. self.isNotDele = NO;
  866. [self deleteObject:depart parent:parent];
  867. }
  868. }
  869. }
  870. - (void)deleNode {
  871. DepartObject *parent = [self.treeView parentForItem:self.item];
  872. if ([self.item isMemberOfClass:[EmployeObject class]]) {
  873. EmployeObject * employee = self.item;
  874. [g_server deleteEmployee:employee.departmentId userId:employee.userId toView:self];
  875. }else if ([self.item isMemberOfClass:[DepartObject class]]) {
  876. DepartObject * depart = self.item;
  877. [g_server deleteDepartment:depart.departId toView:self];
  878. }
  879. __weak typeof(self) weakSelf = self;
  880. self.rowActionAfterRequestBlock = ^(id sender) {
  881. NSInteger index = 0;
  882. if (parent == nil) {
  883. index = [self.dataArray indexOfObject:self.item];
  884. NSMutableArray *children = [weakSelf.dataArray mutableCopy];
  885. [children removeObject:weakSelf.item];
  886. weakSelf.dataArray = [children copy];
  887. } else {
  888. // index = [parent.children indexOfObject:self.item];
  889. if ([weakSelf.item isKindOfClass:[EmployeObject class]]) {
  890. for (id obj in parent.children) {
  891. EmployeObject *employe = (EmployeObject *)obj;
  892. EmployeObject *employeItem = (EmployeObject *)weakSelf.item;
  893. if ([employe isKindOfClass:[EmployeObject class]]) {
  894. if ([employe.userId intValue] == [employeItem.userId intValue]) {
  895. index = [parent.children indexOfObject:employe];
  896. }
  897. }
  898. }
  899. }else {
  900. index = [parent.children indexOfObject:weakSelf.item];
  901. }
  902. if (index < parent.children.count) {
  903. [weakSelf.treeView deleteItemsAtIndexes:[NSIndexSet indexSetWithIndex:index] inParent:parent withAnimation:RATreeViewRowAnimationRight];
  904. if (parent) {
  905. [weakSelf.treeView reloadRowsForItems:@[parent] withRowAnimation:RATreeViewRowAnimationNone];
  906. }
  907. }
  908. [parent removeChild:weakSelf.item];
  909. if ([weakSelf.item isMemberOfClass:[EmployeObject class]]) {
  910. EmployeObject * employee = weakSelf.item;
  911. NSMutableSet * emplySet = [weakSelf.employeesDict objectForKey:employee.companyId];
  912. [emplySet removeObject:employee.userId];
  913. }
  914. }
  915. };
  916. }
  917. /** 员工详情 */
  918. -(void)employeeDetailWith:(EmployeObject *)employObj{
  919. // [g_server getUser:employObj.userId toView:self];
  920. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  921. vc.userId = employObj.userId;
  922. vc.fromAddType = 6;
  923. vc = [vc init];
  924. [g_navigation pushViewController:vc animated:YES];
  925. }
  926. /** 更改员工部门 */
  927. -(void)employChangeDepartWith:(EmployeObject *)employObj{
  928. [self showChooseDepartCurrent:employObj];
  929. }
  930. /** 修改员工职位 */
  931. -(void)modifyEmployeePositionWith:(EmployeObject *)employObj{
  932. [self inputViewController:OrganizModifyEmployeePosition oldName:employObj.position];
  933. __weak typeof(self) weakSelf = self;
  934. self.rowActionAfterRequestBlock = ^(id sender) {
  935. NSDictionary * dataDict = sender;
  936. if (dataDict[@"position"] != nil && [dataDict[@"position"] length] >0) {
  937. employObj.position = dataDict[@"position"];
  938. [weakSelf.treeView reloadRowsForItems:@[employObj] withRowAnimation:RATreeViewRowAnimationFade];
  939. }
  940. };
  941. }
  942. /** 修改公司名 */
  943. -(void)modifyCompanyNameWith:(DepartObject *)orgObject{
  944. [self inputViewController:OrganizUpdateCompanyName oldName:orgObject.departName];
  945. __weak typeof(self) weakSelf = self;
  946. self.rowActionAfterRequestBlock = ^(id sender) {
  947. NSDictionary * dataDict = sender;
  948. if (dataDict[@"companyName"] != nil && [dataDict[@"companyName"] length] >0) {
  949. orgObject.departName = dataDict[@"companyName"];
  950. [weakSelf.treeView reloadRowsForItems:@[orgObject] withRowAnimation:RATreeViewRowAnimationNone];
  951. }
  952. };
  953. }
  954. /** 退出公司 */
  955. -(void)quitCompanyWith:(DepartObject *)orgObject{
  956. UIAlertView * alert = [g_App showAlert:Localized(@"OrgaVC_ConfirmQuit") delegate:self];
  957. alert.tag = 1001;
  958. __weak typeof(self) weakSelf = self;
  959. self.rowActionAfterRequestBlock = ^(id sender) {
  960. // if (weakSelf.afterDelCompany) {
  961. NSMutableArray * mutaArray = [weakSelf.dataArray mutableCopy];
  962. for (int i=0; i<mutaArray.count; i++) {
  963. DepartObject * rootDep = mutaArray[i];
  964. if ([rootDep.companyId isEqualToString:orgObject.companyId])
  965. [mutaArray removeObject:rootDep];
  966. }
  967. weakSelf.dataArray = mutaArray;
  968. // weakSelf.afterDelCompany = NO;
  969. [weakSelf.treeView reloadData];
  970. // }else{
  971. //
  972. // }
  973. };
  974. }
  975. /** 解散公司 */
  976. -(void)deleteCompanyWith:(DepartObject *)orgObject{
  977. _currentOrgObj = orgObject;
  978. UIAlertView * alert = [g_App showAlert:@"确认删除公司?" delegate:self];
  979. alert.tag = 1009;
  980. __weak typeof(self) weakSelf = self;
  981. self.rowActionAfterRequestBlock = ^(id sender) {
  982. // if (weakSelf.afterDelCompany) {
  983. NSMutableArray * mutaArray = [weakSelf.dataArray mutableCopy];
  984. for (int i=0; i<mutaArray.count; i++) {
  985. DepartObject * rootDep = mutaArray[i];
  986. if ([rootDep.companyId isEqualToString:orgObject.companyId])
  987. [mutaArray removeObject:rootDep];
  988. }
  989. weakSelf.dataArray = mutaArray;
  990. // weakSelf.afterDelCompany = NO;
  991. [weakSelf.treeView reloadData];
  992. // }else{
  993. //
  994. // }
  995. };
  996. }
  997. #pragma mark 跳输入VC
  998. -(void)inputViewController:(OrganizAddType) type oldName:(NSString *)oldName{
  999. JXAddDepartViewController * addDepartVC = [[JXAddDepartViewController alloc] init];
  1000. addDepartVC.delegate = self;
  1001. addDepartVC.type = type;
  1002. addDepartVC.oldName = oldName;
  1003. // [g_window addSubview:addDepartVC.view];
  1004. [g_navigation pushViewController:addDepartVC animated:YES];
  1005. }
  1006. #pragma mark 选择新部门
  1007. -(void)showChooseDepartCurrent:(EmployeObject *)employeeObj{
  1008. NSString * parentId = employeeObj.departmentId;
  1009. // NSDictionary * empDepart = _allDataDict[parentId];
  1010. NSDictionary * rootDict = nil;
  1011. while (parentId.length > 0) {
  1012. NSDictionary * parObj = _allDataDict[parentId];
  1013. if (parObj[@"parentId"])
  1014. parentId = parObj[@"parentId"];
  1015. else{
  1016. rootDict = parObj;
  1017. break;
  1018. parentId = nil;
  1019. }
  1020. }
  1021. NSString * rootId = rootDict[@"id"];
  1022. DepartObject * rootDepart = nil;
  1023. for (DepartObject * root in _dataArray) {
  1024. if ([root.departId isEqualToString:rootId]){
  1025. rootDepart = root;
  1026. break;
  1027. }
  1028. }
  1029. JXSelDepartViewController * selDepartVC = [[JXSelDepartViewController alloc] init];
  1030. selDepartVC.delegate = self;
  1031. selDepartVC.oldDepart = [self.treeView parentForItem:employeeObj];
  1032. selDepartVC.dataArray = @[rootDepart];
  1033. // [g_window addSubview:selDepartVC.view];
  1034. [g_navigation pushViewController:selDepartVC animated:YES];
  1035. }
  1036. #pragma mark alertViewDelegate
  1037. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
  1038. if (alertView.tag == 1001) {
  1039. if (buttonIndex == 1) {
  1040. // [g_server deleteCompany:_companyId userId:g_myself.userId toView:self];
  1041. DepartObject * orgObject = _currentOrgObj;
  1042. [g_server quitCompany:orgObject.companyId toView:self];
  1043. }else{
  1044. self.rowActionAfterRequestBlock = nil;
  1045. }
  1046. }else if (alertView.tag == 2001) {
  1047. if (buttonIndex == 1) {
  1048. [self deleNode];
  1049. }else{
  1050. }
  1051. }else if (alertView.tag == 1009) {
  1052. DepartObject * orgObject = _currentOrgObj;
  1053. [g_server deleteCompany:orgObject.companyId userId:g_myself.userId toView:self];
  1054. }
  1055. }
  1056. #pragma mark - input delegate
  1057. -(void)inputDelegateType:(OrganizAddType)organizType text:(NSString *)updateStr{
  1058. switch (organizType) {
  1059. case OrganizAddCompany:
  1060. case OrganizSearchCompany:{
  1061. [self addCompanyDelegate:updateStr];
  1062. break;
  1063. }
  1064. case OrganizAddDepartment:{
  1065. [self addDepartDelegate:updateStr];
  1066. break;
  1067. }
  1068. case OrganizUpdateCompanyName:{
  1069. [self updateCompanyNameDelegate:updateStr];
  1070. break;
  1071. }
  1072. case OrganizUpdateDepartmentName:{
  1073. [self updateDepartmentNameDelegate:updateStr];
  1074. break;
  1075. }
  1076. case OrganizModifyEmployeePosition:{
  1077. [self modifyEmployeePositionDelegate:updateStr];
  1078. }
  1079. default:
  1080. break;
  1081. }
  1082. }
  1083. #pragma mark 加部门
  1084. -(void)addDepartDelegate:(NSString *)departName{
  1085. DepartObject * dataObject = _currentOrgObj;
  1086. // [_wait start:@"正在添加部门"];
  1087. [g_server createDepartment:dataObject.companyId parentId:dataObject.departId departName:departName createUserId:nil toView:self];
  1088. }
  1089. #pragma mark 加公司
  1090. -(void)addCompanyDelegate:(NSString *)companyName{
  1091. // [_wait start:@"创建公司"];
  1092. [g_server createCompany:companyName toView:self];
  1093. if (_noCompanyView)
  1094. _noCompanyView.hidden = YES;
  1095. }
  1096. #pragma mark 部门改名
  1097. -(void)updateDepartmentNameDelegate:(NSString *)departNewName{
  1098. DepartObject * departObj = _currentOrgObj;
  1099. [g_server updataDepartmentName:departNewName departmentId:departObj.departId toView:self];
  1100. }
  1101. #pragma mark 员工改职位
  1102. -(void)modifyEmployeePositionDelegate:(NSString *)positionStr{
  1103. EmployeObject * employeeObj = _currentOrgObj;
  1104. [g_server modifyPosition:positionStr companyId:employeeObj.companyId userId:employeeObj.userId toView:self];
  1105. }
  1106. #pragma mark 公司改名
  1107. -(void)updateCompanyNameDelegate:(NSString *)companyName{
  1108. DepartObject * departObj = _currentOrgObj;
  1109. [g_server updataCompanyName:companyName noticeContent:nil companyId:departObj.companyId toView:self];
  1110. }
  1111. #pragma mark 加员工
  1112. -(void)addEmployeeDelegate:(JXSelectFriendsVC*)vc{
  1113. NSArray * allArr;
  1114. if (vc.seekTextField.text.length > 0) {
  1115. allArr = [vc.searchArray copy];
  1116. }else{
  1117. allArr = [vc.letterResultArr copy];
  1118. }
  1119. NSArray * indexArr = [vc.set allObjects];
  1120. NSMutableArray * adduserArr = [NSMutableArray array];
  1121. for (NSNumber * index in indexArr) {
  1122. JXUserObject *user;
  1123. if (vc.seekTextField.text.length > 0) {
  1124. user = allArr[[index intValue] % 100000 - 1];
  1125. }else{
  1126. user = [[allArr objectAtIndex:[index intValue] / 100000 - 1] objectAtIndex:[index intValue] % 100000 - 1];
  1127. }
  1128. [adduserArr addObject:user.userId];
  1129. }
  1130. if (adduserArr.count > 0) {
  1131. DepartObject * dataObj = _currentOrgObj;
  1132. [g_server addEmployee:adduserArr companyId:dataObj.companyId departmentId:dataObj.departId roleArray:nil toView:self];
  1133. }
  1134. }
  1135. #pragma mark - selDepart Delegate
  1136. -(void)selNewDepartmentWith:(DepartObject *)newDepart{
  1137. EmployeObject * employeeOBJ = _currentOrgObj;
  1138. [g_server modifyDpart:employeeOBJ.userId companyId:employeeOBJ.companyId newDepartmentId:newDepart.departId toView:self];
  1139. OrganizTableViewCell * cell = (OrganizTableViewCell *)[self.treeView cellForItem:newDepart];
  1140. if (!cell.arrowExpand) {
  1141. cell.arrowExpand = YES;
  1142. [self.treeView expandRowForItem:newDepart expandChildren:NO withRowAnimation:RATreeViewRowAnimationNone];
  1143. }
  1144. __weak typeof(self) weakSelf = self;
  1145. self.rowActionAfterRequestBlock = ^(id sender) {
  1146. // NSDictionary * dict = sender;
  1147. DepartObject * oldDepart = [weakSelf.treeView parentForItem:employeeOBJ];
  1148. // NSString * newDepartId = dict[@"departmentId"];
  1149. // NSInteger index = [weakSelf.treeView indexOfAccessibilityElement:employeeOBJ];
  1150. NSInteger index = [oldDepart.children indexOfObject:employeeOBJ];
  1151. // [weakSelf.treeView beginUpdates];
  1152. [newDepart addChild:employeeOBJ];
  1153. [oldDepart removeChild:employeeOBJ];
  1154. // [weakSelf.treeView moveItemAtIndex:index inParent:oldDepart toIndex:0 inParent:newDepart];
  1155. [weakSelf.treeView insertItemsAtIndexes:[NSIndexSet indexSetWithIndex:0] inParent:newDepart withAnimation:RATreeViewRowAnimationNone];
  1156. if (index < 0 || index > (oldDepart.children.count + 1)) {
  1157. [weakSelf.treeView reloadData];
  1158. }else {
  1159. [weakSelf.treeView deleteItemsAtIndexes:[NSIndexSet indexSetWithIndex:index] inParent:oldDepart withAnimation:RATreeViewRowAnimationNone];
  1160. }
  1161. // [weakSelf.treeView reloadRowsForItems:@[newDepart,oldDepart] withRowAnimation:RATreeViewRowAnimationNone];
  1162. //// [weakSelf.treeView collapseRowForItem:newDepart collapseChildren:NO withRowAnimation:RATreeViewRowAnimationLeft];
  1163. //// [weakSelf.treeView expandRowForItem:newDepart expandChildren:YES withRowAnimation:RATreeViewRowAnimationLeft];
  1164. // [weakSelf.treeView endUpdates];
  1165. // [weakSelf.treeView deleteItemsAtIndexes:[NSIndexSet indexSetWithIndex:<#(NSUInteger)#>] inParent:oldDepart withAnimation:RATreeViewRowAnimationAutomatic];
  1166. };
  1167. }
  1168. -(void)expandAllRows{
  1169. for (DepartObject * depart in _dataArray) {
  1170. if (!depart.parentId.length) {
  1171. [_treeView expandRowForItem:depart expandChildren:NO withRowAnimation:RATreeViewRowAnimationAutomatic];
  1172. }
  1173. }
  1174. [_treeView reloadRows];
  1175. }
  1176. #pragma mark 获取数据后处理及刷新
  1177. /** 自动获取公司成树后reload */
  1178. -(void)autoConstructTreeView:(NSArray *)originalArray{
  1179. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  1180. NSArray * array = [self getRootArray:originalArray];
  1181. dispatch_async(dispatch_get_main_queue(), ^{
  1182. _dataArray = [NSMutableArray arrayWithArray:array];
  1183. if (_dataArray.count > 0){
  1184. [_treeView reloadData];
  1185. [self performSelector:@selector(expandAllRows) withObject:nil afterDelay:0.1f];
  1186. // for (DepartObject * depart in _dataArray) {
  1187. // [_treeView expandRowForItem:depart expandChildren:YES withRowAnimation:RATreeViewRowAnimationRight];
  1188. // }
  1189. }
  1190. });
  1191. });
  1192. }
  1193. /** 创建公司后拉取列表,将新数据加入dataArray,reload */
  1194. -(void)addCompanyTreeView:(NSArray *)originalArray{
  1195. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  1196. NSArray * array = [self constructDepartObject:originalArray];
  1197. dispatch_async(dispatch_get_main_queue(), ^{
  1198. if (array.count > 0){
  1199. [_dataArray addObjectsFromArray:array];
  1200. [_treeView reloadData];
  1201. for (DepartObject * depart in array) {
  1202. [_treeView expandRowForItem:depart expandChildren:YES withRowAnimation:RATreeViewRowAnimationRight];
  1203. }
  1204. }
  1205. });
  1206. });
  1207. }
  1208. #pragma mark 数据成树
  1209. /** 所有公司数据 */
  1210. -(NSArray <DepartObject *>*) getRootArray:(NSArray *)originalArray{
  1211. NSMutableArray * rootArr = [[NSMutableArray alloc] init];
  1212. for (NSDictionary * companyDict in originalArray) {
  1213. [_companyDict setObject:companyDict forKey:companyDict[@"id"]];
  1214. NSArray * compRootDepartArr = [self constructCompanyObject:companyDict];
  1215. [rootArr addObjectsFromArray:compRootDepartArr];
  1216. }
  1217. return rootArr;
  1218. }
  1219. /** 公司实体数据 - 返回根部门数组 */
  1220. -(NSArray <DepartObject *>*) constructCompanyObject:(NSDictionary *)companyDict{
  1221. NSArray *departDictArr = companyDict[@"departments"];
  1222. // NSArray * rootDpartArr = companyDict[@"rootDpartId"];
  1223. return [self constructDepartObject:departDictArr];
  1224. }
  1225. /** 部门列表 */
  1226. -(NSArray <DepartObject *>*) constructDepartObject:(NSArray *)departArray{
  1227. NSMutableArray * rootArr = [[NSMutableArray alloc] init];
  1228. NSMutableDictionary * allDataDict = [NSMutableDictionary new];
  1229. NSMutableArray *allDataArr = [NSMutableArray array];
  1230. for (NSDictionary * departData in departArray) {
  1231. if (!departData[@"parentId"]) {
  1232. [rootArr addObject:departData];
  1233. if (![_employeesDict objectForKey:departData[@"companyId"]])
  1234. [_employeesDict setObject:[NSMutableSet set] forKey:departData[@"companyId"]];
  1235. }
  1236. [allDataDict setObject:departData forKey:departData[@"id"]];
  1237. [allDataArr addObject:departData];
  1238. }
  1239. //
  1240. for (NSDictionary *departData in departArray) {
  1241. if (departData[@"employees"]) {
  1242. NSMutableSet * emplySet = [_employeesDict objectForKey:departData[@"companyId"]];
  1243. NSArray * emplArr = departData[@"employees"];
  1244. for (NSDictionary * emp in emplArr) {
  1245. if (emp[@"departmentId"] != nil && emp[@"userId"] != nil)
  1246. [emplySet addObject:[NSString stringWithFormat:@"%@",emp[@"userId"]]];
  1247. }
  1248. }
  1249. }
  1250. NSMutableArray * departArr = [[NSMutableArray alloc] init];
  1251. for (NSDictionary * rootData in rootArr) {
  1252. DepartObject * departObj = [DepartObject departmentObjectWith:rootData allData:allDataArr];
  1253. [departArr addObject:departObj];
  1254. }
  1255. [_allDataDict addEntriesFromDictionary:allDataDict];
  1256. return departArr;
  1257. }
  1258. //-(void)constructDepartmentTreeObjectArray:(NSArray *) originalArray{
  1259. // NSMutableArray * rootArr = [[NSMutableArray alloc] init];
  1260. // for (NSDictionary * departData in originalArray) {
  1261. // if (!departData[@"parentId"]) {
  1262. // [rootArr addObject:departData];
  1263. // }
  1264. // [_allDataDict setObject:departData forKey:departData[@"id"]];
  1265. // if (departData[@"employees"]) {
  1266. // NSArray * emplArr = departData[@"employees"];
  1267. // for (NSDictionary * emp in emplArr) {
  1268. // if (emp[@"departmentId"] != nil && emp[@"userId"] != nil)
  1269. // [_employeesDict setObject:emp[@"departmentId"] forKey:emp[@"userId"]];
  1270. // }
  1271. // }
  1272. // }
  1273. // NSMutableArray * departArr = [[NSMutableArray alloc] init];
  1274. // for (NSDictionary * rootData in rootArr) {
  1275. // DepartObject * departObj = [DepartObject departmentObjectWith:rootData allData:_allDataDict];
  1276. // [departArr addObject:departObj];
  1277. // }
  1278. // _dataArray = departArr;
  1279. //}
  1280. #pragma mark 选中公司,设置当前公司显示
  1281. //-(void)setUIDataWith:(NSDictionary *)companyDict{
  1282. // _companyId = companyDict[@"id"];
  1283. // _companyName = companyDict[@"companyName"];
  1284. // self.title = _companyName;
  1285. //}
  1286. #pragma mark - **数据请求**
  1287. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  1288. [_wait stop];
  1289. // [self stopLoading];
  1290. if([aDownload.action isEqualToString:act_getCompany]){//自动查找公司
  1291. if (!array1) {
  1292. //没有公司
  1293. [self showNoCompanyView];
  1294. // if (!_afterDelCompany)
  1295. // [self showAddCompanyView];
  1296. }else{
  1297. [self autoConstructTreeView:array1];
  1298. }
  1299. }else if ([aDownload.action isEqualToString:act_creatCompany]) {//创建公司
  1300. if (_noCompanyView)
  1301. [_noCompanyView removeFromSuperview];
  1302. // [self setUIDataWith:dict];
  1303. [JXMyTools showTipView:Localized(@"OrgaVC_CreateCompanySuccess")];
  1304. if ([dict[@"id"] length] > 0) {
  1305. [_companyDict setObject:dict forKey:dict[@"id"]];
  1306. [g_server departmentListPage:[NSNumber numberWithInt:0] companyId:dict[@"id"] toView:self];
  1307. }
  1308. }else if ([aDownload.action isEqualToString:act_departmentList]) {//部门列表
  1309. [self addCompanyTreeView:array1];
  1310. }else if ([aDownload.action isEqualToString:act_addEmployee]) {//添加员工
  1311. [JXMyTools showTipView:Localized(@"OrgaVC_AddEmployeeSuccess")];
  1312. if (self.rowActionAfterRequestBlock) {
  1313. self.rowActionAfterRequestBlock(array1);
  1314. }
  1315. }else if([aDownload.action isEqualToString:act_deleteEmployee]) {//删除员工
  1316. [JXMyTools showTipView:Localized(@"OrgaVC_DelEmployeeSuccess")];
  1317. if (self.rowActionAfterRequestBlock) {
  1318. self.rowActionAfterRequestBlock(act_deleteEmployee);
  1319. }
  1320. }else if ([aDownload.action isEqualToString:act_modifyDpart]) {//更改员工部门
  1321. @try {
  1322. [JXMyTools showTipView:Localized(@"OrgaVC_ModifyEmployeeSuccess")];
  1323. if (self.rowActionAfterRequestBlock) {
  1324. self.rowActionAfterRequestBlock(dict);
  1325. }
  1326. } @catch (NSException *exception) {
  1327. } @finally {
  1328. }
  1329. }else if([aDownload.action isEqualToString:act_deleteDepartment]) {//删除部门
  1330. [JXMyTools showTipView:Localized(@"OrgaVC_DelDepartSuccess")];
  1331. if (self.rowActionAfterRequestBlock) {
  1332. self.rowActionAfterRequestBlock(act_deleteDepartment);
  1333. }
  1334. [g_server getCompanyAuto:self];
  1335. }else if([aDownload.action isEqualToString:act_deleteCompany]) {//删除公司
  1336. [JXMyTools showTipView:@"删除公司成功"];
  1337. // _afterDelCompany = YES;
  1338. // [self.dataArray removeAllObjects];
  1339. // [self.treeView reloadData];
  1340. // [g_server getCompanyAuto:self];
  1341. if (self.rowActionAfterRequestBlock) {
  1342. self.rowActionAfterRequestBlock(nil);
  1343. }
  1344. }else if([aDownload.action isEqualToString:act_companyQuit]) {//退出公司/解散公司
  1345. // _afterDelCompany = YES;
  1346. // [self.dataArray removeAllObjects];
  1347. // [self.treeView reloadData];
  1348. // [g_server getCompanyAuto:self];
  1349. if (self.rowActionAfterRequestBlock) {
  1350. self.rowActionAfterRequestBlock(nil);
  1351. }
  1352. }else if([aDownload.action isEqualToString:act_createDepartment]) {//创建部门
  1353. [JXMyTools showTipView:Localized(@"OrgaVC_CreateDepartSuccess")];
  1354. if (self.rowActionAfterRequestBlock) {
  1355. self.rowActionAfterRequestBlock(dict);
  1356. }
  1357. }else if([aDownload.action isEqualToString:act_updataDepartmentName]) {//修改部门名称
  1358. [JXMyTools showTipView:Localized(@"OrgaVC_UpdateDepartNameSuccess")];
  1359. if (self.rowActionAfterRequestBlock) {
  1360. self.rowActionAfterRequestBlock(dict);
  1361. }
  1362. }else if([aDownload.action isEqualToString:act_updataCompanyName]) {//修改公司名
  1363. [JXMyTools showTipView:Localized(@"JXAlert_UpdateOK")];
  1364. // [self setUIDataWith:dict];
  1365. if (self.rowActionAfterRequestBlock) {
  1366. self.rowActionAfterRequestBlock(dict);
  1367. }
  1368. }else if([aDownload.action isEqualToString:act_dpartmentInfo]) {//部门详情
  1369. }else if([aDownload.action isEqualToString:act_UserGet]){//员工详情
  1370. JXUserObject* user = [[JXUserObject alloc]init];
  1371. [user getDataFromDict:dict];
  1372. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  1373. vc.user = user;
  1374. vc.fromAddType = 6;
  1375. vc = [vc init];
  1376. // [g_window addSubview:vc.view];
  1377. [g_navigation pushViewController:vc animated:YES];
  1378. }else if ([aDownload.action isEqualToString:act_modifyPosition]){//修改员工职位
  1379. [JXMyTools showTipView:Localized(@"OrgaVC_ModifyEmployeePositionSuccess")];
  1380. if (self.rowActionAfterRequestBlock) {
  1381. self.rowActionAfterRequestBlock(dict);
  1382. }
  1383. }
  1384. // else if ([aDownload.action isEqualToString:]) {
  1385. //
  1386. // }
  1387. }
  1388. #pragma mark -
  1389. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  1390. [_wait stop];
  1391. self.rowActionAfterRequestBlock = nil;
  1392. return show_error;
  1393. }
  1394. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  1395. [_wait stop];
  1396. self.rowActionAfterRequestBlock = nil;
  1397. return show_error;
  1398. }
  1399. -(void) didServerConnectStart:(JXConnection*)aDownload{
  1400. dispatch_async(dispatch_get_main_queue(), ^{
  1401. [_wait start];
  1402. });
  1403. }
  1404. @end