猎豆优选

LDMessageListController.m 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. //
  2. // LDMessageListController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDMessageListController.h"
  9. #import "LDMessageListCell.h"
  10. #import "LDMessageModel.h"
  11. #import "LDCommissionMainViewController.h"
  12. #import "LDMyFansViewController.h"
  13. #import "LDCollectionMainViewController.h"
  14. #import "LDChildAccountViewController.h"
  15. #import "LDGoodListViewController.h"
  16. #import "LDAdWebViewController.h"
  17. #import "LDAchievementViewController.h"
  18. #import "LDGoodListViewController.h"
  19. @interface LDMessageListController ()<UITableViewDelegate, UITableViewDataSource>
  20. {
  21. NSInteger _page;
  22. UIButton *rightBtn;
  23. }
  24. @property (nonatomic, strong) UITableView *tableView;
  25. @property (nonatomic, strong) NSMutableArray *dataArr;
  26. @property(nonatomic,strong)UIView *notiView;
  27. @end
  28. @implementation LDMessageListController
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. //监听,是否开启通知
  32. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isshowOpenNot) name:@"setMessage" object:nil];
  33. [self configNavigationBar];
  34. [self configTableView];
  35. [self requestData];
  36. }
  37. -(void)isshowOpenNot
  38. {
  39. if (![self isUserNotificationEnable]) {//是否开启通知
  40. self.notiView.hidden=NO;
  41. self.tableView.frame=CGRectMake(0, NavBarHeight+FITSIZE(50), SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-FITSIZE(50));
  42. }else{
  43. self.notiView.hidden=YES;
  44. self.tableView.frame=CGRectMake(0, NavBarHeight+FITSIZE(10), SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-FITSIZE(10));
  45. }
  46. }
  47. -(void)viewWillAppear:(BOOL)animated{
  48. [super viewWillAppear:animated];
  49. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  50. [self isshowOpenNot];
  51. }
  52. -(void)dealloc
  53. {
  54. [[NSNotificationCenter defaultCenter] removeObserver:self];
  55. }
  56. -(void)viewDidDisappear:(BOOL)animated{
  57. [super viewDidDisappear:animated];
  58. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  59. [LoadingView dismiss];
  60. }
  61. - (void)configTableView {
  62. _page = 1;
  63. [self.view addSubview:self.tableView];
  64. [self.view addSubview:self.notiView];
  65. [LoadingView show];
  66. }
  67. //判断是否开启通知
  68. - (BOOL)isUserNotificationEnable { // 判断用户是否允许接收通知
  69. BOOL isEnable = NO;
  70. if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0f) { // iOS版本 >=8.0 处理逻辑
  71. UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
  72. isEnable = (UIUserNotificationTypeNone == setting.types) ? NO : YES;
  73. } else { // iOS版本 <8.0 处理逻辑
  74. UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
  75. isEnable = (UIRemoteNotificationTypeNone == type) ? NO : YES;
  76. }
  77. return isEnable;
  78. }
  79. // 如果用户关闭了接收通知功能,该方法可以跳转到APP设置页面进行修改 iOS版本 >=8.0 处理逻辑
  80. - (void)goToAppSystemSetting {
  81. UIApplication *application = [UIApplication sharedApplication];
  82. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  83. if ([application canOpenURL:url]) {
  84. if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
  85. if (@available(iOS 10.0, *)) {
  86. [application openURL:url options:@{} completionHandler:nil];
  87. } else {
  88. // Fallback on earlier versions
  89. }
  90. } else {
  91. [application openURL:url];
  92. }
  93. }
  94. }
  95. - (void)configNavigationBar {
  96. [self.navigationBar setNavTitle:@"我的消息"];
  97. self.navigationBar.backgroundColor = [UIColor changeColor];
  98. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  99. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  100. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  101. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  102. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  103. rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  104. [rightBtn setImage:[UIImage imageNamed:@"clear_message"] forState:UIControlStateNormal];
  105. [rightBtn addTarget:self action:@selector(clearAction) forControlEvents:UIControlEventTouchUpInside];
  106. }
  107. #pragma mark-一键已读功能
  108. -(void)clearAction
  109. {
  110. NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/allMessageRead",BaseURL];
  111. [LDHttp post:url params:nil success:^(id json) {
  112. if ([json[@"flag"]intValue] == 1) {
  113. for (LDMessageModel *model in self.dataArr) {
  114. model.is_view = @"1";
  115. }
  116. [SVProgressHUD showSuccessWithStatus:@"全部已读"];
  117. [self.tableView reloadData];
  118. }
  119. } failure:^(NSError *error) {
  120. }];
  121. }
  122. - (void)backAction {
  123. [LoadingView dismiss];
  124. [self.navigationController popViewControllerAnimated:YES];
  125. }
  126. - (void)requestData {
  127. NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/MessagePushList",BaseURL];
  128. [LDHttp post:url params:@{@"page":@(_page)} success:^(id json) {
  129. NSArray *list = [NSArray yy_modelArrayWithClass:[LDMessageModel class] json:json[@"data"]];
  130. if (list.count>0) {
  131. [self.dataArr addObjectsFromArray:list];
  132. [self.tableView.mj_footer endRefreshing];
  133. [self.navigationBar setCustomRightButtons:@[rightBtn]];
  134. }else {
  135. if (_page==1) {
  136. [self setUpNoDataView];
  137. [self.navigationBar setCustomRightButtons:@[]];
  138. }
  139. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  140. }
  141. [LoadingView dismiss];
  142. [self.tableView reloadData];
  143. } failure:^(NSError *error) {
  144. [self.tableView.mj_footer endRefreshing];
  145. [LoadingView dismiss];
  146. }];
  147. }
  148. - (void)setUpNoDataView {
  149. self.tableView.showNoDataView = YES;
  150. self.tableView.defaultNoDataText = @"您还没有任何记录";
  151. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  152. }
  153. #pragma mark -------- UITableView Delegate -----
  154. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  155. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  156. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
  157. }
  158. }
  159. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  160. return self.dataArr.count;
  161. }
  162. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  163. return 120;
  164. }
  165. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  166. return .1;
  167. }
  168. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  169. return 0.1;
  170. }
  171. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  172. LDMessageModel *model = self.dataArr[indexPath.row];
  173. LDMessageListCell *cell = [LDMessageListCell cellWithTableView:tableView];
  174. cell.model = model;
  175. return cell;
  176. }
  177. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  178. LDMessageModel *model = self.dataArr[indexPath.row];
  179. NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/MessageClick",BaseURL];
  180. NSDictionary *dict = @{
  181. @"message_id":model.Id,
  182. @"person_group":model.person_group,
  183. @"is_view":model.is_view
  184. };
  185. [LDHttp post:url params:dict success:^(id json) {
  186. LDMessageListCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  187. [cell isRead];
  188. } failure:^(NSError *error) {
  189. }];
  190. switch ([model.message_type integerValue]) {
  191. case 1:
  192. [self gotoMyFans]; //我的粉丝
  193. break;
  194. case 2:
  195. [self gotoGoodDetailPage:model]; //商品详情或列表
  196. break;
  197. case 3:
  198. [self gotoUpdateApp]; //更新app
  199. break;
  200. case 4:
  201. [self gotoMyOrderPage]; // 我的订单
  202. break;
  203. case 5:
  204. [self gotoBackMoneyPage]; //提现完成
  205. break;
  206. case 6:
  207. [self gotoMyCollectionPage]; //我的收藏
  208. break;
  209. case 7:
  210. [self openWebPage:model]; //h5
  211. break;
  212. case 8:
  213. [self gotoMyIncome]; //我的收益
  214. break;
  215. case 9:
  216. [self gotoGoodList:model]; //商品列表
  217. break;
  218. default:
  219. break;
  220. }
  221. }
  222. /**
  223. 打开H5
  224. */
  225. - (void)openWebPage:(LDMessageModel *)model {
  226. LDAdWebViewController *web = [[LDAdWebViewController alloc] init];
  227. web.url = model.url;
  228. [self.navigationController pushViewController:web animated:YES];
  229. }
  230. /**
  231. 我的收益
  232. */
  233. - (void)gotoMyIncome {
  234. LDAchievementViewController *detail = [[LDAchievementViewController alloc] init];
  235. [self.navigationController pushViewController:detail animated:YES];
  236. }
  237. - (void)gotoGoodList:(LDMessageModel *)model {
  238. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  239. list.cate_id = model.gid;
  240. list.name = model.name;
  241. list.topRequest = 2;
  242. [self.navigationController pushViewController:list animated:YES];
  243. }
  244. /**
  245. 去我的粉丝
  246. */
  247. - (void)gotoMyFans {
  248. LDMyFansViewController *myFans = [[LDMyFansViewController alloc] init];
  249. [self.navigationController pushViewController:myFans animated:YES];
  250. }
  251. /**
  252. 打开详情页
  253. */
  254. - (void)gotoGoodDetailPage:(LDMessageModel *)model {
  255. if ([model.goods_or_group isEqualToString:@"1"]) {
  256. LDGoodDetailViewController *goodDetail = [[LDGoodDetailViewController alloc] init];
  257. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id
  258. is_coupon:model.is_coupon
  259. coupon_price:model.coupon_price
  260. price:model.price
  261. discount_price:model.discount_price
  262. commission_rate:model.commission_rate
  263. coupon_start_time:model.coupon_start_time
  264. coupon_end_time:model.coupon_end_time
  265. coupon_id:model.coupon_id];
  266. goodDetail.requestModel = requestModel;
  267. [self.navigationController pushViewController:goodDetail animated:YES];
  268. }else {
  269. //列表页
  270. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  271. list.cate_id = model.group_id;
  272. list.topRequest = 2;
  273. [self.navigationController pushViewController:list animated:YES];
  274. }
  275. }
  276. /**
  277. 版本更新
  278. */
  279. - (void)gotoUpdateApp {
  280. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:APP_STORE_URL]];
  281. }
  282. /**
  283. 我的订单
  284. */
  285. - (void)gotoMyOrderPage {
  286. LDCommissionMainViewController *orderMain = [[LDCommissionMainViewController alloc] init];
  287. [self.navigationController pushViewController:orderMain animated:YES];
  288. }
  289. /**
  290. 提现完成
  291. */
  292. - (void)gotoBackMoneyPage {
  293. LDChildAccountViewController *account = [[LDChildAccountViewController alloc] init];
  294. [self.navigationController pushViewController:account animated:YES];
  295. }
  296. /**
  297. 我的收藏
  298. */
  299. - (void)gotoMyCollectionPage {
  300. LDCollectionMainViewController *collection = [[LDCollectionMainViewController alloc] init];
  301. [self.navigationController pushViewController:collection animated:YES];
  302. }
  303. #pragma mark---开启通知
  304. -(void)opentNotiClickBtn
  305. {
  306. [self goToAppSystemSetting];
  307. }
  308. #pragma mark ------- layzer ------
  309. - (UITableView *)tableView {
  310. if (!_tableView) {
  311. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStyleGrouped];
  312. _tableView.estimatedSectionHeaderHeight = 0;
  313. _tableView.estimatedSectionFooterHeight = 0;
  314. _tableView.sectionFooterHeight = 0;
  315. _tableView.sectionHeaderHeight = 0;
  316. _tableView.estimatedRowHeight = 0;
  317. _tableView.delegate = self;
  318. _tableView.dataSource = self;
  319. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  320. _tableView.backgroundColor = [UIColor yhGrayColor];
  321. _tableView.showsVerticalScrollIndicator = NO;
  322. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  323. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  324. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  325. _page ++;
  326. [self requestData];
  327. }];
  328. }
  329. return _tableView;
  330. }
  331. -(UIView *)notiView
  332. {
  333. if (!_notiView) {
  334. _notiView =[[UIView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, FITSIZE(50))];
  335. _notiView.backgroundColor=[UIColor backgroudColor];
  336. UIButton *accountBtn =[[UIButton alloc]initWithFrame:CGRectMake(0, FITSIZE(10), SCREEN_WIDTH, FITSIZE(30))];
  337. accountBtn.backgroundColor =[UIColor whiteColor];
  338. [self.notiView addSubview:accountBtn];
  339. UIButton *openbtn =[[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-FITSIZE(56), FITSIZE(6.5), FITSIZE(40), FITSIZE(17))];
  340. [openbtn setTitle:@"开启" forState:UIControlStateNormal];
  341. [openbtn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal];
  342. openbtn.titleLabel.font =[UIFont systemFontOfSize:FITSIZE(9)];
  343. openbtn.layer.cornerRadius=FITSIZE(8.5);
  344. openbtn.layer.masksToBounds=YES;
  345. openbtn.layer.borderColor =[UIColor homeRedColor].CGColor;
  346. openbtn.layer.borderWidth=0.5;
  347. [openbtn addTarget:self action:@selector(opentNotiClickBtn) forControlEvents:UIControlEventTouchUpInside];
  348. [accountBtn addSubview:openbtn];
  349. UIImageView *imgv =[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(15), FITSIZE(7.5), FITSIZE(15), FITSIZE(15))];
  350. imgv.image =[UIImage imageNamed:@"order_notice"];
  351. [accountBtn addSubview:imgv];
  352. UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(40), 0, FITSIZE(300), FITSIZE(30))];
  353. label.text=@"您还未开启消息通知,开启获取最新通知";
  354. label.textColor=[UIColor YHColorWithHex:0xFB6526];
  355. label.font=[UIFont systemFontOfSize:FITSIZE(12)];
  356. [accountBtn addSubview:label];
  357. label.tag = 1234;
  358. }
  359. return _notiView;
  360. }
  361. - (NSMutableArray *)dataArr {
  362. if (!_dataArr) {
  363. _dataArr = [NSMutableArray array];
  364. }
  365. return _dataArr;
  366. }
  367. - (void)didReceiveMemoryWarning {
  368. [super didReceiveMemoryWarning];
  369. // Dispose of any resources that can be recreated.
  370. }
  371. /*
  372. #pragma mark - Navigation
  373. // In a storyboard-based application, you will often want to do a little preparation before navigation
  374. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  375. // Get the new view controller using [segue destinationViewController].
  376. // Pass the selected object to the new view controller.
  377. }
  378. */
  379. @end