酷店

KDPLiveRightHeaderView.m 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //
  2. // KDPLiveRightHeaderView.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/9.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPLiveRightHeaderView.h"
  9. @interface KDPLiveRightHeaderView ()
  10. @property (nonatomic, strong) UIView *topHeaderView;
  11. @property (nonatomic, strong) UIView *goodView;
  12. @property (nonatomic, strong) UILabel *goodCountLabel;
  13. @property (nonatomic, strong) UILabel *orderCountLabel;
  14. @property (nonatomic, strong) UILabel *investLabel;
  15. @property (nonatomic, strong) UIButton *todayBtn;
  16. @end
  17. @implementation KDPLiveRightHeaderView
  18. - (instancetype)initWithFrame:(CGRect)frame{
  19. if (self = [super initWithFrame:frame]) {
  20. [self setContentView];
  21. }
  22. return self;
  23. }
  24. - (void)setContentView{
  25. self.backgroundColor = [UIColor clearColor];
  26. self.topHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 116)];
  27. self.topHeaderView.backgroundColor = [UIColor whiteColor];
  28. [self.topHeaderView addCornerRadiusByRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(6, 6)];
  29. [self addSubview:self.topHeaderView];
  30. self.goodView = [[UIView alloc] initWithFrame:CGRectMake(0, self.topHeaderView.bottom + 10, SCREEN_WIDTH-20, 43)];
  31. self.goodView.backgroundColor = [UIColor whiteColor];
  32. self.goodView.hidden = YES;
  33. [self addSubview:self.goodView];
  34. UILabel *goodTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 14, SCREEN_WIDTH-20, 21)];
  35. goodTitleLabel.textColor = [UIColor colorWithHex:0x333333];
  36. goodTitleLabel.font = FONT_SYS(15);
  37. goodTitleLabel.text = @"商品列表";
  38. [self.goodView addSubview:goodTitleLabel];
  39. self.todayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  40. [self.todayBtn setTitle:@"今天" forState:UIControlStateNormal];
  41. [self.todayBtn setTitleColor:[UIColor colorWithHex:0x333333] forState:UIControlStateNormal];
  42. self.todayBtn.titleLabel.font = FONT_SYS(14);
  43. self.todayBtn.tag = 2000;
  44. [self.todayBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  45. self.todayBtn.showsTouchWhenHighlighted = NO;
  46. [self.topHeaderView addSubview:self.todayBtn];
  47. UIButton *yestBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  48. [yestBtn setTitle:@"昨天" forState:UIControlStateNormal];
  49. [yestBtn setTitleColor:[UIColor colorWithHex:0x333333] forState:UIControlStateNormal];
  50. yestBtn.titleLabel.font = FONT_SYS(14);
  51. yestBtn.tag = 2001;
  52. [yestBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  53. yestBtn.showsTouchWhenHighlighted = NO;
  54. [self.topHeaderView addSubview:yestBtn];
  55. UIButton *totalBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  56. [totalBtn setTitle:@"全部" forState:UIControlStateNormal];
  57. [totalBtn setTitleColor:[UIColor colorWithHex:0x333333] forState:UIControlStateNormal];
  58. totalBtn.titleLabel.font = FONT_SYS(14);
  59. totalBtn.tag = 2002;
  60. [totalBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  61. totalBtn.showsTouchWhenHighlighted = NO;
  62. [self.topHeaderView addSubview:totalBtn];
  63. // 虚线
  64. CAShapeLayer *dotteShapeLayer = [CAShapeLayer layer];
  65. CGMutablePathRef dotteshapePath = CGPathCreateMutable();
  66. // 设置虚线颜色
  67. [dotteShapeLayer setStrokeColor:[UIColor colorWithHex:0xC5C5C5].CGColor];
  68. dotteShapeLayer.lineWidth = 0.3f;
  69. NSArray *dottehShapeArr = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4], nil];
  70. [dotteShapeLayer setLineDashPattern:dottehShapeArr];
  71. CGPathMoveToPoint(dotteshapePath, NULL, 8,40);
  72. CGPathAddLineToPoint(dotteshapePath, NULL, self.topHeaderView.width-7, 40);
  73. [dotteShapeLayer setPath:dotteshapePath];
  74. CGPathRelease(dotteshapePath);
  75. [self.topHeaderView.layer addSublayer:dotteShapeLayer];
  76. self.goodCountLabel = [[UILabel alloc] init];
  77. self.goodCountLabel.font = FONT_SYS(20);
  78. self.goodCountLabel.textAlignment = NSTextAlignmentCenter;
  79. self.goodCountLabel.textColor = [UIColor colorWithHex:0x333333];
  80. self.goodCountLabel.text = @"0";
  81. [self.topHeaderView addSubview:self.goodCountLabel];
  82. UILabel *goodDetailLabel = [[UILabel alloc] init];
  83. goodDetailLabel.textColor = [UIColor colorWithHex:0x666666];
  84. goodDetailLabel.font = FONT_SYS(12);
  85. goodDetailLabel.textAlignment = NSTextAlignmentCenter;
  86. goodDetailLabel.text = @"上架商品数";
  87. [self.topHeaderView addSubview:goodDetailLabel];
  88. self.orderCountLabel = [[UILabel alloc] init];
  89. self.orderCountLabel.font = FONT_SYS(20);
  90. self.orderCountLabel.textColor = [UIColor colorWithHex:0x333333];
  91. self.orderCountLabel.text = @"0";
  92. self.orderCountLabel.textAlignment = NSTextAlignmentCenter;
  93. [self.topHeaderView addSubview:self.orderCountLabel];
  94. UILabel *orderDetailLabel = [[UILabel alloc] init];
  95. orderDetailLabel.textColor = [UIColor colorWithHex:0x666666];
  96. orderDetailLabel.font = FONT_SYS(12);
  97. orderDetailLabel.textAlignment = NSTextAlignmentCenter;
  98. orderDetailLabel.text = @"订单数";
  99. [self.topHeaderView addSubview:orderDetailLabel];
  100. self.investLabel = [[UILabel alloc] init];
  101. self.investLabel.font = FONT_SYS(20);
  102. self.investLabel.textColor = [UIColor colorWithHex:0x333333];
  103. self.investLabel.text = @"0";
  104. self.investLabel.textAlignment = NSTextAlignmentCenter;
  105. [self.topHeaderView addSubview:self.investLabel];
  106. UILabel *investDetailLabel = [[UILabel alloc] init];
  107. investDetailLabel.textColor = [UIColor colorWithHex:0x666666];
  108. investDetailLabel.font = FONT_SYS(12);
  109. investDetailLabel.textAlignment = NSTextAlignmentCenter;
  110. investDetailLabel.text = @"预估收益";
  111. [self.topHeaderView addSubview:investDetailLabel];
  112. [yestBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.size.equalTo(CGSizeMake(30, 20));
  114. make.top.equalTo(self.topHeaderView.mas_top).offset(10);
  115. make.centerX.equalTo(self.topHeaderView);
  116. }];
  117. [self.todayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.right.equalTo(yestBtn.mas_left).offset(-36);
  119. make.size.top.equalTo(yestBtn);
  120. }];
  121. [totalBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  122. make.left.equalTo(yestBtn.mas_right).offset(35);
  123. make.size.top.equalTo(yestBtn);
  124. }];
  125. [self.orderCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.top.equalTo(yestBtn.mas_bottom).offset(20);
  127. make.centerX.equalTo(self.topHeaderView);
  128. make.size.equalTo(CGSizeMake(80, 28));
  129. }];
  130. [orderDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.top.equalTo(self.orderCountLabel.mas_bottom).offset(6);
  132. make.centerX.equalTo(self.orderCountLabel);
  133. make.size.equalTo(self.orderCountLabel);
  134. }];
  135. [self.goodCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.top.equalTo(self.orderCountLabel.mas_top);
  137. make.right.equalTo(self.orderCountLabel.mas_left).offset(-20);
  138. make.size.equalTo(self.orderCountLabel);
  139. }];
  140. [goodDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  141. make.top.equalTo(self.goodCountLabel.mas_bottom).offset(6);
  142. make.size.equalTo(self.goodCountLabel);
  143. make.right.equalTo(self.goodCountLabel);
  144. }];
  145. [self.investLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  146. make.top.equalTo(self.orderCountLabel);
  147. make.left.equalTo(self.orderCountLabel.mas_right).offset(20);
  148. make.size.equalTo(self.orderCountLabel);
  149. }];
  150. [investDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  151. make.left.equalTo(self.investLabel);
  152. make.size.equalTo(self.investLabel);
  153. make.top.equalTo(goodDetailLabel);
  154. }];
  155. }
  156. - (void)setSelectIndex:(NSInteger)selectIndex{
  157. _selectIndex = selectIndex;
  158. UIButton *button = [self.topHeaderView viewWithTag:2000+selectIndex];
  159. [self buttonClick:button];
  160. }
  161. - (void)reloadHeaderData:(NSDictionary *)dict{
  162. if ([dict isEqual:[NSNull null]]) {
  163. return;
  164. }
  165. if ([dict valueForKey:@"goods_num"] != nil) {
  166. self.goodCountLabel.text = [NSString stringWithFormat:@"%@",[dict valueForKey:@"goods_num"]];
  167. }
  168. if ([dict valueForKey:@"order_num"] != nil) {
  169. self.orderCountLabel.text = [NSString stringWithFormat:@"%@",[dict valueForKey:@"order_num"]];
  170. }
  171. if ([dict valueForKey:@"total_rebate"] != nil) {
  172. self.investLabel.text = [NSString stringWithFormat:@"%@",[dict valueForKey:@"total_rebate"]];
  173. }
  174. }
  175. - (void)setHiddenGoodTipView:(BOOL)hiddenGoodTipView{
  176. _hiddenGoodTipView = hiddenGoodTipView;
  177. self.goodView.hidden = hiddenGoodTipView;
  178. }
  179. - (void)buttonClick:(UIButton *)sender{
  180. NSInteger index = sender.tag - 2000;
  181. [self.topHeaderView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  182. if ([obj isKindOfClass:[UIButton class]]) {
  183. UIButton *button = (UIButton *)obj;
  184. [button setTitleColor:[UIColor colorWithHex:0x333333] forState:UIControlStateNormal];
  185. }
  186. }];
  187. [UIView animateWithDuration:0.25 animations:^{
  188. [sender setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
  189. }];
  190. if (self.clickBlock) {
  191. self.clickBlock(index);
  192. }
  193. }
  194. @end