//
|
// MyDeviceStatusView.m
|
// GoldRich
|
//
|
// Created by WindShan on 2017/2/13.
|
// Copyright © 2017年 WindShan. All rights reserved.
|
//
|
|
#import "MyDeviceStatusView.h"
|
#import "GloriaLabel.h"
|
#import "UIImageView+WebCache.h"
|
#import "MyDeviceStatusCell.h"
|
#import "MBProgressHUD+Add.h"
|
#import "NetworkSingleton.h"
|
|
@interface MyDeviceStatusView()<UITableViewDelegate,UITableViewDataSource,SelCellDetailDelegate>
|
/*
|
// Only override drawRect: if you perform custom drawing.
|
// An empty implementation adversely affects performance during animation.
|
- (void)drawRect:(CGRect)rect {
|
// Drawing code
|
}
|
*/
|
{
|
UIButton* deviceOpenBtn;
|
NSInteger pageIndex;
|
NSInteger pageSize;
|
}
|
@end
|
|
|
@implementation MyDeviceStatusView
|
|
- (UITableView *)tableView
|
{
|
if (!_tableView)
|
{
|
_tableView = [[UITableView alloc] init];
|
|
|
_tableView.delegate = self;
|
_tableView.dataSource = self;
|
_tableView.separatorColor = [UIColor clearColor];
|
|
[self addSubview:_tableView];
|
|
[_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.edges.mas_equalTo(UIEdgeInsetsMake(0 , 0, 0, 0));
|
}];
|
|
_tableView.tableFooterView = [UIView new];
|
}
|
return _tableView;
|
}
|
|
- (instancetype)initWithFrame:(CGRect)frame userId:(NSString*)uid devicetype:(NSString*)type searchkey:(NSString*)key
|
{
|
if (self = [super initWithFrame:frame])
|
{
|
self.tableView.frame = frame;
|
self.tableView.hidden = NO;
|
self.modelArray = [[NSMutableArray alloc] init];
|
self.uid = uid;
|
self.type = type;
|
self.key = key;
|
pageIndex = 1;
|
pageSize = 20;
|
|
__loadErrorBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
__loadErrorBtn.frame = CGRectMake((SCREEN_WIDTH-100)/2, SCREEN_HEIGHT/3, 100, 100);
|
[__loadErrorBtn setImage:[UIImage imageNamed:@"page_icon_empty"] forState:UIControlStateNormal];
|
__loadErrorBtn.layer.masksToBounds=YES;
|
__loadErrorBtn.layer.cornerRadius=8.0f;
|
[__loadErrorBtn addTarget:self action:@selector(getFirstPageData) forControlEvents:UIControlEventTouchUpInside];
|
[self addSubview:__loadErrorBtn];
|
|
_tipsLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT/3 + 120, SCREEN_WIDTH, 60)];
|
_tipsLabel.font = [UIFont systemFontOfSize:20.0];
|
_tipsLabel.textColor = [UIColor blackColor];
|
_tipsLabel.textAlignment = NSTextAlignmentCenter;
|
_tipsLabel.text = @"亲,暂无设备,请前去添加!";
|
[self addSubview:_tipsLabel];
|
|
__loadErrorBtn.hidden = YES;
|
_tipsLabel.hidden = YES;
|
|
// test
|
//for (int i = 0; i < 10; i++)
|
//{
|
// MyDeviceStatus * status = [[MyDeviceStatus alloc] init];
|
// [self.modelArray addObject:status];
|
//}
|
|
[self setUpTableView];
|
}
|
|
return self;
|
}
|
|
-(void)getFirstPageData
|
{
|
__loadErrorBtn.hidden = YES;
|
_tableView.hidden = NO;
|
_tipsLabel.hidden = YES;
|
pageIndex=1;
|
[self getDeviceList:self.uid devicetype:self.type searchkey:self.key isTips:NO pageIndex:[NSString stringWithFormat:@"%ld",pageIndex] pageSize:[NSString stringWithFormat:@"%ld",pageSize]];
|
}
|
|
-(void) reloadData
|
{
|
pageIndex++;
|
[self getDeviceList:self.uid devicetype:self.type searchkey:self.key isTips:NO pageIndex:[NSString stringWithFormat:@"%ld",pageIndex] pageSize:[NSString stringWithFormat:@"%ld",pageSize]];
|
}
|
|
-(void)setUpTableView
|
{
|
//添加下拉的动画图片
|
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
|
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(getFirstPageData)];
|
|
// 马上进入刷新状态
|
//
|
[_tableView.mj_header beginRefreshing];
|
|
|
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
|
_tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(reloadData)];
|
}
|
|
|
-(void) getDeviceList:(NSString *) userID devicetype:(NSString*)type searchkey:(NSString*)key isTips:(BOOL) isShow pageIndex:(NSString *)page pageSize:(NSString *)size
|
{
|
// 执行登录操作
|
MBProgressHUD *HUD = nil;
|
if( isShow == YES)
|
{
|
HUD = [MBProgressHUD showHUDAddedTo:self animated:YES];
|
HUD.labelText = @"数据加载中...";
|
// 隐藏时候从父控件中移除
|
HUD.removeFromSuperViewOnHide = YES;
|
// YES代表需要蒙版效果
|
HUD.dimBackground = YES;
|
}
|
|
//@property (nonatomic, assign) int opt;//opt=1表示运维人员,opt=2表示酒店前台
|
|
int userOpt = [[UserDefault stringForKey:@"opt"] intValue];
|
|
NSString *path = [[NSString alloc] initWithFormat:userOpt == 1? GET_DEVICE_INFO:GET_DEVICE_INFO_WAITER];
|
|
NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
|
|
// tempdebug
|
if(userOpt == 1)
|
[param setObject:userID forKey:@"userID"];
|
else
|
[param setObject:userID forKey:@"waiterID"];
|
|
[param setObject:key forKey:@"keyword"];
|
[param setObject:self.hotel_id forKey:@"hotel_id"];
|
[param setObject:type forKey:@"type"];
|
[param setObject:page forKey:@"currentPage"];
|
[param setObject:size forKey:@"pageSize"];
|
|
|
MPWeakSelf(self);
|
[NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody)
|
{
|
if( isShow == YES)
|
HUD.hidden = YES;
|
|
[_tableView.mj_header endRefreshing];
|
[_tableView.mj_footer endRefreshing];
|
MPStrongSelf(self);
|
BaseResModel * resModel = [Global toBaseModel:responseBody];
|
|
|
if(pageIndex == 1)
|
{
|
[_modelArray removeAllObjects];
|
}
|
|
if(resModel.code == 0)
|
{
|
if(![Global isEmptyObject:resModel.content])
|
{
|
NSMutableArray *modelTempArray = [MyDeviceStatus mj_objectArrayWithKeyValuesArray:resModel.content];
|
|
BASE_INFO_FUN(resModel.content);
|
|
[_modelArray addObjectsFromArray:modelTempArray];
|
|
__loadErrorBtn.hidden = YES;
|
_tipsLabel.hidden = YES;
|
|
_tableView.hidden = NO;
|
[_tableView reloadData];
|
|
}
|
else
|
{
|
// 出错处理
|
if(self.modelArray.count > 0)
|
{
|
[self.modelArray removeAllObjects];
|
|
}
|
|
__loadErrorBtn.hidden = NO;
|
_tipsLabel.hidden = NO;
|
[_tableView reloadData];
|
_tableView.hidden = YES;
|
|
[Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"确定" delegate:self];
|
}
|
|
}
|
else
|
{
|
if(self.modelArray.count > 0)
|
{
|
[self.modelArray removeAllObjects];
|
|
}
|
|
[_tableView reloadData];
|
_tableView.hidden = YES;
|
__loadErrorBtn.hidden = NO;
|
_tipsLabel.hidden = NO;
|
|
}
|
}
|
failure:^(NSString *error)
|
{
|
[_tableView.mj_header endRefreshing];
|
[_tableView.mj_footer endRefreshing];
|
if( isShow == YES)
|
HUD.hidden = YES;
|
|
[_tableView reloadData];
|
|
_tableView.hidden = YES;
|
|
__loadErrorBtn.hidden = NO;
|
_tipsLabel.hidden = NO;
|
|
[Global alertMessageEx:error title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}];
|
|
|
}
|
|
- (void) reSetView:(NSString*)uid devicetype:(NSString*)type searchkey:(NSString*)key
|
{
|
if(key!=nil)
|
{
|
self.key = key;
|
|
}
|
|
pageIndex = 1;
|
self.type = type;
|
|
[self getDeviceList:self.uid devicetype:self.type searchkey:self.key isTips:NO pageIndex:[NSString stringWithFormat:@"%ld",pageIndex] pageSize:[NSString stringWithFormat:@"%ld",pageSize]];
|
}
|
|
#pragma mark - UITableViewDelegate&UITableViewDataSource
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
{
|
return 1;
|
}
|
|
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
//{
|
// return 0;
|
//}
|
//
|
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
{
|
return 0;
|
}
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
{
|
return self.modelArray.count;
|
}
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
return 106;
|
}
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
|
NSString * identifier = @"MyDeviceStatusCell";
|
MyDeviceStatusCell * statusCell = [tableView dequeueReusableCellWithIdentifier:identifier];
|
if (nil == statusCell) {
|
statusCell = [[MyDeviceStatusCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
|
|
}
|
|
statusCell.delegate = self;
|
statusCell.selectionStyle = UITableViewCellSelectionStyleNone;
|
statusCell.userInteractionEnabled = YES;
|
|
MyDeviceStatus * model = [self.modelArray objectAtIndex:indexPath.row];
|
|
[statusCell setItemView:model];
|
|
return statusCell;
|
}
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
if ( _delegate && [_delegate respondsToSelector:@selector(didSelectedSection:)])
|
{
|
MyDeviceStatus * model = [self.modelArray objectAtIndex:indexPath.row];
|
[_delegate didSelectedSection:model];
|
}
|
}
|
|
|
- (void)didCellDetailSection:(MyDeviceStatus*)model
|
{
|
if ( _detailDelegate && [_detailDelegate respondsToSelector:@selector(didDetailSection:)])
|
{
|
[_detailDelegate didDetailSection:model];
|
}
|
}
|
|
@end
|