ShareGoodsAlert.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // ShareGoodsAlert.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2021/6/7.
  6. // Copyright © 2021 cat. All rights reserved.
  7. //
  8. #import "ShareGoodsAlert.h"
  9. #import "ShareFriendVC.h"
  10. //#import "PublishDynamicViewController.h"
  11. @implementation ShareGoodsAlert
  12. {
  13. CommodityDetailModel *goodsData;
  14. }
  15. -(instancetype)initWithFrame:(CGRect)frame andGoodsModel:(CommodityDetailModel *)goodsModel
  16. {
  17. self = [super initWithFrame:frame];
  18. if (self) {
  19. goodsData = goodsModel;
  20. UITapGestureRecognizer *taps =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideSelf)];
  21. [self addGestureRecognizer:taps];
  22. self.backgroundColor = RGBA(1, 1, 1, 0.3);
  23. backView = [[UIView alloc]init];
  24. backView.frame = CGRectMake(0, _window_height, _window_width, 185);
  25. backView.backgroundColor = UIColor.whiteColor;
  26. [self addSubview:backView];
  27. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:backView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
  28. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  29. maskLayer.frame = backView.bounds;
  30. maskLayer.path = maskPath.CGPath;
  31. backView.layer.mask = maskLayer;
  32. NSArray *arr;
  33. if ([goodsModel.shop_uid isEqual:[Config getOwnID]]) {
  34. arr=@[YZMsg(@"分享商品"),YZMsg(@"取消分享")];
  35. backView.size = CGSizeMake(_window_width, 125);
  36. }else{
  37. arr=@[YZMsg(@"分享商品,赚取佣金¥"),YZMsg(@"分享商品"),YZMsg(@"取消分享")];
  38. backView.size = CGSizeMake(_window_width, 185);
  39. }
  40. for (int i = 0; i < arr.count; i ++) {
  41. UIView *views = [[UIView alloc]init];
  42. views.backgroundColor = [UIColor whiteColor];
  43. [backView addSubview:views];
  44. UILabel *lineLb = [[UILabel alloc]init];
  45. if ([goodsModel.shop_uid isEqual:[Config getOwnID]]) {
  46. if ( i == 0) {
  47. views.frame = CGRectMake(0,i*60, backView.width, 65);
  48. UIButton *friendBtn = [UIButton buttonWithType:0];
  49. friendBtn.frame = CGRectMake(0, 0, views.width, views.height);
  50. [friendBtn setTitle:arr[i] forState:0];
  51. friendBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  52. [friendBtn setTitleColor:Pink_Cor forState:0];
  53. [friendBtn addTarget:self action:@selector(shareFriend) forControlEvents:UIControlEventTouchUpInside];
  54. [views addSubview:friendBtn];
  55. lineLb.frame = CGRectMake(0, views.height-5, backView.width, 5);
  56. }else{
  57. views.frame = CGRectMake(0,i*60+5, backView.width, 60);
  58. UIButton *cancelBtn = [UIButton buttonWithType:0];
  59. cancelBtn.frame = CGRectMake(0, 0, views.width, views.height);
  60. [cancelBtn setTitle:arr[i] forState:0];
  61. cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  62. [cancelBtn setTitleColor:UIColor.blackColor forState:0];
  63. [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
  64. [views addSubview:cancelBtn];
  65. }
  66. }else{
  67. if (i == 0) {
  68. views.frame = CGRectMake(0,i*60, backView.width, 60);
  69. _subTitle = [[UILabel alloc]init];
  70. _subTitle.frame = CGRectMake(0, 20, backView.width, 20);
  71. _subTitle.font = [UIFont systemFontOfSize:14];
  72. _subTitle.text = [NSString stringWithFormat:@"%@%@",arr[i],minstr([ goodsModel.goods_info valueForKey:@"share_income"])] ;
  73. _subTitle.textAlignment = NSTextAlignmentCenter;
  74. _subTitle.textColor = UIColor.grayColor;
  75. [views addSubview:_subTitle];
  76. lineLb.frame = CGRectMake(0, views.height-1, backView.width, 1);
  77. }else if(i == 1){
  78. views.frame = CGRectMake(0,i*60, backView.width, 65);
  79. UIButton *friendBtn = [UIButton buttonWithType:0];
  80. friendBtn.frame = CGRectMake(0, 0, views.width, views.height);
  81. [friendBtn setTitle:arr[i] forState:0];
  82. friendBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  83. [friendBtn setTitleColor:Pink_Cor forState:0];
  84. [friendBtn addTarget:self action:@selector(shareFriend) forControlEvents:UIControlEventTouchUpInside];
  85. [views addSubview:friendBtn];
  86. lineLb.frame = CGRectMake(0, views.height-5, backView.width, 5);
  87. }else{
  88. views.frame = CGRectMake(0,i*60+5, backView.width, 60);
  89. UIButton *cancelBtn = [UIButton buttonWithType:0];
  90. cancelBtn.frame = CGRectMake(0, 0, views.width, views.height);
  91. [cancelBtn setTitle:arr[i] forState:0];
  92. cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  93. [cancelBtn setTitleColor:UIColor.blackColor forState:0];
  94. [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
  95. [views addSubview:cancelBtn];
  96. }
  97. }
  98. lineLb.backgroundColor = RGB(245, 245, 245);
  99. [views addSubview:lineLb];
  100. }
  101. [UIView animateWithDuration:0.3 animations:^{
  102. if ([goodsModel.shop_uid isEqual:[Config getOwnID]]) {
  103. backView.frame = CGRectMake(0, _window_height-125, _window_width, 125);
  104. }else{
  105. backView.frame = CGRectMake(0, _window_height-185, _window_width, 185);
  106. }
  107. }];
  108. }
  109. return self;
  110. }
  111. -(void)hideSelf{
  112. [UIView animateWithDuration:0.3 animations:^{
  113. if ([goodsData.shop_uid isEqual:[Config getOwnID]]) {
  114. backView.frame = CGRectMake(0, _window_height, _window_width, 125);
  115. }else{
  116. backView.frame = CGRectMake(0, _window_height, _window_width, 185);
  117. }
  118. } completion:^(BOOL finished) {
  119. [self removeFromSuperview];
  120. }];
  121. }
  122. -(void)cancelBtnClick{
  123. [self hideSelf];
  124. }
  125. -(void)shareFriend{
  126. ShareFriendVC *friendVc = [[ShareFriendVC alloc]init];
  127. friendVc.goodsId =goodsData.goodsid;
  128. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:friendVc animated:YES];
  129. [self cancelBtnClick];
  130. }
  131. @end