// // YOUPAILZChatRoomReportWindow.m // VQU // // Created by CY on 2021/11/11. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZChatRoomReportWindow.h" #import "YOUPAILZChatRoomReportTypeCell.h" #import "YOUPAILZTextView.h" #import "IQKeyboardManager.h" @interface YOUPAILZChatRoomReportWindow () @property (nonatomic,weak)UICollectionView *youpaipcollectionView; @property (nonatomic,weak)YOUPAILZTextView *youpaipdescTextView; @property (nonatomic,weak)UIButton *youpaipsubmitBtn; @property (nonatomic,strong)NSArray *youpaipdataSource; @property (nonatomic,strong)YOUPAILZChatRoomReportTypeModel *youpaipselectedModel; @end @implementation YOUPAILZChatRoomReportWindow - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[IQKeyboardManager sharedManager] setEnable:YES]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[IQKeyboardManager sharedManager] setEnable:NO]; } - (void)viewDidLoad { [super viewDidLoad]; self.baseView.hidden = YES; [IQKeyboardManager sharedManager].enableAutoToolbar = NO; // 控制是否显示键盘上的工具条 [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = NavBarHeight; // [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES; [self youpaifinitUI]; [self youpaifrequestReportTypeList]; } - (void)youpaifinitUI{ UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 551.0f + SafeHeight)]; bgV.backgroundColor = HexColorFromRGB(0x2A2935); [self.view addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.offset(0.0f); make.height.offset(551.0f + SafeHeight); }]; [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)]; UIView *navV = [[UIView alloc] init]; [bgV addSubview:navV]; [navV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.offset(0.0f); make.height.offset(49.0f); }]; UIButton *youpaipcloseBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_nav_return_white"] forState:UIControlStateNormal]; [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_nav_return_white"] forState:UIControlStateHighlighted]; [youpaipcloseBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside]; [navV addSubview:youpaipcloseBtn]; [youpaipcloseBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(4.0f); make.centerY.equalTo(navV); make.size.mas_offset(CGSizeMake(44.0f, 44.0f)); }]; UILabel *titleL = [[UILabel alloc] init]; titleL.text = @"举报"; titleL.textColor = [UIColor whiteColor]; titleL.font = LCBoldFont(17.0f); [navV addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(navV); }]; UILabel *typeL = [[UILabel alloc] init]; typeL.font = LCFont(12.0f); typeL.textColor = HexColorFromRGB(0x9F9DA5); typeL.text = @"举报类型"; [bgV addSubview:typeL]; [typeL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.top.equalTo(navV.mas_bottom).offset(10.0f); make.height.offset(17.0f); }]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; flowLayout.minimumLineSpacing = 14.0f; flowLayout.minimumInteritemSpacing = 14.0f; flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 14.0f, 14.0f, 14.0f); flowLayout.itemSize = CGSizeMake(((KScreenWidth - 14.0f) / 3.0f) - 14.0f, 40.0f); UICollectionView *youpaipcollectonView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; youpaipcollectonView.delegate = self; youpaipcollectonView.dataSource = self; youpaipcollectonView.showsVerticalScrollIndicator = NO; youpaipcollectonView.showsHorizontalScrollIndicator = NO; youpaipcollectonView.backgroundColor = [UIColor clearColor]; youpaipcollectonView.clipsToBounds = NO; [youpaipcollectonView registerClass:YOUPAILZChatRoomReportTypeCell.class forCellWithReuseIdentifier:NSStringFromClass(YOUPAILZChatRoomReportTypeCell.class)]; [bgV addSubview:youpaipcollectonView]; self.youpaipcollectionView = youpaipcollectonView; [youpaipcollectonView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(navV.mas_bottom).offset(37.0f); make.left.right.offset(0.0f); make.height.offset(108.0f); }]; UILabel *descL = [[UILabel alloc] init]; descL.font = LCFont(12.0f); descL.textColor = HexColorFromRGB(0x9F9DA5); descL.text = @"举报理由"; [bgV addSubview:descL]; [descL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.top.equalTo(youpaipcollectonView.mas_bottom).offset(10.0f); make.height.offset(17.0f); }]; YOUPAILZTextView *youpaipdescTextView = [[YOUPAILZTextView alloc] initWithMaxCount:200.0f]; youpaipdescTextView.youpaiptextViewPadding = UIEdgeInsetsMake(15.0f, 12.0f, 16.0f, 12.0f); youpaipdescTextView.youpaiptextLengthDefaultColor = HexColorFromRGB(0x6C6B70); youpaipdescTextView.youpaiptextLengthHigtColor = ZYPinkColor; youpaipdescTextView.youpaiptextLengthFont = LCFont(14.0f); youpaipdescTextView.youpaiptextLengthRight = 14.0f; youpaipdescTextView.youpaiptextLengthBottom = 14.0f; youpaipdescTextView.youpaiptextView.placeholderFont = LCFont(14.0f); youpaipdescTextView.youpaiptextView.placeholderTextColor = HexColorFromRGB(0x908E96); youpaipdescTextView.youpaiptextView.placeholderText = @"请描述举报原因~"; youpaipdescTextView.youpaiptextView.textColor = [UIColor whiteColor]; youpaipdescTextView.youpaiptextView.font = LCFont(14.0f); youpaipdescTextView.backgroundColor = HexColorFromRGB(0x4F4B5B); youpaipdescTextView.layer.cornerRadius = 5.0f; youpaipdescTextView.clipsToBounds = YES; youpaipdescTextView.tintColor = ZYPinkColor; [bgV addSubview:youpaipdescTextView]; self.youpaipdescTextView = youpaipdescTextView; [youpaipdescTextView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.top.equalTo(descL.mas_bottom).offset(10.0f); make.size.mas_offset(CGSizeMake(KScreenWidth - 28.0f, 220.0f)); }]; UIButton *youpaipsubmitBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaipsubmitBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight] forState:UIControlStateSelected]; [youpaipsubmitBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; [youpaipsubmitBtn setTitle:@"提交" forState:UIControlStateNormal]; [youpaipsubmitBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal]; [youpaipsubmitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected]; youpaipsubmitBtn.titleLabel.font = LCFont(16.0f); youpaipsubmitBtn.layer.cornerRadius = 24.0f; youpaipsubmitBtn.clipsToBounds = YES; [youpaipsubmitBtn addTarget:self action:@selector(youpaifsubmitBtnClick) forControlEvents:UIControlEventTouchUpInside]; [bgV addSubview:youpaipsubmitBtn]; self.youpaipsubmitBtn = youpaipsubmitBtn; [youpaipsubmitBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(40.0f); make.top.equalTo(youpaipdescTextView.mas_bottom).offset(20.0f); make.size.mas_offset(CGSizeMake(KScreenWidth - 80.0f, 48.0f)); }]; } - (void)youpaifcloseBtnClick{ [self dismissViewControllerAnimated:YES completion:^{}]; } - (void)youpaifsubmitBtnClick{ @weakify(self); [LCHttpHelper requestWithURLString:ChatRoomReport parameters:@{@"room_id":self.youpaipchatroomModel.youpaiproom_id,@"type_id":self.youpaipselectedModel.youpaipid,@"content":self.youpaipdescTextView.youpaiptextView.text} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [ZCHUDHelper showTitle:@"举报成功"]; [self dismissViewControllerAnimated:YES completion:^{}]; } } failure:^(NSError *error) { }]; } #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.youpaipdataSource.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILZChatRoomReportTypeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(YOUPAILZChatRoomReportTypeCell.class) forIndexPath:indexPath]; [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]]; return cell; } #pragma mark - UICollectionViewDelegate - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ self.youpaipselectedModel.youpaipisSelected = NO; self.youpaipselectedModel = self.youpaipdataSource[indexPath.item]; self.youpaipselectedModel.youpaipisSelected = YES; [self.youpaipcollectionView reloadData]; [self youpaifhideKeyboard]; } - (void)youpaifrequestReportTypeList{ @weakify(self); [LCHttpHelper requestWithURLString:GetReportType parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) {//成功 self.youpaipdataSource = [YOUPAILZChatRoomReportTypeModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"] objectForKey:@"list"]]; [self.youpaipcollectionView reloadData]; } } failure:^(NSError *error) { }]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch* touch = [touches anyObject]; UIView* view = [touch view]; if (view != self.youpaipdescTextView) { [self youpaifhideKeyboard]; } } - (void)youpaifhideKeyboard{ dispatch_async(dispatch_get_main_queue(), ^{ [self.view endEditing:YES]; }); if (self.youpaipselectedModel != nil) { self.youpaipsubmitBtn.selected = YES; self.youpaipsubmitBtn.userInteractionEnabled = YES; }else{ self.youpaipsubmitBtn.selected = NO; self.youpaipsubmitBtn.userInteractionEnabled = NO; } } @end