Files
2025-08-08 11:05:33 +08:00

118 lines
3.5 KiB
Objective-C
Executable File

//
// YYPMPickTimeView.m
// YaYin
//
// Created by bj_szd on 2023/7/12.
// Copyright © 2023 YaYin. All rights reserved.
//
#import "YYPMPickTimeView.h"
#import "YYJYRelationCell.h"
#import "YYPMPickGiftView.h"
@interface YYPMPickTimeView ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, assign) NSInteger selectedIndex;
@end
@implementation YYPMPickTimeView
- (void)awakeFromNib {
[super awakeFromNib];
self.selectedIndex = -1;
[self createUI];
[self fetchDaysData];
}
- (IBAction)onDismiss:(id)sender {
[self removeFromSuperview];
}
- (void)createUI {
[self.applyBtn setJianBianWithCGSize:CGSizeMake(ScreenWidth-30*2, 46)];
WEAK_SELF
[self.touchImgV dg_Tapped:^{
[weakSelf removeFromSuperview];
}];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
CGFloat itemW = (ScreenWidth-15*2-15*2)/3;
layout.itemSize = CGSizeMake(itemW, 44);
layout.minimumInteritemSpacing = 15;
layout.minimumLineSpacing = 15;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
_collectionView.collectionViewLayout = layout;
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerNib:[UINib nibWithNibName:@"YYJYRelationCell" bundle:nil] forCellWithReuseIdentifier:@"YYJYRelationCell"];
}
- (void)fetchDaysData {
NSDictionary *params = @{};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/auction_room/get_day_list" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
NSArray *arr = [YYJYRelationModel mj_objectArrayWithKeyValuesArray:responseDic[@"data"]];
self.dataArray = arr;
[self.collectionView reloadData];
} Failure:^(id _Nonnull errorData) {
}];
}
- (IBAction)onApplyUp:(id)sender {
if (self.selectedIndex == -1) {
[HelpPageDefine showMessage:@"请选择时长"];
return;
}
YYJYRelationModel *model = self.dataArray[self.selectedIndex];
YYPMPickGiftView *view = LoadNib(@"YYPMPickGiftView");
view.frame = [UIScreen mainScreen].bounds;
[MainWindow() addSubview:view];
view.rid = self.rid;
view.relation_id = self.relation_id;
view.day = model.day;
[self removeFromSuperview];
}
#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{
YYJYRelationCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YYJYRelationCell" forIndexPath:indexPath];
YYJYRelationModel *model = self.dataArray[indexPath.row];
cell.titleLab.text = [NSString stringWithFormat:@"%@天", model.day];
if (self.selectedIndex == indexPath.row) {
cell.bgImgV.image = ImageNamed(@"relation_item_sel");
cell.titleLab.textColor = kBlackColor;
}else {
cell.bgImgV.image = ImageNamed(@"relation_item_nor");
cell.titleLab.textColor = kWhiteColor;
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
self.selectedIndex = indexPath.row;
[self.collectionView reloadData];
}
@end