SlectSchCell.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /**
  2. */
  3. #import "SchCell.h"
  4. #import "Tools.h"
  5. #define schCellHeight 100
  6. @interface SchCell ()
  7. {
  8. NSInteger star;
  9. NSDictionary* modict;
  10. }
  11. @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
  12. @property (weak, nonatomic) IBOutlet UILabel *addrLabel;
  13. @property (weak, nonatomic) IBOutlet UILabel *telLabel;
  14. @property (weak, nonatomic) IBOutlet UILabel *cntLabel;
  15. @property (weak, nonatomic) IBOutlet UILabel *yuanLab;
  16. @property (weak, nonatomic) IBOutlet UIImageView *vipImg;
  17. @property (strong, nonatomic) NSMutableArray* ivs;
  18. @end
  19. @implementation SchCell
  20. +(id)cellWithTableView:(UITableView*)tableView
  21. {
  22. SchCell* cell = [tableView dequeueReusableCellWithIdentifier:@"SchCell"];
  23. if (!cell) {
  24. NSBundle *rootBundle = [NSBundle mainBundle];
  25. cell = [[rootBundle loadNibNamed:@"SchCell" owner:nil options:nil] lastObject];
  26. cell.ivs = [NSMutableArray array];
  27. CGFloat sX = 108;
  28. CGFloat sW = 16;
  29. CGFloat sH = sW;
  30. CGFloat sY = 40;
  31. for (int i =0; i<5; i++)
  32. {
  33. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(sX, sY, sW, sH)];
  34. // iv.frame = CGRectMake(sX, sY, sW, sH);
  35. [cell.contentView addSubview:iv];
  36. sX += (sW + 2);
  37. [cell.ivs addObject:iv];
  38. }
  39. }
  40. return cell;
  41. }
  42. - (void)awakeFromNib {
  43. [super awakeFromNib];
  44. _countLabel = _telLabel;
  45. _headImg.layer.masksToBounds = YES;
  46. _headImg.layer.cornerRadius = 3;
  47. }
  48. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  49. [super setSelected:selected animated:animated];
  50. }
  51. //推荐驾校
  52. -(void)setSchool:(SchInfo *)school
  53. {
  54. _school = school;
  55. [self setHeadImageView:_headImg withImg:school.headImg];
  56. _nameLabel.text = school.jxjc;
  57. _addrLabel.text = school.price;
  58. _telLabel.text = [NSString stringWithFormat:@"%@人关注",[Tools isWan:school.watch]];
  59. _cntLabel.text = [NSString stringWithFormat:@"距你%@公里",school.distance];
  60. [_vipImg setHidden:![school.vip intValue]];
  61. if ([school.price isEqualToString:@"0"])
  62. {
  63. _addrLabel.text = @"暂无";
  64. }
  65. star = [school.starCnt intValue];
  66. if (star == 0)
  67. {
  68. star = 3;
  69. }
  70. [self configStars];
  71. }
  72. //排行榜--驾校--dict
  73. -(void)setSchDict:(NSDictionary*)dict
  74. {
  75. CGFloat bd = 0;
  76. NSString *str = dict[@"headimg"];
  77. if (str && str.length!= 0) {
  78. NSURL * url = [NSURL URLWithString:str];
  79. NSData * imgData = [NSData dataWithContentsOfURL:url];
  80. UIImage *header = [UIImage imageWithData:imgData];
  81. bd = header.size.width - header.size.height;
  82. }
  83. //NSLog(@"图片宽高差-->%f-->%f-->%f",header.size.width,header.size.height,bd);
  84. if (bd < 10 && bd > -10) {
  85. _headImg.width = _headImg.height;
  86. }else{
  87. _headImg.width = 90;
  88. }
  89. [self setHeadImageView:_headImg withImg:dict[@"headimg"]];
  90. _nameLabel.text = dict[@"name"];
  91. _addrLabel.text = dict[@"price"];
  92. _telLabel.text = [NSString stringWithFormat:@"%@人关注",[Tools isWan:dict[@"watch"]]];
  93. _cntLabel.text = [NSString stringWithFormat:@"距你%@公里",dict[@"distance"]];//@lee-mark
  94. [_vipImg setHidden:![dict[@"vip"] intValue]];
  95. if ([dict[@"price"] isEqualToString:@""] || [dict[@"price"] isEqualToString:@"0"])
  96. {
  97. _addrLabel.text = @"暂无";
  98. _yuanLab.hidden = YES;
  99. }else{
  100. _yuanLab.hidden = NO;
  101. }
  102. star = [dict[@"star"] integerValue]/3;
  103. //NSLog(@"%d",(int)star);
  104. //因为现在服务器取到的都是0 所以先模拟数据
  105. if (star == 0)
  106. {
  107. star = 3;
  108. }
  109. [self configStars];
  110. }
  111. //普通--教练--驾校--dict
  112. -(void)setSparDict:(NSDictionary *)dict
  113. {
  114. [self setHeadImageView:_headImg withImg:dict[@"headimg"]];
  115. [_nameLabel setText:dict[@"name"]];
  116. [_telLabel setText:[NSString stringWithFormat:@"交易量:%@",dict[@"ordernum"]]];
  117. [_cntLabel setText:[NSString stringWithFormat:@"人气:%@",dict[@"watch"]]];
  118. [_vipImg setHidden:YES];
  119. //NSLog(@"传过来的trainType---->%d",(int)_trainType);
  120. if (_trainType == 1)
  121. {
  122. _addrLabel.text = dict[@"fxPrice"];
  123. }
  124. else if (_trainType == 2)
  125. {
  126. _addrLabel.text = dict[@"plPrice"];
  127. }
  128. else
  129. {
  130. _addrLabel.text = dict[@"qzPrice"];
  131. }
  132. if ([_addrLabel.text isEqualToString:@""] || [_addrLabel.text isEqualToString:@"0"])
  133. {
  134. _addrLabel.text = @"暂无";
  135. }
  136. star = [dict[@"star"] intValue];
  137. //模拟数据
  138. if (star == 0)
  139. {
  140. star = 3;
  141. }
  142. [self configStars];
  143. }
  144. //排行榜--教练--dict--
  145. -(void)setCoaDict:(NSDictionary*)dict
  146. {
  147. //NSLog(@"教练排行榜-->%@",dict);
  148. //教练头像 优先显示真实头像 如果没有再显示上传的头像
  149. //NSLog(@"head-->%@--photo-->%@",dict[@"headImg"],dict[@"photo"]);
  150. NSString *headString = [Tools imageStringWithPhotoString:dict[@"photo"] HeadImgString:dict[@"headImg"] Type:1];
  151. //NSLog(@"----->%@",headString);
  152. _headImg.contentMode = UIViewContentModeScaleAspectFit;
  153. [_headImg setImageWithURL:[NSURL URLWithString:headString] placeholderImage:[UIImage imageNamed:@"NOIMG"]];
  154. [_nameLabel setText:dict[@"name"]];
  155. [_telLabel setText:dict[@"mobile"]];
  156. [_addrLabel setText:dict[@"price"]];
  157. //关注度的问题 如果count不是关注度 这栏就改为综合评分吧
  158. [_cntLabel setText:[NSString stringWithFormat:@"关注:%@",dict[@"count"]]];
  159. [_vipImg setHidden:![dict[@"vip"] intValue]];
  160. if ([dict[@"price"] isEqualToString:@""] || [dict[@"price"] isEqualToString:@"0"])
  161. {
  162. [_addrLabel setText:@"暂无"];
  163. }
  164. star = [dict[@"star"] intValue];
  165. //因为现在服务器取到的都是0 所以先模拟数据
  166. if (star == 0)
  167. {
  168. star = 3;
  169. }
  170. [self configStars];
  171. }
  172. //普通的--教练--dict--
  173. -(void)setCoaSparDict:(NSDictionary*)dict{
  174. NSString *path = dict[@"headImg"];
  175. if (path && ![path hasPrefix:@"http"]){
  176. path = [imgPreFix stringByAppendingString:path];
  177. }
  178. [_headImg setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"NOIMG"]];
  179. [_nameLabel setText:dict[@"ciName"]];
  180. //这个参数
  181. [_cntLabel setText:dict[@"watch"]];
  182. [_telLabel setText:dict[@"ciTelephone"]];
  183. //如果教练有VIP 再打开 --danson
  184. [_vipImg setHidden:YES];
  185. if ([dict[@"price"] isEqualToString:@""] || [dict[@"price"] isEqualToString:@"0"]) {
  186. [_addrLabel setText:@"暂无"];
  187. }else{
  188. [_addrLabel setText:dict[@"price"]];
  189. }
  190. star = [dict[@"star"] intValue];
  191. [self configStars];
  192. }
  193. +(CGFloat)cellHeight
  194. {
  195. return schCellHeight;
  196. }
  197. -(void)setHeadImageView:(UIImageView *)image withImg:(NSString *)img
  198. {
  199. //设置图片大小不变 超出部分截掉
  200. image.contentMode = UIViewContentModeScaleAspectFill;
  201. image.clipsToBounds = YES;
  202. NSURL * url = nil;
  203. if (img) {
  204. url = [NSURL URLWithString:[imgPreFix stringByAppendingString:img]];
  205. }
  206. [_headImg setImageWithURL:url placeholderImage:[UIImage imageNamed:@"NOIMG"]];
  207. }
  208. /**添加星级
  209. */
  210. -(void)configStars
  211. {
  212. for (int i =0; i<5; i++)
  213. {
  214. UIImage* img = [UIImage imageNamed:@"rankstar0_img.png"];
  215. if (i >= star)
  216. {
  217. img = [img tint:backGroundColor];
  218. }
  219. UIImageView*iv= _ivs[i];
  220. [iv setImage:img];
  221. }
  222. }
  223. @end