123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- //
- // JXCustomerChatListVc.m
- // shiku_im
- //
- // Created by 123 on 2020/6/8.
- // Copyright © 2020 Reese. All rights reserved.
- //
- #import "JXCustomerChatListVc.h"
- #import "JXCustomerChatListCell.h"
- #import "SaveOrReadArr.h"
- @interface JXCustomerChatListVc ()<UITableViewDataSource,UITableViewDelegate,webViewCellDelegate>
- @property (nonatomic,strong) UITableView *tableview;
- @property (nonatomic,strong) NSMutableArray *dataArr;
-
- @property (nonatomic,strong) NSMutableDictionary *cellHDic;
- @end
- @implementation JXCustomerChatListVc
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationItem.title=@"即信客服";
- [self defineNavBar:@"系统消息" andRinghtBtnImg:@""];
- _dataArr=[NSMutableArray array];
-
- self.cellHDic = [NSMutableDictionary dictionary];
-
- self.view.backgroundColor = kRGBColor(237, 243, 252);
- /// 存放所有cell里webview高度的字典
- self.cellHDic = [NSMutableDictionary dictionary];
- 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];
- self.tableview.backgroundColor=kRGBColor(237, 243, 252);
- [self.view addSubview:self.tableview];
- self.tableview.delegate = self;
- self.tableview.dataSource = self;
- self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.tableview.contentInset=UIEdgeInsetsMake(0, 0, 10, 0);
- /// 防止tableview不停刷新的状态
- [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"reload"];
- [self loadData];
- }
- - (void)loadData{
-
-
- NSMutableArray *personArr = [SaveOrReadArr initNSKeyedUnarchiverHuiLv];
- self.dataArr = personArr;
- if (personArr.count>=8) {
- NSArray *smallArray = [personArr subarrayWithRange:NSMakeRange(personArr.count-7, 7)];
- self.dataArr = smallArray.mutableCopy;
- }
-
-
- [self.tableview reloadData];
-
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.dataArr.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%ld%ld", [indexPath section], [indexPath row]];
- JXCustomerChatListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (!cell) {
- cell = [[JXCustomerChatListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- }
- cell.backgroundColor = [UIColor clearColor];
- cell.delegate = self;
- chatListModel *dic = self.dataArr[indexPath.row];
- [cell refreshWebView:dic indexPath:indexPath.row];
-
- if (indexPath.row==_dataArr.count-1) {
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:_dataArr.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:NO];
- });
- }
-
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return [self.cellHDic[[NSString stringWithFormat:@"%ld",indexPath.row]] floatValue];
- }
- - (void)webViewDidFinishLoad:(CGFloat)webHeight cellIndex:(NSInteger)index{
- [self.cellHDic setValue:[NSString stringWithFormat:@"%f",webHeight+60] forKey:[NSString stringWithFormat:@"%ld",index]];
- /// 防止一直刷新 只有字典中的元素个数和tableviewcell个数相同时才刷新tableview
- if (self.cellHDic.count==self.dataArr.count) {
- /// 通过NSUserDefaults 存的一个状态让tableview只刷新一次
- if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"reload"] isEqualToString:@"0"]) {
- NSArray *paths = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:index inSection:0],nil];
- [self.tableview reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
-
- [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"reload"];
- }
- }
- }
-
- // -------------------服务器返回数据--------------------
- -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
- [SVProgressHUD dismiss];
- if ([aDownload.action isEqualToString:act_fuwenBenGetAllt])
- {
-
- _dataArr=[chatListModel mj_objectArrayWithKeyValuesArray:array1];
- NSMutableArray *arrxx=[[NSMutableArray alloc]initWithArray:[SaveOrReadArr initNSKeyedUnarchiverHuiLv]];
- //本地存储
- [arrxx addObjectsFromArray:[_dataArr copy]];
- [SaveOrReadArr initSerializationArrayHuiLv:arrxx];
-
-
-
-
-
- [self.tableview reloadData];
-
- }
- }
- -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
- [SVProgressHUD dismiss];
- NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
- if([errorCode isEqualToString:@"权限验证失败"])
- {
- if ([aDownload.action isEqualToString:act_fuwenBenGetAllt])
- {
-
-
- }
- }
-
- return [errorCode intValue];
- }
- @end
|