酷店

KDPIDTipView.m 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // KDPIDTipView.m
  3. // KuDianProject
  4. //
  5. // Created by 学丽 on 2019/7/9.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPIDTipView.h"
  9. @implementation KDPIDTipView
  10. -(instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self=[super initWithFrame:frame];
  13. if (self) {
  14. self.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.4];
  15. UIView *backV=[[UIView alloc]init];
  16. backV.backgroundColor=[UIColor whiteColor];
  17. backV.layer.cornerRadius=9;
  18. self.backV=backV;
  19. backV.layer.masksToBounds=YES;
  20. [self addSubview:backV];
  21. [backV mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.width.mas_equalTo(281);
  23. make.height.mas_equalTo(345);
  24. make.centerY.mas_equalTo(self.mas_centerY);
  25. make.centerX.mas_equalTo(self.mas_centerX);
  26. }];
  27. self.pidtitleL=[[UILabel alloc]init];
  28. self.pidtitleL.font=[UIFont boldSystemFontOfSize:20];
  29. self.pidtitleL.textColor=[UIColor colorWithHexString:ThemeColor];
  30. self.pidtitleL.text=@"推广商品前需绑定PID"; self.pidtitleL.textAlignment=NSTextAlignmentCenter;
  31. [backV addSubview:self.pidtitleL];
  32. [self.pidtitleL mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.left.right.mas_equalTo(0);
  34. make.height.mas_equalTo(28);
  35. make.top.mas_equalTo(31);
  36. }];
  37. self.pidContentL =[[UILabel alloc]init];
  38. self.pidContentL.textColor=[UIColor colorWithHexString:@"#333333"];
  39. self.pidContentL.font=[UIFont systemFontOfSize:15];
  40. self.pidContentL.attributedText=[KDPublicMethod sethanggaoWithStr:@"PID是您的专属推广位,用于同步订单 获得收益,推广商品前请确保您已在 快手小店上绑定了该PID。" linSpacing:4];
  41. [backV addSubview:self.pidContentL];
  42. self.pidContentL.numberOfLines=0;
  43. [self.pidContentL mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.mas_equalTo(self.pidtitleL.mas_bottom).offset(10);
  45. make.left.mas_equalTo(10);
  46. make.right.mas_equalTo(-10);
  47. make.height.mas_equalTo(98);
  48. }];
  49. //
  50. self.pidLabel=[[UILabel alloc]init];
  51. self.pidLabel.text=@"您的PID已生成,记得去绑定";
  52. self.pidLabel.font=[UIFont systemFontOfSize:11];
  53. self.pidLabel.textAlignment=NSTextAlignmentCenter;
  54. self.pidLabel.textColor=[UIColor colorWithHexString:@"#9B9B9B"];
  55. [backV addSubview:self.pidLabel];
  56. self.bindBtn =[[UIButton alloc]init];
  57. [self.bindBtn setTitle:@"去绑定" forState:UIControlStateNormal];
  58. self.bindBtn.titleLabel.font=[UIFont systemFontOfSize:14];
  59. [self.bindBtn addTarget:self action:@selector(bingdclickButton) forControlEvents:UIControlEventTouchUpInside];
  60. self.bindBtn.layer.cornerRadius=21.5;
  61. self.bindBtn.layer.masksToBounds=YES;
  62. self.bindBtn.backgroundColor=[UIColor gradientOneColor:[UIColor colorWithHexString:@"#FF235F"] toColor:[UIColor colorWithHexString:@"#FF7676"] Width:230];
  63. [backV addSubview:self.bindBtn];
  64. [self.bindBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.mas_equalTo(26);
  66. make.top.mas_equalTo(self.pidContentL.mas_bottom).offset(16);
  67. make.height.mas_equalTo(43);
  68. make.right.mas_equalTo(-25);
  69. }];
  70. [self.pidLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.right.mas_equalTo(0);
  72. make.height.mas_equalTo(16);
  73. make.top.mas_equalTo(self.bindBtn.mas_bottom).offset(31);
  74. }];
  75. self.CancelBtn=[[UIButton alloc]init];
  76. [self.CancelBtn setTitle:@"已绑定,不再提示" forState:UIControlStateNormal];
  77. [self.CancelBtn setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  78. self.CancelBtn.titleLabel.font=[UIFont systemFontOfSize:12];
  79. [self.CancelBtn addTarget:self action:@selector(copyPidClickBtn) forControlEvents:UIControlEventTouchUpInside];
  80. [backV addSubview:self.CancelBtn];
  81. [self.CancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.height.mas_equalTo(20);
  83. make.top.mas_equalTo(self.pidLabel.mas_bottom).offset(12);
  84. make.left.mas_equalTo(26);
  85. make.right.mas_equalTo(-26);
  86. }];
  87. }
  88. return self;
  89. }
  90. -(void)setResultDic:(NSDictionary *)resultDic
  91. {
  92. _resultDic = resultDic;
  93. NSString *str=[NSString stringWithFormat:@"%@",resultDic[@"message"]];
  94. NSMutableAttributedString * attstr = [[NSMutableAttributedString alloc] initWithString:str];
  95. NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
  96. [paragraphStyle1 setLineSpacing:8];
  97. [attstr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [str length])];
  98. [self.pidContentL setAttributedText:attstr];
  99. self.pidtitleL.text=resultDic[@"title"];
  100. /**
  101. 弹框状态 1:用户没有快手Pid
  102. 2:用户有Pid,首次提示
  103. 3:用户有Pid,二次提示
  104. */
  105. self.CancelBtn.hidden=YES;
  106. self.pidLabel.hidden=YES;
  107. self.pidLabel.text=resultDic[@"pid"];
  108. NSString *status=resultDic[@"status"];
  109. if (status.integerValue == 1) {
  110. [self.bindBtn setTitle:@"好的" forState:UIControlStateNormal];
  111. [self.backV mas_updateConstraints:^(MASConstraintMaker *make) {
  112. make.height.mas_equalTo(263);
  113. }];
  114. }else if (status.integerValue == 2)
  115. {
  116. self.CancelBtn.hidden=NO;
  117. self.pidLabel.hidden=NO;
  118. [self.bindBtn setTitle:@"去填写" forState:UIControlStateNormal];
  119. [self.backV mas_updateConstraints:^(MASConstraintMaker *make) {
  120. make.height.mas_equalTo(317);
  121. }];
  122. [self.CancelBtn setTitle:@"复制Pid" forState:UIControlStateNormal];
  123. [self.CancelBtn setTitleColor:[UIColor colorWithHexString:ThemeColor] forState:UIControlStateNormal];
  124. [self.CancelBtn mas_updateConstraints:^(MASConstraintMaker *make) {
  125. make.top.mas_equalTo(self.pidLabel.mas_bottom).offset(12);
  126. }];
  127. }else if (status.integerValue == 3)
  128. {
  129. self.CancelBtn.hidden=NO;
  130. [self.backV mas_updateConstraints:^(MASConstraintMaker *make) {
  131. make.height.mas_equalTo(284);
  132. }];
  133. [self.CancelBtn setTitle:@"已填好,不在提示" forState:UIControlStateNormal];
  134. [self.CancelBtn setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  135. [self.bindBtn setTitle:@"没有填好,去填写" forState:UIControlStateNormal];
  136. [self.CancelBtn mas_updateConstraints:^(MASConstraintMaker *make) {
  137. make.top.mas_equalTo(self.bindBtn.mas_bottom).offset(19);
  138. }];
  139. }
  140. }
  141. #pragma mark---pid跳转操作
  142. -(void)bingdclickButton
  143. {
  144. NSString *status=self.resultDic[@"status"];
  145. if (status.integerValue ==1) {//创建中
  146. self.hidden= YES;
  147. }else if(status.integerValue == 2 || status.integerValue == 3){
  148. //为2的时候需要统计
  149. if (status.integerValue == 2) {
  150. [self pidNumAdd];
  151. }
  152. BOOL isapp =[KDPublicMethod JumpOpenURL:self.resultDic[@"kwai_url"]];
  153. if (isapp) {
  154. [self jumpKwaiURL:self.resultDic[@"kwai_url"]];
  155. }else{
  156. [MBProgressHUD showMessage:KWaiMessage];
  157. }
  158. }
  159. self.hidden=YES;
  160. }
  161. #pragma mark---pid计数y统计
  162. -(void)pidNumAdd
  163. {
  164. [KDPNetworkRequestHTTP postURL:pidNumTotalURL params:nil success:^(id _Nonnull json) {
  165. [UIView animateWithDuration:1 animations:^{
  166. self.hidden =YES;
  167. }];
  168. } failure:^(NSError * _Nonnull error) {
  169. }];
  170. }
  171. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  172. {
  173. self.hidden =YES;
  174. }
  175. -(void) jumpKwaiURL:(NSString *)schemeUrl{
  176. NSURL *URL = [NSURL URLWithString:schemeUrl];
  177. dispatch_async(dispatch_get_main_queue(), ^{
  178. [[UIApplication sharedApplication] openURL:URL];
  179. });
  180. }
  181. -(void)tbOpenAndKwai
  182. {
  183. if (![KDPublicMethod JumpOpenURL:KWai]) {
  184. [MBProgressHUD showMessage:KWaiMessage];
  185. return;
  186. }
  187. NSString* requesturl= [NSString stringWithFormat:KWai];
  188. UIWebView* webview = [[UIWebView alloc]initWithFrame:CGRectZero];
  189. [[UIApplication sharedApplication].keyWindow addSubview:webview];
  190. NSURL*url = [NSURL URLWithString:requesturl];
  191. NSURLRequest *request = [NSURLRequest requestWithURL:url];
  192. [webview loadRequest:request];
  193. }
  194. #pragma mark---复制pid
  195. -(void)copyPidClickBtn
  196. {
  197. NSString *status=self.resultDic[@"status"];
  198. if (status.integerValue == 3) {
  199. [self pidNumAdd];
  200. return;
  201. }
  202. UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
  203. if (self.resultDic) {
  204. pastboard.string = self.resultDic[@"pid"];
  205. [MBProgressHUD showMessage:@"复制成功"];
  206. [UIView animateWithDuration:1 animations:^{
  207. self.hidden=YES;
  208. [self tbOpenAndKwai];
  209. }];
  210. }else {
  211. [MBProgressHUD showMessage:@"复制失败"];
  212. }
  213. }
  214. @end