//
//  NoticeListViewController.m
//  Macalline
//
//  Created by JianjiYuan on 14-12-1.
//  Copyright (c) 2014年 JianjiYuan. All rights reserved.
//

#import "NoticeListViewController.h"
#import "NoteDetailViewController.h"
#import "BRNetworkMgr.h"
#import "RDVTabBarController.h"
#import "DBDaoMgr.h"

@interface NoticeListViewController () < BRNetworkMgrDelegate >
{
    UILabel*lblNotice;
    UIImageView* imageNotice;
    UILabel*lblRemind;
    UIImageView* imageRemind;
}
@property(nonatomic,strong)UIButton* btnLeft;
@property(nonatomic,strong)UIButton* btnRight;
@property(nonatomic,strong)NSArray * noticeArr;

@property(nonatomic,strong)NSString * tableType;;

@end

@implementation NoticeListViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
//        self.title = @"公告信息";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _tableType = @"";
    CGFloat w = self.view.bounds.size.width;
    _btnLeft = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, w/2, 50)];
    [_btnLeft addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    _btnLeft.tag = 99;
    [_btnLeft setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:_btnLeft];
    
    lblNotice = [[UILabel alloc] init];
    lblNotice.text = @"公告";
    lblNotice.font =[UIFont systemFontOfSize:14];
    lblNotice.textColor = RGBColor(44, 172, 236, 1);
    lblNotice.textAlignment = NSTextAlignmentCenter;
    [_btnLeft addSubview:lblNotice];
    [lblNotice autoAlignAxis:ALAxisVertical toSameAxisOfView:_btnLeft];
    [lblNotice autoAlignAxis:ALAxisHorizontal toSameAxisOfView:_btnLeft withOffset:10];
    
    imageNotice = [[UIImageView alloc] init];
    imageNotice.image = [UIImage imageNamed:@"Settings/notice_pic_change.png"];
    [_btnLeft addSubview:imageNotice];
    [imageNotice autoAlignAxis:ALAxisVertical toSameAxisOfView:_btnLeft];
    [imageNotice autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:lblNotice withOffset:-2];
    [imageNotice autoSetDimensionsToSize:CGSizeMake(15, 15)];
    
    _btnRight = [[UIButton alloc] initWithFrame:CGRectMake(w/2, 0, w/2, 50)];
    [_btnRight addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_btnRight setBackgroundColor:RGBColor(54, 182, 242, 1)];
    [self.view addSubview:_btnRight];
    
    lblRemind = [[UILabel alloc] init];
    lblRemind.text = @"提醒";
    lblRemind.font =[UIFont systemFontOfSize:14];
    lblRemind.textColor = [UIColor whiteColor];
    lblRemind.textAlignment = NSTextAlignmentCenter;
    [_btnRight addSubview:lblRemind];
    [lblRemind autoAlignAxis:ALAxisVertical toSameAxisOfView:_btnRight];
    [lblRemind autoAlignAxis:ALAxisHorizontal toSameAxisOfView:_btnRight withOffset:10];
    
    imageRemind = [[UIImageView alloc] init];
    imageRemind.image = [UIImage imageNamed:@"Settings/remind_pic_change.png"];
    [_btnRight addSubview:imageRemind];
    [imageRemind autoAlignAxis:ALAxisVertical toSameAxisOfView:_btnRight];
    [imageRemind autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:lblNotice withOffset:-2];
    [imageRemind autoSetDimensionsToSize:CGSizeMake(13, 17)];
    
    if ([[DataMgr getInstance].roleId isEqualToString:@"daqufuzeren"]) {
        lblNotice.textColor = RGBColor(0, 117, 196, 1);
        [_btnLeft setBackgroundColor:[UIColor whiteColor]];
        [_btnRight setBackgroundColor:RGBColor(0, 117, 196, 1)];
    }
    else if ([[DataMgr getInstance].roleId isEqualToString:@"xiaoqufuzeren"]) {
        lblNotice.textColor = RGBColor(0, 171, 202, 1);
        [_btnLeft setBackgroundColor:[UIColor whiteColor]];
        [_btnRight setBackgroundColor:RGBColor(0, 171, 202, 1)];
    }
    else
    {
        lblNotice.textColor = RGBColor(44, 172, 236, 1);
        [_btnLeft setBackgroundColor:[UIColor whiteColor]];
        [_btnRight setBackgroundColor:RGBColor(44, 172, 236, 1)];
        
    }
    
    self.tableVContent.separatorStyle = UITableViewCellSelectionStyleNone;
}
-(void)btnClick:(UIButton*)sender
{
    self.imageVNoResult.hidden = YES;
    if (sender.tag == 99) {
        _tableType = @"";
        [self.tableVContent reloadData];
        if ([[DataMgr getInstance].roleId isEqualToString:@"daqufuzeren"]) {
            imageNotice.image = [UIImage imageNamed:@"Settings/notice_pic_change.png"];
            imageRemind.image = [UIImage imageNamed:@"Settings/remind_pic_change.png"];
            lblNotice.textColor = RGBColor(0, 117, 196, 1);
            lblRemind.textColor = [UIColor whiteColor];
            
            [_btnLeft setBackgroundColor:[UIColor whiteColor]];
            [_btnRight setBackgroundColor:RGBColor(0, 117, 196, 1)];
        }
        else if ([[DataMgr getInstance].roleId isEqualToString:@"xiaoqufuzeren"]) {
            imageNotice.image = [UIImage imageNamed:@"Settings/notice_pic_change.png"];
            imageRemind.image = [UIImage imageNamed:@"Settings/remind_pic_change.png"];
            lblNotice.textColor = RGBColor(0, 171, 202, 1);
            lblRemind.textColor = [UIColor whiteColor];
            [_btnLeft setBackgroundColor:[UIColor whiteColor]];
            [_btnRight setBackgroundColor:RGBColor(0, 171, 202, 1)];
        }
        else
        {
            imageNotice.image = [UIImage imageNamed:@"Settings/notice_pic_change.png"];
            imageRemind.image = [UIImage imageNamed:@"Settings/remind_pic_change.png"];
            lblNotice.textColor = RGBColor(44, 172, 236, 1);
            lblRemind.textColor = [UIColor whiteColor];
            
            [_btnLeft setBackgroundColor:[UIColor whiteColor]];
            [_btnRight setBackgroundColor:RGBColor(44, 172, 236, 1)];
        }
    }
    else
    {
        if ([[DataMgr getInstance].roleId isEqualToString:@"daqufuzeren"]) {
            imageNotice.image = [UIImage imageNamed:@"Settings/notice_pic.png"];
            imageRemind.image = [UIImage imageNamed:@"Settings/remind_pic.png"];
            lblNotice.textColor = [UIColor whiteColor];
            lblRemind.textColor = RGBColor(0, 117, 196, 1);
            
            [_btnRight setBackgroundColor:[UIColor whiteColor]];
            [_btnLeft setBackgroundColor:RGBColor(0, 117, 196, 1)];
        }
        else if ([[DataMgr getInstance].roleId isEqualToString:@"xiaoqufuzeren"]) {
            imageNotice.image = [UIImage imageNamed:@"Settings/notice_pic.png"];
            imageRemind.image = [UIImage imageNamed:@"Settings/remind_pic.png"];
            lblNotice.textColor = [UIColor whiteColor];
            lblRemind.textColor = RGBColor(0, 171, 202, 1);
            [_btnRight setBackgroundColor:[UIColor whiteColor]];
            [_btnLeft setBackgroundColor:RGBColor(0, 171, 202, 1)];
        }
        else
        {
            imageNotice.image = [UIImage imageNamed:@"Settings/notice_pic.png"];
            imageRemind.image = [UIImage imageNamed:@"Settings/remind_pic.png"];
            lblNotice.textColor = [UIColor whiteColor];
            lblRemind.textColor = RGBColor(44, 172, 236, 1);
            
            [_btnRight setBackgroundColor:[UIColor whiteColor]];
            [_btnLeft setBackgroundColor:RGBColor(44, 172, 236, 1)];
        }
        
        [self selectNoticeDatas];
    }
}

