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.
293 lines
10 KiB
293 lines
10 KiB
// |
|
// WatchDialViewController.m |
|
// tongxin |
|
// |
|
// Created by ecell on 2023/3/22. |
|
// Copyright © 2023 xTT. All rights reserved. |
|
// |
|
|
|
#import "WatchDialViewController.h" |
|
#import "MyWatchDialViewController.h" |
|
#import <AFNetworking.h> |
|
#import "DialMsgModel.h" |
|
#import "WSLWaterFlowLayout.h" |
|
#import "WatchDialCollectionViewCell.h" |
|
#import "DialCollectionReusableView.h" |
|
#import "PayPopView.h" |
|
#import "PayModel.h" |
|
|
|
@interface WatchDialViewController ()<WSLWaterFlowLayoutDelegate,UICollectionViewDelegate,UICollectionViewDataSource> |
|
|
|
@property (nonatomic, assign) WSLWaterFlowLayoutStyle flowLayoutStyle; |
|
@property (nonatomic ,strong) UICollectionView *menuCollectionView; |
|
@property (nonatomic ,strong) NSMutableArray *modelListArr; |
|
|
|
@property (nonatomic ,assign) NSInteger page; |
|
|
|
@property (nonatomic ,strong) PayPopView *popView; |
|
|
|
|
|
@end |
|
|
|
@implementation WatchDialViewController |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
self.view.backgroundColor = self.myTableView.backgroundColor; |
|
self.title = @"表盘中心"; |
|
self.popView = [[PayPopView alloc] init]; |
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"我的表盘" style:UIBarButtonItemStylePlain target:self action:@selector(MyDialAction)]; |
|
|
|
self.page = 1; |
|
[self GetPayModel]; |
|
[self GetModel]; |
|
|
|
WEAKSELF |
|
WSLWaterFlowLayout *FlowLayout = [[WSLWaterFlowLayout alloc] init]; |
|
FlowLayout.delegate = self; |
|
FlowLayout.flowLayoutStyle = self.flowLayoutStyle; |
|
|
|
_menuCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) collectionViewLayout:FlowLayout]; |
|
_menuCollectionView.backgroundColor = UIColor.clearColor; |
|
_menuCollectionView.dataSource = self; |
|
_menuCollectionView.delegate = self; |
|
// _menuCollectionView.showsVerticalScrollIndicator = NO; |
|
// _menuCollectionView.alwaysBounceVertical = NO; |
|
// _menuCollectionView.scrollEnabled = NO; |
|
if (@available(iOS 11.0, *)) |
|
_menuCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; |
|
[_menuCollectionView registerClass:WatchDialCollectionViewCell.class forCellWithReuseIdentifier:NSStringFromClass(WatchDialCollectionViewCell.class)]; |
|
[_menuCollectionView registerClass:[DialCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"DialCollectionReusableView"]; |
|
[self.view addSubview:_menuCollectionView]; |
|
[_menuCollectionView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.edges.equalTo(self.view); |
|
}]; |
|
_menuCollectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ |
|
weakSelf.page = 1; |
|
[weakSelf GetModel]; |
|
}]; |
|
_menuCollectionView.mj_footer = [MJRefreshFooter footerWithRefreshingBlock:^{ |
|
|
|
[weakSelf GetModel]; |
|
}]; |
|
} |
|
|
|
|
|
#pragma mark - WSLWaterFlowLayoutDelegate |
|
//返回每个item大小 |
|
- (CGSize)waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
return CGSizeMake((ScreenWidth-35)/2, (ScreenWidth)/1.85); |
|
} |
|
|
|
/** 头视图Size */ |
|
-(CGSize )waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForHeaderViewInSection:(NSInteger)section |
|
{ |
|
return CGSizeMake(ScreenWidth, 40); |
|
} |
|
/** 列数*/ |
|
-(CGFloat)columnCountInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout |
|
{ |
|
return 2; |
|
} |
|
|
|
/** 列间距*/ |
|
-(CGFloat)columnMarginInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout |
|
{ |
|
return 15; |
|
} |
|
/** 行间距*/ |
|
-(CGFloat)rowMarginInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout |
|
{ |
|
return 10; |
|
} |
|
/** 边缘之间的间距*/ |
|
-(UIEdgeInsets)edgeInsetInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout |
|
{ |
|
return UIEdgeInsetsMake(5, 10, 5, 10); |
|
} |
|
|
|
#pragma mark - UICollectionView数据源 |
|
//组个数 |
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView |
|
{ |
|
|
|
return self.modelListArr.count; |
|
} |
|
|
|
//组内成员个数 |
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section |
|
{ |
|
return [self.modelListArr[section] count]; |
|
} |
|
|
|
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) |
|
{ |
|
DialCollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"DialCollectionReusableView" forIndexPath:indexPath]; |
|
DialMsgModel *model = self.modelListArr[indexPath.section][0]; |
|
headerView.titleStr = model.categoryName; |
|
|
|
return headerView; |
|
} |
|
return nil; |
|
} |
|
|
|
|
|
//设置元素内容 |
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
|
|
WatchDialCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(WatchDialCollectionViewCell.class) forIndexPath:indexPath]; |
|
DialMsgModel *model = self.modelListArr[indexPath.section][indexPath.item]; |
|
cell.model = model; |
|
cell.labelTouch = ^(DialMsgModel * _Nonnull model) { |
|
[self.popView subPopView:model]; |
|
}; |
|
|
|
return cell; |
|
} |
|
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
|
|
} |
|
|
|
|
|
#pragma mark 获取表盘列表 |
|
- (void)GetModel |
|
{ |
|
if (self.page == 1) |
|
{ |
|
[self.myDataSource removeAllObjects]; |
|
} |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setObject:@(self.page) forKey:@"current"]; |
|
[parameters setObject:@"" forKey:@"marketName"]; |
|
[parameters setObject:@(20) forKey:@"pageSize"]; |
|
|
|
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; |
|
NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:HTTP_POST_PAGELIST parameters:parameters error:nil]; |
|
request.timeoutInterval = 10.f; |
|
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; |
|
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; |
|
|
|
NSURLSessionDataTask*task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { |
|
|
|
NSDictionary *dic = responseObject; |
|
if (dic && [dic[@"code"] integerValue] == 200) |
|
{ |
|
NSArray *arr = dic[@"data"][@"records"]; |
|
for (NSDictionary *dics in arr) { |
|
[self.myDataSource addObject:dics]; |
|
} |
|
[self modelWithJSON:self.myDataSource]; |
|
if (arr.count > 0) |
|
self.page++; |
|
else |
|
self.menuCollectionView.mj_footer.state = MJRefreshStateNoMoreData; |
|
|
|
[self.menuCollectionView.mj_header endRefreshing]; |
|
[self.menuCollectionView.mj_footer endRefreshing]; |
|
} |
|
else |
|
{ |
|
NSLog(@"请求失败error=%@", error); |
|
} |
|
}]; |
|
[task resume]; |
|
} |
|
|
|
|
|
- (void)modelWithJSON:(NSMutableArray *)arr |
|
{ |
|
[self.modelListArr removeAllObjects]; |
|
NSArray *typesArray = [arr valueForKey:@"categoryName"];//得到的属性type对应的value数组 ,listArray 是没有分组的数据 |
|
NSOrderedSet *set = [NSOrderedSet orderedSetWithArray:typesArray];//排序 |
|
NSArray *sectionArray = [set array]; |
|
|
|
[sectionArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { |
|
NSPredicate *pre = [NSPredicate predicateWithFormat:@"categoryName == %@", obj]; |
|
NSArray *indexArray = [self.myDataSource filteredArrayUsingPredicate:pre]; |
|
NSMutableArray *modelArr = [[NSMutableArray alloc] init]; |
|
for (NSDictionary *dic in indexArray) |
|
{ |
|
DialMsgModel *model = [DialMsgModel yy_modelWithJSON:dic]; |
|
[modelArr addObject:model]; |
|
} |
|
|
|
[self.modelListArr addObject:modelArr]; |
|
}]; |
|
[self.menuCollectionView reloadData]; |
|
NSLog(@"%@",self.modelListArr); |
|
} |
|
|
|
#pragma mark 获取支付方式 |
|
- (void)GetPayModel |
|
{ |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
|
|
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; |
|
NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:HTTP_POST_PAYTYPE parameters:parameters error:nil]; |
|
request.timeoutInterval = 10.f; |
|
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; |
|
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; |
|
|
|
NSURLSessionDataTask*task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { |
|
|
|
NSDictionary *dic = responseObject; |
|
if (dic && [dic[@"code"] integerValue] == 200) |
|
{ |
|
BOOL payInnerFlag = [dic[@"data"][@"payInnerFlag"] boolValue];/// 是否是内购 |
|
if (payInnerFlag) |
|
{ |
|
|
|
} |
|
else |
|
{ |
|
NSMutableArray *payArr = [[NSMutableArray alloc] init]; |
|
NSArray *arr = dic[@"data"][@"payDialTypeVOList"]; |
|
[arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { |
|
PayModel *model = [PayModel yy_modelWithJSON:obj]; |
|
[payArr addObject:model]; |
|
}]; |
|
self.popView.payArr = payArr; |
|
} |
|
|
|
} |
|
else |
|
{ |
|
NSLog(@"请求失败error=%@", error); |
|
} |
|
}]; |
|
[task resume]; |
|
} |
|
|
|
|
|
- (NSMutableArray *)modelListArr |
|
{ |
|
if(!_modelListArr) _modelListArr = [[NSMutableArray alloc] init]; |
|
return _modelListArr; |
|
} |
|
|
|
- (void)MyDialAction |
|
{ |
|
MyWatchDialViewController *vc = [[MyWatchDialViewController alloc] init]; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
} |
|
|
|
|
|
|
|
/* |
|
#pragma mark - Navigation |
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation |
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { |
|
// Get the new view controller using [segue destinationViewController]. |
|
// Pass the selected object to the new view controller. |
|
} |
|
*/ |
|
|
|
@end
|
|
|