No Description

FKCustomerEnquiryView.m 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. //
  2. // FKCustomerEnquiryView.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/5/26.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKCustomerEnquiryView.h"
  9. #import "FKWindowViewManager.h"
  10. #import "FLProgressHUDHelper.h"
  11. @interface FKCustomerEnquiryView ()
  12. <UITextViewDelegate>
  13. @property (nonatomic, strong) UIView *bgView;
  14. @property (nonatomic, strong) UILabel *tipLabel;
  15. @property (nonatomic, strong) UIButton *starButton0;
  16. @property (nonatomic, strong) UIButton *starButton1;
  17. @property (nonatomic, strong) UIButton *starButton2;
  18. @property (nonatomic, strong) UIButton *starButton3;
  19. @property (nonatomic, strong) UIButton *starButton4;
  20. @property (nonatomic, assign) NSInteger score;
  21. @property (nonatomic, strong) UILabel *scoreDescLabel;
  22. @property (nonatomic, strong) NSArray *scoreDescArray;
  23. @property (nonatomic, strong) UITextView *messageView;
  24. @property (nonatomic, strong) UILabel *placeHolderLabel;
  25. @property (nonatomic, strong) UIButton *submitButton;
  26. @property (nonatomic, strong) UIButton *closeButton;
  27. @end
  28. @implementation FKCustomerEnquiryView
  29. /*
  30. // Only override drawRect: if you perform custom drawing.
  31. // An empty implementation adversely affects performance during animation.
  32. - (void)drawRect:(CGRect)rect {
  33. // Drawing code
  34. }
  35. */
  36. - (instancetype)init {
  37. self = [super init];
  38. if (self) {
  39. self.starButton0 = [self makeButtonWithTag:1];
  40. self.starButton1 = [self makeButtonWithTag:2];
  41. self.starButton2 = [self makeButtonWithTag:3];
  42. self.starButton3 = [self makeButtonWithTag:4];
  43. self.starButton4 = [self makeButtonWithTag:5];
  44. [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyboardGesture:)]];
  45. [self addAllSubviews];
  46. [self configKeyboardEvent];
  47. }
  48. return self;
  49. }
  50. - (void)dealloc {
  51. [self removeKeyboardEvent];
  52. }
  53. #pragma mark - UITextFieldDelegate
  54. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  55. if ([text isEqualToString:@"\n"]) {
  56. [self.messageView resignFirstResponder];
  57. return NO;
  58. }
  59. if (text.length > 0) {
  60. self.placeHolderLabel.hidden = YES;
  61. }
  62. return YES;
  63. }
  64. - (void)textViewDidChange:(UITextView *)textView {
  65. self.placeHolderLabel.hidden = textView.text.length;
  66. }
  67. #pragma mark - Action
  68. - (IBAction)clickStarButton:(UIButton *)sender {
  69. NSArray *array = @[self.starButton0, self.starButton1, self.starButton2, self.starButton3, self.starButton4];
  70. for (int index = 0; index < array.count; index++) {
  71. UIButton *button = array[index];
  72. if (index <= (sender.tag - 1)) {
  73. [button setImage:[UIImage imageNamed:@"ScoredStar"] forState:UIControlStateNormal];
  74. } else {
  75. [button setImage:[UIImage imageNamed:@"UnScoreStar"] forState:UIControlStateNormal];
  76. }
  77. }
  78. self.score = sender.tag;
  79. self.scoreDescLabel.hidden = NO;
  80. self.scoreDescLabel.text = self.scoreDescArray[sender.tag - 1];
  81. }
  82. - (IBAction)clickSubmitButton:(id)sender {
  83. [self disappearFromWindow];
  84. }
  85. - (IBAction)clickCloseButton:(id)sender {
  86. [self.superview removeFromSuperview];
  87. [[FKWindowViewManager sharedManager] closeFloatView];
  88. }
  89. - (IBAction)closeKeyboardGesture:(id)sender {
  90. [self.messageView resignFirstResponder];
  91. }
  92. - (void)disappearFromWindow {
  93. if (self.score > 0) {
  94. if (self.enquirySubmitCallback) {
  95. NSString *summary = ([NSString stringWithFormat:@"%d", (int)self.score]);
  96. self.enquirySubmitCallback(summary, self.messageView.text);
  97. }
  98. [self.superview removeFromSuperview];
  99. [[FKWindowViewManager sharedManager] closeFloatView];
  100. } else {
  101. [FLProgressHUDHelper showText:@"请给客服打分" inView:self];
  102. }
  103. }
  104. #pragma mark - Keyboard Event
  105. - (void)keyboardWillShow:(NSNotification *)notification {
  106. [self changeFramwWithKeyboard:notification];
  107. }
  108. - (void)keyboardWillHide:(NSNotification *)notification {
  109. [self changeFramwWithKeyboard:notification];
  110. }
  111. - (void)changeFramwWithKeyboard:(NSNotification *)notification {
  112. CGFloat duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
  113. CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  114. CGRect viewFrame = [self.window convertRect:self.messageView.frame fromView:self];
  115. CGFloat offset = (CGRectGetHeight(keyboardFrame) - (UISCREENHEIGH - CGRectGetMaxY(viewFrame)));
  116. CGPoint center;
  117. if (offset > 0) {
  118. center = CGPointMake(UISCREENWIDTH/2, self.center.y - offset);
  119. } else {
  120. center = CGPointMake(UISCREENWIDTH/2, UISCREENHEIGH/2);
  121. }
  122. UIViewAnimationOptions curve = (UIViewAnimationOptions)[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
  123. [UIView animateWithDuration:duration delay:0 options:curve animations:^{
  124. self.center = center;
  125. } completion:^(BOOL finished) {
  126. }];
  127. }
  128. #pragma mark - Method
  129. - (void)configKeyboardEvent {
  130. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  131. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  132. }
  133. - (void)removeKeyboardEvent {
  134. [[NSNotificationCenter defaultCenter] removeObserver:self];
  135. }
  136. #pragma mark - Layout
  137. - (void)addAllSubviews {
  138. [self addSubview:self.bgView];
  139. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.centerX.equalTo(self);
  141. make.top.equalTo(self);
  142. make.size.mas_equalTo(CGSizeMake(275, 370));
  143. }];
  144. [self.bgView addSubview:self.headImgView];
  145. [self.headImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  146. make.centerX.equalTo(self.bgView);
  147. make.top.equalTo(self.bgView).offset(23);
  148. make.size.mas_equalTo(CGSizeMake(50, 50));
  149. }];
  150. [self.bgView addSubview:self.tipLabel];
  151. [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  152. make.centerX.equalTo(self.bgView);
  153. make.top.equalTo(self.headImgView.mas_bottom).offset(8);
  154. }];
  155. [self.bgView addSubview:self.starButton2];
  156. [self.starButton2 mas_makeConstraints:^(MASConstraintMaker *make) {
  157. make.centerX.equalTo(self.bgView);
  158. make.top.equalTo(self.tipLabel.mas_bottom).offset(6);
  159. make.size.mas_equalTo(CGSizeMake(40, 40));
  160. }];
  161. [self.bgView addSubview:self.starButton1];
  162. [self.starButton1 mas_makeConstraints:^(MASConstraintMaker *make) {
  163. make.centerY.equalTo(self.starButton2);
  164. make.right.equalTo(self.starButton2.mas_left);
  165. make.size.mas_equalTo(CGSizeMake(40, 40));
  166. }];
  167. [self.bgView addSubview:self.starButton0];
  168. [self.starButton0 mas_makeConstraints:^(MASConstraintMaker *make) {
  169. make.centerY.equalTo(self.starButton2);
  170. make.right.equalTo(self.starButton1.mas_left);
  171. make.size.mas_equalTo(CGSizeMake(40, 40));
  172. }];
  173. [self.bgView addSubview:self.starButton3];
  174. [self.starButton3 mas_makeConstraints:^(MASConstraintMaker *make) {
  175. make.centerY.equalTo(self.starButton2);
  176. make.left.equalTo(self.starButton2.mas_right);
  177. make.size.mas_equalTo(CGSizeMake(40, 40));
  178. }];
  179. [self.bgView addSubview:self.starButton4];
  180. [self.starButton4 mas_makeConstraints:^(MASConstraintMaker *make) {
  181. make.centerY.equalTo(self.starButton2);
  182. make.left.equalTo(self.starButton3.mas_right);
  183. make.size.mas_equalTo(CGSizeMake(40, 40));
  184. }];
  185. [self.bgView addSubview:self.scoreDescLabel];
  186. [self.scoreDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  187. make.centerX.equalTo(self.bgView);
  188. make.top.equalTo(self.starButton2.mas_bottom).offset(4);
  189. }];
  190. [self.bgView addSubview:self.messageView];
  191. [self.messageView mas_makeConstraints:^(MASConstraintMaker *make) {
  192. make.centerX.equalTo(self.bgView);
  193. make.top.equalTo(self.scoreDescLabel.mas_bottom).offset(14);
  194. make.size.mas_equalTo(CGSizeMake(220, 110));
  195. }];
  196. [self.messageView addSubview:self.placeHolderLabel];
  197. [self.placeHolderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  198. make.left.equalTo(self.messageView).offset(5);
  199. make.top.equalTo(self.messageView).offset(8);
  200. }];
  201. [self.bgView addSubview:self.submitButton];
  202. [self.submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
  203. make.left.right.bottom.equalTo(self.bgView);
  204. make.height.mas_equalTo(50);
  205. }];
  206. [self addSubview:self.closeButton];
  207. [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.right.equalTo(self.bgView).offset(-6);
  209. make.top.equalTo(self.bgView).offset(6);
  210. make.size.mas_equalTo(CGSizeMake(40, 40));
  211. }];
  212. }
  213. #pragma mark - Property
  214. - (UIView *)bgView {
  215. if (!_bgView) {
  216. _bgView = [UIView new];
  217. _bgView.clipsToBounds = YES;
  218. _bgView.backgroundColor = [UIColor whiteColor];
  219. _bgView.layer.cornerRadius = 6;
  220. }
  221. return _bgView;
  222. }
  223. - (UIImageView *)headImgView {
  224. if (!_headImgView) {
  225. _headImgView = [[UIImageView alloc] init];
  226. _headImgView.layer.cornerRadius = 3;
  227. _headImgView.clipsToBounds = YES;
  228. _headImgView.contentMode = UIViewContentModeScaleAspectFit;
  229. }
  230. return _headImgView;
  231. }
  232. - (UILabel *)tipLabel {
  233. if (!_tipLabel) {
  234. _tipLabel = [[UILabel alloc]init];
  235. _tipLabel.font = [UIFont systemFontOfSize:14];
  236. _tipLabel.textColor = UIColorFromRGB(0x666666);
  237. _tipLabel.textAlignment = NSTextAlignmentCenter;
  238. _tipLabel.text = @"请对本次服务评分";
  239. }
  240. return _tipLabel;
  241. }
  242. - (UIButton *)makeButtonWithTag:(NSInteger)tag {
  243. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  244. button.tag = tag;
  245. [button setImage:[UIImage imageNamed:@"UnScoreStar"] forState:UIControlStateNormal];
  246. [button addTarget:self action:@selector(clickStarButton:) forControlEvents:UIControlEventTouchUpInside];
  247. return button;
  248. }
  249. - (UILabel *)scoreDescLabel {
  250. if (!_scoreDescLabel) {
  251. _scoreDescLabel = [[UILabel alloc] init];
  252. _scoreDescLabel.font = [UIFont systemFontOfSize:13];
  253. _scoreDescLabel.textColor = UIColorFromRGB(0xff6362);
  254. _scoreDescLabel.textAlignment = NSTextAlignmentCenter;
  255. _scoreDescLabel.hidden = YES;
  256. }
  257. return _scoreDescLabel;
  258. }
  259. - (NSArray*)scoreDescArray {
  260. if (!_scoreDescArray) {
  261. _scoreDescArray = @[@"非常不满意,各方面都很差",
  262. @"不满意,服务比较差",
  263. @"服务一般需要改善",
  264. @"较满意,但仍可改善",
  265. @"非常满意,无可挑剔"];
  266. }
  267. return _scoreDescArray;
  268. }
  269. - (UITextView *)messageView {
  270. if (!_messageView) {
  271. _messageView = [[UITextView alloc] init];
  272. _messageView.font = [UIFont systemFontOfSize:14];
  273. _messageView.layer.borderWidth = 1.0/[UIScreen mainScreen].scale;
  274. _messageView.layer.cornerRadius = 3;
  275. _messageView.layer.borderColor = UIColorFromRGB(0xcccccc).CGColor;
  276. _messageView.textColor = UIColorFromRGB(0x666666);
  277. _messageView.delegate = self;
  278. _messageView.returnKeyType = UIReturnKeyDone;
  279. }
  280. return _messageView;
  281. }
  282. - (UILabel *)placeHolderLabel {
  283. if (!_placeHolderLabel) {
  284. _placeHolderLabel = [[UILabel alloc] init];
  285. _placeHolderLabel.textAlignment = NSTextAlignmentLeft;
  286. _placeHolderLabel.font = [UIFont systemFontOfSize:14];
  287. _placeHolderLabel.backgroundColor = [UIColor whiteColor];
  288. _placeHolderLabel.textColor = UIColorFromRGB(0xcccccc);
  289. _placeHolderLabel.text = @"请输入留言...";
  290. }
  291. return _placeHolderLabel;
  292. }
  293. - (UIButton *)submitButton {
  294. if (!_submitButton) {
  295. _submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
  296. _submitButton.backgroundColor = UIColorFromRGB(0xff6362);
  297. [_submitButton setTitle:@"提交" forState:UIControlStateNormal];
  298. [_submitButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
  299. [_submitButton setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
  300. [_submitButton addTarget:self action:@selector(clickSubmitButton:) forControlEvents:UIControlEventTouchUpInside];
  301. }
  302. return _submitButton;
  303. }
  304. - (UIButton *)closeButton {
  305. if (!_closeButton) {
  306. _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  307. [_closeButton setImage:[UIImage imageNamed:@"DetailPriceCloseIcon"] forState:UIControlStateNormal];
  308. [_closeButton addTarget:self action:@selector(clickCloseButton:) forControlEvents:UIControlEventTouchUpInside];
  309. }
  310. return _closeButton;
  311. }
  312. @end