NYClassRoomPeiCell.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. //
  2. // NYClassRoomPeiCell.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2024/2/4.
  6. // Copyright © 2024 JCZ. All rights reserved.
  7. //
  8. #import "NYClassRoomPeiCell.h"
  9. #import "NYClassRoomPeiViewModel.h"
  10. #import "MapManager.h"
  11. #import "TZImagePickerController.h"//第三方相册
  12. @interface NYClassRoomPeiCell ()<TZImagePickerControllerDelegate,UICollectionViewDelegate,UICollectionViewDataSource>{
  13. CGFloat _itemWH;
  14. CGFloat _margin;
  15. NSInteger _index;
  16. }
  17. @property (nonatomic, readwrite, strong) NYClassRoomPeiViewModel *viewModel;
  18. @property (nonatomic, readwrite, assign) CLLocationCoordinate2D myLocation;
  19. @property (nonatomic ,strong) NSMutableArray *photosArray;
  20. @end
  21. @implementation NYClassRoomPeiCell
  22. #pragma mark - PublicMethods
  23. + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
  24. static NSString *ID = @"NYClassRoomPeiCell";
  25. [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
  26. NYClassRoomPeiCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  27. if (!cell) cell = [self rq_viewFromXib];
  28. [cell setup_UI];
  29. return cell;
  30. }
  31. -(void)setup_UI{
  32. [self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
  33. [self.imageArrayView addSubview:self.collectionView];
  34. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.edges.mas_equalTo(self.imageArrayView);
  36. }];
  37. self.collectionView.backgroundColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:1.0];
  38. }
  39. //详细
  40. - (void)setCultivateInfoModel:(CultivateInfoModel *)cultInfoModel{
  41. self.viewModel.cultivateInfoModel = cultInfoModel;
  42. RAC(self.coach_name_label, text) = [[RACObserve(cultInfoModel, coachName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  43. RAC(self.stu_name_label, text) = [[RACObserve(cultInfoModel, stuName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  44. RAC(self.cat_type_label, text) = [[RACObserve(cultInfoModel, stuCx) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  45. RAC(self.cat_num_label, text) = [[RACObserve(cultInfoModel, licnum) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  46. RAC(self.room_name_label, text) = [[RACObserve(cultInfoModel, roomName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  47. RAC(self.school_name_label, text) = [[RACObserve(cultInfoModel, schName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  48. RAC(self.sign_time_label, text) = [[RACObserve(cultInfoModel, signTime) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  49. RAC(self.pei_type_label, text) = [[RACObserve(cultInfoModel, typeName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  50. }
  51. - (void)bindViewModel:(NYClassRoomPeiViewModel *)viewModel {
  52. self.viewModel = viewModel;
  53. [self getClassRoomInfo];
  54. [self getPhotoArray];
  55. //定位功能
  56. [MBProgressHUD rq_showProgressHUD:@"正在获取当前位置..."];
  57. [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location, BMKLocation * _Nullable bmkLocation) {
  58. [MBProgressHUD rq_hideHUD];
  59. if (success) {
  60. _myLocation = location.coordinate;
  61. }
  62. }];
  63. }
  64. //获取 课堂 信息
  65. - (void)getClassRoomInfo{
  66. NSMutableArray *arr = [NSMutableArray array];
  67. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outid"];
  68. [arr property:@"1" forKey:@"type"];//1课堂 2模拟
  69. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  70. NSString* method = @"getStunocarSignInfo";
  71. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  72. if ([dict[@"code"] intValue]!=0) {
  73. return;
  74. }
  75. CultivateInfoModel *cultInfoModel = [CultivateInfoModel modelWithDictionary:[NSMutableDictionary dictionaryWithDictionary:dict[@"body"]]];
  76. [self setCultivateInfoModel:cultInfoModel];
  77. }];
  78. }
  79. //获取课堂 照片
  80. - (void)getPhotoArray{
  81. NSMutableArray *arr = [NSMutableArray array];
  82. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outid"];
  83. [arr property:@"1" forKey:@"type"];//1课堂 2模拟
  84. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  85. [arr property:@"183093223" forKey:@"classid"];
  86. [self.photosArray removeAllObjects];
  87. NSString* method = @"getStunocarPhoto";
  88. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  89. //NSLog(@"getStunocarSignInfodict=====%@",dict);
  90. NSArray<CultivatePhotoModel*> *photo_array = [CultivatePhotoModel modelArrayWithJSON:dict[@"body"][@"photos"]];
  91. [self.photosArray addObjectsFromArray:photo_array];
  92. [self.collectionView reloadData];
  93. }];
  94. }
  95. - (IBAction)submit_clickdo:(UIButton *)sender {
  96. CultivateInfoModel *cultInfoModel = self.viewModel.cultivateInfoModel;
  97. // roomLat roomLng maxDistance
  98. NSString *title = [NSString stringWithFormat:@"您距离课堂超过了%@m",cultInfoModel.maxDistance];
  99. //计算距离
  100. double this_distance = 0.0;
  101. double lat1 = cultInfoModel.roomLat.doubleValue;
  102. double lng1 = cultInfoModel.roomLng.doubleValue;
  103. if(_myLocation.latitude >0){
  104. double lat2 = _myLocation.latitude;
  105. double lng2 = _myLocation.longitude;
  106. this_distance = [self distanceBetweenOrderBy:lat1 :lat2 :lng1 :lng2];
  107. }
  108. if(this_distance>cultInfoModel.maxDistance.doubleValue){//超出范围
  109. // if(cultInfoModel.isDistance){//是否强制 判断-范围
  110. // [RQ_SHARE_FUNCTION showAlertWithTitle:@"提示" message:title alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  111. // if (selectedOtherButtonIndex == 0) {
  112. //
  113. // }
  114. // }];
  115. // }else{
  116. // [RQ_SHARE_FUNCTION showAlertWithTitle:@"提示" message:title alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:nil otherButtonTitles:@[@"确定"] otherButtonStyles:@"取消" showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  117. // if (selectedOtherButtonIndex == 0) {
  118. //
  119. // }
  120. // }];
  121. // }
  122. }else{//未超出范围
  123. //直接-进入人脸-签到流程
  124. }
  125. //-人脸比对
  126. /// 1.本地活体检测
  127. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  128. //@strongify(self)
  129. if (success) {
  130. /// 2.线上活体检测
  131. NSMutableArray *arr = [NSMutableArray array];
  132. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuId"];
  133. [arr property:@"1" forKey:@"type"];//1课堂 2模拟
  134. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  135. [arr property:@"183093223" forKey:@"photo"];
  136. NSString* method = @"stunocarfaceToface";
  137. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  138. //NSLog(@"getStunocarSignInfodict=====%@",dict);
  139. }];
  140. /// 3. updateStunocarPhoto 过程上传
  141. }
  142. }];
  143. //上传-课堂照片
  144. }
  145. -(double)distanceBetweenOrderBy:(double) latitude1 :(double) latitude2 :(double) longitude1 :(double) longitude2{
  146. CLLocation *curLocation = [[CLLocation alloc] initWithLatitude:latitude1 longitude:longitude1];
  147. CLLocation *otherLocation = [[CLLocation alloc] initWithLatitude:latitude2 longitude:longitude2];
  148. // 计算两个坐标之间的距离
  149. CLLocationDistance distance = [curLocation distanceFromLocation:otherLocation];
  150. //double distance = [curLocation distanceFromLocation:otherLocation];
  151. return distance;
  152. }
  153. -(UICollectionView *)collectionView{
  154. if (!_collectionView) {
  155. UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
  156. flowLayOut.itemSize = CGSizeMake(65, 65);
  157. flowLayOut.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
  158. flowLayOut.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  159. self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayOut];
  160. self.collectionView.showsHorizontalScrollIndicator = NO;
  161. self.collectionView.delegate = self;
  162. self.collectionView.dataSource = self;
  163. // self.collectionView.scrollEnabled = NO;
  164. }
  165. return _collectionView;
  166. }
  167. - (NSMutableArray *)photosArray{
  168. if (!_photosArray) {
  169. self.photosArray = [NSMutableArray array];
  170. }
  171. return _photosArray;
  172. }
  173. #pragma mark - SystemMethods
  174. - (void)awakeFromNib {
  175. [super awakeFromNib];
  176. self.contentView.backgroundColor = UIColor.clearColor;
  177. _px00_view.layer.shadowColor = RGBA_COLOR(124, 129, 136, 0.2).CGColor;
  178. _px01_view.layer.shadowColor = RGBA_COLOR(124, 129, 136, 0.2).CGColor;
  179. }
  180. - (void)checkLocalPhoto{
  181. int currentIndex = _index;
  182. NSMutableArray *images = [NSMutableArray array];
  183. for (CultivatePhotoModel *photoModel in self.photosArray) {
  184. [images addObject:photoModel.filepath];
  185. }
  186. [RQ_SHARE_FUNCTION showPhotoBrowserWithDataSource:images currentIndex:currentIndex isCanSave:NO];
  187. }
  188. #pragma mark UICollectionViewDelegate
  189. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  190. _index = indexPath.row;
  191. [self checkLocalPhoto];
  192. }
  193. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  194. return _photosArray.count;
  195. }
  196. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  197. CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  198. cell.deleteButton.hidden = YES;
  199. cell.imagev.frame = CGRectMake(0, 0, 65, 65);
  200. CultivatePhotoModel *photoModel = self.photosArray[indexPath.row];
  201. [cell.imagev sd_setImageWithURL:[NSURL URLWithString:photoModel.filepath]];
  202. return cell;
  203. }
  204. @end