330 lines
14 KiB
Objective-C
330 lines
14 KiB
Objective-C
//
|
|
// QXDressShopBuyView.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2026/1/3.
|
|
//
|
|
|
|
#import "QXDressShopBuyView.h"
|
|
#import "QXSettingCell.h"
|
|
#import "QXMineNetwork.h"
|
|
#import "QXSelectAuctionInfoView.h"
|
|
#import "QXGiftPlayerManager.h"
|
|
|
|
@interface QXDressShopBuyView()<UIGestureRecognizerDelegate,UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,QXSettingCellDelegate>
|
|
@property (nonatomic,strong)UIView *bgView;
|
|
@property (nonatomic,strong)UITableView *tableView;
|
|
@property (nonatomic,strong)QXSeatHeaderView *headerView;
|
|
@property (nonatomic,strong)UIImageView *dressImageView;
|
|
@property (nonatomic,strong)NSArray *titleArray;
|
|
@property (nonatomic,strong)NSDictionary *cellValueDict;
|
|
@property (nonatomic,strong)NSDictionary *cellTypeDict;
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
|
|
|
@property (nonatomic,strong)QXShopDressDetailModel *infoModel;
|
|
@property (nonatomic,strong)QXShopDressPriceModel* selectedPriceModel;
|
|
|
|
@property (nonatomic,strong)QXEffectContentView *fullEffectView;
|
|
|
|
|
|
@property (nonatomic,strong)UIButton* coinBtn;
|
|
@property (nonatomic,strong)UIButton* rechargeBtn;
|
|
@property (nonatomic,strong)UIButton* payBtn;
|
|
|
|
@property (nonatomic,strong)NSString* num;
|
|
@end
|
|
|
|
@implementation QXDressShopBuyView
|
|
|
|
- (instancetype)init
|
|
{
|
|
self = [super init];
|
|
if (self) {
|
|
self.frame = [UIScreen mainScreen].bounds;
|
|
[self initSubviews];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
-(void)initSubviews{
|
|
self.num = @"1";
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
|
|
tap.delegate = self;
|
|
[self addGestureRecognizer:tap];
|
|
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
|
|
|
|
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, ScaleWidth(144), SCREEN_WIDTH, kSafeAreaBottom+ScaleWidth(429))];
|
|
self.bgView.backgroundColor = UIColor.whiteColor;
|
|
[self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
|
|
[self addSubview:self.bgView];
|
|
|
|
self.headerView = [[QXSeatHeaderView alloc] initWithFrame:CGRectMake((self.width-80)/2, 10, 80, 80)];
|
|
self.headerView.hidden = YES;
|
|
[self.bgView addSubview:self.headerView];
|
|
|
|
self.dressImageView = [[UIImageView alloc] initWithFrame:CGRectMake((self.width-80)/2, 10, 80, 80)];
|
|
self.dressImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
self.dressImageView.hidden = YES;
|
|
[self.bgView addSubview:self.dressImageView];
|
|
|
|
|
|
self.cellValueDict = [NSMutableDictionary dictionaryWithDictionary:@{
|
|
@"商品名称":@"",
|
|
@"商品价格":@"",
|
|
@"有效期至":@"",
|
|
@"购买时长":@"",
|
|
@"购买次数":self.num,
|
|
@"商品总价":@"",
|
|
@"商品单价":@""
|
|
}];
|
|
|
|
self.cellTypeDict = [NSMutableDictionary dictionaryWithDictionary:@{
|
|
@"商品名称":[NSNumber numberWithInteger:QXSettingCellTypeOnlyDetail],
|
|
@"商品价格":[NSNumber numberWithInteger:QXSettingCellTypeNormal],
|
|
@"有效期至":[NSNumber numberWithInteger:QXSettingCellTypeOnlyDetail],
|
|
@"购买时长":[NSNumber numberWithInteger:QXSettingCellTypeOnlyDetail],
|
|
@"购买次数":[NSNumber numberWithInteger:QXSettingCellTypeBuyCount],
|
|
@"商品总价":[NSNumber numberWithInteger:QXSettingCellTypeNormal],
|
|
@"商品单价":[NSNumber numberWithInteger:QXSettingCellTypeNormal],
|
|
}];
|
|
[self.bgView addSubview:self.tableView];
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.minimumLineSpacing = 12;
|
|
layout.minimumInteritemSpacing = 12;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
|
|
NSInteger itemWidth = (SCREEN_WIDTH-15*2-12*3)/4;
|
|
layout.itemSize = CGSizeMake(itemWidth, 44);
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.tableView.bottom+5, self.bgView.width, 60) collectionViewLayout:layout];
|
|
[self.collectionView registerClass:[QXSelectAuctionInfoCell class] forCellWithReuseIdentifier:@"QXSelectAuctionInfoCell"];
|
|
self.collectionView.delegate = self;
|
|
self.collectionView.dataSource = self;
|
|
self.collectionView.showsHorizontalScrollIndicator = NO;
|
|
self.collectionView.showsVerticalScrollIndicator = NO;
|
|
self.collectionView.bounces = NO;
|
|
self.collectionView.backgroundColor = [UIColor clearColor];
|
|
[self.bgView addSubview:self.collectionView];
|
|
|
|
self.coinBtn = [[UIButton alloc] initWithFrame:CGRectMake(16, self.collectionView.bottom+15, (self.width-32)/2-6, 25)];
|
|
self.coinBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
|
|
[self.coinBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateNormal)];
|
|
self.coinBtn.titleLabel.font = [UIFont systemFontOfSize:13];
|
|
[self.coinBtn setImage:[UIImage imageNamed:@"mine_recharge_corn"] forState:(UIControlStateNormal)];
|
|
[self.bgView addSubview:self.coinBtn];
|
|
|
|
self.rechargeBtn = [[UIButton alloc] initWithFrame:CGRectMake((self.width)/2+3, self.collectionView.bottom+15, (self.width-32)/2-6, 25)];
|
|
self.rechargeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
|
[self.rechargeBtn setTitleColor:QXConfig.themeColor forState:(UIControlStateNormal)];
|
|
self.rechargeBtn.titleLabel.font = [UIFont systemFontOfSize:13];
|
|
[self.rechargeBtn addTarget:self action:@selector(rechargeAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self.rechargeBtn setTitle:@"去充值" forState:(UIControlStateNormal)];
|
|
[self.bgView addSubview:self.rechargeBtn];
|
|
|
|
self.payBtn = [[UIButton alloc] initWithFrame:CGRectMake((self.width-280)/2, self.coinBtn.bottom+10, 280, 40)];
|
|
self.payBtn.backgroundColor = QXConfig.themeColor;
|
|
[self.payBtn addRoundedCornersWithRadius:20];
|
|
[self.payBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
|
|
self.payBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
[self.payBtn addTarget:self action:@selector(payAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self.payBtn setTitle:@"确认支付" forState:(UIControlStateNormal)];
|
|
[self.bgView addSubview:self.payBtn];
|
|
|
|
[self addSubview:self.fullEffectView];
|
|
}
|
|
-(void)rechargeAction{
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickRecharge)]) {
|
|
[self.delegate didClickRecharge];
|
|
}
|
|
[self hide];
|
|
}
|
|
|
|
-(void)payAction{
|
|
MJWeakSelf
|
|
[QXMineNetwork shopDressBuyWithDid:self.model.did day:self.selectedPriceModel.day num:self.num successBlock:^(NSDictionary * _Nonnull dict) {
|
|
showToast(@"购买成功");
|
|
[weakSelf hide];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
showToast(msg);
|
|
}];
|
|
}
|
|
|
|
-(void)setModel:(QXShopDressModel *)model{
|
|
_model = model;
|
|
[self.cellValueDict setValue:model.title forKey:@"商品名称"];
|
|
if ([self.typeId isEqualToString:@"2"]) {
|
|
/// 预览座驾
|
|
self.fullEffectView.hidden = NO;
|
|
[self.fullEffectView previewEffectWith:self.model.play_image];
|
|
}
|
|
if ([self.typeId isEqualToString:@"12"]) {
|
|
self.titleArray = @[@"商品名称",@"商品单价",@"购买次数",@"商品总价"];
|
|
}else{
|
|
self.titleArray = @[@"商品名称",@"商品价格",@"有效期至",@"购买时长"];
|
|
}
|
|
[self getDressInfo];
|
|
}
|
|
-(void)setTypeId:(NSString *)typeId{
|
|
_typeId = typeId;
|
|
|
|
}
|
|
-(void)getDressInfo{
|
|
MJWeakSelf
|
|
[QXMineNetwork shopDressDetailWithDid:self.model.did successBlock:^(QXShopDressDetailModel * _Nonnull model) {
|
|
weakSelf.infoModel = model;
|
|
if ([weakSelf.typeId isEqualToString:@"1"]) {
|
|
weakSelf.headerView.hidden = NO;
|
|
[weakSelf.headerView setHeadIcon:QXGlobal.shareGlobal.loginModel.avatar dress:weakSelf.model.play_image];
|
|
}else{
|
|
weakSelf.dressImageView.hidden = NO;
|
|
[weakSelf.dressImageView sd_setImageWithURL:[NSURL URLWithString:weakSelf.model.base_image]];
|
|
}
|
|
QXShopDressPriceModel *price = model.decorate.price_list.firstObject;
|
|
if (price) {
|
|
weakSelf.selectedPriceModel = price;
|
|
weakSelf.selectedPriceModel.isSelected = YES;
|
|
[weakSelf.cellValueDict setValue:price.price forKey:@"商品价格"];
|
|
[weakSelf.cellValueDict setValue:price.end_time forKey:@"有效期至"];
|
|
}else{
|
|
[weakSelf.cellValueDict setValue:model.decorate.price forKey:@"商品单价"];
|
|
[weakSelf.cellValueDict setValue:model.decorate.price forKey:@"商品总价"];
|
|
}
|
|
[weakSelf.coinBtn setTitle:model.user_info.user_coin forState:(UIControlStateNormal)];
|
|
[weakSelf.tableView reloadData];
|
|
[weakSelf.collectionView reloadData];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
showToast(msg);
|
|
}];
|
|
}
|
|
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
|
|
return touch.view == self;
|
|
}
|
|
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
return self.titleArray.count;
|
|
}
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXSettingCell *cell = [QXSettingCell cellWithTableView:tableView];
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
cell.needLine = NO;
|
|
cell.delegate = self;
|
|
NSString *title = self.titleArray[indexPath.row];
|
|
cell.titleLabel.text = title;
|
|
NSNumber *type = self.cellTypeDict[title];;
|
|
cell.cellType = type.integerValue;
|
|
NSString *value = self.cellValueDict[title];;
|
|
if (type.integerValue == QXSettingCellTypeBuyCount) {
|
|
cell.textField.text = value;
|
|
}else{
|
|
cell.detailLabel.text = value;
|
|
}
|
|
if ([title isEqualToString:@"商品价格"] || [title isEqualToString:@"商品单价"] || [title isEqualToString:@"商品总价"]) {
|
|
cell.rightArrow.image = [UIImage imageNamed:@"mine_recharge_corn"];
|
|
}else{
|
|
cell.rightArrow.image = [UIImage imageNamed:@"arrowRight"];
|
|
}
|
|
return cell;
|
|
}
|
|
//-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
// QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init];
|
|
// QXUserHomeModel *model = self.dataArray[indexPath.row];
|
|
// vc.user_id = model.user_id;
|
|
// [self.navigationController pushViewController:vc animated:YES];
|
|
//}
|
|
|
|
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
return self.infoModel.decorate.price_list.count;
|
|
}
|
|
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXSelectAuctionInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXSelectAuctionInfoCell" forIndexPath:indexPath];
|
|
cell.priceModel = self.infoModel.decorate.price_list[indexPath.row];
|
|
return cell;
|
|
}
|
|
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
int width = (SCREEN_WIDTH-15*2-15*3-1)/4;
|
|
return CGSizeMake((int)width, 60);
|
|
}
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXShopDressPriceModel *model = self.infoModel.decorate.price_list[indexPath.row];
|
|
if (model.isSelected) {
|
|
return;
|
|
}
|
|
self.selectedPriceModel.isSelected = NO;
|
|
model.isSelected = YES;
|
|
self.selectedPriceModel = model;
|
|
[self.cellValueDict setValue:model.price forKey:@"商品价格"];
|
|
[self.cellValueDict setValue:model.end_time forKey:@"有效期至"];
|
|
[collectionView reloadData];
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
-(void)reductionDidClickWithTotalNum:(NSString *)totalNum{
|
|
self.num = totalNum;
|
|
[self.cellValueDict setValue:[NSString stringWithFormat:@"%ld",self.infoModel.decorate.price.integerValue*totalNum.integerValue] forKey:@"商品总价"];
|
|
[self.cellValueDict setValue:totalNum forKey:@"购买次数"];
|
|
[self.tableView reloadData];
|
|
}
|
|
-(void)addDidClickWithTotalNum:(NSString *)totalNum{
|
|
self.num = totalNum;
|
|
[self.cellValueDict setValue:[NSString stringWithFormat:@"%ld",self.infoModel.decorate.price.integerValue*totalNum.integerValue] forKey:@"商品总价"];
|
|
[self.cellValueDict setValue:totalNum forKey:@"购买次数"];
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
-(UITableView *)tableView{
|
|
if (!_tableView) {
|
|
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, 44*4) style:(UITableViewStylePlain)];
|
|
_tableView.dataSource = self;
|
|
_tableView.delegate = self;
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
_tableView.rowHeight = 44;
|
|
_tableView.scrollEnabled = NO;
|
|
|
|
// MJWeakSelf
|
|
// _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
// weakSelf.page = 1;
|
|
// if (self.isSearch) {
|
|
// [self getMemberListWithSearch:self.textField.text];
|
|
// }else{
|
|
// [self getMemberListWithSearch:@""];
|
|
// }
|
|
// }];
|
|
// _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
|
// weakSelf.page++;
|
|
// if (self.isSearch) {
|
|
// [self getMemberListWithSearch:self.textField.text];
|
|
// }else{
|
|
// [self getMemberListWithSearch:@""];
|
|
// }
|
|
// }];
|
|
}
|
|
return _tableView;
|
|
}
|
|
- (QXEffectContentView *)fullEffectView {
|
|
if (!_fullEffectView) {
|
|
_fullEffectView = [[QXEffectContentView alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
|
_fullEffectView.queue = dispatch_queue_create("qx_room_full_preview_dress.com", NULL);
|
|
_fullEffectView.hidden = YES;
|
|
}
|
|
return _fullEffectView;
|
|
}
|
|
|
|
-(void)showInView:(UIView *)view{
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|
[view addSubview:self];
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
self.bgView.y = SCREEN_HEIGHT- ScaleWidth(429)-kSafeAreaBottom;
|
|
}];
|
|
}
|
|
-(void)hide{
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|
} completion:^(BOOL finished) {
|
|
[self removeFromSuperview];
|
|
}];
|
|
}
|
|
@end
|