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

DRMessageListController.m 14KB

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