省钱达人

DRMessageListController.m 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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 "DROrderMainViewController.h"
  14. #import "DRMyFansViewController.h"
  15. #import "DRCollectionMainViewController.h"
  16. #import "DRAccountDetailController.h"
  17. #import "DRGoodListViewController.h"
  18. @interface DRMessageListController ()<UITableViewDelegate, UITableViewDataSource>
  19. {
  20. NSInteger _page;
  21. }
  22. @property (nonatomic, strong) UITableView *tableView;
  23. @property (nonatomic, strong) NSMutableArray *dataArr;
  24. @end
  25. @implementation DRMessageListController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self configNavigationBar];
  29. [self configTableView];
  30. [self requestData];
  31. }
  32. -(void)viewWillAppear:(BOOL)animated{
  33. [super viewWillAppear:animated];
  34. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  35. }
  36. -(void)viewDidDisappear:(BOOL)animated{
  37. [super viewDidDisappear:animated];
  38. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  39. [SVProgressHUD dismiss];
  40. }
  41. - (void)configTableView {
  42. _page = 1;
  43. [self.view addSubview:self.tableView];
  44. }
  45. - (void)configNavigationBar {
  46. [self.navigationBar setNavTitle:@"我的消息"];
  47. self.navigationBar.backgroundColor = [UIColor changeColor];
  48. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  49. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  50. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  51. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  52. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  53. }
  54. - (void)backAction {
  55. [SVProgressHUD dismiss];
  56. [self.navigationController popViewControllerAnimated:YES];
  57. }
  58. - (void)requestData {
  59. [SVProgressHUD show];
  60. NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/MessagePushList",BaseURL];
  61. [DRHttp post:url params:@{@"page":@(_page)} success:^(id json) {
  62. NSArray *list = [NSArray yy_modelArrayWithClass:[DRMessageModel class] json:json[@"data"]];
  63. if (list.count>0) {
  64. [self.dataArr addObjectsFromArray:list];
  65. [self.tableView.mj_footer endRefreshing];;
  66. }else {
  67. if (_page==1) {
  68. [self setUpNoDataView];
  69. }
  70. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  71. }
  72. [SVProgressHUD dismiss];
  73. [self.tableView reloadData];
  74. } failure:^(NSError *error) {
  75. [self.tableView.mj_footer endRefreshing];
  76. }];
  77. }
  78. - (void)setUpNoDataView {
  79. self.tableView.showNoDataView = YES;
  80. self.tableView.defaultNoDataText = @"您还没有任何记录";
  81. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  82. }
  83. #pragma mark -------- UITableView Delegate -----
  84. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  85. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  86. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
  87. }
  88. }
  89. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  90. return self.dataArr.count;
  91. }
  92. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  93. return 120;
  94. }
  95. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  96. return .1;
  97. }
  98. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  99. return 0.1;
  100. }
  101. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  102. DRMessageModel *model = self.dataArr[indexPath.row];
  103. DRMessageListCell *cell = [DRMessageListCell cellWithTableView:tableView];
  104. cell.model = model;
  105. return cell;
  106. }
  107. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  108. DRMessageModel *model = self.dataArr[indexPath.row];
  109. NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/MessageClick",BaseURL];
  110. NSDictionary *dict = @{
  111. @"message_id":model.Id,
  112. @"person_group":model.person_group,
  113. @"is_view":model.is_view
  114. };
  115. [DRHttp post:url params:dict success:^(id json) {
  116. DRMessageListCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  117. [cell isRead];
  118. } failure:^(NSError *error) {
  119. }];
  120. switch ([model.message_type integerValue]) {
  121. case 1:
  122. [self gotoMyFans]; //我的粉丝
  123. break;
  124. case 2:
  125. [self gotoGoodDetailPage:model]; //商品详情或列表
  126. break;
  127. case 3:
  128. [self gotoUpdateApp]; //更新app
  129. break;
  130. case 4:
  131. [self gotoMyOrderPage]; // 收入结算
  132. break;
  133. case 5:
  134. [self gotoBackMoneyPage]; //提现完成
  135. break;
  136. case 6:
  137. [self gotoMyCollectionPage]; //我的收藏
  138. break;
  139. default:
  140. break;
  141. }
  142. }
  143. /**
  144. 去我的粉丝
  145. */
  146. - (void)gotoMyFans {
  147. DRMyFansViewController *myFans = [[DRMyFansViewController alloc] init];
  148. [self.navigationController pushViewController:myFans animated:YES];
  149. }
  150. /**
  151. 打开详情页
  152. */
  153. - (void)gotoGoodDetailPage:(DRMessageModel *)model {
  154. if ([model.goods_or_group isEqualToString:@"1"]) {
  155. DRGoodDetailViewController *goodDetail = [[DRGoodDetailViewController alloc] init];
  156. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId: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_start_time:model.coupon_start_time
  163. coupon_end_time:model.coupon_end_time];
  164. goodDetail.requestModel = requestModel;
  165. [self.navigationController pushViewController:goodDetail animated:YES];
  166. }else {
  167. //列表页
  168. DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
  169. list.cate_id = model.group_id;
  170. list.topRequest = 2;
  171. [self.navigationController pushViewController:list animated:YES];
  172. }
  173. }
  174. /**
  175. 版本更新
  176. */
  177. - (void)gotoUpdateApp {
  178. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:APP_STORE_URL]];
  179. }
  180. /**
  181. 我的订单
  182. */
  183. - (void)gotoMyOrderPage {
  184. DRAccountDetailController *orderMain = [[DRAccountDetailController alloc] init];
  185. [self.navigationController pushViewController:orderMain animated:YES];
  186. }
  187. /**
  188. 提现完成
  189. */
  190. - (void)gotoBackMoneyPage {
  191. [self gotoMyOrderPage];
  192. }
  193. /**
  194. 我的收藏
  195. */
  196. - (void)gotoMyCollectionPage {
  197. DRCollectionMainViewController *collection = [[DRCollectionMainViewController alloc] init];
  198. [self.navigationController pushViewController:collection animated:YES];
  199. }
  200. #pragma mark ------- layzer ------
  201. - (UITableView *)tableView {
  202. if (!_tableView) {
  203. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStyleGrouped];
  204. _tableView.estimatedSectionHeaderHeight = 0;
  205. _tableView.estimatedSectionFooterHeight = 0;
  206. _tableView.sectionFooterHeight = 0;
  207. _tableView.sectionHeaderHeight = 0;
  208. _tableView.estimatedRowHeight = 0;
  209. _tableView.delegate = self;
  210. _tableView.dataSource = self;
  211. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  212. _tableView.backgroundColor = [UIColor yhGrayColor];
  213. _tableView.showsVerticalScrollIndicator = NO;
  214. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  215. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  216. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  217. _page ++;
  218. [self requestData];
  219. }];
  220. }
  221. return _tableView;
  222. }
  223. - (NSMutableArray *)dataArr {
  224. if (!_dataArr) {
  225. _dataArr = [NSMutableArray array];
  226. }
  227. return _dataArr;
  228. }
  229. - (void)didReceiveMemoryWarning {
  230. [super didReceiveMemoryWarning];
  231. // Dispose of any resources that can be recreated.
  232. }
  233. /*
  234. #pragma mark - Navigation
  235. // In a storyboard-based application, you will often want to do a little preparation before navigation
  236. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  237. // Get the new view controller using [segue destinationViewController].
  238. // Pass the selected object to the new view controller.
  239. }
  240. */
  241. @end