猎豆优选

LDCommunityLeftController.m 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. //
  2. // LDCommunityLeftController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDCommunityLeftController.h"
  9. #import "LDCommunityCell.h"
  10. #import "UITableView+SDAutoTableViewCellHeight.h"
  11. #import "LDCommunityModel.h"
  12. #import "LDCommunityDetailModel.h"
  13. #import "LDShareGoodsModel.h"
  14. #import "LDShareGoodsView.h"
  15. #import "LDLoginViewController.h"
  16. #import "LDPopShareGoodView.h"
  17. #import "LDCommunityTopModel.h"
  18. #import "LDCommunityShareCell.h"
  19. #import "LDGoodDetailModel.h"
  20. #import "LDShareImgPopView.h"
  21. #import "LDCommunityRightController.h"
  22. #import "LDCommunityCell.h"
  23. #import "UITableView+SDAutoTableViewCellHeight.h"
  24. #import "LDCommunityModel.h"
  25. #import "LDCommunityDetailModel.h"
  26. #import "LDShareGetFriendsModel.h"
  27. #import "LDShareGetFriendsView.h"
  28. #import "LDLoginViewController.h"
  29. #import "LDCommunityRightCell.h"
  30. #import "LDCommunityRightModel.h"
  31. #import "shareView.h"
  32. #import "LDShareGoodsTempModel.h"
  33. #import "LDShareGoodsModel.h"
  34. #import <SDWebImageDownloader.h>
  35. #import "LDPopShareGoodView.h"
  36. #import "LDShareManager.h"
  37. #import "HYUMShareManager.h"
  38. #import "WXApi.h"
  39. #import "LDShareImgPopView.h"
  40. #import "CCAlertShowView.h"
  41. #import "LDGoodDetailModel.h"
  42. #import "LDLinkFansController.h"
  43. #import "AccountTool.h"
  44. @interface LDCommunityLeftController ()
  45. <
  46. UICollectionViewDelegate,
  47. UICollectionViewDataSource,
  48. UICollectionViewDelegateFlowLayout,
  49. UITableViewDelegate,
  50. UITableViewDataSource,
  51. YHCommunityDelegate,
  52. PhotoContainerViewDelegate
  53. >
  54. {
  55. ActivityIndicatorView *_indicatorView;
  56. }
  57. @property (nonatomic, strong) UITableView *tableView;
  58. @property (nonatomic, strong) NSMutableArray *dataArr;//分享前十
  59. @property(nonatomic,strong)NSMutableArray *recommendListArray;//优选推荐
  60. //@property (nonatomic,strong ) UIView *backgroudView;
  61. @property(nonatomic,strong)UICollectionView *collections;
  62. @property (nonatomic ) NSInteger page;
  63. @end
  64. @implementation LDCommunityLeftController
  65. - (void)viewDidLoad {
  66. [super viewDidLoad];
  67. [self initHUD];
  68. self.page=1;
  69. [self configTableView];
  70. }
  71. - (void)initHUD {
  72. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  73. _indicatorView = indicatorView;
  74. [_indicatorView startAnimating];
  75. }
  76. - (void)configTableView {
  77. self.view.backgroundColor = [UIColor backgroudColor];
  78. [self.view addSubview:self.tableView];
  79. // [[UIApplication sharedApplication].keyWindow addSubview:self.backgroudView];
  80. }
  81. - (void)requestData {
  82. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/todayHotGoodsList",BaseURL];
  83. NSDictionary *dic=@{
  84. @"page":@(self.page)
  85. };
  86. [LDHttp post:url params:dic success:^(id json) {
  87. [_indicatorView stopAnimating];
  88. [self.dataArr removeAllObjects];
  89. if ([self.tableView.mj_header isRefreshing]) {
  90. [self.recommendListArray removeAllObjects];
  91. }
  92. NSArray *arr=[NSArray yy_modelArrayWithClass:[LDCommunityDetailModel class] json:json[@"recommendList"]];
  93. NSArray *dataA =[NSArray yy_modelArrayWithClass:[LDCommunityDetailModel class] json:json[@"top10"]];
  94. [self.dataArr addObjectsFromArray:dataA];
  95. [self.recommendListArray addObjectsFromArray:arr];
  96. if (self.dataArr.count != 0) {
  97. [self addTableViewHeader];
  98. [self.collections reloadData];
  99. }
  100. [self setNoDataView:arr];
  101. [self.tableView reloadData];
  102. [self.tableView.mj_header endRefreshing];
  103. } failure:^(NSError *error) {
  104. [self.tableView.mj_header endRefreshing];
  105. [self.tableView.mj_footer endRefreshing];
  106. [_indicatorView stopAnimating];
  107. }];
  108. }
  109. - (void)setNoDataView:(NSArray *)array {
  110. self.tableView.showNoDataView = YES;
  111. self.tableView.defaultNoDataText = @"暂无数据";
  112. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  113. if (array.count > 0) {
  114. [self.tableView.mj_footer endRefreshing];
  115. }else {
  116. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  117. }
  118. }
  119. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  120. return self.dataArr.count;
  121. }
  122. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  123. LDCommunityShareCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
  124. if (!cell ) {
  125. cell = [[LDCommunityShareCell alloc] init];
  126. }
  127. cell.model=self.dataArr[indexPath.row];
  128. switch (indexPath.row) {
  129. case 0:
  130. cell.tipeImg.image =[UIImage imageNamed:@"comm_one"];
  131. break;
  132. case 1:
  133. cell.tipeImg.image =[UIImage imageNamed:@"comm_two"];
  134. break;
  135. case 2:
  136. cell.tipeImg.image =[UIImage imageNamed:@"comm_three"];
  137. break;
  138. default:
  139. cell.tipeImg.image =[UIImage imageNamed:@""];
  140. break;
  141. }
  142. cell.backgroundColor = [UIColor yellowColor];
  143. return cell;
  144. }
  145. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  146. {
  147. LDCommunityDetailModel *model=self.dataArr[indexPath.row];
  148. [self otherOPByModel:model isTop:YES];
  149. [MobClick event:FaddishTopItemClick];
  150. }
  151. #pragma mark ============ UITableView Delegate && DataSource ==========
  152. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  153. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  154. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  155. }
  156. }
  157. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  158. {
  159. return FITSIZE(10);
  160. }
  161. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  162. return 1;
  163. }
  164. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  165. {
  166. return self.recommendListArray.count;
  167. }
  168. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  169. LDCommunityDetailModel *model = self.recommendListArray[indexPath.section];
  170. LDCommunityCell *cell = [LDCommunityCell cellWithTableView:tableView];
  171. cell.model = model;
  172. cell.picContainerView.delegate=self;
  173. cell.delegate=self;
  174. cell.layer.cornerRadius=5;
  175. cell.layer.masksToBounds=YES;
  176. cell.shareClick = ^{
  177. if (![AccountTool isLogin]) {
  178. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  179. login.modalPresentationStyle = UIModalPresentationFullScreen;
  180. [self presentViewController:login animated:YES completion:nil];
  181. }else{
  182. [self showShareView:model];
  183. }
  184. };
  185. return cell;
  186. }
  187. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  188. LDCommunityDetailModel *model=self.recommendListArray[indexPath.section];
  189. if (model.texts.length ==0) {
  190. return FITSIZE(155);
  191. }
  192. return FITSIZE(270);
  193. }
  194. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  195. LDCommunityDetailModel *model=self.recommendListArray[indexPath.section];
  196. [self otherOPByModel:model isTop:NO];
  197. [MobClick event:FaddishNormalItemClick];
  198. }
  199. #pragma mark -代理 PhotoContainerViewDelegate
  200. - (void)otherOPByModel:(LDCommunityDetailModel *)model isTop:(BOOL)isTop{
  201. LDEventModel *eventModel;
  202. if (isTop) {
  203. eventModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:TodayFaddishTopAction];
  204. }else {
  205. eventModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:TodayFaddishAction];
  206. }
  207. LDGoodDetailViewController *detailVC = [[LDGoodDetailViewController alloc] init];
  208. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithCommunityDetailModel:model];
  209. detailVC.requestModel = requestModel;
  210. detailVC.eventModel = eventModel;
  211. [self.navigationController pushViewController:detailVC animated:YES];
  212. [MobClick event:ComunityGoodClick label:@"今日爆款"];
  213. }
  214. - (void)showShareView:(LDCommunityDetailModel *)model {
  215. LDGoodDetailModel *detailModel = [[LDGoodDetailModel alloc] init];
  216. [detailModel changeDetailModelWithComunityModel:model];
  217. LDShareImgPopView *shareView = [[LDShareImgPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) goodModel:detailModel];
  218. CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:shareView backgroundDismissEnable:YES];
  219. shareView.closeAction = ^{
  220. [showView dismiss];
  221. };
  222. shareView.shareResult = ^(id result, NSError *error) {
  223. if (!error) {
  224. [self shareSuccManagerWithModel:model];
  225. }else {
  226. [MBProgressHUD showMessage:@"分享失败"];
  227. }
  228. };
  229. showView.backgroundView.backgroundColor = [UIColor clearColor];
  230. [showView show];
  231. }
  232. - (void)shareSuccManagerWithModel:(LDCommunityDetailModel *)model {
  233. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/shareCount",BaseURL];
  234. NSDictionary *para = @{@"goods_id":model.goods_id};
  235. [LDHttp post:url params:para success:^(id json) {
  236. [MBProgressHUD showMessage:@"分享成功"];
  237. } failure:^(NSError *error) {
  238. }];
  239. }
  240. #pragma mark -代理 YHCommunityDelegate
  241. -(void)oneTouchShareWithModel:(LDCommunityModel *)model{
  242. // NSArray *arr=model.detail;
  243. [MobClick event:OneKeyShareRecommend label:@"优选商品"];
  244. if([AccountTool isLogin]){
  245. // UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  246. // pasteboard.string=model.note;
  247. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/oneKeySharing",BaseURL];
  248. NSDictionary *dic=@{@"id":model.Id};
  249. [SVProgressHUD showWithStatus:@"生成分享中"];
  250. [LDHttp post:url params:dic success:^(id json) {
  251. NSArray *arr=[NSArray yy_modelArrayWithClass:[LDCommunityDetailModel class] json:json[@"data"]];
  252. NSDictionary *userInfo = json[@"userinfo"];
  253. if (arr.count>0) {
  254. __block NSInteger count=0;
  255. NSMutableArray *imgArr=[NSMutableArray array];
  256. __block NSInteger max=(arr.count<9?arr.count:9);
  257. // self.backgroudView.hidden=NO;
  258. for (int i=0;i<max;i++) {
  259. LDCommunityDetailModel *model=arr[i];
  260. NSLog(@"model.img--%@",model.img);
  261. LDShareGoodsModel *goodsModel=[[LDShareGoodsModel alloc]init];
  262. goodsModel.mainImageUrl=model.img;
  263. goodsModel.commission_price = model.commission_price;
  264. if([model.shop_type integerValue]==0){
  265. goodsModel.shareGoodsFromType=YHShareGoodsFromTypeTaoBao;
  266. }else if([model.shop_type integerValue]==1){
  267. goodsModel.shareGoodsFromType=YHShareGoodsFromTypeTianMao;
  268. }else{
  269. goodsModel.shareGoodsFromType=YHShareGoodsFromTypeOriginal;
  270. }
  271. goodsModel.title=model.title;
  272. goodsModel.ticketAfterPrice=model.discount_price;
  273. goodsModel.ticketPrice=model.coupon_price;
  274. goodsModel.originalPrice=model.price;
  275. goodsModel.QRcodeImageUrl=model.url;
  276. if ([model.is_coupon integerValue]==0) {//进入折扣
  277. goodsModel.shareGoodsPurchaseType=YHShareGoodsPurchaseTypePrice;
  278. }
  279. LDShareGoodsView *view1=[[LDShareGoodsView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];
  280. __weak __typeof(view1) weakView1 = view1;
  281. view1.imgSuccBlock = ^{
  282. count++;
  283. [imgArr addObject: [weakView1 changeToImage]];
  284. if (count==max) {
  285. count=0;
  286. [SVProgressHUD dismiss];
  287. // self.backgroudView.hidden=YES;
  288. UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:imgArr applicationActivities:nil];
  289. activityVC.modalPresentationStyle = UIModalPresentationFullScreen;
  290. [self presentViewController:activityVC animated:YES completion:nil];
  291. }
  292. };
  293. view1.model=goodsModel;
  294. view1.userInfo = userInfo;
  295. }
  296. }else{
  297. [SVProgressHUD dismiss];
  298. [MBProgressHUD showMessage:@"没有商品可以分享"];
  299. }
  300. } failure:^(NSError *error) {
  301. [SVProgressHUD dismiss];
  302. [MBProgressHUD showMessage:@"加载失败,请稍后再试"];
  303. }];
  304. }else{
  305. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  306. login.loginSucc = ^{
  307. [self requestData];
  308. };
  309. login.modalPresentationStyle = UIModalPresentationFullScreen;
  310. [self.navigationController presentViewController:login animated:YES completion:nil];
  311. }
  312. }
  313. #pragma mark ------- layzer ---------
  314. -(UICollectionView *)collections
  315. {
  316. if (!_collections) {
  317. CGRect collectionViewFrame= CGRectMake(0, FITSIZE(10), [UIScreen mainScreen].bounds.size.width-FITSIZE(20), FITSIZE(182));
  318. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  319. // 设置UICollectionView为横向滚动
  320. flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  321. // 每一行cell之间的间距
  322. flowLayout.minimumLineSpacing = FITSIZE(10);
  323. // 每一列cell之间的间距
  324. // flowLayout.minimumInteritemSpacing = 10;
  325. // 设置第一个cell和最后一个cell,与父控件之间的间距
  326. flowLayout.sectionInset = UIEdgeInsetsMake(FITSIZE(40), FITSIZE(10), 0, FITSIZE(10));
  327. flowLayout.itemSize = CGSizeMake(FITSIZE(106), FITSIZE(140));// 该行代码就算不写,item也会有默认尺寸
  328. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:flowLayout];
  329. collectionView.backgroundColor = [UIColor whiteColor];
  330. collectionView.dataSource = self;
  331. collectionView.delegate = self;
  332. _collections = collectionView;
  333. _collections.showsVerticalScrollIndicator=NO;
  334. _collections.showsHorizontalScrollIndicator=NO;
  335. self.collections.hidden=YES;
  336. _collections.layer.cornerRadius=5;
  337. _collections.layer.masksToBounds=YES;
  338. [self.collections registerClass:[LDCommunityShareCell class] forCellWithReuseIdentifier:@"cellId"];
  339. }
  340. return _collections;
  341. }
  342. - (UITableView *)tableView {
  343. if (!_tableView) {
  344. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(FITSIZE(10), 0, SCREEN_WIDTH-FITSIZE(20), ChildTableViewHeight+40) style:UITableViewStyleGrouped];
  345. _tableView.estimatedSectionHeaderHeight = 0;
  346. _tableView.estimatedSectionFooterHeight = 0;
  347. _tableView.sectionFooterHeight = 0;
  348. _tableView.sectionHeaderHeight = 0;
  349. _tableView.estimatedRowHeight = 0;
  350. _tableView.delegate = self;
  351. _tableView.dataSource = self;
  352. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  353. _tableView.backgroundColor = [UIColor clearColor];
  354. _tableView.bounces = YES;
  355. _tableView.showsVerticalScrollIndicator = NO;
  356. _tableView.separatorColor = [UIColor lineColor];
  357. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  358. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  359. self.page = 1;
  360. [_tableView.mj_footer resetNoMoreData];
  361. [self requestData];
  362. }];
  363. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  364. _page++;
  365. [self requestData];
  366. }];
  367. _tableView.mj_footer = footer;
  368. [_tableView.mj_header beginRefreshing];
  369. }
  370. return _tableView;
  371. }
  372. #pragma mark-添加区头
  373. -(void)addTableViewHeader
  374. {
  375. UIView *bakck =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-FITSIZE(20), FITSIZE(200))];
  376. [bakck addSubview:self.collections];
  377. UIImageView *imgV =[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(10), FITSIZE(20), FITSIZE(20), FITSIZE(20))];
  378. imgV.image=[UIImage imageNamed:@"paihang"];
  379. [bakck addSubview:imgV];
  380. self.collections.hidden=NO;
  381. UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(40), FITSIZE(10), FITSIZE(85), FITSIZE(40))];
  382. label.text=@"分享排行榜";
  383. label.textColor=[UIColor homeRedColor];
  384. [bakck addSubview:label];
  385. label.font =[UIFont systemFontOfSize:FITSIZE(15)];
  386. UILabel *tiplabel =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(130), FITSIZE(10), FITSIZE(120), FITSIZE(40))];
  387. tiplabel.text=@"那些值得分享的好物";
  388. tiplabel.textColor=[UIColor YHColorWithHex:0x9B9B9B];
  389. [bakck addSubview:tiplabel];
  390. tiplabel.font =[UIFont systemFontOfSize:FITSIZE(13)];
  391. self.tableView.tableHeaderView =bakck;
  392. }
  393. - (NSMutableArray *)dataArr {
  394. if (!_dataArr) {
  395. _dataArr = [NSMutableArray array];
  396. }
  397. return _dataArr;
  398. }
  399. -(NSMutableArray *)recommendListArray
  400. {
  401. if (!_recommendListArray) {
  402. _recommendListArray =[NSMutableArray array];
  403. }
  404. return _recommendListArray;
  405. }
  406. //-(UIView *)backgroudView{
  407. // if (!_backgroudView) {
  408. // _backgroudView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  409. // _backgroudView.backgroundColor=[[UIColor grayColor] colorWithAlphaComponent:0.2];
  410. // _backgroudView.hidden=YES;
  411. // }
  412. // return _backgroudView;
  413. //}
  414. @end