dkahgld

ZBOrderListVC.m 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // ZBOrderListVC.m
  3. // ZBProject
  4. //
  5. // Created by 学丽 on 2019/4/9.
  6. // Copyright © 2019 ZB. All rights reserved.
  7. //
  8. #import "ZBOrderListVC.h"
  9. @interface ZBOrderListVC ()<UITableViewDelegate,UITableViewDataSource>
  10. {
  11. NSTimer *timer;
  12. }
  13. @property(nonatomic,strong)UITableView *tableViews;
  14. @property(nonatomic,strong)NSMutableArray *listArray;
  15. @property(nonatomic,copy)NSString *order_count;//订单数量
  16. @property(nonatomic,strong)ZBTableHeadView *headView;
  17. @property(nonatomic,copy)NSString *last_order_id;
  18. @property(nonatomic,copy)NSString *is_new;
  19. @end
  20. @implementation ZBOrderListVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self initWithNav];
  24. [self getOrderList];
  25. timer = [NSTimer timerWithTimeInterval:30 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
  26. [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
  27. }
  28. -(void)timerAction
  29. {
  30. if ([AccountTool isLogin]) {
  31. self.is_new =@"1";
  32. if (self.listArray.count>0) {
  33. ZBOrderModel *model=self.listArray.firstObject;
  34. self.last_order_id=model.Id;
  35. }
  36. [self getOrderList];
  37. }
  38. }
  39. -(void)viewWillDisappear:(BOOL)animated
  40. {
  41. [super viewWillDisappear:animated];
  42. [timer invalidate];
  43. }
  44. -(void)initWithNav
  45. {
  46. self.order_count=@"-";
  47. self.is_new=@"1";
  48. self.last_order_id=@"";
  49. //发送通知
  50. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateData) name:@"listorder" object:nil];
  51. //添加tableview
  52. [self.view addSubview:self.tableViews];
  53. [self.tableViews mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.mas_equalTo(0);
  55. make.height.mas_equalTo(SCREEN_HEIGHT-45-NavBarHeight);
  56. make.left.right.mas_equalTo(0);
  57. }];
  58. self.headView=[[ZBTableHeadView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
  59. self.tableViews.tableHeaderView=self.headView;
  60. [self addFooterrefresh];
  61. }
  62. -(void)updateData
  63. {
  64. NSLog(@"dddd");
  65. // [self getOrderList];
  66. }
  67. -(void)viewWillAppear:(BOOL)animated
  68. {
  69. [super viewWillAppear:animated];
  70. }
  71. -(UITableView *)tableViews
  72. {
  73. if (!_tableViews) {
  74. _tableViews =[[UITableView alloc]init];
  75. _tableViews.delegate=self;
  76. _tableViews.dataSource=self;
  77. _tableViews.backgroundColor=[UIColor whiteColor];
  78. _tableViews.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
  79. // _tableViews.sectionHeaderHeight=10;
  80. _tableViews.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; _tableViews.showsHorizontalScrollIndicator=NO;
  81. _tableViews.showsVerticalScrollIndicator=NO;
  82. }
  83. return _tableViews;
  84. }
  85. #pragma mark--获取订单列表
  86. -(void)getOrderList
  87. {
  88. if (![AccountTool isLogin]) {
  89. return;
  90. }
  91. [LoadingView showInView:self.view];
  92. NSDictionary *para=@{@"is_new":self.is_new,@"last_order_id":self.last_order_id};
  93. [ZBHTTP post:getOrderListURL params:para success:^(id _Nonnull json) {
  94. if (self.is_new.integerValue == 1) {
  95. self.order_count=json[@"order_count"];
  96. self.headView.titlelabel.text=[NSString stringWithFormat:@"共%@单",self.order_count];
  97. }
  98. NSArray *array =[NSArray yy_modelArrayWithClass:[ZBOrderModel class] json:json[@"order_list"]];
  99. [self.listArray addObjectsFromArray:array];
  100. if (self.listArray.count ==0) {
  101. [self setUpNoDataView];
  102. }
  103. [self.tableViews reloadData];
  104. [self.tableViews.mj_footer endRefreshing];
  105. [self.tableViews.mj_header endRefreshing];
  106. [LoadingView dismiss];
  107. } failure:^(NSError * _Nonnull error) {
  108. [LoadingView dismiss];
  109. }];
  110. }
  111. #pragma mark---TableViewDelegate&&DataSource
  112. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. ZBOrderListCell *listC =[tableView dequeueReusableCellWithIdentifier:@"list"];
  115. if (!listC) {
  116. listC=[[ZBOrderListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"list"];
  117. listC.selectionStyle=UITableViewCellSelectionStyleNone;
  118. }
  119. listC.model=self.listArray[indexPath.section];
  120. return listC;
  121. }
  122. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  123. {
  124. return 1;
  125. }
  126. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  127. {
  128. return self.listArray.count;
  129. }
  130. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  131. {
  132. return 116;
  133. }
  134. //-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  135. //{
  136. // return 10;
  137. //}
  138. //-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  139. //{
  140. // UIView *back =[[UIView alloc]init];
  141. // back.backgroundColor=[UIColor YHColorWithHex:0xF4F4F4];
  142. // return back;
  143. //}
  144. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  145. {
  146. }
  147. - (void)setUpNoDataView {
  148. self.tableViews.showNoDataView = YES;
  149. self.tableViews.noDataImageOffsetY = -70;
  150. self.tableViews.defaultNoDataText = @"还没有记录";
  151. self.tableViews.defaultNoDataImage = [UIImage imageNamed:@"no_order"];
  152. }
  153. -(NSMutableArray *)listArray
  154. {
  155. if (!_listArray) {
  156. _listArray=[NSMutableArray array];
  157. }
  158. return _listArray;
  159. }
  160. #pragma mark -- 移除通知
  161. -(void)dealloc{
  162. [[NSNotificationCenter defaultCenter]removeObserver:self];
  163. }
  164. -(void)addFooterrefresh
  165. {
  166. self.tableViews.mj_footer =[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  167. self.is_new=@"0";
  168. if (self.listArray.count>0) {
  169. ZBOrderModel *model=self.listArray.lastObject;
  170. self.last_order_id=model.Id;
  171. }
  172. [self getOrderList];
  173. }];
  174. }
  175. @end