FenceSiteCell.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. //
  2. // FenceSiteCell.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2017/8/16.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "FenceSiteCell.h"
  9. #import "MJPhotoBrowser.h"
  10. #import "MJPhoto.h"
  11. #import "descVC.h"
  12. #import "MapVC.h"
  13. @implementation FenceSiteCell
  14. - (void)awakeFromNib {
  15. [super awakeFromNib];
  16. }
  17. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  18. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  19. if (self) {
  20. CGFloat x,y,w,h;
  21. x = y = 10;
  22. w = 150;
  23. if (kSize.width == 320) {
  24. w = 130;
  25. }
  26. h = 120;
  27. headImg = [[UIImageView alloc] KSetxywh];
  28. headImg.layer.masksToBounds = YES;
  29. headImg.layer.cornerRadius = 5;
  30. headImg.clipsToBounds = YES;
  31. [headImg setContentMode:UIViewContentModeScaleAspectFit];
  32. [self.contentView addSubview:headImg];
  33. // headImg.userInteractionEnabled = YES;
  34. // [headImg addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)]];
  35. x += w + 10;
  36. w = kSize.width - x - 10;
  37. h = 24;
  38. UILabel *label = [[UILabel alloc] KSetxywh];
  39. [label setText:@"" Font:Font21 TextColor:defGreen];
  40. [self.contentView addSubview:label];
  41. nameLabel = label;
  42. y += h;
  43. label = [[UILabel alloc] KSetxywh];
  44. [label setText:@"" Font:Font17 TextColor:KTitleColor];
  45. [self.contentView addSubview:label];
  46. timeLabel = label;
  47. y += h;
  48. label = [[UILabel alloc] KSetxywh];
  49. [label setText:@"" Font:Font17 TextColor:KTitleColor];
  50. [self.contentView addSubview:label];
  51. carTypeLabel = label;
  52. y += h;
  53. label = [[UILabel alloc] KSetxywh];
  54. [label setText:@"" Font:Font17 TextColor:KTitleColor];
  55. [self.contentView addSubview:label];
  56. carModelLabel = label;
  57. y += h;
  58. label = [[UILabel alloc] KSetxywh];
  59. [label setText:@"" Font:Font17 TextColor:KTitleColor];
  60. [self.contentView addSubview:label];
  61. areaLabel = label;
  62. //简介
  63. x = 10;
  64. y += h + 15;
  65. w = kSize.width - 20;
  66. h = 29;
  67. label = [[UILabel alloc] KSetxywh];
  68. [label setText:@"场地简介" Font:Font18 TextColor:KTitleColor Alignment:NSTextAlignmentLeft];
  69. [self.contentView addSubview:label];
  70. label = [[UILabel alloc] KSetxywh];
  71. [label setText:@"更多 >" Font:Font17 TextColor:defGreen Alignment:NSTextAlignmentRight];
  72. [self.contentView addSubview:label];
  73. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, y, kSize.width, h)];
  74. [btn target:self Tag:1];
  75. [self.contentView addSubview:btn];
  76. lookMoreBtn = btn;
  77. [self.contentView addViewWithRect:CGRectMake(0, y - 7, kSize.width, 7)];
  78. [self.contentView addViewWithRect:CGRectMake(0, y + h, kSize.width, 1)];
  79. y += h + 5;
  80. h = 60;
  81. label = [[UILabel alloc] KSetxywh];
  82. [label setText:@"暂无简介" Font:Font17 TextColor:KTitleColor];
  83. label.numberOfLines = 0;
  84. [self.contentView addSubview:label];
  85. remarkLabel = label;
  86. //地址
  87. y += h + 10;
  88. h = 30;
  89. w -= 85;
  90. label = [[UILabel alloc] KSetxywh];
  91. [label setText:@"" Font:Font17 TextColor:KTitleColor];
  92. [self.contentView addSubview:label];
  93. adressLabel = label;
  94. btn = [[UIButton alloc] initWithFrame:CGRectMake(x + w + 5, y, 80, h)];
  95. [btn setTitle:@"查看地图" textColor:defGreen font:Font17 fotState:UIControlStateNormal];
  96. [btn target:self Tag:2];
  97. [self.contentView addSubview:btn];
  98. lookMapBtn = btn;
  99. y += h;
  100. w = kSize.width - 2*x;
  101. label = [[UILabel alloc] KSetxywh];
  102. [label setText:@"" Font:Font17 TextColor:KTitleColor];
  103. [self.contentView addSubview:label];
  104. lineLabel = label;
  105. y += h;
  106. label = [[UILabel alloc] KSetxywh];
  107. [label setText:@"" Font:Font17 TextColor:KTitleColor];
  108. [self.contentView addSubview:label];
  109. principalLabel = label;
  110. x += 120;
  111. w = kSize.width - x;;
  112. label = [[UILabel alloc] KSetxywh];
  113. [label setText:@"" Font:Font17 TextColor:KTitleColor];
  114. [self.contentView addSubview:label];
  115. mobileLabel = label;
  116. btn = [[UIButton alloc] KSetxywh];
  117. [btn target:self Tag:3];
  118. [self.contentView addSubview:btn];
  119. mobileBtn = btn;
  120. y += h;
  121. label = [[UILabel alloc] KSetxywh];
  122. [label setText:@"" Font:Font17 TextColor:KTitleColor];
  123. [self.contentView addSubview:label];
  124. telLabel = label;
  125. btn = [[UIButton alloc] KSetxywh];
  126. [btn target:self Tag:4];
  127. [self.contentView addSubview:btn];
  128. telBtn = btn;
  129. }
  130. return self;
  131. }
  132. -(void)setDataDic:(NSDictionary *)dataDic {
  133. _dataDic = dataDic;
  134. NSArray *imgs = dataDic[@"imgs"];
  135. if (imgs.count > 0) {
  136. NSString *img = [[imgs firstObject] objectForKey:@"IMGPATH"];
  137. [headImg sd_setImageWithURL:[NSURL URLWithString:img] placeholderImage:[UIImage imageNamed:@"NOIMG"]];
  138. }else{
  139. [headImg sd_setImageWithURL:nil placeholderImage:[UIImage imageNamed:@"NOImg"]];
  140. }
  141. nameLabel.text = dataDic[@"NAME"];
  142. timeLabel.text = [NSString stringWithFormat:@"训练时间:%@",dataDic[@"TRAINTIME"]];
  143. carTypeLabel.text = [NSString stringWithFormat:@"带教车型:%@",dataDic[@"TRAINTYPE"]];
  144. carModelLabel.text = [NSString stringWithFormat:@"训练车品牌:%@",dataDic[@"CARMODEL"]];
  145. areaLabel.text = [NSString stringWithFormat:@"场地占地面积:%@m2",dataDic[@"AREA"]];
  146. NSString *remarkString = @"暂无简介";
  147. if ([dataDic[@"REMARK"] length] > 0) {
  148. remarkString = dataDic[@"REMARK"];
  149. }
  150. remarkLabel.text = remarkString;
  151. adressLabel.text = [NSString stringWithFormat:@"地址:%@",dataDic[@"ADDRESS"]];
  152. lineLabel.text = [NSString stringWithFormat:@"接送点:%@",[dataDic[@"ISPICKUP"] intValue] == 0?@"不接送":dataDic[@"PICK_LINE"]];
  153. principalLabel.text = [NSString stringWithFormat:@"联系人:%@",dataDic[@"PRINCIPAL"]];
  154. [self setLabelTextWithLabel:mobileLabel textString:[NSString stringWithFormat:@"联系电话:%@",dataDic[@"MOBILE"]]];
  155. [self setLabelTextWithLabel:telLabel textString:[NSString stringWithFormat:@"固定电话:%@",dataDic[@"TELPHONE"]]];
  156. }
  157. - (void)btnClick:(UIButton *)sender {
  158. // NSLog(@"click-----><>%d",(int)sender.tag);
  159. if (sender.tag == 1) {
  160. descVC *vc = [[descVC alloc] init];
  161. vc.desc = _dataDic[@"REMARK"];
  162. vc.titleString = @"场地简介";
  163. [_superVC navPushHideTabbarToVC:vc];
  164. }
  165. if (sender.tag == 2) {
  166. MapVC *map = [[MapVC alloc] init];
  167. map.isJustLoad = YES;
  168. map.lat = [_dataDic[@"BDLAT"] floatValue];
  169. map.lng = [_dataDic[@"BDLNG"] floatValue];
  170. map.siteName = _dataDic[@"NAME"];
  171. [_superVC navPushHideTabbarToVC:map];
  172. }
  173. if (sender.tag == 3) {
  174. UIAlertController *alert = [UIAlertController alertControllerWithTitle:_dataDic[@"MOBILE"] message:nil preferredStyle:UIAlertControllerStyleAlert];
  175. [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  176. [alert addAction:[UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  177. NSMutableString * url=[[NSMutableString alloc] initWithFormat:@"tel:%@",_dataDic[@"MOBILE"]];
  178. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  179. }]];
  180. [_superVC presentViewController:alert animated:YES completion:nil];
  181. }
  182. if (sender.tag == 4) {
  183. UIAlertController *alert = [UIAlertController alertControllerWithTitle:_dataDic[@"TELPHONE"] message:nil preferredStyle:UIAlertControllerStyleAlert];
  184. [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  185. [alert addAction:[UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  186. NSMutableString * url=[[NSMutableString alloc] initWithFormat:@"tel:%@",_dataDic[@"TELPHONE"]];
  187. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  188. }]];
  189. [_superVC presentViewController:alert animated:YES completion:nil];
  190. }
  191. }
  192. //用富文本封装个方法供调用
  193. -(void)setLabelTextWithLabel:(UILabel *)label textString:(NSString *)str
  194. {
  195. NSMutableAttributedString *abs = [[NSMutableAttributedString alloc]initWithString:str];
  196. [abs beginEditing];
  197. //字体大小
  198. // [abs addAttribute:NSFontAttributeName
  199. // value:[UIFont scaleSize:30.0]
  200. // range:NSMakeRange(8, 1)];
  201. //字体颜色
  202. [abs addAttribute:NSForegroundColorAttributeName
  203. value:defGreen
  204. range:NSMakeRange(5, str.length - 5)];
  205. //下划线
  206. [abs addAttribute:NSUnderlineStyleAttributeName
  207. value:@(NSUnderlineStyleSingle)
  208. range:NSMakeRange(5, str.length - 5)];
  209. label.attributedText = abs;
  210. }
  211. -(void)tapImage:(UITapGestureRecognizer *)tap
  212. {
  213. NSArray *imgArray = _dataDic[@"imgs"];
  214. if (imgArray.count < 1) {
  215. return;
  216. }
  217. // 1.封装图片数据
  218. NSMutableArray *photos = [NSMutableArray arrayWithCapacity:imgArray.count];
  219. for (NSDictionary *dic in imgArray) {
  220. MJPhoto *photo = [[MJPhoto alloc] init];
  221. photo.url = [NSURL URLWithString:dic[@"IMGPATH"]]; //图片路径
  222. photo.srcImageView = headImg; // 来源于哪个UIImageView
  223. [photos addObject:photo];
  224. }
  225. // 2.显示相册
  226. MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
  227. browser.currentPhotoIndex = 0; //弹出相册时显示的第一张图片
  228. browser.photos = photos; // 设置所有的图片
  229. [browser show];
  230. }
  231. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  232. [super setSelected:selected animated:animated];
  233. }
  234. @end