Files
xj-ios/XinjiangProject/XinjiangProject/Project/SOS/View/XJSOSAddressView.m
T

260 lines
8.4 KiB
Objective-C

//
// XJSOSAddressView.m
// XinjiangProject
//
// Created by 仁康信息 on 2023/6/2.
//
#import "XJSOSAddressView.h"
#import "PaddingLabel.h"
@interface XJSOSAddressView ()
@property (nonatomic, strong) PaddingLabel * lvLabel;
@property (nonatomic, strong) UILabel * hospitalName;
@property (nonatomic, strong) UILabel * phoneLabel;
@property (nonatomic, strong) UILabel * addressLabel;
@property (nonatomic, strong) UIButton * samllPhoneBtn;
@end
@implementation XJSOSAddressView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self createUI];
}
return self;
}
- (void)createUI {
self.layer.cornerRadius = 10;
self.layer.masksToBounds = true;
self.lvLabel = [[PaddingLabel alloc] init];
self.lvLabel.layer.cornerRadius = 3.0f;
self.lvLabel.textInsets = UIEdgeInsetsMake(0, 6, 0, 6); // 上下0,左右6
self.lvLabel.layer.masksToBounds = true;
self.lvLabel.text = @"--";
self.lvLabel.textColor = KWhiteColor;
self.lvLabel.backgroundColor = UIColorHex(#21BEBD);
self.lvLabel.textAlignment = NSTextAlignmentCenter;
self.lvLabel.font = MEDIUMFONT(9);
self.lvLabel.hidden = true;
[self addSubview:self.lvLabel];
[self.lvLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kRealValue(18));
make.top.mas_offset(20);
make.height.mas_offset(16);
}];
[self.lvLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
self.hospitalName = [[UILabel alloc] init];
self.hospitalName.text = @"--";
self.hospitalName.font = BOLDSYSTEMFONT(14);
self.hospitalName.textColor = UIColorHex(#333333);
self.hospitalName.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.hospitalName];
[self.hospitalName mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.lvLabel.mas_right).offset(10);
make.right.mas_offset(-30);
make.top.mas_offset(20);
make.height.mas_offset(15);
}];
self.phoneLabel = [[UILabel alloc] init];
self.phoneLabel.text = @"--";
self.phoneLabel.font = MEDIUMFONT(13);
self.phoneLabel.textColor = UIColorHex(#999999);
self.phoneLabel.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.phoneLabel];
[self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kRealValue(15));
make.right.mas_offset(-30);
make.top.mas_equalTo(self.lvLabel.mas_bottom).offset(11);
make.height.mas_offset(13);
}];
self.addressLabel = [[UILabel alloc] init];
self.addressLabel.text = @"--km | ---";
self.addressLabel.font = MEDIUMFONT(13);
self.addressLabel.numberOfLines = 0;
self.addressLabel.textColor = UIColorHex(#999999);
[self addSubview:self.addressLabel];
[self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kRealValue(18));
make.right.mas_offset(kRealValue(-15));
make.top.mas_equalTo(self.phoneLabel.mas_bottom).offset(11);
make.bottom.mas_offset(-26);
}];
[self.addressLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
UIButton * closeBtn = [[UIButton alloc] init];
[closeBtn setImage:IMAGE_NAMED(@"close_icon") forState:UIControlStateNormal];
[closeBtn addTarget:self action:@selector(closePopView) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:closeBtn];
[closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_offset(kRealValue(-15));
make.top.mas_equalTo(@10);
make.width.height.mas_offset(20);
}];
UIButton * navBtn = [[UIButton alloc] init];
[navBtn setImage:IMAGE_NAMED(@"address_NavLoctaion") forState:UIControlStateNormal];
[navBtn addTarget:self action:@selector(navLocationView) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:navBtn];
[navBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_offset(kRealValue(-21));
make.top.mas_equalTo(self.hospitalName.mas_bottom).offset(4);
make.width.height.mas_offset(26);
}];
UIButton * samllPhoneBtn = [[UIButton alloc] init];
[samllPhoneBtn setImage:IMAGE_NAMED(@"address_phone") forState:UIControlStateNormal];
[samllPhoneBtn addTarget:self action:@selector(LocationPhoneView) forControlEvents:UIControlEventTouchUpInside];
self.samllPhoneBtn = samllPhoneBtn;
[self addSubview:samllPhoneBtn];
[samllPhoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(navBtn.mas_left).offset(-14);
make.top.mas_equalTo(self.hospitalName.mas_bottom).offset(4);
make.width.height.mas_offset(26);
}];
}
- (void)setResourceModel:(XJSOSResourcesModel *)resourceModel {
_resourceModel = resourceModel;
if ( !ValidStr(_resourceModel.level_dictText) ) {
self.lvLabel.hidden = false;
self.lvLabel.text = _resourceModel.level_dictText;
[self.hospitalName mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.lvLabel.mas_right).offset(10);
make.right.mas_offset(-30);
make.top.mas_offset(20);
make.height.mas_offset(15);
}];
}else
{
[self.hospitalName mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kRealValue(18));
make.right.mas_offset(-30);
make.top.mas_offset(20);
make.height.mas_offset(15);
}];
}
self.addressLabel.text = [NSString stringWithFormat:@"%@",_resourceModel.address];
self.hospitalName.text = _resourceModel.name;
if (!ValidStr(_resourceModel.mobile)) {
self.phoneLabel.text = _resourceModel.mobile;
self.samllPhoneBtn.hidden = false;
[self.addressLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kRealValue(18));
make.right.mas_offset(kRealValue(-15));
make.top.mas_equalTo(self.phoneLabel.mas_bottom).offset(11);
make.bottom.mas_offset(-25);
}];
}else
{
self.phoneLabel.text = @"";
self.samllPhoneBtn.hidden = true;
[self.addressLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kRealValue(18));
make.right.mas_offset(kRealValue(-15));
make.top.mas_equalTo(self.hospitalName.mas_bottom).offset(11);
make.bottom.mas_offset(-25);
}];
}
}
- (void)setAedModel:(XJHealthInterveneAEDModel *)aedModel {
_aedModel = aedModel;
[self.hospitalName mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kRealValue(18));
make.right.mas_offset(-30);
make.top.mas_offset(20);
make.height.mas_offset(15);
}];
self.addressLabel.text = [NSString stringWithFormat:@"%.2f | %@",_aedModel.distance / 1000.0, _aedModel.resourceAddress] ;
self.hospitalName.text = _aedModel.resourceName;
if (!ValidStr(_aedModel.principalPhone)) {
self.phoneLabel.text = _aedModel.principalPhone;
self.samllPhoneBtn.hidden = false;
}else
{
self.phoneLabel.text = @"";
self.samllPhoneBtn.hidden = true;
}
}
- (void)navLocationView {
if ([self.addressDelegate respondsToSelector:@selector(addressNavLocataion)]) {
[self.addressDelegate addressNavLocataion];
}
}
- (void)LocationPhoneView {
if ([self.addressDelegate respondsToSelector:@selector(resourcePhoneOnclick:)]) {
if (self.resourceModel) {
[self.addressDelegate resourcePhoneOnclick:self.resourceModel.mobile];
}
if (self.aedModel ) {
[self.addressDelegate resourcePhoneOnclick:self.aedModel.principalPhone];
}
}
}
- (void)closePopView {
if ([self.addressDelegate respondsToSelector:@selector(showBottomBtn)]) {
[self.addressDelegate showBottomBtn];
}
[self removeFromSuperview];
}
@end