dkahgld

ZBPidView.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. //
  2. // ZBPidView.m
  3. // ZBProject
  4. //
  5. // Created by 学丽 on 2019/4/2.
  6. // Copyright © 2019 ZB. All rights reserved.
  7. //
  8. #import "ZBPidView.h"
  9. @implementation ZBPidView
  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.5];
  15. [self addSubview:self.backV];
  16. [self.backV mas_makeConstraints:^(MASConstraintMaker *make) {
  17. make.width.mas_equalTo(281);
  18. make.height.mas_equalTo(345);
  19. make.centerX.mas_equalTo(self.centerX);
  20. make.centerY.mas_equalTo(self.centerY);
  21. }];
  22. [self.backV addSubview:self.titleLabel];
  23. [self.backV addSubview:self.contentLabel];
  24. [self.backV addSubview:self.okBtn];
  25. [self.backV addSubview:self.tipeBtn];
  26. [self.backV addSubview:self.copyBtn];
  27. [self.backV addSubview:self.pidLabael];
  28. [self.backV addSubview:self.segMentLabel];
  29. [self.backV addSubview:self.tipeLabel];
  30. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.top.mas_equalTo(35);
  32. make.height.mas_equalTo(28);
  33. make.left.mas_equalTo(10);
  34. make.right.mas_equalTo(-10);
  35. }];
  36. [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(20);
  38. make.left.mas_equalTo(16);
  39. make.right.mas_equalTo(-16);
  40. }];
  41. [self.segMentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.mas_equalTo(10);
  43. make.right.mas_equalTo(-10);
  44. make.height.mas_equalTo(2);
  45. make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(26);
  46. }];
  47. [self.tipeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.mas_equalTo(10);
  49. make.right.mas_equalTo(-10);
  50. make.height.mas_equalTo(25);
  51. make.top.mas_equalTo(self.segMentLabel.mas_bottom).offset(23);
  52. }];
  53. [self.okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.mas_equalTo(26);
  55. make.height.mas_equalTo(43);
  56. make.top.mas_equalTo(self.tipeLabel.mas_bottom).offset(36);
  57. make.right.mas_equalTo(-25);
  58. }];
  59. [self.tipeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(26);
  61. make.height.mas_equalTo(43);
  62. make.top.mas_equalTo(self.okBtn.mas_bottom).offset(5);
  63. make.right.mas_equalTo(-25);
  64. }];
  65. [self.pidLabael mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.mas_equalTo(self.okBtn.mas_bottom).offset(31);
  67. make.height.mas_equalTo(16);
  68. make.left.mas_equalTo(10);
  69. make.right.mas_equalTo(-10);
  70. }];
  71. [self.copyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.top.mas_equalTo(self.pidLabael.mas_bottom).offset(12);
  73. make.left.mas_equalTo(10);
  74. make.height.mas_equalTo(16);
  75. make.right.mas_equalTo(-10);
  76. }];
  77. }
  78. return self;
  79. }
  80. -(void)setAlertDic:(NSDictionary *)alertDic
  81. {
  82. _alertDic = alertDic;
  83. self.titleLabel.text=alertDic[@"title"];
  84. NSString *str=[NSString stringWithFormat:@"%@",alertDic[@"message"]];
  85. NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:str];
  86. NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
  87. [paragraphStyle1 setLineSpacing:8];
  88. [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [str length])];
  89. [self.contentLabel setAttributedText:attributedString1];
  90. [self.contentLabel sizeToFit];
  91. self.pidLabael.text=alertDic[@"pid"];
  92. //status
  93. NSString *status=alertDic[@"status"];
  94. self.tipeBtn.hidden=YES;
  95. self.copyBtn.hidden=YES;
  96. self.pidLabael.hidden=YES;
  97. if (status.integerValue == 1) {
  98. [self.okBtn setTitle:@"好的" forState:UIControlStateNormal];
  99. }else if (status.integerValue == 2)
  100. {
  101. self.pidLabael.hidden=YES;
  102. self.copyBtn.hidden=YES;
  103. [self.okBtn setTitle:@"去绑定" forState:UIControlStateNormal];
  104. [self.backV mas_updateConstraints:^(MASConstraintMaker *make) {
  105. make.height.mas_equalTo(345);
  106. }];
  107. self.tipeBtn.hidden=NO;
  108. }else if (status.integerValue == 3)
  109. {
  110. [self.backV mas_updateConstraints:^(MASConstraintMaker *make) {
  111. make.height.mas_equalTo(284);
  112. }];
  113. [self.okBtn setTitle:@"没填好去填写" forState:UIControlStateNormal];
  114. self.tipeBtn.hidden=NO;
  115. }
  116. self.tipeLabel.text=alertDic[@"red_message"];
  117. }
  118. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  119. {
  120. [UIView animateWithDuration:1 animations:^{
  121. if (self.type.integerValue == 1) {
  122. [self removeFromSuperview];
  123. }else{
  124. self.hidden =YES;
  125. }
  126. }];
  127. }
  128. -(UILabel *)titleLabel
  129. {
  130. if (!_titleLabel ) {
  131. _titleLabel=[[UILabel alloc]init];
  132. _titleLabel.textColor=[UIColor fontColor];
  133. _titleLabel.font=[UIFont boldSystemFontOfSize:20];
  134. _titleLabel.text=@"推广商品前需绑定PID"; _titleLabel.textAlignment=NSTextAlignmentCenter;
  135. }
  136. return _titleLabel;
  137. }
  138. -(UILabel *)contentLabel
  139. {
  140. if (!_contentLabel) {
  141. _contentLabel=[[UILabel alloc]init];
  142. _contentLabel.textColor=[UIColor fontColor];
  143. _contentLabel.font=[UIFont systemFontOfSize:15];
  144. _contentLabel.numberOfLines=0;
  145. _contentLabel.text=@"PID是您的专属推广位,用于同步订单 获得收益,推广商品前请确保您已在 快手小店上绑定了该PID。"; _contentLabel.textAlignment=NSTextAlignmentCenter;
  146. }
  147. return _contentLabel;
  148. }
  149. -(UIButton *)okBtn
  150. {
  151. if (!_okBtn) {
  152. _okBtn =[[UIButton alloc]init];
  153. _okBtn.backgroundColor=[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xFF8300] toColor:[UIColor YHColorWithHex:0xFF5200] withWidth:230];
  154. [_okBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  155. _okBtn.titleLabel.font=[UIFont systemFontOfSize:15];
  156. _okBtn.layer.cornerRadius=21.5;
  157. _okBtn.layer.masksToBounds=YES;
  158. [_okBtn addTarget:self action:@selector(clickOpenKwai) forControlEvents:UIControlEventTouchUpInside];
  159. }
  160. return _okBtn;
  161. }
  162. -(UIButton *)tipeBtn
  163. {
  164. if (!_tipeBtn) {
  165. _tipeBtn =[[UIButton alloc]init];
  166. _tipeBtn.backgroundColor=[UIColor clearColor];
  167. [_tipeBtn setTitleColor:[UIColor YHColorWithHex:0x9B9B9B] forState:UIControlStateNormal];
  168. _tipeBtn.titleLabel.font=[UIFont systemFontOfSize:14];
  169. [_tipeBtn setTitle:@"已绑定,不再提示" forState:UIControlStateNormal];
  170. _tipeBtn.layer.cornerRadius=21.5;
  171. _tipeBtn.layer.masksToBounds=YES;
  172. _tipeBtn.hidden=YES;
  173. [_tipeBtn addTarget:self action:@selector(clickTipe) forControlEvents:UIControlEventTouchUpInside];
  174. }
  175. return _tipeBtn;
  176. }
  177. -(UILabel *)segMentLabel
  178. {
  179. if (!_segMentLabel) {
  180. _segMentLabel=[[UILabel alloc]init];
  181. _segMentLabel.textColor=[UIColor baseColor];
  182. _segMentLabel.text=@"----------------------------------";
  183. }
  184. return _segMentLabel;
  185. }
  186. -(UILabel *)tipeLabel
  187. {
  188. if (!_tipeLabel ) {
  189. _tipeLabel=[[UILabel alloc]init];
  190. _tipeLabel.textColor=[UIColor YHColorWithHex:0xFF5703];
  191. _tipeLabel.font=[UIFont boldSystemFontOfSize:16];
  192. _tipeLabel.text=@"您的PID正在生成,请耐心等待~";
  193. _tipeLabel.textAlignment=NSTextAlignmentCenter;
  194. }
  195. return _tipeLabel;
  196. }
  197. -(UILabel *)pidLabael
  198. {
  199. if (!_pidLabael) {
  200. _pidLabael =[[UILabel alloc]init];
  201. _pidLabael.textColor=[UIColor YHColorWithHex:0x9B9B9B];
  202. _pidLabael.font=[UIFont systemFontOfSize:11];
  203. _pidLabael.textAlignment=NSTextAlignmentCenter;
  204. }
  205. return _pidLabael;
  206. }
  207. -(UIButton *)copyBtn
  208. {
  209. if (!_copyBtn) {
  210. _copyBtn =[[UIButton alloc]init];
  211. [_copyBtn setTitle:@"复制Pid" forState:UIControlStateNormal];
  212. [_copyBtn setTitleColor:[UIColor YHColorWithHex:0xFF7700] forState:UIControlStateNormal];
  213. _copyBtn.titleLabel.font=[UIFont systemFontOfSize:14];
  214. [_copyBtn addTarget:self action:@selector(cotyCLickBtn) forControlEvents:UIControlEventTouchUpInside];
  215. }
  216. return _copyBtn;
  217. }
  218. -(UIView *)backV
  219. {
  220. if (!_backV) {
  221. _backV =[[UIView alloc]init];
  222. _backV.backgroundColor=[UIColor whiteColor];
  223. _backV.layer.cornerRadius=9;
  224. _backV.layer.masksToBounds=YES;
  225. }
  226. return _backV;
  227. }
  228. -(void)clickOpenKwai
  229. {
  230. //status
  231. NSString *status=self.alertDic[@"status"];
  232. if (status.integerValue == 2 || status.integerValue == 3) {
  233. BOOL isopen =[PublicFunction canOpenURL:self.alertDic[@"kwai_url"]];
  234. if (isopen) {
  235. [self jumpKuaishouWithStr:self.alertDic[@"kwai_url"]];
  236. }else{
  237. [MBProgressHUD showTip:KWaiTipe];
  238. }
  239. if (status.integerValue == 2) {//第一次提示去填写调用
  240. [self getStatusUrl];
  241. }
  242. }else{
  243. self.hidden=YES;
  244. }
  245. }
  246. -(void) jumpKuaishouWithStr:(NSString *)schemeUrlString{
  247. NSURL *schemeUrl = [NSURL URLWithString:schemeUrlString];
  248. dispatch_async(dispatch_get_main_queue(), ^{
  249. [[UIApplication sharedApplication] openURL:schemeUrl];
  250. });
  251. }
  252. -(void)getStatusUrl
  253. {
  254. if (![AccountTool isLogin]) {
  255. return;
  256. }
  257. [ZBHTTP post:getpidStatisticalUrl params:nil success:^(id _Nonnull json) {
  258. NSLog(@"%@",json);
  259. [UIView animateWithDuration:1 animations:^{
  260. if (self.type.integerValue == 1) {
  261. [self removeFromSuperview];
  262. }else{
  263. self.hidden =YES;
  264. }
  265. }];
  266. } failure:^(NSError * _Nonnull error) {
  267. }];
  268. }
  269. #pragma mark---复制
  270. -(void)cotyCLickBtn
  271. {
  272. UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
  273. if (self.alertDic) {
  274. pastboard.string = self.alertDic[@"pid"];
  275. [MBProgressHUD showMessage:@"复制成功"];
  276. [UIView animateWithDuration:1 animations:^{
  277. if (self.type.integerValue == 1) {
  278. [self removeFromSuperview];
  279. }else{
  280. self.hidden =YES;
  281. }
  282. [self openKwai];
  283. }];
  284. }else {
  285. [MBProgressHUD showMessage:@"复制失败"];
  286. }
  287. }
  288. -(void)openKwai
  289. {
  290. if (![PublicFunction canOpenURL:kwaiUrl]) {
  291. [MBProgressHUD showTip:KWaiTipe];
  292. return;
  293. }
  294. NSString* taobao = [NSString stringWithFormat:kwaiUrl];
  295. UIWebView* webview = [[UIWebView alloc]initWithFrame:CGRectZero];
  296. [[UIApplication sharedApplication].keyWindow addSubview:webview];
  297. NSURL*url = [NSURL URLWithString:taobao];
  298. NSURLRequest *request = [NSURLRequest requestWithURL:url];
  299. [webview loadRequest:request];
  300. }
  301. -(void)clickTipe
  302. {
  303. [self getStatusUrl];//不再提示也需要调用
  304. }
  305. @end