No Description

FKBasketSiteHeaderView.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //
  2. // FKBasketSiteHeaderView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/2/19.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKBasketSiteHeaderView.h"
  9. #import "FKBasketPriceView.h"
  10. #import "FKBasketViewModel.h"
  11. @interface FKBasketSiteHeaderView ()
  12. @property (nonatomic, strong) UIView *containerView;
  13. @property (nonatomic, strong) UIView *bottomLine;
  14. @property (nonatomic, strong) UIButton *moreActionBtn;
  15. @property (nonatomic, strong) UIImageView *flagImgView;
  16. @property (nonatomic, strong) UILabel *siteNameLabel;
  17. @property (nonatomic, strong) UILabel *advLabel;
  18. @property (nonatomic, strong) UILabel *authenLabel; // 认证采购
  19. @property (nonatomic, strong) UILabel *postageDescLabel;
  20. @property (nonatomic, strong) FKBasketPriceView *priceView;
  21. @property (nonatomic, strong) FKBasketUnitItem *unitItem;
  22. @end
  23. @implementation FKBasketSiteHeaderView
  24. - (instancetype)init {
  25. if (self = [super init]) {
  26. self.backgroundColor = [UIColor whiteColor];
  27. [self addAllSubviews];
  28. }
  29. return self;
  30. }
  31. - (void)addAllSubviews {
  32. UIButton *seeMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  33. [seeMoreBtn addTarget:self action:@selector(clickMoreAction:) forControlEvents:UIControlEventTouchUpInside];
  34. [self addSubview:self.containerView];
  35. [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.edges.equalTo(self);
  37. }];
  38. [self.containerView addSubview:self.selectBtn];
  39. [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.equalTo(self.containerView);
  41. make.centerY.equalTo(self.containerView);
  42. make.width.mas_equalTo(48);
  43. make.height.mas_equalTo(45);
  44. }];
  45. [self.containerView addSubview:self.flagImgView];
  46. [self.flagImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.equalTo(self.selectBtn.mas_right);
  48. make.top.equalTo(self.containerView).offset(15);
  49. make.size.mas_equalTo(CGSizeMake(20, 13));
  50. }];
  51. [self.containerView addSubview:self.siteNameLabel];
  52. [self.siteNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.equalTo(self.flagImgView.mas_right).offset(10);
  54. make.centerY.equalTo(self.flagImgView);
  55. }];
  56. [self.containerView addSubview:self.authenLabel];
  57. [self.authenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.equalTo(self.siteNameLabel.mas_right).offset(10);
  59. make.centerY.equalTo(self.siteNameLabel);
  60. make.size.mas_equalTo(CGSizeMake(40, 13));
  61. }];
  62. [self.containerView addSubview:self.moreActionBtn];
  63. [self.moreActionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.centerY.equalTo(self.containerView);
  65. make.centerX.equalTo(self.containerView.mas_right).offset(- 20);
  66. make.size.mas_equalTo(CGSizeMake(60, 40));
  67. }];
  68. [self.containerView addSubview:self.advLabel];
  69. [self.advLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.equalTo(self.flagImgView).offset(- 7);
  71. make.top.equalTo(self.flagImgView.mas_bottom).offset(5);
  72. make.width.mas_equalTo(UISCREENWIDTH - 15 - 48);
  73. }];
  74. CGFloat descWidth = UISCREENWIDTH - 100;
  75. [self.containerView addSubview:self.postageDescLabel];
  76. [self.postageDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.left.equalTo(self.flagImgView);
  78. make.top.equalTo(self.advLabel.mas_bottom).offset(5);
  79. make.width.mas_equalTo(descWidth);
  80. }];
  81. [self.containerView addSubview:seeMoreBtn];
  82. [seeMoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.right.top.bottom.equalTo(self.containerView);
  84. make.width.mas_equalTo(UISCREENWIDTH / 2.0f);
  85. }];
  86. [self addSubview:self.bottomLine];
  87. [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.right.bottom.equalTo(self);
  89. make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale);
  90. }];
  91. self.priceView.hidden = YES;
  92. [self addSubview:self.priceView];
  93. }
  94. - (void)configWithUnitItem:(FKBasketUnitItem *)unitItem viewModel:(FKBasketViewModel *)viewModel {
  95. if ([unitItem isKindOfClass:[FKBasketUnitItem class]]){
  96. self.selectBtn.hidden = ([unitItem hasCanBeBuyProduct] ? NO : YES);
  97. if (unitItem.beingEdit) self.selectBtn.hidden = NO;
  98. self.selectBtn.selected = unitItem.allSelected;
  99. self.flagImgView.image = nil;
  100. [self.flagImgView setImageWithURL:unitItem.countryInfo.countryPicUrl placeholderImage:nil width:20 height:13];
  101. self.siteNameLabel.text = unitItem.supplyInfo.supplyName;
  102. NSString *shipTypeText = @" ";
  103. if ([unitItem.supplyInfo shipTypeText]) shipTypeText = [unitItem.supplyInfo shipTypeText];
  104. if ([unitItem.supplyInfo.postageRule isKindOfClass:[NSString class]]){
  105. shipTypeText = [shipTypeText stringByAppendingString:unitItem.supplyInfo.postageRule];
  106. }
  107. self.advLabel.text = shipTypeText;
  108. BOOL postageDescHidden = YES;
  109. if ([unitItem getPostageFreeAdv]) {
  110. postageDescHidden = NO;
  111. self.postageDescLabel.text = [unitItem getPostageFreeAdv];
  112. }
  113. self.postageDescLabel.hidden = postageDescHidden;
  114. self.authenLabel.hidden = ([unitItem.supplyInfo isAuthenedProduct] ? NO : YES);
  115. if ([unitItem getSelectedWeight]) {
  116. self.priceView.hidden = NO;
  117. [self.priceView mas_remakeConstraints:^(MASConstraintMaker *make) {
  118. make.left.bottom.right.equalTo(self);
  119. make.height.mas_equalTo([FKBasketSiteHeaderView priceViewHeight]);
  120. }];
  121. [self.containerView mas_remakeConstraints:^(MASConstraintMaker *make) {
  122. make.left.top.right.equalTo(self);
  123. make.bottom.equalTo(self.priceView.mas_top);
  124. }];
  125. [self bringSubviewToFront:self.bottomLine];
  126. [self.bottomLine mas_remakeConstraints:^(MASConstraintMaker *make) {
  127. make.left.right.bottom.equalTo(self);
  128. make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale);
  129. }];
  130. self.priceView.weightLabel.text = [NSString stringWithFormat:@"重量:%ldg", (unsigned long)[unitItem getSelectedWeight]];
  131. self.priceView.postageLabel.text = [NSString stringWithFormat:@"运费:¥%.2f", [unitItem getMinPostageForUserLevel:viewModel.userLevel]];
  132. } else {
  133. self.priceView.hidden = YES;
  134. [self.containerView mas_remakeConstraints:^(MASConstraintMaker *make) {
  135. make.edges.equalTo(self);
  136. }];
  137. [self bringSubviewToFront:self.bottomLine];
  138. [self.bottomLine mas_remakeConstraints:^(MASConstraintMaker *make) {
  139. make.left.right.bottom.equalTo(self);
  140. make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale);
  141. }];
  142. }
  143. }
  144. }
  145. + (CGFloat)priceViewHeight {
  146. return 25;
  147. }
  148. #pragma mark - action
  149. - (void)clickMoreAction:(UIButton *)sender{
  150. if (self.didSeeMore){
  151. self.didSeeMore(self);
  152. }
  153. }
  154. #pragma mark - property
  155. - (UIView *)containerView {
  156. if (!_containerView) {
  157. _containerView = [UIView new];
  158. }
  159. return _containerView;
  160. }
  161. - (UIView *)bottomLine {
  162. if (!_bottomLine) {
  163. _bottomLine = [UIView new];
  164. _bottomLine.backgroundColor = UIColorFromRGB(0xe5e5e5);
  165. }
  166. return _bottomLine;
  167. }
  168. - (UIButton *)selectBtn{
  169. if (_selectBtn == nil) {
  170. _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  171. [_selectBtn setImage:[UIImage imageNamed:@"basket_unSelect"] forState:UIControlStateNormal];
  172. [_selectBtn setImage:[UIImage imageNamed:@"basket_selected"] forState:UIControlStateSelected];
  173. }
  174. return _selectBtn;
  175. }
  176. - (UIButton *)moreActionBtn{
  177. if (_moreActionBtn == nil) {
  178. _moreActionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  179. [_moreActionBtn setImage:[UIImage imageNamed:@"basket_more_action"] forState:UIControlStateNormal];
  180. _moreActionBtn.userInteractionEnabled = NO;
  181. // [_moreActionBtn addTarget:self action:@selector(clickMoreAction:) forControlEvents:UIControlEventTouchUpInside];
  182. }
  183. return _moreActionBtn;
  184. }
  185. - (UIImageView *)flagImgView{
  186. if (_flagImgView == nil) {
  187. _flagImgView = [[UIImageView alloc]init];
  188. [_flagImgView setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  189. }
  190. return _flagImgView;
  191. }
  192. - (UILabel *)siteNameLabel{
  193. if (_siteNameLabel == nil) {
  194. _siteNameLabel = [[UILabel alloc]init];
  195. _siteNameLabel.font = [UIFont systemFontOfSize:13];
  196. _siteNameLabel.textColor = UIColorFromRGB(0x333333);
  197. [_siteNameLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  198. }
  199. return _siteNameLabel;
  200. }
  201. - (UILabel *)advLabel{
  202. if (_advLabel == nil) {
  203. _advLabel = [[UILabel alloc]init];
  204. _advLabel.font = [UIFont systemFontOfSize:12];
  205. _advLabel.textColor = UIColorFromRGB(0x999999);
  206. }
  207. return _advLabel;
  208. }
  209. - (UILabel *)authenLabel{
  210. if (_authenLabel == nil) {
  211. _authenLabel = [[UILabel alloc]init];
  212. _authenLabel.font = [UIFont systemFontOfSize:9];
  213. _authenLabel.textColor = UIColorFromRGB(0xF7AC22);
  214. _authenLabel.text = @"认证采购";
  215. _authenLabel.textAlignment = NSTextAlignmentCenter;
  216. _authenLabel.layer.cornerRadius = 3.0;
  217. _authenLabel.layer.borderWidth = 0.5;
  218. _authenLabel.layer.borderColor = UIColorFromRGB(0xF7AC22).CGColor;
  219. }
  220. return _authenLabel;
  221. }
  222. - (UILabel *)postageDescLabel{
  223. if (_postageDescLabel == nil) {
  224. _postageDescLabel = [[UILabel alloc]init];
  225. _postageDescLabel.textColor = UIColorFromRGB(0xff624a);
  226. _postageDescLabel.font = [UIFont systemFontOfSize:12];
  227. if (UISCREENWIDTH <= 320) _postageDescLabel.font = [UIFont systemFontOfSize:11];
  228. _postageDescLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  229. }
  230. return _postageDescLabel;
  231. }
  232. - (FKBasketPriceView *)priceView {
  233. if (!_priceView) {
  234. _priceView = [FKBasketPriceView new];
  235. }
  236. return _priceView;
  237. }
  238. @end