118 lines
3.5 KiB
Objective-C
Executable File
118 lines
3.5 KiB
Objective-C
Executable File
//
|
|
// YYPMPickRelationView.m
|
|
// YaYin
|
|
//
|
|
// Created by bj_szd on 2023/7/12.
|
|
// Copyright © 2023 YaYin. All rights reserved.
|
|
//
|
|
|
|
#import "YYPMPickRelationView.h"
|
|
#import "YYJYRelationCell.h"
|
|
#import "YYPMPickTimeView.h"
|
|
|
|
@interface YYPMPickRelationView ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
|
|
|
@property (nonatomic, strong) NSArray *dataArray;
|
|
@property (nonatomic, assign) NSInteger selectedIndex;
|
|
|
|
@end
|
|
|
|
@implementation YYPMPickRelationView
|
|
|
|
- (void)awakeFromNib {
|
|
[super awakeFromNib];
|
|
|
|
self.selectedIndex = -1;
|
|
|
|
[self createUI];
|
|
|
|
[self fetchRelationData];
|
|
}
|
|
|
|
- (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)fetchRelationData {
|
|
NSDictionary *params = @{@"type":@"2"};
|
|
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/dating_room/get_relation_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];
|
|
|
|
YYPMPickTimeView *view = LoadNib(@"YYPMPickTimeView");
|
|
view.frame = [UIScreen mainScreen].bounds;
|
|
[MainWindow() addSubview:view];
|
|
view.rid = self.rid;
|
|
view.relation_id = model.id;
|
|
|
|
[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 = model.name;
|
|
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
|