// // MyWatchDialViewController.m // tongxin // // Created by ecell on 2023/3/22. // Copyright © 2023 xTT. All rights reserved. // #import "MyWatchDialViewController.h" #import "WSLWaterFlowLayout.h" #import "WatchDialCollectionViewCell.h" #import #import "DialMsgModel.h" @interface MyWatchDialViewController () @property (nonatomic, assign) WSLWaterFlowLayoutStyle flowLayoutStyle; @property (nonatomic ,strong) UICollectionView *menuCollectionView; @property (nonatomic ,assign) NSInteger page; @end @implementation MyWatchDialViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = self.myTableView.backgroundColor; self.title = @"我的表盘"; self.page = 1; 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)]; [self.view addSubview:_menuCollectionView]; [_menuCollectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); }]; [UICommon MessageUpload:@"正在加载"]; [self GetListModel]; } #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, 0.1); } /** 列数*/ -(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 1; } //组内成员个数 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.myDataSource.count; } //设置元素内容 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { WatchDialCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(WatchDialCollectionViewCell.class) forIndexPath:indexPath]; DialMsgModel *model = self.myDataSource[indexPath.item]; cell.Mymodel = model; WEAKSELF cell.labelTouch = ^(DialMsgModel * _Nonnull model) { [weakSelf setMyDial:model]; }; return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { } #pragma mark 同步表盘到手表 /// 同步表盘到手表 - (void)setMyDial:(DialMsgModel *)model { [UICommon MessageUpload:@"正在加载"]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setValue:model.dialDownload forKey:@"url"]; [parameters setValue:cUser.cDevice.imei forKey:@"imei"]; [parameters setValue:cUser.openid forKey:@"openid"]; [parameters setValue:cUser.accesstoken forKey:@"accesstoken"]; [cUser.cDevice updateMyDial:parameters success:^{ [UICommon HidenLoading]; [UICommon MessageSuccessText:@"同步成功" isImg:YES]; } failure:^(NSError *error) { [UICommon MessageErrorText:error.userInfo[@"msg"]]; }]; } #pragma mark 获取我的表盘 /// 获取我的标配 - (void)GetListModel { if (self.page == 1) { [self.myDataSource removeAllObjects]; } NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setObject:@(self.page) forKey:@"current"]; [parameters setObject:@(20) forKey:@"pageSize"]; AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:HTTP_POST_MYPAGELIST parameters:parameters error:nil]; request.timeoutInterval = 10.f; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:cUser.openid forHTTPHeaderField:@"userId"]; NSURLSessionDataTask*task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { [UICommon HidenLoading]; NSDictionary *dic = responseObject; if (dic && [dic[@"code"] integerValue] == 200) { NSArray *arr = dic[@"data"][@"records"]; [arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { DialMsgModel *model = [DialMsgModel yy_modelWithJSON:obj]; [self.myDataSource addObject:model]; }]; if(arr.count > 0) { self.page++; [self.menuCollectionView reloadData]; } } else { NSLog(@"请求失败error=%@", error); } }]; [task resume]; } /* #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