MGShopView.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // MGShopView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2020/7/17.
  6. // Copyright © 2020 xfg. All rights reserved.
  7. //
  8. #import "MGShopView.h"
  9. #import "MGShopTableCell.h"
  10. @implementation MGShopView
  11. -(instancetype)initWithFrame:(CGRect)frame UserId:(NSString *)userID ResponseJson:(NSDictionary *)json{
  12. if (self = [super initWithFrame:frame]) {
  13. self.backgroundColor = kWhiteColor;
  14. self.layer.cornerRadius = 10;
  15. self.clipsToBounds = YES;
  16. self.user_id = userID;
  17. // self.json = json;
  18. [self initSubview];
  19. }
  20. return self;
  21. }
  22. - (void)initSubview{
  23. [self addSubview:self.titleLabel];
  24. UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, self.titleLabel.bottom - 0.5, self.width, 0.5)];
  25. lineView.backgroundColor = kClearColor;
  26. [self addSubview:lineView];
  27. [self addSubview:self.tableView];
  28. UIButton *closeBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 10, kRealValue(25), kRealValue(25))];
  29. closeBtn.right = self.right - kRealValue(25);
  30. [closeBtn setImage:[UIImage imageNamed:@"pl_publishlive_close"] forState:UIControlStateNormal];
  31. [closeBtn addTarget:self action:@selector(closeBtn:) forControlEvents:UIControlEventTouchUpInside];
  32. [self addSubview:closeBtn];
  33. [self bringSubviewToFront:closeBtn];
  34. }
  35. -(void)closeBtn:(UIButton *)sender{
  36. [self hide];
  37. }
  38. - (void)requestWardData{
  39. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  40. [dict setValue:@"myshop" forKey:@"ctl"];
  41. [dict setValue:@"get_other_shop_product_list" forKey:@"act"];
  42. [dict setValue:self.user_id forKey:@"to_user_id"];
  43. FWWeakify(self)
  44. [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  45. if ([responseJson toInt:@"status"] == 200) {
  46. //守护数量
  47. }
  48. [self.dataArray removeAllObjects];
  49. NSArray *arr = [responseJson valueForKey:@"list"];
  50. for (NSDictionary *dic in arr) {
  51. MGShopListModel *model = [MGShopListModel mj_objectWithKeyValues:dic];
  52. [self.dataArray addObject:model];
  53. }
  54. [self.tableView reloadData];
  55. } FailureBlock:^(NSError *error) {
  56. }];
  57. // [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  58. //
  59. // if ([responseJson toInt:@"status"] == 200) {
  60. // //守护数量
  61. // [self.dataArray removeAllObjects];
  62. // NSDictionary *dataDic = [responseJson valueForKey:@"data"];
  63. // //守护数量
  64. // NSString *total = dataDic[@"total"];
  65. //
  66. // [self.titleLabel setText:[NSString stringWithFormat:ASLocalizedString(@"道具礼物(%@)"),total]];
  67. //
  68. // self.tableView.frame = CGRectMake(0, self.titleLabel.bottom, self.bounds.size.width, self.bounds.size.height - self.titleLabel.height);
  69. //
  70. // NSArray *list = dataDic[@"data"];
  71. // if (list && list.count) {
  72. // for (NSDictionary *dict in list) {
  73. // GiftModel *model = [GiftModel mj_objectWithKeyValues:dict];
  74. // model.isSelected = NO;
  75. // if (self.dataArray.count < 1) {
  76. // model.isSelected = YES;
  77. // }
  78. // [self.dataArray addObject:model];
  79. // }
  80. //
  81. //
  82. // if (!self.dataArray.count) {
  83. // [self addSubview:self.noWardView];
  84. // }else{
  85. // [self.noWardView removeFromSuperview];
  86. // }
  87. // [self.tableView reloadData];
  88. // }else{
  89. //
  90. // }
  91. // }else{
  92. // //接口请求失败
  93. // NSLog(ASLocalizedString(@"守护列表请求数据失败responseJson:%@"),responseJson);
  94. // }
  95. //
  96. // } failure:^(NSString *errorStr, id mark) {
  97. //
  98. // }];
  99. }
  100. - (void)show:(UIView *)superView{
  101. [self requestWardData];
  102. [superView addSubview:self.shadowView];
  103. [superView addSubview:self];
  104. [UIView animateWithDuration:0.25 animations:^{
  105. // self.center = CGPointMake(kScreenW / 2, kScreenH / 2);
  106. self.bottom = kScreenH;
  107. self.shadowView.alpha = 1;
  108. }];
  109. }
  110. - (void)hide{
  111. [UIView animateWithDuration:0.25 animations:^{
  112. self.frame = CGRectMake(0, kScreenH, self.width, self.height);
  113. self.shadowView.alpha = 0;
  114. } completion:^(BOOL finished) {
  115. [self removeFromSuperview];
  116. [self.shadowView removeFromSuperview];
  117. }];
  118. }
  119. #pragma mark - UITableViewDelegate UITableViewDataSource
  120. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  121. return self.dataArray.count;
  122. }
  123. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  124. if (indexPath.row >= self.dataArray.count) {
  125. return nil;
  126. }
  127. MGShopListModel *model = self.dataArray[indexPath.row];
  128. MGShopTableCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MGShopTableCell class])];
  129. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  130. [cell resetViewWithModel:model];
  131. // cell.clickBtnBlock = ^(GiftModel * _Nonnull model) {
  132. //
  133. //
  134. //// _model = model;
  135. // };
  136. return cell;
  137. }
  138. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  139. return 80;
  140. }
  141. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  142. MGShopListModel *model = self.dataArray[indexPath.row];
  143. if (![model.shop_url containsString:@"http"]) {
  144. [BGHUDHelper alert:ASLocalizedString(@"URL不合法")];
  145. return;
  146. }
  147. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:model.shop_url]];
  148. }
  149. #pragma mark - Lazy Load
  150. - (UIView *)shadowView{
  151. if (!_shadowView) {
  152. _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScaleH)];
  153. _shadowView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.3];
  154. _shadowView.alpha = 0;
  155. _shadowView.userInteractionEnabled = YES;
  156. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
  157. [_shadowView addGestureRecognizer:tap];
  158. }
  159. return _shadowView;
  160. }
  161. - (UITableView *)tableView{
  162. if (!_tableView) {
  163. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, self.titleLabel.bottom, self.bounds.size.width, self.bounds.size.height - self.titleLabel.height - 60) style:UITableViewStylePlain];
  164. _tableView.delegate = self;
  165. _tableView.dataSource = self;
  166. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  167. [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([MGShopTableCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:NSStringFromClass([MGShopTableCell class])];
  168. // [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([WardViewCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:NSStringFromClass([WardViewCell class])];
  169. _tableView.backgroundColor = kWhiteColor;
  170. }
  171. return _tableView;
  172. }
  173. - (NSMutableArray *)dataArray{
  174. if (!_dataArray) {
  175. _dataArray = [[NSMutableArray alloc]init];
  176. }
  177. return _dataArray;
  178. }
  179. - (UILabel *)titleLabel{
  180. if (!_titleLabel) {
  181. _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.width, 50)];
  182. _titleLabel.text = ASLocalizedString(@"商品列表");
  183. _titleLabel.textColor = kBlackColor;
  184. _titleLabel.backgroundColor = kWhiteColor;
  185. _titleLabel.font = [UIFont systemFontOfSize:15];
  186. _titleLabel.textAlignment = NSTextAlignmentCenter;
  187. }
  188. return _titleLabel;
  189. }
  190. //- (UIView *)noWardView{
  191. // if (!_noWardView) {
  192. // _noWardView = [[UIView alloc]initWithFrame:self.tableView.bounds];
  193. // _noWardView.top = kRealValue(44);
  194. // _noWardView.height = self.tableView.height - kRealValue(44);
  195. // UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 188, 130)];
  196. // imageView.centerX = self.tableView.width / 2;
  197. // imageView.top = self.titleLabel.bottom + 10;
  198. // imageView.image = [UIImage imageNamed:ASLocalizedString(@"暂无数据")];
  199. // [_noWardView addSubview:imageView];
  200. // UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, imageView.bottom + 20, self.tableView.width - 20, 20)];
  201. // label.textColor = RGB(230, 230, 230);
  202. // label.textAlignment = NSTextAlignmentCenter;
  203. // label.font = [UIFont systemFontOfSize:15];
  204. // [_noWardView addSubview:label];
  205. // self.noWardViewLabel = label;
  206. // }
  207. // return _noWardView;
  208. //}
  209. /*
  210. // Only override drawRect: if you perform custom drawing.
  211. // An empty implementation adversely affects performance during animation.
  212. - (void)drawRect:(CGRect)rect {
  213. // Drawing code
  214. }
  215. */
  216. @end