CNBPersonalInfoCell.m 16.1 KB
//
//  CNBPersonalInfoCell.m
//  CNLiveBPersonalVerificationModule
//
//  Created by 殷巧娟 on 2020/4/14.
//

#import "CNBPersonalInfoCell.h"
#import "CNLivePerAuthGetImage.h"
#import "CNBPerCertificationSuccessModel.h"
#import "CNBImageZoom.h"

#import <Masonry/Masonry.h>
#import <CNLiveCommonCategory/UIColor+CNLiveExtension.h>
#import <CNLiveBaseKit/CNLiveBaseKit.h>
#import <QMUIKit/QMUIKit.h>
#import <SDWebImage/SDWebImage.h>
#import <MJExtension/MJExtension.h>

#pragma mark - 身份证cell
@interface CNBPersonalInfoCell ()
@property (nonatomic, strong) UILabel *nameLabel; //名字名称
@property (nonatomic, strong) UILabel *cardLabel;  //身份证号
@property (nonatomic, strong) UIImageView *photoImageV; //图片
@property (nonatomic, strong) UIImageView *authImageV; //认证图片
@property (nonatomic, strong) UIView  *bgView;
@property (nonatomic, assign) CGSize imageSize;
@end

@implementation CNBPersonalInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self configUI];
    }
    return self;
}
#pragma mark - 配置UI
- (void)configUI{
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.cardLabel];
    [self.contentView addSubview:self.photoImageV];
    [self.contentView addSubview:self.authImageV];
    [self addMasony];
}
- (void)addMasony {
    __weak typeof(self) weakSelf = self;
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.contentView.mas_left).offset(11.5);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).offset(-150);
        make.top.mas_equalTo(weakSelf.contentView.mas_top).offset(20);
        make.height.mas_equalTo(15);
    }];
    [_cardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.contentView.mas_left).offset(11.5);
         make.right.mas_equalTo(weakSelf.contentView.mas_right).offset(-150);
        make.top.mas_equalTo(weakSelf.nameLabel.mas_bottom).offset(12);
        make.height.mas_equalTo(10);
    }];
    [_photoImageV mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.mas_equalTo(weakSelf.contentView.mas_left).offset(11.5);
        make.top.mas_equalTo(weakSelf.cardLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(101, 151));
    }];
    [_authImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakSelf.contentView.mas_right).mas_offset(-28);
        make.top.mas_equalTo(weakSelf.contentView.mas_top).offset(26);
        make.size.mas_equalTo(CGSizeMake(81, 81));
    }];
}
#pragma mark - GetterAndSetter
- (void)setInfoModel:(CNBUserInfoModel *)infoModel {
    _infoModel = infoModel;
   self.nameLabel.text = [self replaceWithOriginalStr:infoModel.realName startLocation:0 length:infoModel.realName.length - 1];
    self.cardLabel.text = [self replaceCardWithOriginalStr:infoModel.idCardNo];
    __weak typeof(self) weakSelf = self;
    UIImage *placeholder = [UIImage qmui_imageWithColor:[UIColor qmui_colorWithHexString:@"#F9F9F9"] size:CGSizeMake(101, 151) cornerRadius:0];
    [_photoImageV sd_setImageWithURL:[NSURL URLWithString:infoModel.icon] placeholderImage:placeholder completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        weakSelf.photoImageV.image = image;
    }];
}
#pragma mark - 颜色转成image
- (UIImage *)creatImageWithColor:(UIColor *)color {
    
    CGRect rect = CGRectMake(0.0f, 0.0f, 101.f, 151.f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context,[color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
#pragma mark -姓名替换字符串
- (NSString *)replaceWithOriginalStr:(NSString *)originalStr startLocation:(NSInteger)startLocation length:(NSInteger)length {
    NSString *newStr = originalStr;
    for (int i = 0 ; i < length; i ++ ) {
        NSRange range = NSMakeRange(startLocation, 1);
        newStr = [newStr stringByReplacingCharactersInRange:range withString:@"*"];
        startLocation ++;
    }
    return newStr;
}
#pragma mark - 身份证替换
- (NSString *)replaceCardWithOriginalStr:(NSString *)originalStr {
    NSString *xingStr = @"";
    for (int i = 0; i< originalStr.length - 10; i++) {
        xingStr = [xingStr stringByAppendingString:@"*"];
    }
    originalStr = [NSString stringWithFormat:@"%@ %@ %@",

    [originalStr substringToIndex:6],xingStr,

    [originalStr substringFromIndex:originalStr.length-4]];
    return originalStr;
}
#pragma mark -身份证点击放大预览
- (void)tapAction:(UITapGestureRecognizer *)tap {
    UIImageView *clickedImageView = (UIImageView *)tap.view;
    if (clickedImageView.image && [clickedImageView.image isKindOfClass:[UIImage class]]) {
        [CNBImageZoom imageZoomWithImageView:clickedImageView];
    }
       
}
#pragma mark -lazy
- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.textColor = CNLiveColorWithHexString(@"1A1A1A");
        _nameLabel.font = [UIFont systemFontOfSize:16];
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.numberOfLines = 0;
        _nameLabel.text = @"**哈";
    }
    return _nameLabel;
}
- (UILabel *)cardLabel {
    if (!_cardLabel) {
        _cardLabel = [[UILabel alloc]init];
        _cardLabel.textColor = CNLiveColorWithHexString(@"9C9C9C");
        _cardLabel.font = [UIFont systemFontOfSize:12];
        _cardLabel.numberOfLines = 1;
        _cardLabel.textAlignment = NSTextAlignmentLeft;
        _cardLabel.text = @"1****0";
    }
    return _cardLabel;
}
- (UIImageView *)photoImageV {
    if (!_photoImageV) {
        _photoImageV = [[UIImageView alloc]init];
        _photoImageV.contentMode = UIViewContentModeScaleAspectFit;
        _photoImageV.userInteractionEnabled = YES;
        _photoImageV.layer.cornerRadius = 5;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
        [_photoImageV addGestureRecognizer:tap];
    }
    return _photoImageV;
}
- (UIImageView *)authImageV {
    if (!_authImageV) {
        _authImageV = [[UIImageView alloc]init];
        _authImageV.image =[CNLivePerAuthGetImage cnLivePerAuth_getImageName:@"authSuccess" bundle:@"CNLiveBPersonalVerificationModule.bundle/CNLiveBPersonalVerificationModule" targetClass:[self class]];
        _authImageV.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _authImageV;
}
@end
#pragma mark - 机构cell
@interface CNBInstitutionsInfoCell ()
@property (nonatomic, strong) UILabel *institutionsLabel; //圈子
@property (nonatomic, strong) UILabel *institutionsDescLabel;
@end

@implementation CNBInstitutionsInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
         self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self configUI];
    }
    return self;
}
#pragma mark - 配置UI
- (void)configUI {
    [self.contentView addSubview:self.institutionsLabel];
    [self.contentView addSubview:self.institutionsDescLabel];
    __weak typeof(self) weakSelf = self;
    [_institutionsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.contentView.mas_left).offset(12);
        make.top.mas_equalTo(weakSelf.contentView.mas_top).offset(14);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(118);
    }];
    [_institutionsDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.institutionsLabel.mas_right).offset(8);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).offset(-15);
        make.top.mas_equalTo(weakSelf.contentView.mas_top).offset(14);
        make.height.mas_equalTo(12);
    }];
}
- (void)setInstitutionModel:(CNBInstitutionModel *)institutionModel {
    _institutionModel = institutionModel;
    _institutionsDescLabel.text = institutionModel.mainName;
}
#pragma mark -Lazy
- (UILabel *)institutionsLabel {
    if (!_institutionsLabel) {
        _institutionsLabel = [[UILabel alloc]init];
        _institutionsLabel.textColor = CNLiveColorWithHexString(@"333333");
        _institutionsLabel.font = [UIFont systemFontOfSize:12.5];
        _institutionsLabel.numberOfLines = 1;
        _institutionsLabel.text = @"所属机构 (主账号) :";
        _institutionsLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _institutionsLabel;
}
- (UILabel *)institutionsDescLabel {
    if (!_institutionsDescLabel) {
        _institutionsDescLabel = [[UILabel alloc]init];
        _institutionsDescLabel.textColor = CNLiveColorWithHexString(@"B9B9B9");
        _institutionsDescLabel.font = [UIFont systemFontOfSize:12.5];
        _institutionsDescLabel.numberOfLines = 1;
        _institutionsDescLabel.textAlignment = NSTextAlignmentLeft;
        _institutionsDescLabel.text = @"北京中投视讯文化传媒股份有限公司";
    }
    return _institutionsDescLabel;
}
@end
#pragma mark -群组cell
@interface CNBGroupInfoCell ()
@property (nonatomic, strong) UILabel *circleLabel; //圈子
@property (nonatomic, strong) UILabel *circleDescLabel;
@property (nonatomic, strong) UILabel *groupLabel; //群组
@property (nonatomic, strong) UIView  *groupDesView;
@property (nonatomic, strong) UIView  *middleline;  //中间的line
@end
@implementation CNBGroupInfoCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}
#pragma mark - 配置UI
- (void)configUI {
    [self.contentView addSubview:self.circleLabel];
    [self.contentView addSubview:self.circleDescLabel];
    [self.contentView addSubview:self.middleline];
    [self.contentView addSubview:self.groupLabel];
    [self.contentView addSubview:self.groupDesView];
    __weak typeof(self) weakSelf = self;
    [_circleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.contentView.mas_left).offset(12);
        make.top.mas_equalTo(weakSelf.contentView.mas_top).offset(14);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(118);
    }];
    [_circleDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.circleLabel.mas_right).offset(8);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).offset(-15);
        make.top.mas_equalTo(weakSelf.contentView.mas_top).offset(14);
        make.height.mas_equalTo(12);
    }];
    [_middleline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.circleLabel.mas_bottom).offset(14);
        make.left.right.mas_equalTo(weakSelf.contentView);
        make.height.mas_equalTo(0.5);
    }];
    [_groupLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo (weakSelf.middleline.mas_bottom).offset(14);
        make.left.mas_equalTo(weakSelf.contentView.mas_left).offset(12);
        make.width.mas_equalTo(118);
        make.height.mas_equalTo(12);
    }];
    [_groupDesView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.groupLabel.mas_right);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).offset(-15);
         make.top.mas_equalTo (weakSelf.middleline.mas_bottom).offset(8.5);
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).offset(-10);
    }];
    
}
- (void)setCircleModel:(CNBCirccleModel *)circleModel {
    _circleModel = circleModel;
    _circleDescLabel.text = CNLiveStringIsEmpty(circleModel.quanziName)? @"" :circleModel.quanziName;
    NSMutableArray *groupArray = [NSMutableArray array];
    if (circleModel.groupItem && circleModel.groupItem.count > 0) {
         [self setTagView:circleModel.groupItem];
    }else {
       NSArray *noneArray = @[@{@"groupId":@"",@"groupName":@"无"},
        ];
        for (NSDictionary *dic in noneArray) {
            CNBGroupModel *model = [CNBGroupModel mj_objectWithKeyValues:dic];
            [groupArray addObject:model];
        }
//        array = groupArray.copy;
        [self setTagView:groupArray.copy];
    }
//    [self setTagView:circleModel.groupItem];
}
#pragma mark -展示标签列表
- (void)setTagView:(NSArray *)array {
    CGFloat tagsTotalWidth = 8;
    CGFloat tagsTotalHeigh = 0;
    CGFloat tagHeight = 0;
    [self.groupDesView qmui_removeAllSubviews];
//    if (array && array.count > 0) {
        for (CNBGroupModel *groupModel in array) {
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(tagsTotalWidth, tagsTotalHeigh, 0, 0)];
            label.font = [UIFont systemFontOfSize:12];
            label.textAlignment = NSTextAlignmentCenter;
            if ([groupModel.groupName isEqualToString:@"无"]) {
                label.textColor = CNLiveColorWithHexString(@"B9B9B9");
            }else {
                label.layer.cornerRadius = 5;
                label.layer.borderWidth = 1;
                label.layer.borderColor = CNLiveColorWithHexString(@"48A7F9").CGColor;
                label.textColor = CNLiveColorWithHexString(@"48A7F9");
            }
            label.text = groupModel.groupName;
            [label sizeToFit];
            label.frame = CGRectMake(tagsTotalWidth, tagsTotalHeigh, CGRectGetWidth(label.frame) + 7.5, CGRectGetHeight(label.frame)+7.5);
            
            tagsTotalWidth += CGRectGetWidth(label.frame)+8;
            tagHeight = CGRectGetHeight(label.frame);
            if (tagsTotalWidth > KScreenWidth - 170) {
                tagsTotalHeigh += CGRectGetHeight(label.frame) + 7.5;
                           tagsTotalWidth = 8;
                           label.frame = CGRectMake(tagsTotalWidth, tagsTotalHeigh, CGRectGetWidth(label.frame) + 7.5, CGRectGetHeight(label.frame));
                           tagsTotalWidth += CGRectGetWidth(label.frame)+7.5;
            }
             [self.groupDesView addSubview:label];
            
        }
        tagsTotalHeigh += tagHeight;
        [_groupDesView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(tagsTotalHeigh);
        }];

}
#pragma mark -Lazy
- (UILabel *)circleLabel {
    if (!_circleLabel) {
        _circleLabel = [[UILabel alloc]init];
        _circleLabel.textColor = CNLiveColorWithHexString(@"333333");
        _circleLabel.font = [UIFont systemFontOfSize:12.5];
        _circleLabel.numberOfLines = 1;
        _circleLabel.text = @"您的圈子 (子账号) :";
        _circleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _circleLabel;
}
- (UILabel *)circleDescLabel {
    if (!_circleDescLabel) {
        _circleDescLabel = [[UILabel alloc]init];
        _circleDescLabel.textColor = CNLiveColorWithHexString(@"B9B9B9");
        _circleDescLabel.font = [UIFont systemFontOfSize:12.5];
        _circleDescLabel.numberOfLines = 1;
        _circleDescLabel.textAlignment = NSTextAlignmentLeft;
        _circleDescLabel.text = @"无";
    }
    return _circleDescLabel;
}
- (UIView *)middleline {
    if (!_middleline) {
        _middleline = [[UIView alloc]init];
        _middleline.backgroundColor = CNLiveColorWithHexString(@"EDEDED");
    }
    return _middleline;
}
- (UILabel *)groupLabel {
    if (!_groupLabel) {
        _groupLabel = [[UILabel alloc]init];
        _groupLabel.textColor = CNLiveColorWithHexString(@"333333");
        _groupLabel.font = [UIFont systemFontOfSize:13];
        _groupLabel.text = @"圈子群组 (子群组) :";
        _groupLabel.numberOfLines = 1;
    }
    return _groupLabel;
}
- (UIView *)groupDesView {
    if (!_groupDesView) {
        _groupDesView = [[UIView alloc]init];
        _groupDesView.backgroundColor = [UIColor whiteColor];
    }
    return _groupDesView;
}
@end