CNLiveTradingRecordDetailHeaderView.m
5.9 KB
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
54
55
56
57
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
97
98
99
100
101
102
103
104
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
146
147
148
149
150
151
152
153
154
//
// CNLiveTradingRecordDetailHeaderView.m
// CNLiveBalanceModule
//
// Created by CNLive-zxw on 2019/9/6.
// Copyright © 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveTradingRecordDetailHeaderView.h"
#import <Masonry/Masonry.h>
#import "CNLiveBaseKit.h"
#import "QMUIKit.h"
#import "CNLiveCategory.h"
#import <SDWebImage/SDWebImage.h>
#import "CNLiveTradingRecordModel.h"
@interface CNLiveTradingRecordDetailHeaderView ()
@property (nonatomic, strong) UIImageView *shopIcon;
@property (nonatomic, strong) UILabel *shopName;
@property (nonatomic, strong) UILabel *money;
@property (nonatomic, strong) UILabel *tips;
@end
@implementation CNLiveTradingRecordDetailHeaderView
static const NSInteger margin = 10;
static const NSInteger height = 50;
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
[self createSubViews];
}
return self;
}
- (void)createSubViews {
[self addSubview:self.shopIcon];
[self addSubview:self.shopName];
[self addSubview:self.money];
[self addSubview:self.tips];
[self.money mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.centerY.equalTo(self);
}];
[self.tips mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.mas_bottom).offset(-margin);
make.centerX.equalTo(self);
make.height.offset(40);
}];
}
- (void)setModel:(CNLiveTradingRecordListModel *)model {
_model = model;
if (![model.sum containsString:@"-"]) {
self.money.text = [NSString stringWithFormat:@"+%@",model.sum];
} else {
self.money.text = model.sum;//[NSString stringWithFormat:@"%.2f",model.money];
}
if ([model.sourceType containsString:@"refill"] || [model.sourceType isEqualToString:@"group_vote"] || [model.sourceType containsString:@"refund"]) {
// 收入
self.tips.text = @"收款金额";
if ([model.payType isEqualToString:@"ali"]) {
self.shopIcon.image = [self getImageWithImageName:@"trading_record_ali_pay" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
self.shopName.text = @"支付宝支付";
} else if ([model.payType isEqualToString:@"wechat"]) {
self.shopIcon.image = [self getImageWithImageName:@"trading_record_wechat_pay" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
self.shopName.text = @"微信支付";
} else if ([model.payType isEqualToString:@"wjj"]) {
self.shopIcon.image = [self getImageWithImageName:@"trading_record_wjj_pay" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
self.shopName.text = @"网家家支付";
} else if ([model.payType isEqualToString:@"union"]) {
self.shopIcon.image = [self getImageWithImageName:@"trading_record_union_pay" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
self.shopName.text = @"银行卡";
} else {
self.shopIcon.image = [UIImage imageNamed:@""];
self.shopName.text = @"未知";
}
} else if ([model.sourceType containsString:@"order"] || [model.sourceType containsString:@"payment"]) {
// 支出
self.tips.text = @"付款金额";
self.shopIcon.layer.cornerRadius = 15.0;
self.shopIcon.layer.masksToBounds = YES;
UIImage *xw_image = [self getImageWithImageName:@"default_avatar_f" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
[self.shopIcon sd_setImageWithURL:[NSURL URLWithString:model.iconBean.image] placeholderImage:xw_image];
self.shopName.text = model.iconBean.nickName?model.iconBean.nickName:@"未知";
}
NSDictionary *dic = @{NSFontAttributeName:UIFontCNMake(16)};
CGFloat width = [self.shopName.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:dic context:nil].size.width+margin;
if(width >= SCREEN_WIDTH){
width = SCREEN_WIDTH-40;
}
[_shopName mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).with.offset((SCREEN_WIDTH-width)/2.0+2*margin);
make.right.mas_lessThanOrEqualTo(self.mas_right).with.offset(-margin);
make.top.equalTo(self.mas_top).with.offset(margin);
make.width.offset(width);
make.height.offset(40);
}];
[_shopIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.shopName.mas_left).with.offset(-margin);
make.centerY.equalTo(self.shopName.mas_centerY);
make.width.height.offset(30);
}];
}
#pragma mark - 懒加载
- (UIImageView *)shopIcon {
if (!_shopIcon) {
_shopIcon = [[UIImageView alloc] init];
_shopIcon.contentMode = UIViewContentModeScaleAspectFill;
_shopIcon.backgroundColor = [UIColor whiteColor];
_shopIcon.image = [UIImage imageNamed:@"ye_wxzffs"]; //fenlei_touxiang2
}
return _shopIcon;
}
- (UILabel *)shopName {
if (!_shopName) {
_shopName = [[UILabel alloc] init];
_shopName.textColor = [UIColor blackColor];
_shopName.font = UIFontCNMake(16);//[UIFont fontWithName:@"PingFangSC-Regular" size:16.0f];
}
return _shopName;
}
- (UILabel *)money {
if (!_money) {
_money = [[UILabel alloc] init];
_money.textColor = RGB(34, 34, 34);
_money.font = UIFontCNMake(36);//[UIFont fontWithName:@"PingFangSC-Regular" size:36];
_money.textAlignment = NSTextAlignmentCenter;
}
return _money;
}
- (UILabel *)tips {
if (!_tips) {
_tips = [[UILabel alloc] init];
_tips.text = @"付款金额";
_tips.textColor = RGB(156, 156, 156);
_tips.font = UIFontCNMake(15);//[UIFont fontWithName:@"PingFangSC-Regular" size:15];
_tips.textAlignment = NSTextAlignmentCenter;
}
return _tips;
}
@end