// // OrderDetailViewController.m // IBOSSmini // // Created by guan hong hou on 2017/5/24. // Copyright © 2017年 elongtian. All rights reserved. // #import "OrderDetailViewController.h" #import "OrderDetailTableViewCell.h" #import "DateFormat.h" @interface OrderDetailViewController () @end @implementation OrderDetailViewController #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; _detailArr=[[NSArray alloc] init]; _cartModel=[ShopCartModel new]; self.navigationItem.title=@"订单明细"; _vCustomTableView = [[UITableView alloc] initWithFrame:CGRectMake(10,10, self.view.frame.size.width-20, self.view.frame.size.height-20)]; _vCustomTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _vCustomTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _vCustomTableView.backgroundColor=[UIColor clearColor]; _vCustomTableView.delegate = self; _vCustomTableView.dataSource=self; _vCustomTableView.showsVerticalScrollIndicator = NO; [self.view addSubview:_vCustomTableView]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0, 15, 18); UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = menuButton; [self initHeaderView]; [self reloadData]; } /** 安全区改变 */ -(void)viewSafeAreaInsetsDidChange{ _vCustomTableView.frame = CGRectMake(10, 10, self.view.safeAreaLayoutGuide.layoutFrame.size.width-20, self.view.safeAreaLayoutGuide.layoutFrame.size.height); [super viewSafeAreaInsetsDidChange]; } /** didReceiveMemoryWarning函数 */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark -委托函数 //订单细节数据加载成功接口 - (void)onLoadFinish:(ASIDownManager *)sender { NSDictionary *dic = [sender.mWebStr JSONValue]; [self cancel]; if (dic && [dic isKindOfClass:[NSDictionary class]]) { int iStatus = [[dic objectForKey:@"Status"] intValue]; NSString *message=[dic objectForKey:@"Message"]; if (iStatus == 0) { NSArray * approvArr=[dic objectForKey:@"Result"]; if(approvArr!=nil&&approvArr.count>0) { _detailArr= approvArr; if( _detailArr.count==0){ [self showAlertViewText:@"未找到匹配结果"]; } [_cartModel parseOrderDetailArr:_detailArr]; [_vCustomTableView reloadData]; } } else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [self showReLoginDialog:message]; return; } else { [self showAlertViewText:message]; } } } //数据加载失败接口 - (void)onLoadFail:(ASIDownManager *)sender { [self cancel]; [self showAlertViewText:@"加载失败"]; } //tableview的高度 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 560; } //tableview的分区数 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return _detailArr.count; } //tableview分区的间隔高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 10; } //tableview的行数 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } //tableview分区 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView* myView =[[UIView alloc]init]; myView.backgroundColor = [UIColor clearColor]; return myView; } //获取tableviewcell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellIdentifier=@"OrderDetailCell"; OrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; cell=[[OrderDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; NSArray *checkArr=_cartModel.orderDetailArr; ShopCartItemModel *infoModel=checkArr[indexPath.section]; [cell parseOrderInfo:infoModel]; return cell; } #pragma mark - 私有函数 //返回函数 -(void)goBack{ [self.navigationController popViewControllerAnimated:YES]; } //初始化headerview -(void)initHeaderView{ UIView *headerContentView=[[UIView alloc]init]; headerContentView.layer.cornerRadius=CornerRadius; headerContentView.backgroundColor=[UIColor whiteColor]; headerContentView.frame=CGRectZero; _vCustomTableView.tableHeaderView=headerContentView; CGFloat xpadding=10; CGFloat ypadding=10; UILabel *lblTitleOrderNo=[[UILabel alloc]init]; lblTitleOrderNo.frame=CGRectMake(xpadding, ypadding,80,25); lblTitleOrderNo.text=@"订单单号:"; lblTitleOrderNo.font=orderTextFont; [headerContentView addSubview:lblTitleOrderNo]; _lblOrderNo=[[UILabel alloc]init]; _lblOrderNo.frame=CGRectMake(CGRectGetMaxX(lblTitleOrderNo.frame), ypadding,250, 25); _lblOrderNo.text=[_dicInfo objectForKey:@"OrderNo"]; _lblOrderNo.font=orderTextFont; [headerContentView addSubview:_lblOrderNo]; UIImageView *separatorImg=[[UIImageView alloc]init]; separatorImg.frame=CGRectMake(0,CGRectGetMaxY(lblTitleOrderNo.frame)+10,Screen_Width, 1); [separatorImg setImage:[UIImage imageNamed:@"dash"]]; [headerContentView addSubview:separatorImg]; UILabel *lblTitleCustomerName=[[UILabel alloc]init]; lblTitleCustomerName.frame=CGRectMake(xpadding,CGRectGetMaxY(separatorImg.frame)+10,80,25); lblTitleCustomerName.text=@"客户名称:"; lblTitleCustomerName.font=orderTextFont; [headerContentView addSubview:lblTitleCustomerName]; _lblCustomerName=[[UILabel alloc]init]; _lblCustomerName.frame=CGRectMake(CGRectGetMaxX(lblTitleCustomerName.frame), CGRectGetMaxY(separatorImg.frame)+10,250, 25); _lblCustomerName.text=[_dicInfo objectForKey:@"CustomerName"]; _lblCustomerName.font=orderTextFont; [headerContentView addSubview:_lblCustomerName]; UILabel *lblTitleCustomerAddress=[[UILabel alloc]init]; lblTitleCustomerAddress.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleCustomerName.frame)+10,80,25); lblTitleCustomerAddress.text=@"客户地址:"; lblTitleCustomerAddress.font=orderTextFont; [headerContentView addSubview:lblTitleCustomerAddress]; _lblCustomerAddress=[[UILabel alloc]init]; _lblCustomerAddress.frame=CGRectMake(CGRectGetMaxX(lblTitleCustomerAddress.frame), CGRectGetMaxY(lblTitleCustomerName.frame)+10,250, 25); _lblCustomerAddress.text=[_dicInfo objectForKey:@"Address"]; _lblCustomerAddress.font=orderTextFont; [headerContentView addSubview:_lblCustomerAddress]; UILabel *lblTitleMarkedPriceAmount=[[UILabel alloc]init]; lblTitleMarkedPriceAmount.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleCustomerAddress.frame)+10,80,25); lblTitleMarkedPriceAmount.text=@"标价总额:"; lblTitleMarkedPriceAmount.font=orderTextFont; [headerContentView addSubview:lblTitleMarkedPriceAmount]; _lblMarkedPriceAmount=[[UILabel alloc]init]; _lblMarkedPriceAmount.frame=CGRectMake(CGRectGetMaxX(lblTitleMarkedPriceAmount.frame), CGRectGetMaxY(lblTitleCustomerAddress.frame)+10,250, 25); _lblMarkedPriceAmount.text=[NSString stringWithFormat:@"%@",[_dicInfo objectForKey:@"MarkedPriceAmount"]]; _lblMarkedPriceAmount.font=orderTextFont; [headerContentView addSubview:_lblMarkedPriceAmount]; UILabel *lblTitleGoodsAmount=[[UILabel alloc]init]; lblTitleGoodsAmount.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleMarkedPriceAmount.frame)+10,80,25); lblTitleGoodsAmount.text=@"货物总额:"; lblTitleGoodsAmount.font=orderTextFont; [headerContentView addSubview: lblTitleGoodsAmount]; _lblGoodsAmount=[[UILabel alloc]init]; _lblGoodsAmount.frame=CGRectMake(CGRectGetMaxX(lblTitleGoodsAmount.frame), CGRectGetMaxY(lblTitleMarkedPriceAmount.frame)+10,250, 25); _lblGoodsAmount.text=[NSString stringWithFormat:@"%@",[_dicInfo objectForKey:@"GoodsAmount"]];; _lblGoodsAmount.font=orderTextFont; [headerContentView addSubview: _lblGoodsAmount]; UILabel *lblTitleDepartment=[[UILabel alloc]init]; lblTitleDepartment.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleGoodsAmount.frame)+10,80,25); lblTitleDepartment.text=@"业务部门:"; lblTitleDepartment.font=orderTextFont; [headerContentView addSubview: lblTitleDepartment]; _lblDepartment=[[UILabel alloc]init]; _lblDepartment.frame=CGRectMake(CGRectGetMaxX(lblTitleDepartment.frame), CGRectGetMaxY(lblTitleGoodsAmount.frame)+10,250, 25); _lblDepartment.text=[NSString stringWithFormat:@"%@",[_dicInfo objectForKey:@"OrganizationName"]];; _lblDepartment.font=orderTextFont; [headerContentView addSubview:_lblDepartment]; UILabel *lblTitleChannel=[[UILabel alloc]init]; lblTitleChannel.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleDepartment.frame)+10,80,25); lblTitleChannel.text=@"渠 道:"; lblTitleChannel.font=orderTextFont; [headerContentView addSubview:lblTitleChannel]; _lblChannelName=[[UILabel alloc]init]; _lblChannelName.frame=CGRectMake(CGRectGetMaxX(lblTitleChannel.frame), CGRectGetMaxY(lblTitleDepartment.frame)+10,250, 25); _lblChannelName.text=[NSString stringWithFormat:@"%@",[_dicInfo objectForKey:@"ChannelName"]];; _lblChannelName.font=orderTextFont; [headerContentView addSubview: _lblChannelName]; UILabel *lblTitleSalesMan=[[UILabel alloc]init]; lblTitleSalesMan.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleChannel.frame)+10,80,25); lblTitleSalesMan.text=@"业 务 员:"; lblTitleSalesMan.font=orderTextFont; [headerContentView addSubview: lblTitleSalesMan]; _lblStaffName=[[UILabel alloc]init]; _lblStaffName.frame=CGRectMake(CGRectGetMaxX(lblTitleSalesMan.frame), CGRectGetMaxY(lblTitleChannel.frame)+10,250, 25); _lblStaffName.text=[NSString stringWithFormat:@"%@",[_dicInfo objectForKey:@"StaffName"]];; _lblStaffName.font=orderTextFont; [headerContentView addSubview:_lblStaffName]; UILabel *lblTitleCreateDate=[[UILabel alloc]init]; lblTitleCreateDate.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleSalesMan.frame)+10,80,25); lblTitleCreateDate.text=@"创建日期:"; lblTitleCreateDate.font=orderTextFont; [headerContentView addSubview: lblTitleCreateDate]; _lblCreateDate=[[UILabel alloc]init]; _lblCreateDate.frame=CGRectMake(CGRectGetMaxX(lblTitleCreateDate.frame), CGRectGetMaxY( lblTitleSalesMan.frame)+10,250, 25); NSString *createTime=[_dicInfo objectForKey:@"CreateTime"]; createTime= [DateFormat dateFormatSplit:createTime]; _lblCreateDate.text=createTime; _lblCreateDate.font=orderTextFont; [headerContentView addSubview:_lblCreateDate]; headerContentView.frame=CGRectMake(0,0 ,_vCustomTableView.frame.size.width,CGRectGetMaxY(lblTitleCreateDate.frame)); } //加载订单明细 -(void)reloadData{ self.mDownManager = [[ASIDownManager alloc] init]; _mDownManager.delegate = self; _mDownManager.OnImageDown = @selector(onLoadFinish:); _mDownManager.OnImageFail = @selector(onLoadFail:); [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetIOrderDetailSourceIphone" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; [dict setObject:_orderId forKey:@"OrderID"]; [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } //取消进度条 - (void)cancel { [self stopLoading]; } @end