123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- //
- // ZBOrderListVC.m
- // ZBProject
- //
- // Created by 学丽 on 2019/4/9.
- // Copyright © 2019 ZB. All rights reserved.
- //
- #import "ZBOrderListVC.h"
- @interface ZBOrderListVC ()<UITableViewDelegate,UITableViewDataSource>
- {
- NSTimer *timer;
- }
- @property(nonatomic,strong)UITableView *tableViews;
- @property(nonatomic,strong)NSMutableArray *listArray;
- @property(nonatomic,copy)NSString *order_count;//订单数量
- @property(nonatomic,strong)ZBTableHeadView *headView;
- @property(nonatomic,copy)NSString *last_order_id;
- @property(nonatomic,copy)NSString *is_new;
- @end
- @implementation ZBOrderListVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
-
- [self initWithNav];
- [self getOrderList];
- timer = [NSTimer timerWithTimeInterval:30 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
- [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
-
- }
- -(void)timerAction
- {
- if ([AccountTool isLogin]) {
- self.is_new =@"1";
- if (self.listArray.count>0) {
- ZBOrderModel *model=self.listArray.firstObject;
- self.last_order_id=model.Id;
- }
- [self getOrderList];
- }
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [timer invalidate];
- }
- -(void)initWithNav
- {
- self.order_count=@"-";
- self.is_new=@"1";
- self.last_order_id=@"";
- //发送通知
- [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateData) name:@"listorder" object:nil];
-
- //添加tableview
- [self.view addSubview:self.tableViews];
- [self.tableViews mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(0);
- make.height.mas_equalTo(SCREEN_HEIGHT-45-NavBarHeight);
- make.left.right.mas_equalTo(0);
- }];
- self.headView=[[ZBTableHeadView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
- self.tableViews.tableHeaderView=self.headView;
- [self addFooterrefresh];
- }
- -(void)updateData
- {
- NSLog(@"dddd");
- // [self getOrderList];
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- }
- -(UITableView *)tableViews
- {
- if (!_tableViews) {
- _tableViews =[[UITableView alloc]init];
- _tableViews.delegate=self;
- _tableViews.dataSource=self;
- _tableViews.backgroundColor=[UIColor whiteColor];
- _tableViews.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
- // _tableViews.sectionHeaderHeight=10;
- _tableViews.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; _tableViews.showsHorizontalScrollIndicator=NO;
- _tableViews.showsVerticalScrollIndicator=NO;
-
-
- }
- return _tableViews;
- }
- #pragma mark--获取订单列表
- -(void)getOrderList
- {
- if (![AccountTool isLogin]) {
- return;
- }
-
- [LoadingView showInView:self.view];
-
- NSDictionary *para=@{@"is_new":self.is_new,@"last_order_id":self.last_order_id};
-
- [ZBHTTP post:getOrderListURL params:para success:^(id _Nonnull json) {
- if (self.is_new.integerValue == 1) {
- self.order_count=json[@"order_count"];
- self.headView.titlelabel.text=[NSString stringWithFormat:@"共%@单",self.order_count];
- }
-
- NSArray *array =[NSArray yy_modelArrayWithClass:[ZBOrderModel class] json:json[@"order_list"]];
- [self.listArray addObjectsFromArray:array];
- if (self.listArray.count ==0) {
- [self setUpNoDataView];
- }
- [self.tableViews reloadData];
- [self.tableViews.mj_footer endRefreshing];
- [self.tableViews.mj_header endRefreshing];
-
-
- [LoadingView dismiss];
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
-
- }];
- }
- #pragma mark---TableViewDelegate&&DataSource
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- ZBOrderListCell *listC =[tableView dequeueReusableCellWithIdentifier:@"list"];
- if (!listC) {
- listC=[[ZBOrderListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"list"];
- listC.selectionStyle=UITableViewCellSelectionStyleNone;
- }
- listC.model=self.listArray[indexPath.section];
- return listC;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 1;
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return self.listArray.count;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 116;
- }
- //-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // return 10;
- //}
- //-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- //{
- // UIView *back =[[UIView alloc]init];
- // back.backgroundColor=[UIColor YHColorWithHex:0xF4F4F4];
- // return back;
- //}
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- }
- - (void)setUpNoDataView {
- self.tableViews.showNoDataView = YES;
- self.tableViews.noDataImageOffsetY = -70;
- self.tableViews.defaultNoDataText = @"还没有记录";
- self.tableViews.defaultNoDataImage = [UIImage imageNamed:@"no_order"];
- }
- -(NSMutableArray *)listArray
- {
- if (!_listArray) {
- _listArray=[NSMutableArray array];
-
- }
- return _listArray;
- }
- #pragma mark -- 移除通知
- -(void)dealloc{
-
- [[NSNotificationCenter defaultCenter]removeObserver:self];
- }
- -(void)addFooterrefresh
- {
- self.tableViews.mj_footer =[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- self.is_new=@"0";
- if (self.listArray.count>0) {
- ZBOrderModel *model=self.listArray.lastObject;
-
- self.last_order_id=model.Id;
- }
-
- [self getOrderList];
- }];
- }
- @end
|