口袋优选

KBCommunityLeftController.m 11KB

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