SchCell.m 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. UILabel *_watchLab;
  11. }
  12. @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
  13. @property (weak, nonatomic) IBOutlet UILabel *addrLabel;
  14. @property (weak, nonatomic) IBOutlet UILabel *telLabel;
  15. @property (weak, nonatomic) IBOutlet UILabel *cntLabel;
  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 = 96;
  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. //教练计划--进来教练列表cell
  48. CGRect frame = _addrLabel.frame;
  49. _watchLab = [[UILabel alloc]initWithFrame:CGRectMake(kSize.width-180, frame.origin.y, 100, frame.size.height)];
  50. [_watchLab setText:@"" Font:14 TextColor:contentTextColor Alignment:NSTextAlignmentRight];
  51. _watchLab.hidden = YES;
  52. [self.contentView addSubview:_watchLab];
  53. }
  54. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  55. [super setSelected:selected animated:animated];
  56. }
  57. //推荐驾校
  58. -(void)setSchool:(SchInfo *)school
  59. {
  60. _school = school;
  61. [self setHeadImageView:_headImg withImg:school.headImg];
  62. _nameLabel.text = school.jxjc;
  63. _addrLabel.text = school.price;
  64. _telLabel.text = [NSString stringWithFormat:@"%@人关注",[Tools isWan:school.watch]];
  65. _cntLabel.text = [NSString stringWithFormat:@"距您%@公里",school.distance];
  66. [_vipImg setHidden:![school.vip intValue]];
  67. if ([school.price isEqualToString:@"0"])
  68. {
  69. _addrLabel.text = @"暂无";
  70. }
  71. star = [school.starCnt intValue];
  72. if (star == 0)
  73. {
  74. star = 3;
  75. }
  76. [self configStars];
  77. }
  78. //驾校列表
  79. -(void)setSelectDic:(NSDictionary *)selectDic
  80. {
  81. _selectDic = selectDic;
  82. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  83. CGFloat bd = 0;
  84. NSString *str = selectDic[@"HEADIMG"];
  85. if (str && str.length!= 0) {
  86. NSURL * url = [NSURL URLWithString:str];
  87. NSData * imgData = [NSData dataWithContentsOfURL:url];
  88. UIImage *header = [UIImage imageWithData:imgData];
  89. bd = header.size.width - header.size.height;
  90. }
  91. dispatch_async(dispatch_get_main_queue(), ^{
  92. //NSLog(@"图片宽高差-->%f-->%f-->%f",header.size.width,header.size.height,bd);
  93. if (bd < 10 && bd > -10 && bd != 0) {
  94. _headImg.width = _headImg.height;
  95. }else{
  96. _headImg.width = 80;
  97. }
  98. });
  99. });
  100. [self setHeadImageView:_headImg withImg:selectDic[@"HEADIMG"]];
  101. _nameLabel.text = selectDic[@"SHORTNAME"];
  102. _watchLab.text = [NSString stringWithFormat:@"%@人关注",selectDic[@"WATCH"]];
  103. if (_watchLab.hidden == YES){
  104. _watchLab.hidden = NO;
  105. }
  106. _addrLabel.text = selectDic[@"PRICE"];
  107. _telLabel.text = [NSString stringWithFormat:@"%@",selectDic[@"ADDRESS"]];
  108. _cntLabel.text = [NSString stringWithFormat:@"距您%.1fkm",[selectDic[@"DISTANCE"] floatValue]];
  109. [_vipImg setHidden:![selectDic[@"VIP"] intValue]];
  110. if ([selectDic[@"PRICE"] isEqualToString:@""] || [selectDic[@"PRICE"] isEqualToString:@"0"])
  111. {
  112. _addrLabel.text = @"暂无";
  113. }
  114. star = [selectDic[@"STAR"] integerValue]/3;
  115. //NSLog(@"%d",(int)star);
  116. //因为现在服务器取到的都是0 所以先模拟数据
  117. if (star == 0)
  118. {
  119. star = 3;
  120. }
  121. [self configStars];
  122. }
  123. //排行榜--驾校--dict
  124. -(void)setSchDict:(NSDictionary*)dict
  125. {
  126. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  127. CGFloat bd = 0;
  128. NSString *str = dict[@"headimg"];
  129. if (str && str.length!= 0) {
  130. NSURL * url = [NSURL URLWithString:str];
  131. NSData * imgData = [NSData dataWithContentsOfURL:url];
  132. UIImage *header = [UIImage imageWithData:imgData];
  133. bd = header.size.width - header.size.height;
  134. }
  135. //NSLog(@"图片宽高差-->%f-->%f-->%f",header.size.width,header.size.height,bd);
  136. if (str.length > 0 && bd < 10 && bd > -10 && bd != 0) {
  137. _headImg.width = _headImg.height;
  138. }else{
  139. _headImg.width = 80;
  140. }
  141. });
  142. [self setHeadImageView:_headImg withImg:dict[@"headimg"]];
  143. _nameLabel.text = dict[@"name"];
  144. _addrLabel.text = dict[@"price"];
  145. _telLabel.text = [NSString stringWithFormat:@"%@人关注",[Tools isWan:dict[@"watch"]]];
  146. _cntLabel.text = [NSString stringWithFormat:@"距你%@公里",dict[@"distance"]];
  147. [_vipImg setHidden:![dict[@"vip"] intValue]];
  148. if ([dict[@"price"] isEqualToString:@""] || [dict[@"price"] isEqualToString:@"0"])
  149. {
  150. _addrLabel.text = @"暂无";
  151. }
  152. star = [dict[@"star"] integerValue]/3;
  153. //NSLog(@"%d",(int)star);
  154. //因为现在服务器取到的都是0 所以先模拟数据
  155. if (star == 0)
  156. {
  157. star = 3;
  158. }
  159. [self configStars];
  160. }
  161. //普通--教练--驾校--dict
  162. -(void)setSparDict:(NSDictionary *)dict
  163. {
  164. [self setHeadImageView:_headImg withImg:dict[@"headimg"]];
  165. [_nameLabel setText:dict[@"name"]];
  166. [_telLabel setText:[NSString stringWithFormat:@"交易量:%@",dict[@"ordernum"]]];
  167. [_cntLabel setText:[NSString stringWithFormat:@"人气:%@",dict[@"watch"]]];
  168. [_vipImg setHidden:YES];
  169. //NSLog(@"传过来的trainType---->%d",(int)_trainType);
  170. if (_trainType == 1)
  171. {
  172. _addrLabel.text = dict[@"fxPrice"];
  173. }
  174. else if (_trainType == 2)
  175. {
  176. _addrLabel.text = dict[@"plPrice"];
  177. }
  178. else
  179. {
  180. _addrLabel.text = dict[@"qzPrice"];
  181. }
  182. if ([_addrLabel.text isEqualToString:@""] || [_addrLabel.text isEqualToString:@"0"])
  183. {
  184. _addrLabel.text = @"暂无";
  185. }
  186. star = [dict[@"star"] intValue];
  187. //模拟数据
  188. if (star == 0)
  189. {
  190. star = 3;
  191. }
  192. [self configStars];
  193. }
  194. //排行榜--教练--dict--
  195. -(void)setCoaDict:(NSDictionary*)dict
  196. {
  197. //NSLog(@"教练排行榜-->%@",dict);
  198. //教练头像 优先显示真实头像 如果没有再显示上传的头像
  199. //NSLog(@"head-->%@--photo-->%@",dict[@"headImg"],dict[@"photo"]);
  200. NSString *headString = [Tools imageStringWithPhotoString:dict[@"photo"] HeadImgString:dict[@"headImg"] Type:1];
  201. //NSLog(@"----->%@",headString);
  202. _headImg.contentMode = UIViewContentModeScaleAspectFit;
  203. [_headImg sd_setImageWithURL:[NSURL URLWithString:headString] placeholderImage:[UIImage imageNamed:@"NOIMG"]];
  204. [_nameLabel setText:dict[@"name"]];
  205. [_telLabel setText:dict[@"mobile"]];
  206. [_addrLabel setText:dict[@"price"]];
  207. //关注度的问题 如果count不是关注度 这栏就改为综合评分吧
  208. [_cntLabel setText:[NSString stringWithFormat:@"关注:%@",dict[@"count"]]];
  209. [_vipImg setHidden:![dict[@"vip"] intValue]];
  210. if ([dict[@"price"] isEqualToString:@""] || [dict[@"price"] isEqualToString:@"0"])
  211. {
  212. [_addrLabel setText:@"暂无"];
  213. }
  214. star = [dict[@"star"] intValue];
  215. //因为现在服务器取到的都是0 所以先模拟数据
  216. if (star == 0)
  217. {
  218. star = 3;
  219. }
  220. [self configStars];
  221. }
  222. //普通的--教练--dict--
  223. -(void)setCoaSparDict:(NSDictionary*)dict{
  224. NSString *path = dict[@"headImg"];
  225. if (path && ![path hasPrefix:@"http"]){
  226. path = [imgPreFix stringByAppendingString:path];
  227. }
  228. [_headImg sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"NOIMG"]];
  229. [_nameLabel setText:dict[@"ciName"]];
  230. //这个参数
  231. [_cntLabel setText:dict[@"watch"]];
  232. [_telLabel setText:dict[@"ciTelephone"]];
  233. //如果教练有VIP 再打开 --danson
  234. [_vipImg setHidden:YES];
  235. if ([dict[@"price"] isEqualToString:@""] || [dict[@"price"] isEqualToString:@"0"]) {
  236. [_addrLabel setText:@"暂无"];
  237. }else{
  238. [_addrLabel setText:dict[@"price"]];
  239. }
  240. star = [dict[@"star"] intValue];
  241. [self configStars];
  242. }
  243. +(CGFloat)cellHeight
  244. {
  245. return schCellHeight;
  246. }
  247. -(void)setHeadImageView:(UIImageView *)image withImg:(NSString *)img
  248. {
  249. //设置图片大小不变 超出部分截掉
  250. // image.contentMode = UIViewContentModeScaleAspectFill;
  251. // image.clipsToBounds = YES;
  252. //
  253. NSString * imgStr = @"";
  254. if (img && img.length > 0) {
  255. imgStr = img;
  256. }
  257. [_headImg sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"NOIMG"]];
  258. }
  259. /**添加星级
  260. */
  261. -(void)configStars
  262. {
  263. for (int i =0; i<5; i++)
  264. {
  265. UIImage* img = [UIImage imageNamed:@"rankstar0_img.png"];
  266. if (i >= star)
  267. {
  268. img = [img tint:backGroundColor];
  269. }
  270. UIImageView*iv= _ivs[i];
  271. [iv setImage:img];
  272. }
  273. }
  274. @end