BGConversationTradeController.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. //
  2. // BGConversationTradeController.m
  3. // BuguLive
  4. //
  5. // Created by 朱庆彬 on 2017/8/23.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BGConversationTradeController.h"
  9. #import "ChatTradeCell.h"
  10. #import "IMModel.h"
  11. @interface BGConversationTradeController () <UITableViewDelegate, UITableViewDataSource>
  12. @end
  13. @implementation BGConversationTradeController
  14. {
  15. int _select; //1.交易 2.好友 3.未关注
  16. NetHttpsManager *_httpManager;
  17. int _has_next; //是否还有下一页
  18. int _page; //页数
  19. int _flag;
  20. }
  21. - (void)viewWillAppear:(BOOL)animated
  22. {
  23. [super viewWillAppear:animated];
  24. [self.navigationController setNavigationBarHidden:YES animated:NO];
  25. }
  26. - (void)dealloc
  27. {
  28. [[NSNotificationCenter defaultCenter] removeObserver:self];
  29. }
  30. - (void)viewDidLoad
  31. {
  32. _select = 1;
  33. _flagArr = NSMutableArray.new;
  34. _conversationArr = NSMutableArray.new;
  35. _httpManager = [NetHttpsManager manager];
  36. self.mTableView = [[UITableView alloc] initWithFrame:CGRectZero];
  37. self.mTableView.delegate = self;
  38. self.mTableView.dataSource = self;
  39. self.mTableView.backgroundColor = kBackGroundColor;
  40. [self.view addSubview:self.mTableView];
  41. self.mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  42. [self.mTableView registerNib:[UINib nibWithNibName:@"ChatTradeCell" bundle:nil] forCellReuseIdentifier:@"ChatTradeCell"];
  43. [BGMJRefreshManager refresh:self.mTableView target:self headerRereshAction:@selector(headerStartRefresh) footerRereshAction:@selector(footerStartRefresh)];
  44. }
  45. - (void)updateTableViewFrame
  46. {
  47. CGFloat tableViewHeight;
  48. if (!self.isHaveLive)
  49. {
  50. tableViewHeight = kScreenH - 64;
  51. }
  52. else
  53. {
  54. tableViewHeight = kScreenH / 2 - 44;
  55. }
  56. [self.mTableView setFrame:CGRectMake(0, 0, kScreenW, tableViewHeight)];
  57. }
  58. - (void)headerStartRefresh
  59. {
  60. [self.mTableView reloadData];
  61. [self loadDataWithPage:1];
  62. }
  63. - (void)footerStartRefresh
  64. {
  65. if (_has_next == 1)
  66. {
  67. _page++;
  68. [self loadDataWithPage:_page];
  69. }
  70. else
  71. {
  72. [BGMJRefreshManager endRefresh:self.mTableView];
  73. return;
  74. }
  75. }
  76. #pragma mark--------------------------网络请求----------------------------
  77. - (void)loadDataWithPage:(int)page
  78. {
  79. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  80. [parmDict setObject:@"message" forKey:@"ctl"];
  81. [parmDict setObject:@"getlist" forKey:@"act"];
  82. [parmDict setObject:[NSString stringWithFormat:@"%d", page] forKey:@"p"];
  83. [_httpManager POSTWithParameters:parmDict
  84. SuccessBlock:^(NSDictionary *responseJson) {
  85. if ([responseJson toInt:@"status"] == 1)
  86. {
  87. NSDictionary *dataDic = [responseJson objectForKey:@"data"];
  88. NSMutableArray *dataArr = NSMutableArray.new;
  89. dataArr = dataDic[@"list"];
  90. NSDictionary *pageDic = dataDic[@"page"];
  91. _has_next = [pageDic toInt:@"has_next"];
  92. _page = [pageDic toInt:@"page"];
  93. if (_page == 1)
  94. {
  95. [_conversationArr removeAllObjects];
  96. [_flagArr removeAllObjects];
  97. }
  98. if (dataArr.count > 0)
  99. {
  100. for (NSDictionary *dic in dataArr)
  101. {
  102. IMModel *model = [IMModel mj_objectWithKeyValues:dic];
  103. [_conversationArr addObject:model];
  104. [_flagArr addObject:@"0"];
  105. }
  106. }
  107. else
  108. {
  109. [self showNoContentView];
  110. if (_isHaveLive)
  111. {
  112. self.noContentView.center = CGPointMake(self.view.frame.size.width/2, 87.5+40);
  113. }
  114. }
  115. }
  116. [BGMJRefreshManager endRefresh:self.mTableView];
  117. [self.mTableView reloadData];
  118. }
  119. FailureBlock:^(NSError *error) {
  120. [self showNoContentView];
  121. [BGMJRefreshManager endRefresh:self.mTableView];
  122. }];
  123. }
  124. #pragma mark----------------------tableView的协议方法------------------------
  125. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  126. {
  127. return _conversationArr.count;
  128. }
  129. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  130. {
  131. if (indexPath.row < _flagArr.count)
  132. {
  133. if ([_flagArr[indexPath.row] isEqualToString:@"0"])
  134. {
  135. return 60.0f;
  136. }
  137. else
  138. {
  139. if (indexPath.row < _conversationArr.count)
  140. {
  141. IMModel *model = _conversationArr[indexPath.row];
  142. CGFloat height = [model getHeight:model.content];
  143. return height;
  144. }
  145. }
  146. }
  147. return 60.0f;
  148. }
  149. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  150. {
  151. IMModel *model = _conversationArr[indexPath.row];
  152. NSString *CellIdentifier = @"ChatTradeCell";
  153. ChatTradeCell *cell = (ChatTradeCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  154. if (cell == nil)
  155. {
  156. cell = (ChatTradeCell *) [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] lastObject];
  157. }
  158. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  159. if (model.send_user_name.length > 11)
  160. {
  161. cell.mname.text = [NSString stringWithFormat:@"%@...", [model.send_user_name substringToIndex:11]];
  162. }
  163. else
  164. {
  165. cell.mname.text = model.send_user_name;
  166. }
  167. [cell.mheadimg sd_setImageWithURL:[NSURL URLWithString:model.send_user_avatar] placeholderImage:kDefaultPreloadHeadImg];
  168. cell.mmsg.text = model.content;
  169. [cell judge:cell.mmsg.text];
  170. cell.mtime.text = model.create_date;
  171. if (indexPath.row < _flagArr.count)
  172. {
  173. if ([cell judge:cell.mmsg.text] > 17)
  174. {
  175. cell.contentFlag = _flagArr[indexPath.row];
  176. }
  177. }
  178. return cell;
  179. }
  180. #pragma mark 点击单元格的方法
  181. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  182. {
  183. [self handleSelectedCell:indexPath];
  184. }
  185. - (void)handleSelectedCell:(NSIndexPath *)indexPath
  186. {
  187. if (indexPath.section == 0)
  188. {
  189. if ([_flagArr[indexPath.row] isEqualToString:@"0"])
  190. {
  191. [_flagArr replaceObjectAtIndex:indexPath.row withObject:@"1"];
  192. }
  193. else
  194. {
  195. [_flagArr replaceObjectAtIndex:indexPath.row withObject:@"0"];
  196. }
  197. [self.mTableView reloadData];
  198. }
  199. }
  200. - (void)didReceiveMemoryWarning
  201. {
  202. [super didReceiveMemoryWarning];
  203. // Dispose of any resources that can be recreated.
  204. }
  205. /*
  206. #pragma mark - Navigation
  207. // In a storyboard-based application, you will often want to do a little preparation before navigation
  208. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  209. // Get the new view controller using [segue destinationViewController].
  210. // Pass the selected object to the new view controller.
  211. }
  212. */
  213. @end