口袋优选

KBMessageListController.m 9.5KB

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