123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- //
- // KDPIDTipView.m
- // KuDianProject
- //
- // Created by 学丽 on 2019/7/9.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPIDTipView.h"
- @implementation KDPIDTipView
- -(instancetype)initWithFrame:(CGRect)frame
- {
- self=[super initWithFrame:frame];
- if (self) {
- self.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.4];
- UIView *backV=[[UIView alloc]init];
- backV.backgroundColor=[UIColor whiteColor];
- backV.layer.cornerRadius=9;
- self.backV=backV;
- backV.layer.masksToBounds=YES;
- [self addSubview:backV];
-
- [backV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(281);
- make.height.mas_equalTo(345);
- make.centerY.mas_equalTo(self.mas_centerY);
- make.centerX.mas_equalTo(self.mas_centerX);
- }];
-
- self.pidtitleL=[[UILabel alloc]init];
- self.pidtitleL.font=[UIFont boldSystemFontOfSize:20];
- self.pidtitleL.textColor=[UIColor colorWithHexString:ThemeColor];
- self.pidtitleL.text=@"推广商品前需绑定PID"; self.pidtitleL.textAlignment=NSTextAlignmentCenter;
- [backV addSubview:self.pidtitleL];
- [self.pidtitleL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(28);
- make.top.mas_equalTo(31);
- }];
-
- self.pidContentL =[[UILabel alloc]init];
- self.pidContentL.textColor=[UIColor colorWithHexString:@"#333333"];
- self.pidContentL.font=[UIFont systemFontOfSize:15];
-
- self.pidContentL.attributedText=[KDPublicMethod sethanggaoWithStr:@"PID是您的专属推广位,用于同步订单 获得收益,推广商品前请确保您已在 快手小店上绑定了该PID。" linSpacing:4];
- [backV addSubview:self.pidContentL];
- self.pidContentL.numberOfLines=0;
- [self.pidContentL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.pidtitleL.mas_bottom).offset(10);
- make.left.mas_equalTo(10);
- make.right.mas_equalTo(-10);
- make.height.mas_equalTo(98);
- }];
-
-
-
- //
- self.pidLabel=[[UILabel alloc]init];
- self.pidLabel.text=@"您的PID已生成,记得去绑定";
- self.pidLabel.font=[UIFont systemFontOfSize:11];
- self.pidLabel.textAlignment=NSTextAlignmentCenter;
- self.pidLabel.textColor=[UIColor colorWithHexString:@"#9B9B9B"];
- [backV addSubview:self.pidLabel];
-
-
- self.bindBtn =[[UIButton alloc]init];
- [self.bindBtn setTitle:@"去绑定" forState:UIControlStateNormal];
- self.bindBtn.titleLabel.font=[UIFont systemFontOfSize:14];
- [self.bindBtn addTarget:self action:@selector(bingdclickButton) forControlEvents:UIControlEventTouchUpInside];
- self.bindBtn.layer.cornerRadius=21.5;
- self.bindBtn.layer.masksToBounds=YES;
- self.bindBtn.backgroundColor=[UIColor gradientOneColor:[UIColor colorWithHexString:@"#FF235F"] toColor:[UIColor colorWithHexString:@"#FF7676"] Width:230];
- [backV addSubview:self.bindBtn];
-
- [self.bindBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(26);
- make.top.mas_equalTo(self.pidContentL.mas_bottom).offset(16);
- make.height.mas_equalTo(43);
- make.right.mas_equalTo(-25);
- }];
-
- [self.pidLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(16);
- make.top.mas_equalTo(self.bindBtn.mas_bottom).offset(31);
- }];
-
- self.CancelBtn=[[UIButton alloc]init];
- [self.CancelBtn setTitle:@"已绑定,不再提示" forState:UIControlStateNormal];
- [self.CancelBtn setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
- self.CancelBtn.titleLabel.font=[UIFont systemFontOfSize:12];
- [self.CancelBtn addTarget:self action:@selector(copyPidClickBtn) forControlEvents:UIControlEventTouchUpInside];
- [backV addSubview:self.CancelBtn];
- [self.CancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(20);
- make.top.mas_equalTo(self.pidLabel.mas_bottom).offset(12);
- make.left.mas_equalTo(26);
- make.right.mas_equalTo(-26);
- }];
-
-
- }
- return self;
- }
- -(void)setResultDic:(NSDictionary *)resultDic
- {
- _resultDic = resultDic;
-
- NSString *str=[NSString stringWithFormat:@"%@",resultDic[@"message"]];
- NSMutableAttributedString * attstr = [[NSMutableAttributedString alloc] initWithString:str];
- NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle1 setLineSpacing:8];
- [attstr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [str length])];
- [self.pidContentL setAttributedText:attstr];
-
-
- self.pidtitleL.text=resultDic[@"title"];
- /**
- 弹框状态 1:用户没有快手Pid
- 2:用户有Pid,首次提示
- 3:用户有Pid,二次提示
- */
- self.CancelBtn.hidden=YES;
- self.pidLabel.hidden=YES;
- self.pidLabel.text=resultDic[@"pid"];
-
- NSString *status=resultDic[@"status"];
- if (status.integerValue == 1) {
- [self.bindBtn setTitle:@"好的" forState:UIControlStateNormal];
- [self.backV mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(263);
- }];
- }else if (status.integerValue == 2)
- {
- self.CancelBtn.hidden=NO;
- self.pidLabel.hidden=NO;
- [self.bindBtn setTitle:@"去填写" forState:UIControlStateNormal];
- [self.backV mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(317);
- }];
- [self.CancelBtn setTitle:@"复制Pid" forState:UIControlStateNormal];
- [self.CancelBtn setTitleColor:[UIColor colorWithHexString:ThemeColor] forState:UIControlStateNormal];
-
- [self.CancelBtn mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.pidLabel.mas_bottom).offset(12);
- }];
- }else if (status.integerValue == 3)
- {
- self.CancelBtn.hidden=NO;
-
- [self.backV mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(284);
- }];
- [self.CancelBtn setTitle:@"已填好,不在提示" forState:UIControlStateNormal];
- [self.CancelBtn setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
- [self.bindBtn setTitle:@"没有填好,去填写" forState:UIControlStateNormal];
-
- [self.CancelBtn mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.bindBtn.mas_bottom).offset(19);
- }];
- }
-
- }
- #pragma mark---pid跳转操作
- -(void)bingdclickButton
- {
- NSString *status=self.resultDic[@"status"];
- if (status.integerValue ==1) {//创建中
- self.hidden= YES;
- }else if(status.integerValue == 2 || status.integerValue == 3){
- //为2的时候需要统计
- if (status.integerValue == 2) {
- [self pidNumAdd];
- }
- BOOL isapp =[KDPublicMethod JumpOpenURL:self.resultDic[@"kwai_url"]];
- if (isapp) {
- [self jumpKwaiURL:self.resultDic[@"kwai_url"]];
- }else{
- [MBProgressHUD showMessage:KWaiMessage];
- }
- }
- self.hidden=YES;
- }
- #pragma mark---pid计数y统计
- -(void)pidNumAdd
- {
- [KDPNetworkRequestHTTP postURL:pidNumTotalURL params:nil success:^(id _Nonnull json) {
- [UIView animateWithDuration:1 animations:^{
- self.hidden =YES;
- }];
- } failure:^(NSError * _Nonnull error) {
-
- }];
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- self.hidden =YES;
- }
- -(void) jumpKwaiURL:(NSString *)schemeUrl{
-
-
- NSURL *URL = [NSURL URLWithString:schemeUrl];
- dispatch_async(dispatch_get_main_queue(), ^{
- [[UIApplication sharedApplication] openURL:URL];
- });
-
-
- }
- -(void)tbOpenAndKwai
- {
- if (![KDPublicMethod JumpOpenURL:KWai]) {
- [MBProgressHUD showMessage:KWaiMessage];
- return;
- }
- NSString* requesturl= [NSString stringWithFormat:KWai];
- UIWebView* webview = [[UIWebView alloc]initWithFrame:CGRectZero];
- [[UIApplication sharedApplication].keyWindow addSubview:webview];
- NSURL*url = [NSURL URLWithString:requesturl];
- NSURLRequest *request = [NSURLRequest requestWithURL:url];
- [webview loadRequest:request];
- }
- #pragma mark---复制pid
- -(void)copyPidClickBtn
- {
- NSString *status=self.resultDic[@"status"];
- if (status.integerValue == 3) {
- [self pidNumAdd];
- return;
- }
- UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
- if (self.resultDic) {
- pastboard.string = self.resultDic[@"pid"];
- [MBProgressHUD showMessage:@"复制成功"];
- [UIView animateWithDuration:1 animations:^{
- self.hidden=YES;
- [self tbOpenAndKwai];
-
- }];
- }else {
- [MBProgressHUD showMessage:@"复制失败"];
- }
- }
- @end
|