123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- //
- // ZBPidView.m
- // ZBProject
- //
- // Created by 学丽 on 2019/4/2.
- // Copyright © 2019 ZB. All rights reserved.
- //
- #import "ZBPidView.h"
- @implementation ZBPidView
- -(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.5];
-
-
- [self addSubview:self.backV];
- [self.backV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(281);
- make.height.mas_equalTo(345);
- make.centerX.mas_equalTo(self.centerX);
- make.centerY.mas_equalTo(self.centerY);
- }];
-
- [self.backV addSubview:self.titleLabel];
- [self.backV addSubview:self.contentLabel];
- [self.backV addSubview:self.okBtn];
- [self.backV addSubview:self.tipeBtn];
- [self.backV addSubview:self.copyBtn];
- [self.backV addSubview:self.pidLabael];
- [self.backV addSubview:self.segMentLabel];
- [self.backV addSubview:self.tipeLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(35);
- make.height.mas_equalTo(28);
- make.left.mas_equalTo(10);
- make.right.mas_equalTo(-10);
-
- }];
-
- [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(20);
-
- make.left.mas_equalTo(16);
- make.right.mas_equalTo(-16);
- }];
- [self.segMentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.right.mas_equalTo(-10);
- make.height.mas_equalTo(2);
- make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(26);
- }];
-
- [self.tipeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.right.mas_equalTo(-10);
- make.height.mas_equalTo(25);
- make.top.mas_equalTo(self.segMentLabel.mas_bottom).offset(23);
- }];
-
- [self.okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(26);
- make.height.mas_equalTo(43);
- make.top.mas_equalTo(self.tipeLabel.mas_bottom).offset(36);
- make.right.mas_equalTo(-25);
- }];
-
- [self.tipeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(26);
- make.height.mas_equalTo(43);
- make.top.mas_equalTo(self.okBtn.mas_bottom).offset(5);
- make.right.mas_equalTo(-25);
- }];
- [self.pidLabael mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.okBtn.mas_bottom).offset(31);
- make.height.mas_equalTo(16);
- make.left.mas_equalTo(10);
- make.right.mas_equalTo(-10);
-
- }];
-
-
- [self.copyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.pidLabael.mas_bottom).offset(12);
- make.left.mas_equalTo(10);
- make.height.mas_equalTo(16);
- make.right.mas_equalTo(-10);
- }];
- }
-
- return self;
- }
- -(void)setAlertDic:(NSDictionary *)alertDic
- {
- _alertDic = alertDic;
- self.titleLabel.text=alertDic[@"title"];
-
- NSString *str=[NSString stringWithFormat:@"%@",alertDic[@"message"]];
- NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:str];
- NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle1 setLineSpacing:8];
- [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [str length])];
- [self.contentLabel setAttributedText:attributedString1];
- [self.contentLabel sizeToFit];
-
- self.pidLabael.text=alertDic[@"pid"];
- //status
- NSString *status=alertDic[@"status"];
- self.tipeBtn.hidden=YES;
- self.copyBtn.hidden=YES;
- self.pidLabael.hidden=YES;
-
- if (status.integerValue == 1) {
- [self.okBtn setTitle:@"好的" forState:UIControlStateNormal];
- }else if (status.integerValue == 2)
- {
- self.pidLabael.hidden=YES;
- self.copyBtn.hidden=YES;
- [self.okBtn setTitle:@"去绑定" forState:UIControlStateNormal];
- [self.backV mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(345);
- }];
- self.tipeBtn.hidden=NO;
- }else if (status.integerValue == 3)
- {
- [self.backV mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(284);
- }];
- [self.okBtn setTitle:@"没填好去填写" forState:UIControlStateNormal];
- self.tipeBtn.hidden=NO;
- }
-
- self.tipeLabel.text=alertDic[@"red_message"];
-
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- [UIView animateWithDuration:1 animations:^{
- if (self.type.integerValue == 1) {
- [self removeFromSuperview];
- }else{
- self.hidden =YES;
- }
-
- }];
- }
- -(UILabel *)titleLabel
- {
- if (!_titleLabel ) {
- _titleLabel=[[UILabel alloc]init];
- _titleLabel.textColor=[UIColor fontColor];
- _titleLabel.font=[UIFont boldSystemFontOfSize:20];
- _titleLabel.text=@"推广商品前需绑定PID"; _titleLabel.textAlignment=NSTextAlignmentCenter;
-
- }
- return _titleLabel;
- }
- -(UILabel *)contentLabel
- {
- if (!_contentLabel) {
- _contentLabel=[[UILabel alloc]init];
- _contentLabel.textColor=[UIColor fontColor];
- _contentLabel.font=[UIFont systemFontOfSize:15];
- _contentLabel.numberOfLines=0;
- _contentLabel.text=@"PID是您的专属推广位,用于同步订单 获得收益,推广商品前请确保您已在 快手小店上绑定了该PID。"; _contentLabel.textAlignment=NSTextAlignmentCenter;
- }
- return _contentLabel;
- }
- -(UIButton *)okBtn
- {
- if (!_okBtn) {
- _okBtn =[[UIButton alloc]init];
- _okBtn.backgroundColor=[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xFF8300] toColor:[UIColor YHColorWithHex:0xFF5200] withWidth:230];
- [_okBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- _okBtn.titleLabel.font=[UIFont systemFontOfSize:15];
- _okBtn.layer.cornerRadius=21.5;
- _okBtn.layer.masksToBounds=YES;
- [_okBtn addTarget:self action:@selector(clickOpenKwai) forControlEvents:UIControlEventTouchUpInside];
- }
- return _okBtn;
- }
- -(UIButton *)tipeBtn
- {
- if (!_tipeBtn) {
- _tipeBtn =[[UIButton alloc]init];
- _tipeBtn.backgroundColor=[UIColor clearColor];
- [_tipeBtn setTitleColor:[UIColor YHColorWithHex:0x9B9B9B] forState:UIControlStateNormal];
- _tipeBtn.titleLabel.font=[UIFont systemFontOfSize:14];
- [_tipeBtn setTitle:@"已绑定,不再提示" forState:UIControlStateNormal];
- _tipeBtn.layer.cornerRadius=21.5;
- _tipeBtn.layer.masksToBounds=YES;
- _tipeBtn.hidden=YES;
- [_tipeBtn addTarget:self action:@selector(clickTipe) forControlEvents:UIControlEventTouchUpInside];
-
- }
- return _tipeBtn;
- }
- -(UILabel *)segMentLabel
- {
- if (!_segMentLabel) {
- _segMentLabel=[[UILabel alloc]init];
- _segMentLabel.textColor=[UIColor baseColor];
- _segMentLabel.text=@"----------------------------------";
-
- }
- return _segMentLabel;
- }
- -(UILabel *)tipeLabel
- {
- if (!_tipeLabel ) {
- _tipeLabel=[[UILabel alloc]init];
- _tipeLabel.textColor=[UIColor YHColorWithHex:0xFF5703];
- _tipeLabel.font=[UIFont boldSystemFontOfSize:16];
- _tipeLabel.text=@"您的PID正在生成,请耐心等待~";
- _tipeLabel.textAlignment=NSTextAlignmentCenter;
-
- }
- return _tipeLabel;
- }
- -(UILabel *)pidLabael
- {
- if (!_pidLabael) {
- _pidLabael =[[UILabel alloc]init];
- _pidLabael.textColor=[UIColor YHColorWithHex:0x9B9B9B];
- _pidLabael.font=[UIFont systemFontOfSize:11];
- _pidLabael.textAlignment=NSTextAlignmentCenter;
-
- }
- return _pidLabael;
- }
- -(UIButton *)copyBtn
- {
- if (!_copyBtn) {
- _copyBtn =[[UIButton alloc]init];
- [_copyBtn setTitle:@"复制Pid" forState:UIControlStateNormal];
- [_copyBtn setTitleColor:[UIColor YHColorWithHex:0xFF7700] forState:UIControlStateNormal];
- _copyBtn.titleLabel.font=[UIFont systemFontOfSize:14];
- [_copyBtn addTarget:self action:@selector(cotyCLickBtn) forControlEvents:UIControlEventTouchUpInside];
- }
- return _copyBtn;
- }
- -(UIView *)backV
- {
- if (!_backV) {
- _backV =[[UIView alloc]init];
- _backV.backgroundColor=[UIColor whiteColor];
- _backV.layer.cornerRadius=9;
- _backV.layer.masksToBounds=YES;
- }
- return _backV;
- }
- -(void)clickOpenKwai
- {
- //status
- NSString *status=self.alertDic[@"status"];
-
- if (status.integerValue == 2 || status.integerValue == 3) {
-
- BOOL isopen =[PublicFunction canOpenURL:self.alertDic[@"kwai_url"]];
- if (isopen) {
- [self jumpKuaishouWithStr:self.alertDic[@"kwai_url"]];
- }else{
- [MBProgressHUD showTip:KWaiTipe];
- }
-
- if (status.integerValue == 2) {//第一次提示去填写调用
- [self getStatusUrl];
- }
- }else{
- self.hidden=YES;
- }
-
- }
- -(void) jumpKuaishouWithStr:(NSString *)schemeUrlString{
-
-
-
- NSURL *schemeUrl = [NSURL URLWithString:schemeUrlString];
- dispatch_async(dispatch_get_main_queue(), ^{
- [[UIApplication sharedApplication] openURL:schemeUrl];
- });
-
-
- }
- -(void)getStatusUrl
- {
- if (![AccountTool isLogin]) {
- return;
- }
- [ZBHTTP post:getpidStatisticalUrl params:nil success:^(id _Nonnull json) {
- NSLog(@"%@",json);
- [UIView animateWithDuration:1 animations:^{
- if (self.type.integerValue == 1) {
- [self removeFromSuperview];
- }else{
- self.hidden =YES;
- }
-
- }];
- } failure:^(NSError * _Nonnull error) {
-
- }];
- }
- #pragma mark---复制
- -(void)cotyCLickBtn
- {
- UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
- if (self.alertDic) {
- pastboard.string = self.alertDic[@"pid"];
- [MBProgressHUD showMessage:@"复制成功"];
- [UIView animateWithDuration:1 animations:^{
- if (self.type.integerValue == 1) {
- [self removeFromSuperview];
- }else{
- self.hidden =YES;
- }
- [self openKwai];
-
- }];
- }else {
- [MBProgressHUD showMessage:@"复制失败"];
- }
- }
- -(void)openKwai
- {
- if (![PublicFunction canOpenURL:kwaiUrl]) {
- [MBProgressHUD showTip:KWaiTipe];
- return;
- }
- NSString* taobao = [NSString stringWithFormat:kwaiUrl];
- UIWebView* webview = [[UIWebView alloc]initWithFrame:CGRectZero];
- [[UIApplication sharedApplication].keyWindow addSubview:webview];
- NSURL*url = [NSURL URLWithString:taobao];
- NSURLRequest *request = [NSURLRequest requestWithURL:url];
- [webview loadRequest:request];
-
- }
- -(void)clickTipe
- {
- [self getStatusUrl];//不再提示也需要调用
- }
- @end
|