You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

282 lines
9.1 KiB

//
// PayPopView.m
// tongxin
//
// Created by ecell on 2023/3/27.
// Copyright © 2023 xTT. All rights reserved.
//
#import "PayPopView.h"
#import "PayTableViewCell.h"
#import "User.h"
#import "Device.h"
@interface PayPopView ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
@property (nonatomic ,weak) UIView *bgView;
@property (nonatomic ,weak) UILabel *titleLabel;
@property (nonatomic ,weak) UILabel *moneyLabel;
@property (nonatomic ,weak) UIButton *payBtn;
@property (nonatomic ,strong) UITableView *payTable;
@property (nonatomic ,strong) DialMsgModel *dialModel;
@property (nonatomic ,strong) NSString *payMethodStr;
@end
@implementation PayPopView
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.frame = [UIScreen mainScreen].bounds;
self.backgroundColor = RGBA(0, 0, 0, 0.5);
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGuesture:)];
tapGesture.delegate = self;
[self addGestureRecognizer:tapGesture];
self.payMethodStr = @"";
}
return self;
}
- (void)setPayArr:(NSArray *)payArr
{
_payArr = payArr;
}
- (void)subPopView:(DialMsgModel *)model
{
self.dialModel = model;
UIView *bgView = [[UIView alloc] init];
bgView.frame = CGRectMake(0, ScreenHeight, ScreenWidth, 300);
bgView.backgroundColor = UIColor.whiteColor;
self.bgView = bgView;
[self addSubview:bgView];
UILabel *titleLabel = [UILabel new];
titleLabel.textColor = UIColor.blackColor;
titleLabel.text = model.dialName;
self.titleLabel = titleLabel;
titleLabel.font = Font_(16);
[bgView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(bgView);
make.top.equalTo(bgView.mas_top).offset(15);
}];
UILabel *moneyLabel = [UILabel new];
moneyLabel.textColor = mainColor;
moneyLabel.userInteractionEnabled = YES;
moneyLabel.text = [NSString stringWithFormat:@"¥ %@",model.price];
moneyLabel.font = Font_(15);
self.moneyLabel = moneyLabel;
[bgView addSubview:moneyLabel];
[moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(bgView);
make.top.equalTo(titleLabel.mas_bottom).offset(15);
}];
CGFloat b = iPhoneX_TabbarSafeBottomMargin > 0 ? iPhoneX_TabbarSafeBottomMargin : 20;
UIButton *payBtn = [[UIButton alloc] init];
[payBtn setTitle:[NSString stringWithFormat:@"确认支付 ¥%@",model.price] forState:0];
[payBtn setTitleColor:UIColor.whiteColor forState:0];
payBtn.titleLabel.font = Font_(15);
payBtn.backgroundColor = mainColor;
payBtn.layer.cornerRadius = 25;
self.layer.masksToBounds = YES;
[payBtn addTarget:self action:@selector(DialPay) forControlEvents:UIControlEventTouchUpInside];
self.payBtn = payBtn;
[bgView addSubview:payBtn];
[payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(bgView).inset(15);
make.bottom.equalTo(bgView.mas_bottom).inset(b);
make.height.mas_equalTo(50);
}];
[bgView addSubview:self.payTable];
[self.payTable mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(bgView).inset(10);
make.top.equalTo(moneyLabel.mas_bottom).offset(15);
make.bottom.equalTo(payBtn.mas_top).inset(15);
}];
[self showView];
}
- (UITableView *)payTable
{
if (!_payTable)
{
_payTable = [[UITableView alloc] init];
_payTable.backgroundColor = UIColor.whiteColor;
// _payTable.layer.cornerRadius = 5;
// _payTable.layer.shadowOffset = CGSizeMake(1, 5);
// _payTable.layer.shadowOpacity = 0.8;
// _payTable.layer.shadowColor = [UIColor lightGrayColor].CGColor;
_payTable.dataSource = self;
_payTable.delegate = self;
_payTable.rowHeight = Adapted(50);
_payTable.scrollEnabled = NO;
[_payTable registerClass:PayTableViewCell.class forCellReuseIdentifier:NSStringFromClass(PayTableViewCell.class)];
}
return _payTable;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
PayModel *model = self.payArr[indexPath.row];
self.payMethodStr = model.payNum;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.payArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PayTableViewCell *cell = [PayTableViewCell cellWithTableView:tableView indexPath:indexPath];
cell.paymodel = self.payArr[indexPath.row];
return cell;
}
#pragma mark 购买表盘
/// 购买表盘
- (void)DialPay
{
if (self.payMethodStr.length <= 0)
{
[UICommon MessageErrorText:@"请选择支付方式"];
return;
}
[UICommon MessageUpload:@"正在加载"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setObject:cUser.cDevice.imei forKey:@"imei"];
[parameters setObject:self.payMethodStr forKey:@"payType"];
[parameters setObject:@(2) forKey:@"systemType"];
[parameters setObject:self.dialModel.dialId forKey:@"producedId"];
[parameters setObject:cUser.openid forKey:@"appUserId"];
[parameters setObject:cUser.name forKey:@"appUsername"];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:HTTP_POST_PAYORDERAPP parameters:parameters error:nil];
request.timeoutInterval = 10.f;
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
//[request setValue:cUser.openid forHTTPHeaderField:@"userId"];
NSURLSessionDataTask*task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
NSDictionary *dic = responseObject;
if (dic && [dic[@"code"] integerValue] == 200)
{
[UICommon HidenLoading];
[self dismiss];
[[APHandleManager sharedManager] wxPay:dic[@"data"] success:^(HandleStatus code) {
if (code == HandleStatus_Success)
{
[UICommon MessageSuccessText:@"支付成功" isImg:YES];
}else if (code == HandleStatus_Cancel)
{
[UICommon MessageErrorText:@"支付取消"];
}else if (code == HandleStatus_Error)
{
[UICommon MessageErrorText:@"支付失败"];
}
} failure:^(HandleStatus code) {
[UICommon HidenLoading];
if (code == HandleStatus_Cancel)
{
[UICommon MessageErrorText:@"支付取消"];
}else if (code == HandleStatus_Error) {
[UICommon MessageErrorText:@"支付失败"];
}
}];
}
else
{
[UICommon HidenLoading];
NSLog(@"请求失败error=%@", error);
}
}];
[task resume];
}
- (void)showView
{
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
[window addSubview:self];
[UIView animateWithDuration:0.25f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGRect frame = self.bgView.frame;
frame.origin.y = frame.origin.y - frame.size.height;
self.bgView.frame = frame;
}
completion:^(BOOL finished) {
}];
}
- (void)dismiss
{
[UIView animateWithDuration:0.25f
delay:0.0f
options:UIViewAnimationOptionCurveEaseIn
animations:^{
CGRect frame = self.bgView.frame;
frame.origin.y = frame.origin.y + frame.size.height;
self.bgView.frame = frame;
}
completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
- (void)handleGuesture:(UITapGestureRecognizer *)sender
{
CGPoint point = [sender locationInView:self.bgView];
if(![self.bgView.layer containsPoint:point])
{
[self dismiss];
return;
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch
{
if([NSStringFromClass([touch.view class])isEqual:@"UITableViewCellContentView"])
{
return NO;
}
return YES;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end