125 lines
3.6 KiB
Objective-C
125 lines
3.6 KiB
Objective-C
//
|
|
// ZXYChooseNumView.m
|
|
// SweetParty
|
|
//
|
|
// Created by MAC on 2024/5/6.
|
|
//
|
|
|
|
#import "ZXYChooseNumView.h"
|
|
#import "ZXYChooseNumCell.h"
|
|
|
|
@interface ZXYChooseNumView ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
|
|
|
@property (nonatomic, strong) NSArray *dataArray;
|
|
|
|
@property (nonatomic, copy) NSString *rid;
|
|
@property (nonatomic, assign) NSInteger type;
|
|
|
|
@end
|
|
|
|
@implementation ZXYChooseNumView
|
|
|
|
- (void)awakeFromNib {
|
|
[super awakeFromNib];
|
|
|
|
self.dataArray = @[@"10",@"20",@"30",@"50",@"100"];
|
|
|
|
[self createUI];
|
|
|
|
//添加方法
|
|
[self.numTF addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
|
|
}
|
|
|
|
- (void)textFieldChanged:(UITextField*)textField {
|
|
|
|
}
|
|
|
|
- (void)onUpdateWith:(NSInteger)type rid:(NSString *)rid {
|
|
self.type = type;
|
|
self.rid = rid;
|
|
//中奖类型 1吉他2小提琴3古筝4架子鼓5钢琴
|
|
NSArray *titleArr = @[@"吉他", @"小提琴", @"古筝", @"架子鼓", @"钢琴"];
|
|
self.titleLab.text = titleArr[type-1];
|
|
self.titleImgV.image = [UIImage imageNamed:[NSString stringWithFormat:@"zxy_yueqi_%ld", type]];
|
|
}
|
|
|
|
- (void)createUI {
|
|
WEAK_SELF
|
|
[self.touchImgV dg_Tapped:^{
|
|
[weakSelf removeFromSuperview];
|
|
}];
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.itemSize = CGSizeMake(90, 40);
|
|
layout.minimumInteritemSpacing = 15;
|
|
layout.minimumLineSpacing = 13;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
|
|
|
|
_collectionView.collectionViewLayout = layout;
|
|
_collectionView.delegate = self;
|
|
_collectionView.dataSource = self;
|
|
[_collectionView registerNib:[UINib nibWithNibName:@"ZXYChooseNumCell" bundle:nil] forCellWithReuseIdentifier:@"ZXYChooseNumCell"];
|
|
}
|
|
|
|
- (IBAction)onLess:(id)sender {
|
|
NSInteger num = [self.numTF.text integerValue];
|
|
if (num <= 1) {
|
|
return;
|
|
}
|
|
num -= 1;
|
|
self.numTF.text = [NSString stringWithFormat:@"%ld", num];
|
|
}
|
|
|
|
- (IBAction)onMore:(id)sender {
|
|
NSInteger num = [self.numTF.text integerValue];
|
|
num += 1;
|
|
self.numTF.text = [NSString stringWithFormat:@"%ld", num];
|
|
}
|
|
|
|
- (IBAction)onCancel:(id)sender {
|
|
[self removeFromSuperview];
|
|
}
|
|
|
|
- (IBAction)onConfirm:(id)sender {
|
|
if ([self.numTF.text integerValue] <= 0) {
|
|
return;
|
|
}
|
|
NSString *open_data = [NSString stringWithFormat:@"%ld-%ld", self.type, [self.numTF.text integerValue]];
|
|
NSDictionary *params = @{@"open_data":open_data, @"rid":C_string(self.rid)};
|
|
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/Sprite/open_explore_star" Loading:NO Hud:YES Success:^(id _Nonnull responseDic) {
|
|
if (self.onConfirmBlock) {
|
|
self.onConfirmBlock();
|
|
}
|
|
[self removeFromSuperview];
|
|
|
|
} Failure:^(id _Nonnull errorData) {
|
|
|
|
}];
|
|
}
|
|
|
|
#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
|
|
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
|
{
|
|
return self.dataArray.count;
|
|
}
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
ZXYChooseNumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZXYChooseNumCell" forIndexPath:indexPath];
|
|
NSString *str = self.dataArray[indexPath.row];
|
|
cell.numLab.text = str;
|
|
|
|
return cell;
|
|
}
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
self.numTF.text = self.dataArray[indexPath.row];
|
|
}
|
|
|
|
@end
|