ChangeTopicVC.m 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. //
  2. // ChangeTopicVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/25.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "ChangeTopicVC.h"
  9. #import "SmartBar.h"
  10. #import "NewTopicModel.h"
  11. #import "NewTopicCell.h"
  12. #import "NewTopicTextView.h"
  13. #import "LYLPhotoTailoringTool.h"
  14. #import "FWZFileGetTool.h"
  15. #import "FWZGetNoteBookTool.h"
  16. #define BARHEIGHT 42.5f
  17. #define TextViewTag 1000
  18. @interface ChangeTopicVC ()<SmartBarDelegate,UITextViewDelegate,UITableViewDelegate,UITableViewDataSource>
  19. @property (weak, nonatomic) IBOutlet UIView *NavBarV;
  20. @property (weak, nonatomic) IBOutlet UIButton *DoneBtn;
  21. @property (strong, nonatomic) UITableView *tableView;
  22. @property (strong, nonatomic) SmartBar *SmartBar;
  23. @property (strong, nonatomic) NSMutableArray *dataArray;
  24. @property (strong, nonatomic) NewTopicTextView *defualtView;
  25. @end
  26. @implementation ChangeTopicVC
  27. + (ChangeTopicVC *)initChangeTopicVC{
  28. ChangeTopicVC *controller = [StoryboardManager.shared.myTDTopicExtent instantiateViewControllerWithIdentifier:@"ChangeTopicVC"];
  29. return controller;
  30. }
  31. - (void)viewWillAppear:(BOOL)animated
  32. {
  33. [super viewWillAppear:animated];
  34. [[IQKeyboardManager sharedManager] setEnable:YES];
  35. }
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. self.fd_prefersNavigationBarHidden = YES;
  39. [self.view addSubview:self.tableView];
  40. self.SmartBar.delegate = self;
  41. [self.view addSubview:self.SmartBar];
  42. [self.SmartBar mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.left.right.mas_equalTo(self.view);
  44. make.height.mas_offset(BARHEIGHT);
  45. if (@available(iOS 11.0, *)) {
  46. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(BARHEIGHT);
  47. } else {
  48. make.bottom.equalTo(self.view.mas_bottom).offset(BARHEIGHT);
  49. }
  50. }];
  51. self.tableView.delegate = self;
  52. self.tableView.dataSource = self;
  53. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.right.mas_equalTo(self.view);
  55. make.top.mas_equalTo(self.NavBarV.mas_bottom);
  56. make.bottom.mas_equalTo(self.SmartBar.mas_top);
  57. }];
  58. WS(weakSelf);
  59. [self.DoneBtn setAction:^{
  60. [weakSelf editTopicPut];
  61. }];
  62. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  63. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  64. [self editData:self.dataDict];
  65. }
  66. - (void)editData:(NSDictionary *)dict
  67. {
  68. [self.dataArray removeAllObjects];
  69. NewTopicModel * titleModel = [[NewTopicModel alloc] init];
  70. titleModel.title = @"编辑标题";
  71. titleModel.content = [dict objectForKey:@"Title"];
  72. titleModel.type = CollectDataType_Text;
  73. [self.dataArray addObject:titleModel];
  74. if ([[dict objectForKey:@"Data"] isKindOfClass:[NSArray class]]) {
  75. NSArray * array = [dict objectForKey:@"Data"];
  76. for (NSInteger i = 0; i < array.count; i ++) {
  77. NSDictionary * dataDic = array[i];
  78. NewTopicModel * model = [[NewTopicModel alloc] initWithDict:dataDic];
  79. switch (model.type) {
  80. case CollectDataType_Text:
  81. {
  82. if (i == 0) {
  83. [self.dataArray addObject:model];
  84. }
  85. }
  86. break;
  87. case CollectDataType_IMG:
  88. {
  89. NSDictionary * pdDict = array[i + 1];
  90. if ([[pdDict objectForKey:@"Type"] integerValue] == CollectDataType_Text) {
  91. model.content = [pdDict objectForKey:@"Text"];
  92. }else{
  93. model.content = @"";
  94. }
  95. [self.dataArray addObject:model];
  96. }
  97. break;
  98. default:
  99. {
  100. if (array.count == i + 1) {
  101. break;
  102. }
  103. NSDictionary * pdDict = array[i + 1];
  104. if ([[pdDict objectForKey:@"Type"] integerValue] == CollectDataType_Text) {
  105. model.content = [pdDict objectForKey:@"Text"];
  106. }else{
  107. model.content = @"";
  108. }
  109. [self.dataArray addObject:model];
  110. }
  111. break;
  112. }
  113. }
  114. }
  115. [self.tableView reloadData];
  116. }
  117. #pragma -mark UItableViewDelegate
  118. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  119. {
  120. return self.dataArray.count;
  121. }
  122. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  123. {
  124. WS(weakSelf);
  125. NewTopicModel *model = [self.dataArray objectAtIndex:indexPath.row];
  126. if (indexPath.row == 0) {
  127. NewTopicCell *cell = [NewTopicCell configCell0:tableView indexPath:indexPath];
  128. if (!self.defualtView) {
  129. self.defualtView = cell.textView;
  130. }
  131. cell.textView.placeholder = model.title;
  132. cell.textView.text = model.content;
  133. cell.bgLabel.text = cell.textView.text;
  134. cell.textView.tag = TextViewTag + indexPath.row;
  135. cell.textView.delegate = self;
  136. return cell;
  137. }
  138. switch (model.type) {
  139. case CollectDataType_Text:
  140. {
  141. NewTopicCell *cell = [NewTopicCell configCell1:tableView indexPath:indexPath];
  142. cell.textView.placeholder = model.title;
  143. cell.textView.text = model.content;
  144. cell.bgLabel.text = cell.textView.text;
  145. cell.textView.tag = TextViewTag + indexPath.row;
  146. cell.textView.delegate = self;
  147. return cell;
  148. }
  149. break;
  150. case CollectDataType_File:
  151. {
  152. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  153. cell.textView.placeholder = @"";
  154. cell.textView.text = model.content;
  155. cell.cell2TitleL.text = model.FileName;
  156. cell.cell2SubTitleL.text = model.fileSize;
  157. cell.bgLabel.text = cell.textView.text;
  158. cell.textView.tag = TextViewTag + indexPath.row;
  159. cell.textView.delegate = self;
  160. NSString * imageName = [ZYCTool getFileNameImage:model.File];
  161. if (imageName.length > 0) {
  162. cell.cell2ImagV.image = IMG(imageName);
  163. }else{
  164. [cell.cell2ImagV sd_setImageWithURL:[NSURL URLWithString:model.File] placeholderImage:IMG(@"icon_weizhiwenjian")];
  165. }
  166. [cell.cell2CloseBtn setAction:^{
  167. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  168. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  169. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  170. [weakSelf.tableView reloadData];
  171. }];
  172. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  173. }];
  174. [alert addAction:sureAction];
  175. [alert addAction:cancelAction];
  176. [weakSelf presentViewController:alert animated:YES completion:^{
  177. }];
  178. }];
  179. return cell;
  180. }
  181. break;
  182. case CollectDataType_IMG:
  183. {
  184. NewTopicCell *cell = [NewTopicCell configCell3:tableView indexPath:indexPath];
  185. cell.textView.placeholder =@"";
  186. cell.textView.text = model.content;
  187. cell.bgLabel.text = cell.textView.text;
  188. cell.textView.tag = TextViewTag + indexPath.row;
  189. cell.textView.delegate = self;
  190. [cell.cell3ImagV sd_setImageWithURL:[NSURL URLWithString:model.imageUrl]];
  191. [cell.cell3CloseBtn setAction:^{
  192. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  193. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  194. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  195. [weakSelf.tableView reloadData];
  196. }];
  197. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  198. }];
  199. [alert addAction:sureAction];
  200. [alert addAction:cancelAction];
  201. [weakSelf presentViewController:alert animated:YES completion:^{
  202. }];
  203. }];
  204. return cell;
  205. }
  206. break;
  207. case CollectDataType_Collect:
  208. {
  209. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  210. cell.textView.text = model.content;
  211. cell.bgLabel.text = cell.textView.text;
  212. cell.textView.tag = TextViewTag + indexPath.row;
  213. cell.textView.delegate = self;
  214. cell.cell2TitleL.text = model.FileName;
  215. cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的收藏",model.AuthorName] KeyString:model.AuthorName];
  216. cell.cell2ImagV.image = IMG(@"收藏");
  217. [cell.cell2CloseBtn setAction:^{
  218. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  219. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  220. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  221. [weakSelf.tableView reloadData];
  222. }];
  223. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  224. }];
  225. [alert addAction:sureAction];
  226. [alert addAction:cancelAction];
  227. [weakSelf presentViewController:alert animated:YES completion:^{
  228. }];
  229. }];
  230. return cell;
  231. }
  232. break;
  233. case CollectDataType_Note:
  234. {
  235. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  236. cell.textView.placeholder = @"";
  237. cell.textView.text = model.content;
  238. cell.cell2TitleL.text = model.FileName;
  239. cell.bgLabel.text = cell.textView.text;
  240. cell.textView.tag = TextViewTag + indexPath.row;
  241. cell.textView.delegate = self;
  242. cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的笔记",model.AuthorName] KeyString:model.AuthorName];
  243. cell.cell2ImagV.image = IMG(@"noteBook_icon");
  244. [cell.cell2CloseBtn setAction:^{
  245. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  246. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  247. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  248. [weakSelf.tableView reloadData];
  249. }];
  250. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  251. }];
  252. [alert addAction:sureAction];
  253. [alert addAction:cancelAction];
  254. [weakSelf presentViewController:alert animated:YES completion:^{
  255. }];
  256. }];
  257. return cell;
  258. }
  259. break;
  260. case CollectDataType_NoteFile:
  261. {
  262. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  263. cell.textView.placeholder = @"";
  264. cell.textView.text = model.content;
  265. cell.cell2TitleL.text = model.FileName;
  266. cell.bgLabel.text = cell.textView.text;
  267. cell.textView.tag = TextViewTag + indexPath.row;
  268. cell.textView.delegate = self;
  269. cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的笔记文件夹",model.AuthorName] KeyString:model.AuthorName];
  270. cell.cell2ImagV.image = IMG(@"find_1");
  271. [cell.cell2CloseBtn setAction:^{
  272. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  273. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  274. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  275. [weakSelf.tableView reloadData];
  276. }];
  277. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  278. }];
  279. [alert addAction:sureAction];
  280. [alert addAction:cancelAction];
  281. [weakSelf presentViewController:alert animated:YES completion:^{
  282. }];
  283. }];
  284. return cell;
  285. }break;
  286. case CollectDataType_CollectFile:
  287. {
  288. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  289. cell.textView.placeholder = @"";
  290. cell.textView.text = model.content;
  291. cell.cell2TitleL.text = model.FileName;
  292. cell.bgLabel.text = cell.textView.text;
  293. cell.textView.tag = TextViewTag + indexPath.row;
  294. cell.textView.delegate = self;
  295. cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的收藏文件夹",model.AuthorName] KeyString:model.AuthorName];
  296. cell.cell2ImagV.image = IMG(@"find_1");
  297. [cell.cell2CloseBtn setAction:^{
  298. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  299. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  300. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  301. [weakSelf.tableView reloadData];
  302. }];
  303. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  304. }];
  305. [alert addAction:sureAction];
  306. [alert addAction:cancelAction];
  307. [weakSelf presentViewController:alert animated:YES completion:^{
  308. }];
  309. }];
  310. return cell;
  311. }break;
  312. case CollectDataType_Group:
  313. {
  314. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  315. cell.textView.placeholder = @"";
  316. cell.textView.text = model.content;
  317. cell.cell2TitleL.text = model.FileName;
  318. cell.bgLabel.text = cell.textView.text;
  319. cell.textView.tag = TextViewTag + indexPath.row;
  320. cell.textView.delegate = self;
  321. cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@小组",model.AuthorName] KeyString:model.AuthorName];
  322. cell.cell2ImagV.image = IMG(@"笔记小组");
  323. [cell.cell2CloseBtn setAction:^{
  324. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  325. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  326. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  327. [weakSelf.tableView reloadData];
  328. }];
  329. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  330. }];
  331. [alert addAction:sureAction];
  332. [alert addAction:cancelAction];
  333. [weakSelf presentViewController:alert animated:YES completion:^{
  334. }];
  335. }];
  336. return cell;
  337. }break;
  338. case CollectDataType_Topic:
  339. {
  340. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  341. cell.textView.placeholder = @"";
  342. cell.textView.text = model.content;
  343. cell.cell2TitleL.text = model.FileName;
  344. cell.bgLabel.text = cell.textView.text;
  345. cell.textView.tag = TextViewTag + indexPath.row;
  346. cell.textView.delegate = self;
  347. cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@",model.AuthorName] KeyString:model.AuthorName];
  348. cell.cell2ImagV.image = IMG(@"话题");
  349. [cell.cell2CloseBtn setAction:^{
  350. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  351. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  352. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  353. [weakSelf.tableView reloadData];
  354. }];
  355. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  356. }];
  357. [alert addAction:sureAction];
  358. [alert addAction:cancelAction];
  359. [weakSelf presentViewController:alert animated:YES completion:^{
  360. }];
  361. }];
  362. return cell;
  363. }break;
  364. case CollectDataType_InterMail:
  365. {
  366. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  367. cell.textView.placeholder = @"";
  368. cell.textView.text = model.content;
  369. cell.cell2TitleL.text = model.FileName;
  370. cell.bgLabel.text = cell.textView.text;
  371. cell.textView.tag = TextViewTag + indexPath.row;
  372. cell.textView.delegate = self;
  373. cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的站内信",model.AuthorName] KeyString:model.AuthorName];
  374. cell.cell2ImagV.image = IMG(@"站内信");
  375. [cell.cell2CloseBtn setAction:^{
  376. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  377. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  378. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  379. [weakSelf.tableView reloadData];
  380. }];
  381. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  382. }];
  383. [alert addAction:sureAction];
  384. [alert addAction:cancelAction];
  385. [weakSelf presentViewController:alert animated:YES completion:^{
  386. }];
  387. }];
  388. return cell;
  389. }break;
  390. case CollectDataType_Notice:
  391. {
  392. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  393. cell.textView.placeholder = @"";
  394. cell.textView.text = model.content;
  395. cell.cell2TitleL.text = model.FileName;
  396. cell.bgLabel.text = cell.textView.text;
  397. cell.textView.tag = TextViewTag + indexPath.row;
  398. cell.textView.delegate = self;
  399. cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的通知",model.AuthorName] KeyString:model.AuthorName];
  400. cell.cell2ImagV.image = IMG(@"通知图标");
  401. [cell.cell2CloseBtn setAction:^{
  402. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  403. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  404. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  405. [weakSelf.tableView reloadData];
  406. }];
  407. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  408. }];
  409. [alert addAction:sureAction];
  410. [alert addAction:cancelAction];
  411. [weakSelf presentViewController:alert animated:YES completion:^{
  412. }];
  413. }];
  414. return cell;
  415. }break;
  416. case CollectDataType_Meeting:
  417. {
  418. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  419. cell.textView.placeholder = @"";
  420. cell.textView.text = model.content;
  421. cell.cell2TitleL.text = model.FileName;
  422. cell.bgLabel.text = cell.textView.text;
  423. cell.textView.tag = TextViewTag + indexPath.row;
  424. cell.textView.delegate = self;
  425. cell.cell2SubTitleL.hidden = YES;
  426. cell.cell2ImagV.image = IMG(@"会议");
  427. [cell.cell2CloseBtn setAction:^{
  428. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  429. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  430. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  431. [weakSelf.tableView reloadData];
  432. }];
  433. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  434. }];
  435. [alert addAction:sureAction];
  436. [alert addAction:cancelAction];
  437. [weakSelf presentViewController:alert animated:YES completion:^{
  438. }];
  439. }];
  440. return cell;
  441. }break;
  442. case CollectDataType_Article:
  443. {
  444. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  445. cell.textView.placeholder = @"";
  446. cell.textView.text = model.content;
  447. cell.cell2TitleL.text = model.FileName;
  448. cell.bgLabel.text = cell.textView.text;
  449. cell.textView.tag = TextViewTag + indexPath.row;
  450. cell.textView.delegate = self;
  451. cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的文章",model.AuthorName] KeyString:model.AuthorName];
  452. cell.cell2ImagV.image = IMG(@"文章");
  453. [cell.cell2CloseBtn setAction:^{
  454. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  455. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  456. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  457. [weakSelf.tableView reloadData];
  458. }];
  459. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  460. }];
  461. [alert addAction:sureAction];
  462. [alert addAction:cancelAction];
  463. [weakSelf presentViewController:alert animated:YES completion:^{
  464. }];
  465. }];
  466. return cell;
  467. }break;
  468. case CollectDataType_Approval:
  469. {
  470. NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath];
  471. cell.textView.placeholder = @"";
  472. cell.textView.text = model.content;
  473. cell.cell2TitleL.text = model.FileName;
  474. cell.bgLabel.text = cell.textView.text;
  475. cell.textView.tag = TextViewTag + indexPath.row;
  476. cell.textView.delegate = self;
  477. cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的审批",model.AuthorName] KeyString:model.AuthorName];
  478. cell.cell2ImagV.image = IMG(@"审批");
  479. [cell.cell2CloseBtn setAction:^{
  480. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  481. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  482. [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
  483. [weakSelf.tableView reloadData];
  484. }];
  485. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  486. }];
  487. [alert addAction:sureAction];
  488. [alert addAction:cancelAction];
  489. [weakSelf presentViewController:alert animated:YES completion:^{
  490. }];
  491. }];
  492. return cell;
  493. }break;
  494. default:
  495. {
  496. NewTopicCell *cell = [NewTopicCell configCell0:tableView indexPath:indexPath];
  497. return cell;
  498. }
  499. break;
  500. }
  501. }
  502. #pragma -mark loadView
  503. - (UITableView *)tableView{
  504. if (!_tableView) {
  505. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  506. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  507. }
  508. return _tableView;
  509. }
  510. - (SmartBar *)SmartBar
  511. {
  512. if (!_SmartBar) {
  513. _SmartBar = [[SmartBar alloc] init];
  514. }
  515. return _SmartBar;
  516. }
  517. - (NSMutableArray *)dataArray
  518. {
  519. if (!_dataArray) {
  520. _dataArray = [NSMutableArray array];
  521. }
  522. return _dataArray;
  523. }
  524. #pragma -mark UItextViewDelegate
  525. - (void)textViewDidBeginEditing:(UITextView *)textView
  526. {
  527. self.defualtView = (NewTopicTextView *)textView;
  528. }
  529. - (void)textViewDidChange:(UITextView *)textView
  530. {
  531. self.defualtView = (NewTopicTextView *)textView;
  532. NSInteger index = textView.tag - TextViewTag;
  533. NewTopicModel * model = [self.dataArray objectAtIndex:index];
  534. model.content = textView.text;
  535. CGRect bounds = textView.bounds;
  536. CGSize maxSize = CGSizeMake(bounds.size.width, CGFLOAT_MAX);
  537. CGSize newSize = [textView sizeThatFits:maxSize];
  538. if (model.height != newSize.height) {
  539. [self.tableView beginUpdates];
  540. [self.tableView endUpdates];
  541. model.height = newSize.height;
  542. }
  543. }
  544. #pragma mark - SmartBarDelegate
  545. - (void)didSelectBarWithType:(SmartBarType)type
  546. {
  547. WS(weakSelf);
  548. switch (type) {
  549. case SmartBarPhoto:
  550. {
  551. [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera1 crop:YES showImgBlock:^(NSString *imageUrlStr) {
  552. } choosImgBlock:^(UIImage *image) {
  553. [weakSelf didSelectImage:image];
  554. }];
  555. }
  556. break;
  557. case SmartBarCamera:
  558. {
  559. [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) {
  560. } choosImgBlock:^(UIImage *image) {
  561. [weakSelf didSelectImage:image];
  562. }];
  563. }
  564. break;
  565. case SmartBarNotes:
  566. {
  567. [[FWZGetNoteBookTool sharedTool] openNoteBookListChooseNoteBookBlock:^(NSMutableArray<MyNoteBookSubModel *> * _Nonnull noteArr) {
  568. NSLog(@"SmartBarNotes %@",noteArr);
  569. [weakSelf disSelectNoteBook:noteArr];
  570. }];
  571. }
  572. break;
  573. case SmartBarCollection:
  574. {
  575. [[FWZGetNoteBookTool sharedTool] openCollectListChooseCollectBlock:^(NSMutableArray<MyFavoriteSubModel *> * _Nonnull collectArr) {
  576. NSLog(@"SmartBarCollection %@",collectArr);
  577. [weakSelf disSelectCollect:collectArr];
  578. }];
  579. }
  580. break;
  581. case SmartBarFile:
  582. {
  583. WS(weakSelf);
  584. [[FWZFileGetTool sharedTool] openFileWithCrop:YES showImgBlock:^(NSString * _Nonnull fileUrlStr) {
  585. } choosFileBlock:^(NSData * _Nonnull fileData, NSString * _Nonnull fileName) {
  586. SHOWLOADING
  587. [[HttpManager sharedHttpManager] HeaderUploadFileUrl:Host(Modify_UserImages_Post) parameters:@{} fileData:fileData fileKey:@"file" fileName:fileName mimeType:@"multipart/form-data" success:^(id _Nonnull responseObject) {
  588. REMOVESHOW
  589. NSLog(@"上传成功的文件%@",responseObject);
  590. [weakSelf fileSizeWithData:fileData withDict:responseObject[0]];
  591. } failure:^(NSError * _Nonnull error) {
  592. REMOVESHOW
  593. }];
  594. }];
  595. }
  596. break;
  597. default:
  598. break;
  599. }
  600. }
  601. - (void)disSelectNoteBook:(NSMutableArray<MyNoteBookSubModel *>*_Nonnull )noteArr{
  602. for (MyNoteBookSubModel *dataModel in noteArr ) {
  603. if (dataModel.AttributeValue == 1) {
  604. NewTopicModel * model = [[NewTopicModel alloc] init];
  605. model.ID = dataModel.MiddleId;
  606. model.FileId =dataModel.MiddleId;
  607. model.imageUrl = dataModel.AvatarUrl;
  608. model.AuthorName = dataModel.Name;
  609. model.FileName = dataModel.Title;
  610. model.type = CollectDataType_Note;
  611. [self.dataArray addObject:model];
  612. WS(weakSelf);
  613. dispatch_async(dispatch_get_main_queue(), ^{
  614. [weakSelf.tableView reloadData];
  615. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  616. [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO];
  617. });
  618. });
  619. }else{
  620. NewTopicModel * model = [[NewTopicModel alloc] init];
  621. model.ID = dataModel.Id;
  622. model.FileId = dataModel.Id;
  623. model.imageUrl = dataModel.AvatarUrl;
  624. model.AuthorName = [AppUserModel sharedAppUserModel].Name;
  625. model.FileName = dataModel.FolderName;
  626. model.type = CollectDataType_NoteFile;
  627. [self.dataArray addObject:model];
  628. WS(weakSelf);
  629. dispatch_async(dispatch_get_main_queue(), ^{
  630. [weakSelf.tableView reloadData];
  631. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  632. [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO];
  633. });
  634. });
  635. }
  636. }
  637. }
  638. - (void)disSelectCollect:(NSMutableArray<MyFavoriteSubModel *> * _Nonnull) collectArr{
  639. for (MyFavoriteSubModel *dataModel in collectArr ) {
  640. if(dataModel.AttributeValue == 1)
  641. {
  642. NewTopicModel * model = [[NewTopicModel alloc] init];
  643. model.ID = dataModel.CollectionDataId;
  644. model.FileId = dataModel.CollectionDataId;
  645. model.imageUrl = dataModel.Data.AvatarUrl;
  646. model.AuthorName = dataModel.Data.Author;
  647. model.FileName = dataModel.Title;
  648. model.type = [ZYCTool returnDataType:dataModel.CollectionType];
  649. [self.dataArray addObject:model];
  650. WS(weakSelf);
  651. dispatch_async(dispatch_get_main_queue(), ^{
  652. [weakSelf.tableView reloadData];
  653. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  654. [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO];
  655. });
  656. });
  657. }else{
  658. NewTopicModel * model = [[NewTopicModel alloc] init];
  659. model.ID = dataModel.Id;
  660. model.FileId = dataModel.Id;
  661. model.imageUrl = dataModel.Data.AvatarUrl;
  662. model.AuthorName = [AppUserModel sharedAppUserModel].Name;
  663. model.FileName = dataModel.FolderName;
  664. model.type = CollectDataType_CollectFile;
  665. [self.dataArray addObject:model];
  666. WS(weakSelf);
  667. dispatch_async(dispatch_get_main_queue(), ^{
  668. [weakSelf.tableView reloadData];
  669. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  670. [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO];
  671. });
  672. });
  673. }
  674. }
  675. }
  676. - (void)fileSizeWithData:(NSData *)fileData withDict:(NSDictionary *)dict
  677. {
  678. unsigned long long size = [fileData length];
  679. NSString * fileZise;
  680. if (size >= pow(10, 9)) { // size >= 1GB
  681. fileZise = [NSString stringWithFormat:@"%.2fGB", size / pow(10, 9)];
  682. } else if (size >= pow(10, 6)) { // 1GB > size >= 1MB
  683. fileZise = [NSString stringWithFormat:@"%.2fMB", size / pow(10, 6)];
  684. } else if (size >= pow(10, 3)) { // 1MB > size >= 1KB
  685. fileZise = [NSString stringWithFormat:@"%.2fKB", size / pow(10, 3)];
  686. } else { // 1KB > size
  687. fileZise = [NSString stringWithFormat:@"%lluB", size];
  688. }
  689. [self didSelectFile:dict withSize:fileZise];
  690. }
  691. - (void)didSelectImage:(UIImage *)image
  692. {
  693. WS(weakSelf);
  694. NSString *urlString = [[NSString alloc] initWithFormat:@"%@%@",BaseUrl,Modify_UserImages_Post];
  695. [[HttpManager sharedHttpManager] HeaderUploadUrl:urlString parameters:@{} pictureArray:@[UIImageJPEGRepresentation(image,1.0f)] pictureKey:@"file" success:^(id _Nonnull responseObject) {
  696. NSLog(@"%@",responseObject);
  697. NSDictionary * dict = responseObject[0];
  698. NewTopicModel * model = [[NewTopicModel alloc] init];
  699. model.title = @"";
  700. model.content = @"";
  701. model.imageUrl = dict[@"AbsolutePath"];
  702. model.FileId = [dict[@"FileId"] integerValue];
  703. model.FileName = dict[@"FileName"];
  704. model.type = CollectDataType_IMG;
  705. [weakSelf.dataArray addObject:model];
  706. dispatch_async(dispatch_get_main_queue(), ^{
  707. [weakSelf.tableView reloadData];
  708. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  709. [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO];
  710. });
  711. });
  712. } failure:^(NSError * _Nonnull error) {
  713. }];
  714. }
  715. - (void)didSelectFile:(NSDictionary *)dict withSize:(NSString *)fileSize
  716. {
  717. NewTopicModel * model = [[NewTopicModel alloc] init];
  718. model.title = @"";
  719. model.content = @"";
  720. model.imageUrl = dict[@"AbsolutePath"];
  721. model.FileId = [dict[@"FileId"] integerValue];
  722. model.FileName = dict[@"FileName"];
  723. model.type = CollectDataType_File;
  724. model.fileSize = fileSize;
  725. [self.dataArray addObject:model];
  726. WS(weakSelf);
  727. dispatch_async(dispatch_get_main_queue(), ^{
  728. [weakSelf.tableView reloadData];
  729. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  730. [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO];
  731. });
  732. });
  733. }
  734. - (void)didSelectBarAddBtnIsShow:(BOOL)isShow
  735. {
  736. [self.view endEditing:YES];
  737. }
  738. - (void)didSelectBarKeyBtnIsShow:(BOOL)isShow
  739. {
  740. [self.defualtView resignFirstResponder];
  741. }
  742. #pragma mark - KeyBoard
  743. - (void)keyBoardWillShow:(NSNotification *)note
  744. {
  745. // 获取用户信息
  746. NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
  747. // 获取键盘高度
  748. CGRect keyBoardBounds = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  749. CGFloat keyBoardHeight = keyBoardBounds.size.height;
  750. // 获取键盘动画时间
  751. CGFloat animationTime = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
  752. // 定义好动作
  753. WS(weakSelf);
  754. void (^animation)(void) = ^void(void) {
  755. [weakSelf.SmartBar mas_updateConstraints:^(MASConstraintMaker *make) {
  756. if (@available(iOS 11.0, *)) {
  757. make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom).offset(-keyBoardHeight);
  758. } else {
  759. make.bottom.equalTo(weakSelf.view.mas_bottom).offset(-keyBoardHeight);
  760. }
  761. }];
  762. };
  763. if (animationTime > 0) {
  764. [UIView animateWithDuration:animationTime animations:animation completion:^(BOOL finished) {
  765. }];
  766. } else {
  767. animation();
  768. }
  769. }
  770. - (void)keyBoardWillHide:(NSNotification *)note
  771. {
  772. // 获取用户信息
  773. NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
  774. // 获取键盘动画时间
  775. CGFloat animationTime = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
  776. // 定义好动作
  777. WS(weakSelf);
  778. void (^animation)(void) = ^void(void) {
  779. [weakSelf.SmartBar mas_updateConstraints:^(MASConstraintMaker *make) {
  780. if (@available(iOS 11.0, *)) {
  781. make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom).offset(BARHEIGHT);
  782. } else {
  783. make.bottom.equalTo(weakSelf.view.mas_bottom).offset(BARHEIGHT);
  784. }
  785. }];
  786. };
  787. if (animationTime > 0) {
  788. [UIView animateWithDuration:animationTime animations:animation];
  789. } else {
  790. animation();
  791. }
  792. }
  793. #pragma mark - 修改话题
  794. - (void)editTopicPut
  795. {
  796. NSMutableArray * array = [NSMutableArray array];
  797. for (NSInteger i = 1; i < self.dataArray.count; i ++) {
  798. NewTopicModel * model = self.dataArray[i];
  799. switch (model.type) {
  800. case CollectDataType_Text:
  801. {
  802. if (model.content.length == 0) {
  803. break;
  804. }
  805. NSDictionary * dict = @{@"TextType":@"",
  806. @"File":@"",
  807. @"FileName":@"",
  808. @"Text":model.content,
  809. @"Title":@"",
  810. @"Type":@(CollectDataType_Text),
  811. @"Author":@"",
  812. @"Content":@"",
  813. @"Id":@(0),
  814. @"CreatedData":@""
  815. };
  816. [array addObject:dict];
  817. }
  818. break;
  819. case CollectDataType_IMG:
  820. {
  821. if (model.imageUrl.length == 0) {
  822. break;
  823. }
  824. NSDictionary * dict = @{@"TextType":@"",
  825. @"File":model.imageUrl,
  826. @"FileName":model.FileName,
  827. @"Text":@"",
  828. @"Title":@"",
  829. @"Type":@(CollectDataType_IMG),
  830. @"Author":@"",
  831. @"Content":@"",
  832. @"Id":@(model.FileId),
  833. @"CreatedData":@""
  834. };
  835. [array addObject:dict];
  836. if (model.content.length > 0) {
  837. NSDictionary * subDict = @{@"TextType":@"",
  838. @"File":@"",
  839. @"FileName":@"",
  840. @"Text":model.content,
  841. @"Title":@"",
  842. @"Type":@(CollectDataType_Text),
  843. @"Author":@"",
  844. @"Content":@"",
  845. @"Id":@(0),
  846. @"CreatedData":@""
  847. };
  848. [array addObject:subDict];
  849. }
  850. }
  851. break;
  852. case CollectDataType_File:
  853. {
  854. if (model.FileName.length == 0) {
  855. break;
  856. }
  857. NSDictionary * dict = @{@"TextType":@"",
  858. @"File":model.File,
  859. @"FileName":model.FileName,
  860. @"Text":@"",
  861. @"Title":@"",
  862. @"Type":@(CollectDataType_File),
  863. @"Author":@"",
  864. @"Content":@"",
  865. @"Id":@(model.FileId),
  866. @"CreatedData":@""
  867. };
  868. [array addObject:dict];
  869. if (model.content.length > 0) {
  870. NSDictionary * subDict = @{@"TextType":@"",
  871. @"File":@"",
  872. @"FileName":@"",
  873. @"Text":model.content,
  874. @"Title":@"",
  875. @"Type":@(CollectDataType_Text),
  876. @"Author":@"",
  877. @"Content":@"",
  878. @"Id":@(0),
  879. @"CreatedData":@""
  880. };
  881. [array addObject:subDict];
  882. }
  883. }
  884. break;
  885. case CollectDataType_Group:
  886. {
  887. if (model.FileName.length == 0) {
  888. break;
  889. }
  890. NSDictionary * dict = @{@"TextType":@"",
  891. @"File":model.imageUrl,
  892. @"FileName":model.FileName,
  893. @"Text":@"",
  894. @"Title":@"",
  895. @"Type":@(CollectDataType_Group),
  896. @"Author":@"",
  897. @"Content":@"",
  898. @"Id":@(model.FileId),
  899. @"CreatedData":@""
  900. };
  901. [array addObject:dict];
  902. if (model.content.length > 0) {
  903. NSDictionary * subDict = @{@"TextType":@"",
  904. @"File":@"",
  905. @"FileName":@"",
  906. @"Text":model.content,
  907. @"Title":@"",
  908. @"Type":@(CollectDataType_Text),
  909. @"Author":@"",
  910. @"Content":@"",
  911. @"Id":@(0),
  912. @"CreatedData":@""
  913. };
  914. [array addObject:subDict];
  915. }
  916. }
  917. break;
  918. case CollectDataType_Collect:
  919. {
  920. if (model.FileName.length == 0) {
  921. break;
  922. }
  923. NSDictionary * dict = @{@"TextType":@"",
  924. @"File":model.imageUrl,
  925. @"FileName":@"",
  926. @"Text":@"",
  927. @"Title":model.FileName,
  928. @"Type":@(CollectDataType_Collect),
  929. @"Author":model.AuthorName,
  930. @"Content":@"",
  931. @"Id":@(model.FileId),
  932. @"CreatedData":@""
  933. };
  934. [array addObject:dict];
  935. if (model.content.length > 0) {
  936. NSDictionary * subDict = @{@"TextType":@"",
  937. @"File":@"",
  938. @"FileName":@"",
  939. @"Text":model.content,
  940. @"Title":@"",
  941. @"Type":@(CollectDataType_Text),
  942. @"Author":@"",
  943. @"Content":@"",
  944. @"Id":@(0),
  945. @"CreatedData":@""
  946. };
  947. [array addObject:subDict];
  948. }
  949. }break;
  950. case CollectDataType_Note:
  951. {
  952. if (model.FileName.length == 0) {
  953. break;
  954. }
  955. NSDictionary * dict = @{@"TextType":@"",
  956. @"File":model.imageUrl,
  957. @"FileName":@"",
  958. @"Text":@"",
  959. @"Title":model.FileName,
  960. @"Type":@(CollectDataType_Note),
  961. @"Author":model.AuthorName,
  962. @"Content":@"",
  963. @"Id":@(model.FileId),
  964. @"CreatedData":@""
  965. };
  966. [array addObject:dict];
  967. if (model.content.length > 0) {
  968. NSDictionary * subDict = @{@"TextType":@"",
  969. @"File":@"",
  970. @"FileName":@"",
  971. @"Text":model.content,
  972. @"Title":@"",
  973. @"Type":@(CollectDataType_Text),
  974. @"Author":@"",
  975. @"Content":@"",
  976. @"Id":@(0),
  977. @"CreatedData":@""
  978. };
  979. [array addObject:subDict];
  980. }
  981. }break;
  982. case CollectDataType_CollectFile:
  983. {
  984. if (model.FileName.length == 0) {
  985. break;
  986. }
  987. NSDictionary * dict = @{@"TextType":@"",
  988. @"File":model.imageUrl,
  989. @"FileName":@"",
  990. @"Text":@"",
  991. @"Title":model.FileName,
  992. @"Type":@(CollectDataType_CollectFile),
  993. @"Author":model.AuthorName,
  994. @"Content":@"",
  995. @"Id":@(model.FileId),
  996. @"CreatedData":@""
  997. };
  998. [array addObject:dict];
  999. if (model.content.length > 0) {
  1000. NSDictionary * subDict = @{@"TextType":@"",
  1001. @"File":@"",
  1002. @"FileName":@"",
  1003. @"Text":model.content,
  1004. @"Title":@"",
  1005. @"Type":@(CollectDataType_Text),
  1006. @"Author":@"",
  1007. @"Content":@"",
  1008. @"Id":@(0),
  1009. @"CreatedData":@""
  1010. };
  1011. [array addObject:subDict];
  1012. }
  1013. }break;
  1014. case CollectDataType_NoteFile:
  1015. {
  1016. if (model.FileName.length == 0) {
  1017. break;
  1018. }
  1019. NSDictionary * dict = @{@"TextType":@"",
  1020. @"File":model.imageUrl,
  1021. @"FileName":@"",
  1022. @"Text":@"",
  1023. @"Title":model.FileName,
  1024. @"Type":@(CollectDataType_NoteFile),
  1025. @"Author":model.AuthorName,
  1026. @"Content":@"",
  1027. @"Id":@(model.FileId),
  1028. @"CreatedData":@""
  1029. };
  1030. [array addObject:dict];
  1031. if (model.content.length > 0) {
  1032. NSDictionary * subDict = @{@"TextType":@"",
  1033. @"File":@"",
  1034. @"FileName":@"",
  1035. @"Text":model.content,
  1036. @"Title":@"",
  1037. @"Type":@(CollectDataType_Text),
  1038. @"Author":@"",
  1039. @"Content":@"",
  1040. @"Id":@(0),
  1041. @"CreatedData":@""
  1042. };
  1043. [array addObject:subDict];
  1044. }
  1045. }break;
  1046. case CollectDataType_Notice:
  1047. {
  1048. if (model.FileName.length == 0) {
  1049. break;
  1050. }
  1051. NSDictionary * dict = @{@"TextType":@"",
  1052. @"File":model.imageUrl,
  1053. @"FileName":model.FileName,
  1054. @"Text":@"",
  1055. @"Title":model.FileName,
  1056. @"Type":@(CollectDataType_Notice),
  1057. @"Author":model.AuthorName,
  1058. @"Content":@"",
  1059. @"Id":@(model.FileId),
  1060. @"CreatedData":@""
  1061. };
  1062. [array addObject:dict];
  1063. if (model.content.length > 0) {
  1064. NSDictionary * subDict = @{@"TextType":@"",
  1065. @"File":@"",
  1066. @"FileName":@"",
  1067. @"Text":model.content,
  1068. @"Title":@"",
  1069. @"Type":@(CollectDataType_Text),
  1070. @"Author":@"",
  1071. @"Content":@"",
  1072. @"Id":@(0),
  1073. @"CreatedData":@""
  1074. };
  1075. [array addObject:subDict];
  1076. }
  1077. }break;
  1078. case CollectDataType_InterMail:
  1079. {
  1080. if (model.FileName.length == 0) {
  1081. break;
  1082. }
  1083. NSDictionary * dict = @{@"TextType":@"",
  1084. @"File":model.imageUrl,
  1085. @"FileName":@"",
  1086. @"Text":@"",
  1087. @"Title":model.FileName,
  1088. @"Type":@(CollectDataType_InterMail),
  1089. @"Author":model.AuthorName,
  1090. @"Content":@"",
  1091. @"Id":@(model.FileId),
  1092. @"CreatedData":@""
  1093. };
  1094. [array addObject:dict];
  1095. if (model.content.length > 0) {
  1096. NSDictionary * subDict = @{@"TextType":@"",
  1097. @"File":@"",
  1098. @"FileName":@"",
  1099. @"Text":model.content,
  1100. @"Title":@"",
  1101. @"Type":@(CollectDataType_Text),
  1102. @"Author":@"",
  1103. @"Content":@"",
  1104. @"Id":@(0),
  1105. @"CreatedData":@""
  1106. };
  1107. [array addObject:subDict];
  1108. }
  1109. }break;
  1110. case CollectDataType_Meeting:
  1111. {
  1112. if (model.FileName.length == 0) {
  1113. break;
  1114. }
  1115. NSDictionary * dict = @{@"TextType":@"",
  1116. @"File":model.imageUrl,
  1117. @"FileName":@"",
  1118. @"Text":@"",
  1119. @"Title":model.FileName,
  1120. @"Type":@(CollectDataType_Meeting),
  1121. @"Author":model.AuthorName,
  1122. @"Content":@"",
  1123. @"Id":@(model.FileId),
  1124. @"CreatedData":@""
  1125. };
  1126. [array addObject:dict];
  1127. if (model.content.length > 0) {
  1128. NSDictionary * subDict = @{@"TextType":@"",
  1129. @"File":@"",
  1130. @"FileName":@"",
  1131. @"Text":model.content,
  1132. @"Title":@"",
  1133. @"Type":@(CollectDataType_Text),
  1134. @"Author":@"",
  1135. @"Content":@"",
  1136. @"Id":@(0),
  1137. @"CreatedData":@""
  1138. };
  1139. [array addObject:subDict];
  1140. }
  1141. }break;
  1142. case CollectDataType_Approval:
  1143. {
  1144. if (model.FileName.length == 0) {
  1145. break;
  1146. }
  1147. NSDictionary * dict = @{@"TextType":@"",
  1148. @"File":model.imageUrl,
  1149. @"FileName":@"",
  1150. @"Text":@"",
  1151. @"Title":model.FileName,
  1152. @"Type":@(CollectDataType_Approval),
  1153. @"Author":model.AuthorName,
  1154. @"Content":@"",
  1155. @"Id":@(model.FileId),
  1156. @"CreatedData":@""
  1157. };
  1158. [array addObject:dict];
  1159. if (model.content.length > 0) {
  1160. NSDictionary * subDict = @{@"TextType":@"",
  1161. @"File":@"",
  1162. @"FileName":@"",
  1163. @"Text":model.content,
  1164. @"Title":@"",
  1165. @"Type":@(CollectDataType_Text),
  1166. @"Author":@"",
  1167. @"Content":@"",
  1168. @"Id":@(0),
  1169. @"CreatedData":@""
  1170. };
  1171. [array addObject:subDict];
  1172. }
  1173. }break;
  1174. case CollectDataType_Article:
  1175. {
  1176. if (model.FileName.length == 0) {
  1177. break;
  1178. }
  1179. NSDictionary * dict = @{@"TextType":@"",
  1180. @"File":model.imageUrl,
  1181. @"FileName":@"",
  1182. @"Text":@"",
  1183. @"Title":model.FileName,
  1184. @"Type":@(CollectDataType_Article),
  1185. @"Author":model.AuthorName,
  1186. @"Content":@"",
  1187. @"Id":@(model.FileId),
  1188. @"CreatedData":@""
  1189. };
  1190. [array addObject:dict];
  1191. if (model.content.length > 0) {
  1192. NSDictionary * subDict = @{@"TextType":@"",
  1193. @"File":@"",
  1194. @"FileName":@"",
  1195. @"Text":model.content,
  1196. @"Title":@"",
  1197. @"Type":@(CollectDataType_Text),
  1198. @"Author":@"",
  1199. @"Content":@"",
  1200. @"Id":@(0),
  1201. @"CreatedData":@""
  1202. };
  1203. [array addObject:subDict];
  1204. }
  1205. }break;
  1206. default:
  1207. break;
  1208. }
  1209. }
  1210. NSMutableDictionary * paraDict = [NSMutableDictionary dictionary];
  1211. NewTopicModel * fristModel = [self.dataArray firstObject];
  1212. [paraDict setObject:fristModel.content forKey:@"Title"];
  1213. [paraDict setObject:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"];
  1214. [paraDict setObject:@(self.topicId) forKey:@"Id"];
  1215. if (array.count == 0 && fristModel.content.length == 0) {
  1216. SHOWERROR(@"话题标题和内容不能都为空");
  1217. return;
  1218. }
  1219. [paraDict setObject:[self arrayToJSONString:array] forKey:@"Content"];
  1220. WS(weakSelf);
  1221. SHOWLOADING
  1222. [[HttpManager sharedHttpManager] PUTUrl:Host(API_APP_Topic_Update) parameters:paraDict responseStyle:DATA success:^(id _Nonnull responseObject) {
  1223. NSLog(@"%@",responseObject);
  1224. REMOVESHOW
  1225. SHOWSUCCESS(@"创建成功");
  1226. if (weakSelf.upDateBlock) {
  1227. weakSelf.upDateBlock();
  1228. }
  1229. [weakSelf.navigationController popViewControllerAnimated:YES];
  1230. } failure:^(NSError * _Nonnull error) {
  1231. REMOVESHOW
  1232. }];
  1233. }
  1234. - (NSString *)arrayToJSONString:(NSArray *)array
  1235. {
  1236. NSError *error = nil;
  1237. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:&error];
  1238. NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  1239. return jsonString;
  1240. }
  1241. - (void)viewWillDisappear:(BOOL)animated
  1242. {
  1243. [super viewWillDisappear:animated];
  1244. [[IQKeyboardManager sharedManager] setEnable:NO];
  1245. WS(weakSelf);
  1246. [self.view endEditing:YES];
  1247. [self.SmartBar downBar];
  1248. [self.SmartBar mas_updateConstraints:^(MASConstraintMaker *make) {
  1249. if (@available(iOS 11.0, *)) {
  1250. make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom).offset(BARHEIGHT);
  1251. } else {
  1252. make.bottom.equalTo(weakSelf.view.mas_bottom).offset(BARHEIGHT);
  1253. }
  1254. }];
  1255. }
  1256. - (NSString *)getFileNameImage:(NSString *)fileName
  1257. {
  1258. if ([fileName hasPrefix:@".doc"]) {
  1259. return @"icon_word";
  1260. }else if([fileName hasPrefix:@".xls"]){
  1261. return @"icon_excel";
  1262. }else if([fileName hasPrefix:@".ppt"]){
  1263. return @"icon_ppt";
  1264. }else if([fileName hasPrefix:@".pdf"]){
  1265. return @"icon_pdf";
  1266. }else if([fileName hasPrefix:@".zip"]){
  1267. return @"icon_yasuowenjian";
  1268. }else if([fileName hasPrefix:@".psd"]){
  1269. return @"icon_psd";
  1270. }else if([fileName hasPrefix:@".ai"]){
  1271. return @"icon_ai";
  1272. }else if([fileName hasPrefix:@".txt"]){
  1273. return @"icon_txt";
  1274. }else if([fileName hasPrefix:@".html"]){
  1275. return @"icon_html";
  1276. }else{
  1277. return @"icon_weizhiwenjian";
  1278. }
  1279. }
  1280. - (void)dealloc
  1281. {
  1282. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1283. }
  1284. @end