// // ReportViewController.m // Youth // // Created by mambaxie on 2022/1/2. // #import "ReportViewController.h" #import "FSTextInputView.h" @interface ReportViewController () @property (nonatomic, strong) FSTextInputView *inputView; @property (nonatomic, strong) NSMutableArray *addImageButtons; @property (nonatomic, strong) PYThemeButton *okButton; @end @implementation ReportViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"举报"; self.view.backgroundColor = BG_COLOR; UIView *imageItem = [[UIView alloc] init]; imageItem.width = SCREEN_WIDTH; imageItem.backgroundColor = [UIColor clearColor]; UIView *imageSection = [self sectionWithTitle:@"图片证据" tips:@"(至少1张 · 重要)"]; imageSection.y = NAVIGATION_BAR_HEIGHT; [imageItem addSubview:imageSection]; self.addImageButtons = [NSMutableArray array]; WeakSelf(self); for (int i = 0; i < 3; i++) { PYThemeButton *addButton = [PYThemeButton addImageButtonWithAction:^(UIButton * _Nonnull btn) { [weakself updateOKButton]; }]; addButton.x = FIX_SIZE(15) + (addButton.width + FIX_SIZE(10)) * i; addButton.y = imageSection.bottom + FIX_SIZE(10); [self.addImageButtons addObject:addButton]; [imageItem addSubview:addButton]; imageItem.height = addButton.bottom + FIX_SIZE(15); } [self.view addSubview:imageItem]; UIView *contentItem = [UIView new]; contentItem.backgroundColor = UIColor.clearColor; contentItem.width = SCREEN_WIDTH; [self.view addSubview:contentItem]; contentItem.y = imageItem.bottom + FIX_SIZE(10); UIView *contentSection = [self sectionWithTitle:@"举报内容" tips:@"(必选)"]; [contentItem addSubview:contentSection]; FSTextInputView *inputView = [[FSTextInputView alloc] init]; inputView.placeHolderLabel.text = @"最多200字"; inputView.x = FIX_SIZE(15); inputView.y = contentSection.bottom + FIX_SIZE(10); inputView.width = self.view.width - inputView.x * 2; inputView.height = FIX_SIZE(90); inputView.maxTextLength = 200; [contentItem addSubview:inputView]; inputView.backgroundColor = COLOR_WITH_RGB(0x2D2F42 ); inputView.textview.font = MT_FONT_REGULAR_SIZE(13); inputView.textview.textColor = TITLE_COLOR; inputView.layer.cornerRadius = FIX_SIZE(13); inputView.layer.borderWidth = 0.5; inputView.layer.borderColor = COLOR_WITH_RGB(0x83A4A).CGColor; self.inputView = inputView; contentItem.height = inputView.bottom + FIX_SIZE(15); PYThemeButton *okButton = [PYThemeButton buttonWithTitle:@"提交" action:^(UIButton * _Nonnull button) { [SVProgressHUD showWithStatus:nil]; NSMutableArray *datasM = [NSMutableArray array]; for (PYThemeButton *btn in weakself.addImageButtons) { if (btn.addedImage) { [datasM addObject:compressImageToDataIfNeed(btn.addedImage)]; } } NSString *content = weakself.inputView.textview.text; [PYHTTPManager uploadFileWithScene:AliOSSUploadSceneReport datas:datasM completion:^(id _Nullable rsp, NSError * _Nullable error) { if (!error) { NSMutableDictionary *paramsM = [NSMutableDictionary dictionary]; if ([rsp isKindOfClass:[NSArray class]]) { NSArray *urls = rsp; if (urls.count >= 1) { paramsM[@"report_img_one"] = urls[0]; } if (urls.count >= 2) { paramsM[@"report_img_two"] = urls[1]; } if (urls.count >= 3) { paramsM[@"report_img_three"] = urls[2]; } } paramsM[@"report_text"] = content; paramsM[@"report_user_id"] = @(weakself.user.ID); [PYHTTPManager postWithPath:@"reportuser" params:paramsM callback:^(id _Nullable rsp, NSError * _Nullable error) { if (!error) { [SVProgressHUD showSuccessWithStatus:@"举报成功"]; [weakself.navigationController popViewControllerAnimated:YES]; } }]; } }]; }]; self.okButton = okButton; okButton.enabled = NO; [self.view addSubview:okButton]; okButton.bottom = SCREEN_HEIGHT - FIX_SIZE(28); inputView.didChangeText = ^(FSTextInputView *inputView) { [weakself updateOKButton]; }; } - (void)updateOKButton { BOOL hasImage = NO; for (PYThemeButton *btn in self.addImageButtons) { if (btn.addedImage) { hasImage = YES; break; } } self.okButton.enabled = self.inputView.textview.hasText && hasImage; } - (UIView *)sectionWithTitle:(NSString *)title tips:(NSString *)tips { UIView *item = [[UIView alloc] init]; item.width = SCREEN_WIDTH; item.height = FIX_SIZE(48); UILabel *titleLabel = [UILabel mt_titleLabelWithText:title]; titleLabel.font = MT_FONT_MEDIUM_SIZE(13); titleLabel.textColor = TITLE_COLOR; [titleLabel sizeToFit]; titleLabel.x = FIX_SIZE(15); titleLabel.centerY = item.height * 0.5; [item addSubview:titleLabel]; UILabel *tipsLabel = [UILabel mt_titleLabelWithText:tips]; tipsLabel.font = MT_FONT_MEDIUM_SIZE(11); tipsLabel.textColor = COLOR_WITH_RGB(0xFC4588); [tipsLabel sizeToFit]; tipsLabel.x = titleLabel.right; tipsLabel.centerY = item.height * 0.5; [item addSubview:tipsLabel]; return item; } @end