HomeDetailController.m 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. //
  2. // HomeDetailController.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/26.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "HomeDetailController.h"
  9. #import "DocumentModel.h"
  10. #import "DetailTitleView.h"
  11. #import "CommentSetView.h"
  12. #import "TextInputView.h"
  13. #import "MHComment.h"
  14. #import "ReplyDetailController.h"
  15. #import "ThirdSharedView.h"
  16. #import <WebKit/WebKit.h>
  17. #import "DetailContentView.h"
  18. #import "ClickOKView.h"
  19. #import "ClickOKViewController.h"
  20. #import "DrawerView.h"
  21. #import "FavoritesViewController.h"
  22. #import "MyTDGroupViewController.h"
  23. #import "MyTDTopicViewController.h"
  24. #import "TDNavigationBar.h"
  25. #import "SendInfoGroupVC.h"
  26. #import "NoticeUnreadVC.h"
  27. #import "ArticleTextCell.h"
  28. #import "ArticleImageCell.h"
  29. #import "ArticleBlocks.h"
  30. #import "UILabel+Extension.h"
  31. #import "MailListDetailVC.h"
  32. #import "MHTopicFrame.h"
  33. #import "MHTopicCell.h"
  34. #import "TabBarController.h"
  35. #import "FecordDetailsGoodsCell.h"
  36. #import "CreateNoteBookVC.h"
  37. #import "NoteBookShareVC.h"
  38. #import "MyTDGroupViewController.h"
  39. #import "MyTDTopicCreateVC.h"
  40. #import "MoveViewController.h"
  41. #import "HomeCommentView.h"
  42. #import "FLAnimatedImage.h"
  43. #import "MailListVC.h"
  44. static NSString *textID = @"ArticleTextCell";
  45. static NSString *imageID = @"ArticleImageCell";
  46. #define kTopHeigh (IS_IPHONEX?88:64)
  47. @interface HomeDetailController () <WKUIDelegate, WKNavigationDelegate, UITableViewDataSource, UITableViewDelegate,DetailTitleViewDelegate,TDNavigationBarDelegate,MHTopicCellDelegate,NoteBookShareVCDelegate> {
  48. }
  49. @property (nonatomic, strong) Item *currentModel;
  50. @property (nonatomic, strong) UIView *scrollView;
  51. @property (nonatomic, strong) DetailTitleView *titleView;
  52. @property (nonatomic, strong) WKWebView *webView;
  53. @property (nonatomic, strong) TDTableView *tableView;
  54. @property (nonatomic, strong) HomeCommentView *commentView;
  55. @property (nonatomic, strong) TextInputView *commentInputView;
  56. @property (nonatomic, strong) ClickOKView *zanView;
  57. @property (nonatomic, strong) TDNavigationBar *myNavigationBar;
  58. @property (nonatomic, strong) DrawerView *drawerView;
  59. @property (nonatomic, copy) NSMutableArray *dataArr;
  60. @property (nonatomic, strong) DetailContentView *textContentView;
  61. @property (nonatomic, assign) NSInteger loadingfalg;
  62. @property (nonatomic, assign) NSInteger zantotal;
  63. @property (nonatomic, strong) NSMutableArray *goodsSource;
  64. @property (nonatomic, copy) NSString *sort;
  65. @property (nonatomic, strong) UILabel *lastLabel;
  66. @property (strong, nonatomic) NoteBookShareVC * noteBookShareVC;
  67. @property (nonatomic, assign) NSInteger countComment;
  68. @property (nonatomic, assign) BOOL isScrComment;
  69. @property (nonatomic,assign) NSInteger commentId;
  70. @end
  71. @implementation HomeDetailController
  72. - (void)dealloc {
  73. [[NSNotificationCenter defaultCenter] removeObserver:self];
  74. }
  75. - (void)viewDidLoad {
  76. [super viewDidLoad];
  77. [self.view addSubview:self.myNavigationBar];
  78. self.fd_prefersNavigationBarHidden = YES;
  79. [self.view addSubview:self.tableView];
  80. self.view.backgroundColor = [UIColor whiteColor];
  81. self.title = @"正文";
  82. // _tableView.frame = CGRectMake(0, kNavigationHeight, kGXScreenWidth, SCREEN_HEIGHT - kiphoneXBootomHeight - 45 - kNavigationHeight);
  83. // 评论
  84. self.sort = @"desc"; // 默认正序
  85. [self.view addSubview:self.commentView];
  86. [self.commentView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.left.right.mas_equalTo(self.view);
  88. make.height.mas_offset(@58);
  89. if (@available(iOS 11.0, *)) {
  90. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  91. } else {
  92. make.bottom.equalTo(self.view.mas_bottom);
  93. }
  94. }];
  95. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.right.mas_equalTo(self.view);
  97. make.top.mas_equalTo(self.myNavigationBar.mas_bottom);
  98. make.bottom.mas_equalTo(self.commentView.mas_top);
  99. }];
  100. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(collectSuccess) name:COLLECTSUCCESS object:nil];
  101. WS(weakSelf);
  102. [self.commentView.shareButton setAction:^{
  103. [weakSelf ShareDetail];
  104. }];
  105. [self.commentView.zanButton setAction:^{
  106. [weakSelf sendZanToServer:1];
  107. }];
  108. [self.commentView.commentButton setAction:^{
  109. [weakSelf commentHander];
  110. }];
  111. [self.commentView.commentScrollBtn setAction:^{
  112. weakSelf.isScrComment = !weakSelf.isScrComment;
  113. [weakSelf scrollToCommentViewTop];
  114. }];
  115. _scrollView.frame = CGRectMake(0, 0, kGXScreenWidth, kGXScreenHeigh);
  116. [self.scrollView addSubview:self.titleView];
  117. _titleView.frame = CGRectMake(0, 0, kGXScreenWidth, 0);
  118. [_titleView loadTitleModel:self.currentModel];
  119. CGRect frame = self.scrollView.frame;
  120. frame.size.height = _zanView.height + _titleView.height ;
  121. self.scrollView.frame = frame;
  122. [self.tableView setTableHeaderView:self.scrollView];
  123. UIView *myfootView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kGXScreenWidth, 60)];
  124. UIView *MYlineView = [[UIView alloc] initWithFrame:CGRectMake(21,0, kGXScreenWidth-42,0.5)];
  125. MYlineView.backgroundColor = UIColorHex(E5E5E5);
  126. [myfootView addSubview:MYlineView];
  127. self.lastLabel = [[UILabel alloc]init];
  128. self.lastLabel.frame = CGRectMake(0, 0, 200, 30);
  129. self.lastLabel.center = myfootView.center;
  130. self.lastLabel.font = [UIFont systemFontOfSize:13.f];
  131. self.lastLabel.textAlignment = NSTextAlignmentCenter;
  132. self.lastLabel.textColor = UIColorHex(CCCCCC);
  133. self.lastLabel.text = @"已经到底啦~";
  134. [myfootView addSubview:self.lastLabel];
  135. // UIView *MYlineView2 = [[UIView alloc] initWithFrame:CGRectMake(21,59, kGXScreenWidth-42,0.5)];
  136. // MYlineView2.backgroundColor = UIColorHex(E5E5E5);
  137. // [myfootView addSubview:MYlineView2];
  138. // [self.tableView setTableFooterView:myfootView];
  139. self.navigationItem.leftBarButtonItems = @[[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"首页-书籍详情-返回"] style:0 target:self action:@selector(back)],[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_menu"] style:0 target:self action:@selector(secondBarButtonItems)]];
  140. self.loadingfalg = 1 ;
  141. [self loadDetails];
  142. SHOWLOADING
  143. [self getZanData];
  144. [self getConmmtenData];
  145. // 通知-监听键盘弹出事件
  146. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeKeyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil];
  147. // 通知-监听键盘回收事
  148. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeKeyboardWillHideNotification:) name:UIKeyboardWillHideNotification object:nil];
  149. //注册点赞
  150. [self.tableView registerNib:[UINib nibWithNibName:@"FecordDetailsGoodsCell" bundle:nil] forCellReuseIdentifier:@"FecordDetailsGoodsCell"];
  151. self.tableView.backgroundColor = [UIColor colorWithHexString:@"F7F7F7"];
  152. [self.view addSubview:self.noteBookShareVC.view];
  153. [self.view addSubview:self.commentInputView];
  154. }
  155. #pragma mark - UIKeyBoradNotification
  156. - (void)changeKeyboardWillShowNotification:(NSNotification*)notification
  157. {
  158. WS(weakSelf);
  159. NSDictionary *userInfo = [notification userInfo];
  160. // 键盘弹出后的frame的结构体对象
  161. NSValue *valueEndFrame = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  162. // 得到键盘弹出后的键盘视图所在y坐标
  163. CGFloat keyBoardEndY = valueEndFrame.CGRectValue.origin.y;
  164. // 键盘弹出的动画时间
  165. NSNumber *duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
  166. // 键盘弹出的动画曲线
  167. NSNumber *curve = [userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
  168. // 添加移动动画,使视图跟随键盘移动(动画时间和曲线都保持一致)
  169. [UIView animateWithDuration:[duration doubleValue] animations:^{
  170. [UIView setAnimationBeginsFromCurrentState:YES];
  171. [UIView setAnimationCurve:[curve intValue]];
  172. [UIView animateWithDuration:0.5 animations:^{
  173. [weakSelf.commentInputView startAnimationWithY:keyBoardEndY - 150.f];
  174. }];
  175. } completion:^(BOOL finished) {
  176. }];
  177. }
  178. - (void)changeKeyboardWillHideNotification:(NSNotification*)notification
  179. {
  180. WS(weakSelf);
  181. NSDictionary *userInfo = [notification userInfo];
  182. // 键盘弹出的动画时间
  183. NSNumber *duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
  184. // 键盘弹出的动画曲线
  185. NSNumber *curve = [userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
  186. [UIView animateWithDuration:[duration doubleValue]animations:^{
  187. [weakSelf.commentInputView startAnimationWithY:SCREEN_HEIGHT];
  188. [UIView setAnimationBeginsFromCurrentState:YES];
  189. [UIView setAnimationCurve:[curve intValue]];
  190. } completion:^(BOOL finished) {
  191. }];
  192. }
  193. - (void)setBottomViewData:(Item *)model
  194. {
  195. self.countComment = model.CommentCount;
  196. if (model.CommentCount == 0) {
  197. self.commentView.commentCountL.text = [NSString stringWithFormat:@"评 论"];
  198. }else{
  199. if (model.CommentCount > 10000) {
  200. self.commentView.commentCountL.text = [NSString stringWithFormat:@"%.1f万\n评 论",model.CommentCount / 10000.0];
  201. }else{
  202. self.commentView.commentCountL.text = [NSString stringWithFormat:@"%ld\n评 论",(long)model.CommentCount];
  203. }
  204. }
  205. self.commentView.zanCountL.text = [NSString stringWithFormat:@"%ld",(long)model.PraiseCount];
  206. self.commentView.collectL.text = [NSString stringWithFormat:@"%ld",(long)model.CollectCount];
  207. self.commentView.shareL.text = [NSString stringWithFormat:@"%ld",(long)model.RetransmissionCount];
  208. self.commentView.zanCountL.hidden = model.PraiseCount == 0 ? YES : NO;
  209. self.commentView.collectL.hidden = model.CollectCount == 0 ? YES : NO;
  210. self.commentView.shareL.hidden = model.RetransmissionCount == 0 ? YES : NO;
  211. self.commentView.zanImgV.image = model.IsPraise ? IMG(@"zan_yes"):IMG(@"zan_no");
  212. self.commentView.collectImgV.image = model.IsCollect ? IMG(@"icon_collect_off"):IMG(@"收藏五角星");
  213. self.commentView.shareImgV.image = IMG(@"icon_share");
  214. WS(weakSelf);
  215. [self.commentView.collectButton setAction:^{
  216. if (model.IsCollect) {
  217. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"真的取消收藏吗?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  218. UIAlertAction *actionYes = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  219. NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
  220. [dic setValue:@(self.currentModel.Id) forKey:@"CollectionDataId"];
  221. /// 1文章 2话题 3 收藏 4笔记 5通知 6站内信 7小组 8 会议详情 14工作流审批 300 文件 400 会议纪要
  222. [dic setValue:@(1) forKey:@"CollectionType"];
  223. [dic setValue:@(0) forKey:@"FolderId"];
  224. [dic setValue:@(0) forKey:@"SourceUserId"];
  225. [[HttpManager sharedHttpManager] PUTUrl:Host(API_CreateCollect) parameters:dic success:^(id _Nonnull responseObject) {
  226. [weakSelf refreshBottomData];
  227. } failure:^(NSError * _Nonnull error) {
  228. SHOWERROR([ZYCTool handerResultData:error]);
  229. }];
  230. }];
  231. UIAlertAction *actionNo = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  232. }];
  233. [alert addAction:actionYes];
  234. [alert addAction:actionNo];
  235. [weakSelf presentViewController:alert animated:YES completion:^{
  236. }];
  237. }else{
  238. NSLog(@"文章详情--收藏");
  239. MoveViewController *vc = [MoveViewController initMoveViewController];
  240. vc.CollectionDataId = weakSelf.currentModel.Id;
  241. vc.collectType = CollectHanderType_Collect;
  242. vc.ParentId = 0;
  243. vc.titleStr = @"我的收藏";
  244. vc.TypeId = CreateCollectionType;
  245. vc.FolderIds = @[].mutableCopy;
  246. vc.CollectionType = 1;
  247. [weakSelf.navigationController pushViewController:vc animated:YES];
  248. }
  249. }];
  250. self.commentView.zanCountL.textColor = model.IsPraise ? UIColorHex(#009AFF):UIColorHex(#999999);
  251. self.commentView.collectL.textColor = model.IsCollect ? UIColorHex(#009AFF):UIColorHex(#999999);
  252. self.commentView.shareL.textColor = UIColorHex(#009AFF);
  253. }
  254. - (void)collectSuccess
  255. {
  256. [self refreshBottomData];
  257. }
  258. - (void)loadDetails {
  259. WEAKSELF
  260. [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,[NSString stringWithFormat:@"/api/app/article/detail/%zi",self.currentModel.Id]] parameters:@{@"id":@(self.currentModel.Id)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  261. weakSelf.currentModel = [Item modelWithDictionary:responseObject];
  262. //设置收藏等数量以及状态
  263. dispatch_async(dispatch_get_main_queue(), ^{
  264. [weakSelf.tableView reloadData];
  265. [weakSelf setBottomViewData:weakSelf.currentModel];
  266. });
  267. weakSelf.loadingfalg +=1;
  268. if (weakSelf.loadingfalg == 3) {
  269. REMOVESHOW
  270. }
  271. } failure:^(NSError * _Nonnull error) {
  272. REMOVESHOW
  273. SHOWERROR([ZYCTool handerResultData:error]);
  274. }];
  275. }
  276. - (void)getZanData{
  277. SHOWLOADING
  278. WEAKSELF
  279. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,@"/api/app/analyze/list"] parameters:@{@"SourceId":@(self.currentModel.Id),@"Page":@1,@"PerPage":@10,@"TypeValue":@"0"} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  280. NSLog(@"%@点赞页数据",responseObject);
  281. REMOVESHOW
  282. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  283. NSDictionary *dic = responseObject;
  284. weakSelf.zantotal = [dic[@"Total"] integerValue];
  285. weakSelf.goodsSource = dic[@"Items"];
  286. weakSelf.loadingfalg +=1;
  287. if (weakSelf.loadingfalg == 3) {
  288. REMOVESHOW
  289. }
  290. dispatch_async(dispatch_get_main_queue(), ^{
  291. [weakSelf.tableView reloadData];
  292. });
  293. }
  294. } failure:^(NSError * _Nonnull error) {
  295. SHOWERROR([ZYCTool handerResultData:error]);
  296. }];
  297. }
  298. - (void)getConmmtenData{
  299. // 排序todo
  300. [self.dataArr removeAllObjects];
  301. WEAKSELF
  302. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Artticle_ConmmentList_Post] parameters:@{@"ArticleId":@(self.currentModel.Id),@"TypeValue":@"0",@"Page":@1,@"PerPage":@100000,@"Sort":self.sort} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  303. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  304. if ([responseObject[@"Items"] isKindOfClass:[NSArray class]]) {
  305. for (NSDictionary * dict in responseObject[@"Items"]) {
  306. MHTopic * topic = [MHTopic modelWithDictionary:dict];
  307. if ([[dict objectForKey:@"TopicCommentReplyResults"] isKindOfClass:[NSArray class]]) {
  308. NSMutableArray<MHComment *> * subArray = [NSMutableArray<MHComment *> array];
  309. for (NSDictionary * subDict in dict[@"TopicCommentReplyResults"]) {
  310. MHComment * commentModel = [MHComment modelWithDictionary:subDict];
  311. [subArray addObject:commentModel];
  312. }
  313. topic.CommentReplyResults = [NSMutableArray<MHComment *> arrayWithArray:subArray];
  314. }
  315. [weakSelf.dataArr addObject:[weakSelf _topicFrameWithTopic:topic]];
  316. }
  317. weakSelf.lastLabel.hidden = (weakSelf.dataArr.count < 1);
  318. }
  319. dispatch_async(dispatch_get_main_queue(), ^{
  320. [weakSelf.tableView reloadData];
  321. });
  322. weakSelf.loadingfalg +=1;
  323. if (weakSelf.loadingfalg == 3) {
  324. REMOVESHOW
  325. }
  326. }
  327. } failure:^(NSError * _Nonnull error) {
  328. SHOWERROR([ZYCTool handerResultData:error]);
  329. }];
  330. }
  331. #pragma mark - 导航事件处理
  332. -(void)back{
  333. if (self.navigationController.viewControllers.count > 1) {
  334. [self.navigationController popViewControllerAnimated:YES];
  335. }else{
  336. [self dismissViewControllerAnimated:YES completion:nil];
  337. }
  338. }
  339. - (void)secondBarButtonItems{
  340. [self.view endEditing:YES];
  341. [[UtilsTools getWindow] addSubview:self.drawerView];
  342. WS(weakSelf);
  343. self.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
  344. if (![weakSelf.tabBarController isKindOfClass:[TabBarController class]]) {
  345. [TabBarController sharedTabBarController].tabBar.hidden = NO;
  346. [weakSelf.tabBarController.navigationController popViewControllerAnimated:NO];
  347. }
  348. if ([weakSelf.navigationController.viewControllers count] > 1) {
  349. [weakSelf.navigationController popToRootViewControllerAnimated:NO];
  350. }
  351. switch (indexPath.section) {
  352. case 0:
  353. {
  354. [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
  355. }
  356. break;
  357. case 1:
  358. {
  359. switch (indexPath.row) {
  360. case 0:
  361. {
  362. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  363. }
  364. break;
  365. case 1:
  366. {
  367. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  368. }
  369. break;
  370. default:
  371. {
  372. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  373. }
  374. break;
  375. }
  376. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  377. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(indexPath.row)}];
  378. });
  379. }
  380. break;
  381. default:
  382. {
  383. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  384. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  385. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(4 + indexPath.row)}];
  386. });
  387. }
  388. break;
  389. }
  390. };
  391. self.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);// - kNavigationHeight
  392. }
  393. - (void)loadCurrentModel:(Item *)model {
  394. self.currentModel = model;
  395. }
  396. #pragma mark - UITableViewDataSource && UITableViewDelegate
  397. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  398. return 3;
  399. }
  400. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  401. if (section==0) {
  402. return self.currentModel.ArticleBlocks.count ;
  403. }else if (section == 1){
  404. return 1;
  405. }
  406. return self.dataArr.count;
  407. }
  408. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  409. if (indexPath.section==0) {
  410. ArticleBlocks *articleBlock = self.currentModel.ArticleBlocks[indexPath.row];
  411. if ([articleBlock.Type isEqualToString:@"image"]) {
  412. NSDictionary *file = articleBlock.Data.File;
  413. UIImage *image = [[YYImageCache sharedCache] getImageForKey:file[@"Url"]];
  414. CGFloat height = 0 ;
  415. if (image.size.width > 0.0) {
  416. height += image.size.height * SCREEN_WIDTH / image.size.width;
  417. return height;
  418. }else{
  419. return 180.f;
  420. }
  421. return UITableViewAutomaticDimension;
  422. }else{
  423. return [ArticleTextCell cellHeight:articleBlock.Data.Text];
  424. }
  425. return UITableViewAutomaticDimension;
  426. }
  427. else if (indexPath.section==1){
  428. if (self.goodsSource.count ==0 && self.dataArr.count == 0) {
  429. return 0.001f;
  430. }else{
  431. return 50;
  432. }
  433. }
  434. MHTopicFrame *topicFrame = self.dataArr[indexPath.row];
  435. if (topicFrame.tableViewFrame.size.height == 0) {
  436. return topicFrame.height+topicFrame.tableViewFrame.size.height;
  437. }else{
  438. return topicFrame.height+topicFrame.tableViewFrame.size.height+MHTopicVerticalSpace;
  439. }
  440. }
  441. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  442. {
  443. return .001f;
  444. }
  445. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  446. {
  447. return .001f;
  448. }
  449. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  450. WEAKSELF
  451. switch (indexPath.section) {
  452. case 0:
  453. {
  454. ArticleBlocks *articleBlock = self.currentModel.ArticleBlocks[indexPath.row];
  455. if ([articleBlock.Type isEqualToString:@"image"]) {
  456. ArticleImageCell *imageCell = [tableView dequeueReusableCellWithIdentifier:imageID];
  457. if (!imageCell) {
  458. [tableView registerNib:[UINib nibWithNibName:imageID bundle:nil] forCellReuseIdentifier:imageID];
  459. imageCell = [tableView dequeueReusableCellWithIdentifier:imageID];
  460. }
  461. NSDictionary *file = articleBlock.Data.File;
  462. WS(weakSelf);
  463. UILongPressGestureRecognizer * longges = [[UILongPressGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  464. UILongPressGestureRecognizer * press = (UILongPressGestureRecognizer *)sender;
  465. if (press.state == UIGestureRecognizerStateBegan) {
  466. dispatch_async(dispatch_get_main_queue(), ^{
  467. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  468. UIAlertAction *actionYes = [UIAlertAction actionWithTitle:@"保存图片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  469. UIImage * img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:file[@"Url"]]]];
  470. [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
  471. [PHAssetChangeRequest creationRequestForAssetFromImage:img];
  472. } completionHandler:^(BOOL success, NSError * _Nullable error) {
  473. dispatch_async(dispatch_get_main_queue(), ^{
  474. if (success) {
  475. SHOWSUCCESS(@"图片保存成功");
  476. }else{
  477. SHOWERROR(@"图片保存失败");
  478. }
  479. });
  480. }];
  481. }];
  482. UIAlertAction *actionNo = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  483. }];
  484. [alert addAction:actionYes];
  485. [alert addAction:actionNo];
  486. [weakSelf presentViewController:alert animated:YES completion:^{
  487. }];
  488. });
  489. }
  490. }];
  491. [imageCell.imgView addGestureRecognizer:longges];
  492. imageCell.imgView.userInteractionEnabled = YES;
  493. imageCell.selectionStyle = UITableViewCellSelectionStyleNone;
  494. if ([self isGifOrSwf:file[@"Url"]]) {
  495. FLAnimatedImage * image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:file[@"Url"]]]];
  496. FLAnimatedImageView * imageV = [[FLAnimatedImageView alloc] init];
  497. imageV.animatedImage = image;
  498. imageCell.imgView = imageV;
  499. }else{
  500. [imageCell.imgView setImageWithURL:[NSURL URLWithString:file[@"Url"]] placeholder:IMG(@"img_placeHolder")];
  501. }
  502. imageCell.imgTitleLab.text = articleBlock.Data.Caption;
  503. return imageCell;
  504. }else{
  505. ArticleTextCell *textCell = [tableView dequeueReusableCellWithIdentifier:textID];
  506. if (!textCell) {
  507. [tableView registerNib:[UINib nibWithNibName:textID bundle:nil] forCellReuseIdentifier:textID];
  508. textCell = [tableView dequeueReusableCellWithIdentifier:textID];
  509. }
  510. textCell.selectionStyle = UITableViewCellSelectionStyleNone;
  511. [textCell setContent:articleBlock.Data.Text];
  512. return textCell;
  513. }
  514. }
  515. break;
  516. case 1:{
  517. FecordDetailsGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FecordDetailsGoodsCell" forIndexPath:indexPath];
  518. WEAKSELF
  519. [cell.sortButton setAction:^{
  520. cell.sortButton.selected = !cell.sortButton.isSelected;
  521. self.sort = cell.sortButton.isSelected ? @"asc" : @"desc";
  522. // 排序按钮
  523. [weakSelf getConmmtenData];
  524. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  525. weakSelf.isScrComment = YES;
  526. [weakSelf scrollToCommentViewTop];
  527. });
  528. }];
  529. [cell setCellData:self.goodsSource];
  530. cell.sortButton.hidden = (self.dataArr.count < 1);
  531. cell.backgroundColor = [UIColor colorWithHexString:@"FAFAFA"];
  532. return cell;
  533. }
  534. default:
  535. {
  536. MHTopicCell *cell = [MHTopicCell cellWithTableView:tableView];
  537. MHTopicFrame *topicFrame = self.dataArr[indexPath.row];
  538. cell.topicFrame = topicFrame;
  539. cell.createTimeLabel.text = [NSString stringWithFormat:@"%@ %@",topicFrame.topic.FloorCount,topicFrame.topic.CreatedTime];
  540. [cell.thumbBtn setAction:^{
  541. [weakSelf didClickZanComment:topicFrame.topic withIndexPath:indexPath];
  542. }];
  543. cell.replyContentBlock = ^{
  544. [weakSelf replyCommentName:topicFrame.topic.Name andId:[NSString stringWithFormat:@"%ld",(long)topicFrame.topic.Id]];
  545. };
  546. __block MHTopicCell * bCell = cell;
  547. cell.longBlock = ^{
  548. weakSelf.commentId = topicFrame.topic.Id;
  549. [weakSelf longDeleteSelf:bCell];
  550. };
  551. // cell.longSubBlock = ^(NSInteger commentId,UILabel * label) {
  552. // weakSelf.commentId = commentId;
  553. // [weakSelf longDeleteSubCell:label];
  554. // };
  555. cell.delegate = self;
  556. return cell;
  557. }
  558. break;
  559. }
  560. }
  561. - (BOOL)isGifOrSwf:(NSString *)imageStr
  562. {
  563. NSString * name = [[imageStr pathExtension] lowercaseString];
  564. if ([name hasSuffix:@"gif"] || [name hasSuffix:@"swf"]) {
  565. return YES;
  566. }else{
  567. return NO;
  568. }
  569. }
  570. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  571. if (indexPath.section == 1) {
  572. ClickOKViewController *vc = [ClickOKViewController initClickOKViewController];
  573. vc.indexId = self.currentModel.Id;
  574. vc.zanToTal = self.zantotal;
  575. vc.type = ZanListPageType_Article;
  576. [self.navigationController pushViewController:vc animated:YES];
  577. }
  578. }
  579. - (MHTopicFrame *)_topicFrameWithTopic:(MHTopic *)topic
  580. {
  581. MHTopicFrame *topicFrame = [[MHTopicFrame alloc] init];
  582. // 传递微博模型数据,计算所有子控件的frame
  583. topicFrame.topic = topic;
  584. return topicFrame;
  585. }
  586. -(void)didClickZanComment:(MHTopic *)model withIndexPath:(NSIndexPath *)indexPath{
  587. NSLog(@"点击赞%@",model);
  588. [self sendZanToServerWithCommentId:model.Id withArticle:self.currentModel.Id model:model indexPath:indexPath];
  589. }
  590. #pragma mark - CommentSetViewDelegate
  591. - (void)commentNunberClick {
  592. //滑动到评论模块
  593. NSLog(@"滑动到评论顶部");
  594. if (self.dataArr.count > 0) {
  595. [self.tableView scrollToRow:0 inSection:2 atScrollPosition:UITableViewScrollPositionTop animated:YES];
  596. }
  597. }
  598. // 评论
  599. - (void)commentHander {
  600. [_commentInputView startEditing];
  601. WEAKSELF
  602. self.commentInputView.inputBlock = ^(NSString * _Nonnull content) {
  603. NSLog(@"%@",content);
  604. STRONGSELF
  605. [strongSelf sendCommentToServer:content];
  606. };
  607. }
  608. //
  609. //- (void)functionTouch:(TDButton *)button {
  610. // switch (button.tag) {
  611. // case SharedTag:
  612. // NSLog(@"文章详情--分享");
  613. // {
  614. // [self shareHander];
  615. // }
  616. // break;
  617. // case CollectTag: {
  618. // NSLog(@"文章详情--收藏");
  619. // MoveViewController *vc = [MoveViewController initMoveViewController];
  620. // vc.CollectionDataId = _currentModel.Id;
  621. // vc.collectType = CollectHanderType_Collect;
  622. // vc.ParentId = 0;
  623. // vc.titleStr = @"我的收藏";
  624. // vc.TypeId = CreateCollectionType;
  625. // vc.FolderIds = @[].mutableCopy;
  626. // vc.CollectionType = 1;
  627. // [self.navigationController pushViewController:vc animated:YES];
  628. // }break;
  629. // case ThumbTag:
  630. // NSLog(@"文章详情--点赞");
  631. // [self sendZanToServer:1];
  632. // break;
  633. // default:
  634. // break;
  635. // }
  636. //}
  637. #pragma mark - 赞 评论数据操作
  638. - (void)sendZanToServerWithCommentId:(NSInteger)CommentId withArticle:(NSInteger)ArticleId model:(MHTopic *)model indexPath:(NSIndexPath *)indexPath
  639. {
  640. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  641. [dic setValue:@(ArticleId) forKey:@"SourceId"];
  642. [dic setValue:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"];
  643. [dic setValue:@(2) forKey:@"AnalyzeType"];///详情点赞
  644. [dic setValue:@(CommentId) forKey:@"CommentId"];
  645. [dic setValue:@(0) forKey:@"TypeValue"];///文章
  646. WS(weakSelf);
  647. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Analyze_Set) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
  648. model.IsLaud = !model.IsLaud;
  649. if (model.IsLaud) {
  650. SHOWSUCCESS(@"点赞成功");
  651. }else{
  652. SHOWSUCCESS(@"取消点赞");
  653. }
  654. dispatch_async(dispatch_get_main_queue(), ^{
  655. [weakSelf.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  656. });
  657. } failure:^(NSError * _Nonnull error) {
  658. SHOWERROR([ZYCTool handerResultData:error]);
  659. }];
  660. }
  661. #pragma mark - 赞 文章数据操作
  662. - (void)sendZanToServer:(NSInteger)ArticleAnalyzeType{
  663. SHOWLOADING
  664. WS(weakSelf);
  665. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,@"/api/app/analyze/set"] parameters:@{@"SourceId":@(_currentModel.Id),@"AnalyzeType":@(ArticleAnalyzeType),@"TypeValue":@"0"} responseStyle:DATA success:^(id _Nonnull responseObject) {
  666. REMOVESHOW
  667. if (self->_currentModel.IsLaud == 1) {
  668. //SHOWSUCCESS(@"已取消点赞");
  669. self->_currentModel.IsLaud = 0;
  670. }else {
  671. self.currentModel.IsLaud = 1;
  672. //SHOWSUCCESS(@"点赞成功");
  673. }
  674. [weakSelf refreshLikeData];
  675. } failure:^(NSError * _Nonnull error) {
  676. REMOVESHOW
  677. SHOWERROR([ZYCTool handerResultData:error]);
  678. }];
  679. }
  680. - (void)refreshLikeData{
  681. SHOWLOADING
  682. WEAKSELF
  683. [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,[NSString stringWithFormat:@"/api/app/article/detail/%zi",self.currentModel.Id]] parameters:@{@"id":@(self.currentModel.Id)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  684. weakSelf.currentModel = [Item modelWithDictionary:responseObject];
  685. //设置收藏等数量以及状态
  686. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,@"/api/app/analyze/list"] parameters:@{@"SourceId":@(self.currentModel.Id),@"Page":@1,@"PerPage":@10,@"TypeValue":@"0"} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  687. NSLog(@"%@点赞页数据",responseObject);
  688. REMOVESHOW
  689. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  690. NSDictionary *dic = responseObject;
  691. weakSelf.zantotal = [dic[@"Total"] integerValue];
  692. weakSelf.goodsSource = dic[@"Items"];
  693. dispatch_async(dispatch_get_main_queue(), ^{
  694. [weakSelf.tableView reloadData];
  695. [weakSelf setBottomViewData:weakSelf.currentModel];
  696. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  697. weakSelf.isScrComment = YES;
  698. [weakSelf scrollToCommentViewTop];
  699. });
  700. });
  701. }
  702. } failure:^(NSError * _Nonnull error) {
  703. REMOVESHOW
  704. SHOWERROR([ZYCTool handerResultData:error]);
  705. }];
  706. } failure:^(NSError * _Nonnull error) {
  707. REMOVESHOW
  708. SHOWERROR([ZYCTool handerResultData:error]);
  709. }];
  710. }
  711. #pragma mark - 评论文章 数据操作
  712. - (void)sendCommentToServer:(NSString *)content{
  713. if (content.length < 1) {
  714. SHOWERROR(@"请输入评论");
  715. return;
  716. }
  717. WS(weakSelf);
  718. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Artticle_AddConmment_Post] parameters:@{@"ArticleId":@(self.currentModel.Id),@"TypeValue":@"0",@"Content":content} responseStyle:DATA success:^(id _Nonnull responseObject) {
  719. SHOWSUCCESS(@"评论成功");
  720. dispatch_async(dispatch_get_main_queue(), ^{
  721. [weakSelf.dataArr removeAllObjects];
  722. WEAKSELF
  723. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Artticle_ConmmentList_Post] parameters:@{@"ArticleId":@(self.currentModel.Id),@"TypeValue":@"0",@"Page":@1,@"PerPage":@100000,@"Sort":self.sort} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  724. if ([responseObject[@"Items"] isKindOfClass:[NSArray class]]) {
  725. for (NSDictionary * dict in responseObject[@"Items"]) {
  726. MHTopic * topic = [MHTopic modelWithDictionary:dict];
  727. if ([[dict objectForKey:@"TopicCommentReplyResults"] isKindOfClass:[NSArray class]]) {
  728. NSMutableArray<MHComment *> * subArray = [NSMutableArray<MHComment *> array];
  729. for (NSDictionary * subDict in dict[@"TopicCommentReplyResults"]) {
  730. MHComment * commentModel = [MHComment modelWithDictionary:subDict];
  731. [subArray addObject:commentModel];
  732. }
  733. topic.CommentReplyResults = [NSMutableArray<MHComment *> arrayWithArray:subArray];
  734. }
  735. [weakSelf.dataArr addObject:[weakSelf _topicFrameWithTopic:topic]];
  736. }
  737. weakSelf.lastLabel.hidden = (weakSelf.dataArr.count < 1);
  738. }
  739. [weakSelf refreshCommentData];
  740. } failure:^(NSError * _Nonnull error) {
  741. SHOWERROR([ZYCTool handerResultData:error]);
  742. }];
  743. });
  744. } failure:^(NSError * _Nonnull error) {
  745. SHOWERROR(@"评论失败");
  746. }];
  747. }
  748. #pragma mark - MHTopicCellDelegate
  749. - (void)topicCellForClickedThumbAction:(MHTopicCell *)topicCell
  750. {
  751. }
  752. - (void)topicCellForClickedMoreAction:(MHTopicCell *)topicCell
  753. {
  754. /**
  755. * 这里点击事件自行根据自己UI处理
  756. *
  757. */
  758. // 修改数据源方法
  759. MHTopic *topic = topicCell.topicFrame.topic;
  760. topic.IsLaud = !topic.IsLaud;
  761. if (topic.IsLaud) {
  762. // topic.thumbNums+=1;
  763. // }else{
  764. // topic.thumbNums-=1;
  765. }
  766. // 刷新数据
  767. [self.tableView reloadData];
  768. }
  769. - (void)topicCellDidClickedUser:(MHTopicCell *)topicCell
  770. {
  771. MailListDetailVC * vc = [MailListDetailVC initMailListDetailVC];
  772. vc.indexId = topicCell.topicFrame.topic.UserId;
  773. [self.navigationController pushViewController:vc animated:YES];
  774. }
  775. - (void) topicCell:(MHTopicCell *)topicCell didClickedUser:(NSString *)userId
  776. {
  777. NSLog(@"======%@",userId);
  778. // MHUserInfoController *userInfo = [[MHUserInfoController alloc] init];
  779. // userInfo.user = user;
  780. // [self.navigationController pushViewController:userInfo animated:YES];
  781. }
  782. ///评论正文 回复评论在Cell的block里面
  783. - (void)topicCell:(MHTopicCell *)topicCell didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  784. {
  785. MHTopicFrame *topicFrame = topicCell.topicFrame;
  786. MHCommentFrame *commentFrame = topicFrame.commentFrames[indexPath.row];
  787. [self replyCommentName:commentFrame.comment.Name andId:commentFrame.comment.Id];
  788. }
  789. - (void)replyCommentName:(NSString *)name andId:(NSString *)commentId{
  790. [_commentInputView startEditing];
  791. [_commentInputView setPlaceText:[NSString stringWithFormat:@"回复%@:",name]];
  792. WEAKSELF
  793. self.commentInputView.inputBlock = ^(NSString * _Nonnull content) {
  794. NSLog(@"%@",content);
  795. [weakSelf replyCommentWithcontent:content andId:commentId];
  796. };
  797. }
  798. - (void)replyCommentWithcontent:(NSString *)content andId:(NSString *)commentId
  799. {
  800. if (content.length < 1) {
  801. SHOWERROR(@"请输入评论");
  802. return;
  803. }
  804. SHOWLOADING
  805. WS(weakSelf);
  806. //@{@"ArticleId":@(self.currentModel.Id),@"Content":content,@"UserId":@([AppUserModel sharedAppUserModel].Id),@"Pid":commentId,@"TypeValue":@"0"}
  807. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Artticle_AddConmment_Post] parameters:@{@"ArticleId":@(self.currentModel.Id),@"Content":content,@"UserId":@([AppUserModel sharedAppUserModel].Id),@"Pid":commentId} responseStyle:DATA success:^(id _Nonnull responseObject) {
  808. SHOWSUCCESS(@"评论楼主成功");
  809. [weakSelf getConmmtenData];
  810. } failure:^(NSError * _Nonnull error) {
  811. SHOWERROR(@"评论楼主失败");
  812. }];
  813. }
  814. #pragma mark - 点击已阅读数代理
  815. - (void)didDetailTitlefunctionTouch:(TDButton *)button{
  816. NoticeUnreadVC *vc = [NoticeUnreadVC initNoticeUnreadVC];
  817. [self.navigationController pushViewController:vc animated:YES];
  818. }
  819. #pragma mark - setter
  820. - (UIView *)scrollView {
  821. if (!_scrollView) {
  822. _scrollView = [[UIView alloc] init];
  823. }
  824. return _scrollView;
  825. }
  826. - (DetailTitleView *)titleView {
  827. if (!_titleView) {
  828. _titleView = [[DetailTitleView alloc] init];
  829. _titleView.backgroundColor = [UIColor whiteColor];
  830. _titleView.delegate = self;
  831. }
  832. return _titleView;
  833. }
  834. - (DetailContentView *)textContentView{
  835. if(!_textContentView){
  836. _textContentView = [[DetailContentView alloc]init];
  837. }
  838. return _textContentView;
  839. }
  840. - (TDTableView *)tableView {
  841. if (!_tableView) {
  842. _tableView = [[TDTableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  843. _tableView.backgroundColor = [UIColor clearColor];
  844. _tableView.dataSource = self;
  845. _tableView.delegate = self;
  846. }
  847. return _tableView;
  848. }
  849. - (HomeCommentView *)commentView {
  850. if (!_commentView) {
  851. _commentView = [HomeCommentView shareView];
  852. }
  853. return _commentView;
  854. }
  855. - (TextInputView *)commentInputView
  856. {
  857. if (!_commentInputView) {
  858. _commentInputView = [[TextInputView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  859. }
  860. return _commentInputView;
  861. }
  862. - (ClickOKView *)zanView{
  863. if(!_zanView){
  864. _zanView = [[ClickOKView alloc] init];
  865. // _zanView.delegate = self;
  866. }
  867. return _zanView;
  868. }
  869. - (TDNavigationBar *)myNavigationBar{
  870. if (!_myNavigationBar) {
  871. _myNavigationBar = [[TDNavigationBar alloc] initNavigationBar];
  872. _myNavigationBar.backgroundColor = [UIColor whiteColor];
  873. _myNavigationBar.delegate = self;
  874. _myNavigationBar.backButton2.hidden = NO;
  875. [_myNavigationBar.backButton2 setImage:IMG(@"menu_black_icon") forState:UIControlStateNormal];
  876. [_myNavigationBar setTitle:@"正文"];
  877. }
  878. return _myNavigationBar;
  879. }
  880. - (void)backButtonAction{
  881. [self back];
  882. }
  883. - (void)backButtonAction2:(TDButton *)sender{
  884. [self secondBarButtonItems];
  885. }
  886. - (void)rightButtonAction:(TDButton *)sender{
  887. [self secondBarButtonItems];
  888. }
  889. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  890. }
  891. - (DrawerView *)drawerView{
  892. if (!_drawerView) {
  893. _drawerView = [[DrawerView alloc]init];
  894. }
  895. return _drawerView;
  896. }
  897. - (NSMutableArray *)dataArr{
  898. if (!_dataArr) {
  899. _dataArr = [NSMutableArray array];
  900. }
  901. return _dataArr;
  902. }
  903. - (Item *)currentModel {
  904. if (!_currentModel) {
  905. _currentModel = [Item new];
  906. }
  907. return _currentModel;
  908. }
  909. #pragma mark -转发
  910. - (void)shareHander{
  911. [self.noteBookShareVC initNoteBookShareData];
  912. self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
  913. }
  914. - (NoteBookShareVC *)noteBookShareVC{
  915. if (_noteBookShareVC == nil) {
  916. _noteBookShareVC = [NoteBookShareVC initNoteBookShareVC];
  917. [_noteBookShareVC.view setFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  918. [_noteBookShareVC.view setHidden:YES];
  919. _noteBookShareVC.delegate = self;
  920. }
  921. return _noteBookShareVC;
  922. }
  923. -(void)userSelectType:(NSString *)typeName WithIndexPath:(NSIndexPath *)indexPath{
  924. self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
  925. if ([typeName isEqualToString:@"发给微信好友"]) {
  926. [self returnToWechatSession];
  927. }else if ([typeName isEqualToString:@"发到朋友圈"]){
  928. [self returnToWechatTimeLine];
  929. }else if ([typeName isEqualToString:@"发到微博"]){
  930. [self returnToSina];
  931. }else if ([typeName isEqualToString:@"发给QQ好友"]){
  932. [self returnToQQ];
  933. }else if ([typeName isEqualToString:@"发到消息"]){
  934. [self returnToMessage];
  935. }else if ([typeName isEqualToString:@"发到小组"]){
  936. [self returnToGroup];
  937. }else if ([typeName isEqualToString:@"发到笔记"]){
  938. [self returnToNote];
  939. }else if ([typeName isEqualToString:@"发到话题"]){
  940. [self returnToTopic];
  941. }else{
  942. }
  943. }
  944. //UMSocialPlatformType_Sina = 0, //新浪
  945. //UMSocialPlatformType_WechatSession = 1, //微信聊天
  946. //UMSocialPlatformType_WechatTimeLine = 2,//微信朋友圈
  947. //UMSocialPlatformType_WechatFavorite = 3,//微信收藏
  948. //UMSocialPlatformType_QQ = 4,//QQ聊天页面
  949. - (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType title:(NSString *)title desc:(NSString *)desc url:(NSString *)url
  950. {
  951. //创建分享消息对象
  952. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  953. messageObject.title = title;
  954. //创建网页内容对象
  955. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:desc thumImage:IMG(@"logo_60")];
  956. //设置网页地址
  957. shareObject.webpageUrl = url;
  958. //分享消息对象设置分享内容对象
  959. messageObject.shareObject = shareObject;
  960. //调用分享接口
  961. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  962. if (error) {
  963. SHOWERROR(@"分享失败,请先安装应用");
  964. }else{
  965. NSLog(@"response data is %@",data);
  966. }
  967. }];
  968. }
  969. - (void)returnToWechatSession
  970. {
  971. NSString * url = [NSString stringWithFormat:@"%@%ld",@"http://192.168.0.119:8080/admin/mobile/mainText?",(long)self.currentModel.Id];
  972. [self shareWebPageToPlatformType:UMSocialPlatformType_WechatSession title:self.currentModel.Title desc:self.currentModel.Summary url:url];
  973. }
  974. - (void)returnToWechatTimeLine
  975. {
  976. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(@"/admin/mobile/mainText?"),(long)self.currentModel.Id];
  977. [self shareWebPageToPlatformType:UMSocialPlatformType_WechatTimeLine title:self.currentModel.Title desc:self.currentModel.Summary url:url];
  978. }
  979. - (void)returnToSina
  980. {
  981. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(@"/admin/mobile/mainText?"),(long)self.currentModel.Id];
  982. [self shareWebPageToPlatformType:UMSocialPlatformType_Sina title:self.currentModel.Title desc:self.currentModel.Summary url:url];
  983. }
  984. - (void)returnToQQ
  985. {
  986. // NSString * url = [NSString stringWithFormat:@"%@%ld",@"http://192.168.0.119:8080/admin/mobile/mainText?",(long)self.currentModel.Id];
  987. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(@"/admin/mobile/mainText?"),(long)self.currentModel.Id];
  988. [self shareWebPageToPlatformType:UMSocialPlatformType_QQ title:self.currentModel.Title desc:self.currentModel.Summary url:url];
  989. }
  990. - (void)returnToMessage
  991. {
  992. MailListVC * vc = [MailListVC initMailListVC];
  993. FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
  994. model.SoureId = self.currentModel.Id;
  995. model.SoureTypeId = CollectModel_Aritle;
  996. model.Title = self.currentModel.Title;
  997. model.Author = self.currentModel.Author;
  998. vc.sendModel = model;
  999. vc.isReturn = YES;
  1000. [self.navigationController pushViewController:vc animated:YES];
  1001. }
  1002. - (void)returnToGroup
  1003. {
  1004. MyTDGroupViewController * vc = [[MyTDGroupViewController alloc] init];
  1005. vc.type = CollectModel_Group;
  1006. FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
  1007. model.SoureId = self.currentModel.Id;
  1008. model.SoureTypeId = CollectModel_Aritle;
  1009. model.Title = self.currentModel.Title;
  1010. model.Author = self.currentModel.Author;
  1011. vc.sendModel = model;
  1012. vc.isReturn = YES;
  1013. [self.navigationController pushViewController:vc animated:YES];
  1014. }
  1015. - (void)returnToNote
  1016. {
  1017. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  1018. vc.type = CollectModel_NoteBook;
  1019. FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
  1020. model.SoureId = self.currentModel.Id;
  1021. model.SoureTypeId = CollectModel_Aritle;
  1022. model.Title = self.currentModel.Title;
  1023. model.Author = self.currentModel.Author;
  1024. vc.sendModel = model;
  1025. vc.isReturn = YES;
  1026. [self.navigationController pushViewController:vc animated:YES];
  1027. }
  1028. - (void)returnToTopic
  1029. {
  1030. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  1031. vc.type = CollectModel_NewTopic;
  1032. FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
  1033. model.SoureId = self.currentModel.Id;
  1034. model.SoureTypeId = CollectModel_Aritle;
  1035. model.Title = self.currentModel.Title;
  1036. model.Author = self.currentModel.Author;
  1037. vc.sendModel = model;
  1038. vc.isReturn = YES;
  1039. [self.navigationController pushViewController:vc animated:YES];
  1040. }
  1041. - (void)scrollToCommentViewTop
  1042. {
  1043. if (self.isScrComment) {
  1044. if (self.dataArr.count > 0 || self.goodsSource.count > 0) {
  1045. [self.tableView scrollToRow:0 inSection:1 atScrollPosition:UITableViewScrollPositionTop animated:YES];
  1046. }
  1047. }else{
  1048. [self.tableView scrollToTop];
  1049. }
  1050. }
  1051. - (void)ShareDetail{
  1052. SHOWLOADING
  1053. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  1054. [dic setValue:@(self.currentModel.Id) forKey:@"SourceId"];
  1055. [dic setValue:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"];
  1056. [dic setValue:@(4) forKey:@"AnalyzeType"];///转发
  1057. [dic setValue:@(0) forKey:@"CommentId"];
  1058. [dic setValue:@(0) forKey:@"TypeValue"];///0文章
  1059. WS(weakSelf);
  1060. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Analyze_Set) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
  1061. REMOVESHOW
  1062. [weakSelf refreshBottomData];
  1063. [weakSelf shareHander];
  1064. } failure:^(NSError * _Nonnull error) {
  1065. REMOVESHOW
  1066. // SHOWERROR([ZYCTool handerResultData:error]);
  1067. }];
  1068. }
  1069. - (void)refreshBottomData
  1070. {
  1071. WEAKSELF
  1072. [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,[NSString stringWithFormat:@"/api/app/article/detail/%zi",self.currentModel.Id]] parameters:@{@"id":@(self.currentModel.Id)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  1073. REMOVESHOW
  1074. weakSelf.currentModel = [Item modelWithDictionary:responseObject];
  1075. //设置收藏等数量以及状态
  1076. dispatch_async(dispatch_get_main_queue(), ^{
  1077. [weakSelf setBottomViewData:weakSelf.currentModel];
  1078. });
  1079. } failure:^(NSError * _Nonnull error) {
  1080. REMOVESHOW
  1081. SHOWERROR([ZYCTool handerResultData:error]);
  1082. }];
  1083. }
  1084. - (void)refreshCommentData
  1085. {
  1086. WEAKSELF
  1087. [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,[NSString stringWithFormat:@"/api/app/article/detail/%zi",self.currentModel.Id]] parameters:@{@"id":@(self.currentModel.Id)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  1088. REMOVESHOW
  1089. weakSelf.currentModel = [Item modelWithDictionary:responseObject];
  1090. //设置收藏等数量以及状态
  1091. [weakSelf.dataArr removeAllObjects];
  1092. WEAKSELF
  1093. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Artticle_ConmmentList_Post] parameters:@{@"ArticleId":@(self.currentModel.Id),@"TypeValue":@"0",@"Page":@1,@"PerPage":@100000,@"Sort":self.sort} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  1094. if ([responseObject[@"Items"] isKindOfClass:[NSArray class]]) {
  1095. for (NSDictionary * dict in responseObject[@"Items"]) {
  1096. MHTopic * topic = [MHTopic modelWithDictionary:dict];
  1097. if ([[dict objectForKey:@"TopicCommentReplyResults"] isKindOfClass:[NSArray class]]) {
  1098. NSMutableArray<MHComment *> * subArray = [NSMutableArray<MHComment *> array];
  1099. for (NSDictionary * subDict in dict[@"TopicCommentReplyResults"]) {
  1100. MHComment * commentModel = [MHComment modelWithDictionary:subDict];
  1101. [subArray addObject:commentModel];
  1102. }
  1103. topic.CommentReplyResults = [NSMutableArray<MHComment *> arrayWithArray:subArray];
  1104. }
  1105. [weakSelf.dataArr addObject:[weakSelf _topicFrameWithTopic:topic]];
  1106. }
  1107. weakSelf.lastLabel.hidden = (weakSelf.dataArr.count < 1);
  1108. }
  1109. dispatch_async(dispatch_get_main_queue(), ^{
  1110. [weakSelf.tableView reloadData];
  1111. [weakSelf setBottomViewData:weakSelf.currentModel];
  1112. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1113. weakSelf.isScrComment = YES;
  1114. [weakSelf scrollToCommentViewTop];
  1115. });
  1116. });
  1117. } failure:^(NSError * _Nonnull error) {
  1118. SHOWERROR([ZYCTool handerResultData:error]);
  1119. }];
  1120. } failure:^(NSError * _Nonnull error) {
  1121. REMOVESHOW
  1122. SHOWERROR([ZYCTool handerResultData:error]);
  1123. }];
  1124. }
  1125. #pragma mark - 长按删除评论Cell
  1126. - (void)longDeleteSelf:(MHTopicCell *)cell
  1127. {
  1128. [self becomeFirstResponder];
  1129. UIMenuController *menu = [UIMenuController sharedMenuController];
  1130. UIMenuItem *deleteItem = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(deleteItemAction:)];
  1131. [menu setMenuItems: @[deleteItem]];
  1132. NSLog(@"%@",NSStringFromCGRect(cell.frame));
  1133. [menu setTargetRect:cell.contentLabel.frame inView:cell];
  1134. [menu setMenuVisible:YES animated:NO];
  1135. }
  1136. - (void)longDeleteSubCell:(UILabel *)label
  1137. {
  1138. [self becomeFirstResponder];
  1139. UIMenuController *menu = [UIMenuController sharedMenuController];
  1140. UIMenuItem *deleteItem = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(deleteItemAction:)];
  1141. [menu setMenuItems: @[deleteItem]];
  1142. [menu setTargetRect:label.frame inView:label];
  1143. [menu setMenuVisible:YES animated:NO];
  1144. }
  1145. - (BOOL)canBecomeFirstResponder
  1146. {
  1147. return YES;
  1148. }
  1149. - (void)deleteItemAction:(UIMenuItem *)item
  1150. {
  1151. WS(weakSelf);
  1152. SHOWLOADING
  1153. [[HttpManager sharedHttpManager] DeleteUrl:Host(API_APP_Comment_Delete) parameters:@{@"ArticleId":@(self.currentModel.Id),@"CommentId":@(self.commentId)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  1154. REMOVESHOW
  1155. SHOWSUCCESS(@"删除成功");
  1156. [weakSelf refreshCommentData];
  1157. } failure:^(NSError * _Nonnull error) {
  1158. REMOVESHOW
  1159. SHOWERROR([ZYCTool handerResultData:error])
  1160. }];
  1161. }
  1162. @end