// // OrderSalesTableViewCell.m // IBOSS // // Created by guan hong hou on 2017/5/26. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved. // // 功能描述:订单销售单列表单元格 // #import "OrderSalesTableViewCell.h" #import "DateFormat.h" #import "NSString+Tools.h" #define reportTextFont [UIFont systemFontOfSize:LabelAndTextFontOfSize] @implementation OrderSalesTableViewCell /** 初始化数据 @param style <#style description#> @param reuseIdentifier <#reuseIdentifier description#> @return <#return value description#> */ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { } return self; } /** 单元格ui布局 @param orderItem <#orderItem description#> */ - (void)parseOrderSalesInfo:(OrderSaleListModel *)orderItem{ CGFloat xpadding=20; CGFloat ypadding=15; _lblCustomerName = [[UILabel alloc]init]; _lblCustomerName.frame=CGRectMake(xpadding,ypadding,150,16); _lblCustomerName.text=orderItem.customerName; _lblCustomerName.font=reportTextFont; [self.contentView addSubview:_lblCustomerName]; _lblAccountDate = [[UILabel alloc]init]; _lblAccountDate.frame=CGRectMake(Screen_Width-120,ypadding,100,16); _lblAccountDate.text = [DateFormat dateFormatSplit: orderItem.accountDate]; _lblAccountDate.textAlignment=NSTextAlignmentRight; _lblAccountDate.font=reportTextFont; [self.contentView addSubview:_lblAccountDate]; UIView *middleSeparator = [[UIView alloc]init]; middleSeparator.frame=CGRectMake(0,CGRectGetMaxY(_lblCustomerName.frame)+10, Screen_Width, 1); middleSeparator.backgroundColor=LineBackgroundColor; [self.contentView addSubview:middleSeparator]; NSDictionary *reportDict = @{NSFontAttributeName:reportTextFont}; UILabel *lblTitleStaffName = [[UILabel alloc]init]; NSString *titleStaffName = @"业务员:"; CGRect titleStaffNameFrame = [titleStaffName textRectWithSize:CGSizeMake(100,16) attributes:reportDict]; titleStaffNameFrame.origin.x = xpadding; titleStaffNameFrame.origin.y = CGRectGetMaxY(middleSeparator.frame)+15; lblTitleStaffName.font=reportTextFont; lblTitleStaffName.frame=titleStaffNameFrame; lblTitleStaffName.text=titleStaffName; lblTitleStaffName.textColor=LabelGrayTextColor; [self.contentView addSubview:lblTitleStaffName]; _lblStaffName = [[UILabel alloc]init]; CGFloat w = Screen_Width / 2 - CGRectGetMaxX(lblTitleStaffName.frame)-5; CGRect staffNameFrame = CGRectMake(CGRectGetMaxX(lblTitleStaffName.frame), CGRectGetMaxY(middleSeparator.frame)+15, w, 16); _lblStaffName.frame=staffNameFrame; _lblStaffName.text=orderItem.staffName; _lblStaffName.font=reportTextFont; [self.contentView addSubview:_lblStaffName]; UILabel *lblTitleInoviceType = [[UILabel alloc]init]; NSString *titleInvoiceType = @"单据类型:"; CGRect titleInvoiceTypeFrame = [titleInvoiceType textRectWithSize:CGSizeMake(100, MAXFLOAT) attributes:reportDict]; titleInvoiceTypeFrame.origin.x= Screen_Width/2; titleInvoiceTypeFrame.origin.y =CGRectGetMaxY(middleSeparator.frame)+15; lblTitleInoviceType.frame=titleInvoiceTypeFrame; lblTitleInoviceType.font=reportTextFont; lblTitleInoviceType.text=titleInvoiceType; lblTitleInoviceType.textColor=LabelGrayTextColor; [self.contentView addSubview:lblTitleInoviceType]; NSString *invoiceType=orderItem.invoiceTypeName; _lblInvoiceType = [[UILabel alloc]init]; _lblInvoiceType.frame=CGRectMake(CGRectGetMaxX(lblTitleInoviceType.frame), CGRectGetMaxY(middleSeparator.frame)+15,70, 17); _lblInvoiceType.text=invoiceType; _lblInvoiceType.lineBreakMode = NSLineBreakByWordWrapping | NSLineBreakByTruncatingTail; _lblInvoiceType.numberOfLines=1; _lblInvoiceType.font=reportTextFont; [self.contentView addSubview:_lblInvoiceType]; UILabel *lblTitleOrganizationName = [[UILabel alloc]init]; NSString *titleOrganizationName = @"部门:"; lblTitleOrganizationName.text=titleOrganizationName; CGRect titleOrganizationNameFrame = [titleOrganizationName textRectWithSize:CGSizeMake(100, MAXFLOAT) attributes:reportDict]; titleOrganizationNameFrame.origin.x =xpadding; titleOrganizationNameFrame.origin.y =CGRectGetMaxY(lblTitleStaffName.frame)+15; lblTitleOrganizationName.font=reportTextFont; lblTitleOrganizationName.textColor=LabelGrayTextColor; lblTitleOrganizationName.frame=titleOrganizationNameFrame; [self.contentView addSubview:lblTitleOrganizationName]; NSString *organizationName=orderItem.organizationName; _lblOrganizationName = [[UILabel alloc]init]; w = Screen_Width - CGRectGetMaxX(lblTitleOrganizationName.frame)-20; CGRect organizationNameFrame = [organizationName textRectWithSize:CGSizeMake(w, MAXFLOAT) attributes:reportDict]; organizationNameFrame.origin.x =CGRectGetMaxX(lblTitleOrganizationName.frame); organizationNameFrame.origin.y =CGRectGetMaxY(lblTitleStaffName.frame)+15; _lblOrganizationName.frame=organizationNameFrame; _lblOrganizationName.font=reportTextFont; _lblOrganizationName.text=organizationName; [self.contentView addSubview:_lblOrganizationName]; UILabel *lblTitleCustomerAddress = [[UILabel alloc]init]; NSString *titleCustomerAddress = @"客户地址:"; lblTitleCustomerAddress.text=titleCustomerAddress; CGRect titleCustomerAddressFrame = [titleCustomerAddress textRectWithSize:CGSizeMake(200, MAXFLOAT) attributes:reportDict]; titleCustomerAddressFrame.origin.x =xpadding; titleCustomerAddressFrame.origin.y =CGRectGetMaxY(lblTitleOrganizationName.frame)+15; lblTitleCustomerAddress.font=reportTextFont; lblTitleCustomerAddress.textColor=LabelGrayTextColor; lblTitleCustomerAddress.frame=titleCustomerAddressFrame; [self.contentView addSubview:lblTitleCustomerAddress]; NSString *customerAddress=orderItem.customerAddress; _lblCustomerAddress = [[UILabel alloc]init]; w = Screen_Width - CGRectGetMaxX(lblTitleCustomerAddress.frame)-20; CGRect customerAddressFrame = [customerAddress textRectWithSize:CGSizeMake(w, MAXFLOAT) attributes:reportDict]; customerAddressFrame.origin.x =CGRectGetMaxX(lblTitleCustomerAddress.frame); customerAddressFrame.origin.y =CGRectGetMaxY(lblTitleOrganizationName.frame)+15; _lblCustomerAddress.frame=customerAddressFrame; _lblCustomerAddress.font=reportTextFont; _lblCustomerAddress.text=customerAddress; [self.contentView addSubview:_lblCustomerAddress]; UILabel *lblTitleTelephone = [[UILabel alloc]init]; NSString *titleTelephone = @"联系电话:"; lblTitleTelephone.text=titleTelephone; CGRect titleTelephoneFrame = [titleTelephone textRectWithSize:CGSizeMake(200, MAXFLOAT) attributes:reportDict]; titleTelephoneFrame.origin.x =xpadding; titleTelephoneFrame.origin.y =CGRectGetMaxY(lblTitleCustomerAddress.frame)+15; lblTitleTelephone.font=reportTextFont; lblTitleTelephone.textColor=LabelGrayTextColor; lblTitleTelephone.frame=titleTelephoneFrame; [self.contentView addSubview:lblTitleTelephone]; NSString *telephone=orderItem.telephone; _lblTelephone = [[UILabel alloc]init]; w = Screen_Width - CGRectGetMaxX(lblTitleTelephone.frame)-20; CGRect telephoneFrame = [telephone textRectWithSize:CGSizeMake(w, MAXFLOAT) attributes:reportDict]; telephoneFrame.origin.x =CGRectGetMaxX(lblTitleTelephone.frame); telephoneFrame.origin.y =CGRectGetMaxY(lblTitleCustomerAddress.frame)+15; _lblTelephone.frame=telephoneFrame; _lblTelephone.font=reportTextFont; _lblTelephone.text=telephone; [self.contentView addSubview:_lblTelephone]; middleSeparator = [[UIView alloc]init]; middleSeparator.frame=CGRectMake(0,CGRectGetMaxY(lblTitleTelephone.frame)+15, Screen_Width, 1); middleSeparator.backgroundColor=LineBackgroundColor; [self.contentView addSubview:middleSeparator]; NSDictionary *orderDict = @{NSFontAttributeName:[UIFont systemFontOfSize:SubLabelAndTextFontOfSize]}; _lblTotalElse = [[UILabel alloc]init]; _lblTotalElse.font = [UIFont systemFontOfSize:11]; _lblTotalElse.textAlignment=NSTextAlignmentRight; CGRect littleCountElseFrame; NSString *littleCountTitle=@"小计:¥"; NSString *semicolon=@";"; NSString *abandonZeroTitle=@"(舍零¥"; NSString *goodsAmountTitle=@"货款¥"; NSString *outInventoryAmountTitle=@"出库金额¥"; NSString *rightBrackets=@")"; if([orderItem.invoiceType isEqualToString:@"2"]){ NSString *littleCountElse= [NSString stringWithFormat:@"%@%@%@%@%@%@%@%@%@%@%@%@",littleCountTitle,orderItem.totalAmount,semicolon,abandonZeroTitle,orderItem.discountAmount,semicolon,goodsAmountTitle,orderItem.goodsAmount,semicolon,outInventoryAmountTitle,orderItem.outAmount,rightBrackets]; NSMutableAttributedString *littleCountStr = [[NSMutableAttributedString alloc] initWithString:littleCountElse]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,littleCountTitle.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(littleCountTitle.length,orderItem.totalAmount.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length,semicolon.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length,abandonZeroTitle.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length,orderItem.discountAmount.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length,semicolon.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length+semicolon.length,goodsAmountTitle.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length+semicolon.length+goodsAmountTitle.length,orderItem.goodsAmount.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length+semicolon.length+goodsAmountTitle.length+orderItem.goodsAmount.length,semicolon.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length+semicolon.length+goodsAmountTitle.length+orderItem.goodsAmount.length+semicolon.length,outInventoryAmountTitle.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length+semicolon.length+goodsAmountTitle.length+orderItem.goodsAmount.length+semicolon.length+outInventoryAmountTitle.length,orderItem.outAmount.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length+semicolon.length+goodsAmountTitle.length+orderItem.goodsAmount.length+semicolon.length+outInventoryAmountTitle.length+orderItem.outAmount.length,rightBrackets.length)]; _lblTotalElse.attributedText=littleCountStr; littleCountElseFrame = [littleCountElse textRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) attributes:orderDict]; littleCountElseFrame.origin.x =Screen_Width-littleCountElseFrame.size.width-xpadding; littleCountElseFrame.origin.y =CGRectGetMaxY(middleSeparator.frame)+ 15; _lblTotalElse.frame=littleCountElseFrame; [self.contentView addSubview:_lblTotalElse]; } else { NSString *littleCountElse= [NSString stringWithFormat:@"%@%@%@%@%@%@%@%@%@",littleCountTitle,orderItem.totalAmount,semicolon,abandonZeroTitle,orderItem.discountAmount,semicolon,goodsAmountTitle,orderItem.goodsAmount,rightBrackets]; NSMutableAttributedString *littleCountStr = [[NSMutableAttributedString alloc] initWithString:littleCountElse]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,littleCountTitle.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(littleCountTitle.length,orderItem.totalAmount.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length,semicolon.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length,abandonZeroTitle.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length,orderItem.discountAmount.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length,semicolon.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length+semicolon.length,goodsAmountTitle.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length+semicolon.length+goodsAmountTitle.length,orderItem.goodsAmount.length)]; [littleCountStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(littleCountTitle.length+orderItem.totalAmount.length+semicolon.length+abandonZeroTitle.length+orderItem.discountAmount.length+semicolon.length+goodsAmountTitle.length+orderItem.goodsAmount.length,rightBrackets.length)]; _lblTotalElse.attributedText=littleCountStr; _lblTotalElse.text=littleCountElse; littleCountElseFrame = [littleCountElse textRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) attributes:orderDict]; littleCountElseFrame.origin.x =Screen_Width-littleCountElseFrame.size.width-xpadding; littleCountElseFrame.origin.y =CGRectGetMaxY(middleSeparator.frame)+ 15; _lblTotalElse.frame=littleCountElseFrame; [self.contentView addSubview:_lblTotalElse]; } UIView *bottomSeparator = [[UIView alloc]init]; bottomSeparator.frame=CGRectMake(0,CGRectGetMaxY(_lblTotalElse.frame)+15, Screen_Width, 10); bottomSeparator.backgroundColor=LineBackgroundColor; [self.contentView addSubview:bottomSeparator]; } @end