- (void)setViewLayoutConstraint
{
    if ([[DataMgr getInstance].roleId isEqualToString:@"daqufuzeren"]) {
        _btnLeft.hidden = YES;
        _btnRight.hidden = YES;
        [self.tableVContent autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    else
    {
        _btnLeft.hidden = NO;
        _btnRight.hidden = NO;
        [self.tableVContent autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0) excludingEdge:ALEdgeTop];
        [self.tableVContent autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.btnLeft];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationItem.leftBarButtonItems = nil;
    self.navigationController.navigationBarHidden = NO;
    self.rdv_tabBarController.navigationController.navigationBarHidden = YES;
    [self setViewLayoutConstraint];
    [self requestDatas];
    
}
-(void)selectNoticeDatas
{
    _tableType = @"notice";
    DLog(@"userID:%@",[DataMgr getInstance].userID);
    _noticeArr = [DBDaoMgr fetchNoticeByUserId:[DataMgr getInstance].userID];
    [self.tableVContent reloadData];
    if (_noticeArr.count!=0) {
        self.imageVNoResult.hidden = YES;
    }
    else
    {
        self.imageVNoResult.hidden = NO;
    }
    
}
- (void)requestDatas
{
    [UIApplication showLoadingView:kTextShowInProgress];
    NSString *interface = @"queryNoticeListEX";
    NSOperation *operation = [self.networkMgr operationWithURL:kBaseEXURL(interface)
                                                                interface:interface
                                                                   params:nil
                                                                 dataType:BRNetMgrDataTypeJSON
                                                                   method:BRNetMgrMethodPost];
    
    [self.networkMgr startOperation:operation];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark =============  BRNetworkMgr Delegate  =============
- (void)httpOperationSuccess:(AFHTTPRequestOperation *)operation
                      result:(NSDictionary *)result
{
    self.arrContents = result[@"noticeList"];
    [self.tableVContent reloadData];
    
    if (self.arrContents.count == 0 && ![_tableType isEqualToString:@"notice"]) {
        self.imageVNoResult.hidden = NO;
    }
    else
    {
        self.imageVNoResult.hidden = YES;
    }
    
}

- (void)httpOperationFailed:(AFHTTPRequestOperation *)operation
                      error:(NSError *)error
{

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([_tableType isEqualToString:@"notice"]) {
        
        static NSString *cellIdentifier = @"remindCell";
        
        RemindListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (!cell) {
            cell = [[RemindListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
        
        cell.lblTitle.text = _noticeArr[indexPath.row][@"title"];
        cell.lblContent.text =  _noticeArr[indexPath.row][@"content"];;
        cell.lblTime.text = _noticeArr[indexPath.row][@"time"];
        
        
        NSString* nid = _noticeArr[indexPath.row][@"isRead"];
        if([nid isEqualToString:@"NO"])
        {
            cell.lblTitle.textColor = [UIColor darkGrayColor];
            cell.lblContent.textColor = [UIColor darkGrayColor];
            cell.lblTime.textColor = [UIColor darkGrayColor];
            cell.view.hidden = NO;
        }
        else
        {
            cell.lblTitle.textColor = [UIColor lightGrayColor];
            cell.lblContent.textColor = [UIColor lightGrayColor];
            cell.lblTime.textColor = [UIColor lightGrayColor];
            cell.view.hidden = YES;
        }
        UIView* lineView = [[UIView alloc] init];
        lineView.backgroundColor = [UIColor lightGrayColor];
        [cell.contentView addSubview:lineView];
        [lineView autoSetDimension:ALDimensionHeight toSize:0.5];
        [lineView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 10, 0, 10) excludingEdge:ALEdgeTop];
        
        return cell;
    }
    else
    {
        NSString *cellIdentifier = @"NoticeListCell";
        NoticeListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (!cell) {
            cell = [[NoticeListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
        cell.lblTitle.text = self.arrContents[indexPath.row][@"title"];
        cell.lblcontent.text = self.arrContents[indexPath.row][@"context"];
        

        
        cell.lblCreateTime.text = [self.arrContents[indexPath.row][@"createTime"] substringToIndex:10];
        if ([self.arrContents[indexPath.row][@"isRead"] isEqualToString:@"01"]) {
            cell.lblTitle.textColor = [UIColor darkGrayColor];
            cell.lblCreateTime.textColor = [UIColor darkGrayColor];
            cell.lblcontent.textColor = [UIColor darkGrayColor];
            cell.view.hidden = NO;
        }else if ([self.arrContents[indexPath.row][@"isRead"] isEqualToString:@"02"]) {
            cell.lblTitle.textColor = [UIColor lightGrayColor];
            cell.lblCreateTime.textColor = [UIColor lightGrayColor];
            cell.lblcontent.textColor = [UIColor lightGrayColor];
            cell.view.hidden = YES;
        }
        cell.tag = 100+[self.arrContents[indexPath.row][@"isRead"] intValue];
        
        return cell;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([_tableType isEqualToString:@"notice"]) {
        NSString *strTitle = _noticeArr[indexPath.row][@"title"];
        CGFloat hight1 = [strTitle boundingRectWithSize:CGSizeMake(215, CGFLOAT_MAX)
                                                options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin
                                             attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}
                                                context:nil].size.height;
        
        NSString *strContent = _noticeArr[indexPath.row][@"content"];
        CGFloat hight2 = [strContent boundingRectWithSize:CGSizeMake(275, CGFLOAT_MAX)
                                       options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin
                                    attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}
                                       context:nil].size.height+10+22+10+5;
        if (hight2 > 20) {
            return hight1+15+40+10;
        }
        else
        {
            return hight1+15+20+10;
        }
    }
    else
    {
//        NSString *strTitle = self.arrContents[indexPath.row][@"context"];
//        return 25+5+5+[strTitle sizeWithFont:[UIFont systemFontOfSize:13]
//                           constrainedToSize:CGSizeMake(300, 190) lineBreakMode:NSLineBreakByTruncatingTail].height;
        NSString *strTitle = self.arrContents[indexPath.row][@"title"];
        CGFloat hight1 = [strTitle boundingRectWithSize:CGSizeMake(215, CGFLOAT_MAX)
                                                                    options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin
                                                                 attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}
                                                                    context:nil].size.height;
        
        NSString *contentTitle = self.arrContents[indexPath.row][@"context"];
        CGFloat hight2 = [contentTitle boundingRectWithSize:CGSizeMake(275, CGFLOAT_MAX)
                                                options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin
                                             attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}
                                                context:nil].size.height;
        if (hight2 > 20) {
            return hight1+15+40+10;
        }
        else
        {
            return hight1+15+20+10;
        }
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([_tableType isEqualToString:@"notice"]) {
        return self.noticeArr.count;
    }
    return self.arrContents.count;
}

#pragma mark =============  UITableView Delegate  =============

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.selectedIndexPath = indexPath;
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if ([_tableType isEqualToString:@"notice"]) {
//        NSDictionary* dic= self.noticeArr[indexPath.row];
//        NoteDetailViewController *detailVC = [[NoteDetailViewController alloc] initWithNotice:dic];
//        [self.rdv_tabBarController.navigationController pushViewController:detailVC animated:YES];
        NSString* nid = _noticeArr[indexPath.row][@"noticeId"];
        [DBDaoMgr updateNoticeById:nid];
        [self selectNoticeDatas];
        [[NSNotificationCenter defaultCenter] postNotificationName:kShouldReQueryCountInit object:nil];
    }
    else
    {
        NoteDetailViewController *detailVC = [[NoteDetailViewController alloc] initWithNibName:nil bundle:nil];
        detailVC.dictNotice = self.arrContents[indexPath.row];
        [self.rdv_tabBarController.navigationController pushViewController:detailVC animated:YES];
    }
}

@end

@implementation NoticeListCell

- (void)dealloc
{
    self.lblTitle = nil;
    self.lblCreateTime = nil;
    self.viewLine = nil;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.lblCreateTime autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:12];
        [self.lblCreateTime autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
        [self.lblCreateTime autoSetDimensionsToSize:CGSizeMake(80, 20)];
        
        [self.lblTitle autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:10];
        [self.lblTitle autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20];
        [self.lblTitle autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:self.lblCreateTime withOffset:-5];
        //[self.lblTitle autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:self.lblCreateTime withOffset:-10];
    
        [self.view autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.lblTitle withOffset:4];
        [self.view autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:self.lblTitle withOffset:-3];
        [self.view autoSetDimensionsToSize:CGSizeMake(6, 6)];
        
        [self.lblcontent autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20];
        [self.lblcontent autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:25];
        [self.lblcontent autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.lblTitle withOffset:10];
        [self.viewLine autoSetDimension:ALDimensionHeight toSize:0.5];
//        [self.viewLine autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.lblTitle withOffset:5];
        [self.viewLine autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 10, 0, 10) excludingEdge:ALEdgeTop];
        
        [self.imageview autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self];
        [self.imageview autoPinEdge: ALEdgeLeft toEdge:ALEdgeRight ofView:self.lblcontent withOffset:4];
        [self.imageview autoSetDimensionsToSize:CGSizeMake(8, 15)];
    }
    return self;
}

//- (void)setSelected:(BOOL)selected animated:(BOOL)animated
//{
//    [super setSelected:selected animated:animated];
//    if (selected) {
//        if (self.tag == 101) {//未读
//            self.lblCreateTime.backgroundColor = RGBColor(229, 0, 129, 1);
//        }else {
//            self.lblCreateTime.backgroundColor = [UIColor grayColor];
//        }
//        
//    }
//    
//}
//
//- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
//{
//    [super setHighlighted:highlighted animated:animated];
//    if (highlighted) {
//        if (self.tag == 101) {//未读
//            self.lblCreateTime.backgroundColor = RGBColor(229, 0, 129, 1);
//        }else {
//            self.lblCreateTime.backgroundColor = [UIColor grayColor];
//        }
//    }
//    
//}

#pragma mark =============  LazyLoad Properties  =============

- (UIView *)viewLine
{
    if (!_viewLine) {
        self.viewLine = [UIView newAutoLayoutView];
        _viewLine.backgroundColor = [UIColor lightGrayColor];
        [self.contentView addSubview:_viewLine];
    }
    return _viewLine;
}
- (UIView *)view
{
    if (!_view) {
        self.view = [UIView newAutoLayoutView];
        _view.backgroundColor = RGBColor(246, 88, 95, 1);
        _view.layer.cornerRadius = 3;
        [self.contentView addSubview:_view];
    }
    return _view;
}
- (UILabel *)lblcontent
{
    if (!_lblcontent) {
        self.lblcontent = [UILabel newAutoLayoutView];
        self.lblcontent.textAlignment = NSTextAlignmentLeft;
        self.lblcontent.backgroundColor = [UIColor clearColor];
        self.lblcontent.textColor = [UIColor blackColor];
        self.lblcontent.font = [UIFont systemFontOfSize:13];
        self.lblcontent.numberOfLines = 2;
        [self.contentView addSubview:_lblcontent];
    }
    return _lblcontent;
}

- (UILabel *)lblTitle
{
    if (!_lblTitle) {
        self.lblTitle = [UILabel newAutoLayoutView];
        self.lblTitle.textAlignment = NSTextAlignmentLeft;
        self.lblTitle.backgroundColor = [UIColor clearColor];
        self.lblTitle.textColor = [UIColor blackColor];
        self.lblTitle.font = [UIFont systemFontOfSize:15];
        self.lblTitle.numberOfLines = 0;
        [self.contentView addSubview:_lblTitle];
    }
    return _lblTitle;
}

- (UILabel *)lblCreateTime
{
    if (!_lblCreateTime) {
        self.lblCreateTime = [UILabel newAutoLayoutView];
        self.lblCreateTime.textColor = [UIColor whiteColor];
        self.lblCreateTime.textAlignment = NSTextAlignmentCenter;
        self.lblCreateTime.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_lblCreateTime];
    }
    return _lblCreateTime;
}
- (UIImageView *)imageview
{
    if (!_imageview) {
        self.imageview = [UIImageView newAutoLayoutView];
        _imageview.image = [UIImage imageNamed:@"Task_Point/image_point_arrow.png"];
        [self.contentView addSubview:_imageview];
    }
    return _imageview;
}


@end
@implementation RemindListCell

- (void)dealloc
{
    self.lblTitle = nil;
    self.lblTime = nil;
    self.lblContent = nil;
    self.view = nil;
    self.viewLine = nil;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.lblTime autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:12];
        [self.lblTime autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
        [self.lblTime autoSetDimensionsToSize:CGSizeMake(80, 20)];
        
        [self.lblTitle autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:10];
        [self.lblTitle autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20];
        [self.lblTitle autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:self.lblTime withOffset:-5];
        //[self.lblTitle autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:self.lblCreateTime withOffset:-10];
        
        [self.view autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.lblTitle withOffset:4];
        [self.view autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:self.lblTitle withOffset:-3];
        [self.view autoSetDimensionsToSize:CGSizeMake(6, 6)];
        
        [self.lblContent autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20];
        [self.lblContent autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
        [self.lblContent autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.lblTitle withOffset:10];
        [self.viewLine autoSetDimension:ALDimensionHeight toSize:0.5];
        //        [self.viewLine autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.lblTitle withOffset:5];
        [self.viewLine autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 10, 0, 10) excludingEdge:ALEdgeTop];
    }
    return self;
}
#pragma mark =============  LazyLoad Properties  =============

- (UIView *)viewLine
{
    if (!_viewLine) {
        self.viewLine = [UIView newAutoLayoutView];
        _viewLine.backgroundColor = [UIColor lightGrayColor];
        [self.contentView addSubview:_viewLine];
    }
    return _viewLine;
}
- (UIView *)view
{
    if (!_view) {
        self.view = [UIView newAutoLayoutView];
        _view.backgroundColor = RGBColor(246, 88, 95, 1);
        _view.layer.cornerRadius = 3;
        [self.contentView addSubview:_view];
    }
    return _view;
}
- (UILabel *)lblContent
{
    if (!_lblContent) {
        self.lblContent = [UILabel newAutoLayoutView];
        self.lblContent.textAlignment = NSTextAlignmentLeft;
        self.lblContent.backgroundColor = [UIColor clearColor];
        self.lblContent.textColor = [UIColor blackColor];
        self.lblContent.font = [UIFont systemFontOfSize:13];
        self.lblContent.numberOfLines = 2;
        [self.contentView addSubview:_lblContent];
    }
    return _lblContent;
}

- (UILabel *)lblTitle
{
    if (!_lblTitle) {
        self.lblTitle = [UILabel newAutoLayoutView];
        self.lblTitle.textAlignment = NSTextAlignmentLeft;
        self.lblTitle.backgroundColor = [UIColor clearColor];
        self.lblTitle.textColor = [UIColor blackColor];
        self.lblTitle.font = [UIFont systemFontOfSize:15];
        self.lblTitle.numberOfLines = 0;
        [self.contentView addSubview:_lblTitle];
    }
    return _lblTitle;
}

- (UILabel *)lblTime
{
    if (!_lblTime) {
        self.lblTime = [UILabel newAutoLayoutView];
        self.lblTime.textColor = [UIColor whiteColor];
        self.lblTime.textAlignment = NSTextAlignmentCenter;
        self.lblTime.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_lblTime];
    }
    return _lblTime;
}
@end

