省钱达人老版本

YHGoodDetailView.m 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. //
  2. // YHGoodDetailView.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/25.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "YHGoodDetailView.h"
  9. #import "YHGoodDetailModel.h"
  10. @interface YHGoodDetailView ()
  11. @property (nonatomic, strong) UILabel *goodTitleLabel;
  12. @property (nonatomic, strong) UILabel *priceLabel;
  13. @property (nonatomic, strong) UIImageView *discountImageView;
  14. @property (nonatomic, strong) UILabel *discountPriceLabel;
  15. @property (nonatomic, strong) UILabel *freePostLabel;
  16. @property (nonatomic, strong) UILabel *volumeLabel;
  17. @property (nonatomic, strong) UIImageView *couponImageView;
  18. @property (nonatomic, strong) UILabel *couponPriceLabel;
  19. @property (nonatomic, strong) UILabel *couponTimeLabel;
  20. @property (nonatomic, strong) UILabel *couponGetLabel;
  21. @property (nonatomic, strong) CALayer *middleLineLayer;
  22. @property (nonatomic, strong) UIView *middleView;
  23. @property (nonatomic, strong) UIImageView *shopImageView;
  24. @property (nonatomic, strong) UILabel *shopTitleLabel;
  25. @property (nonatomic, strong) UIImageView *viewShopRightImageView;
  26. @property (nonatomic, strong) UILabel *viewShopLabel;
  27. @property (nonatomic, strong) CALayer *bottomLineLayer;
  28. @property (nonatomic, strong) UIView *bottomView;
  29. @property (nonatomic, strong) UIButton *goodIntro;
  30. @property (nonatomic, strong) UIButton *shopService;
  31. @property (nonatomic, strong) UIButton *postService;
  32. @end
  33. @implementation YHGoodDetailView
  34. - (instancetype)initWithFrame:(CGRect)frame {
  35. self = [super initWithFrame:frame];
  36. if (self) {
  37. self.backgroundColor = [UIColor whiteColor];
  38. [self initSubviews];
  39. }
  40. return self;
  41. }
  42. - (void)setGoodModel:(YHGoodDetailModel *)goodModel {
  43. _goodModel = goodModel;
  44. self.goodTitleLabel.text = goodModel.title;
  45. self.priceLabel.text = [NSString stringWithFormat:@"原价 ¥%@", goodModel.price];
  46. self.discountPriceLabel.text = [NSString stringWithFormat:@"¥%@", goodModel.discount_price];
  47. self.volumeLabel.text = [NSString stringWithFormat:@"月销 %@", goodModel.volume];
  48. self.freePostLabel.text = [goodModel.freeShipping isEqual:@1] ? @"包邮" : [NSString stringWithFormat:@"邮费 %@", goodModel.postage];
  49. self.couponPriceLabel.text = [NSString stringWithFormat:@"%@元优惠券", goodModel.coupon_price];
  50. self.couponTimeLabel.text = [NSString stringWithFormat:@"使用期限:%@-%@", goodModel.start_time, goodModel.end_time];
  51. [self.shopImageView yy_setImageWithURL:[NSURL URLWithString:goodModel.shop_pict_url] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
  52. self.shopTitleLabel.text = goodModel.shop_title;
  53. [self.goodIntro setTitle:[NSString stringWithFormat:@"宝贝描述:%@", goodModel.item_score] forState:UIControlStateNormal];
  54. [self.shopService setTitle:[NSString stringWithFormat:@"卖家服务:%@", goodModel.service_score] forState:UIControlStateNormal];
  55. [self.postService setTitle:[NSString stringWithFormat:@"物流服务:%@", goodModel.delivery_score] forState:UIControlStateNormal];
  56. }
  57. - (void)initSubviews {
  58. [self.layer addSublayer:self.middleLineLayer];
  59. [self.layer addSublayer:self.bottomLineLayer];
  60. [self addSubview:self.goodTitleLabel];
  61. [self addSubview:self.priceLabel];
  62. [self addSubview:self.discountImageView];
  63. [self addSubview:self.discountPriceLabel];
  64. [self addSubview:self.volumeLabel];
  65. [self addSubview:self.freePostLabel];
  66. [self addSubview:self.couponImageView];
  67. [self.couponImageView addSubview:self.couponPriceLabel];
  68. [self.couponImageView addSubview:self.couponTimeLabel];
  69. [self.couponImageView addSubview:self.couponGetLabel];
  70. [self addSubview:self.middleView];
  71. [self.middleView addSubview:self.shopImageView];
  72. [self.middleView addSubview:self.shopTitleLabel];
  73. [self.middleView addSubview:self.viewShopRightImageView];
  74. [self.middleView addSubview:self.viewShopLabel];
  75. [self addSubview:self.bottomView];
  76. [self.bottomView addSubview:self.goodIntro];
  77. [self.bottomView addSubview:self.shopService];
  78. [self.bottomView addSubview:self.postService];
  79. [self makeSubviewsConstraints];
  80. }
  81. - (void)makeSubviewsConstraints {
  82. [self.goodTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.equalTo(self).offset(FITSIZE(20));
  84. make.top.equalTo(self).offset(FITSIZE(15));
  85. make.right.equalTo(self).offset(-FITSIZE(20));
  86. }];
  87. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.equalTo(self.goodTitleLabel);
  89. make.top.equalTo(self.goodTitleLabel.mas_bottom).offset(FITSIZE(15));
  90. }];
  91. [self.discountImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.left.equalTo(self.priceLabel);
  93. make.bottom.equalTo(self.discountPriceLabel).offset(-FITSIZE(3));
  94. make.size.mas_equalTo(CGSizeMake(FITSIZE(FITSIZE(34)), FITSIZE(12)));
  95. }];
  96. [self.discountPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.equalTo(self.discountImageView.mas_right).offset(FITSIZE(10));
  98. make.top.equalTo(self.priceLabel.mas_bottom).offset(FITSIZE(10));
  99. }];
  100. [self.volumeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.right.equalTo(self).offset(-FITSIZE(20));
  102. make.bottom.equalTo(self.discountImageView);
  103. }];
  104. [self.freePostLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.right.equalTo(self.volumeLabel.mas_left).offset(-FITSIZE(10));
  106. make.bottom.equalTo(self.volumeLabel);
  107. }];
  108. [self.couponImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  109. make.centerX.equalTo(self);
  110. make.top.equalTo(self.discountPriceLabel.mas_bottom).offset(FITSIZE(16));
  111. make.size.mas_equalTo(CGSizeMake(FITSIZE(335), FITSIZE(88)));
  112. }];
  113. [self.couponPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.left.equalTo(self.couponImageView);
  115. make.centerY.equalTo(self.couponImageView).offset(-FITSIZE(10));
  116. make.width.mas_equalTo(FITSIZE(216));
  117. }];
  118. [self.couponTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.left.equalTo(self.couponImageView);
  120. make.centerY.equalTo(self.couponImageView).offset(FITSIZE(10));
  121. make.width.mas_equalTo(FITSIZE(216));
  122. }];
  123. [self.couponGetLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.right.equalTo(self.couponImageView);
  125. make.centerY.equalTo(self.couponImageView);
  126. make.width.mas_equalTo(FITSIZE(118));
  127. }];
  128. [self.middleView mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.left.equalTo(self);
  130. make.top.equalTo(self).offset(FITSIZE(214));
  131. make.right.equalTo(self);
  132. make.height.mas_equalTo(FITSIZE(100));
  133. }];
  134. [self.shopImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  135. make.left.equalTo(self.middleView).offset(FITSIZE(20));
  136. make.top.equalTo(self.middleView).offset(FITSIZE(22));
  137. make.size.mas_equalTo(CGSizeMake(FITSIZE(60), FITSIZE(60)));
  138. }];
  139. [self.shopTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.left.equalTo(self.shopImageView.mas_right).offset(FITSIZE(14));
  141. make.centerY.equalTo(self.middleView);
  142. }];
  143. [self.viewShopRightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.right.equalTo(self.middleView).offset(-FITSIZE(20));
  145. make.centerY.equalTo(self.shopTitleLabel);
  146. make.size.mas_equalTo(CGSizeMake(FITSIZE(20), FITSIZE(20)));
  147. }];
  148. [self.viewShopLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.right.equalTo(self.viewShopRightImageView.mas_left);
  150. make.centerY.equalTo(self.shopTitleLabel);
  151. }];
  152. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  153. make.left.equalTo(self);
  154. make.top.equalTo(self).offset(FITSIZE(319));
  155. make.right.equalTo(self);
  156. make.height.mas_equalTo(FITSIZE(40));
  157. }];
  158. [self.goodIntro mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.left.equalTo(self.bottomView);
  160. make.top.equalTo(self.bottomView);
  161. make.width.mas_equalTo(kScreenWidth/3);
  162. make.bottom.equalTo(self.bottomView);
  163. }];
  164. [self.shopService mas_makeConstraints:^(MASConstraintMaker *make) {
  165. make.left.equalTo(self.goodIntro.mas_right);
  166. make.top.equalTo(self.goodIntro);
  167. make.width.equalTo(self.goodIntro);
  168. make.bottom.equalTo(self.goodIntro);
  169. }];
  170. [self.postService mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.left.equalTo(self.shopService.mas_right);
  172. make.top.equalTo(self.shopService);
  173. make.width.equalTo(self.shopService);
  174. make.bottom.equalTo(self.shopService);
  175. }];
  176. }
  177. - (void)couponTapAction:(UIGestureRecognizer *)sender {
  178. if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewTapCoupon)]) {
  179. [self.delegate yh_GoodDetailViewTapCoupon];
  180. }
  181. }
  182. - (void)shopTapAction:(UIGestureRecognizer *)sender {
  183. if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewTapShop)]) {
  184. [self.delegate yh_GoodDetailViewTapShop];
  185. }
  186. }
  187. #pragma mark - lazy
  188. - (CALayer *)middleLineLayer {
  189. if (!_middleLineLayer) {
  190. _middleLineLayer = [CALayer layer];
  191. _middleLineLayer.frame = CGRectMake(0, FITSIZE(214), kScreenWidth, FITSIZE(5));
  192. _middleLineLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
  193. }
  194. return _middleLineLayer;
  195. }
  196. - (CALayer *)bottomLineLayer {
  197. if (!_bottomLineLayer) {
  198. _bottomLineLayer = [CALayer layer];
  199. _bottomLineLayer.frame = CGRectMake(0, FITSIZE(319), kScreenWidth, 0.5);
  200. _bottomLineLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
  201. }
  202. return _bottomLineLayer;
  203. }
  204. - (UILabel *)goodTitleLabel {
  205. if (!_goodTitleLabel) {
  206. _goodTitleLabel = [[UILabel alloc] init];
  207. _goodTitleLabel.backgroundColor = [UIColor clearColor];
  208. _goodTitleLabel.textColor = [UIColor YHColorWithHex:0x222222];
  209. _goodTitleLabel.font = [UIFont systemFontOfSize:FITSIZE(14)];
  210. }
  211. return _goodTitleLabel;
  212. }
  213. - (UILabel *)priceLabel {
  214. if (!_priceLabel) {
  215. _priceLabel = [[UILabel alloc] init];
  216. _priceLabel.backgroundColor = [UIColor clearColor];
  217. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  218. _priceLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  219. }
  220. return _priceLabel;
  221. }
  222. - (UIImageView *)discountImageView {
  223. if (!_discountImageView) {
  224. _discountImageView = [[UIImageView alloc] init];
  225. _discountImageView.backgroundColor = [UIColor clearColor];
  226. _discountImageView.image = [UIImage imageNamed:@"couponPrice"];
  227. }
  228. return _discountImageView;
  229. }
  230. - (UILabel *)discountPriceLabel {
  231. if (!_discountPriceLabel) {
  232. _discountPriceLabel = [[UILabel alloc] init];
  233. _discountPriceLabel.backgroundColor = [UIColor clearColor];
  234. _discountPriceLabel.textColor = [UIColor YHColorWithHex:0xff2420];
  235. _discountPriceLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(18)];
  236. }
  237. return _discountPriceLabel;
  238. }
  239. - (UILabel *)freePostLabel {
  240. if (!_freePostLabel) {
  241. _freePostLabel = [[UILabel alloc] init];
  242. _freePostLabel.backgroundColor = [UIColor clearColor];
  243. _freePostLabel.textColor = [UIColor YHColorWithHex:0x999999];
  244. _freePostLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  245. }
  246. return _freePostLabel;
  247. }
  248. - (UILabel *)volumeLabel {
  249. if (!_volumeLabel) {
  250. _volumeLabel = [[UILabel alloc] init];
  251. _volumeLabel.backgroundColor = [UIColor clearColor];
  252. _volumeLabel.textColor = [UIColor YHColorWithHex:0x999999];
  253. _volumeLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  254. }
  255. return _volumeLabel;
  256. }
  257. - (UIImageView *)couponImageView {
  258. if (!_couponImageView) {
  259. _couponImageView = [[UIImageView alloc] init];
  260. _couponImageView.backgroundColor = [UIColor clearColor];
  261. _couponImageView.image = [UIImage imageNamed:@"cintend_voucher"];
  262. _couponImageView.userInteractionEnabled = YES;
  263. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(couponTapAction:)];
  264. [_couponImageView addGestureRecognizer:tap];
  265. }
  266. return _couponImageView;
  267. }
  268. - (UILabel *)couponPriceLabel {
  269. if (!_couponPriceLabel) {
  270. _couponPriceLabel = [[UILabel alloc] init];
  271. _couponPriceLabel.backgroundColor = [UIColor clearColor];
  272. _couponPriceLabel.textColor = [UIColor whiteColor];
  273. _couponPriceLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(16)];
  274. _couponPriceLabel.textAlignment = NSTextAlignmentCenter;
  275. }
  276. return _couponPriceLabel;
  277. }
  278. - (UILabel *)couponTimeLabel {
  279. if (!_couponTimeLabel) {
  280. _couponTimeLabel = [[UILabel alloc] init];
  281. _couponTimeLabel.backgroundColor = [UIColor clearColor];
  282. _couponTimeLabel.textColor = [UIColor whiteColor];
  283. _couponTimeLabel.font = [UIFont systemFontOfSize:FITSIZE(10)];
  284. _couponTimeLabel.textAlignment = NSTextAlignmentCenter;
  285. }
  286. return _couponTimeLabel;
  287. }
  288. - (UILabel *)couponGetLabel {
  289. if (!_couponGetLabel) {
  290. _couponGetLabel = [[UILabel alloc] init];
  291. _couponGetLabel.backgroundColor = [UIColor clearColor];
  292. _couponGetLabel.textColor = [UIColor whiteColor];
  293. _couponGetLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(14)];
  294. _couponGetLabel.text = @"立即领券";
  295. _couponGetLabel.textAlignment = NSTextAlignmentCenter;
  296. }
  297. return _couponGetLabel;
  298. }
  299. - (UIView *)middleView {
  300. if (!_middleView) {
  301. _middleView = [[UIView alloc] init];
  302. _middleView.backgroundColor = [UIColor clearColor];
  303. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shopTapAction:)];
  304. [_middleView addGestureRecognizer:tap];
  305. }
  306. return _middleView;
  307. }
  308. - (UIImageView *)shopImageView {
  309. if (!_shopImageView) {
  310. _shopImageView = [[UIImageView alloc] init];
  311. _shopImageView.backgroundColor = [UIColor clearColor];
  312. _shopImageView.layer.borderColor = [UIColor YHColorWithHex:0xdddddd].CGColor;
  313. _shopImageView.layer.borderWidth = 0.5f;
  314. }
  315. return _shopImageView;
  316. }
  317. - (UILabel *)shopTitleLabel {
  318. if (!_shopTitleLabel) {
  319. _shopTitleLabel = [[UILabel alloc] init];
  320. _shopTitleLabel.backgroundColor = [UIColor clearColor];
  321. _shopTitleLabel.textColor = [UIColor YHColorWithHex:0x222222];
  322. _shopTitleLabel.font = [UIFont systemFontOfSize:FITSIZE(14)];
  323. }
  324. return _shopTitleLabel;
  325. }
  326. - (UIImageView *)viewShopRightImageView {
  327. if (!_viewShopRightImageView) {
  328. _viewShopRightImageView = [[UIImageView alloc] init];
  329. _viewShopRightImageView.backgroundColor = [UIColor clearColor];
  330. _viewShopRightImageView.image = [UIImage imageNamed:@"goto"];
  331. }
  332. return _viewShopRightImageView;
  333. }
  334. - (UILabel *)viewShopLabel {
  335. if (!_viewShopLabel) {
  336. _viewShopLabel = [[UILabel alloc] init];
  337. _viewShopLabel.backgroundColor = [UIColor clearColor];
  338. _viewShopLabel.textColor = [UIColor YHColorWithHex:0x999999];
  339. _viewShopLabel.font = [UIFont systemFontOfSize:FITSIZE(12)];
  340. _viewShopLabel.text = @"查看店铺所有优惠";
  341. }
  342. return _viewShopLabel;
  343. }
  344. - (UIView *)bottomView {
  345. if (!_bottomView) {
  346. _bottomView = [[UIView alloc] init];
  347. _bottomView.backgroundColor = [UIColor clearColor];
  348. for (NSInteger i=0; i<3; i++) {
  349. CALayer *layer = [CALayer layer];
  350. layer.frame = CGRectMake(kScreenWidth/3*i, FITSIZE(40)/2-FITSIZE(5)/2, 1, FITSIZE(5));
  351. layer.backgroundColor = [UIColor YHColorWithHex:0x999999].CGColor;
  352. [_bottomView.layer addSublayer:layer];
  353. }
  354. }
  355. return _bottomView;
  356. }
  357. - (UIButton *)goodIntro {
  358. if (!_goodIntro) {
  359. _goodIntro = [UIButton buttonWithType:UIButtonTypeCustom];
  360. _goodIntro.backgroundColor = [UIColor clearColor];
  361. [_goodIntro setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
  362. _goodIntro.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  363. }
  364. return _goodIntro;
  365. }
  366. - (UIButton *)shopService {
  367. if (!_shopService) {
  368. _shopService = [UIButton buttonWithType:UIButtonTypeCustom];
  369. _shopService.backgroundColor = [UIColor clearColor];
  370. [_shopService setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
  371. _shopService.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  372. }
  373. return _shopService;
  374. }
  375. - (UIButton *)postService {
  376. if (!_postService) {
  377. _postService = [UIButton buttonWithType:UIButtonTypeCustom];
  378. _postService.backgroundColor = [UIColor clearColor];
  379. [_postService setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
  380. _postService.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  381. }
  382. return _postService;
  383. }
  384. @end