123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176 |
- //
- // HomeDetailController.m
- // TheoryNetwork
- //
- // Created by tederen on 2019/9/26.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "HomeDetailController.h"
- #import "DocumentModel.h"
- #import "DetailTitleView.h"
- #import "CommentSetView.h"
- #import "TextInputView.h"
- #import "MHComment.h"
- #import "ReplyDetailController.h"
- #import "ThirdSharedView.h"
- #import <WebKit/WebKit.h>
- #import "DetailContentView.h"
- #import "ClickOKView.h"
- #import "ClickOKViewController.h"
- #import "DrawerView.h"
- #import "FavoritesViewController.h"
- #import "MyTDGroupViewController.h"
- #import "MyTDTopicViewController.h"
- #import "TDNavigationBar.h"
- #import "SendInfoGroupVC.h"
- #import "NoticeUnreadVC.h"
- #import "ArticleTextCell.h"
- #import "ArticleImageCell.h"
- #import "ArticleBlocks.h"
- #import "UILabel+Extension.h"
- #import "MailListDetailVC.h"
- #import "MHTopicFrame.h"
- #import "MHTopicCell.h"
- #import "TabBarController.h"
- #import "FecordDetailsGoodsCell.h"
- #import "CreateNoteBookVC.h"
- #import "NoteBookShareVC.h"
- #import "MyTDGroupViewController.h"
- #import "MyTDTopicCreateVC.h"
- #import "MoveViewController.h"
- #import "HomeCommentView.h"
- #import "FLAnimatedImage.h"
- static NSString *textID = @"ArticleTextCell";
- static NSString *imageID = @"ArticleImageCell";
- #define kTopHeigh (IS_IPHONEX?88:64)
- @interface HomeDetailController () <WKUIDelegate, WKNavigationDelegate, UITableViewDataSource, UITableViewDelegate,DetailTitleViewDelegate,TDNavigationBarDelegate,MHTopicCellDelegate,NoteBookShareVCDelegate> {
- }
- @property (nonatomic, strong) Item *currentModel;
- @property (nonatomic, strong) UIView *scrollView;
- @property (nonatomic, strong) DetailTitleView *titleView;
- @property (nonatomic, strong) WKWebView *webView;
- @property (nonatomic, strong) TDTableView *tableView;
- @property (nonatomic, strong) HomeCommentView *commentView;
- @property (nonatomic, strong) TextInputView *commentInputView;
- @property (nonatomic, strong) ClickOKView *zanView;
- @property (nonatomic, strong) TDNavigationBar *myNavigationBar;
- @property (nonatomic, strong) DrawerView *drawerView;
- @property (nonatomic, copy) NSMutableArray *dataArr;
- @property (nonatomic, strong) DetailContentView *textContentView;
- @property (nonatomic, assign) NSInteger loadingfalg;
- @property (nonatomic, assign) NSInteger zantotal;
- @property (nonatomic, strong) NSMutableArray *goodsSource;
- @property (nonatomic, copy) NSString *sort;
- @property (nonatomic, strong) UILabel *lastLabel;
- @property (strong, nonatomic) NoteBookShareVC * noteBookShareVC;
- @property (nonatomic, assign) NSInteger countComment;
- @property (nonatomic, assign) BOOL isScrComment;
- @property (nonatomic,assign) NSInteger commentId;
- @end
- @implementation HomeDetailController
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self.view addSubview:self.myNavigationBar];
- self.fd_prefersNavigationBarHidden = YES;
-
- [self.view addSubview:self.tableView];
- self.view.backgroundColor = [UIColor whiteColor];
- self.title = @"正文";
- // _tableView.frame = CGRectMake(0, kNavigationHeight, kGXScreenWidth, SCREEN_HEIGHT - kiphoneXBootomHeight - 45 - kNavigationHeight);
- // 评论
- self.sort = @"desc"; // 默认正序
- [self.view addSubview:self.commentView];
- [self.commentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.height.mas_offset(@58);
- if (@available(iOS 11.0, *)) {
- make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
- } else {
- make.bottom.equalTo(self.view.mas_bottom);
- }
- }];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.myNavigationBar.mas_bottom);
- make.bottom.mas_equalTo(self.commentView.mas_top);
- }];
-
- WS(weakSelf);
- [self.commentView.shareButton setAction:^{
- [weakSelf ShareDetail];
- }];
- [self.commentView.zanButton setAction:^{
- [weakSelf sendZanToServer:1];
- }];
- [self.commentView.commentButton setAction:^{
- [weakSelf commentHander];
- }];
- [self.commentView.commentScrollBtn setAction:^{
- weakSelf.isScrComment = !weakSelf.isScrComment;
- [weakSelf scrollToCommentViewTop];
- }];
-
- _scrollView.frame = CGRectMake(0, 0, kGXScreenWidth, kGXScreenHeigh);
- [self.scrollView addSubview:self.titleView];
- _titleView.frame = CGRectMake(0, 0, kGXScreenWidth, 0);
-
- [_titleView loadTitleModel:self.currentModel];
- CGRect frame = self.scrollView.frame;
- frame.size.height = _zanView.height + _titleView.height ;
- self.scrollView.frame = frame;
- [self.tableView setTableHeaderView:self.scrollView];
-
- UIView *myfootView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kGXScreenWidth, 60)];
- UIView *MYlineView = [[UIView alloc] initWithFrame:CGRectMake(21,0, kGXScreenWidth-42,0.5)];
- MYlineView.backgroundColor = UIColorHex(E5E5E5);
- [myfootView addSubview:MYlineView];
-
- self.lastLabel = [[UILabel alloc]init];
- self.lastLabel.frame = CGRectMake(0, 0, 200, 30);
- self.lastLabel.center = myfootView.center;
- self.lastLabel.font = [UIFont systemFontOfSize:13.f];
- self.lastLabel.textAlignment = NSTextAlignmentCenter;
- self.lastLabel.textColor = UIColorHex(CCCCCC);
- self.lastLabel.text = @"已经到底啦~";
-
- [myfootView addSubview:self.lastLabel];
-
- // UIView *MYlineView2 = [[UIView alloc] initWithFrame:CGRectMake(21,59, kGXScreenWidth-42,0.5)];
- // MYlineView2.backgroundColor = UIColorHex(E5E5E5);
- // [myfootView addSubview:MYlineView2];
-
- // [self.tableView setTableFooterView:myfootView];
-
-
- 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)]];
-
- self.loadingfalg = 1 ;
- [self loadDetails];
- SHOWLOADING
- [self getZanData];
- [self getConmmtenData];
- // 通知-监听键盘弹出事件
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeKeyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil];
- // 通知-监听键盘回收事
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeKeyboardWillHideNotification:) name:UIKeyboardWillHideNotification object:nil];
- //注册点赞
- [self.tableView registerNib:[UINib nibWithNibName:@"FecordDetailsGoodsCell" bundle:nil] forCellReuseIdentifier:@"FecordDetailsGoodsCell"];
- self.tableView.backgroundColor = [UIColor colorWithHexString:@"F7F7F7"];
-
- [self.view addSubview:self.noteBookShareVC.view];
- [self.view addSubview:self.commentInputView];
- }
- #pragma mark - UIKeyBoradNotification
- - (void)changeKeyboardWillShowNotification:(NSNotification*)notification
- {
- WS(weakSelf);
- NSDictionary *userInfo = [notification userInfo];
- // 键盘弹出后的frame的结构体对象
- NSValue *valueEndFrame = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
- // 得到键盘弹出后的键盘视图所在y坐标
- CGFloat keyBoardEndY = valueEndFrame.CGRectValue.origin.y;
- // 键盘弹出的动画时间
- NSNumber *duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
- // 键盘弹出的动画曲线
- NSNumber *curve = [userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
- // 添加移动动画,使视图跟随键盘移动(动画时间和曲线都保持一致)
- [UIView animateWithDuration:[duration doubleValue] animations:^{
- [UIView setAnimationBeginsFromCurrentState:YES];
- [UIView setAnimationCurve:[curve intValue]];
- [UIView animateWithDuration:0.5 animations:^{
- [weakSelf.commentInputView startAnimationWithY:keyBoardEndY - 150.f];
- }];
- } completion:^(BOOL finished) {
-
- }];
- }
- - (void)changeKeyboardWillHideNotification:(NSNotification*)notification
- {
- WS(weakSelf);
- NSDictionary *userInfo = [notification userInfo];
- // 键盘弹出的动画时间
- NSNumber *duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
- // 键盘弹出的动画曲线
- NSNumber *curve = [userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
- [UIView animateWithDuration:[duration doubleValue]animations:^{
- [weakSelf.commentInputView startAnimationWithY:SCREEN_HEIGHT];
- [UIView setAnimationBeginsFromCurrentState:YES];
- [UIView setAnimationCurve:[curve intValue]];
- } completion:^(BOOL finished) {
-
- }];
- }
- - (void)setBottomViewData:(Item *)model
- {
- self.countComment = model.CommentCount;
- if (model.CommentCount == 0) {
- self.commentView.commentCountL.text = [NSString stringWithFormat:@"评 论"];
- }else{
- if (model.CommentCount > 10000) {
- self.commentView.commentCountL.text = [NSString stringWithFormat:@"%.1f万\n评 论",model.CommentCount / 10000.0];
- }else{
- self.commentView.commentCountL.text = [NSString stringWithFormat:@"%ld\n评 论",(long)model.CommentCount];
- }
- }
- self.commentView.zanCountL.text = [NSString stringWithFormat:@"%ld",(long)model.PraiseCount];
- self.commentView.collectL.text = [NSString stringWithFormat:@"%ld",(long)model.CollectCount];
- self.commentView.shareL.text = [NSString stringWithFormat:@"%ld",(long)model.RetransmissionCount];
- self.commentView.zanCountL.hidden = model.PraiseCount == 0 ? YES : NO;
- self.commentView.collectL.hidden = model.CollectCount == 0 ? YES : NO;
- self.commentView.shareL.hidden = model.RetransmissionCount == 0 ? YES : NO;
- self.commentView.zanImgV.image = model.IsPraise ? IMG(@"zan_yes"):IMG(@"zan_no");
- self.commentView.collectImgV.image = model.IsCollect ? IMG(@"icon_collect_off"):IMG(@"收藏五角星");
- self.commentView.shareImgV.image = IMG(@"icon_share");
- WS(weakSelf);
-
- [self.commentView.collectButton setAction:^{
- if (model.IsCollect) {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"真的取消收藏吗?" message:nil preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *actionYes = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
- [dic setValue:@(self.currentModel.Id) forKey:@"CollectionDataId"];
- /// 1文章 2话题 3 收藏 4笔记 5通知 6站内信 7小组 8 会议详情 14工作流审批 300 文件 400 会议纪要
- [dic setValue:@(1) forKey:@"CollectionType"];
- [dic setValue:@(0) forKey:@"FolderId"];
- [dic setValue:@(0) forKey:@"SourceUserId"];
- [[HttpManager sharedHttpManager] PUTUrl:Host(API_CreateCollect) parameters:dic success:^(id _Nonnull responseObject) {
- [weakSelf refreshBottomData];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }];
- UIAlertAction *actionNo = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:actionYes];
- [alert addAction:actionNo];
- [weakSelf presentViewController:alert animated:YES completion:^{
-
- }];
- }else{
- NSLog(@"文章详情--收藏");
- MoveViewController *vc = [MoveViewController initMoveViewController];
- vc.CollectionDataId = weakSelf.currentModel.Id;
- vc.collectType = CollectHanderType_Collect;
- vc.ParentId = 0;
- vc.titleStr = @"我的收藏";
- vc.TypeId = CreateCollectionType;
- vc.FolderIds = @[].mutableCopy;
- vc.CollectionType = 1;
- [vc setActionSuss:^(NSString * _Nonnull status) {
- if ([status isEqualToString:@"YES"]) {
- [weakSelf refreshBottomData];
- }
- }];
- [weakSelf.navigationController pushViewController:vc animated:YES];
- }
- }];
- self.commentView.zanCountL.textColor = model.IsPraise ? UIColorHex(#009AFF):UIColorHex(#999999);
- self.commentView.collectL.textColor = model.IsCollect ? UIColorHex(#009AFF):UIColorHex(#999999);
- self.commentView.shareL.textColor = UIColorHex(#009AFF);
- }
- - (void)loadDetails {
- WEAKSELF
- [[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) {
- weakSelf.currentModel = [Item modelWithDictionary:responseObject];
- //设置收藏等数量以及状态
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- [weakSelf setBottomViewData:weakSelf.currentModel];
- });
- weakSelf.loadingfalg +=1;
- if (weakSelf.loadingfalg == 3) {
- REMOVESHOW
- }
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- - (void)getZanData{
- SHOWLOADING
- WEAKSELF
- [[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) {
- NSLog(@"%@点赞页数据",responseObject);
- REMOVESHOW
- if ([responseObject isKindOfClass:[NSDictionary class]]) {
- NSDictionary *dic = responseObject;
- weakSelf.zantotal = [dic[@"Total"] integerValue];
- weakSelf.goodsSource = dic[@"Items"];
- weakSelf.loadingfalg +=1;
- if (weakSelf.loadingfalg == 3) {
- REMOVESHOW
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- }
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- - (void)getConmmtenData{
- // 排序todo
- [self.dataArr removeAllObjects];
- WEAKSELF
- [[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) {
- if ([responseObject[@"Items"] isKindOfClass:[NSArray class]]) {
- for (NSDictionary * dict in responseObject[@"Items"]) {
- MHTopic * topic = [MHTopic modelWithDictionary:dict];
- if ([[dict objectForKey:@"TopicCommentReplyResults"] isKindOfClass:[NSArray class]]) {
- NSMutableArray<MHComment *> * subArray = [NSMutableArray<MHComment *> array];
- for (NSDictionary * subDict in dict[@"TopicCommentReplyResults"]) {
- MHComment * commentModel = [MHComment modelWithDictionary:subDict];
- [subArray addObject:commentModel];
- }
- topic.CommentReplyResults = [NSMutableArray<MHComment *> arrayWithArray:subArray];
- }
- [weakSelf.dataArr addObject:[weakSelf _topicFrameWithTopic:topic]];
- }
- weakSelf.lastLabel.hidden = (weakSelf.dataArr.count < 1);
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- weakSelf.loadingfalg +=1;
- if (weakSelf.loadingfalg == 3) {
- REMOVESHOW
- }
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- #pragma mark - 导航事件处理
- -(void)back{
- if (self.navigationController.viewControllers.count > 1) {
- [self.navigationController popViewControllerAnimated:YES];
- }else{
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- }
- - (void)secondBarButtonItems{
- [self.view endEditing:YES];
- [[UtilsTools getWindow] addSubview:self.drawerView];
- WS(weakSelf);
- self.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
- if ([weakSelf.navigationController.viewControllers count] > 1) {
- [weakSelf.navigationController popToRootViewControllerAnimated:NO];
- }
- if (indexPath.section == 0) {
- [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
- }else{
- ///@"站内信", @"通知", @"收藏",@"笔记", @"设置"
- switch (indexPath.row) {
- case 0:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:2];
- }
- break;
- case 1:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:2];
- }
- break;
- default:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:3];
- }
- break;
- }
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(indexPath.row)}];
- });
- }
- };
- self.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);
- }
- - (void)loadCurrentModel:(Item *)model {
- self.currentModel = model;
- }
- #pragma mark - UITableViewDataSource && UITableViewDelegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 3;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (section==0) {
- return self.currentModel.ArticleBlocks.count ;
- }else if (section == 1){
- return 1;
- }
- return self.dataArr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- if (indexPath.section==0) {
- ArticleBlocks *articleBlock = self.currentModel.ArticleBlocks[indexPath.row];
- if ([articleBlock.Type isEqualToString:@"image"]) {
- NSDictionary *file = articleBlock.Data.File;
- UIImage *image = [[YYImageCache sharedCache] getImageForKey:file[@"Url"]];
- CGFloat height = 0 ;
- if (image.size.width > 0.0) {
- height += image.size.height * SCREEN_WIDTH / image.size.width;
- return height;
- }else{
- return 180.f;
- }
- return UITableViewAutomaticDimension;
- }else{
- return [ArticleTextCell cellHeight:articleBlock.Data.Text];
- }
- return UITableViewAutomaticDimension;
- }
- else if (indexPath.section==1){
- if (self.goodsSource.count ==0 && self.dataArr.count == 0) {
- return 0.001f;
- }else{
- return 50;
- }
- }
- MHTopicFrame *topicFrame = self.dataArr[indexPath.row];
- if (topicFrame.tableViewFrame.size.height == 0) {
- return topicFrame.height+topicFrame.tableViewFrame.size.height;
- }else{
- return topicFrame.height+topicFrame.tableViewFrame.size.height+MHTopicVerticalSpace;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return .001f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return .001f;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- WEAKSELF
- switch (indexPath.section) {
- case 0:
- {
- ArticleBlocks *articleBlock = self.currentModel.ArticleBlocks[indexPath.row];
- if ([articleBlock.Type isEqualToString:@"image"]) {
- ArticleImageCell *imageCell = [tableView dequeueReusableCellWithIdentifier:imageID];
- if (!imageCell) {
- [tableView registerNib:[UINib nibWithNibName:imageID bundle:nil] forCellReuseIdentifier:imageID];
- imageCell = [tableView dequeueReusableCellWithIdentifier:imageID];
- }
- NSDictionary *file = articleBlock.Data.File;
- WS(weakSelf);
- UILongPressGestureRecognizer * longges = [[UILongPressGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
- UILongPressGestureRecognizer * press = (UILongPressGestureRecognizer *)sender;
- if (press.state == UIGestureRecognizerStateBegan) {
- dispatch_async(dispatch_get_main_queue(), ^{
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- UIAlertAction *actionYes = [UIAlertAction actionWithTitle:@"保存图片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- UIImage * img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:file[@"Url"]]]];
- [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
- [PHAssetChangeRequest creationRequestForAssetFromImage:img];
- } completionHandler:^(BOOL success, NSError * _Nullable error) {
- dispatch_async(dispatch_get_main_queue(), ^{
- if (success) {
- SHOWSUCCESS(@"图片保存成功");
- }else{
- SHOWERROR(@"图片保存失败");
- }
- });
- }];
- }];
- UIAlertAction *actionNo = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:actionYes];
- [alert addAction:actionNo];
- [weakSelf presentViewController:alert animated:YES completion:^{
- }];
- });
- }
- }];
- [imageCell.imgView addGestureRecognizer:longges];
- imageCell.imgView.userInteractionEnabled = YES;
- imageCell.selectionStyle = UITableViewCellSelectionStyleNone;
- if ([self isGifOrSwf:file[@"Url"]]) {
- FLAnimatedImage * image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:file[@"Url"]]]];
- FLAnimatedImageView * imageV = [[FLAnimatedImageView alloc] init];
- imageV.animatedImage = image;
- imageCell.imgView = imageV;
- }else{
- [imageCell.imgView setImageWithURL:[NSURL URLWithString:file[@"Url"]] placeholder:IMG(@"img_placeHolder")];
- }
- imageCell.imgTitleLab.text = articleBlock.Data.Caption;
- return imageCell;
- }else{
- ArticleTextCell *textCell = [tableView dequeueReusableCellWithIdentifier:textID];
- if (!textCell) {
- [tableView registerNib:[UINib nibWithNibName:textID bundle:nil] forCellReuseIdentifier:textID];
- textCell = [tableView dequeueReusableCellWithIdentifier:textID];
- }
- textCell.selectionStyle = UITableViewCellSelectionStyleNone;
- [textCell setContent:articleBlock.Data.Text];
- return textCell;
- }
- }
- break;
- case 1:{
- FecordDetailsGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FecordDetailsGoodsCell" forIndexPath:indexPath];
- WEAKSELF
- [cell.sortButton setAction:^{
- cell.sortButton.selected = !cell.sortButton.isSelected;
- self.sort = cell.sortButton.isSelected ? @"asc" : @"desc";
- // 排序按钮
- [weakSelf getConmmtenData];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- weakSelf.isScrComment = YES;
- [weakSelf scrollToCommentViewTop];
- });
- }];
- [cell setCellData:self.goodsSource];
- cell.sortButton.hidden = (self.dataArr.count < 1);
- cell.backgroundColor = [UIColor colorWithHexString:@"FAFAFA"];
- return cell;
- }
- default:
- {
- MHTopicCell *cell = [MHTopicCell cellWithTableView:tableView];
-
- MHTopicFrame *topicFrame = self.dataArr[indexPath.row];
- cell.topicFrame = topicFrame;
- cell.createTimeLabel.text = [NSString stringWithFormat:@"%@ %@",topicFrame.topic.FloorCount,topicFrame.topic.CreatedTime];
- [cell.thumbBtn setAction:^{
- [weakSelf didClickZanComment:topicFrame.topic withIndexPath:indexPath];
- }];
- cell.replyContentBlock = ^{
- [weakSelf replyCommentName:topicFrame.topic.Name andId:[NSString stringWithFormat:@"%ld",(long)topicFrame.topic.Id]];
- };
- __block MHTopicCell * bCell = cell;
- cell.longBlock = ^{
- weakSelf.commentId = topicFrame.topic.Id;
- [weakSelf longDeleteSelf:bCell];
- };
- cell.longSubBlock = ^(NSInteger commentId,UILabel * label) {
- weakSelf.commentId = commentId;
- [weakSelf longDeleteSubCell:label];
- };
- cell.delegate = self;
- return cell;
- }
- break;
- }
- }
- - (BOOL)isGifOrSwf:(NSString *)imageStr
- {
- NSString * name = [[imageStr pathExtension] lowercaseString];
- if ([name hasSuffix:@"gif"] || [name hasSuffix:@"swf"]) {
- return YES;
- }else{
- return NO;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.section == 1) {
- ClickOKViewController *vc = [ClickOKViewController initClickOKViewController];
- vc.indexId = self.currentModel.Id;
- vc.zanToTal = self.zantotal;
- vc.type = ZanListPageType_Article;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }
- - (MHTopicFrame *)_topicFrameWithTopic:(MHTopic *)topic
- {
- MHTopicFrame *topicFrame = [[MHTopicFrame alloc] init];
- // 传递微博模型数据,计算所有子控件的frame
- topicFrame.topic = topic;
- return topicFrame;
- }
- -(void)didClickZanComment:(MHTopic *)model withIndexPath:(NSIndexPath *)indexPath{
- NSLog(@"点击赞%@",model);
- [self sendZanToServerWithCommentId:model.Id withArticle:self.currentModel.Id model:model indexPath:indexPath];
- }
- #pragma mark - CommentSetViewDelegate
- - (void)commentNunberClick {
- //滑动到评论模块
- NSLog(@"滑动到评论顶部");
- if (self.dataArr.count > 0) {
- [self.tableView scrollToRow:0 inSection:2 atScrollPosition:UITableViewScrollPositionTop animated:YES];
- }
- }
- // 评论
- - (void)commentHander {
- [_commentInputView startEditing];
- WEAKSELF
- self.commentInputView.inputBlock = ^(NSString * _Nonnull content) {
- NSLog(@"%@",content);
- STRONGSELF
- [strongSelf sendCommentToServer:content];
- };
- }
- - (void)functionTouch:(TDButton *)button {
- switch (button.tag) {
- case SharedTag:
- NSLog(@"文章详情--分享");
- {
- [self shareHander];
- }
- break;
- case CollectTag: {
- NSLog(@"文章详情--收藏");
- MoveViewController *vc = [MoveViewController initMoveViewController];
- vc.CollectionDataId = _currentModel.Id;
- vc.collectType = CollectHanderType_Collect;
- vc.ParentId = 0;
- vc.titleStr = @"我的收藏";
- vc.TypeId = CreateCollectionType;
- vc.FolderIds = @[].mutableCopy;
- vc.CollectionType = 1;
- WS(weakSelf);
- [vc setActionSuss:^(NSString * _Nonnull status) {
- if ([status isEqualToString:@"YES"]) {
- [weakSelf loadDetails];
- }
- }];
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case ThumbTag:
- NSLog(@"文章详情--点赞");
- [self sendZanToServer:1];
- break;
- default:
- break;
- }
- }
- #pragma mark - 赞 评论数据操作
- - (void)sendZanToServerWithCommentId:(NSInteger)CommentId withArticle:(NSInteger)ArticleId model:(MHTopic *)model indexPath:(NSIndexPath *)indexPath
- {
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:@(ArticleId) forKey:@"SourceId"];
- [dic setValue:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"];
- [dic setValue:@(2) forKey:@"AnalyzeType"];///详情点赞
- [dic setValue:@(CommentId) forKey:@"CommentId"];
- [dic setValue:@(0) forKey:@"TypeValue"];///文章
- WS(weakSelf);
- [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Analyze_Set) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
- model.IsLaud = !model.IsLaud;
- if (model.IsLaud) {
- SHOWSUCCESS(@"点赞成功");
- }else{
- SHOWSUCCESS(@"取消点赞");
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
- });
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- #pragma mark - 赞 文章数据操作
- - (void)sendZanToServer:(NSInteger)ArticleAnalyzeType{
- SHOWLOADING
- WS(weakSelf);
- [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,@"/api/app/analyze/set"] parameters:@{@"SourceId":@(_currentModel.Id),@"AnalyzeType":@(ArticleAnalyzeType),@"TypeValue":@"0"} responseStyle:DATA success:^(id _Nonnull responseObject) {
- REMOVESHOW
- if (self->_currentModel.IsLaud == 1) {
- //SHOWSUCCESS(@"已取消点赞");
- self->_currentModel.IsLaud = 0;
- }else {
- self.currentModel.IsLaud = 1;
- //SHOWSUCCESS(@"点赞成功");
- }
- [weakSelf refreshLikeData];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- - (void)refreshLikeData{
- SHOWLOADING
- WEAKSELF
- [[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) {
- weakSelf.currentModel = [Item modelWithDictionary:responseObject];
- //设置收藏等数量以及状态
- [[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) {
- NSLog(@"%@点赞页数据",responseObject);
- REMOVESHOW
- if ([responseObject isKindOfClass:[NSDictionary class]]) {
- NSDictionary *dic = responseObject;
- weakSelf.zantotal = [dic[@"Total"] integerValue];
- weakSelf.goodsSource = dic[@"Items"];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- [weakSelf setBottomViewData:weakSelf.currentModel];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- weakSelf.isScrComment = YES;
- [weakSelf scrollToCommentViewTop];
- });
- });
- }
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- #pragma mark - 评论文章 数据操作
- - (void)sendCommentToServer:(NSString *)content{
- if (content.length < 1) {
- SHOWERROR(@"请输入评论");
- return;
- }
- WS(weakSelf);
- [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Artticle_AddConmment_Post] parameters:@{@"ArticleId":@(self.currentModel.Id),@"TypeValue":@"0",@"Content":content} responseStyle:DATA success:^(id _Nonnull responseObject) {
- SHOWSUCCESS(@"评论成功");
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.dataArr removeAllObjects];
- WEAKSELF
- [[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) {
- if ([responseObject[@"Items"] isKindOfClass:[NSArray class]]) {
- for (NSDictionary * dict in responseObject[@"Items"]) {
- MHTopic * topic = [MHTopic modelWithDictionary:dict];
- if ([[dict objectForKey:@"TopicCommentReplyResults"] isKindOfClass:[NSArray class]]) {
- NSMutableArray<MHComment *> * subArray = [NSMutableArray<MHComment *> array];
- for (NSDictionary * subDict in dict[@"TopicCommentReplyResults"]) {
- MHComment * commentModel = [MHComment modelWithDictionary:subDict];
- [subArray addObject:commentModel];
- }
- topic.CommentReplyResults = [NSMutableArray<MHComment *> arrayWithArray:subArray];
- }
- [weakSelf.dataArr addObject:[weakSelf _topicFrameWithTopic:topic]];
- }
- weakSelf.lastLabel.hidden = (weakSelf.dataArr.count < 1);
- }
- [weakSelf refreshCommentData];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- });
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR(@"评论失败");
- }];
- }
- #pragma mark - MHTopicCellDelegate
- - (void)topicCellForClickedThumbAction:(MHTopicCell *)topicCell
- {
- }
- - (void)topicCellForClickedMoreAction:(MHTopicCell *)topicCell
- {
- /**
- * 这里点击事件自行根据自己UI处理
- *
- */
- // 修改数据源方法
- MHTopic *topic = topicCell.topicFrame.topic;
- topic.IsLaud = !topic.IsLaud;
- if (topic.IsLaud) {
- // topic.thumbNums+=1;
- // }else{
- // topic.thumbNums-=1;
- }
-
- // 刷新数据
- [self.tableView reloadData];
- }
- - (void)topicCellDidClickedUser:(MHTopicCell *)topicCell
- {
- MailListDetailVC * vc = [MailListDetailVC initMailListDetailVC];
- vc.indexId = topicCell.topicFrame.topic.UserId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void) topicCell:(MHTopicCell *)topicCell didClickedUser:(NSString *)userId
- {
- NSLog(@"======%@",userId);
- // MHUserInfoController *userInfo = [[MHUserInfoController alloc] init];
- // userInfo.user = user;
- // [self.navigationController pushViewController:userInfo animated:YES];
- }
- ///评论正文 回复评论在Cell的block里面
- - (void)topicCell:(MHTopicCell *)topicCell didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- MHTopicFrame *topicFrame = topicCell.topicFrame;
- MHCommentFrame *commentFrame = topicFrame.commentFrames[indexPath.row];
- [self replyCommentName:commentFrame.comment.Name andId:commentFrame.comment.Id];
- }
- - (void)replyCommentName:(NSString *)name andId:(NSString *)commentId{
- [_commentInputView startEditing];
- [_commentInputView setPlaceText:[NSString stringWithFormat:@"回复%@:",name]];
- WEAKSELF
- self.commentInputView.inputBlock = ^(NSString * _Nonnull content) {
- NSLog(@"%@",content);
- [weakSelf replyCommentWithcontent:content andId:commentId];
- };
- }
- - (void)replyCommentWithcontent:(NSString *)content andId:(NSString *)commentId
- {
- if (content.length < 1) {
- SHOWERROR(@"请输入评论");
- return;
- }
- SHOWLOADING
- WS(weakSelf);
- //@{@"ArticleId":@(self.currentModel.Id),@"Content":content,@"UserId":@([AppUserModel sharedAppUserModel].Id),@"Pid":commentId,@"TypeValue":@"0"}
- [[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) {
- SHOWSUCCESS(@"评论楼主成功");
- [weakSelf getConmmtenData];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR(@"评论楼主失败");
- }];
- }
- #pragma mark - 点击已阅读数代理
- - (void)didDetailTitlefunctionTouch:(TDButton *)button{
- NoticeUnreadVC *vc = [NoticeUnreadVC initNoticeUnreadVC];
- [self.navigationController pushViewController:vc animated:YES];
- }
- #pragma mark - setter
- - (UIView *)scrollView {
- if (!_scrollView) {
- _scrollView = [[UIView alloc] init];
- }
- return _scrollView;
- }
- - (DetailTitleView *)titleView {
- if (!_titleView) {
- _titleView = [[DetailTitleView alloc] init];
- _titleView.backgroundColor = [UIColor whiteColor];
- _titleView.delegate = self;
- }
- return _titleView;
- }
- - (DetailContentView *)textContentView{
- if(!_textContentView){
- _textContentView = [[DetailContentView alloc]init];
- }
- return _textContentView;
- }
- - (TDTableView *)tableView {
- if (!_tableView) {
- _tableView = [[TDTableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.dataSource = self;
- _tableView.delegate = self;
- }
- return _tableView;
- }
- - (HomeCommentView *)commentView {
- if (!_commentView) {
- _commentView = [HomeCommentView shareView];
- }
- return _commentView;
- }
- - (TextInputView *)commentInputView
- {
- if (!_commentInputView) {
- _commentInputView = [[TextInputView alloc] initWithFrame:[UIScreen mainScreen].bounds];
- }
- return _commentInputView;
- }
- - (ClickOKView *)zanView{
- if(!_zanView){
- _zanView = [[ClickOKView alloc] init];
- // _zanView.delegate = self;
- }
- return _zanView;
- }
- - (TDNavigationBar *)myNavigationBar{
- if (!_myNavigationBar) {
- _myNavigationBar = [[TDNavigationBar alloc] initNavigationBar];
- _myNavigationBar.backgroundColor = [UIColor whiteColor];
- _myNavigationBar.delegate = self;
- _myNavigationBar.backButton2.hidden = NO;
- [_myNavigationBar.backButton2 setImage:IMG(@"menu_black_icon") forState:UIControlStateNormal];
- [_myNavigationBar setTitle:@"正文"];
- }
- return _myNavigationBar;
- }
- - (void)backButtonAction{
- [self back];
- }
- - (void)backButtonAction2:(TDButton *)sender{
- [self secondBarButtonItems];
- }
- - (void)rightButtonAction:(TDButton *)sender{
- [self secondBarButtonItems];
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
-
- }
- - (DrawerView *)drawerView{
- if (!_drawerView) {
- _drawerView = [[DrawerView alloc]init];
- }
- return _drawerView;
- }
- - (NSMutableArray *)dataArr{
- if (!_dataArr) {
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- - (Item *)currentModel {
- if (!_currentModel) {
- _currentModel = [Item new];
- }
- return _currentModel;
- }
- #pragma mark -转发
- - (void)shareHander{
- [self.noteBookShareVC initNoteBookShareData];
- self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
- }
- - (NoteBookShareVC *)noteBookShareVC{
- if (_noteBookShareVC == nil) {
- _noteBookShareVC = [NoteBookShareVC initNoteBookShareVC];
- [_noteBookShareVC.view setFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- [_noteBookShareVC.view setHidden:YES];
- _noteBookShareVC.delegate = self;
- }
- return _noteBookShareVC;
- }
- -(void)userSelectType:(NSString *)typeName WithIndexPath:(NSIndexPath *)indexPath{
- self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
- if ([typeName isEqualToString:@"发给微信好友"]) {
-
- }else if ([typeName isEqualToString:@"发到朋友圈"]){
-
- }else if ([typeName isEqualToString:@"发到微博"]){
-
- }else if ([typeName isEqualToString:@"发给QQ好友"]){
-
- }else if ([typeName isEqualToString:@"发到消息"]){
-
- }else if ([typeName isEqualToString:@"发到小组"]){
- [self returnToGroup];
- }else if ([typeName isEqualToString:@"发到笔记"]){
- [self returnToNote];
- }else if ([typeName isEqualToString:@"发到话题"]){
- [self returnToTopic];
- }else{
- }
- }
- - (void)returnToGroup
- {
- MyTDGroupViewController * vc = [[MyTDGroupViewController alloc] init];
- vc.type = CollectModel_Group;
- FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
- model.SoureId = self.currentModel.Id;
- model.SoureTypeId = CollectModel_Aritle;
- model.Title = self.currentModel.Title;
- model.Author = self.currentModel.Author;
- vc.sendModel = model;
- vc.isReturn = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)returnToNote
- {
- MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
- vc.type = CollectModel_NoteBook;
- FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
- model.SoureId = self.currentModel.Id;
- model.SoureTypeId = CollectModel_Aritle;
- model.Title = self.currentModel.Title;
- model.Author = self.currentModel.Author;
- vc.sendModel = model;
- vc.isReturn = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)returnToTopic
- {
- MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
- vc.type = CollectModel_NewTopic;
- FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
- model.SoureId = self.currentModel.Id;
- model.SoureTypeId = CollectModel_Aritle;
- model.Title = self.currentModel.Title;
- model.Author = self.currentModel.Author;
- vc.sendModel = model;
- vc.isReturn = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)scrollToCommentViewTop
- {
- if (self.isScrComment) {
- if (self.dataArr.count > 0 || self.goodsSource.count > 0) {
- [self.tableView scrollToRow:0 inSection:1 atScrollPosition:UITableViewScrollPositionTop animated:YES];
- }
- }else{
- [self.tableView scrollToTop];
- }
- }
- - (void)ShareDetail{
- SHOWLOADING
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:@(self.currentModel.Id) forKey:@"SourceId"];
- [dic setValue:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"];
- [dic setValue:@(4) forKey:@"AnalyzeType"];///转发
- [dic setValue:@(0) forKey:@"CommentId"];
- [dic setValue:@(0) forKey:@"TypeValue"];///0文章
- WS(weakSelf);
- [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Analyze_Set) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
- REMOVESHOW
- [weakSelf refreshBottomData];
- [weakSelf shareHander];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- // SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- - (void)refreshBottomData
- {
- WEAKSELF
- [[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) {
- REMOVESHOW
- weakSelf.currentModel = [Item modelWithDictionary:responseObject];
- //设置收藏等数量以及状态
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf setBottomViewData:weakSelf.currentModel];
- });
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- - (void)refreshCommentData
- {
- WEAKSELF
- [[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) {
- REMOVESHOW
- weakSelf.currentModel = [Item modelWithDictionary:responseObject];
- //设置收藏等数量以及状态
- [weakSelf.dataArr removeAllObjects];
- WEAKSELF
- [[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) {
- if ([responseObject[@"Items"] isKindOfClass:[NSArray class]]) {
- for (NSDictionary * dict in responseObject[@"Items"]) {
- MHTopic * topic = [MHTopic modelWithDictionary:dict];
- if ([[dict objectForKey:@"TopicCommentReplyResults"] isKindOfClass:[NSArray class]]) {
- NSMutableArray<MHComment *> * subArray = [NSMutableArray<MHComment *> array];
- for (NSDictionary * subDict in dict[@"TopicCommentReplyResults"]) {
- MHComment * commentModel = [MHComment modelWithDictionary:subDict];
- [subArray addObject:commentModel];
- }
- topic.CommentReplyResults = [NSMutableArray<MHComment *> arrayWithArray:subArray];
- }
- [weakSelf.dataArr addObject:[weakSelf _topicFrameWithTopic:topic]];
- }
- weakSelf.lastLabel.hidden = (weakSelf.dataArr.count < 1);
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- [weakSelf setBottomViewData:weakSelf.currentModel];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- weakSelf.isScrComment = YES;
- [weakSelf scrollToCommentViewTop];
- });
- });
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- #pragma mark - 长按删除评论Cell
- - (void)longDeleteSelf:(MHTopicCell *)cell
- {
- [self becomeFirstResponder];
- UIMenuController *menu = [UIMenuController sharedMenuController];
- UIMenuItem *deleteItem = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(deleteItemAction:)];
- [menu setMenuItems: @[deleteItem]];
- NSLog(@"%@",NSStringFromCGRect(cell.frame));
- [menu setTargetRect:cell.contentLabel.frame inView:cell];
- [menu setMenuVisible:YES animated:NO];
- }
- - (void)longDeleteSubCell:(UILabel *)label
- {
- [self becomeFirstResponder];
- UIMenuController *menu = [UIMenuController sharedMenuController];
- UIMenuItem *deleteItem = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(deleteItemAction:)];
- [menu setMenuItems: @[deleteItem]];
- [menu setTargetRect:label.frame inView:label];
- [menu setMenuVisible:YES animated:NO];
- }
- - (BOOL)canBecomeFirstResponder
- {
- return YES;
- }
- - (void)deleteItemAction:(UIMenuItem *)item
- {
- WS(weakSelf);
- SHOWLOADING
- [[HttpManager sharedHttpManager] DeleteUrl:Host(API_APP_Comment_Delete) parameters:@{@"ArticleId":@(self.currentModel.Id),@"CommentId":@(self.commentId)} responseStyle:DATA success:^(id _Nonnull responseObject) {
- REMOVESHOW
- SHOWSUCCESS(@"删除成功");
- [weakSelf refreshCommentData];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- }
- @end
|