OrganizObject.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // OrganizObject.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 17/5/11.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "OrganizObject.h"
  9. #import "JXUserObject.h"
  10. @implementation OrganizObject
  11. -(id)initWithDict:(NSDictionary *)nodeDict
  12. {
  13. self = [super init];
  14. if (self) {
  15. if (nodeDict[@"nickname"] != nil)
  16. self.nodeName = nodeDict[@"nickname"];
  17. if (nodeDict[@"userId"] != nil)
  18. self.userId = nodeDict[@"userId"];
  19. // if (nodeDict[@""] != nil)
  20. // self.parentId;
  21. // if (nodeDict[@"child"] != nil && [nodeDict[@"child"] count] > 0)
  22. // self.children = nodeDict[@"child"];
  23. // else
  24. // _children = @[];
  25. }
  26. return self;
  27. }
  28. //-(instancetype)initDepart:(NSDictionary *)nodeDict allData:(NSDictionary *)allDict{
  29. // self = [super init];
  30. // if (self) {
  31. //
  32. //
  33. // if (nodeDict[@"departName"] != nil)
  34. // self.departName = nodeDict[@"departName"];
  35. // self.createUserId
  36. // self.empNum
  37. // self.employees
  38. // self.departId = nodeDict[@"id"];
  39. // {
  40. // "companyId": "591e5ea35da45bc34f99d940",
  41. // "createTime": 1495162531,
  42. // "createUserId": 10007882,
  43. // "departName": "跳跳糖",
  44. // "empNum": 1,
  45. // "employees": [
  46. // {
  47. // "companyId": "591e5ea35da45bc34f99d940",
  48. // "departmentId": "591e5ea35da45bc34f99d941",
  49. // "id": "591e5ea35da45bc34f99d942",
  50. // "role": 3,
  51. // "userId": 10007882
  52. // }
  53. // ],
  54. // "id": "591e5ea35da45bc34f99d941"
  55. // }
  56. // }
  57. // return self;
  58. //}
  59. //
  60. ///** 创建部门节点 */
  61. //+(instancetype)departmentObjectWith:(NSDictionary *)nodeDict allData:(NSDictionary *)allDict{
  62. // return [[self alloc] initDepart:nodeDict allData:allDict];
  63. //}
  64. -(void)setChildren:(NSArray *)children{
  65. if ([children[0] isKindOfClass:[OrganizObject class]]) {
  66. _children = children;
  67. return;
  68. }
  69. NSMutableArray *childArray = [NSMutableArray array];
  70. for (NSDictionary * childDict in children) {
  71. OrganizObject * organiz = [OrganizObject organizObjectWithDict:childDict];
  72. [childArray addObject:organiz];
  73. }
  74. _children = [NSArray arrayWithArray:childArray];
  75. }
  76. +(id)organizObjectWithDict:(NSDictionary *)nodeDict
  77. {
  78. return [[self alloc] initWithDict:nodeDict];
  79. }
  80. - (void)addChild:(id)child
  81. {
  82. NSMutableArray *children = [self.children mutableCopy];
  83. [children insertObject:child atIndex:0];
  84. _children = [children copy];
  85. }
  86. - (void)removeChild:(id)child
  87. {
  88. NSMutableArray *children = [self.children mutableCopy];
  89. [children removeObject:child];
  90. _children = [children copy];
  91. }
  92. @end