JXReplyAideKeyManageVC.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // JXReplyAideKeyManageVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/5/15.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXReplyAideKeyManageVC.h"
  9. #import "JXGroupHeplerModel.h"
  10. @interface JXReplyAideKeyManageVC ()
  11. @property (nonatomic, strong) UIView *keysView;
  12. @property (nonatomic, strong) UIView *contentView;
  13. @property (nonatomic, strong) UITextView *keyText;
  14. @property (nonatomic, strong) UITextView *replyText;
  15. @property (nonatomic, strong) NSMutableArray *groupHelperArr;
  16. @property (nonatomic, assign) NSInteger index;
  17. @end
  18. @implementation JXReplyAideKeyManageVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. self.heightHeader = JX_SCREEN_TOP;
  23. self.heightFooter = 0;
  24. self.isGotoBack = YES;
  25. [self createHeadAndFoot];
  26. self.title = [NSString stringWithFormat:@"%@%@",Localized(@"KEYWORD"),Localized(@"JX_KeywordsAdministration")];
  27. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
  28. [self.tableBody addGestureRecognizer:tap];
  29. if (!_keys) {
  30. _keys = [NSMutableArray array];
  31. }
  32. _groupHelperArr = [NSMutableArray array];
  33. [g_server queryGroupHelper:self.roomId toView:self];
  34. [self customView];
  35. [self createKeys];
  36. }
  37. - (void)tapAction {
  38. [self.view endEditing:YES];
  39. }
  40. - (void)customView {
  41. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 30, JX_SCREEN_WIDTH - 15, 20)];
  42. label.font = [UIFont systemFontOfSize:16.0];
  43. label.text = Localized(@"JX_KeywordHasBeenSet:");
  44. [self.tableBody addSubview:label];
  45. _keysView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame) + 10, JX_SCREEN_WIDTH, 0)];
  46. [self.tableBody addSubview:_keysView];
  47. _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_keysView.frame), JX_SCREEN_WIDTH, 0)];
  48. [self.tableBody addSubview:_contentView];
  49. label = [[UILabel alloc] initWithFrame:CGRectMake(15, 20, JX_SCREEN_WIDTH - 15, 20)];
  50. label.font = [UIFont systemFontOfSize:16.0];
  51. label.text = [NSString stringWithFormat:@"%@:",Localized(@"KEYWORD")];
  52. [_contentView addSubview:label];
  53. _keyText = [[UITextView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(label.frame) + 10, JX_SCREEN_WIDTH - 30, 100)];
  54. _keyText.layer.masksToBounds = YES;
  55. _keyText.layer.cornerRadius = 7.f;
  56. _keyText.font = SYSFONT(15);
  57. _keyText.backgroundColor = HEXCOLOR(0xF2F2F2);
  58. [_contentView addSubview:_keyText];
  59. label = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(_keyText.frame) + 20, JX_SCREEN_WIDTH - 15, 20)];
  60. label.font = [UIFont systemFontOfSize:16.0];
  61. label.text = [NSString stringWithFormat:@"%@:",Localized(@"JX_ContentOfReply")];
  62. [_contentView addSubview:label];
  63. _replyText = [[UITextView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(label.frame) + 10, JX_SCREEN_WIDTH - 30, 100)];
  64. _replyText.layer.masksToBounds = YES;
  65. _replyText.layer.cornerRadius = 7.f;
  66. _replyText.font = SYSFONT(15);
  67. _replyText.backgroundColor = HEXCOLOR(0xF2F2F2);
  68. [_contentView addSubview:_replyText];
  69. UIButton *btn = [UIFactory createCommonButton:Localized(@"JX_Add") target:self action:@selector(onAddKeyword)];
  70. [btn setBackgroundImage:nil forState:UIControlStateHighlighted];
  71. btn.custom_acceptEventInterval = 1.f;
  72. btn.frame = CGRectMake(15,CGRectGetMaxY(_replyText.frame) + 30, JX_SCREEN_WIDTH-30, 40);
  73. [btn setBackgroundImage:nil forState:UIControlStateNormal];
  74. btn.layer.masksToBounds = YES;
  75. btn.layer.cornerRadius = 7.f;
  76. btn.backgroundColor = THEMECOLOR;
  77. [_contentView addSubview:btn];
  78. _contentView.frame = CGRectMake(_contentView.frame.origin.x, _contentView.frame.origin.y, _contentView.frame.size.width, CGRectGetMaxY(btn.frame));
  79. }
  80. - (void)onAddKeyword {
  81. if (_keyText.text.length <= 0 || _replyText.text.length <= 0) {
  82. [g_server showMsg:Localized(@"JX_KeywordAndReplyContentCannotBeEmpty")];
  83. return;
  84. }
  85. [g_server addAutoResponse:self.roomId helperId:self.helperId keyword:_keyText.text value:_replyText.text toView:self];
  86. }
  87. - (void)createKeys {
  88. [_keysView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  89. CGFloat inset = 20;
  90. UILabel *lastLabel = nil;
  91. for (NSInteger i = 0; i < _keys.count; i ++) {
  92. NSDictionary *dic = _keys[i];
  93. NSString *name = [dic objectForKey:@"keyWord"];
  94. CGSize size = [name boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size;
  95. UILabel *label = [[UILabel alloc] init];
  96. label.font = [UIFont systemFontOfSize:14.0];
  97. label.tag = i;
  98. label.text = name;
  99. label.backgroundColor = THEMECOLOR;
  100. label.textColor = [UIColor whiteColor];
  101. label.textAlignment = NSTextAlignmentCenter;
  102. label.layer.cornerRadius = 2.0;
  103. label.layer.masksToBounds = YES;
  104. if (!lastLabel) {
  105. label.frame = CGRectMake(inset, 10, (size.width + 20) > (JX_SCREEN_WIDTH - inset*2) ? (JX_SCREEN_WIDTH - inset*2) : (size.width + 20), 30);
  106. }else {
  107. if ((CGRectGetMaxX(lastLabel.frame) + inset + size.width + 20) > (JX_SCREEN_WIDTH - inset*2)) {
  108. label.frame = CGRectMake(inset, CGRectGetMaxY(lastLabel.frame) + inset, (size.width + 20) > (JX_SCREEN_WIDTH - inset*2) ? (JX_SCREEN_WIDTH - inset*2) : (size.width + 20), 30);
  109. }else {
  110. label.frame = CGRectMake(CGRectGetMaxX(lastLabel.frame) + inset, lastLabel.frame.origin.y, (size.width + 20) > (JX_SCREEN_WIDTH - inset*2) ? (JX_SCREEN_WIDTH - inset*2) : (size.width + 20), 30);
  111. }
  112. }
  113. [_keysView addSubview:label];
  114. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label.frame) - 15, label.frame.origin.y - 5, 20, 20)];
  115. btn.tag = i;
  116. [btn setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
  117. [btn addTarget:self action:@selector(onDelete:) forControlEvents:UIControlEventTouchUpInside];
  118. [_keysView addSubview:btn];
  119. lastLabel = label;
  120. }
  121. _keysView.frame = CGRectMake(_keysView.frame.origin.x, _keysView.frame.origin.y, _keysView.frame.size.width, CGRectGetMaxY(lastLabel.frame));
  122. _contentView.frame = CGRectMake(_contentView.frame.origin.x, CGRectGetMaxY(_keysView.frame), _contentView.frame.size.width, _contentView.frame.size.height);
  123. }
  124. - (void)onDelete:(JXImageView *)iv {
  125. self.index = iv.tag;
  126. for (JXGroupHeplerModel *hModel in _groupHelperArr) {
  127. if ([hModel.helperId isEqualToString:self.model.helperId]) {
  128. [g_server deleteAutoResponse:hModel.groupHelperId keyWordId:[(NSDictionary *)_keys[iv.tag] objectForKey:@"id"] toView:self];
  129. }
  130. }
  131. }
  132. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  133. [_wait stop];
  134. // 获取群助手
  135. if ([aDownload.action isEqualToString:act_addAutoResponse]) {
  136. NSDictionary *dict = [NSDictionary dictionaryWithObject:_keyText.text forKey:@"keyWord"];
  137. [_keys addObject:dict];
  138. _keyText.text = nil;
  139. _replyText.text = nil;
  140. [self createKeys];
  141. }
  142. if ([aDownload.action isEqualToString:act_queryGroupHelper]) {
  143. NSMutableArray *arr = [[NSMutableArray alloc] init];
  144. for (int i = 0; i < array1.count; i++) {
  145. JXGroupHeplerModel *model = [[JXGroupHeplerModel alloc] init];
  146. [model getDataWithDict:array1[i]];
  147. [arr addObject:model];
  148. }
  149. _groupHelperArr = arr;
  150. // for (JXGroupHeplerModel *hModel in arr) {
  151. // if ([hModel.helperId isEqualToString:self.model.helperId]) {
  152. // _keys = [NSMutableArray arrayWithArray:hModel.keywords];
  153. // [self createKeys];
  154. // }
  155. // }
  156. }
  157. if ([aDownload.action isEqualToString:act_deleteAutoResponse]) {
  158. [_keys removeObjectAtIndex:self.index];
  159. [self createKeys];
  160. }
  161. }
  162. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  163. [_wait stop];
  164. return show_error;
  165. }
  166. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  167. [_wait stop];
  168. return show_error;
  169. }
  170. -(void) didServerConnectStart:(JXConnection*)aDownload{
  171. [_wait start];
  172. }
  173. @end