InspectDetailHeaderView.m 9.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
//
//  InspectDetailHeaderView.m
//  redstar
//
//  Created by admin on 15/11/12.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "InspectDetailHeaderView.h"

@implementation InspectDetailHeaderView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

#pragma mark - Private Methods
- (void)setup
{
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = kAnnounceTextColor;
    titleLabel.backgroundColor = kSectionBackGroundColor;
    titleLabel.font = [UIFont systemFontOfSize:17.0];
    [self addSubview:titleLabel];
    
    NSLayoutConstraint *titleLabelTop = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
    [self addConstraint:titleLabelTop];
    
    NSLayoutConstraint *titleLabelLeft = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
    [self addConstraint:titleLabelLeft];
    
    NSLayoutConstraint *titleLabelWidth = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
    [self addConstraint:titleLabelWidth];
    
    NSLayoutConstraint *titleLabelHeight = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:45];
    [self addConstraint:titleLabelHeight];
    
54
    _titleLabel = titleLabel;
55 56
    
    
57
    self.detailView.backgroundColor = [UIColor whiteColor];
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    
    UIView *lineView = [[UIView alloc] init];
    lineView.translatesAutoresizingMaskIntoConstraints = NO;
    lineView.backgroundColor = kSeparateLineColor;
    [self addSubview:lineView];
    
    NSLayoutConstraint *upLineBottom = [NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
    [self addConstraint:upLineBottom];
    
    NSLayoutConstraint *upLineLeft = [NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
    [self addConstraint:upLineLeft];
    
    NSLayoutConstraint *upLineRight = [NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
    [self addConstraint:upLineRight];
    
    NSLayoutConstraint *upLineHeight = [NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:1];
    [self  addConstraint:upLineHeight];
    
    
    
    UILabel *classifyLabel = [[UILabel alloc] init];
    classifyLabel.translatesAutoresizingMaskIntoConstraints = NO;
    classifyLabel.textColor = kAnnounceTextColor;
    classifyLabel.backgroundColor = kSectionBackGroundColor;
    classifyLabel.font = [UIFont systemFontOfSize:15.0];
    classifyLabel.text = @"分类项目";
    [self addSubview:classifyLabel];
    
    NSLayoutConstraint *classifyTop = [NSLayoutConstraint constraintWithItem:classifyLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:245];
    [self addConstraint:classifyTop];
    
    NSLayoutConstraint *classifyLeft = [NSLayoutConstraint constraintWithItem:classifyLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
    [self addConstraint:classifyLeft];
    
    
    NSLayoutConstraint *classifyHeight = [NSLayoutConstraint constraintWithItem:classifyLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:39];
    [self addConstraint:classifyHeight];
}

97 98 99 100 101 102 103
- (void)setTaskDetail:(TaskDetailModel *)taskDetail
{
    _taskDetail = taskDetail;
    self.titleLabel.text = [NSString stringWithFormat:@"%@", taskDetail.name];
    self.detailView.shopnameLabel.text = [NSString stringWithFormat:@"%@", taskDetail.store_name];
    self.detailView.startDateLabel.text = [NSString stringWithFormat:@"%@", taskDetail.beginDate];
    self.detailView.overDateLabel.text = [NSString stringWithFormat:@"%@", taskDetail.endDate];
104
    self.detailView.multiplier = (CGFloat)taskDetail.reportCount / taskDetail.questionCount;
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    if ([taskDetail.state isEqualToString:@"initial"]) {
        self.detailView.progressLabel.text = [NSString stringWithFormat:@"未处理 %.0f%%", (CGFloat)taskDetail.reportCount / taskDetail.questionCount * 100];
        self.detailView.progressLabel.textColor = kProgressUnSettledColor;
        self.detailView.alreadyLabel.textColor = kProgressUnSettledColor;
        self.detailView.allLabel.textColor = kProgressUnSettledColor;
    } else if ([taskDetail.state isEqualToString:@"processing"]) {
        self.detailView.progressLabel.text = [NSString stringWithFormat:@"进行中 %.0f%%", (CGFloat)taskDetail.reportCount / taskDetail.questionCount * 100];
        self.detailView.progressLabel.textColor = kProgressDealWithColor;
        self.detailView.alreadyLabel.textColor = kProgressDealWithColor;
        self.detailView.allLabel.textColor = kProgressDealWithColor;

    } else if ([taskDetail.state isEqualToString:@"reported"]) {
        self.detailView.progressLabel.text = [NSString stringWithFormat:@"已上报 %.0f%%", (CGFloat)taskDetail.reportCount / taskDetail.questionCount * 100];
        self.detailView.progressLabel.textColor = kProgressDealWithColor;
        self.detailView.alreadyLabel.textColor = kProgressDealWithColor;
        self.detailView.allLabel.textColor = kProgressDealWithColor;
        
    } else if ([taskDetail.state isEqualToString:@"finished"]) {
        self.detailView.progressLabel.text = [NSString stringWithFormat:@"已评分 %.0f%%", (CGFloat)taskDetail.reportCount / taskDetail.questionCount * 100];
        self.detailView.progressLabel.textColor = kProgressDealWithColor;
        self.detailView.alreadyLabel.textColor = kProgressDealWithColor;
        self.detailView.allLabel.textColor = kProgressDealWithColor;
    } else if ([taskDetail.state isEqualToString:@"published"]) {
        self.detailView.progressLabel.text = [NSString stringWithFormat:@"已发布 %.0f%%", (CGFloat)taskDetail.reportCount / taskDetail.questionCount * 100];
        self.detailView.progressLabel.textColor = kProgressDealWithColor;
        self.detailView.alreadyLabel.textColor = kProgressDealWithColor;
        self.detailView.allLabel.textColor = kProgressDealWithColor;
    } else {
        self.detailView.progressLabel.text = [NSString stringWithFormat:@"已过期 %.0f%%", (CGFloat)taskDetail.reportCount / taskDetail.questionCount * 100];
        self.detailView.progressLabel.textColor = kProgressOverDueColor;
        self.detailView.alreadyLabel.textColor = kProgressOverDueColor;
        self.detailView.allLabel.textColor = kProgressOverDueColor;
    }
    self.detailView.allView.backgroundColor = kProgressViewAllBackColor;
    self.detailView.alreadyView.backgroundColor = kProgressViewAlreadyBackColor;
    
    self.detailView.alreadyLabel.text = [NSString stringWithFormat:@"%d", taskDetail.reportCount];
    self.detailView.allLabel.text = [NSString stringWithFormat:@"/%d", taskDetail.questionCount];

}

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
- (InspectDetailView *)detailView
{
    if (!_detailView) {
        _detailView = [[InspectDetailView alloc] init];
        _detailView.translatesAutoresizingMaskIntoConstraints = NO;
        
        [self addSubview:_detailView];
        
        NSLayoutConstraint *titleLabelTop = [NSLayoutConstraint constraintWithItem:_detailView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:45];
        [self addConstraint:titleLabelTop];
        
        NSLayoutConstraint *titleLabelLeft = [NSLayoutConstraint constraintWithItem:_detailView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self addConstraint:titleLabelLeft];
        
        NSLayoutConstraint *titleLabelWidth = [NSLayoutConstraint constraintWithItem:_detailView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self addConstraint:titleLabelWidth];
        
        NSLayoutConstraint *titleLabelHeight = [NSLayoutConstraint constraintWithItem:_detailView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:200];
        [self addConstraint:titleLabelHeight];
    }
    return _detailView;
}

@end