123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- //
- // YOUPAIHRChatRoomEditInfoVC.m
- // VQU
- //
- // Created by xiaohaoran on 2021/11/8.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAIHRChatRoomEditInfoVC.h"
- #import "IQKeyboardManager.h"
- #import "YOUPAILZTextView.h"
- @interface YOUPAIHRChatRoomEditInfoVC ()<UIScrollViewDelegate,TZImagePickerControllerDelegate,UITextFieldDelegate,UITextViewDelegate,UIGestureRecognizerDelegate>
- @property(nonatomic,strong)UIImageView *youpaipavtarImageView;
- @property(nonatomic,strong)UITextField *youpaiptextField;
- @property(nonatomic,strong)UILabel *youpaipplaceholderLabel;
- @property(nonatomic,strong)UILabel *youpaiptextCountLabel;
- @property(nonatomic,strong)UILabel *youpaipcountLabel;
- @property(nonatomic,strong)UIScrollView *youpaipscrollview;
- @property (copy, nonatomic) NSString *youpaipimageUrl;
- @property(nonatomic,strong)UIButton *youpaipsaveBtn;
- @property (nonatomic,weak)YOUPAILZTextView *youpaiptextView;
- @end
- @implementation YOUPAIHRChatRoomEditInfoVC
- - (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.title = @"编辑资料";
-
- [IQKeyboardManager sharedManager].enableAutoToolbar = NO; // 控制是否显示键盘上的工具条
- [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = NavBarHeight; //
- [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
- [self youpaifsetupUI];
- [self youpaifloadData];
- }
- -(void)youpaifsaveBtnClick{
- NSLog(@"hahahah");
- [self youpaifupdataInfo];
- }
- -(void)youpaifupdataInfo{
- @weakify(self);
-
- NSMutableDictionary *mutDict = [NSMutableDictionary new];
- [mutDict setObject:@(self.youpaiproom_id) forKey:@"room_id"];
- [mutDict setValue:self.youpaiptextField.text forKey:@"title"];
- [mutDict setValue:self.youpaiptextView.youpaiptextView.text forKey:@"notice"];
- [mutDict setValue:self.youpaipimageUrl forKey:@"cover_img"];
- [LCHttpHelper requestWithURLString:ChatRoom_setTalkTitleANotice parameters:mutDict needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
-
- [self.navigationController popViewControllerAnimated:YES];
- }else{
- [ZCHUDHelper showTitle:dict[@"message"]];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- -(void)youpaifsetupUI{
-
- UIScrollView *scrollView = [[UIScrollView alloc]init];
- self.youpaipscrollview = scrollView;
- [self.view addSubview:scrollView];
- [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(NavBarHeight);
- make.left.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.bottom.mas_equalTo(-SafeHeight);
- }];
- scrollView.showsVerticalScrollIndicator = NO;
- scrollView.showsHorizontalScrollIndicator = NO;
- scrollView.backgroundColor = LCBkgColor;
- //headView
- UIView *headerView = [UIView new];
- [scrollView addSubview:headerView];
- [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.width.mas_equalTo(KScreenWidth);
- make.top.mas_equalTo(0);
- make.height.mas_equalTo(211);
- }];
-
- //头像
- UIImageView *youpaipavtarImageView = [UIImageView new];
- self.youpaipavtarImageView = youpaipavtarImageView;
- [headerView addSubview:youpaipavtarImageView];
- [youpaipavtarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(30);
- make.centerX.mas_equalTo(0);
- make.size.mas_equalTo(CGSizeMake(100, 100));
- }];
- youpaipavtarImageView.userInteractionEnabled = YES;
- youpaipavtarImageView.layer.cornerRadius = 10;
- youpaipavtarImageView.layer.masksToBounds = YES;
- youpaipavtarImageView.contentMode = UIViewContentModeScaleAspectFill;
- youpaipavtarImageView.clipsToBounds = YES;
- youpaipavtarImageView.image = [UIImage imageNamed:@"vqu_images_finish_msg_n"];
- UITapGestureRecognizer *avtarImageViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifopenAlbum)];
- avtarImageViewTap.delegate = self;
- [self.youpaipavtarImageView addGestureRecognizer:avtarImageViewTap];
- //
- UIImageView *avtarImageView1 = [UIImageView new];
- [youpaipavtarImageView addSubview:avtarImageView1];
- [avtarImageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.mas_equalTo(0);
- make.centerX.mas_equalTo(0);
- make.size.mas_equalTo(CGSizeMake(24, 24));
- }];
- avtarImageView1.image = [UIImage imageNamed:@"vqu_images_chatroom_photo"];
- //
- UILabel *titleLabel = [UILabel new];
- [headerView addSubview:titleLabel];
- [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(youpaipavtarImageView);
- make.top.mas_equalTo(youpaipavtarImageView.mas_bottom).offset(14);
- }];
- titleLabel.text = @"点击图片更换房间封面";
- titleLabel.textColor = HexColorFromRGB(0x9F9DA5);
- titleLabel.font = [UIFont systemFontOfSize:12];
- //房间名称
- UILabel *roomLabel = [UILabel new];
- [scrollView addSubview:roomLabel];
- [roomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(14);
- make.top.mas_equalTo(headerView.mas_bottom);
- }];
- roomLabel.text = @"房间名称";
- roomLabel.textColor = HexColorFromRGB(0x9F9DA5);
- roomLabel.font = [UIFont systemFontOfSize:12];
-
- //bgView
- UIView *roomBgView = [[UIView alloc]init];
- [scrollView addSubview:roomBgView];
- [roomBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(14);
- make.top.mas_equalTo(roomLabel.mas_bottom).offset(10);
- make.width.mas_equalTo(KScreenWidth-28);
- make.height.mas_equalTo(49);
- }];
- roomBgView.backgroundColor = HexColorFromRGB(0x2A2935);
- roomBgView.layer.cornerRadius = 5.0f;
- roomBgView.layer.masksToBounds = YES;
-
-
- UITextField* textField = [[UITextField alloc]init];
- [roomBgView addSubview:textField];
- [textField mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- textField.tintColor = ZYPinkColor;
- textField.backgroundColor = HexColorFromRGB(0x2A2935);
- textField.layer.cornerRadius = 5.0f;
- textField.layer.masksToBounds = YES;
- textField.delegate = self;
- textField.font = LCFont(14);
- textField.textColor = [UIColor whiteColor];
- textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,12,49)];
- textField.leftViewMode = UITextFieldViewModeAlways;
- NSString *holderText = @"输入房间名称";
- NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:holderText];
- [placeholder addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x6C6B70) range:NSMakeRange(0, holderText.length)];
- [placeholder addAttribute:NSFontAttributeName value:LCFont(14) range:NSMakeRange(0, holderText.length)];
- textField.attributedPlaceholder = placeholder;
- self.youpaiptextField = textField;
- //添加监听
- [self.youpaiptextField addTarget:self action:@selector(textFieldTextDidChange:) forControlEvents:UIControlEventEditingChanged];
- //字数提示
- UILabel *youpaipcountLabel = [UILabel new];
- self.youpaipcountLabel = youpaipcountLabel;
- [roomBgView addSubview:youpaipcountLabel];
- [youpaipcountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-12);
- make.centerY.mas_equalTo(0);
- }];
-
- youpaipcountLabel.textColor = HexColorFromRGB(0x6C6B70);
- youpaipcountLabel.font = [UIFont systemFontOfSize:14];
- //房间公告
- UILabel *noticLabel = [UILabel new];
- [scrollView addSubview:noticLabel];
- [noticLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(14);
- make.top.mas_equalTo(roomBgView.mas_bottom).offset(24);
- }];
- noticLabel.text = @"房间公告";
- noticLabel.textColor = HexColorFromRGB(0x9F9DA5);
- noticLabel.font = [UIFont systemFontOfSize:12];
- //输入框bg
- UIView *textViewBgView = [[UIView alloc]init];
- [scrollView addSubview:textViewBgView];
- [textViewBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(14);
- make.width.mas_equalTo(KScreenWidth-28);
- make.top.mas_equalTo(noticLabel.mas_bottom).offset(10);
- make.height.mas_equalTo(220);
- }];
- textViewBgView.backgroundColor = HexColorFromRGB(0x2A2935);
- textViewBgView.layer.cornerRadius = 5;
- textViewBgView.layer.masksToBounds = YES;
- //
- YOUPAILZTextView *textView = [[YOUPAILZTextView alloc] initWithMaxCount:200.0f];
- textView.youpaiptextViewPadding = UIEdgeInsetsMake(15.0f, 12.0f, 16.0f, 12.0f);
- textView.youpaiptextLengthDefaultColor = HexColorFromRGB(0x6C6B70);
- textView.youpaiptextLengthHigtColor = ZYPinkColor;
- textView.youpaiptextLengthFont = LCFont(14.0f);
- textView.youpaiptextLengthRight = 12.0f;
- textView.youpaiptextLengthBottom = 18.0f;
- textView.youpaiptextView.placeholderFont = LCFont(14.0f);
- textView.youpaiptextView.placeholderTextColor = HexColorFromRGB(0x908E96);
- textView.youpaiptextView.placeholderText = @"请输入房间公告";
- textView.youpaiptextView.font = LCFont(14.0f);
- textView.backgroundColor = HexColorFromRGB(0x4F4B5B);
- textView.layer.cornerRadius = 5.0f;
- textView.clipsToBounds = YES;
- textView.tintColor = ZYPinkColor;
- [textViewBgView addSubview:textView];
- textView.youpaiptextView.textColor = HexColorFromRGB(0xffffff);
- self.youpaiptextView = textView;
- textView.backgroundColor = [UIColor clearColor];
- [textView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- //保存资料
- UIButton *youpaipsaveBtn = [UIButton new];
- self.youpaipsaveBtn = youpaipsaveBtn;
- [scrollView addSubview:youpaipsaveBtn];
- [youpaipsaveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(0);
- make.top.mas_equalTo(textViewBgView.mas_bottom).offset(40);
- make.size.mas_equalTo(CGSizeMake(294, 49));
- }];
- [youpaipsaveBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(294, 49) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:1] forState:UIControlStateNormal];
- [youpaipsaveBtn setTitle:@"保存资料" forState:UIControlStateNormal];
- [youpaipsaveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- youpaipsaveBtn.titleLabel.font = LCBoldFont(16);
- [youpaipsaveBtn addTarget:self action:@selector(youpaifsaveBtnClick) forControlEvents:UIControlEventTouchUpInside];
- youpaipsaveBtn.layer.cornerRadius = 49/2;
- youpaipsaveBtn.layer.masksToBounds = YES;
-
- if (scrollView.contentSize.height>KScreenHeight) {
- scrollView.contentSize = CGSizeMake(KScreenWidth, KScreenHeight + 1);
- }else{
- scrollView.contentSize = CGSizeMake(KScreenWidth, KScreenHeight);
- }
-
- }
- //监听改变方法
- - (void)textFieldTextDidChange:(UITextField *)textChange{
- NSString * temp = textChange.text;
- if (temp.length >= 15) {
-
- textChange.text = [textChange.text substringToIndex:15];
- }else{
-
- }
- self.youpaipcountLabel.text = [NSString stringWithFormat:@"%@/%@",@(textChange.text.length),@(15)];
- }
- -(void)youpaifupdateStartBtnStatu{
- if (![self.youpaiptextField.text isEqualToString:@""] ||
- ![self.youpaiptextView.youpaiptextView.text isEqualToString:@""]||
- !self.youpaipimageUrl) {
- [self.youpaipsaveBtn setBackgroundImage:[LCTools ColorImage:self.youpaipsaveBtn.frame.size FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
- self.youpaipsaveBtn.userInteractionEnabled = YES;;
- }else{
- self.youpaipsaveBtn.backgroundColor = HexColorFromRGB(0x2A2935);
- [self.youpaipsaveBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
- self.youpaipsaveBtn.userInteractionEnabled = NO;
- }
-
- }
- - (void)youpaifopenAlbum{
-
- @weakify(self);
- TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self];
- [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVc];
- imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮
- imagePickerVc.allowPickingVideo = NO;//是否允许选择视频
- imagePickerVc.allowPickingImage = YES;//是否允许选择照片
- imagePickerVc.allowPickingOriginalPhoto = NO;//是否选择原图
- imagePickerVc.showSelectedIndex = YES; //显示图片序号
- imagePickerVc.allowCrop = NO;//是否允许裁剪
-
- // // 裁剪框的尺寸
- // imagePickerVc.cropRect = CGRectMake(0, KScreenHeight/2-(KScreenWidth/3.0*4)/2, KScreenWidth,KScreenWidth/3.0*4);
- // 4. 照片排列按修改时间升序
- imagePickerVc.sortAscendingByModificationDate = YES;//按时间倒序排列图片
- // You can get the photos by block, the same as by delegate.
- // 你可以通过block或者代理,来得到用户选择的照片.
-
- [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
- [ZCHUDHelper showWithStatus:@"上传中..."];
- @strongify(self);
- // 1通过,0待审核,2,未通过
- [LCCommonHttp uploadWithImages:photos Type:@"cover" successBlock:^(NSArray<NSString *> *ossImagePaths) {
- [ZCHUDHelper dismiss];
- self.youpaipimageUrl = ossImagePaths.firstObject;
- self.youpaipavtarImageView.image = photos[0];
-
- [self youpaifupdateStartBtnStatu];
- }];
- }];
- [self presentViewController:imagePickerVc animated:YES completion:nil];
- }
- - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
- NSLog(@"%@",photos[0]);
- }
- -(void)youpaifloadData{
- @weakify(self);
- [LCHttpHelper requestWithURLString:ChatRoom_getDataBefore parameters:@{@"room_id":@(self.youpaiproom_id)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
- NSString *youpaipcover_img = dict[@"data"][@"cover_img"];
- NSString *title = dict[@"data"][@"title"];
- NSString *notice = dict[@"data"][@"notice"];
- [self.youpaipavtarImageView sd_setImageWithURL:[LCTools getImageUrlWithAddress:youpaipcover_img] placeholderImage:[UIImage imageNamed:@"vqu_images_finish_msg_n"]];
- self.youpaipimageUrl = youpaipcover_img;
- self.youpaiptextField.text = title;
- self.youpaipcountLabel.text = [NSString stringWithFormat:@"%lu/15",(unsigned long)title.length];
- self.youpaiptextView.youpaiptextView.text = notice;
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextViewTextDidChangeNotification object:self.youpaiptextField];
- }
- @end
|