HomeDetailController.m 48 KB

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