HomeMingShiVC.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // HomeMingShiVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/6/23.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeMingShiVC.h"
  9. #import "HomeSubModel.h"
  10. #import "HomeSubItemModel.h"
  11. #import "HomeTeacherCell.h"
  12. #import "MoveViewController.h"
  13. #import "BookTeacherDetailVC.h"
  14. @interface HomeMingShiVC ()<UITableViewDelegate,UITableViewDataSource>
  15. @property (nonatomic, strong) UITableView * tableView;
  16. @property (nonatomic, strong) NSMutableArray * dataSource;
  17. @end
  18. @implementation HomeMingShiVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self.view addSubview:self.tableView];
  22. self.tableView.delegate = self;
  23. self.tableView.dataSource = self;
  24. [self getData];
  25. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(collectSuccess) name:COLLECTSUCCESS object:nil];
  26. }
  27. - (void)dealloc
  28. {
  29. [[NSNotificationCenter defaultCenter] removeObserver:self];
  30. }
  31. - (void)setHeight:(CGFloat)height
  32. {
  33. [self.tableView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, height - 45)];
  34. }
  35. - (UITableView *)tableView
  36. {
  37. if (!_tableView) {
  38. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  39. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  40. _tableView.showsVerticalScrollIndicator = NO;
  41. }
  42. return _tableView;
  43. }
  44. - (NSMutableArray *)dataSource
  45. {
  46. if (!_dataSource) {
  47. _dataSource = [NSMutableArray array];
  48. }
  49. return _dataSource;
  50. }
  51. - (void)getData
  52. {
  53. WS(weakSelf);
  54. [weakSelf.dataSource removeAllObjects];
  55. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_Teacher) parameters:@{@"StyleCss":self.style,@"Page":@(1),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  56. NSLog(@"%@",responseObject);
  57. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  58. HomeSubModel *model = [HomeSubModel modelWithDictionary:responseObject];
  59. for (NSDictionary * dict in model.Items) {
  60. HomeSubItemModel *smodel = [HomeSubItemModel modelWithDictionary:dict];
  61. [weakSelf.dataSource addObject:smodel];
  62. }
  63. }
  64. dispatch_async(dispatch_get_main_queue(), ^{
  65. [weakSelf.tableView reloadData];
  66. });
  67. } failure:^(NSError * _Nonnull error) {
  68. }];
  69. }
  70. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  71. {
  72. return 1;
  73. }
  74. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  75. {
  76. return self.dataSource.count;
  77. }
  78. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  79. {
  80. return UITableViewAutomaticDimension;
  81. }
  82. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. WS(weakSelf);
  85. HomeSubItemModel *model = self.dataSource[indexPath.row];
  86. HomeTeacherCell * cell = [HomeTeacherCell configCell:tableView indexPath:indexPath];
  87. [cell setDataWithModel:model];
  88. cell.ClickCollectBlock = ^(NSInteger Id) {
  89. if (model.IsCollect) {
  90. dispatch_async(dispatch_get_main_queue(), ^{
  91. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"真的取消收藏吗?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  92. UIAlertAction *actionYes = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  93. NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
  94. [dic setValue:@(Id) forKey:@"CollectionDataId"];
  95. /// 1文章 2话题 3 收藏 4笔记 5通知 6站内信 7小组 8 会议详情 14工作流审批 300 文件 400 会议纪要
  96. [dic setValue:@(CollectModel_Teacher) forKey:@"CollectionType"];
  97. [dic setValue:@(0) forKey:@"FolderId"];
  98. [dic setValue:@(0) forKey:@"SourceUserId"];
  99. [[HttpManager sharedHttpManager] PUTUrl:Host(API_CreateCollect) parameters:dic success:^(id _Nonnull responseObject) {
  100. model.IsCollect = NO;
  101. dispatch_async(dispatch_get_main_queue(), ^{
  102. [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  103. });
  104. } failure:^(NSError * _Nonnull error) {
  105. // SHOWERROR([ZYCTool handerResultData:error]);
  106. }];
  107. }];
  108. UIAlertAction *actionNo = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  109. }];
  110. [alert addAction:actionYes];
  111. [alert addAction:actionNo];
  112. [weakSelf presentViewController:alert animated:YES completion:^{
  113. }];
  114. });
  115. }else{
  116. [weakSelf gotoCollectHander:Id];
  117. }
  118. };
  119. return cell;
  120. }
  121. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  122. {
  123. HomeSubItemModel * model = self.dataSource[indexPath.row];
  124. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  125. BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
  126. vc.Id = model.Id;
  127. [self.navigationController pushViewController:vc animated:YES];
  128. }
  129. - (void)gotoCollectHander:(NSInteger)Id{
  130. MoveViewController *vc = [MoveViewController initMoveViewController];
  131. vc.CollectionDataId = Id;
  132. vc.collectType = CollectHanderType_Collect;
  133. vc.CollectionType = CollectModel_Teacher;
  134. vc.ParentId = 0;
  135. vc.titleStr = @"我的收藏";
  136. vc.TypeId = CreateCollectionType;
  137. vc.FolderIds = @[].mutableCopy;
  138. [self.navigationController pushViewController:vc animated:YES];
  139. }
  140. - (void)collectSuccess
  141. {
  142. [self getData];
  143. }
  144. @end