Files
fanyin-ios/QXLive/Mine(音域)/View/我的房间/QXRoomDetailHeaderView.m

383 lines
16 KiB
Mathematica
Raw Permalink Normal View History

2025-08-12 14:27:12 +08:00
//
// QXRoomDetailHeaderView.m
// IsLandVoice
//
// Created by on 2025/3/5.
//
#import "QXRoomDetailHeaderView.h"
#import "UIButton+QX.h"
@class QXDatePickerView;
@interface QXRoomDetailHeaderView()
@property (nonatomic,strong)UIImageView*bigBgImageView;
@property (nonatomic,strong)UIImageView*bgImageView;
@property (nonatomic,strong)UIImageView*bottomBGView;
@property (nonatomic,strong)UIImageView*allPriceImageView;
@property (nonatomic,strong)UILabel*allPriceTitleLabel;
@property (nonatomic,strong)UILabel*allPriceLabel;
@property (nonatomic,strong)UILabel*allWaterTitleLabel;
@property (nonatomic,strong)UILabel*allWaterLabel;
@property (nonatomic,strong)UIImageView*allWaterImageView;
@property (nonatomic,strong)UIButton*timeBtn;
@property (nonatomic,strong)QXDatePickerView *pickerView;
@end
@implementation QXRoomDetailHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubView];
}
return self;
}
-(void)initSubView{
self.backgroundColor = [UIColor clearColor];
[self addSubview:self.bigBgImageView];
[self.bigBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self);
make.right.equalTo(self);
make.top.equalTo(self);
make.bottom.equalTo(self);
}];
[self addSubview:self.bottomBGView];
// [self.bottomBGView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(self);
// make.right.equalTo(self);
// make.top.equalTo(self);
// make.bottom.equalTo(self);
// }];
[self addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(16);
make.right.equalTo(self).offset(-16);
make.top.equalTo(self).offset(11+kSafeAreaTop+44);
make.bottom.equalTo(self);
}];
[self addSubview:self.allPriceTitleLabel];
[self.allPriceTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.bgImageView).offset(16);
make.top.equalTo(self.bgImageView).offset(13);
make.width.mas_equalTo(128);
make.height.mas_equalTo(20);
}];
[self addSubview:self.allPriceImageView];
[self.allPriceImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.allPriceTitleLabel);
make.top.equalTo(self.bgImageView).offset(35);
make.height.width.mas_equalTo(40);
}];
[self addSubview:self.allPriceLabel];
[self.allPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.allPriceImageView.mas_right).offset(5);
make.top.equalTo(self.bgImageView).offset(32);
make.right.equalTo(self.bgImageView).offset(-16);
make.height.mas_equalTo(45);
}];
[self addSubview:self.allWaterTitleLabel];
[self.allWaterTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.bgImageView).offset(16);
make.top.equalTo(self.bgImageView).offset(87);
make.right.equalTo(self.bgImageView).offset(-16);
make.height.mas_equalTo(20);
}];
[self addSubview:self.allWaterImageView];
[self.allWaterImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.allWaterTitleLabel);
make.top.equalTo(self.bgImageView).offset(107);
make.height.width.mas_equalTo(20);
}];
[self addSubview:self.allWaterLabel];
[self.allWaterLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.allWaterImageView.mas_right).offset(5);
make.top.equalTo(self.bgImageView).offset(107);
make.right.equalTo(self.bgImageView).offset(-16);
make.height.mas_equalTo(20);
}];
[self addSubview:self.timeBtn];
[self.timeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.bgImageView).offset(-12);
make.centerY.equalTo(self.allPriceTitleLabel);
make.width.mas_greaterThanOrEqualTo(60);
make.height.mas_equalTo(40);
}];
}
-(void)layoutSubviews{
[super layoutSubviews];
self.bottomBGView.bottom = self.height;
}
-(void)timeAction:(UIButton*)sender{
[self.pickerView show];
}
-(void)setModel:(QXRoomDetailModel *)model{
_model = model;
self.allWaterLabel.text = [NSString stringWithFormat:@"%.2f",model.total_amount];;
self.allPriceLabel.text = [NSString stringWithFormat:@"%.2f",model.total_earning];
}
-(UIImageView *)bgImageView{
if (!_bgImageView) {
_bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_room_water_bg"]];
_bgImageView.contentMode = UIViewContentModeScaleToFill;
}
return _bgImageView;
}
-(UIImageView *)bigBgImageView{
if (!_bigBgImageView) {
_bigBgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"detail_bg"]];
_bigBgImageView.contentMode = UIViewContentModeScaleToFill;
}
return _bigBgImageView;
}
-(UIImageView *)bottomBGView{
if (!_bottomBGView) {
UIImage*img = [UIImage imageNamed:@"mine_room_water_bg"];
CGFloat height = (SCREEN_WIDTH-32)/img.size.width*img.size.height;
_bottomBGView = [[UIImageView alloc] initWithFrame:CGRectMake(0, kSafeAreaTop+44+height/2.0, SCREEN_WIDTH, height/2.0)];
_bottomBGView.backgroundColor = [UIColor whiteColor];
[_bottomBGView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopRight|UIRectCornerTopLeft)];
}
return _bottomBGView;
}
-(UILabel *)allPriceTitleLabel{
if (!_allPriceTitleLabel) {
_allPriceTitleLabel = [[UILabel alloc] init];
_allPriceTitleLabel.textColor = [UIColor colorWithHexString:@"#999999"];
_allPriceTitleLabel.font = [UIFont systemFontOfSize:13];
_allPriceTitleLabel.text = @"累计收益";
}
return _allPriceTitleLabel;
}
-(UILabel *)allPriceLabel{
if (!_allPriceLabel) {
_allPriceLabel = [[UILabel alloc] init];
_allPriceLabel.textColor = [UIColor colorWithHexString:@"#333333"];
_allPriceLabel.font = [UIFont boldSystemFontOfSize:33];
_allPriceLabel.text = @"-";
}
return _allPriceLabel;
}
-(UILabel *)allWaterTitleLabel{
if (!_allWaterTitleLabel) {
_allWaterTitleLabel = [[UILabel alloc] init];
_allWaterTitleLabel.textColor = [UIColor colorWithHexString:@"#999999"];
_allWaterTitleLabel.font = [UIFont systemFontOfSize:13];
_allWaterTitleLabel.text = @"累计流水";
}
return _allWaterTitleLabel;
}
-(UIImageView *)allWaterImageView{
if (!_allWaterImageView) {
_allWaterImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wallet_corn"]];
}
return _allWaterImageView;
}
-(UIImageView *)allPriceImageView{
if (!_allPriceImageView) {
_allPriceImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wallet_diamond"]];
}
return _allPriceImageView;
}
-(UILabel *)allWaterLabel{
if (!_allWaterLabel) {
_allWaterLabel = [[UILabel alloc] init];
_allWaterLabel.textColor = [UIColor colorWithHexString:@"#333333"];
_allWaterLabel.font = [UIFont boldSystemFontOfSize:14];
_allWaterLabel.text = @"-";
}
return _allWaterLabel;
}
-(UIButton *)timeBtn{
if (!_timeBtn) {
_timeBtn = [[UIButton alloc] init];
[_timeBtn setTitle:@"全部" forState:UIControlStateNormal];
[_timeBtn setImage:[UIImage imageNamed:@"下拉"] forState:UIControlStateNormal];
[_timeBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:(UIControlStateNormal)];
_timeBtn.titleLabel.font = [UIFont systemFontOfSize:13];
[_timeBtn qx_layoutButtonNOSizeToFitWithEdgeInsetsStyle:(QXButtonEdgeInsetsStyleRight) imageTitleSpace:3];
[_timeBtn addTarget:self action:@selector(timeAction:) forControlEvents:(UIControlEventTouchUpInside)];
}
return _timeBtn;
}
-(QXDatePickerView *)pickerView{
if (!_pickerView) {
_pickerView = [[QXDatePickerView alloc] init];
MJWeakSelf
_pickerView.chooseDateBlock = ^(NSString * _Nonnull startTime, NSString * _Nonnull endTime) {
[weakSelf.timeBtn setTitle:[NSString stringWithFormat:@"%@至%@",startTime,endTime] forState:(UIControlStateNormal)];
[weakSelf.timeBtn qx_layoutButtonNOSizeToFitWithEdgeInsetsStyle:(QXButtonEdgeInsetsStyleRight) imageTitleSpace:3];
if (weakSelf.chooseDateBlock) {
weakSelf.chooseDateBlock(startTime, endTime);
}
};
}
return _pickerView;
}
@end
@implementation QXDatePickerView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[self createViews];
}
return self;
}
-(void)createViews{
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ScaleWidth(400))];
self.bgView.backgroundColor = [UIColor whiteColor];
[self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
[self addSubview:self.bgView];
self.cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 40)];
[self.cancelBtn setTitle:@"取消" forState:(UIControlStateNormal)];
[self.cancelBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:(UIControlStateNormal)];
self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:15];
[self.cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:(UIControlEventTouchUpInside)];
[self.bgView addSubview:self.cancelBtn];
self.doneBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.width-70, 0, 70, 40)];
[self.doneBtn setTitle:@"完成" forState:(UIControlStateNormal)];
[self.doneBtn addTarget:self action:@selector(doneAction) forControlEvents:(UIControlEventTouchUpInside)];
[self.doneBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:(UIControlStateNormal)];
self.doneBtn.titleLabel.font = [UIFont systemFontOfSize:15];
[self.bgView addSubview:self.doneBtn];
CGFloat btnWith = (self.bgView.width-40*2-25)/2.0;
self.beginTimeBtn = [[UIButton alloc] initWithFrame:CGRectMake(40, self.cancelBtn.bottom, btnWith, 40)];
[self.beginTimeBtn setTitle:@"开始时间" forState:(UIControlStateNormal)];
[self.beginTimeBtn setTitleColor:[UIColor colorWithHexString:@"#BBBBBB"] forState:(UIControlStateNormal)];
[self.beginTimeBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:(UIControlStateSelected)];
[self.beginTimeBtn addTarget:self action:@selector(beginTimeAction) forControlEvents:(UIControlEventTouchUpInside)];
self.beginTimeBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
[self.bgView addSubview:self.beginTimeBtn];
self.beginTimeLine = [[UIView alloc] initWithFrame:CGRectMake(self.beginTimeBtn.left, self.beginTimeBtn.bottom, btnWith, 1)];
self.beginTimeLine.backgroundColor = [UIColor colorWithHexString:@"#BBBBBB"];
[self.bgView addSubview:self.beginTimeLine];
self.endTimeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.width-40-btnWith, self.beginTimeBtn.top, btnWith, 40)];
[self.endTimeBtn setTitle:@"结束时间" forState:(UIControlStateNormal)];
[self.endTimeBtn setTitleColor:[UIColor colorWithHexString:@"#BBBBBB"] forState:(UIControlStateNormal)];
[self.endTimeBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:(UIControlStateSelected)];
[self.endTimeBtn addTarget:self action:@selector(endTimeAction) forControlEvents:(UIControlEventTouchUpInside)];
self.endTimeBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
[self.bgView addSubview:self.endTimeBtn];
self.endTimeLine = [[UIView alloc] initWithFrame:CGRectMake(self.endTimeBtn.left, self.endTimeBtn.bottom, btnWith, 1)];
self.endTimeLine.backgroundColor = [UIColor colorWithHexString:@"#BBBBBB"];
[self.bgView addSubview:self.endTimeLine];
self.centerLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.beginTimeBtn.right, self.beginTimeBtn.top, self.endTimeBtn.left-self.beginTimeBtn.right, 40)];
self.centerLabel.textAlignment = NSTextAlignmentCenter;
self.centerLabel.text = @"至";
self.centerLabel.textColor = [UIColor colorWithHexString:@"#666666"];
self.centerLabel.font = [UIFont systemFontOfSize:14];
[self.bgView addSubview:self.centerLabel];
self.pickerBGView = [[UIView alloc] initWithFrame:CGRectMake(0, self.beginTimeBtn.bottom+15, self.bgView.width, self.bgView.height-self.beginTimeBtn.bottom-30)];
[self.bgView addSubview:self.pickerBGView];
[self.pickerView addPickerToView:self.pickerBGView];
[self beginTimeAction];
}
-(void)beginTimeAction{
self.beginTimeBtn.selected = YES;
self.beginTimeLine.backgroundColor = [UIColor colorWithHexString:@"#333333"];
self.endTimeBtn.selected = NO;
self.endTimeLine.backgroundColor = [UIColor colorWithHexString:@"#BBBBBB"];
}
-(void)endTimeAction{
self.endTimeBtn.selected = YES;
self.endTimeLine.backgroundColor = [UIColor colorWithHexString:@"#333333"];
self.beginTimeBtn.selected = NO;
self.beginTimeLine.backgroundColor = [UIColor colorWithHexString:@"#BBBBBB"];
}
-(void)cancelAction{
[self hide];
}
-(void)doneAction{
if ([self.beginTimeBtn.titleLabel.text isEqualToString:@"开始时间"]) {
showToast(@"请选择开始时间");
return;
}
if ([self.endTimeBtn.titleLabel.text isEqualToString:@"结束时间"]) {
showToast(@"请选择结束时间");
return;
}
NSComparisonResult result = [self.endDate compare:self.beginDate];
if (result == NSOrderedAscending) {
showToast(@"结束时间早于开始时间");
return;
}
[self hide];
if (self.chooseDateBlock) {
self.chooseDateBlock(self.beginTimeBtn.titleLabel.text, self.endTimeBtn.titleLabel.text);
}
if (self.selectedDateBlock) {
self.selectedDateBlock(self.beginTimeBtn.titleLabel.text, self.beginDate, self.endTimeBtn.titleLabel.text, self.endDate);
}
}
-(void)show{
for (UIWindow *w in [UIApplication sharedApplication].windows) {
if ([w isKeyWindow]) {
[w addSubview:self];
break;
}
}
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT-ScaleWidth(400);
}];
}
-(void)hide{
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
-(void)setPickerMode:(BRDatePickerMode)pickerMode{
_pickerMode = pickerMode;
self.pickerView.pickerMode = pickerMode;
}
-(BRDatePickerView *)pickerView{
if (!_pickerView) {
_pickerView = [[BRDatePickerView alloc] initWithPickerMode:BRDatePickerModeYMD];
_pickerView.maxDate = [NSDate date];
_pickerView.minDate = [NSDate br_setYear:2020];
_pickerView.selectDate = [NSDate date];
_pickerView.isAutoSelect = YES;
MJWeakSelf
_pickerView.resultBlock = ^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
if (weakSelf.beginTimeBtn.selected) {
[weakSelf.beginTimeBtn setTitle:selectValue forState:(UIControlStateNormal)];
weakSelf.beginDate = selectDate;
}else{
[weakSelf.endTimeBtn setTitle:selectValue forState:(UIControlStateNormal)];
weakSelf.endDate = selectDate;
}
};
}
return _pickerView;
}
@end