JXCustomerChatListVc.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // JXCustomerChatListVc.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/6/8.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXCustomerChatListVc.h"
  9. #import "JXCustomerChatListCell.h"
  10. #import "SaveOrReadArr.h"
  11. @interface JXCustomerChatListVc ()<UITableViewDataSource,UITableViewDelegate,webViewCellDelegate>
  12. @property (nonatomic,strong) UITableView *tableview;
  13. @property (nonatomic,strong) NSMutableArray *dataArr;
  14. @property (nonatomic,strong) NSMutableDictionary *cellHDic;
  15. @end
  16. @implementation JXCustomerChatListVc
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.navigationItem.title=@"即信客服";
  20. [self defineNavBar:@"系统消息" andRinghtBtnImg:@""];
  21. _dataArr=[NSMutableArray array];
  22. self.cellHDic = [NSMutableDictionary dictionary];
  23. self.view.backgroundColor = kRGBColor(237, 243, 252);
  24. /// 存放所有cell里webview高度的字典
  25. self.cellHDic = [NSMutableDictionary dictionary];
  26. self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-JX_SCREEN_TOP) style:UITableViewStylePlain];
  27. self.tableview.backgroundColor=kRGBColor(237, 243, 252);
  28. [self.view addSubview:self.tableview];
  29. self.tableview.delegate = self;
  30. self.tableview.dataSource = self;
  31. self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
  32. self.tableview.contentInset=UIEdgeInsetsMake(0, 0, 10, 0);
  33. /// 防止tableview不停刷新的状态
  34. [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"reload"];
  35. [self loadData];
  36. }
  37. - (void)loadData{
  38. NSMutableArray *personArr = [SaveOrReadArr initNSKeyedUnarchiverHuiLv];
  39. self.dataArr = personArr;
  40. if (personArr.count>=8) {
  41. NSArray *smallArray = [personArr subarrayWithRange:NSMakeRange(personArr.count-7, 7)];
  42. self.dataArr = smallArray.mutableCopy;
  43. }
  44. [self.tableview reloadData];
  45. }
  46. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  47. return self.dataArr.count;
  48. }
  49. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  50. NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%ld%ld", [indexPath section], [indexPath row]];
  51. JXCustomerChatListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  52. if (!cell) {
  53. cell = [[JXCustomerChatListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  54. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  55. }
  56. cell.backgroundColor = [UIColor clearColor];
  57. cell.delegate = self;
  58. chatListModel *dic = self.dataArr[indexPath.row];
  59. [cell refreshWebView:dic indexPath:indexPath.row];
  60. if (indexPath.row==_dataArr.count-1) {
  61. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  62. [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:_dataArr.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:NO];
  63. });
  64. }
  65. return cell;
  66. }
  67. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  68. return [self.cellHDic[[NSString stringWithFormat:@"%ld",indexPath.row]] floatValue];
  69. }
  70. - (void)webViewDidFinishLoad:(CGFloat)webHeight cellIndex:(NSInteger)index{
  71. [self.cellHDic setValue:[NSString stringWithFormat:@"%f",webHeight+60] forKey:[NSString stringWithFormat:@"%ld",index]];
  72. /// 防止一直刷新 只有字典中的元素个数和tableviewcell个数相同时才刷新tableview
  73. if (self.cellHDic.count==self.dataArr.count) {
  74. /// 通过NSUserDefaults 存的一个状态让tableview只刷新一次
  75. if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"reload"] isEqualToString:@"0"]) {
  76. NSArray *paths = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:index inSection:0],nil];
  77. [self.tableview reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
  78. [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"reload"];
  79. }
  80. }
  81. }
  82. // -------------------服务器返回数据--------------------
  83. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  84. [SVProgressHUD dismiss];
  85. if ([aDownload.action isEqualToString:act_fuwenBenGetAllt])
  86. {
  87. _dataArr=[chatListModel mj_objectArrayWithKeyValuesArray:array1];
  88. NSMutableArray *arrxx=[[NSMutableArray alloc]initWithArray:[SaveOrReadArr initNSKeyedUnarchiverHuiLv]];
  89. //本地存储
  90. [arrxx addObjectsFromArray:[_dataArr copy]];
  91. [SaveOrReadArr initSerializationArrayHuiLv:arrxx];
  92. [self.tableview reloadData];
  93. }
  94. }
  95. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  96. [SVProgressHUD dismiss];
  97. NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
  98. if([errorCode isEqualToString:@"权限验证失败"])
  99. {
  100. if ([aDownload.action isEqualToString:act_fuwenBenGetAllt])
  101. {
  102. }
  103. }
  104. return [errorCode intValue];
  105. }
  106. @end