// // TFGiftAlertView.m // TFReader // // Created by 谢腾飞 on 2020/12/17. // Copyright © 2020 xtfei_2011@126.com. All rights reserved. // #import "TFGiftAlertView.h" #import "WXYZ_TickectAlertModel.h" #import "WXYZ_GiftMonthlyPassModel.h" #import "TFReaderBookManager.h" #import "TFRechargeViewController.h" @implementation TFGiftAlertView - (void)createSubviews { [super createSubviews]; self.alertBtnType = TFAlertButtonTypeSingleConfirm; } - (void)setAlertModel:(WXYZ_TickectAlertModel *)alertModel giftModel:(WXYZ_GiftMonthlyPassListModel *)giftModel production_id:(NSInteger)production_id ticketBlock:(void(^)(NSInteger number))ticketBlock { self.alertTitle = alertModel.title ? : @""; NSString *str = [alertModel.desc componentsJoinedByString:@"\n"]; NSRange range = [str rangeOfString:@"###.*###" options:NSRegularExpressionSearch]; if (range.length == 0) range = NSMakeRange(0, 0); NSString *suffix = [[str substringWithRange:range] stringByReplacingOccurrencesOfString:@"#" withString:@""]; NSMutableString *prefix = [NSMutableString stringWithString:[str stringByReplacingCharactersInRange:range withString:@""]]; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; style.lineSpacing = 9.0; [prefix insertString:suffix atIndex:range.location]; NSMutableAttributedString *t_atr = [[NSMutableAttributedString alloc] initWithString:prefix attributes:@{NSFontAttributeName : kFont13, NSForegroundColorAttributeName : kGrayTextColor, NSParagraphStyleAttributeName : style}]; [t_atr addAttributes:@{NSForegroundColorAttributeName : kMainColor} range:NSMakeRange(range.location, suffix.length)]; t_atr.alignment = NSTextAlignmentCenter; self.attributedStr = t_atr; self.confirmTitle = alertModel.items.firstObject.title ?: @""; [self.contentScrollView mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.alertTitleLabel.mas_bottom).offset(0); make.left.equalTo(self.alertBackView).offset(kHalfMargin); make.right.equalTo(self.alertBackView).offset(-kHalfMargin); make.height.mas_equalTo([TFViewHelper getDynamicHeightWithLabelFont:kMainFont labelWidth:SCREEN_WIDTH - 3 * kMargin labelText:self.attributedStr.string] + kLabelHeight); }]; self.contentScrollView.scrollEnabled = NO; [self.alertBackView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.alertBackView.superview).offset(kMargin * 2); make.right.equalTo(self.alertBackView.superview).offset(-kMargin * 2); make.bottom.mas_equalTo(self.confirmButton.mas_bottom).with.offset(0).priorityLow(); make.center.equalTo(self.alertBackView.superview); }]; [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.left.right.bottom.equalTo(self.contentScrollView); }]; [self.confirmButton mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.alertBackView.mas_right).with.offset(0); make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(kHalfMargin); make.height.mas_equalTo(45.0); make.width.equalTo(self.alertBackView); }]; self.confirmButtonClickBlock = ^{ if ([alertModel.items.firstObject.action isEqualToString:@"recharge"]) { [[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@""]; [[TFViewHelper getCurrentNavigationController] pushViewController:[[TFRechargeViewController alloc] init] animated:YES]; } else { NSDictionary *params = @{ @"book_id" : @(production_id), @"chapter_id" : @([TFReaderBookManager sharedManager].chapter_id), @"num" : @(giftModel.num), @"use_gold" : @"1" }; [TFNetworkTools POST:Book_Reward_Ticket_Vote parameters:params model:nil success:^(BOOL isSuccess, NSDictionary * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) { if (isSuccess) { NSString *text = [NSString stringWithFormat:@"%@", t_model[@"data"][@"ticket_num"]]; [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTicket" object:text]; [TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"投票成功")]; [TFReaderBookManager sharedManager].ticket_num = text ?: @""; !ticketBlock ?: ticketBlock([text integerValue]); } else { [TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg]; } } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { [TFPromptManager showPromptWithError:error defaultText:nil]; }]; } }; } @end