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.
 
 
 
 

264 lines
10 KiB

//
// HAndTViewController.m
// tongxin
//
// Created by Apple on 2020/4/9.
// Copyright © 2020 xTT. All rights reserved.
//
#import "HAndTViewController.h"
#import "HAndTChartCell.h"
#import "HeartAndTempModel.h"
@interface HAndTViewController ()<UITableViewDelegate,UITableViewDataSource>
{
NSString *qDayStr;
}
/// 编辑上报频率的容器View
@property (strong, nonatomic) UIView * editingFrequencyView;
/// 编辑上报频率的TextField
@property (strong, nonatomic) UITextField * editingFrequencyTextField;
@property (strong, nonatomic) UITableView *myTableView;
@property (strong, nonatomic) HeartAndTempModel* model;
@end
@implementation HAndTViewController
@synthesize myDataSource = _myDataSource;
-(NSMutableArray *)myDataSource{
if(!_myDataSource){
_myDataSource = [NSMutableArray arrayWithArray:@[@[@"图表"],@[@"开关"],@[@"上报频率"]]];
}
return _myDataSource;
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self loadDataWithQdayStr:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initUI];
}
- (void)loadDataWithQdayStr:(NSString*)qDay{
WEAKSELF
if(!qDay || qDay.length == 0){
//今天
qDayStr = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" date:[NSDate date]];
}else{
qDayStr = qDay;
}
// add by lsz 21-12-28 @try{}@catch{}
@try {
[HeartAndTempModel getHeartAndTempDataWithType:self.type date:qDayStr success:^(HeartAndTempModel * _Nonnull model) {
weakSelf.model = model;
[weakSelf.myTableView reloadData];
} failure:^(NSError * _Nonnull error) {
}];
} @catch (NSException *exception) {
NSLog(@"HeartAndTemp err=%@",exception);
}
}
- (void)initUI{
if(self.type == 0){
self.title = @"心率";
self.myDataSource[1] = @[@"心率开关"];
}else{
self.title = @"体温";
self.myDataSource[1] = @[@"体温开关"];
}
_myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-getRectNavAndStatusHight) style:UITableViewStyleGrouped];
_myTableView.backgroundColor = tabViewBG;
_myTableView.delegate = self;
_myTableView.dataSource = self;
[self.view addSubview:_myTableView];
_myTableView.bounces = NO; //禁止弹跳
_myTableView.showsHorizontalScrollIndicator = NO;
_myTableView.showsVerticalScrollIndicator = NO;
//去线
_myTableView.separatorStyle = UITableViewCellSelectionStyleNone;
// iOS 11 系统 tableView 会自动调整高度 在 Gounp 模式下 头部的高度会有问题 ,需要对 预设的高度设置为0
_myTableView.estimatedRowHeight = 0;
_myTableView.estimatedSectionHeaderHeight = 0;
_myTableView.estimatedSectionFooterHeight = 0;
[_myTableView registerNib:[UINib nibWithNibName:@"HAndTChartCell" bundle:nil] forCellReuseIdentifier:@"HAndTChartCellID"];
[_myTableView registerClass:[baseCell class] forCellReuseIdentifier:@"baseCell"];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return self.myDataSource.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.myDataSource[section] count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section == 0) {
return 0.01;
}else if(section == 1){
return 15 * FIX_SCREEN;
}else{
return 1;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *title = self.myDataSource[indexPath.section][indexPath.row];
if([title isEqualToString:@"图表"]){
return 491;
}else{
return 49;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *title = self.myDataSource[indexPath.section][indexPath.row];
WEAKSELF
if([title isEqualToString:@"图表"]){
HAndTChartCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HAndTChartCellID" forIndexPath:indexPath];
if(_model){
[cell setDataModel:_model WithType:_type WithqDayStr:qDayStr];
}
cell.measurementEndBlock = ^{
[weakSelf loadDataWithQdayStr:nil];
};
cell.switchQueryBlock = ^(NSString * _Nonnull qDay) {
[weakSelf loadDataWithQdayStr:qDay];
};
return cell;
}else if ([title containsString:@"开关"]){
baseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HAndTbaseCell"];
if (!cell) {
cell = [[baseCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"HAndTbaseCell"];
cell.textLabel.font = DefineFontSize;
UISwitch *uiSwitch = [[UISwitch alloc] init];
cell.accessoryView = uiSwitch;
[uiSwitch addTarget:cell
action:@selector(cellClick:)
forControlEvents:UIControlEventValueChanged];
}
cell.textLabel.text = title;
UISwitch *uiSwitch = (UISwitch *)cell.accessoryView;
uiSwitch.onTintColor = mainColor;
if(_model){
uiSwitch.on = [_model.switchStatus boolValue];
}
// cell.textLabel.text = voiceAlarm.time;
// cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ , %@",voiceAlarm.text,[myHelper getWeekDayStr:[voiceAlarm week]]];
cell.block = ^(UISwitch *uiSwitch, TextFieldCell *blockCell){
//切换开关
xLog(@"切换开关");
if(weakSelf.model){
[HeartAndTempModel postHeartAndTempDataWithType:weakSelf.type params:@[@{@"switch":@(uiSwitch.on)}] success:^(id _Nonnull responseObject) {
[UICommon MessageSuccessText:@"修改成功" isImg:YES];
weakSelf.model.switchStatus = @(uiSwitch.on);
[weakSelf.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationNone];
} failure:^(NSError * _Nonnull error) {
[weakSelf.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationNone];
}];
}
};
return cell;
}else{
baseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HAndTFrequency"];
if (!cell) {
cell = [[baseCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"HAndTFrequency"];
UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 21)];
tempLabel.textColor = mainColor;
tempLabel.font = DefineFontSize;
tempLabel.textAlignment = NSTextAlignmentRight;
cell.accessoryView = tempLabel;
}
UILabel *label = (UILabel*)cell.accessoryView;
label.text = [NSString stringWithFormat:@"%@分钟/次",self.model.frequency];
cell.textLabel.text = title;
cell.textLabel.font = DefineFontSize;
return cell;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *title = self.myDataSource[indexPath.section][indexPath.row];
if([title containsString:@"频率"]){
//显示
[self showChangeFrequency];
}
}
-(void)showChangeFrequency{
if(!_editingFrequencyView){
_editingFrequencyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)];
_editingFrequencyView.backgroundColor = [UIColor whiteColor];
CGFloat alertViewWidth = (320.f - 20*2 - 20*2);
_editingFrequencyTextField = [[UITextField alloc] initWithFrame:CGRectMake((ScreenWidth - alertViewWidth)/2, 1, alertViewWidth, 48)];
_editingFrequencyTextField.borderStyle = UITextBorderStyleRoundedRect;
_editingFrequencyTextField.layer.borderColor = RGB(229, 229, 229).CGColor;
_editingFrequencyTextField.backgroundColor = RGB(250, 250, 250);
_editingFrequencyTextField.placeholder = @"请输入上报频率(分钟/次)";
_editingFrequencyTextField.keyboardType = UIKeyboardTypeNumberPad;
[_editingFrequencyView addSubview:_editingFrequencyTextField];
}
_editingFrequencyTextField.text = self.model.frequency;
WEAKSELF
LGAlertView *alertView = [[LGAlertView alloc] initWithViewAndTitle:@"上报频率" message:@"" style:LGAlertViewStyleAlert view:_editingFrequencyView buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
[weakSelf.editingFrequencyTextField resignFirstResponder];
xLog(@"修改 上报频率 %@",weakSelf.editingFrequencyTextField.text);
NSNumber *tempFrequency = @([weakSelf.model.frequency intValue]);
@try {
tempFrequency = @([weakSelf.editingFrequencyTextField.text intValue]);
} @catch (NSException *exception) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UICommon MessageErrorText:@"请输入正确的数值"];
});
return ;
} @finally {
}
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setValue:tempFrequency forKey:@"frequency"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[HeartAndTempModel postHeartAndTempDataWithType:weakSelf.type params:@[dic] success:^(id _Nonnull responseObject) {
[UICommon MessageSuccessText:@"修改成功" isImg:YES];
weakSelf.model.frequency = weakSelf.editingFrequencyTextField.text;
[weakSelf.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:2]] withRowAnimation:UITableViewRowAnimationNone];
} failure:^(NSError * _Nonnull error) {
[weakSelf.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:2]] withRowAnimation:UITableViewRowAnimationNone];
}];
});
} cancelHandler:^(LGAlertView *alertView) {
[weakSelf.editingFrequencyTextField resignFirstResponder];
} destructiveHandler:nil];
[alertView showAnimated:YES completionHandler:nil];
}
@end