猎豆优选

LDPopShareGoodView.m 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. //
  2. // LDPopShareGoodView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/10.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDPopShareGoodView.h"
  9. #import "PhoneLoginManager.h"
  10. #define FitYHShareGoodsWidth(X) (X)
  11. #define FitYHShareGoodsHeight(X) (X)
  12. //#define FitYHShareGoodsWidth(X) (X)
  13. //#define FitYHShareGoodsHeight(X) (X)
  14. #define QRWidth (85)
  15. @interface LDPopShareGoodView()
  16. {
  17. NSInteger count;
  18. }
  19. //主图
  20. @property (strong, nonatomic) UIImageView *mainImageView;
  21. //商品标题
  22. @property (strong, nonatomic) UILabel *titleLabel;
  23. //商品券后价
  24. @property (strong, nonatomic) UILabel *ticketAfterPrice;
  25. //券钱
  26. @property (strong, nonatomic) UILabel *ticketPrice;
  27. //券钱
  28. @property (strong, nonatomic) UIImageView *ticketPriceBackImageView;
  29. //原始价格
  30. @property (strong, nonatomic) UILabel *originalPrice;
  31. //二维码图片
  32. @property (strong, nonatomic) UIImageView *QRcodeImageView;
  33. @property (strong, nonatomic) UIImageView *appImageView;
  34. @property (strong,nonatomic) UILabel *appTitle;
  35. @property (nonatomic, strong) UILabel *quanType;
  36. @property (nonatomic, strong) UILabel *commissionLabel;
  37. @property (nonatomic, strong) UIActivityIndicatorView *indicatorView;
  38. @property (nonatomic, strong) UIImageView *userIcon;
  39. @property (nonatomic, strong) UILabel *nickName;
  40. @property (nonatomic, strong) UILabel *inviteCode;
  41. @property (nonatomic, strong) YYLabel *redPacket;
  42. @end
  43. @implementation LDPopShareGoodView
  44. -(instancetype)initWithFrame:(CGRect)frame{
  45. if (self=[super initWithFrame:frame]) {
  46. }
  47. return self;
  48. }
  49. -(void)setModel:(LDShareInfoModel *)model{
  50. _model=model;
  51. [self addUI];
  52. [self adjustUI];
  53. [self otherOP];
  54. }
  55. -(void)drawRect:(CGRect)rect{
  56. [super drawRect:rect];
  57. }
  58. -(void)addUI{
  59. [self addSubview:self.titleLabel];
  60. [self addSubview:self.mainImageView];
  61. [self addSubview:self.ticketAfterPrice];
  62. [self addSubview:self.originalPrice];
  63. [self addSubview:self.ticketPriceBackImageView];
  64. [self.ticketPriceBackImageView addSubview:self.ticketPrice];
  65. [self.ticketPriceBackImageView addSubview:self.quanType];
  66. [self addSubview:self.QRcodeImageView];
  67. [self addSubview:self.appImageView];
  68. [self addSubview:self.appTitle];
  69. [self addSubview:self.commissionLabel];
  70. [self addSubview:self.indicatorView];
  71. [self.indicatorView startAnimating];
  72. [self addSubview:self.userIcon];
  73. [self addSubview:self.nickName];
  74. [self addSubview:self.inviteCode];
  75. [self addSubview:self.redPacket];
  76. if (!self.model.is_coupon.boolValue) {
  77. self.ticketPrice.hidden=YES;
  78. self.ticketPriceBackImageView.hidden=YES;
  79. }else{
  80. self.ticketPrice.hidden=NO;
  81. self.ticketPriceBackImageView.hidden=NO;
  82. }
  83. }
  84. -(void)adjustUI{
  85. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(20)));
  87. make.top.mas_equalTo(FitYHShareGoodsHeight(26));
  88. make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-20)));
  89. }];
  90. [self.mainImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(20)));
  92. make.top.equalTo(self.titleLabel.mas_bottom).offset(FitYHShareGoodsHeight(22));
  93. make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-20)));
  94. make.height.mas_equalTo(FitYHShareGoodsWidth(self.width-2*FITSIZE(20)));
  95. }];
  96. [self.ticketAfterPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(15)));
  98. make.top.equalTo(self.mainImageView.mas_bottom).offset(FitYHShareGoodsHeight(20));
  99. }];
  100. [self.originalPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.left.mas_equalTo(self.ticketAfterPrice.mas_right).mas_offset(5);
  102. make.centerY.mas_equalTo(self.ticketAfterPrice.mas_centerY);
  103. // make.width.mas_equalTo(FITSIZE(74));
  104. }];
  105. [self.ticketPriceBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.left.equalTo(self.originalPrice.mas_left);
  107. make.top.mas_equalTo(self.originalPrice.mas_bottom).mas_offset(Fitsize(10));
  108. make.width.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(64)));
  109. make.height.mas_equalTo(FitYHShareGoodsHeight(FITSIZE(14)));
  110. }];
  111. [self.quanType mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.top.bottom.mas_equalTo(0);
  113. make.width.mas_equalTo(Fitsize(20));
  114. }];
  115. [self.ticketPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.left.mas_equalTo(Fitsize(20));
  117. make.right.top.bottom.mas_equalTo(0);
  118. }];
  119. [self.QRcodeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  120. make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-19)));
  121. make.top.equalTo(self.mainImageView.mas_bottom).offset(FitYHShareGoodsHeight(20));
  122. make.width.height.mas_equalTo(FITSIZE(QRWidth));
  123. }];
  124. [self.appImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.centerX.mas_equalTo(self.QRcodeImageView.mas_centerX);
  126. make.centerY.mas_equalTo(self.QRcodeImageView.mas_centerY);
  127. make.width.height.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(18)));
  128. }];
  129. // [self.appTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  130. // make.top.equalTo(self.appImageView.mas_top);
  131. // make.right.equalTo(self.QRcodeImageView.mas_right);
  132. // }];
  133. [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.centerX.mas_equalTo(self.QRcodeImageView.mas_centerX);
  135. make.top.mas_equalTo(self.QRcodeImageView.mas_bottom).mas_offset(5);
  136. }];
  137. [self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.left.mas_equalTo(self.ticketAfterPrice.mas_left);
  139. make.top.mas_equalTo(self.ticketAfterPrice.mas_bottom).mas_offset(Fitsize(10));
  140. make.width.height.mas_equalTo(Fitsize(30));
  141. }];
  142. [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
  143. make.left.mas_equalTo(self.userIcon.mas_right).mas_offset(5);
  144. make.centerY.mas_equalTo(self.userIcon.mas_centerY);
  145. make.width.mas_equalTo(Fitsize(100));
  146. make.height.mas_equalTo(Fitsize(20));
  147. }];
  148. [self.inviteCode mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.left.mas_equalTo(self.userIcon.mas_left);
  150. make.top.mas_equalTo(self.userIcon.mas_bottom).mas_equalTo(Fitsize(10));
  151. make.width.mas_equalTo(Fitsize(140));
  152. make.height.mas_equalTo(Fitsize(20));
  153. }];
  154. [self.redPacket mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.left.mas_equalTo(self.inviteCode.mas_left);
  156. make.top.mas_equalTo(self.inviteCode.mas_bottom).mas_offset(Fitsize(10));
  157. }];
  158. self.ticketPriceBackImageView.hidden = YES;
  159. }
  160. -(void)otherOP{
  161. self.backgroundColor=[UIColor yhGrayColor];
  162. [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:self.model.img] placeholderImage:[UIImage imageNamed:@"share_goods_default_img"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  163. [self.indicatorView stopAnimating];
  164. count++;
  165. if (count>1) {
  166. if (self.imgSuccBlock) {
  167. self.imgSuccBlock();
  168. }
  169. }
  170. }];
  171. }
  172. #pragma mark 懒加载
  173. -(UILabel *)titleLabel{
  174. if (!_titleLabel) {
  175. _titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(20)), FitYHShareGoodsHeight(46), FitYHShareGoodsWidth(self.width-2*FITSIZE(20)), 0)];
  176. _titleLabel.font = [UIFont systemFontOfSize:14];
  177. // NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
  178. // UIImage *img;
  179. // if (self.model.shareGoodsFromType==YHShareGoodsFromTypeTianMao) {
  180. // img= [UIImage imageNamed:@"share_title_tm"];
  181. // }else if(self.model.shareGoodsFromType==YHShareGoodsFromTypeTaoBao){
  182. //
  183. // }
  184. // if (img) {
  185. // textAttach.image = img;
  186. // }
  187. // textAttach.bounds = CGRectMake(0, -2, img.size.width*0.7, img.size.height*0.7);
  188. // NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",self.model.title]];
  189. // NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
  190. // [attri insertAttributedString:string atIndex:0];
  191. NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
  192. UIImage *img;
  193. if (self.model.shop_type.integerValue == 1) {
  194. img= [UIImage imageNamed:@"tm_shop"];
  195. }
  196. if (img) {
  197. textAttach.image = img;
  198. textAttach.bounds = CGRectMake(0, -2, 15, 15);
  199. }
  200. NSMutableAttributedString *attri;
  201. if (self.model.shop_type.integerValue == 1) {
  202. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",self.model.title]];
  203. }else {
  204. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",self.model.title]];
  205. }
  206. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
  207. [attri insertAttributedString:string atIndex:0];
  208. _titleLabel.attributedText = attri;
  209. // _titleLabel.text=@"虹小型电风扇迷你手持电扇USB学生宿舍 ";
  210. _titleLabel.numberOfLines=2;
  211. [_titleLabel sizeToFit];
  212. }
  213. return _titleLabel;
  214. }
  215. -(UIImageView *)mainImageView{
  216. if (!_mainImageView) {
  217. _mainImageView=[[UIImageView alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(20)), self.titleLabel.bottom+FitYHShareGoodsHeight(42), FitYHShareGoodsWidth(self.width-2*FITSIZE(20)), FitYHShareGoodsWidth((self.width-2*FITSIZE(20))))];
  218. }
  219. return _mainImageView;
  220. }
  221. -(UILabel *)ticketAfterPrice{
  222. if (!_ticketAfterPrice) {
  223. _ticketAfterPrice=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(15)), self.mainImageView.bottom+FitYHShareGoodsHeight(40), 0, 0)];
  224. if (self.model.is_coupon.boolValue) {
  225. _ticketAfterPrice.text=[NSString stringWithFormat:@"券后¥%.2f",[self.model.discount_price floatValue]];
  226. }else{
  227. _ticketAfterPrice.text=[NSString stringWithFormat:@"折后¥%.2f",[self.model.discount_price floatValue]];
  228. }
  229. _ticketAfterPrice.font=[UIFont systemFontOfSize:14.0f];
  230. _ticketAfterPrice.textColor=[UIColor YHColorWithHex:0xEE1515];
  231. [_ticketAfterPrice sizeToFit];
  232. }
  233. return _ticketAfterPrice;
  234. }
  235. -(UILabel *)originalPrice{
  236. if (!_originalPrice) {
  237. _originalPrice=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(14)), self.ticketAfterPrice.bottom+FitYHShareGoodsHeight(14), 0, 0)];
  238. NSString *price=[NSString stringWithFormat:@"%.2f",[self.model.price floatValue]];
  239. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:price];
  240. [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, price.length)];
  241. [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor YHColorWithHex:0x999999] range:NSMakeRange(0, price.length)];
  242. [_originalPrice setAttributedText:attri];
  243. _originalPrice.textColor=[UIColor YHColorWithHex:0x999999];
  244. _originalPrice.font=[UIFont systemFontOfSize:12.0f];
  245. [_originalPrice sizeToFit];
  246. _originalPrice.centerY = self.ticketAfterPrice.centerY;
  247. }
  248. return _originalPrice;
  249. }
  250. -(UIImageView *)ticketPriceBackImageView{
  251. if (!_ticketPriceBackImageView) {
  252. _ticketPriceBackImageView=[[UIImageView alloc]initWithFrame:CGRectMake(self.originalPrice.x, self.originalPrice.bottom+FitYHShareGoodsHeight(22), FitYHShareGoodsWidth(FITSIZE(64)), FitYHShareGoodsHeight(14))];
  253. // _ticketPriceBackImageView.backgroundColor=[UIColor blueColor];
  254. [_ticketPriceBackImageView setImage:[UIImage imageNamed:@"quan_detail"]];
  255. }
  256. return _ticketPriceBackImageView;
  257. }
  258. -(UILabel *)ticketPrice{
  259. if (!_ticketPrice) {
  260. _ticketPrice=[[UILabel alloc]init];
  261. _ticketPrice.textColor=[UIColor whiteColor];
  262. _ticketPrice.text=[NSString stringWithFormat:@"%@元",self.model.coupon_price];
  263. _ticketPrice.font=[UIFont systemFontOfSize:Fitsize(10)];
  264. _ticketPrice.textAlignment=NSTextAlignmentCenter;
  265. }
  266. return _ticketPrice;
  267. }
  268. - (UILabel *)quanType {
  269. if (!_quanType) {
  270. _quanType = [[UILabel alloc] init];
  271. if (self.model.is_coupon.boolValue) {
  272. _quanType.text=@"券";
  273. }else{
  274. _quanType.text=@"折";
  275. }
  276. _quanType.textColor=[UIColor whiteColor];
  277. _quanType.font=[UIFont systemFontOfSize:Fitsize(10)];
  278. _quanType.textAlignment=NSTextAlignmentCenter;
  279. }
  280. return _quanType;
  281. }
  282. - (UILabel *)commissionLabel {
  283. if (!_commissionLabel) {
  284. _commissionLabel = [[UILabel alloc] init];
  285. _commissionLabel.text = [NSString stringWithFormat:@"购买可赚¥%@",self.model.self_commission];
  286. _commissionLabel.textColor = [UIColor homeRedColor];
  287. _commissionLabel.font = [UIFont boldSystemFontOfSize:Fitsize(12)];
  288. _commissionLabel.text = [NSString stringWithFormat:@"扫我赚¥%@",self.model.self_commission];
  289. _commissionLabel.hidden = YES;
  290. }
  291. return _commissionLabel;
  292. }
  293. -(UIImageView *)QRcodeImageView{
  294. if (!_QRcodeImageView) {
  295. _QRcodeImageView=[[UIImageView alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(self.width-FITSIZE(19)-FITSIZE(QRWidth)), self.mainImageView.bottom+FitYHShareGoodsHeight(38), FitYHShareGoodsWidth(FITSIZE(QRWidth)), FitYHShareGoodsWidth(FITSIZE(QRWidth)))];
  296. //1. 实例化二维码滤镜
  297. CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
  298. // 2. 恢复滤镜的默认属性
  299. [filter setDefaults];
  300. // 3. 将字符串转换成NSData
  301. NSString *urlStr =self.model.url;
  302. NSData *data = [urlStr dataUsingEncoding:NSUTF8StringEncoding];
  303. // 4. 通过KVO设置滤镜inputMessage数据
  304. [filter setValue:data forKey:@"inputMessage"];
  305. // 5. 获得滤镜输出的图像
  306. CIImage *outputImage = [filter outputImage];
  307. UIImage *img=[outputImage createNonInterpolatedUIImagewithSize:FITSIZE(QRWidth)];
  308. [_QRcodeImageView setImage:img];
  309. _QRcodeImageView.backgroundColor=[UIColor clearColor];
  310. }
  311. return _QRcodeImageView;
  312. }
  313. -(UIImageView *)appImageView{
  314. if (!_appImageView) {
  315. _appImageView=[[UIImageView alloc]init];
  316. [_appImageView setImage:[UIImage imageNamed:@"share_appicon"]];
  317. }
  318. return _appImageView;
  319. }
  320. -(UILabel *)appTitle{
  321. if (!_appTitle) {
  322. _appTitle=[[UILabel alloc]initWithFrame:CGRectMake(self.appImageView.right, self.appImageView.y, self.QRcodeImageView.right-self.appImageView.right-10,self.appImageView.height )];
  323. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  324. NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
  325. _appTitle.text=app_Name;
  326. _appTitle.textColor=[UIColor YHColorWithHex:0x666666];
  327. _appTitle.font=[UIFont systemFontOfSize:12.0f];
  328. _appTitle.textAlignment=NSTextAlignmentRight;
  329. }
  330. return _appTitle;
  331. }
  332. - (UIActivityIndicatorView *)indicatorView {
  333. if (!_indicatorView) {
  334. _indicatorView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
  335. _indicatorView.frame= CGRectMake(0, 0, 50, 50);
  336. _indicatorView.color = [UIColor homeRedColor];
  337. _indicatorView.center = CGPointMake(self.width/2, self.height/2);
  338. _indicatorView.hidesWhenStopped = YES;
  339. }
  340. return _indicatorView;
  341. }
  342. - (UIImageView *)userIcon {
  343. if (!_userIcon) {
  344. _userIcon = [[UIImageView alloc] init];
  345. _userIcon.layer.cornerRadius = Fitsize(15);
  346. _userIcon.backgroundColor = [UIColor yhGrayColor];
  347. _userIcon.layer.masksToBounds = YES;
  348. [_userIcon sd_setImageWithURL:[NSURL URLWithString:self.model.userinfo[@"headimg"]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  349. count++;
  350. if (count>1) {
  351. if (self.imgSuccBlock) {
  352. self.imgSuccBlock();
  353. }
  354. }
  355. }];
  356. }
  357. return _userIcon;
  358. }
  359. - (UILabel *)nickName {
  360. if (!_nickName) {
  361. _nickName = [[UILabel alloc] init];
  362. _nickName.textColor = [UIColor YHColorWithHex:0x333333];
  363. _nickName.font = [UIFont systemFontOfSize:Fitsize(14)];
  364. _nickName.text = self.model.userinfo[@"nickname"];
  365. }
  366. return _nickName;
  367. }
  368. - (UILabel *)inviteCode {
  369. if (!_inviteCode) {
  370. _inviteCode = [[UILabel alloc] init];
  371. _inviteCode.textColor = [UIColor YHColorWithHex:0x333333];
  372. _inviteCode.font = [UIFont systemFontOfSize:Fitsize(12)];
  373. _inviteCode.text = [NSString stringWithFormat:@"邀请码:%@",self.model.userinfo[@"invite_code"]];
  374. }
  375. return _inviteCode;
  376. }
  377. - (YYLabel *)redPacket {
  378. if (!_redPacket) {
  379. _redPacket = [[YYLabel alloc] init];
  380. _redPacket.hidden = ![self.model.red_active_status boolValue];
  381. if ([self.model.red_active_status boolValue]) {
  382. UIImage *img = [UIImage imageNamed:@"redPicket"];
  383. YYAnimatedImageView *imgeView = [[YYAnimatedImageView alloc] initWithImage:img];
  384. imgeView.frame = CGRectMake(0, 0, 15, 18);
  385. NSMutableAttributedString *shopAtti = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@元红包",self.model.red_active_money]];
  386. NSMutableAttributedString *mua = [NSMutableAttributedString yy_attachmentStringWithContent:imgeView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imgeView.frame.size alignToFont:[UIFont systemFontOfSize:14] alignment:YYTextVerticalAlignmentCenter];
  387. [shopAtti insertAttributedString:mua atIndex:0];
  388. shopAtti.yy_font = [UIFont systemFontOfSize:12];
  389. shopAtti.yy_color = [UIColor homeRedColor];
  390. // [shopAtti yy_setColor:[UIColor YHColorWithHex:0x262626] range:NSMakeRange(shopAtti.length-2, 2)];
  391. _redPacket.attributedText = shopAtti;
  392. }
  393. }
  394. return _redPacket;
  395. }
  396. @end