HMCommentView.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. //
  2. // HMCommentView.m
  3. // BuguLive
  4. //
  5. // Created by 范东 on 2019/1/2.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "HMCommentView.h"
  9. #import "BGReplyCell.h"
  10. #import "CommentModel.h"
  11. #import "PersonCenterModel.h"
  12. #import "BGReportController.h"
  13. #define kCommentCellID @"HMCommentViewCommentCellID"
  14. #define kCommentViewHeight 400
  15. @interface HMCommentView ()<UITableViewDelegate,UITableViewDataSource,commentDeleGate,UIActionSheetDelegate,UITextFieldDelegate>
  16. @property (nonatomic, strong) UIView *shadowView;
  17. @property (nonatomic, assign) int currentPage; //当前页数
  18. @property (nonatomic, assign) int has_next; //是否还有下一页1代表有
  19. @property (nonatomic, strong) PersonCenterModel *detailModel;
  20. @property (nonatomic, strong) UITextField *commentTextField; //发表评论的输入框
  21. @property (nonatomic, strong) UIButton *sendBtn;
  22. @property (nonatomic, assign) int rowCount;
  23. @property (nonatomic, copy) NSString *comment_id;
  24. @property (nonatomic, assign) BOOL isShowKeyBoard;
  25. @property (nonatomic, strong) UIImageView *bottomView;
  26. @property (nonatomic, strong) UIView *commentShadowView;
  27. @property (nonatomic, copy) operateCommentSuccessBlock operateCommentSuccessBlock;
  28. @end
  29. @implementation HMCommentView
  30. - (instancetype)initWithFrame:(CGRect)frame{
  31. if (self = [super initWithFrame:frame]) {
  32. self.backgroundColor = kWhiteColor;
  33. self.userInteractionEnabled = YES;
  34. UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
  35. swipe.direction = UISwipeGestureRecognizerDirectionDown;
  36. swipe.numberOfTouchesRequired = 1;
  37. [self addGestureRecognizer:swipe];
  38. [self initSubview];
  39. [self keyboardMonitor];//通知
  40. }
  41. return self;
  42. }
  43. - (void)initSubview{
  44. //全部评论
  45. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
  46. titleLabel.font = [UIFont boldSystemFontOfSize:16];
  47. titleLabel.text = ASLocalizedString(@"全部评论");
  48. [self addSubview:titleLabel];
  49. [self addSubview:self.tableView];
  50. [self addSubview:self.bottomView];
  51. self.bottomView.hidden = NO;
  52. UIImageView *pencilImg = [UIImageView new];
  53. [pencilImg setImage:[UIImage imageNamed:@"mg_video_pencil"]];
  54. [self.bottomView addSubview:pencilImg];
  55. //想撩TA,先评论
  56. [self.bottomView addSubview:self.commentTextField];
  57. //发送按钮
  58. [self.bottomView addSubview:self.sendBtn];
  59. //tableView上的细线
  60. UIView *lineView = [[UIView alloc]initWithFrame:CGRectZero];
  61. lineView.backgroundColor = kLightGrayColor;
  62. [self.tableView addSubview:lineView];
  63. //约束
  64. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.equalTo(self).offset(10);
  66. make.top.equalTo(self).offset(10);
  67. }];
  68. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.right.equalTo(self);
  70. make.top.equalTo(self.tableView.mas_top).offset(0);
  71. make.height.mas_equalTo(@(0.5));
  72. }];
  73. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.right.equalTo(self);
  75. make.top.equalTo(titleLabel.mas_bottom).offset(10);
  76. make.height.mas_equalTo(@(kCommentViewHeight - [ASLocalizedString(@"全部评论")textSizeIn:CGSizeMake(MAXFLOAT, MAXFLOAT) font:[UIFont systemFontOfSize:16]].height - 20 - 50));
  77. }];
  78. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.mas_equalTo(19);
  80. make.top.equalTo(self.tableView.mas_bottom).offset(-5);
  81. make.size.mas_equalTo(CGSizeMake(kScreenW - 19 * 2, 50));
  82. // make.bottom.mas_equalTo(-55);
  83. }];
  84. [pencilImg mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.equalTo(self.bottomView).offset(10);
  86. make.size.mas_equalTo(CGSizeMake(23, 21));
  87. make.centerY.equalTo(self.bottomView);
  88. }];
  89. [self.commentTextField mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.equalTo(pencilImg.mas_right).offset(10);
  91. make.bottom.equalTo(self.bottomView).offset(-5);
  92. make.size.mas_equalTo(CGSizeMake(kRealValue(210), 40));
  93. }];
  94. [self.sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.right.equalTo(self.bottomView.mas_right).offset(-10);
  96. make.centerY.equalTo(self.commentTextField.mas_centerY);
  97. make.size.mas_equalTo(CGSizeMake(100, 40));
  98. }];
  99. }
  100. #pragma mark - Data
  101. - (void)setModel:(SmallVideoListModel *)model{
  102. _model = model;
  103. [self loadNetDataWithPage:1];
  104. }
  105. #pragma mark - Show And Hide
  106. - (void)show:(UIView *)superView{
  107. [superView addSubview:self.shadowView];
  108. [superView addSubview:self];
  109. [UIView animateWithDuration:0.25 animations:^{
  110. self.shadowView.alpha = 1;
  111. self.y = kScreenH - kCommentViewHeight;
  112. }];
  113. }
  114. - (void)hide{
  115. [UIView animateWithDuration:0.25 animations:^{
  116. self.shadowView.alpha = 0;
  117. self.y = kScreenH;
  118. } completion:^(BOOL finished) {
  119. [self.shadowView removeFromSuperview];
  120. [self removeFromSuperview];
  121. }];
  122. }
  123. #pragma mark - Refresh
  124. - (void)headerReresh
  125. {
  126. [self loadNetDataWithPage:1];
  127. }
  128. - (void)refresherOfNew
  129. {
  130. if (_has_next == 1)
  131. {
  132. _currentPage ++;
  133. [self loadNetDataWithPage:_currentPage];
  134. }
  135. else
  136. {
  137. [BGMJRefreshManager endRefresh:self.tableView];
  138. }
  139. }
  140. #pragma mark - Data
  141. -(void)loadNetDataWithPage:(int)page
  142. {
  143. NSMutableDictionary *MDict = [NSMutableDictionary new];
  144. [MDict setObject:@"weibo" forKey:@"ctl"];
  145. [MDict setObject:@"index" forKey:@"act"];
  146. [MDict setObject:@"xr" forKey:@"itype"];
  147. if (self.model.weibo_id.length)
  148. {
  149. [MDict setObject:self.model.weibo_id forKey:@"weibo_id"];
  150. }
  151. if (self.model.id.length)
  152. {
  153. [MDict setObject:self.model.id forKey:@"weibo_id"];
  154. }
  155. FWWeakify(self)
  156. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  157. {
  158. FWStrongify(self)
  159. _has_next = [responseJson toInt:@"has_next"];
  160. _currentPage = [responseJson toInt:@"page"];
  161. if (_currentPage == 1)
  162. {
  163. [_dataArray removeAllObjects];
  164. }
  165. if ([responseJson toInt:@"status"]== 1)
  166. {
  167. _detailModel = [PersonCenterModel mj_objectWithKeyValues:responseJson];
  168. //动态
  169. NSArray *comment_listArray = [responseJson objectForKey:@"comment_list"];
  170. if (comment_listArray && [comment_listArray isKindOfClass:[NSArray class]])
  171. {
  172. if (comment_listArray.count)
  173. {
  174. for (NSDictionary *dict in comment_listArray)
  175. {
  176. CommentModel *CModel = [CommentModel mj_objectWithKeyValues:dict];
  177. [self.dataArray addObject:CModel];
  178. }
  179. }
  180. [self.tableView reloadData];
  181. [BGMJRefreshManager endRefresh:self.tableView];
  182. }
  183. }else
  184. {
  185. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  186. }
  187. } FailureBlock:^(NSError *error)
  188. {
  189. [BGMJRefreshManager endRefresh:self.tableView];
  190. FWStrongify(self)
  191. NSLog(@"error==%@",error);
  192. }];
  193. }
  194. #pragma mark - UITableViewDelegate/UITableViewDataSource
  195. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  196. return _dataArray.count;
  197. }
  198. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  199. BGReplyCell *cell = [tableView dequeueReusableCellWithIdentifier:kCommentCellID];
  200. if (_dataArray.count) {
  201. [cell creatCellWithModel:_dataArray[indexPath.row] andRow:indexPath.row];
  202. }
  203. cell.CDelegate = self;
  204. return cell;
  205. }
  206. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  207. BGReplyCell *cell = [tableView dequeueReusableCellWithIdentifier:kCommentCellID];
  208. return [cell creatCellWithModel:_dataArray[indexPath.row] andRow:(int)indexPath.row];
  209. }
  210. #pragma mark - Keyboard
  211. - (void)keyboardMonitor{
  212. //键盘显示时发出通知
  213. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  214. //键盘隐藏时发出
  215. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  216. }
  217. - (void)keyboardWillShow:(NSNotification *)notification{
  218. _isShowKeyBoard = YES;
  219. // 键盘弹出需要的时间
  220. CGFloat animationDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  221. // 取出键盘高度
  222. CGRect keyboardF = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  223. [self insertSubview:self.commentShadowView belowSubview:self.bottomView];
  224. [self.commentShadowView mas_remakeConstraints:^(MASConstraintMaker *make) {
  225. make.left.right.equalTo(self);
  226. make.top.equalTo(self.mas_top);
  227. make.size.mas_equalTo(CGSizeMake(kScreenW, kCommentViewHeight));
  228. }];
  229. // 执行动画
  230. [UIView animateWithDuration:animationDuration animations:^{
  231. self.commentShadowView.alpha = 1;
  232. [_bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
  233. make.top.mas_equalTo(kCommentViewHeight - keyboardF.size.height - 50);
  234. make.left.equalTo(self);
  235. make.size.mas_equalTo(CGSizeMake(kScreenW, 50));
  236. }];
  237. }];
  238. }
  239. - (void)keyboardWillHide:(NSNotification *)notification{
  240. // 键盘弹出需要的时间
  241. CGFloat animationDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  242. [UIView animateWithDuration:animationDuration animations:^{
  243. [_sendBtn setTitle:ASLocalizedString(@"发表评论")forState:UIControlStateNormal];
  244. [_bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
  245. make.left.equalTo(self);
  246. make.top.equalTo(self.tableView.mas_bottom);
  247. make.size.mas_equalTo(CGSizeMake(kScreenW, 50));
  248. }];
  249. [self.commentShadowView mas_remakeConstraints:^(MASConstraintMaker *make) {
  250. make.left.right.equalTo(self);
  251. make.top.equalTo(self.bottomView.mas_bottom);
  252. make.size.mas_equalTo(CGSizeMake(kScreenW, kCommentViewHeight));
  253. }];
  254. self.commentShadowView.alpha = 0;
  255. } completion:^(BOOL finished) {
  256. [self.commentShadowView removeFromSuperview];
  257. }];
  258. }
  259. #pragma mark - commentDeleGate
  260. - (void)commentNewsWithTag:(int)tag{
  261. //
  262. if (!_dataArray.count) {
  263. return;
  264. }
  265. _rowCount = tag;
  266. CommentModel *CModel = _dataArray[tag];
  267. if (_detailModel.user_id >0)
  268. {
  269. if (_detailModel.is_admin)
  270. {
  271. if ([CModel.user_id intValue] == _detailModel.user_id)//如果是自己的评论,且是自己的回复就只有删除取消
  272. {
  273. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  274. [headImgSheet addButtonWithTitle:ASLocalizedString(@"删除")];
  275. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  276. [headImgSheet setTintColor:kAppGrayColor1];
  277. headImgSheet.tag = 0;
  278. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  279. headImgSheet.delegate = self;
  280. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  281. }else//如果是自己的评论,但是是别人的评论就有删除回复取消
  282. {
  283. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  284. [headImgSheet addButtonWithTitle:ASLocalizedString(@"回复")];
  285. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  286. [headImgSheet setTintColor:kAppGrayColor1];
  287. headImgSheet.tag = 2;
  288. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  289. headImgSheet.delegate = self;
  290. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  291. }
  292. }else
  293. {
  294. if ([CModel.user_id intValue] == _detailModel.user_id)//不是自己的评论,是回复别人的评论,只有删除
  295. {
  296. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  297. [headImgSheet addButtonWithTitle:ASLocalizedString(@"删除")];
  298. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  299. [headImgSheet setTintColor:kAppGrayColor1];
  300. headImgSheet.tag = 0;
  301. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  302. headImgSheet.delegate = self;
  303. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  304. }else//不是自己的评论,是别人的评论,只能回复别人的评论
  305. {
  306. _isShowKeyBoard = YES;
  307. // _isShowKeyBoard =! _isShowKeyBoard;
  308. if (_isShowKeyBoard == YES)
  309. {
  310. UIActionSheet *testSheet = [[UIActionSheet alloc] init];
  311. [testSheet bk_addButtonWithTitle:ASLocalizedString(@"回复")handler:^{
  312. [_sendBtn setTitle:ASLocalizedString(@"回复")forState:UIControlStateNormal];
  313. [_commentTextField becomeFirstResponder];
  314. _commentTextField.placeholder = [NSString stringWithFormat:ASLocalizedString(@"回复:%@"),CModel.nick_name];
  315. _comment_id = CModel.comment_id;
  316. }];
  317. [testSheet bk_addButtonWithTitle:ASLocalizedString(@"复制")handler:^{
  318. UIPasteboard * paste = [UIPasteboard generalPasteboard];
  319. paste.string = CModel.content;
  320. [BGHUDHelper alert:ASLocalizedString(@"复制成功")];
  321. }];
  322. [testSheet bk_addButtonWithTitle:ASLocalizedString(@"评论举报")handler:^{
  323. [self goToReportControllerWithTag:3 commentModel:CModel];
  324. // _liveReportV = [[SLiveReportView alloc]initWithFrame:CGRectMake(0,0,kScreenW,kScreenH)];
  325. // _liveReportV.reportDelegate = self;
  326. }];
  327. [testSheet bk_setCancelButtonWithTitle:ASLocalizedString(@"取消") handler:nil];
  328. [testSheet showInView:self];
  329. }else
  330. {
  331. _commentTextField.placeholder = ASLocalizedString(@"说点什么···");
  332. _comment_id = @"";
  333. [self tap];
  334. }
  335. }
  336. }
  337. }
  338. }
  339. - (void)clickNameStringWithTag:(int)tag{
  340. [UIView animateWithDuration:0.25 animations:^{
  341. self.shadowView.alpha = 0;
  342. self.y = kScreenH;
  343. } completion:^(BOOL finished) {
  344. [self.shadowView removeFromSuperview];
  345. [self removeFromSuperview];
  346. CommentModel *CModel = _dataArray[tag];
  347. SHomePageVC *myVC = [[SHomePageVC alloc]init];
  348. myVC.user_id = CModel.user_id;
  349. myVC.type = 0;
  350. [[AppDelegate sharedAppDelegate] pushViewController:myVC animated:YES];
  351. }];
  352. }
  353. #pragma mark - Action
  354. - (void)deleteCommentWithTag:(int)count{
  355. CommentModel *CModel = _dataArray[_rowCount];
  356. NSMutableDictionary *MDict = [NSMutableDictionary new];
  357. [MDict setObject:@"user" forKey:@"ctl"];
  358. [MDict setObject:@"del_comment" forKey:@"act"];
  359. if (CModel.comment_id.length)
  360. {
  361. [MDict setObject:CModel.comment_id forKey:@"comment_id"];
  362. }
  363. [MDict setObject:@"xr" forKey:@"itype"];
  364. FWWeakify(self)
  365. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  366. {
  367. FWStrongify(self)
  368. if ([responseJson toInt:@"status"]== 1)
  369. {
  370. [_dataArray removeObjectAtIndex:_rowCount];
  371. _detailModel.info.comment_count = [NSString stringWithFormat:@"%d",(int)_dataArray.count];
  372. [_tableView reloadData];
  373. //需要告诉上一个页面评论数量
  374. if (self.operateCommentSuccessBlock) {
  375. self.operateCommentSuccessBlock(_detailModel.info.comment_count);
  376. }
  377. }
  378. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  379. } FailureBlock:^(NSError *error)
  380. {
  381. NSLog(@"error==%@",error);
  382. }];
  383. }
  384. - (void)buttonClick{
  385. if (_commentTextField.text.length < 1)
  386. {
  387. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请输入评论的内容")];
  388. return;
  389. }
  390. NSMutableDictionary *MDict = [NSMutableDictionary new];
  391. [MDict setObject:@"user" forKey:@"ctl"];
  392. [MDict setObject:@"publish_comment" forKey:@"act"];
  393. [MDict setObject:@"1" forKey:@"type"];
  394. if (self.model.weibo_id.length)
  395. {
  396. [MDict setObject:self.model.weibo_id forKey:@"weibo_id"];
  397. }
  398. if (_comment_id.length)
  399. {
  400. [MDict setObject:_comment_id forKey:@"to_comment_id"];
  401. }
  402. [MDict setObject:@"xr" forKey:@"itype"];
  403. [MDict setObject:_commentTextField.text forKey:@"content"];
  404. [MDict setObject:_detailModel.info.user_id forKey:@"user_id"];
  405. [self inputViewDown];
  406. FWWeakify(self)
  407. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  408. {
  409. FWStrongify(self)
  410. if ([responseJson toInt:@"status"]== 1)
  411. {
  412. _commentTextField.text = @"";
  413. NSDictionary *commentDict = [responseJson objectForKey:@"comment"];
  414. if (commentDict && [commentDict isKindOfClass:[NSDictionary class]])
  415. {
  416. CommentModel *CModel = [CommentModel mj_objectWithKeyValues:commentDict];
  417. [_dataArray insertObject:CModel atIndex:0];
  418. }
  419. _detailModel.info.comment_count =[NSString stringWithFormat:@"%d",(int)_dataArray.count] ;
  420. [_tableView reloadData];
  421. //需要告诉上一个页面评论数量
  422. if (self.operateCommentSuccessBlock) {
  423. self.operateCommentSuccessBlock(_detailModel.info.comment_count);
  424. }
  425. }else{
  426. [BGHUDHelper alert:[responseJson toString:@"error"]];
  427. }
  428. //
  429. // [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  430. } FailureBlock:^(NSError *error)
  431. {
  432. NSLog(@"error==%@",error);
  433. }];
  434. }
  435. - (void)tap{
  436. _isShowKeyBoard = NO;
  437. [self inputViewDown];
  438. }
  439. - (void)inputViewDown{
  440. _commentTextField.placeholder = ASLocalizedString(@"说点什么···");
  441. _comment_id = @"";
  442. _isShowKeyBoard = NO;
  443. [_commentTextField resignFirstResponder];
  444. }
  445. - (void)goToReportControllerWithTag:(int)tag commentModel:(CommentModel *)model{
  446. [self hide];
  447. BGReportController *reportVC = [[BGReportController alloc]init];
  448. reportVC.weibo_id = _detailModel.info.weibo_id;
  449. reportVC.to_user_id = _detailModel.info.user_id;
  450. reportVC.commentID = model.comment_id;
  451. if (tag == 1)//动态
  452. {
  453. reportVC.reportType = 1;
  454. }else if (tag == 2)
  455. {
  456. reportVC.reportType = 2;
  457. }else if (tag == 3)
  458. {
  459. reportVC.reportType = 3;
  460. }
  461. [[AppDelegate sharedAppDelegate] pushViewController:reportVC animated:YES];
  462. }
  463. - (void)deleteDynamicWithString:(NSString *)string{
  464. NSMutableDictionary *MDict = [NSMutableDictionary new];
  465. [MDict setObject:@"user" forKey:@"ctl"];
  466. [MDict setObject:@"del_weibo" forKey:@"act"];
  467. if (self.model.weibo_id)
  468. {
  469. [MDict setObject:self.model.weibo_id forKey:@"weibo_id"];
  470. }
  471. [MDict setObject:@"xr" forKey:@"itype"];
  472. FWWeakify(self)
  473. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  474. {
  475. FWStrongify(self);
  476. if ([responseJson toInt:@"status"]== 1)
  477. {
  478. }
  479. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  480. } FailureBlock:^(NSError *error)
  481. {
  482. NSLog(@"error==%@",error);
  483. }];
  484. }
  485. #pragma mark UIActionSheetDelegate
  486. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger) buttonIndex{
  487. if (actionSheet.tag == 0)//如果是自己的评论,且是自己的回复就只有删除取消
  488. {
  489. if (buttonIndex == 0)
  490. {
  491. [self deleteCommentWithTag:_rowCount];
  492. }else if (buttonIndex == 1)
  493. {
  494. }
  495. }else if(actionSheet.tag == 1)
  496. {
  497. if (buttonIndex == 0)
  498. {
  499. [self goToReportControllerWithTag:1 commentModel:nil];
  500. }else if (buttonIndex == 1)
  501. {
  502. [self goToReportControllerWithTag:2 commentModel:nil];
  503. }
  504. }else if(actionSheet.tag == 2)
  505. {
  506. if (buttonIndex == 0)
  507. {
  508. _isShowKeyBoard =! _isShowKeyBoard;
  509. if (_isShowKeyBoard == YES)
  510. {
  511. [_sendBtn setTitle:ASLocalizedString(@"回复")forState:UIControlStateNormal];
  512. [_commentTextField becomeFirstResponder];
  513. CommentModel *CModel =_dataArray[_rowCount];
  514. _commentTextField.placeholder = [NSString stringWithFormat:ASLocalizedString(@"回复%@"),CModel.nick_name];
  515. _comment_id = CModel.comment_id;
  516. }else
  517. {
  518. _commentTextField.placeholder = ASLocalizedString(@"说点什么···");
  519. _comment_id = @"";
  520. [self tap];
  521. }
  522. }
  523. }else if(actionSheet.tag == 3)//自己对自己的更多去操作
  524. {
  525. if (buttonIndex == 0)
  526. {
  527. [self deleteDynamicWithString:self.model.weibo_id];
  528. }
  529. }
  530. }
  531. - (void)setOperateCommentSuccessBlock:(operateCommentSuccessBlock)operateCommentSuccessBlock{
  532. _operateCommentSuccessBlock = operateCommentSuccessBlock;
  533. }
  534. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  535. {
  536. [self buttonClick];
  537. return YES;
  538. }
  539. #pragma mark - Lazy Load
  540. - (UITableView *)tableView{
  541. if (!_tableView) {
  542. _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  543. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  544. _tableView.delegate = self;
  545. _tableView.dataSource = self;
  546. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(inputViewDown)];
  547. [_tableView addGestureRecognizer:tap];
  548. _tableView.userInteractionEnabled = YES;
  549. [_tableView registerClass:[BGReplyCell class] forCellReuseIdentifier:kCommentCellID];
  550. [BGMJRefreshManager refresh:_tableView target:self headerRereshAction:@selector(headerReresh) footerRereshAction:@selector(refresherOfNew)];
  551. }
  552. return _tableView;
  553. }
  554. - (UIView *)shadowView{
  555. if (!_shadowView) {
  556. _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  557. _shadowView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.5];
  558. _shadowView.alpha = 0;
  559. _shadowView.userInteractionEnabled = YES;
  560. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
  561. [_shadowView addGestureRecognizer:tap];
  562. }
  563. return _shadowView;
  564. }
  565. - (NSMutableArray *)dataArray{
  566. if (!_dataArray) {
  567. _dataArray = [[NSMutableArray alloc]init];
  568. }
  569. return _dataArray;
  570. }
  571. - (UITextField *)commentTextField{
  572. if (!_commentTextField) {
  573. _commentTextField = [[UITextField alloc]initWithFrame:CGRectZero];
  574. _commentTextField.userInteractionEnabled = YES;
  575. _commentTextField.layer.cornerRadius = 3;
  576. // _commentTextField.leftViewMode = UITextFieldViewModeAlways;
  577. // _commentTextField.backgroundColor = kBackGroundColor;
  578. _commentTextField.textColor = kBlackColor;
  579. // RGB(153, 153, 153);
  580. _commentTextField.textAlignment = NSTextAlignmentLeft;
  581. _commentTextField.font = [UIFont systemFontOfSize:12];
  582. _commentTextField.delegate = self;
  583. _commentTextField.placeholder = ASLocalizedString(@"说点什么···");
  584. _commentTextField.returnKeyType = UIReturnKeySend;
  585. // UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0,0,10,40)];
  586. // leftView.backgroundColor = kClearColor;
  587. // _commentTextField.leftView = leftView;
  588. // _commentTextField.leftViewMode = UITextFieldViewModeAlways;
  589. // _commentTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  590. }
  591. return _commentTextField;
  592. }
  593. - (UIButton *)sendBtn{
  594. if (!_sendBtn) {
  595. _sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(kScreenW-110, 5, 100, 40)];
  596. _sendBtn.layer.cornerRadius = 3;
  597. _sendBtn.backgroundColor = kAppMainColor;
  598. [_sendBtn setTitle:ASLocalizedString(@"发表评论")forState:UIControlStateNormal];
  599. [_sendBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  600. [_sendBtn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
  601. _sendBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  602. _sendBtn.hidden = YES;
  603. }
  604. return _sendBtn;
  605. }
  606. - (UIImageView *)bottomView{
  607. if (!_bottomView) {
  608. _bottomView = [[UIImageView alloc]initWithFrame:CGRectZero];
  609. _bottomView.backgroundColor = kWhiteColor;
  610. _bottomView.userInteractionEnabled = YES;
  611. _bottomView.image = [UIImage imageNamed:@"mg_video_comment"];
  612. }
  613. return _bottomView;
  614. }
  615. - (UIView *)commentShadowView{
  616. if (!_commentShadowView) {
  617. _commentShadowView = [[UIView alloc]initWithFrame:CGRectZero];
  618. _commentShadowView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.2];
  619. _commentShadowView.alpha = 0;
  620. _commentShadowView.userInteractionEnabled = YES;
  621. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
  622. [_commentShadowView addGestureRecognizer:tap];
  623. }
  624. return _commentShadowView;
  625. }
  626. - (void)dealloc
  627. {
  628. [[NSNotificationCenter defaultCenter]removeObserver:self];
  629. }
  630. /*
  631. // Only override drawRect: if you perform custom drawing.
  632. // An empty implementation adversely affects performance during animation.
  633. - (void)drawRect:(CGRect)rect {
  634. // Drawing code
  635. }
  636. */
  637. @end