FeedbackDetailController.m 9.0 KB
//
//  FeedbackDetailController.m
//  DreamSleep
//
//  Created by peter on 2022/4/26.
//

#import "FeedbackDetailController.h"
#import "FeedbackRequestModel.h"

@interface FeedbackDetailController ()
@property (nonatomic, strong) UIScrollView *detailSV;

@property (nonatomic, strong) UIView *feedView;
@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UIView *imgContainerView;
@property (nonatomic, strong) UILabel *createdTimeLab;

@property (nonatomic, strong) UIView *replyView;
@property (nonatomic, strong) UILabel *replyTitleLab;
@property (nonatomic, strong) UILabel *replierContentLab;
@property (nonatomic, strong) UILabel *replierNameLab;
@property (nonatomic, strong) UILabel *replierTimeLab;
@end

@implementation FeedbackDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"详情信息";
    self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
    
    [FeedbackRequestModel queryAdviceDetailWithAdviceID:self.advice_id completion:^(FeedbackRequestModel * _Nonnull requestModel) {
        if (requestModel.resCode == DSResCodeSuccess) {
            [self buildUI:requestModel.feedDetailModel];
        }
    }];
}

- (void)buildUI:(MyFeedDetailModel *)detailModel {
    [self.view addSubview:self.detailSV];
    [self.detailSV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    [self.detailSV addSubview:self.feedView];
    [self.feedView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.detailSV.mas_top).offset(15);
        make.left.equalTo(self.view).offset(15);
        make.right.equalTo(self.view).offset(-15);
    }];
    
    [self.feedView addSubview:self.contentLab];
    self.contentLab.text = detailModel.content;
    [self.contentLab sizeToFit];
    [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.feedView).offset(8);
        make.top.equalTo(self.feedView).offset(8);
        make.right.equalTo(self.feedView).offset(-8);
    }];
    
    BOOL hasImg = NO;
    if (detailModel.content_img && detailModel.content_img.length > 0) {
        hasImg = YES;
        [self.feedView addSubview:self.imgContainerView];
        [self.imgContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.feedView).offset(8);
            make.top.equalTo(self.contentLab.mas_bottom).offset(20);
            make.right.equalTo(self.feedView).offset(-8);
            make.height.equalTo(@105);
        }];
        
        // 截取图片字符串链接
        NSArray *imgUrls = [detailModel.content_img componentsSeparatedByString:@","];
        for (int i = 0; i < imgUrls.count; i++) {
            UIImageView *showIV = [[UIImageView alloc] initWithFrame:CGRectMake(i*(105 + 8), 0, 105, 105)];
            showIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .5, .5);
            [showIV yy_setImageWithURL:[NSURL URLWithString:imgUrls[i]] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
            [showIV cornerRadius:12.0];
            [self.imgContainerView addSubview:showIV];
            UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRAction:)];
            [showIV addGestureRecognizer:tapGR];
            showIV.userInteractionEnabled = YES;
        }
    }
    
    [self.feedView addSubview:self.createdTimeLab];
    self.createdTimeLab.text = detailModel.created_at;
    [self.createdTimeLab sizeToFit];
    [self.createdTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.feedView).offset(-8);
        make.bottom.equalTo(self.feedView).offset(-8);
        make.top.equalTo(hasImg ? self.imgContainerView.mas_bottom : self.contentLab.mas_bottom).offset(39);
    }];
    
    UIView *lastView = self.feedView;
    // 判断是否有回复信息
    if (detailModel.replier_content && detailModel.replier_content.length > 0) {
        [self.detailSV addSubview:self.replyView];
        lastView = self.replyView;
        [self.replyView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(15);
            make.right.equalTo(self.view).offset(-15);
            make.top.equalTo(self.feedView.mas_bottom).offset(15);
        }];
        
        [self.replyView addSubview:self.replyTitleLab];
        [self.replyTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.replyView).offset(8);
            make.top.equalTo(self.replyView).offset(15);
        }];
        
        [self.replyView addSubview:self.replierContentLab];
        self.replierContentLab.text = detailModel.replier_content;
        [self.replierContentLab sizeToFit];
        [self.replierContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.replyTitleLab.mas_bottom).offset(12);
            make.left.equalTo(self.replyView).offset(8);
            make.right.equalTo(self.replyView).offset(-8);
        }];
        
        [self.replyView addSubview:self.replierNameLab];
        self.replierNameLab.text = [NSString stringWithFormat:@"回复人:%@", detailModel.replier_name];
        [self.replyTitleLab sizeToFit];
        [self.replierNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.replierContentLab.mas_bottom).offset(46);
            make.right.equalTo(self.replyView).offset(-8);
        }];
        
        [self.replyView addSubview:self.replierTimeLab];
        self.replierTimeLab.text = [NSString stringWithFormat:@"回复时间:%@", detailModel.replier_time];
        [self.replierTimeLab sizeToFit];
        [self.replierTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.replierNameLab.mas_bottom).offset(8);
            make.right.equalTo(self.replyView).offset(-8);
            make.bottom.equalTo(self.replyView).offset(-15);
        }];
    }
    [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.detailSV.mas_bottom).offset(-15);
    }];
}

