FeedbackViewController.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // FeedbackViewController.m
  3. // DSH
  4. //
  5. // Created by 张毅成 on 2018/10/8.
  6. // Copyright © 2018 WZX. All rights reserved.
  7. //
  8. #import "FeedbackViewController.h"
  9. @interface FeedbackViewController ()<UITextViewDelegate>
  10. @property (weak, nonatomic) IBOutlet UITextView *textView;
  11. @property (weak, nonatomic) IBOutlet UIButton *buttonCheck;
  12. @property (weak, nonatomic) IBOutlet UILabel *labelPlaceholder;
  13. @property (weak, nonatomic) IBOutlet UILabel *labelTextLength;
  14. @property (weak, nonatomic) IBOutlet UIView *viewBottom;
  15. @property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *arrayButtonType;
  16. @property (assign, nonatomic) NSInteger feedbackType;
  17. @end
  18. @implementation FeedbackViewController
  19. - (NSMutableDictionary *)parameters {
  20. if (!_parameters) {
  21. _parameters = @{}.mutableCopy;
  22. }
  23. return _parameters;
  24. }
  25. - (void)Network {
  26. SHOWLOADING
  27. NSString *URL = self.URL;
  28. self.parameters[@"content"] = self.textView.text;
  29. if (self.controllerType == FeedbackViewControllerTypeFeedback) {//意见反馈
  30. self.parameters[@"type"] = @(self.feedbackType).stringValue;
  31. }else if (self.controllerType == FeedbackViewControllerTypeSelfIntroduction) {//自我介绍
  32. self.parameters[@"myselfMsg"] = self.textView.text;
  33. }else if (self.controllerType == FeedbackViewControllerTypeSign) {//我的签名
  34. self.parameters[@"userTag"] = self.textView.text;
  35. }
  36. [[HttpManager sharedHttpManager] POST:URL parameters:self.parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  37. NSLog(@"%@",responseObject);
  38. REMOVESHOW
  39. if ([responseObject[@"code"] integerValue] == 0) {
  40. SHOWSUCCESS(@"提交成功")
  41. if (self.blockFeedBack) {
  42. self.blockFeedBack();
  43. }
  44. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  45. [self.navigationController popViewControllerAnimated:true];
  46. });
  47. }
  48. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  49. REMOVESHOW
  50. SHOWERROR(@"提交失败")
  51. }];
  52. }
  53. - (void)viewDidLoad {
  54. [super viewDidLoad];
  55. self.viewBottom.hidden = true;
  56. if (self.controllerType == FeedbackViewControllerTypeSelfIntroduction) {
  57. self.title = @"自我介绍";
  58. if (self.modelMy.myselfMsg.length) {
  59. self.textView.text = self.modelMy.myselfMsg;
  60. self.labelTextLength.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)self.textView.text.length];
  61. }else
  62. self.labelPlaceholder.text = @"请输入您的介绍";
  63. }else if (self.controllerType == FeedbackViewControllerTypeSign) {
  64. self.title = @"我的签名";
  65. if (self.modelMy.userTag.length) {
  66. self.textView.text = self.modelMy.userTag;
  67. self.labelTextLength.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)self.textView.text.length];
  68. }else
  69. self.labelPlaceholder.text = @"请输入您的签名";
  70. }else if (self.controllerType == FeedbackViewControllerTypeFeedback) {
  71. self.title = @"意见反馈";
  72. self.labelPlaceholder.text = @"请输入您的意见";
  73. self.viewBottom.hidden = false;
  74. self.feedbackType = 1;
  75. }else if (self.controllerType == FeedbackViewControllerTypeEvaluate) {
  76. self.title = @"商品评价";
  77. self.labelPlaceholder.text = @"请输入您对商品的评价";
  78. }
  79. self.view.backgroundColor = kBackgroundColor;
  80. self.textView.delegate = self;
  81. self.textView.returnKeyType = UIReturnKeyDone;
  82. [self.buttonCheck setCorner];
  83. }
  84. #pragma textView
  85. - (void)textViewDidBeginEditing:(UITextView *)textView {
  86. self.labelPlaceholder.hidden = true;
  87. }
  88. - (void)textViewDidEndEditing:(UITextView *)textView {
  89. if (textView.text.length == 0) {
  90. self.labelPlaceholder.hidden = false;
  91. }
  92. }
  93. - (void)textViewDidChange:(UITextView *)textView {
  94. self.labelTextLength.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)textView.text.length];
  95. if (textView == self.textView){
  96. if (textView.text.length >= 140) {
  97. [textView resignFirstResponder];
  98. }
  99. }
  100. }
  101. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  102. if (textView == self.textView) {
  103. if ([text isEqualToString:@"\n"]){
  104. [self.textView resignFirstResponder];
  105. return NO;
  106. }
  107. if (text.length == 0) return YES;
  108. NSInteger existedLength = textView.text.length;
  109. NSInteger selectedLength = range.length;
  110. NSInteger replaceLength = text.length;
  111. if (existedLength - selectedLength + replaceLength > 140) {
  112. [textView resignFirstResponder];
  113. return NO;
  114. }
  115. self.labelTextLength.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)textView.text.length];
  116. }
  117. return YES;
  118. }
  119. - (IBAction)didTouchButtonCheck:(UIButton *)sender {
  120. if (self.textView.text.length == 0) {
  121. SHOWERROR(@"说点儿什么吧")
  122. return;
  123. }
  124. [self Network];
  125. }
  126. - (IBAction)didTouchButtonType:(UIButton *)sender {
  127. [self.arrayButtonType enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  128. UIButton *button = obj;
  129. button.selected = false;
  130. }];
  131. sender.selected = true;
  132. self.feedbackType = sender.tag;
  133. }
  134. @end