//
|
// PBPublishCommentCell.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2019/1/18.
|
// Copyright © 2019 ProBIM. All rights reserved.
|
//
|
|
#import "PBPublishCommentCell.h"
|
#import "PBProjectModel.h"
|
#import "PBCommentsModel.h"
|
#import "PBImageCollectionViewCell.h"
|
|
#define ALineCount 3
|
#define Spacing 10
|
static NSString *const cellID = @"cellID";
|
@interface PBPublishCommentCell()<UICollectionViewDataSource, UICollectionViewDelegate, SDPhotoBrowserDelegate>
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
@property (assign, nonatomic) CGFloat itemWH;
|
@property (nonatomic, weak) UIImageView *iconImageV;
|
@property (nonatomic, weak) UILabel *creatorL;
|
@property (nonatomic, weak) UILabel *textL;
|
@property (nonatomic, weak) UILabel *creatimeL;
|
@property (nonatomic, weak) UIButton *functionBtn;
|
@property (nonatomic, weak) UILabel *iconL;
|
@end
|
@implementation PBPublishCommentCell
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
[self setupUI];
|
}
|
return self;
|
}
|
- (void)setupUI {
|
UIImageView *iconImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Issue_comments_iconbg"]];
|
[self.contentView addSubview:iconImageV];
|
[iconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.contentView).offset(8);
|
make.left.equalTo(self.contentView).offset(16);
|
make.size.mas_equalTo(CGSizeMake(30, 30));
|
}];
|
UILabel *iconL = [UILabel z_labelWithText:@"" Color:[UIColor whiteColor] isBold:YES Font:DescFontSize];
|
iconL.textAlignment = NSTextAlignmentCenter;
|
[iconImageV addSubview:iconL];
|
[iconL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.left.right.equalTo(iconImageV);
|
make.height.equalTo(@20);
|
make.center.equalTo(iconImageV);
|
}];
|
|
UILabel *creatorL = [UILabel z_labelWithText:@"" Color:TitleColor isBold:YES Font:TitleFontSize];
|
[self.contentView addSubview:creatorL];
|
[creatorL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.contentView).offset(8);
|
make.left.equalTo(iconImageV.mas_right).offset(8);
|
make.height.equalTo(@22);
|
make.right.equalTo(self.contentView).offset(-16);
|
}];
|
|
UILabel *textL = [UILabel z_labelWithText:@"" Color:TitleColor isBold:NO Font:CommentsSize];
|
textL.numberOfLines = 0;
|
[self.contentView addSubview:textL];
|
[textL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(creatorL.mas_bottom).offset(8);
|
make.left.equalTo(self.contentView).offset(54);
|
make.right.equalTo(self.contentView).offset(-16);
|
}];
|
|
[self.contentView addSubview:self.collectionView];
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(textL.mas_bottom).offset(8);
|
make.left.equalTo(self.contentView).offset(54);
|
make.right.equalTo(self.contentView).offset(-16);
|
make.height.equalTo(@95);
|
make.bottom.equalTo(self.contentView).offset(-46);
|
}];
|
|
UILabel *creatimeL = [UILabel z_labelWithText:@"" Color:PromptColor isBold:NO Font:DescFontSize];
|
[self.contentView addSubview:creatimeL];
|
[creatimeL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.bottom.equalTo(self.contentView).offset(-18);
|
make.left.equalTo(self.contentView).offset(54);
|
make.height.equalTo(@20);
|
}];
|
UIButton *replyBtn = [UIButton z_textButton:@"回复TA" fontSize:DescFontSize normalColor:IndicatedColor];
|
[replyBtn addTarget:self action:@selector(replyBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.contentView addSubview:replyBtn];
|
[replyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerY.equalTo(creatimeL);
|
make.left.equalTo(creatimeL.mas_right).offset(23);
|
}];
|
|
UIButton *functionBtn = [[UIButton alloc] init];
|
[functionBtn setImage:[UIImage imageNamed:@"Issue_comment_deleteBtn"] forState:UIControlStateNormal];
|
[functionBtn addTarget:self action:@selector(deletecomment) forControlEvents:UIControlEventTouchUpInside];
|
[self.contentView addSubview:functionBtn];
|
[functionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerY.equalTo(creatimeL);
|
make.right.equalTo(self.contentView).offset(-16);
|
make.size.mas_equalTo(CGSizeMake(20, 20));
|
}];
|
|
UIView *linV = [[UIView alloc] init];
|
linV.backgroundColor = PBColor(242, 242, 242);
|
[self.contentView addSubview:linV];
|
[linV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.bottom.left.right.equalTo(self.contentView);
|
make.height.equalTo(@10);
|
}];
|
|
self.iconImageV = iconImageV;
|
self.creatorL = creatorL;
|
self.textL = textL;
|
self.creatimeL = creatimeL;
|
self.functionBtn = functionBtn;
|
self.iconL = iconL;
|
}
|
//回复
|
- (void)replyBtnAction {
|
if (self.ReplyBlock) {
|
self.ReplyBlock(self.commentsModel);
|
}
|
}
|
|
//删除
|
- (void)deletecomment {
|
if (self.deleteCommentsBlock) {
|
self.deleteCommentsBlock();
|
}
|
}
|
|
//懒加载
|
- (UICollectionView *)collectionView{
|
if (!_collectionView) {
|
UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout.alloc init];
|
CGFloat itemWH = (PBScreenWidth - 54 - 16 - (ALineCount - 1) * Spacing) / ALineCount;
|
self.itemWH = itemWH;
|
layout.itemSize = CGSizeMake(itemWH, itemWH);
|
layout.minimumLineSpacing = Spacing;
|
layout.minimumInteritemSpacing = Spacing;
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
_collectionView = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout];
|
_collectionView.backgroundColor = [UIColor clearColor];
|
[_collectionView registerClass:[PBImageCollectionViewCell class] forCellWithReuseIdentifier:cellID];
|
_collectionView.delegate = self;
|
_collectionView.dataSource = self;
|
}
|
return _collectionView;
|
}
|
|
|
- (void)setCommentsModel:(PBCommentsModel *)commentsModel {
|
_commentsModel = commentsModel;
|
self.iconL.text = commentsModel.realname;
|
self.creatorL.text = commentsModel.realname;
|
if ([commentsModel.userid isEqualToString:UserID]) {
|
self.functionBtn.hidden = NO;
|
}else {
|
self.functionBtn.hidden = YES;
|
}
|
self.textL.text = commentsModel.content;
|
NSRange range = [commentsModel.createdate rangeOfString:@":"];
|
NSString *timeStr = [commentsModel.createdate substringToIndex:range.location + 3];
|
timeStr = [timeStr stringByReplacingOccurrencesOfString:@" " withString:@" "];
|
self.creatimeL.text = [timeStr stringByReplacingOccurrencesOfString:@"-" withString:@"/"];
|
// NSInteger more = self.commentsModel.TalkDocs.count % ALineCount == 0 ? 0 : 1;
|
// NSInteger rowNumber = (self.commentsModel.TalkDocs.count / ALineCount) + more;
|
// CGFloat collectViewH = (self.itemWH * rowNumber) + (rowNumber - 1) * Spacing;
|
// collectViewH = collectViewH < 0 ? 0 : collectViewH;
|
// [self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
|
// make.height.equalTo(@(collectViewH));
|
// }];
|
// [self.collectionView reloadData];
|
}
|
|
- (void)setProjectModel:(PBProjectModel *)projectModel {
|
_projectModel = projectModel;
|
}
|
#pragma mark - UICollectionViewDataSource
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
// return self.commentsModel.TalkDocs.count;
|
return 0;
|
}
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
PBImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
|
// NSDictionary *associatedImage = self.commentsModel.TalkDocs[indexPath.row];
|
// NSString *url = [NSString stringWithFormat:@"%@/api/Doc/GetHideFile?ProjectID=%@&FileId=%@&FileType=Issue",BimUrl, self.projectModel.bimcomposerid,[associatedImage valueForKey:@"TargetID"]];
|
// cell.imageUrl = url;
|
// cell.roleType = PARTICIPANT;
|
return cell;
|
}
|
|
#pragma mark - UICollectionViewDelegate
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
SDPhotoBrowser *photoBrowser = [SDPhotoBrowser new];
|
photoBrowser.delegate = self;
|
photoBrowser.currentImageIndex = indexPath.item;
|
// photoBrowser.imageCount = self.commentsModel.TalkDocs.count;
|
photoBrowser.sourceImagesContainerView = self.collectionView;
|
[photoBrowser show];
|
|
}
|
#pragma mark - SDPhotoBrowserDelegate
|
// 返回临时占位图片(即原来的小图)
|
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
|
// 不建议用此种方式获取小图,这里只是为了简单实现展示而已
|
PBImageCollectionViewCell *cell = (PBImageCollectionViewCell *)[self collectionView:self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
|
return cell.imageV.image;
|
}
|
// 返回高质量图片的url
|
//- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index
|
//{
|
// NSString *urlStr = self.imageUrls[index];
|
// return [NSURL URLWithString:urlStr];
|
//}
|
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
[super setSelected:selected animated:animated];
|
|
// Configure the view for the selected state
|
}
|
|
@end
|