IndexSubVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. //
  2. // IndexSubVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/9/17.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "IndexSubVC.h"
  9. #import "HomeWeiCousreCell.h"
  10. #import "BookSubArticeCell.h"
  11. #import "HomeTeacherCell.h"
  12. #import "HomeMusicCell.h"
  13. #import "HomeSchoolCell.h"
  14. #import "IndexGoodBookCell.h"
  15. #import "HomeSubItemModel.h"
  16. #import "BookTeacherDetailVC.h"
  17. #import "BookWCDetailVC.h"
  18. #import "BookListenVC.h"
  19. #import "BookListDetailVC.h"
  20. @interface IndexSubVC ()<UITableViewDelegate,UITableViewDataSource>
  21. @property (nonatomic, strong) UITableView * tableView;
  22. @property (nonatomic, strong) NSMutableArray * dataArray;
  23. @property (nonatomic, assign) NSInteger currentPage;
  24. @property (nonatomic, assign) NSInteger Total;
  25. @end
  26. @implementation IndexSubVC
  27. - (NSMutableArray *)dataArray
  28. {
  29. if (!_dataArray) {
  30. _dataArray = [NSMutableArray array];
  31. }
  32. return _dataArray;
  33. }
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. self.view.backgroundColor = UIColorHex(0xF8F8F8);
  37. [self.view addSubview:self.tableView];
  38. self.tableView.showsVerticalScrollIndicator = NO;
  39. self.tableView.backgroundColor = [UIColor clearColor];
  40. self.tableView.delegate = self;
  41. self.tableView.dataSource = self;
  42. self.tableView.layer.cornerRadius = 8.f;
  43. self.tableView.layer.masksToBounds = YES;
  44. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.edges.mas_offset(UIEdgeInsetsMake(20,15,(IS_IPHONEX ? 40 : 20) + EMVIEWBOTTOMMARGIN + 50,15));
  46. }];
  47. WS(weakSelf);
  48. self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
  49. [weakSelf footerRefresh];
  50. }];
  51. }
  52. - (void)footerRefresh
  53. {
  54. self.currentPage += 1;
  55. if (self.dataArray.count == self.Total) {
  56. self.tableView.mj_footer.hidden = YES;
  57. [self.tableView.mj_footer resetNoMoreData];
  58. return;
  59. }
  60. [self getDataNetWork];
  61. }
  62. - (void)getDataNetWork
  63. {
  64. WS(weakSelf);
  65. SHOWLOADING
  66. NSDictionary * paraDict = @{@"MediaType":@(self.type),
  67. @"Page":@(self.currentPage),
  68. @"PerPage":@(10),
  69. @"KeyWord":self.searchText
  70. };
  71. [[HttpManager sharedHttpManager] GETUrl:Host(API_APP_Media_Search) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  72. REMOVESHOW
  73. NSLog(@"%@",responseObject);
  74. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  75. for (NSDictionary * dict in responseObject[@"Items"]) {
  76. HomeSubItemModel * model = [HomeSubItemModel modelWithDictionary:dict];
  77. [weakSelf.dataArray addObject:model];
  78. }
  79. }
  80. weakSelf.Total = [responseObject[@"Total"] integerValue];
  81. [weakSelf.tableView.mj_footer endRefreshing];
  82. dispatch_async(dispatch_get_main_queue(), ^{
  83. [weakSelf.tableView reloadData];
  84. });
  85. } failure:^(NSError * _Nonnull error) {
  86. REMOVESHOW
  87. }];
  88. }
  89. - (void)getData
  90. {
  91. [self.dataArray removeAllObjects];
  92. self.currentPage = 1;
  93. self.Total = 0;
  94. [self getDataNetWork];
  95. }
  96. - (UITableView *)tableView
  97. {
  98. if (!_tableView) {
  99. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  100. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  101. }
  102. return _tableView;
  103. }
  104. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  105. //{
  106. // return self.dataArray.count == 0 ? 0.01f : 15.f;
  107. //}
  108. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  109. //{
  110. // return self.dataArray.count == 0 ? 0.01f : 15.f;
  111. //}
  112. //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  113. //{
  114. // UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.dataArray.count == 0 ? 0.01f : 15.f)];
  115. // view.backgroundColor = UIColorHex(0xFFFFFF);
  116. // return view;
  117. //}
  118. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  119. //{
  120. // UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.dataArray.count == 0 ? 0.01f : 15.f)];
  121. // view.backgroundColor = UIColorHex(0xFFFFFF);
  122. // return view;
  123. //}
  124. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  125. {
  126. return self.dataArray.count;
  127. }
  128. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  129. {
  130. HomeSubItemModel * model = [self.dataArray objectAtIndex:indexPath.row];
  131. switch ((CollectModelType)model.MediaType) {
  132. case CollectModel_StoreBook:
  133. {
  134. IndexGoodBookCell * cell = [IndexGoodBookCell configCell0:tableView indexPath:indexPath];
  135. [cell setDataWithModel:model searchText:self.searchText];
  136. if (self.dataArray.count == indexPath.row + 1) {
  137. cell.lineV.hidden = YES;
  138. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
  139. }else{
  140. cell.lineV.hidden = NO;
  141. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
  142. }
  143. return cell;
  144. }
  145. break;
  146. case CollectModel_StoreVideo:
  147. {
  148. HomeWeiCousreCell * cell = [HomeWeiCousreCell configCell0:tableView indexPath:indexPath];
  149. [cell setDataWithIndexModel:model searchText:self.searchText];
  150. if (self.dataArray.count == indexPath.row + 1) {
  151. cell.lineV.hidden = YES;
  152. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
  153. }else{
  154. cell.lineV.hidden = NO;
  155. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
  156. }
  157. return cell;
  158. }
  159. break;
  160. case CollectModel_StoreSound:
  161. {
  162. HomeMusicCell * cell = [HomeMusicCell configCell:tableView indexPath:indexPath];
  163. [cell setDataWithModel:model searchText:self.searchText];
  164. if (self.dataArray.count == indexPath.row + 1) {
  165. cell.lineV.hidden = YES;
  166. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
  167. }else{
  168. cell.lineV.hidden = NO;
  169. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
  170. }
  171. return cell;
  172. }
  173. break;
  174. case CollectModel_Teacher:
  175. {
  176. HomeTeacherCell * cell = [HomeTeacherCell configCell:tableView indexPath:indexPath];
  177. [cell setDataWithModel:model searchText:self.searchText];
  178. if (self.dataArray.count == indexPath.row + 1) {
  179. cell.lineV.hidden = YES;
  180. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
  181. }else{
  182. cell.lineV.hidden = NO;
  183. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
  184. }
  185. return cell;
  186. }
  187. break;
  188. case CollectModel_Organization:
  189. {
  190. HomeSchoolCell * cell = [HomeSchoolCell configCell1:tableView indexPath:indexPath];
  191. [cell setDataIndexModel:model searchText:self.searchText];
  192. if (self.dataArray.count == indexPath.row + 1) {
  193. cell.lineV.hidden = YES;
  194. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
  195. }else{
  196. cell.lineV.hidden = NO;
  197. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
  198. }
  199. return cell;
  200. }
  201. break;
  202. default:
  203. {
  204. IndexGoodBookCell * cell = [IndexGoodBookCell configCell1:tableView indexPath:indexPath];
  205. [cell setDataWithModel:model searchText:self.searchText];
  206. if (self.dataArray.count == indexPath.row + 1) {
  207. cell.lineV.hidden = YES;
  208. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
  209. }else{
  210. cell.lineV.hidden = NO;
  211. [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
  212. }
  213. return cell;
  214. }
  215. break;
  216. }
  217. }
  218. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  219. {
  220. HomeSubItemModel * model = [self.dataArray objectAtIndex:indexPath.row];
  221. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  222. switch ((CollectModelType)model.MediaType) {
  223. case CollectModel_StoreBook:
  224. {
  225. BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC];
  226. vc.Id = model.Id;
  227. [self.navigationController pushViewController:vc animated:YES];
  228. }
  229. break;
  230. case CollectModel_StoreVideo:
  231. {
  232. BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
  233. vc.Id = model.Id;
  234. [self.navigationController pushViewController:vc animated:YES];
  235. }
  236. break;
  237. case CollectModel_StoreSound:
  238. {
  239. BookListenVC * vc = [BookListenVC initBookListenVC];
  240. vc.Id = model.Id;
  241. vc.MediaType = MediaMusicType;
  242. [self.navigationController pushViewController:vc animated:YES];
  243. }
  244. break;
  245. case CollectModel_Teacher:
  246. {
  247. BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
  248. vc.Id = model.Id;
  249. [self.navigationController pushViewController:vc animated:YES];
  250. }
  251. break;
  252. case CollectModel_Organization:
  253. {
  254. }
  255. break;
  256. default:
  257. {
  258. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  259. vc.type = (CollectModelType)model.MediaType;
  260. vc.Id = model.Id;
  261. [self.navigationController pushViewController:vc animated:YES];
  262. }
  263. break;
  264. }
  265. }
  266. - (void)setupRoundedCornersWithView:(UITableViewCell *)cell cutCorners:(UIRectCorner)rectCorner isMask:(BOOL)isMask{
  267. CAShapeLayer *mask = [CAShapeLayer layer];
  268. UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 30, cell.bounds.size.height) byRoundingCorners:rectCorner cornerRadii:CGSizeMake(isMask ? 8 : 0, isMask ? 8 : 0)];
  269. mask.path = path.CGPath;
  270. mask.frame = cell.bounds;
  271. CAShapeLayer *borderLayer = [CAShapeLayer layer];
  272. borderLayer.path = path.CGPath;
  273. borderLayer.fillColor = [UIColor clearColor].CGColor;
  274. borderLayer.strokeColor = [UIColor whiteColor].CGColor;
  275. borderLayer.lineWidth = 0;
  276. borderLayer.frame = cell.bounds;
  277. cell.layer.mask = mask;
  278. [cell.layer addSublayer:borderLayer];
  279. }
  280. @end