ifish/Ifish/controllers/IfishTabControllers/探索/lookafterWorkbech/WorkbechViewController.m

487 lines
14 KiB
Objective-C

//
// WorkbechViewController.m
// Ifish
//
// Created by imac on 16/8/24.
// Copyright © 2016年 lianxiang. All rights reserved.
//
#import "WorkbechViewController.h"
#import "KanHuWorkViewFirstCell.h"
#import "KanHuWorkViewSecondCell.h"
#import "KanHuWorkHeaderViewCell.h"
#import "ShopEditViewController.h"
#import "KanHuListModel.h"
#import "shopNoCumtomerViewCell.h"
#import "JHRefresh.h"
#import "ShopKanHuP2PViewController.h"
#import "KanHuViewLastCell.h"
#import "NIMKit.h"
#import "IfishSessionViewController.h"
@interface WorkbechViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
{
BOOL _isRefreshing;
BOOL _isLoadMore;
NSIndexPath * _chatSelectIndex;
}
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong) NSArray *myCameraArr;
@property(nonatomic,copy) NSString* total;
@property(nonatomic,strong) NSMutableArray *kanHuListArr;
@property(nonatomic)BOOL isRefreshing;
@property(nonatomic)BOOL isLoadMore;
@property(nonatomic) int page;
@end
@implementation WorkbechViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.kanHuListArr = [[NSMutableArray alloc] init];
//self.title = @"看护工作台";
[self addTitleViewWithTitle:@"看护工作台"];
[self setUI];
[self creatReatRefreshView];
[self getKanHuList];
}
-(void)viewWillAppear:(BOOL)animated{
self.shopsInfo = [[DataCenter defaultDtacenter] valueForKeyPath:@"ShopsInfo"];
[self.tableView reloadData];
}
//重写返回事件 此界面 可能认证成功进入(老版本入口在主页新版不需要)
-(void)goBackAction{
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setUI{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStylePlain];
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];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (self.kanHuListArr.count!=0) {
return 2 + self.kanHuListArr.count + 1;
}
return 3;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 0) {
KanHuWorkViewFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KanHuWorkViewFirstCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"KanHuWorkViewFirstCell" owner:self options:nil]lastObject];
}
[cell.bianJIBtn addTarget:self action:@selector(bianJiBtnAction:) forControlEvents:UIControlEventTouchUpInside];
[cell cellsetshopsInfoWith:self.shopsInfo];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}else if (indexPath.row == 1){
KanHuWorkHeaderViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KanHuWorkHeaderViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"KanHuWorkHeaderViewCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}else{
if (self.kanHuListArr.count!=0) {
if (indexPath.row == self.kanHuListArr.count + 1 + 1) {
//最后一个cellKanHuViewLastCell
KanHuViewLastCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KanHuViewLastCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"KanHuViewLastCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}else{
KanHuWorkViewSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KanHuWorkViewSecondCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"KanHuWorkViewSecondCell" owner:self options:nil]lastObject];
}
KanHuListModel *kanHuCamera= self.kanHuListArr[indexPath.row - 2];
NSString *filePath = [Utils getHeaderFilePathWithId:kanHuCamera.cameraId];
UIImage *headImg = [UIImage imageWithContentsOfFile:filePath];
if(headImg==nil){
cell.CameraHoldImg.image = LXImageWithImageName(@"ic_header.png");
}else{
cell.CameraHoldImg.image = headImg;
}
cell.guKeMing.text = kanHuCamera.nickName;
//cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.chatBtn addTarget:self action:@selector(chatBtnAction:) forControlEvents:UIControlEventTouchUpInside];
cell.chatBtn.tag = indexPath.row;
return cell;
}
}else{
shopNoCumtomerViewCell *customerNoneCell = [tableView dequeueReusableCellWithIdentifier:@"shopNoCumtomerViewCell"];
if (!customerNoneCell) {
customerNoneCell = [[[NSBundle mainBundle]loadNibNamed:@"shopNoCumtomerViewCell" owner:self options:nil]lastObject];
}
[customerNoneCell cellSetnoGuKeBackViewCorner];
customerNoneCell.userInteractionEnabled = NO;
return customerNoneCell;
}
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row ==0) {
return 175;
}else if (indexPath.row ==1){
return 61;
}else if (indexPath.row == self.kanHuListArr.count + 1 + 1){
// return kScreenSize.width/320 * 212;
return 48;
}else{
return 280;
}
//return UITableViewAutomaticDimension;
}
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//
// return 0;
//}
//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//
// return 0;
//}
//
//- (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 || indexPath.row == 1) {
return;
}
if (self.kanHuListArr.count == 0) {
return;
}
//最后一个空cell return掉
if (indexPath.row == self.kanHuListArr.count + 1 + 1 ) {
return;
}
KanHuListModel *kanHuCamera= self.kanHuListArr[indexPath.row - 2];
self.hidesBottomBarWhenPushed = YES;
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];
[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"];
[self.kanHuListArr addObject:listmodel];
}
[self.tableView reloadData];
} failure:^(NSError *err) {
}];
}
-(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<pagecount-1) {
_page++;
NSInteger first=(NSInteger)_page*10;
NSString *firsStr=[NSString stringWithFormat:@"%ld",(long)first];
[weskSelf addTaskWithFirst:firsStr addpageSize:@"10" isRefresh:NO];
}else{
[self endRefreshing];
[self.view makeToast:@"没有了"];
}
}];
}
-(void)endRefreshing{
if (self.isRefreshing) {
self.isRefreshing=NO;
[self.tableView headerEndRefreshingWithResult:JHRefreshResultNone];
}
if (self.isLoadMore) {
self.isLoadMore=NO;
[self.tableView footerEndRefreshing];
}
}
-(void)addTaskWithFirst:(NSString *)firstrRsult addpageSize:(NSString *)pageSiaze isRefresh:(BOOL)isRefresh{
if (isRefresh) {
[self.kanHuListArr removeAllObjects];
}
[AFNOHeaderHttpTool getKanHuListWithShopsId:self.shopsInfo.userId firstResult:firstrRsult pageSize:pageSiaze 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"];
[self.kanHuListArr addObject:listmodel];
}
[self.tableView reloadData];
[self endRefreshing];
} failure:^(NSError *err) {
[self endRefreshing];
}];
}
#pragma mark-编辑
-(void)bianJiBtnAction:(UIButton *)btn{
ShopEditViewController *editVC=[[ShopEditViewController alloc] init];
editVC.shopInfo = self.shopsInfo;
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:editVC animated:YES];
}
#pragma mark -和客户聊天
-(void)chatBtnAction:(UIButton *)btn{
KanHuListModel *listmodel = self.kanHuListArr[btn.tag - 2];
UserModel*model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
NSString *myAcount = [NSString stringWithFormat:@"%@",model.userId];
NSString *tarGetAcount = [NSString stringWithFormat:@"%@",listmodel.userId];
[[NIMSDK sharedSDK].loginManager login:myAcount token:model.neteaseToken completion:^(NSError *error) {
if (!error) {
NSLog(@"登录成功");
//创建session
NIMSession *session = [NIMSession session:tarGetAcount type:NIMSessionTypeP2P];
//创建聊天页,这个页面继承自 NIMKit 中的组件 NIMSessionViewController
self.hidesBottomBarWhenPushed = YES;
IfishSessionViewController *vc = [[IfishSessionViewController alloc] initWithSession:session];
//vc.targetChatname = listmodel.nickName;
[self.navigationController pushViewController:vc animated:YES];
}else{
NSLog(@"登录失败");
}
}];
}
@end