IndexAllCell.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. //
  2. // IndexAllCell.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/9/17.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "IndexAllCell.h"
  9. #import "HomeSubItemModel.h"
  10. #import "HomeWeiCousreCell.h"
  11. #import "BookSubArticeCell.h"
  12. #import "HomeTeacherCell.h"
  13. #import "HomeMusicCell.h"
  14. #import "HomeSchoolCell.h"
  15. #import "IndexGoodBookCell.h"
  16. @interface IndexAllCell ()<UITableViewDelegate,UITableViewDataSource>
  17. @property (nonatomic, strong) IndexAllModel * model;
  18. @property (nonatomic, copy) NSString * searchText;
  19. @end
  20. @implementation IndexAllCell
  21. - (void)awakeFromNib {
  22. [super awakeFromNib];
  23. self.subTableV.delegate = self;
  24. self.subTableV.dataSource = self;
  25. self.backgroundColor = [UIColor clearColor];
  26. self.bgView.layer.cornerRadius = 8.f;
  27. self.bgView.layer.masksToBounds = YES;
  28. }
  29. + (IndexAllCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
  30. {
  31. static NSString *cellIdentifer = @"IndexAllCell0";
  32. IndexAllCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  33. if (cell == nil) {
  34. cell = [[[NSBundle mainBundle] loadNibNamed:@"IndexAllCell" owner:nil options:nil] objectAtIndex:0];
  35. }
  36. return cell;
  37. }
  38. + (IndexAllCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
  39. {
  40. static NSString *cellIdentifer = @"IndexAllCell1";
  41. IndexAllCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  42. if (cell == nil) {
  43. cell = [[[NSBundle mainBundle] loadNibNamed:@"IndexAllCell" owner:nil options:nil] objectAtIndex:1];
  44. }
  45. return cell;
  46. }
  47. - (void)setDataWithModel:(IndexAllModel *)model
  48. {
  49. self.model = model;
  50. self.nameL.text = self.model.LableName;
  51. self.subTableV.estimatedRowHeight = 80;
  52. self.subTableV.rowHeight = UITableViewAutomaticDimension;
  53. self.subTableV.showsVerticalScrollIndicator = NO;
  54. self.subTableV.showsHorizontalScrollIndicator = NO;
  55. [self.subTableV reloadData];
  56. HomeSubItemModel * smodel = self.model.Items.firstObject;
  57. switch ((CollectModelType)smodel.MediaType) {
  58. case CollectModel_StoreBook:
  59. {
  60. self.contant.constant = 120.f * self.model.Items.count;
  61. }
  62. break;
  63. case CollectModel_StoreVideo:
  64. {
  65. self.contant.constant = 110.f * self.model.Items.count;
  66. }
  67. break;
  68. case CollectModel_StoreSound:
  69. {
  70. self.contant.constant = 85.f * self.model.Items.count;
  71. }
  72. break;
  73. case CollectModel_Teacher:
  74. {
  75. self.contant.constant = 130.f * self.model.Items.count;
  76. }
  77. break;
  78. case CollectModel_Organization:
  79. {
  80. self.contant.constant = 130.f * self.model.Items.count;
  81. }
  82. break;
  83. default:
  84. {
  85. self.contant.constant = 120.f * self.model.Items.count;
  86. }
  87. break;
  88. }
  89. }
  90. - (void)setDataWithModel:(IndexAllModel *)model searchText:(NSString *)text
  91. {
  92. self.model = model;
  93. self.searchText = text;
  94. self.nameL.text = self.model.LableName;
  95. self.countL.text = [NSString stringWithFormat:@"(%ld)",self.model.Total];
  96. self.topBtn.selected = self.model.IsTop;
  97. [self.topBtn setTitle:@" 置顶 " forState:UIControlStateNormal];
  98. [self.topBtn setTitle:@" 取消置顶 " forState:UIControlStateSelected];
  99. [self.topBtn setTitleColor:UIColorHex(0x3979D3) forState:UIControlStateNormal];
  100. [self.topBtn setTitleColor:UIColorHex(0xBCBCBC) forState:UIControlStateSelected];
  101. if (self.topBtn.selected) {
  102. self.topBtn.layer.borderColor = UIColorHex(0xBCBCBC).CGColor;
  103. }else{
  104. self.topBtn.layer.borderColor = UIColorHex(0x3979D3).CGColor;
  105. }
  106. self.topBtn.layer.borderWidth = 1.f;
  107. self.topBtn.layer.cornerRadius = 4.f;
  108. self.topBtn.layer.masksToBounds = YES;
  109. self.subTableV.estimatedRowHeight = 80;
  110. self.subTableV.rowHeight = UITableViewAutomaticDimension;
  111. self.subTableV.showsVerticalScrollIndicator = NO;
  112. self.subTableV.showsHorizontalScrollIndicator = NO;
  113. [self.subTableV reloadData];
  114. HomeSubItemModel * smodel = self.model.Items.firstObject;
  115. switch ((CollectModelType)smodel.MediaType) {
  116. case CollectModel_StoreBook:
  117. {
  118. self.contant.constant = 120.f * self.model.Items.count;
  119. }
  120. break;
  121. case CollectModel_StoreVideo:
  122. {
  123. self.contant.constant = 110.f * self.model.Items.count;
  124. }
  125. break;
  126. case CollectModel_StoreSound:
  127. {
  128. self.contant.constant = 85.f * self.model.Items.count;
  129. }
  130. break;
  131. case CollectModel_Teacher:
  132. {
  133. self.contant.constant = 130.f * self.model.Items.count;
  134. }
  135. break;
  136. case CollectModel_Organization:
  137. {
  138. self.contant.constant = 130.f * self.model.Items.count;
  139. }
  140. break;
  141. default:
  142. {
  143. self.contant.constant = 120.f * self.model.Items.count;
  144. }
  145. break;
  146. }
  147. }
  148. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  149. {
  150. return self.model.Items.count;
  151. }
  152. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  153. {
  154. HomeSubItemModel * smodel = self.model.Items[indexPath.item];
  155. switch ((CollectModelType)smodel.MediaType) {
  156. case CollectModel_StoreBook:
  157. {
  158. IndexGoodBookCell * cell = [IndexGoodBookCell configCell0:tableView indexPath:indexPath];
  159. [cell setDataWithModel:smodel searchText:self.searchText];
  160. if (self.model.Items.count == indexPath.row + 1) {
  161. cell.lineV.hidden = YES;
  162. }
  163. return cell;
  164. }
  165. break;
  166. case CollectModel_StoreVideo:
  167. {
  168. HomeWeiCousreCell * cell = [HomeWeiCousreCell configCell0:tableView indexPath:indexPath];
  169. [cell setDataWithIndexModel:smodel searchText:self.searchText];
  170. if (self.model.Items.count == indexPath.row + 1) {
  171. cell.lineV.hidden = YES;
  172. }
  173. return cell;
  174. }
  175. break;
  176. case CollectModel_StoreSound:
  177. {
  178. HomeMusicCell * cell = [HomeMusicCell configCell:tableView indexPath:indexPath];
  179. [cell setDataWithModel:smodel searchText:self.searchText];
  180. if (self.model.Items.count == indexPath.row + 1) {
  181. cell.lineV.hidden = YES;
  182. }
  183. return cell;
  184. }
  185. break;
  186. case CollectModel_Teacher:
  187. {
  188. HomeTeacherCell * cell = [HomeTeacherCell configCell:tableView indexPath:indexPath];
  189. [cell setDataWithModel:smodel searchText:self.searchText];
  190. if (self.model.Items.count == indexPath.row + 1) {
  191. cell.lineV.hidden = YES;
  192. }
  193. return cell;
  194. }
  195. break;
  196. case CollectModel_Organization:
  197. {
  198. HomeSchoolCell * cell = [HomeSchoolCell configCell1:tableView indexPath:indexPath];
  199. [cell setDataIndexModel:smodel searchText:self.searchText];
  200. if (self.model.Items.count == indexPath.row + 1) {
  201. cell.lineV.hidden = YES;
  202. }
  203. return cell;
  204. }
  205. break;
  206. default:
  207. {
  208. IndexGoodBookCell * cell = [IndexGoodBookCell configCell1:tableView indexPath:indexPath];
  209. [cell setDataWithModel:smodel searchText:self.searchText];
  210. if (self.model.Items.count == indexPath.row + 1) {
  211. cell.lineV.hidden = YES;
  212. }
  213. return cell;
  214. }
  215. break;
  216. }
  217. }
  218. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  219. {
  220. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  221. HomeSubItemModel * model = self.model.Items[indexPath.item];
  222. if (self.ClickRowBlock) {
  223. self.ClickRowBlock((CollectModelType)model.MediaType, model.Id);
  224. }
  225. }
  226. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  227. [super setSelected:selected animated:animated];
  228. }
  229. @end