天天省钱快报

KBCommunityLeftController.m 10.0KB

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