SecondViewController.m 5.5 KB

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