酷店

KDPNoticeViewController.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. //
  2. // KDPNoticeViewController.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/11.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPNoticeViewController.h"
  9. #import "KDPNoticeModel.h"
  10. #import "KDPMessageTableViewCell.h"
  11. #import "KDPForecastVC.h"
  12. #import "KDPAccountVC.h"
  13. @interface KDPNoticeViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
  14. @property (nonatomic, strong) UITableView *tableView;
  15. @property(nonatomic,strong)UIView *messageNoView;
  16. @property (nonatomic, strong) NSMutableArray *dataSource;
  17. @property (nonatomic, assign) NSInteger page;
  18. @property (nonatomic, strong) UIButton *clearBtn;
  19. @end
  20. @implementation KDPNoticeViewController
  21. -(void)viewWillAppear:(BOOL)animated
  22. {
  23. [super viewWillAppear:animated];
  24. self.tabBarController.tabBar.hidden=YES;
  25. }
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. // Do any additional setup after loading the view.
  29. [self setUpNav];
  30. [self.view addSubview:self.messageNoView];
  31. if (![self isOpenNotice]) {//是否开启通知
  32. self.messageNoView.hidden=NO;
  33. self.tableView.frame=CGRectMake(0, KDNavBarHeight+50, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight-50);
  34. }else{
  35. self.messageNoView.hidden=YES;
  36. self.tableView.frame=CGRectMake(0, KDNavBarHeight+10, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight-10);
  37. }
  38. self.view.backgroundColor = [UIColor colorWithHex:0xF2F2F2];
  39. [self.view addSubview:self.tableView];
  40. }
  41. - (void)setUpNav{
  42. self.navBar.navTitleLabel.text = @"我的消息";
  43. [self.navBar addleftReturnButton:self selector:@selector(backAction)];
  44. UIButton *clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  45. [clearBtn setImage:[UIImage imageNamed:@"clear_icon"] forState:UIControlStateNormal];
  46. clearBtn.frame = CGRectMake(SCREEN_WIDTH-17-16, KDNavBarHeight-16-17, 17, 17);
  47. [clearBtn addTarget:self action:@selector(clearAction) forControlEvents:UIControlEventTouchUpInside];
  48. clearBtn.hidden=YES;
  49. [self.navBar addSubview:clearBtn];
  50. self.clearBtn = clearBtn;
  51. }
  52. - (void)backAction{
  53. if (self.presentingViewController) {
  54. [self dismissViewControllerAnimated:YES completion:nil];
  55. } else{
  56. [self.navigationController popViewControllerAnimated:YES];
  57. }
  58. }
  59. - (void)clearAction{
  60. NSString *clearUrl = [NSString stringWithFormat:@"%@api/message_push/allMessageRead",KDURL];
  61. [KDPNetworkRequestHTTP postURL:clearUrl params:nil success:^(id _Nonnull json) {
  62. if ([json[@"flag"]intValue] == 1) {
  63. for (KDPNoticeModel *model in self.dataSource) {
  64. model.is_view = @"1";
  65. }
  66. [MBProgressHUD showMessage:@"全部已读"];
  67. [self.tableView reloadData];
  68. }
  69. } failure:^(NSError * _Nonnull error) {
  70. }];
  71. }
  72. - (void)requestMessageData{
  73. NSDictionary *params = @{@"page":@(self.page)};
  74. NSString *messageUrl = [NSString stringWithFormat:@"%@api/message_push/messagePushList",KDURL];
  75. [LoadingView show];
  76. [KDPNetworkRequestHTTP postURL:messageUrl params:params success:^(id _Nonnull json) {
  77. [LoadingView dismiss];
  78. NSArray *list = [NSArray yy_modelArrayWithClass:[KDPNoticeModel class] json:json[@"data"]];
  79. if (self.page == 1) {
  80. [self.dataSource removeAllObjects];
  81. }
  82. if (list.count>0) {
  83. [self.dataSource addObjectsFromArray:list];
  84. [self.tableView.mj_footer endRefreshing];
  85. [self.tableView.mj_header endRefreshing];
  86. }else {
  87. [self.tableView.mj_header endRefreshing];
  88. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  89. }
  90. self.clearBtn.hidden = self.dataSource.count ? NO : YES;
  91. [LoadingView dismiss];
  92. [self.tableView reloadData];
  93. } failure:^(NSError * _Nonnull error) {
  94. [LoadingView dismiss];
  95. [self.tableView.mj_header endRefreshing];
  96. [self.tableView.mj_footer endRefreshing];
  97. }];
  98. }
  99. - (UITableView *)tableView{
  100. if (!_tableView) {
  101. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, KDNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight) style:UITableViewStylePlain];
  102. _tableView.showsVerticalScrollIndicator = NO;
  103. _tableView.showsHorizontalScrollIndicator = NO;
  104. _tableView.rowHeight = 121;
  105. _tableView.emptyDataSetDelegate = self;
  106. _tableView.emptyDataSetSource = self;
  107. _tableView.delegate = self;
  108. _tableView.dataSource = self;
  109. _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
  110. _tableView.backgroundColor = [UIColor clearColor];
  111. _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
  112. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  113. [_tableView registerClass:[KDPMessageTableViewCell class] forCellReuseIdentifier:NSStringFromClass([KDPMessageTableViewCell class])];
  114. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  115. self.page = 1;
  116. [self requestMessageData];
  117. }];
  118. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  119. self.page ++;
  120. [self requestMessageData];
  121. }];
  122. [_tableView.mj_header beginRefreshing];
  123. }
  124. return _tableView;
  125. }
  126. - (NSMutableArray *)dataSource{
  127. if (!_dataSource) {
  128. _dataSource = [NSMutableArray array];
  129. }
  130. return _dataSource;
  131. }
  132. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  133. KDPMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPMessageTableViewCell class])];
  134. [cell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
  135. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  136. return cell;
  137. }
  138. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  139. return 1;
  140. }
  141. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  142. return self.dataSource.count;
  143. }
  144. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  145. return [UIImage imageNamed:@"no_order"];
  146. }
  147. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  148. return YES;
  149. }
  150. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  151. {
  152. KDPNoticeModel *model =self.dataSource[indexPath.row];
  153. [self messageisreadLoad:model];
  154. switch (model.message_type.integerValue) {
  155. case 2://商品详情
  156. [self goodDetailWithModel:model];
  157. break;
  158. case 3://版本更新
  159. [self updataArrrapp];
  160. break;
  161. case 4://收入结算
  162. [self ForecastVClist];
  163. break;
  164. case 5://提现通过
  165. [self myAccountList];
  166. break;
  167. default:
  168. break;
  169. }
  170. }
  171. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  172. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  173. }
  174. - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  175. return 30;
  176. }
  177. -(void)messageisreadLoad:(KDPNoticeModel *)model
  178. {
  179. [LoadingView show];
  180. [KDPNetworkRequestHTTP postURL:[NSString stringWithFormat:@"%@api/message_push/messageClick",KDURL] params:@{@"message_id":model.Id,@"person_group":model.person_group,@"is_view":model.is_view} success:^(id _Nonnull json) {
  181. [LoadingView dismiss];
  182. } failure:^(NSError * _Nonnull error) {
  183. [LoadingView dismiss];
  184. }];
  185. }
  186. #pragma mark----收入结算
  187. -(void)ForecastVClist
  188. {
  189. KDPForecastVC *forecastV =[[KDPForecastVC alloc]init];
  190. [self.navigationController pushViewController:forecastV animated:YES];
  191. }
  192. #pragma mark---商品详情
  193. -(void)goodDetailWithModel:(KDPNoticeModel *)model
  194. {
  195. KDPGoodDetailVC *detailVC = [[KDPGoodDetailVC alloc] init];
  196. KDPGoodsModel *goodM =[[KDPGoodsModel alloc]init];
  197. goodM.goods_id=model.goods_id;
  198. detailVC.model = goodM;
  199. [self.navigationController pushViewController:detailVC animated:YES];
  200. }
  201. /**
  202. 版本更新
  203. */
  204. - (void)updataArrrapp {
  205. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:APP_STORE_URL]];
  206. }
  207. #pragma mark---提现通过
  208. -(void)myAccountList
  209. {
  210. KDPAccountVC *drawV =[[KDPAccountVC alloc]init];
  211. [self.navigationController pushViewController:drawV animated:YES];
  212. }
  213. -(UIView *)messageNoView
  214. {
  215. if (!_messageNoView) {
  216. _messageNoView =[[UIView alloc]initWithFrame:CGRectMake(0, KDNavBarHeight, SCREEN_WIDTH, 50)];
  217. _messageNoView.backgroundColor=[UIColor colorWithHexString:LineColor];
  218. UIButton *backBtn =[[UIButton alloc]initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH,30)];
  219. backBtn.backgroundColor =[UIColor whiteColor];
  220. [self.messageNoView addSubview:backBtn];
  221. UIButton *openButton =[[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-56, 6.5, 40,17)];
  222. [openButton setTitle:@"开启" forState:UIControlStateNormal];
  223. [openButton setTitleColor:[UIColor colorWithHexString:ThemeColor] forState:UIControlStateNormal];
  224. openButton.layer.cornerRadius=8.5;
  225. openButton.layer.masksToBounds=YES;
  226. openButton.layer.borderColor =[UIColor colorWithHexString:ThemeColor].CGColor;
  227. openButton.layer.borderWidth=0.5;
  228. openButton.titleLabel.font =[UIFont systemFontOfSize:9];
  229. [openButton addTarget:self action:@selector(openNotice) forControlEvents:UIControlEventTouchUpInside];
  230. [backBtn addSubview:openButton];
  231. UIImageView *messageIcon =[[UIImageView alloc]initWithFrame:CGRectMake(15, 7.5, 15, 15)];
  232. messageIcon.image =[UIImage imageNamed:@"icon_message"];
  233. [backBtn addSubview:messageIcon];
  234. UILabel *tipL =[[UILabel alloc]initWithFrame:CGRectMake(40, 0, 300, 30)];
  235. tipL.textColor=[UIColor colorWithHexString:ThemeColor];
  236. tipL.font=[UIFont systemFontOfSize:12];
  237. [backBtn addSubview:tipL];
  238. tipL.text=@"您还未开启消息通知,开启获取最新通知";
  239. tipL.tag = 1234;
  240. }
  241. return _messageNoView;
  242. }
  243. #pragma mark---开启通知
  244. -(void)openNotice
  245. {
  246. UIApplication *application = [UIApplication sharedApplication];
  247. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  248. if ([application canOpenURL:url]) {
  249. if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
  250. if (@available(iOS 10.0, *)) {
  251. [application openURL:url options:@{} completionHandler:nil];
  252. } else {
  253. // Fallback on earlier versions
  254. }
  255. } else {
  256. [application openURL:url];
  257. }
  258. }
  259. }
  260. //判断是否开启通知
  261. - (BOOL)isOpenNotice { // 判断用户是否允许接收通知
  262. BOOL isEnable = NO;
  263. if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0f) { // iOS版本 >=8.0 处理逻辑
  264. UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
  265. isEnable = (UIUserNotificationTypeNone == setting.types) ? NO : YES;
  266. } else { // iOS版本 <8.0 处理逻辑
  267. UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
  268. isEnable = (UIRemoteNotificationTypeNone == type) ? NO : YES;
  269. }
  270. return isEnable;
  271. }
  272. @end