《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRCommunityRightController.m 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. //
  2. // DRCommunityLeftController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRCommunityRightController.h"
  9. #import "DRCommunityCell.h"
  10. #import "UITableView+SDAutoTableViewCellHeight.h"
  11. #import "DRCommunityModel.h"
  12. #import "DRCommunityDetailModel.h"
  13. #import "DRShareGetFriendsModel.h"
  14. #import "DRShareGetFriendsView.h"
  15. #import "DRLoginViewController.h"
  16. #import "DRCommunityRightCell.h"
  17. #import "DRCommunityRightModel.h"
  18. #import "DRGoodDetailViewController.h"
  19. #import "shareView.h"
  20. #import "DRShareGoodsTempModel.h"
  21. #import "DRShareGoodsModel.h"
  22. #import <SDWebImageDownloader.h>
  23. #import "DRPopShareGoodView.h"
  24. #import "DRShareManager.h"
  25. #import "HYUMShareManager.h"
  26. #import "WXApi.h"
  27. #import "DRShareImgPopView.h"
  28. #import "CCAlertShowView.h"
  29. #import "DRGoodDetailModel.h"
  30. @interface DRCommunityRightController ()
  31. <
  32. UITableViewDelegate,
  33. UITableViewDataSource,
  34. YHCommunityDelegate
  35. >
  36. {
  37. __block BOOL _imgSuccFlag;
  38. }
  39. @property (nonatomic, strong) UITableView *tableView;
  40. @property (nonatomic, strong) NSMutableArray *dataArr;
  41. @property (nonatomic ) NSInteger page;
  42. @property(nonatomic,strong)UIView *backShareView;
  43. @property (nonatomic,strong ) UIView *backgroudView;
  44. @property(nonatomic,strong) shareView *shareView;
  45. @property(nonatomic,strong)DRShareGoodsModel *model;
  46. @property (nonatomic, strong) DRPopShareGoodView *shareGoodView;
  47. @property (nonatomic, assign) BOOL imgSuccFlag;
  48. @property (nonatomic, strong) DRCommunityRightModel *rightModel;
  49. @end
  50. @implementation DRCommunityRightController
  51. - (void)viewDidLoad {
  52. [super viewDidLoad];
  53. self.page=1;
  54. [self configTableView];
  55. }
  56. - (void)configTableView {
  57. self.view.backgroundColor = [UIColor yhGrayColor];
  58. [self.view addSubview:self.tableView];
  59. [[UIApplication sharedApplication].keyWindow addSubview:self.backgroudView];
  60. [[UIApplication sharedApplication].keyWindow addSubview:self.backShareView];
  61. [[UIApplication sharedApplication].keyWindow addSubview:self.shareView];
  62. }
  63. - (void)requestData {
  64. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/editorRecommendation",BaseURL];
  65. NSDictionary *dic=@{
  66. @"page":@(self.page)
  67. };
  68. [DRHttp post:url params:dic success:^(id json) {
  69. if ([self.tableView.mj_header isRefreshing]) {
  70. [self.dataArr removeAllObjects];
  71. }
  72. NSArray *arr=[NSArray yy_modelArrayWithClass:[DRCommunityRightModel class] json:json[@"data"]];
  73. [self setNoDataView:arr];
  74. [self.dataArr addObjectsFromArray:arr];
  75. [self.tableView reloadData];
  76. } failure:^(NSError *error) {
  77. [self.tableView.mj_header endRefreshing];
  78. [self.tableView.mj_footer endRefreshing];
  79. }];
  80. }
  81. - (void)setNoDataView:(NSArray *)array {
  82. if (array.count > 0) {
  83. [self.tableView.mj_header endRefreshing];
  84. [self.tableView.mj_footer endRefreshing];
  85. }else {
  86. [self.tableView.mj_header endRefreshing];
  87. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  88. }
  89. self.tableView.showNoDataView = YES;
  90. self.tableView.defaultNoDataText = @"暂无数据";
  91. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  92. }
  93. #pragma mark ============ UITableView Delegate && DataSource ==========
  94. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  95. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  96. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  97. }
  98. }
  99. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  100. return 0.1;
  101. }
  102. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  103. return self.dataArr.count;
  104. }
  105. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  106. DRCommunityRightModel *model = self.dataArr[indexPath.row];
  107. DRCommunityRightCell *cell = [DRCommunityRightCell cellWithTableView:tableView];
  108. cell.model = model;
  109. cell.shareClick = ^{
  110. // [self loadShareData:model];
  111. [self showShareView:model];
  112. };
  113. return cell;
  114. }
  115. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  116. // return [self cellHeightForIndexPath:indexPath cellContentViewWidth:SCREEN_WIDTH tableView:tableView];
  117. return Fitsize(177);
  118. }
  119. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  120. DRCommunityRightModel *model = self.dataArr[indexPath.row];
  121. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id is_coupon:model.is_coupon coupon_price:model.coupon_price price:model.price discount_price:model.discount_price commission_rate:model.commission_rate coupon_start_time:model.start_time coupon_end_time:model.end_time];
  122. DRGoodDetailViewController *detail = [[DRGoodDetailViewController alloc] init];
  123. detail.requestModel = requestModel;
  124. [self.navigationController pushViewController:detail animated:YES];
  125. [MobClick event:ComunityGoodClick label:@"小编推荐"];
  126. }
  127. - (void)showShareView:(DRCommunityRightModel *)model {
  128. self.rightModel = model;
  129. DRGoodDetailModel *detailModel = [[DRGoodDetailModel alloc] init];
  130. [detailModel changeDetailModelWithComunityRightModel:model];
  131. DRShareImgPopView *shareView = [[DRShareImgPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) goodModel:detailModel];
  132. CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:shareView backgroundDismissEnable:YES];
  133. shareView.closeAction = ^{
  134. [showView dismiss];
  135. };
  136. shareView.shareResult = ^(id result, NSError *error) {
  137. if (!error) {
  138. [self shareSuccManager];
  139. }else {
  140. [MBProgressHUD showMessage:@"分享失败"];
  141. }
  142. };
  143. showView.backgroundView.backgroundColor = [UIColor clearColor];
  144. [showView show];
  145. }
  146. //- (void)loadShareData:(DRCommunityRightModel *)model {
  147. //
  148. // self.rightModel = model;
  149. //
  150. // NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/shareCommonGoods",BaseURL];
  151. // NSString *coupon_start_time = [model.is_coupon boolValue] ? model.start_time : @"";
  152. // NSString *coupon_end_time = [model.is_coupon boolValue] ? model.end_time : @"";
  153. // if (!coupon_start_time) coupon_start_time = @"";
  154. // if (!coupon_end_time) coupon_end_time = @"";
  155. // NSDictionary *dic=@{
  156. // @"goods_id":model.goods_id,
  157. // @"is_coupon":model.is_coupon,
  158. // @"coupon_price":model.coupon_price,
  159. // @"price":model.price,
  160. // @"discount_price":model.discount_price,
  161. // @"commission_rate":model.commission_rate,
  162. // @"coupon_end_time":coupon_end_time,
  163. // @"coupon_start_time":coupon_start_time
  164. // };
  165. //
  166. // [DRHttp post:url params:dic success:^(id json) {
  167. // DRShareGoodsTempModel *tmpModel=[DRShareGoodsTempModel yy_modelWithJSON:json[@"data"]];
  168. // DRShareGoodsModel *shreModel = [DRShareGoodsModel createShareGoodsModelByShareGoodsTempModel:tmpModel];
  169. // shreModel.commissionPrice = model.commission_price;//佣金价格
  170. // shreModel.commission_rate = model.commission_rate;
  171. // shreModel.discount_price = model.discount_price;
  172. // shreModel.userinfo = tmpModel.userinfo;
  173. //
  174. // DRPopShareGoodView *shareGoodView = [[DRPopShareGoodView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, Fitsize(254), Fitsize(455))];
  175. // self.shareGoodView = shareGoodView;
  176. // shareGoodView.backgroundColor = [UIColor whiteColor];
  177. // shareGoodView.imgSuccBlock = ^{
  178. // _imgSuccFlag = YES;
  179. // };
  180. // shareGoodView.model = shreModel;
  181. // [self.view addSubview:shareGoodView];
  182. //
  183. // } failure:^(NSError *error) {
  184. //
  185. // }];
  186. //
  187. // //分享图片
  188. // self.backShareView.hidden = NO;
  189. // [UIView animateWithDuration:0.2f animations:^{
  190. // self.shareView.frame=CGRectMake(0, SCREEN_HEIGHT-200-SafeBottomHeight, SCREEN_WIDTH, 200+SafeBottomHeight);
  191. // }];
  192. //
  193. //}
  194. #pragma mark -代理 YHCommunityDelegate
  195. //-(void)oneTouchShareWithModel:(DRCommunityModel *)model{
  196. //// NSArray *arr=model.detail;
  197. //// /api/v2/adzoneCreate/secretOneSharing
  198. // [MobClick event:OneKeyShareCheats label:@"优选素材"];
  199. // if([AccountTool isLogin]){
  200. // UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  201. // pasteboard.string=model.note;
  202. // NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/secretOneSharing",BaseURL];
  203. // NSDictionary *dic=@{@"id":model.Id};
  204. // [DRHttp post:url params:dic success:^(id json) {
  205. // NSArray *arr=[NSArray yy_modelArrayWithClass:[DRCommunityDetailModel class] json:json[@"data"]];
  206. // NSDictionary *userinfo = json[@"userinfo"];
  207. // if (arr.count>0) {
  208. // __block NSInteger count=0;
  209. // NSMutableArray *imgArr=[NSMutableArray array];
  210. // __block NSInteger max=(arr.count<9?arr.count:9);
  211. // self.backgroudView.hidden=NO;
  212. // [SVProgressHUD showWithStatus:@"生成分享中"];
  213. // for (int i=0;i<max;i++) {
  214. // DRCommunityDetailModel *model=arr[i];
  215. // DRShareGetFriendsModel *friendModel=[[DRShareGetFriendsModel alloc]init];
  216. // friendModel.getFriendCode=@"";
  217. // friendModel.QRcodeUrl=model.url;
  218. // friendModel.imgUrl=model.img;
  219. // DRShareGetFriendsView *view1=[[DRShareGetFriendsView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  220. // view1.model=friendModel;
  221. // view1.userinfo = userinfo;
  222. // __weak __typeof(view1) weakView1 = view1;
  223. // view1.imgSuccBlock = ^{
  224. // count++;
  225. // [imgArr addObject: [weakView1 changeToImage]];
  226. // if (count==max) {
  227. // count=0;
  228. // [SVProgressHUD dismiss];
  229. // self.backgroudView.hidden=YES;
  230. // UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:imgArr applicationActivities:nil];
  231. // [self presentViewController:activityVC animated:YES completion:nil];
  232. // }
  233. // };
  234. //
  235. // }
  236. // }else{
  237. //
  238. // [SVProgressHUD dismiss];
  239. // [MBProgressHUD showMessage:@"没有商品可以分享"];
  240. // }
  241. // } failure:^(NSError *error) {
  242. //
  243. // }];
  244. //
  245. //
  246. //
  247. //
  248. // }else{
  249. // DRLoginViewController *login = [[DRLoginViewController alloc] init];
  250. // login.loginSucc = ^{
  251. // self.page=0;
  252. // [self requestData];
  253. // };
  254. // [self.navigationController presentViewController:login animated:YES completion:nil];
  255. // }
  256. //}
  257. - (void)shareSuccManager {
  258. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/shareCount",BaseURL];
  259. NSDictionary *para = @{@"goods_id":self.rightModel.goods_id};
  260. [DRHttp post:url params:para success:^(id json) {
  261. [MBProgressHUD showMessage:@"分享成功"];
  262. } failure:^(NSError *error) {
  263. }];
  264. }
  265. -(void)doTapChange{
  266. self.backShareView.hidden=YES;
  267. [UIView animateWithDuration:0.2f animations:^{
  268. self.shareView.frame=CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 200+SafeBottomHeight);
  269. } completion:^(BOOL finished) {
  270. }];
  271. }
  272. #pragma mark ------- layzer ---------
  273. - (UITableView *)tableView {
  274. if (!_tableView) {
  275. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 1, SCREEN_WIDTH, ChildTableViewHeight) style:UITableViewStyleGrouped];
  276. _tableView.estimatedSectionHeaderHeight = 0;
  277. _tableView.estimatedSectionFooterHeight = 0;
  278. _tableView.sectionFooterHeight = 0;
  279. _tableView.sectionHeaderHeight = 0;
  280. _tableView.estimatedRowHeight = 0;
  281. _tableView.delegate = self;
  282. _tableView.dataSource = self;
  283. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  284. _tableView.backgroundColor = [UIColor backgroudColor];
  285. _tableView.bounces = YES;
  286. _tableView.showsVerticalScrollIndicator = NO;
  287. _tableView.separatorColor = [UIColor lineColor];
  288. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  289. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  290. self.page = 1;
  291. [_tableView.mj_footer resetNoMoreData];
  292. [self requestData];
  293. }];
  294. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  295. _page++;
  296. [self requestData];
  297. }];
  298. _tableView.mj_footer = footer;
  299. [_tableView.mj_header beginRefreshing];
  300. }
  301. return _tableView;
  302. }
  303. - (NSMutableArray *)dataArr {
  304. if (!_dataArr) {
  305. _dataArr = [NSMutableArray array];
  306. }
  307. return _dataArr;
  308. }
  309. -(UIView *)backgroudView{
  310. if (!_backgroudView) {
  311. _backgroudView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  312. _backgroudView.backgroundColor=[[UIColor grayColor] colorWithAlphaComponent:0.2];
  313. _backgroudView.hidden=YES;
  314. }
  315. return _backgroudView;
  316. }
  317. -(UIView *)shareView{
  318. if (!_shareView) {
  319. _shareView=[[[NSBundle mainBundle] loadNibNamed:@"shareView" owner:self options:nil] lastObject];
  320. _shareView.frame=CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH,SCREEN_HEIGHT);
  321. [_shareView.cancelButton addTarget:self action:@selector(doTapChange) forControlEvents:UIControlEventTouchUpInside];
  322. WeakSelf(weakSelf)
  323. _shareView.shareToFriend = ^{
  324. if (weakSelf.imgSuccFlag) {
  325. [weakSelf doTapChange];
  326. _imgSuccFlag = NO;
  327. [DRShareManager shareImageWithplatformType:UMSocialPlatformType_WechatSession withImg:[weakSelf.shareGoodView changeToImage] complete:^(id result, NSError *error) {
  328. if (!error) {
  329. [weakSelf shareSuccManager];
  330. }else {
  331. [MBProgressHUD showMessage:@"分享失败"];
  332. }
  333. }];
  334. }else {
  335. [MBProgressHUD showMessage:@"海报生成中,请稍后再试"];
  336. }
  337. };
  338. _shareView.shareToSession = ^{
  339. if (weakSelf.imgSuccFlag) {
  340. [weakSelf doTapChange];
  341. _imgSuccFlag = NO;
  342. [DRShareManager shareImageWithplatformType:UMSocialPlatformType_WechatTimeLine withImg:[weakSelf.shareGoodView changeToImage] complete:^(id result, NSError *error) {
  343. if (!error) {
  344. [weakSelf shareSuccManager];
  345. }else {
  346. [MBProgressHUD showMessage:@"分享失败"];
  347. }
  348. }];
  349. }else {
  350. [MBProgressHUD showMessage:@"海报生成中,请稍后再试"];
  351. }
  352. };
  353. // _shareView.shareButtonTwoBlock=^(void){
  354. // __strong typeof(self) strongSelf=weakSelf;
  355. // [strongSelf doTapChange];
  356. // };
  357. // _shareView.shareButtonOneBlock=^(void){
  358. // __strong typeof(self) strongSelf=weakSelf;
  359. // [strongSelf doTapChange];
  360. // };
  361. }
  362. return _shareView;
  363. }
  364. -(UIView *)backShareView{
  365. if (!_backShareView) {
  366. _backShareView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  367. _backShareView.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.3f];
  368. _backShareView.hidden=YES;
  369. UITapGestureRecognizer *r5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doTapChange)];
  370. r5.numberOfTapsRequired = 1;
  371. [_backShareView addGestureRecognizer:r5];
  372. }
  373. return _backShareView;
  374. }
  375. @end