CNLiveBindingManageCell.m 5.43 KB
//
//  CNLiveBindingManageCell.m
//  CNLiveNetAdd
//
//  Created by CNLive-zxw on 2019/9/10.
//  Copyright © 2019 cnlive. All rights reserved.
//

#import "CNLiveBindingManageCell.h"
#import <Masonry/Masonry.h>

#import "CNLiveBindingManageModel.h"
#import "CNLiveBindingManageRequest.h"

@interface CNLiveBindingManageCell()
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *desc;
@property (nonatomic, strong) UIButton *manage;
@property (nonatomic, strong) UIView *line;

@end
@implementation CNLiveBindingManageCell
static NSInteger const margin = 15;

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self createSubViews];
    }
    return self;
}
- (void)setModel:(CNBindingManageModel *)model{
    _model = model;
    _icon.image = [UIImage imageNamed:model.image];
    _title.text = model.title;
    _desc.text = model.desc;
    if([model.isBinding isEqualToString:@"1"]){
        _manage.backgroundColor = RGBOF(0xd9d9d9);
        [_manage setTitle:@"已绑定" forState:UIControlStateNormal];

    }else{
        _manage.backgroundColor = RGBOF(0x23d41e);
        [_manage setTitle:@"未绑定" forState:UIControlStateNormal];

    }

}
#pragma mark - setupUI
- (void)createSubViews {
    [self.contentView addSubview:self.icon];
    [self.contentView addSubview:self.title];
    [self.contentView addSubview:self.desc];
    [self.contentView addSubview:self.manage];
    [self.contentView addSubview:self.line];

}

- (void)layoutSubviews {
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(margin);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);
    }];
    
    [self.manage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView.mas_right).offset(-margin);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(30);
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon.mas_top);
        make.left.equalTo(self.icon.mas_right).offset(margin);
        make.right.equalTo(self.manage.mas_left).offset(-margin);
        make.height.mas_equalTo(25);
    }];
    
    [self.desc mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.title.mas_bottom);
        make.left.equalTo(self.title.mas_left);
        make.right.equalTo(self.title.mas_right);
        make.height.mas_equalTo(25);
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-0.5);
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.height.mas_equalTo(0.5);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - Lazy Loading
- (UIImageView *)icon {
    if (!_icon) {
        _icon = [[UIImageView alloc] init];
        _icon.contentMode = UIViewContentModeScaleAspectFill;
        _icon.layer.cornerRadius = 25;
        _icon.layer.masksToBounds = YES;
    }
    return _icon;
}
- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = RGBOF(0x333333);
        _title.font = UIFontCNMake(16);//[UIFont fontWithName:@"PingFangSC-Regular" size:15];
        _title.numberOfLines = 0;
    }
    return _title;
}
- (UILabel *)desc {
    if (!_desc) {
        _desc = [[UILabel alloc] init];
        _desc.textColor = RGBOF(0x999999);
        _desc.font = UIFontCNMake(12);//[UIFont fontWithName:@"PingFangSC-Regular" size:15];
        _desc.numberOfLines = 0;
    }
    return _desc;
}
- (UIButton *)manage {
    if (!_manage) {
        _manage = [UIButton buttonWithType:UIButtonTypeCustom];
        _manage.backgroundColor = RGBOF(0xd9d9d9);
        [_manage setTitle:@"已绑定" forState:UIControlStateNormal];
        [_manage setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _manage.titleLabel.font = UIFontCNMake(14);
        _manage.layer.cornerRadius = 15;
        _manage.layer.masksToBounds = YES;
        [_manage addTarget:self action:@selector(manageDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _manage;
}

- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = RGBOF(0xeeeeee);
    }
    return _line;
}

#pragma mark - Action
- (void)manageDidClicked:(UIButton *)btn{
    if([self.model.thirdPartyPlat isEqualToString:@"10"]){
        return;
    }
    if(![CNLiveNetworking isNetworking]){
        [QMUITips showError:@"无法连接网络" inView:AppKeyWindow hideAfterDelay:1.5];
        return ;
    }
    btn.userInteractionEnabled = NO;
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickedBindingButton:isBinding:)]) {
        [self.delegate clickedBindingButton:self isBinding:![self.model.isBinding isEqualToString:@"1"]];
        btn.userInteractionEnabled = YES;

    }
}


@end