// // FeedbackViewController.m // DSH // // Created by 张毅成 on 2018/10/8. // Copyright © 2018 WZX. All rights reserved. // #import "FeedbackViewController.h" @interface FeedbackViewController () @property (weak, nonatomic) IBOutlet UITextView *textView; @property (weak, nonatomic) IBOutlet UIButton *buttonCheck; @property (weak, nonatomic) IBOutlet UILabel *labelPlaceholder; @property (weak, nonatomic) IBOutlet UILabel *labelTextLength; @property (weak, nonatomic) IBOutlet UIView *viewBottom; @property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *arrayButtonType; @property (assign, nonatomic) NSInteger feedbackType; @end @implementation FeedbackViewController - (NSMutableDictionary *)parameters { if (!_parameters) { _parameters = @{}.mutableCopy; } return _parameters; } - (void)Network { SHOWLOADING NSString *URL = self.URL; self.parameters[@"content"] = self.textView.text; if (self.controllerType == FeedbackViewControllerTypeFeedback) {//意见反馈 self.parameters[@"type"] = @(self.feedbackType).stringValue; }else if (self.controllerType == FeedbackViewControllerTypeSelfIntroduction) {//自我介绍 self.parameters[@"myselfMsg"] = self.textView.text; }else if (self.controllerType == FeedbackViewControllerTypeSign) {//我的签名 self.parameters[@"userTag"] = self.textView.text; } [[HttpManager sharedHttpManager] POST:URL parameters:self.parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSLog(@"%@",responseObject); REMOVESHOW if ([responseObject[@"code"] integerValue] == 0) { SHOWSUCCESS(@"提交成功") if (self.blockFeedBack) { self.blockFeedBack(); } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.navigationController popViewControllerAnimated:true]; }); } } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { REMOVESHOW SHOWERROR(@"提交失败") }]; } - (void)viewDidLoad { [super viewDidLoad]; self.viewBottom.hidden = true; if (self.controllerType == FeedbackViewControllerTypeSelfIntroduction) { self.title = @"自我介绍"; if (self.modelMy.myselfMsg.length) { self.textView.text = self.modelMy.myselfMsg; self.labelTextLength.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)self.textView.text.length]; }else self.labelPlaceholder.text = @"请输入您的介绍"; }else if (self.controllerType == FeedbackViewControllerTypeSign) { self.title = @"我的签名"; if (self.modelMy.userTag.length) { self.textView.text = self.modelMy.userTag; self.labelTextLength.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)self.textView.text.length]; }else self.labelPlaceholder.text = @"请输入您的签名"; }else if (self.controllerType == FeedbackViewControllerTypeFeedback) { self.title = @"意见反馈"; self.labelPlaceholder.text = @"请输入您的意见"; self.viewBottom.hidden = false; self.feedbackType = 1; }else if (self.controllerType == FeedbackViewControllerTypeEvaluate) { self.title = @"商品评价"; self.labelPlaceholder.text = @"请输入您对商品的评价"; } self.view.backgroundColor = kBackgroundColor; self.textView.delegate = self; self.textView.returnKeyType = UIReturnKeyDone; [self.buttonCheck setCorner]; } #pragma textView - (void)textViewDidBeginEditing:(UITextView *)textView { self.labelPlaceholder.hidden = true; } - (void)textViewDidEndEditing:(UITextView *)textView { if (textView.text.length == 0) { self.labelPlaceholder.hidden = false; } } - (void)textViewDidChange:(UITextView *)textView { self.labelTextLength.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)textView.text.length]; if (textView == self.textView){ if (textView.text.length >= 140) { [textView resignFirstResponder]; } } } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if (textView == self.textView) { if ([text isEqualToString:@"\n"]){ [self.textView resignFirstResponder]; return NO; } if (text.length == 0) return YES; NSInteger existedLength = textView.text.length; NSInteger selectedLength = range.length; NSInteger replaceLength = text.length; if (existedLength - selectedLength + replaceLength > 140) { [textView resignFirstResponder]; return NO; } self.labelTextLength.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)textView.text.length]; } return YES; } - (IBAction)didTouchButtonCheck:(UIButton *)sender { if (self.textView.text.length == 0) { SHOWERROR(@"说点儿什么吧") return; } [self Network]; } - (IBAction)didTouchButtonType:(UIButton *)sender { [self.arrayButtonType enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { UIButton *button = obj; button.selected = false; }]; sender.selected = true; self.feedbackType = sender.tag; } @end