口袋优选

KBCommunityRightController.m 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. //
  2. // KBCommunityLeftController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBCommunityRightController.h"
  9. #import "KBCommunityCell.h"
  10. #import "UITableView+SDAutoTableViewCellHeight.h"
  11. #import "KBCommunityModel.h"
  12. #import "KBCommunityDetailModel.h"
  13. #import "KBShareGetFriendsModel.h"
  14. #import "KBShareGetFriendsView.h"
  15. #import "KBLoginViewController.h"
  16. @interface KBCommunityRightController ()
  17. <
  18. UITableViewDelegate,
  19. UITableViewDataSource,
  20. YHCommunityDelegate
  21. >
  22. @property (nonatomic, strong) UITableView *tableView;
  23. @property (nonatomic, strong) NSMutableArray *dataArr;
  24. @property (nonatomic ) NSInteger page;
  25. @property (nonatomic,strong ) UIView *backgroudView;
  26. @end
  27. @implementation KBCommunityRightController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. self.page=0;
  31. [self configTableView];
  32. [self requestData];
  33. }
  34. - (void)configTableView {
  35. self.view.backgroundColor = [UIColor yhGrayColor];
  36. [self.view addSubview:self.tableView];
  37. [[UIApplication sharedApplication].keyWindow addSubview:self.backgroudView];
  38. }
  39. - (void)requestData {
  40. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/secretOfMakingMoney",BaseURL];
  41. self.page++;
  42. NSDictionary *dic=@{
  43. @"page":@(self.page)
  44. };
  45. [KBHttp post:url params:dic success:^(id json) {
  46. if ([self.tableView.mj_header isRefreshing]) {
  47. [self.dataArr removeAllObjects];
  48. }
  49. NSArray *arr=[NSArray yy_modelArrayWithClass:[KBCommunityModel class] json:json[@"data"]];
  50. [self setNoDataView:arr];
  51. [self.dataArr addObjectsFromArray:arr];
  52. [self.tableView reloadData];
  53. [self.tableView.mj_header endRefreshing];
  54. } failure:^(NSError *error) {
  55. [self.tableView.mj_header endRefreshing];
  56. [self.tableView.mj_footer endRefreshing];
  57. }];
  58. }
  59. - (void)setNoDataView:(NSArray *)array {
  60. if (array.count > 0) {
  61. [self.tableView.mj_footer endRefreshing];
  62. }else {
  63. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  64. }
  65. self.tableView.showNoDataView = YES;
  66. self.tableView.defaultNoDataText = @"暂无数据";
  67. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  68. [self.tableView.mj_header endRefreshing];
  69. }
  70. #pragma mark ============ UITableView Delegate && DataSource ==========
  71. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  72. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  73. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  74. }
  75. }
  76. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  77. return 0.1;
  78. }
  79. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  80. return self.dataArr.count;
  81. }
  82. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  83. KBCommunityModel *model = self.dataArr[indexPath.row];
  84. KBCommunityCell *cell = [KBCommunityCell cellWithTableView:tableView];
  85. cell.model = model;
  86. cell.delegate=self;
  87. return cell;
  88. }
  89. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  90. return [self cellHeightForIndexPath:indexPath cellContentViewWidth:SCREEN_WIDTH tableView:tableView];
  91. }
  92. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  93. }
  94. #pragma mark -代理 YHCommunityDelegate
  95. -(void)oneTouchShareWithModel:(KBCommunityModel *)model{
  96. // NSArray *arr=model.detail;
  97. // /api/v2/adzoneCreate/secretOneSharing
  98. [MobClick event:OneKeyShareCheats label:@"优选素材"];
  99. if([AccountTool isLogin]){
  100. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  101. pasteboard.string=model.note;
  102. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/secretOneSharing",BaseURL];
  103. NSDictionary *dic=@{@"id":model.Id};
  104. [KBHttp post:url params:dic success:^(id json) {
  105. NSArray *arr=[NSArray yy_modelArrayWithClass:[KBCommunityDetailModel class] json:json[@"data"]];
  106. NSDictionary *userinfo = json[@"userinfo"];
  107. if (arr.count>0) {
  108. __block NSInteger count=0;
  109. NSMutableArray *imgArr=[NSMutableArray array];
  110. __block NSInteger max=(arr.count<9?arr.count:9);
  111. self.backgroudView.hidden=NO;
  112. [SVProgressHUD showWithStatus:@"生成分享中"];
  113. for (int i=0;i<max;i++) {
  114. KBCommunityDetailModel *model=arr[i];
  115. KBShareGetFriendsModel *friendModel=[[KBShareGetFriendsModel alloc]init];
  116. friendModel.getFriendCode=@"";
  117. friendModel.QRcodeUrl=model.url;
  118. friendModel.imgUrl=model.img;
  119. KBShareGetFriendsView *view1=[[KBShareGetFriendsView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  120. view1.model=friendModel;
  121. view1.userinfo = userinfo;
  122. __weak __typeof(view1) weakView1 = view1;
  123. view1.imgSuccBlock = ^{
  124. count++;
  125. [imgArr addObject: [weakView1 changeToImage]];
  126. if (count==max) {
  127. count=0;
  128. [SVProgressHUD dismiss];
  129. self.backgroudView.hidden=YES;
  130. UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:imgArr applicationActivities:nil];
  131. [self presentViewController:activityVC animated:YES completion:nil];
  132. }
  133. };
  134. }
  135. }else{
  136. [SVProgressHUD dismiss];
  137. [MBProgressHUD showMessage:@"没有商品可以分享"];
  138. }
  139. } failure:^(NSError *error) {
  140. }];
  141. }else{
  142. KBLoginViewController *login = [[KBLoginViewController alloc] init];
  143. login.loginSucc = ^{
  144. self.page=0;
  145. [self requestData];
  146. };
  147. [self.navigationController presentViewController:login animated:YES completion:nil];
  148. }
  149. }
  150. #pragma mark ------- layzer ---------
  151. - (UITableView *)tableView {
  152. if (!_tableView) {
  153. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 1, SCREEN_WIDTH, ChildTableViewHeight) style:UITableViewStyleGrouped];
  154. _tableView.estimatedSectionHeaderHeight = 0;
  155. _tableView.estimatedSectionFooterHeight = 0;
  156. _tableView.sectionFooterHeight = 0;
  157. _tableView.sectionHeaderHeight = 0;
  158. _tableView.estimatedRowHeight = 0;
  159. _tableView.delegate = self;
  160. _tableView.dataSource = self;
  161. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  162. _tableView.backgroundColor = [UIColor backgroudColor];
  163. _tableView.bounces = YES;
  164. _tableView.showsVerticalScrollIndicator = NO;
  165. _tableView.separatorColor = [UIColor lineColor];
  166. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  167. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  168. self.page = 0;
  169. [_tableView.mj_footer resetNoMoreData];
  170. [self requestData];
  171. }];
  172. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  173. [self requestData];
  174. }];
  175. _tableView.mj_footer = footer;
  176. [_tableView.mj_footer beginRefreshing];
  177. }
  178. return _tableView;
  179. }
  180. - (NSMutableArray *)dataArr {
  181. if (!_dataArr) {
  182. _dataArr = [NSMutableArray array];
  183. }
  184. return _dataArr;
  185. }
  186. -(UIView *)backgroudView{
  187. if (!_backgroudView) {
  188. _backgroudView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  189. _backgroudView.backgroundColor=[[UIColor grayColor] colorWithAlphaComponent:0.2];
  190. _backgroudView.hidden=YES;
  191. }
  192. return _backgroudView;
  193. }
  194. @end