FenceSiteCell.m 10.0 KB

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