YOUPAIHRChatRoomEditInfoVC.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. //
  2. // YOUPAIHRChatRoomEditInfoVC.m
  3. // VQU
  4. //
  5. // Created by xiaohaoran on 2021/11/8.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRChatRoomEditInfoVC.h"
  9. #import "IQKeyboardManager.h"
  10. #import "YOUPAILZTextView.h"
  11. @interface YOUPAIHRChatRoomEditInfoVC ()<UIScrollViewDelegate,TZImagePickerControllerDelegate,UITextFieldDelegate,UITextViewDelegate,UIGestureRecognizerDelegate>
  12. @property(nonatomic,strong)UIImageView *youpaipavtarImageView;
  13. @property(nonatomic,strong)UITextField *youpaiptextField;
  14. @property(nonatomic,strong)UILabel *youpaipplaceholderLabel;
  15. @property(nonatomic,strong)UILabel *youpaiptextCountLabel;
  16. @property(nonatomic,strong)UILabel *youpaipcountLabel;
  17. @property(nonatomic,strong)UIScrollView *youpaipscrollview;
  18. @property (copy, nonatomic) NSString *youpaipimageUrl;
  19. @property(nonatomic,strong)UIButton *youpaipsaveBtn;
  20. @property (nonatomic,weak)YOUPAILZTextView *youpaiptextView;
  21. @end
  22. @implementation YOUPAIHRChatRoomEditInfoVC
  23. - (void)viewWillAppear:(BOOL)animated {
  24. [super viewWillAppear:animated];
  25. [[IQKeyboardManager sharedManager] setEnable:YES];
  26. }
  27. - (void)viewWillDisappear:(BOOL)animated {
  28. [super viewWillDisappear:animated];
  29. [[IQKeyboardManager sharedManager] setEnable:NO];
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. self.title = @"编辑资料";
  34. [IQKeyboardManager sharedManager].enableAutoToolbar = NO; // 控制是否显示键盘上的工具条
  35. [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = NavBarHeight; //
  36. [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
  37. [self youpaifsetupUI];
  38. [self youpaifloadData];
  39. }
  40. -(void)youpaifsaveBtnClick{
  41. NSLog(@"hahahah");
  42. [self youpaifupdataInfo];
  43. }
  44. -(void)youpaifupdataInfo{
  45. @weakify(self);
  46. NSMutableDictionary *mutDict = [NSMutableDictionary new];
  47. [mutDict setObject:@(self.youpaiproom_id) forKey:@"room_id"];
  48. [mutDict setValue:self.youpaiptextField.text forKey:@"title"];
  49. [mutDict setValue:self.youpaiptextView.youpaiptextView.text forKey:@"notice"];
  50. [mutDict setValue:self.youpaipimageUrl forKey:@"cover_img"];
  51. [LCHttpHelper requestWithURLString:ChatRoom_setTalkTitleANotice parameters:mutDict needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  52. @strongify(self);
  53. NSDictionary* dict = (NSDictionary*)responseObject;
  54. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  55. if (code == 0) {//成功
  56. [self.navigationController popViewControllerAnimated:YES];
  57. }else{
  58. [ZCHUDHelper showTitle:dict[@"message"]];
  59. }
  60. } failure:^(NSError *error) {
  61. }];
  62. }
  63. -(void)youpaifsetupUI{
  64. UIScrollView *scrollView = [[UIScrollView alloc]init];
  65. self.youpaipscrollview = scrollView;
  66. [self.view addSubview:scrollView];
  67. [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.mas_equalTo(NavBarHeight);
  69. make.left.mas_equalTo(0);
  70. make.right.mas_equalTo(0);
  71. make.bottom.mas_equalTo(-SafeHeight);
  72. }];
  73. scrollView.showsVerticalScrollIndicator = NO;
  74. scrollView.showsHorizontalScrollIndicator = NO;
  75. scrollView.backgroundColor = LCBkgColor;
  76. //headView
  77. UIView *headerView = [UIView new];
  78. [scrollView addSubview:headerView];
  79. [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.left.mas_equalTo(0);
  81. make.width.mas_equalTo(KScreenWidth);
  82. make.top.mas_equalTo(0);
  83. make.height.mas_equalTo(211);
  84. }];
  85. //头像
  86. UIImageView *youpaipavtarImageView = [UIImageView new];
  87. self.youpaipavtarImageView = youpaipavtarImageView;
  88. [headerView addSubview:youpaipavtarImageView];
  89. [youpaipavtarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.top.mas_equalTo(30);
  91. make.centerX.mas_equalTo(0);
  92. make.size.mas_equalTo(CGSizeMake(100, 100));
  93. }];
  94. youpaipavtarImageView.userInteractionEnabled = YES;
  95. youpaipavtarImageView.layer.cornerRadius = 10;
  96. youpaipavtarImageView.layer.masksToBounds = YES;
  97. youpaipavtarImageView.contentMode = UIViewContentModeScaleAspectFill;
  98. youpaipavtarImageView.clipsToBounds = YES;
  99. youpaipavtarImageView.image = [UIImage imageNamed:@"vqu_images_finish_msg_n"];
  100. UITapGestureRecognizer *avtarImageViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifopenAlbum)];
  101. avtarImageViewTap.delegate = self;
  102. [self.youpaipavtarImageView addGestureRecognizer:avtarImageViewTap];
  103. //
  104. UIImageView *avtarImageView1 = [UIImageView new];
  105. [youpaipavtarImageView addSubview:avtarImageView1];
  106. [avtarImageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.centerY.mas_equalTo(0);
  108. make.centerX.mas_equalTo(0);
  109. make.size.mas_equalTo(CGSizeMake(24, 24));
  110. }];
  111. avtarImageView1.image = [UIImage imageNamed:@"vqu_images_chatroom_photo"];
  112. //
  113. UILabel *titleLabel = [UILabel new];
  114. [headerView addSubview:titleLabel];
  115. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.centerX.mas_equalTo(youpaipavtarImageView);
  117. make.top.mas_equalTo(youpaipavtarImageView.mas_bottom).offset(14);
  118. }];
  119. titleLabel.text = @"点击图片更换房间封面";
  120. titleLabel.textColor = HexColorFromRGB(0x9F9DA5);
  121. titleLabel.font = [UIFont systemFontOfSize:12];
  122. //房间名称
  123. UILabel *roomLabel = [UILabel new];
  124. [scrollView addSubview:roomLabel];
  125. [roomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.left.mas_equalTo(14);
  127. make.top.mas_equalTo(headerView.mas_bottom);
  128. }];
  129. roomLabel.text = @"房间名称";
  130. roomLabel.textColor = HexColorFromRGB(0x9F9DA5);
  131. roomLabel.font = [UIFont systemFontOfSize:12];
  132. //bgView
  133. UIView *roomBgView = [[UIView alloc]init];
  134. [scrollView addSubview:roomBgView];
  135. [roomBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.left.mas_equalTo(14);
  137. make.top.mas_equalTo(roomLabel.mas_bottom).offset(10);
  138. make.width.mas_equalTo(KScreenWidth-28);
  139. make.height.mas_equalTo(49);
  140. }];
  141. roomBgView.backgroundColor = HexColorFromRGB(0x2A2935);
  142. roomBgView.layer.cornerRadius = 5.0f;
  143. roomBgView.layer.masksToBounds = YES;
  144. UITextField* textField = [[UITextField alloc]init];
  145. [roomBgView addSubview:textField];
  146. [textField mas_makeConstraints:^(MASConstraintMaker *make) {
  147. make.edges.mas_equalTo(0);
  148. }];
  149. textField.tintColor = ZYPinkColor;
  150. textField.backgroundColor = HexColorFromRGB(0x2A2935);
  151. textField.layer.cornerRadius = 5.0f;
  152. textField.layer.masksToBounds = YES;
  153. textField.delegate = self;
  154. textField.font = LCFont(14);
  155. textField.textColor = [UIColor whiteColor];
  156. textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,12,49)];
  157. textField.leftViewMode = UITextFieldViewModeAlways;
  158. NSString *holderText = @"输入房间名称";
  159. NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:holderText];
  160. [placeholder addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x6C6B70) range:NSMakeRange(0, holderText.length)];
  161. [placeholder addAttribute:NSFontAttributeName value:LCFont(14) range:NSMakeRange(0, holderText.length)];
  162. textField.attributedPlaceholder = placeholder;
  163. self.youpaiptextField = textField;
  164. //添加监听
  165. [self.youpaiptextField addTarget:self action:@selector(textFieldTextDidChange:) forControlEvents:UIControlEventEditingChanged];
  166. //字数提示
  167. UILabel *youpaipcountLabel = [UILabel new];
  168. self.youpaipcountLabel = youpaipcountLabel;
  169. [roomBgView addSubview:youpaipcountLabel];
  170. [youpaipcountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.right.mas_equalTo(-12);
  172. make.centerY.mas_equalTo(0);
  173. }];
  174. youpaipcountLabel.textColor = HexColorFromRGB(0x6C6B70);
  175. youpaipcountLabel.font = [UIFont systemFontOfSize:14];
  176. //房间公告
  177. UILabel *noticLabel = [UILabel new];
  178. [scrollView addSubview:noticLabel];
  179. [noticLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  180. make.left.mas_equalTo(14);
  181. make.top.mas_equalTo(roomBgView.mas_bottom).offset(24);
  182. }];
  183. noticLabel.text = @"房间公告";
  184. noticLabel.textColor = HexColorFromRGB(0x9F9DA5);
  185. noticLabel.font = [UIFont systemFontOfSize:12];
  186. //输入框bg
  187. UIView *textViewBgView = [[UIView alloc]init];
  188. [scrollView addSubview:textViewBgView];
  189. [textViewBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.left.mas_equalTo(14);
  191. make.width.mas_equalTo(KScreenWidth-28);
  192. make.top.mas_equalTo(noticLabel.mas_bottom).offset(10);
  193. make.height.mas_equalTo(220);
  194. }];
  195. textViewBgView.backgroundColor = HexColorFromRGB(0x2A2935);
  196. textViewBgView.layer.cornerRadius = 5;
  197. textViewBgView.layer.masksToBounds = YES;
  198. //
  199. YOUPAILZTextView *textView = [[YOUPAILZTextView alloc] initWithMaxCount:200.0f];
  200. textView.youpaiptextViewPadding = UIEdgeInsetsMake(15.0f, 12.0f, 16.0f, 12.0f);
  201. textView.youpaiptextLengthDefaultColor = HexColorFromRGB(0x6C6B70);
  202. textView.youpaiptextLengthHigtColor = ZYPinkColor;
  203. textView.youpaiptextLengthFont = LCFont(14.0f);
  204. textView.youpaiptextLengthRight = 12.0f;
  205. textView.youpaiptextLengthBottom = 18.0f;
  206. textView.youpaiptextView.placeholderFont = LCFont(14.0f);
  207. textView.youpaiptextView.placeholderTextColor = HexColorFromRGB(0x908E96);
  208. textView.youpaiptextView.placeholderText = @"请输入房间公告";
  209. textView.youpaiptextView.font = LCFont(14.0f);
  210. textView.backgroundColor = HexColorFromRGB(0x4F4B5B);
  211. textView.layer.cornerRadius = 5.0f;
  212. textView.clipsToBounds = YES;
  213. textView.tintColor = ZYPinkColor;
  214. [textViewBgView addSubview:textView];
  215. textView.youpaiptextView.textColor = HexColorFromRGB(0xffffff);
  216. self.youpaiptextView = textView;
  217. textView.backgroundColor = [UIColor clearColor];
  218. [textView mas_makeConstraints:^(MASConstraintMaker *make) {
  219. make.edges.mas_equalTo(0);
  220. }];
  221. //保存资料
  222. UIButton *youpaipsaveBtn = [UIButton new];
  223. self.youpaipsaveBtn = youpaipsaveBtn;
  224. [scrollView addSubview:youpaipsaveBtn];
  225. [youpaipsaveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  226. make.centerX.mas_equalTo(0);
  227. make.top.mas_equalTo(textViewBgView.mas_bottom).offset(40);
  228. make.size.mas_equalTo(CGSizeMake(294, 49));
  229. }];
  230. [youpaipsaveBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(294, 49) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:1] forState:UIControlStateNormal];
  231. [youpaipsaveBtn setTitle:@"保存资料" forState:UIControlStateNormal];
  232. [youpaipsaveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  233. youpaipsaveBtn.titleLabel.font = LCBoldFont(16);
  234. [youpaipsaveBtn addTarget:self action:@selector(youpaifsaveBtnClick) forControlEvents:UIControlEventTouchUpInside];
  235. youpaipsaveBtn.layer.cornerRadius = 49/2;
  236. youpaipsaveBtn.layer.masksToBounds = YES;
  237. if (scrollView.contentSize.height>KScreenHeight) {
  238. scrollView.contentSize = CGSizeMake(KScreenWidth, KScreenHeight + 1);
  239. }else{
  240. scrollView.contentSize = CGSizeMake(KScreenWidth, KScreenHeight);
  241. }
  242. }
  243. //监听改变方法
  244. - (void)textFieldTextDidChange:(UITextField *)textChange{
  245. NSString * temp = textChange.text;
  246. if (temp.length >= 15) {
  247. textChange.text = [textChange.text substringToIndex:15];
  248. }else{
  249. }
  250. self.youpaipcountLabel.text = [NSString stringWithFormat:@"%@/%@",@(textChange.text.length),@(15)];
  251. }
  252. -(void)youpaifupdateStartBtnStatu{
  253. if (![self.youpaiptextField.text isEqualToString:@""] ||
  254. ![self.youpaiptextView.youpaiptextView.text isEqualToString:@""]||
  255. !self.youpaipimageUrl) {
  256. [self.youpaipsaveBtn setBackgroundImage:[LCTools ColorImage:self.youpaipsaveBtn.frame.size FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  257. self.youpaipsaveBtn.userInteractionEnabled = YES;;
  258. }else{
  259. self.youpaipsaveBtn.backgroundColor = HexColorFromRGB(0x2A2935);
  260. [self.youpaipsaveBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
  261. self.youpaipsaveBtn.userInteractionEnabled = NO;
  262. }
  263. }
  264. - (void)youpaifopenAlbum{
  265. @weakify(self);
  266. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self];
  267. [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVc];
  268. imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮
  269. imagePickerVc.allowPickingVideo = NO;//是否允许选择视频
  270. imagePickerVc.allowPickingImage = YES;//是否允许选择照片
  271. imagePickerVc.allowPickingOriginalPhoto = NO;//是否选择原图
  272. imagePickerVc.showSelectedIndex = YES; //显示图片序号
  273. imagePickerVc.allowCrop = NO;//是否允许裁剪
  274. // // 裁剪框的尺寸
  275. // imagePickerVc.cropRect = CGRectMake(0, KScreenHeight/2-(KScreenWidth/3.0*4)/2, KScreenWidth,KScreenWidth/3.0*4);
  276. // 4. 照片排列按修改时间升序
  277. imagePickerVc.sortAscendingByModificationDate = YES;//按时间倒序排列图片
  278. // You can get the photos by block, the same as by delegate.
  279. // 你可以通过block或者代理,来得到用户选择的照片.
  280. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  281. [ZCHUDHelper showWithStatus:@"上传中..."];
  282. @strongify(self);
  283. // 1通过,0待审核,2,未通过
  284. [LCCommonHttp uploadWithImages:photos Type:@"cover" successBlock:^(NSArray<NSString *> *ossImagePaths) {
  285. [ZCHUDHelper dismiss];
  286. self.youpaipimageUrl = ossImagePaths.firstObject;
  287. self.youpaipavtarImageView.image = photos[0];
  288. [self youpaifupdateStartBtnStatu];
  289. }];
  290. }];
  291. [self presentViewController:imagePickerVc animated:YES completion:nil];
  292. }
  293. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
  294. NSLog(@"%@",photos[0]);
  295. }
  296. -(void)youpaifloadData{
  297. @weakify(self);
  298. [LCHttpHelper requestWithURLString:ChatRoom_getDataBefore parameters:@{@"room_id":@(self.youpaiproom_id)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  299. @strongify(self);
  300. NSDictionary* dict = (NSDictionary*)responseObject;
  301. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  302. if (code == 0) {//成功
  303. NSString *youpaipcover_img = dict[@"data"][@"cover_img"];
  304. NSString *title = dict[@"data"][@"title"];
  305. NSString *notice = dict[@"data"][@"notice"];
  306. [self.youpaipavtarImageView sd_setImageWithURL:[LCTools getImageUrlWithAddress:youpaipcover_img] placeholderImage:[UIImage imageNamed:@"vqu_images_finish_msg_n"]];
  307. self.youpaipimageUrl = youpaipcover_img;
  308. self.youpaiptextField.text = title;
  309. self.youpaipcountLabel.text = [NSString stringWithFormat:@"%lu/15",(unsigned long)title.length];
  310. self.youpaiptextView.youpaiptextView.text = notice;
  311. }
  312. } failure:^(NSError *error) {
  313. }];
  314. }
  315. - (void)dealloc
  316. {
  317. [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextViewTextDidChangeNotification object:self.youpaiptextField];
  318. }
  319. @end