QMChatRoomInvestigateCell.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // QMChatRoomInvestigateCell.m
  3. // IMSDK-OC
  4. //
  5. // Created by HCF on 16/3/11.
  6. // Copyright © 2016年 HCF. All rights reserved.
  7. //
  8. #import "QMChatRoomInvestigateCell.h"
  9. #import <QMLineSDK/QMLineSDK.h>
  10. @implementation QMChatRoomInvestigateCell
  11. {
  12. UIView *_backgrounView;
  13. UILabel *_warnLabel;
  14. NSArray *_investigateArray;
  15. UILabel *_investigateLabel;
  16. UILabel *_investigateValue;
  17. UIButton *_submitButton;
  18. UIButton *_valueButtonOne;
  19. UIButton *_valueButtonTwo;
  20. UIButton *_valueButtonThree;
  21. UIButton *_valueButtonFour;
  22. UIButton *_valueButtonFive;
  23. NSString *_messageId;
  24. }
  25. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  26. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  27. if (self) {
  28. [self createUI];
  29. }
  30. return self;
  31. }
  32. - (void)createUI {
  33. _backgrounView = [[UIView alloc] init];
  34. _backgrounView.frame = CGRectMake(30, 5, kScreenWidth-60, 140);
  35. _backgrounView.backgroundColor = [UIColor whiteColor];
  36. _backgrounView.layer.borderColor = [[UIColor lightGrayColor] CGColor];
  37. _backgrounView.layer.borderWidth = 0.5;
  38. [self.contentView addSubview:_backgrounView];
  39. _warnLabel = [[UILabel alloc] init];
  40. _warnLabel.frame = CGRectMake(10, 5, kScreenWidth-80, 60);
  41. _warnLabel.numberOfLines = 0;
  42. _warnLabel.font = [UIFont systemFontOfSize:15];
  43. _warnLabel.text = @"[邀评]系统提示:“为了提高服务质量,请您在咨询结束后,点击五角星对客服的服务进行评价,谢谢!”";
  44. [_backgrounView addSubview:_warnLabel];
  45. _investigateLabel = [[UILabel alloc] init];
  46. _investigateLabel.frame = CGRectMake(10, 100, 180, 30);
  47. [_backgrounView addSubview:_investigateLabel];
  48. _investigateValue = [[UILabel alloc] init];
  49. _valueButtonOne = [UIButton buttonWithType:UIButtonTypeCustom];
  50. _valueButtonOne.frame = CGRectMake(0, 60, 40, 40);
  51. _valueButtonOne.tag = 1;
  52. _valueButtonOne.selected = YES;
  53. [_valueButtonOne setBackgroundImage:[UIImage imageNamed:@"contactflag_star_nor"] forState:UIControlStateNormal];
  54. [_valueButtonOne setBackgroundImage:[UIImage imageNamed:@"contactflag_star_select"] forState:UIControlStateSelected];
  55. [_valueButtonOne addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  56. _valueButtonTwo = [UIButton buttonWithType:UIButtonTypeCustom];
  57. _valueButtonTwo.frame = CGRectMake(40, 60, 40, 40);
  58. _valueButtonTwo.tag = 2;
  59. _valueButtonTwo.selected = YES;
  60. [_valueButtonTwo setBackgroundImage:[UIImage imageNamed:@"contactflag_star_nor"] forState:UIControlStateNormal];
  61. [_valueButtonTwo setBackgroundImage:[UIImage imageNamed:@"contactflag_star_select"] forState:UIControlStateSelected];
  62. [_valueButtonTwo addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  63. _valueButtonThree = [UIButton buttonWithType:UIButtonTypeCustom];
  64. _valueButtonThree.frame = CGRectMake(80, 60, 40, 40);
  65. _valueButtonThree.tag = 3;
  66. _valueButtonThree.selected = YES;
  67. [_valueButtonThree setBackgroundImage:[UIImage imageNamed:@"contactflag_star_nor"] forState:UIControlStateNormal];
  68. [_valueButtonThree setBackgroundImage:[UIImage imageNamed:@"contactflag_star_select"] forState:UIControlStateSelected];
  69. [_valueButtonThree addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  70. _valueButtonFour = [UIButton buttonWithType:UIButtonTypeCustom];
  71. _valueButtonFour.frame = CGRectMake(120, 60, 40, 40);
  72. _valueButtonFour.tag = 4;
  73. [_valueButtonFour setBackgroundImage:[UIImage imageNamed:@"contactflag_star_nor"] forState:UIControlStateNormal];
  74. [_valueButtonFour setBackgroundImage:[UIImage imageNamed:@"contactflag_star_select"] forState:UIControlStateSelected];
  75. [_valueButtonFour addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  76. _valueButtonFive = [UIButton buttonWithType:UIButtonTypeCustom];
  77. _valueButtonFive.frame = CGRectMake(160, 60, 40, 40);
  78. _valueButtonFive.tag = 5;
  79. [_valueButtonFive setBackgroundImage:[UIImage imageNamed:@"contactflag_star_nor"] forState:UIControlStateNormal];
  80. [_valueButtonFive setBackgroundImage:[UIImage imageNamed:@"contactflag_star_select"] forState:UIControlStateSelected];
  81. [_valueButtonFive addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  82. if ([_investigateArray count] == 0) {
  83. [_backgrounView addSubview:_valueButtonOne];
  84. }else if ([_investigateArray count] == 1) {
  85. [_backgrounView addSubview:_valueButtonOne];
  86. [_backgrounView addSubview:_valueButtonTwo];
  87. }else if ([_investigateArray count] == 2) {
  88. [_backgrounView addSubview:_valueButtonOne];
  89. [_backgrounView addSubview:_valueButtonTwo];
  90. [_backgrounView addSubview:_valueButtonThree];
  91. }else if ([_investigateArray count] == 3) {
  92. [_backgrounView addSubview:_valueButtonOne];
  93. [_backgrounView addSubview:_valueButtonTwo];
  94. [_backgrounView addSubview:_valueButtonThree];
  95. [_backgrounView addSubview:_valueButtonFour];
  96. }else {
  97. [_backgrounView addSubview:_valueButtonOne];
  98. [_backgrounView addSubview:_valueButtonTwo];
  99. [_backgrounView addSubview:_valueButtonThree];
  100. [_backgrounView addSubview:_valueButtonFour];
  101. [_backgrounView addSubview:_valueButtonFive];
  102. }
  103. NSDictionary * dict = [_investigateArray objectAtIndex:[_investigateArray count]-3];
  104. _investigateLabel.text = [dict objectForKey:@"name"];
  105. _investigateValue.text = [dict objectForKey:@"value"];
  106. _submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
  107. _submitButton.frame = CGRectMake(_backgrounView.frame.size.width-80, _backgrounView.frame.size.height-40, 70, 30);
  108. _submitButton.backgroundColor = [UIColor redColor];
  109. [_submitButton setTitle:@"提交" forState:UIControlStateNormal];
  110. [_submitButton addTarget:self action:@selector(submitAction:) forControlEvents:UIControlEventTouchUpInside];
  111. [_backgrounView addSubview:_submitButton];
  112. }
  113. - (void)buttonAction: (UIButton *)sender {
  114. NSDictionary * dict = [_investigateArray objectAtIndex:[_investigateArray count]-(sender.tag-1)-1];
  115. _investigateLabel.text = [dict objectForKey:@"name"];
  116. _investigateValue.text = [dict objectForKey:@"value"];
  117. if (sender.tag == 1) {
  118. _valueButtonOne.selected = YES;
  119. _valueButtonTwo.selected = NO;
  120. _valueButtonThree.selected = NO;
  121. _valueButtonFour.selected = NO;
  122. _valueButtonFive.selected = NO;
  123. }else if (sender.tag == 2) {
  124. _valueButtonOne.selected = YES;
  125. _valueButtonTwo.selected = YES;
  126. _valueButtonThree.selected = NO;
  127. _valueButtonFour.selected = NO;
  128. _valueButtonFive.selected = NO;
  129. }else if (sender.tag == 3) {
  130. _valueButtonOne.selected = YES;
  131. _valueButtonTwo.selected = YES;
  132. _valueButtonThree.selected = YES;
  133. _valueButtonFour.selected = NO;
  134. _valueButtonFive.selected = NO;
  135. }else if (sender.tag == 4) {
  136. _valueButtonOne.selected = YES;
  137. _valueButtonTwo.selected = YES;
  138. _valueButtonThree.selected = YES;
  139. _valueButtonFour.selected = YES;
  140. _valueButtonFive.selected = NO;
  141. }else {
  142. _valueButtonOne.selected = YES;
  143. _valueButtonTwo.selected = YES;
  144. _valueButtonThree.selected = YES;
  145. _valueButtonFour.selected = YES;
  146. _valueButtonFive.selected = YES;
  147. }
  148. }
  149. - (void)setData:(CustomMessage *)message {
  150. _messageId = message._id;
  151. }
  152. - (void)submitAction: (UIButton *)sender {
  153. [QMConnect sdkSubmitInvestigate:_investigateLabel.text value:_investigateValue.text successBlock:^{
  154. NSLog(@"评价成功");
  155. } failBlock:^{
  156. NSLog(@"评价失败");
  157. }];
  158. // 提交评价成功,收到评价状态反馈,不用reload tableView
  159. [QMConnect removeDataFromDataBase:_messageId];
  160. [[NSNotificationCenter defaultCenter] postNotificationName:CHATMSG_RELOAD object:nil];
  161. }
  162. @end