You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
225 lines
8.6 KiB
225 lines
8.6 KiB
1 year ago
|
//
|
||
|
// QueryCallRatesRoFlowVC.m
|
||
|
// tongxin
|
||
|
//
|
||
|
// Created by Apple on 2019/2/25.
|
||
|
// Copyright © 2019年 xTT. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "QueryCallRatesRoFlowVC.h"
|
||
|
#import "QueryFareTableViewCell.h"
|
||
|
#import <MJExtension.h>
|
||
|
#import "QueryFare.h"
|
||
|
#import <MJRefresh/MJRefresh.h>
|
||
|
@interface QueryCallRatesRoFlowVC ()
|
||
|
@property(nonatomic, strong) QueryFareTableViewCell *cell;
|
||
|
@property (nonatomic,strong) UIView * vbottom;
|
||
|
@property (nonatomic,strong) UIButton *leftBtn;
|
||
|
@property (nonatomic,strong) UIButton *rightBtn;
|
||
|
@end
|
||
|
@implementation QueryCallRatesRoFlowVC
|
||
|
|
||
|
|
||
|
- (void)viewWillAppear:(BOOL)animated{
|
||
|
[super viewWillAppear:animated];
|
||
|
[self loadData];
|
||
|
}
|
||
|
- (void)viewDidLoad {
|
||
|
[super viewDidLoad];
|
||
|
self.title = @"话费流量查询";
|
||
|
// Do any additional setup after loading the view.
|
||
|
self.view.backgroundColor = tabViewBG;
|
||
|
self.myTableView.estimatedRowHeight = 100;
|
||
|
self.myTableView.rowHeight = UITableViewAutomaticDimension;
|
||
|
self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||
|
|
||
|
[self setUI];
|
||
|
self.myTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
||
|
[self loadData];
|
||
|
}];
|
||
|
// [self.myTableView.mj_header beginRefreshing];
|
||
|
//
|
||
|
// [[NSNotificationCenter defaultCenter] addObserverForName:@"QueryFareReload" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
|
||
|
// [self loadData];
|
||
|
// }];
|
||
|
}
|
||
|
|
||
|
-(void)loadData{
|
||
|
WeakSelf
|
||
|
[cUser.cDevice getCostAndTrafficRecordWithParameters:nil Success:^(id responseObject) {
|
||
|
if([[responseObject allKeys] containsObject:@"messages"]){
|
||
|
NSArray *msgArray;
|
||
|
@try {
|
||
|
msgArray = responseObject[@"messages"];
|
||
|
} @catch (NSException *exception) {
|
||
|
xLog(@"出错")
|
||
|
} @finally {
|
||
|
|
||
|
}
|
||
|
if(msgArray){
|
||
|
// 数据处理
|
||
|
/* items
|
||
|
{
|
||
|
id :[str]
|
||
|
timestamp :[float]
|
||
|
content :[str]
|
||
|
}
|
||
|
*/
|
||
|
self.myDataSource = [QueryFare mj_objectArrayWithKeyValuesArray:msgArray];
|
||
|
}
|
||
|
[self.myTableView.mj_header endRefreshing];
|
||
|
[weakSelf.myTableView reloadData];
|
||
|
[weakSelf setupNavi];
|
||
|
}
|
||
|
} failure:^(id faiObject) {
|
||
|
|
||
|
[self.myTableView.mj_header endRefreshing];
|
||
|
[weakSelf setupNavi];
|
||
|
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
-(void)setUI{
|
||
|
if(_vbottom){
|
||
|
[_vbottom removeFromSuperview];
|
||
|
_vbottom = nil;
|
||
|
}
|
||
|
CGFloat tempHeight = 45+11;
|
||
|
if(ScreenHeight >= 812){
|
||
|
tempHeight = 45+11+15;
|
||
|
}
|
||
|
_vbottom = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-getRectNavAndStatusHight-tempHeight, ScreenWidth, tempHeight)];
|
||
|
|
||
|
_leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
|
[_leftBtn setTitle:@"查话费" forState:UIControlStateNormal];
|
||
|
_leftBtn.layer.cornerRadius = 3;
|
||
|
_leftBtn.layer.masksToBounds = YES;
|
||
|
[_leftBtn setBackgroundColor:mainColor];
|
||
|
[_leftBtn setTitleColor:[UIColor whiteColor] forState:0];
|
||
|
[_leftBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
|
||
|
|
||
|
_rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
|
[_rightBtn setTitle:@"查流量" forState:UIControlStateNormal];
|
||
|
_rightBtn.layer.cornerRadius = 3;
|
||
|
_rightBtn.layer.masksToBounds = YES;
|
||
|
[_rightBtn setBackgroundColor:mainColor];
|
||
|
[_rightBtn setTitleColor:[UIColor whiteColor] forState:0];
|
||
|
[_rightBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
|
||
|
|
||
|
|
||
|
// [_vbottom.layer setBorderColor:[UIColor lightGrayColor].CGColor];
|
||
|
// _vbottom.backgroundColor = RGBA(241, 241, 241, 1);
|
||
|
|
||
|
_leftBtn.frame = CGRectMake(14, 1, (ScreenWidth-28-25)/2, 44);
|
||
|
_rightBtn.frame = CGRectMake(14+(ScreenWidth-28-25)/2+25, 1, (ScreenWidth-28-25)/2, 44);
|
||
|
[_vbottom addSubview:_leftBtn];
|
||
|
[_vbottom addSubview:_rightBtn];
|
||
|
[self.view addSubview:_vbottom];
|
||
|
[self.view bringSubviewToFront:_vbottom]; //置顶
|
||
|
[_rightBtn addTarget:self action:@selector(actionBalanceAndFlow:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
[_leftBtn addTarget:self action:@selector(actionBalanceAndFlow:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
- (void)setupNavi {
|
||
|
// UIBarButtonItem *settingBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"device_querfare_setting"] style:UIBarButtonItemStylePlain target:self action:@selector(settingBarClick)];
|
||
|
if(self.myDataSource.count == 0){
|
||
|
self.navigationItem.rightBarButtonItems = nil;
|
||
|
}else{
|
||
|
UIBarButtonItem *deleteBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_delect"] style:UIBarButtonItemStylePlain target:self action:@selector(delegateMsg)];
|
||
|
self.navigationItem.rightBarButtonItems = @[
|
||
|
//settingBtn,
|
||
|
deleteBtn];
|
||
|
}
|
||
|
|
||
|
}
|
||
|
- (void)settingBarClick {
|
||
|
[self performSegueWithIdentifier:@"goQueryFareSetting" sender:nil];
|
||
|
}
|
||
|
- (void)delegateMsg {
|
||
|
WEAKSELF
|
||
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"注意" message:@"确认要清空话费流量记录?" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
|
||
|
|
||
|
[QueryFare delectMessageSuccess:^(id result) {
|
||
|
[weakSelf.myDataSource removeAllObjects];
|
||
|
[weakSelf.myTableView reloadData];
|
||
|
xLog(@"删除记录成功!")
|
||
|
} failure:^{
|
||
|
// [SVProgressHUD showSuccessWithStatus:@"删除记录失败,请稍后重试"];
|
||
|
} ];
|
||
|
|
||
|
} cancelHandler:nil destructiveHandler:nil];
|
||
|
[alertView showAnimated:YES completionHandler:nil];
|
||
|
}
|
||
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||
|
return 1;
|
||
|
}
|
||
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||
|
return self.myDataSource.count;
|
||
|
}
|
||
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
QueryFareTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"queryFareTableViewCell"];
|
||
|
if (!cell) {
|
||
|
cell = [QueryFareTableViewCell viewFirstXib];
|
||
|
cell.accessoryType = UITableViewCellAccessoryNone;
|
||
|
}
|
||
|
cell.model = self.myDataSource[indexPath.row];
|
||
|
self.cell = cell;
|
||
|
return cell;
|
||
|
}
|
||
|
|
||
|
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
|
||
|
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
return UITableViewCellEditingStyleNone;
|
||
|
}
|
||
|
|
||
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
|
return [self.cell heightForModel:self.myDataSource[indexPath.row]];
|
||
|
}
|
||
|
|
||
|
- (void)actionBalanceAndFlow:(UIButton *)sender {
|
||
|
|
||
|
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||
|
int temp = 1; //1 话费 0 流量
|
||
|
if ([sender.titleLabel.text isEqualToString:@"查话费"]) {
|
||
|
temp = 1;
|
||
|
}else if([sender.titleLabel.text isEqualToString:@"查流量"]){
|
||
|
temp = 0;
|
||
|
}
|
||
|
[params setValue:@(temp) forKey:@"type"];
|
||
|
WEAKSELF
|
||
|
[cUser.cDevice queryCostAndTrafficFunctionWithParameters:params Success:^(id responseObject) {
|
||
|
// [SVProgressHUD showSuccessWithStatus:@"查询成功,等待设备回复"];
|
||
|
NSString *content;
|
||
|
if ([sender.titleLabel.text isEqualToString:@"查话费"]) {
|
||
|
content = @"查询话费指令已下发,等待设备上传查询短信";
|
||
|
}else if([sender.titleLabel.text isEqualToString:@"查流量"]){
|
||
|
content = @"查询流量指令已下发,等待设备上传查询短信";
|
||
|
}
|
||
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:content style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:nil destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
|
||
|
//设置按钮不可点击
|
||
|
[weakSelf setBtnBadRoGoodFlag:NO WithBtn:sender];
|
||
|
} cancelHandler:nil destructiveHandler:nil];
|
||
|
[alertView showAnimated:YES completionHandler:nil];
|
||
|
} failure:^(id faiObject) {
|
||
|
xLog(@"查询话费或者流量失败");
|
||
|
}];
|
||
|
}
|
||
|
/**
|
||
|
设置按钮不可选且半透明
|
||
|
@param flag Bad is NO , Good is YES
|
||
|
@param button button
|
||
|
*/
|
||
|
-(void)setBtnBadRoGoodFlag:(BOOL)flag WithBtn:(UIButton*) button{
|
||
|
if(flag){
|
||
|
[button setAlpha:1];
|
||
|
[button setEnabled:YES];
|
||
|
}else{
|
||
|
[button setAlpha:0.5];
|
||
|
[button setEnabled:NO];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@end
|