- (void)tapGRAction:(UITapGestureRecognizer *)gr {
    UIImageView *showIV = (UIImageView *)gr.view;
    showIV.image;
    DSLog(@"=========");
}

#pragma mark - 品牌模式
- (NaviStyle)navigationBarStyle {
    return NaviStyleDefault;
}

#pragma mark - lazy
- (UIScrollView *)detailSV {
    if (!_detailSV) {
        _detailSV = [UIScrollView new];
        _detailSV.showsVerticalScrollIndicator = NO;
        _detailSV.contentSize = CGSizeMake(kScreenWidth, 1000);
    }
    return _detailSV;
}

- (UIView *)feedView {
    if (!_feedView) {
        _feedView = [UIView new];
        [_feedView cornerRadius:12.0];
        _feedView.dk_backgroundColorPicker = DKColorPickerWithKey(CornerViewBG);
    }
    return _feedView;
}

- (UILabel *)contentLab {
    if (!_contentLab) {
        _contentLab = [UILabel labWithFont:SysFont(14)];
        _contentLab.numberOfLines = 0;
        _contentLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, DarkTextColor, DSWhite);
    }
    return _contentLab;
}

- (UILabel *)createdTimeLab {
    if (!_createdTimeLab) {
        _createdTimeLab = [UILabel labWithFont:SysFont(12)];
        _createdTimeLab.textAlignment = NSTextAlignmentRight;
        _createdTimeLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHex(0x5C6274), DSWhite);
    }
    return _createdTimeLab;
}

- (UIView *)imgContainerView {
    if (!_imgContainerView) {
        _imgContainerView = [UIView new];
    }
    return _imgContainerView;
}

- (UIView *)replyView {
    if (!_replyView) {
        _replyView = [UIView new];
        [_replyView cornerRadius:12.0];
        _replyView.dk_backgroundColorPicker = DKColorPickerWithKey(CornerViewBG);
    }
    return _replyView;
}

- (UILabel *)replyTitleLab {
    if (!_replyTitleLab) {
        _replyTitleLab = [UILabel labWithText:@"回复内容" textColor:ColorFromHex(0xF04B77) font:BoldFont(16.0)];
        [_replyTitleLab sizeToFit];
    }
    return _replyTitleLab;
}

- (UILabel *)replierContentLab {
    if (!_replierContentLab) {
        _replierContentLab = [UILabel labWithFont:SysFont(14)];
        _replierContentLab.numberOfLines = 0;
        _replierContentLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, DarkTextColor, DSWhite);
    }
    return _replierContentLab;
}

- (UILabel *)replierNameLab {
    if (!_replierNameLab) {
        _replierNameLab = [UILabel labWithFont:SysFont(12)];
        _replierNameLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHex(0x5C6274), DSWhite);
        _replierNameLab.textAlignment = NSTextAlignmentRight;
    }
    return _replierNameLab;
}

- (UILabel *)replierTimeLab {
    if (!_replierTimeLab) {
        _replierTimeLab = [UILabel labWithFont:SysFont(12)];
        _replierTimeLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHex(0x5C6274), DSWhite);
        _replierTimeLab.textAlignment = NSTextAlignmentRight;
    }
    return _replierTimeLab;
}

@end