// // IfishKanHuGuanLiViewController.m // Ifish // // Created by imac on 17/2/16. // Copyright © 2017年 lianlian. All rights reserved. // #import "IfishKanHuGuanLiViewController.h" #import "JHRefresh.h" #import "ShopKanHuP2PViewController.h" #import "NIMKit.h" #import "IfishSessionViewController.h" #import "KanHuGuanLi1ViewCell.h" #import "KanHuGuanLiPictureViewCell.h" @interface IfishKanHuGuanLiViewController () { BOOL _isRefreshing; BOOL _isLoadMore; NSIndexPath * _chatSelectIndex; } @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,copy) NSString* total; @property(nonatomic,strong) NSMutableArray *kanHuListArr; @property(nonatomic)BOOL isRefreshing; @property(nonatomic)BOOL isLoadMore; @property(nonatomic) int page; @end @implementation IfishKanHuGuanLiViewController - (void)viewDidLoad { [super viewDidLoad]; [self addTitleViewWithTitle:@"看护管理"]; // Do any additional setup after loading the view. self.kanHuListArr =[NSMutableArray new]; [self creatUI]; [self getKanHuList]; } -(void)creatUI{ self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.showsVerticalScrollIndicator = NO; self.tableView.backgroundColor = TABLE_BACKGROUD_COLOR; [self.view addSubview:self.tableView]; self.automaticallyAdjustsScrollViewInsets = YES; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 2; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return self.kanHuListArr.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ KanHuListModel *model = self.kanHuListArr[indexPath.section]; if (indexPath.row ==0) { KanHuGuanLi1ViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KanHuGuanLi1ViewCell"]; if (!cell) { cell = [[[NSBundle mainBundle]loadNibNamed:@"KanHuGuanLi1ViewCell" owner:self options:nil]lastObject]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; [cell loadListData:model]; [cell.chatBtn addTarget:self action:@selector(chatBtnAction:) forControlEvents:UIControlEventTouchUpInside]; cell.chatBtn.tag = indexPath.section; return cell; }else if (indexPath.row ==1){ KanHuGuanLiPictureViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KanHuGuanLiPictureViewCell"]; if (!cell) { cell = [[[NSBundle mainBundle]loadNibNamed:@"KanHuGuanLiPictureViewCell" owner:self options:nil]lastObject]; } NSString *filePath = [Utils getHeaderFilePathWithId:model.cameraId]; UIImage *headImg = [UIImage imageWithContentsOfFile:filePath]; if(headImg==nil){ cell.shotImg.image = LXImageWithImageName(@"ic_header.png"); }else{ cell.shotImg.image = headImg; } //cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } return nil; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.1; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section ==0) { return 5.0f; }else{ return 10.0f; } } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row ==0) { return 60.0; } //return 180.0; return self.view.frame.size.width * 0.56; } //- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath //{ // return UITableViewAutomaticDimension; // //} -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (indexPath.row ==0) { return; } KanHuListModel *kanHuCamera = self.kanHuListArr[indexPath.section]; ShopKanHuP2PViewController *shopP2pVC=[[ShopKanHuP2PViewController alloc]init]; shopP2pVC.kanHuCamera = kanHuCamera; [self.navigationController pushViewController:shopP2pVC animated:YES]; } #pragma mark - 获取看护列表 -(void)getKanHuList{ [self.kanHuListArr removeAllObjects]; UserModel*umodel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"]; NSString*userId=[NSString stringWithFormat:@"%@",umodel.userId]; __weak typeof (self)weskSelf=self; [AFNOHeaderHttpTool getKanHuListWithShopsId:userId firstResult:@"0" pageSize:@"10" success:^(id response) { NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSLog(@"*-*-*--*总共的条数%@",resultDic[@"total"]); _total = resultDic[@"total"]; NSArray *arr = resultDic[@"data"]; for (NSDictionary *dict in arr) { KanHuListModel *listmodel = [[KanHuListModel alloc] init]; listmodel.userId = dict[@"userId"]; listmodel.nickName = dict[@"nickName"]; listmodel.cameraId = dict[@"cameraId"]; listmodel.userImg = dict[@"userImg"]; [weskSelf.kanHuListArr addObject:listmodel]; } if (weskSelf.kanHuListArr.count!=0) { [weskSelf.tableView reloadData]; }else{ [weskSelf creatNoDataView]; } } failure:^(NSError *err) { }]; } -(void)creatNoDataView{ UIView*holdView =[[UIView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)]; holdView.backgroundColor = TABLE_BACKGROUD_COLOR; [self.view addSubview:holdView]; UIImageView *backImg = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 98/2 ,self.view.frame.size.height/4, 108, 98)]; backImg.image = [UIImage imageNamed:@"nurse_empty_picture"]; [holdView addSubview:backImg]; UILabel *title=[[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(backImg.frame) + 30, self.view.frame.size.width,20)]; title.text = @"这里空空如也"; title.textAlignment = NSTextAlignmentCenter; title.font =[UIFont systemFontOfSize:15]; title.textColor = RGB(51, 51, 51); [holdView addSubview:title]; UILabel *title2=[[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(title.frame) + 7, self.view.frame.size.width,20)]; title2.text = @"还没有用户让您看护哟"; title2.font =[UIFont systemFontOfSize:12]; title2.textAlignment = NSTextAlignmentCenter; title2.textColor = RGB(153, 153, 153); [holdView addSubview:title2]; [self.view bringSubviewToFront:holdView]; } -(void)creatReatRefreshView{ __weak typeof (self)weskSelf=self; // 下拉刷新 [weskSelf.tableView addRefreshHeaderViewWithAniViewClass:[JHRefreshAmazingAniView class] beginRefresh:^{ if (weskSelf.isRefreshing) { return ; } weskSelf.isRefreshing=YES; _page=0; [weskSelf addTaskWithFirst:@"0" addpageSize:@"10" isRefresh:YES]; }]; //上拉加载更多 [weskSelf.tableView addRefreshFooterViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{ if (weskSelf.isLoadMore) { return ; } weskSelf.isLoadMore=YES; NSInteger pagecount =[_total integerValue]/10+1; if (_page