SLFeedbackVc.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // SLFeedbackVc.m
  3. // SLAiELTS
  4. //
  5. // Created by Gusont on 2023/3/14.
  6. //
  7. #import "SLFeedbackVc.h"
  8. #import "PlaceholderTextView.h"
  9. #import "SLBaseCellView.h"
  10. #import "SLPickView.h"
  11. #import "ZLPhotoBrowerView.h"
  12. @interface SLFeedbackVc ()<UITextViewDelegate>
  13. @property (weak, nonatomic) IBOutlet SLBaseCellView *topView;
  14. @property (weak, nonatomic) IBOutlet PlaceholderTextView *textView;
  15. @property (weak, nonatomic) IBOutlet UILabel *textLabel;
  16. @property (weak, nonatomic) IBOutlet UISwitch *feedBackSwitch;
  17. @property (weak, nonatomic) IBOutlet ZLPhotoBrowerView *photoBrowerView;
  18. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *photoHeightConst;
  19. @property (nonatomic, strong)NSString *classify;
  20. @property (nonatomic, strong) NSMutableArray *photoBrowerModels;
  21. @end
  22. @implementation SLFeedbackVc
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view from its nib.
  26. self.title = @"意见反馈";
  27. self.classify = @"";
  28. self.textView.placeholder = @"想对我们说什么?";
  29. self.textView.font = [UIFont systemFontOfSize:16];
  30. self.textView.delegate = self;
  31. self.topView.titleLabel.text = @"选择问题分类";
  32. self.topView.titleLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.9];
  33. self.topView.subTitleLabel.text = @"问题类别";
  34. [self.topView updateConstraintsWith:SLBaseCellView1];
  35. self.topView.lineView.hidden = YES;
  36. WS(weakSelf);
  37. [self.topView addTapWithBlock:^{
  38. NSMutableArray *arr = [NSMutableArray array];
  39. [arr addObject:@[@"功能bug",@"提升建议",@"其他类型"]];
  40. SLPickView *pickView = [[SLPickView alloc] initWithPickerData:arr];
  41. pickView.resultBlock = ^(NSString * _Nullable str, NSArray *titlesValue) {
  42. weakSelf.classify = str;
  43. weakSelf.topView.subTitleLabel.text = str;
  44. };
  45. [pickView show];
  46. }];
  47. self.photoBrowerView.maxSelectCount = 3;
  48. // self.photoBrowerView.lineCount = 4;
  49. self.photoBrowerModels = [NSMutableArray array];
  50. self.photoBrowerView.dataArray = self.photoBrowerModels;
  51. self.photoBrowerView.selectedData = ^(NSMutableArray<ZLPhotoBrowerModel *> *photoBrowerModels) {
  52. weakSelf.photoBrowerModels = photoBrowerModels;
  53. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  54. float collectViewHeight = weakSelf.photoBrowerView.collectionView.collectionViewLayout.collectionViewContentSize.height;
  55. weakSelf.photoHeightConst.constant = collectViewHeight;
  56. });
  57. };
  58. }
  59. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  60. NSString *toBeString = [textView.text stringByReplacingCharactersInRange:range withString:text];
  61. if (toBeString.length > 500) {
  62. return NO;
  63. }
  64. self.textLabel.text = [NSString stringWithFormat:@"%ld/500",toBeString.length];
  65. return YES;
  66. }
  67. - (IBAction)sureBtnClick:(id)sender {
  68. if (!self.classify.length) {
  69. [ZFToast ShowWithMessage:@"请选择问题类别"];
  70. return;
  71. }
  72. if (!self.textView.text.length) {
  73. [ZFToast ShowWithMessage:@"请输入反馈内容"];
  74. return;
  75. }
  76. if (self.textView.text.length) {
  77. WS(weakSelf);
  78. void(^InsertFeedback)(NSString *imgUrls) = ^(NSString *imgUrls){
  79. NSDictionary *dict = @{@"classify" : self.classify, @"content" : self.textView.text, @"isContact" : @(self.feedBackSwitch.isOn), @"url" : imgUrls ?: @""};
  80. [[SLHttpCenter SharedInstance] postWithUrl:@"/api/User/InsertFeedback" parameter:dict success:^(id responseObject) {
  81. [ZFToast ShowWithMessage:@"反馈成功"];
  82. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  83. [self.navigationController popToRootViewControllerAnimated:YES];
  84. });
  85. } failure:^(SPRequestError *error) {
  86. }];
  87. };
  88. if (self.photoBrowerModels.count) {
  89. [[SLHttpCenter SharedInstance] postWithSubmitUrl:@"/api/User/UploadFiles" parameter:@{} formDataHandel:^(id<AFMultipartFormData> _Nonnull formData) {
  90. [self.photoBrowerModels enumerateObjectsUsingBlock:^(ZLPhotoBrowerModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
  91. [formData appendPartWithFileData:obj.imageData name:@"file" fileName:obj.imageName mimeType:@"image/png"];
  92. }];
  93. } success:^(id responseObject) {
  94. NSString *url = [responseObject objectForKey:@"data"];
  95. InsertFeedback(url);
  96. } failure:^(SPRequestError *error) {
  97. }];
  98. }else {
  99. InsertFeedback(@"");
  100. }
  101. }
  102. }
  103. @end