// // SubmitOrderCellTableViewCell.m // IBOSSmini // // Created by guan hong hou on 2017/5/22. // Copyright © 2017年 elongtian. All rights reserved. // #import "SubmitOrderTableViewCell.h" #define orderTextFont [UIFont systemFontOfSize:14] @implementation SubmitOrderTableViewCell #pragma mark - 公共函数 /** initWithStyle函数 */ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { } return self; } #pragma mark - 委托函数 /** textField回调函数 */ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSCharacterSet *cs; if(textField == _txtSalesQuantity) { cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERSANDDOT] invertedSet]; NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; BOOL basicTest = [string isEqualToString:filtered]; if(!basicTest) { return NO; } } if(textField == _txtSalesPrice) { cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERSANDDOT] invertedSet]; NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; BOOL basicTest = [string isEqualToString:filtered]; if(!basicTest) { return NO; } } return YES; } /** textField失去焦点回调函数 */ - (void) textFieldDidEndEditing:(UITextField *) field { [self endEditing:YES]; if([self.delegate respondsToSelector:@selector(textValueChange: txtField:)]) { [self.delegate textValueChange:self txtField:field]; } } #pragma mark - 私有函数 //初始化提交订单cell UI -(void)parseOrderInfo:(SubmitOrderFrame *)orderFrame{ _cartItemModel= orderFrame.cartModel; _hiddenID=_cartItemModel.cartId; _lblCode=[[UILabel alloc]init]; _lblCode.frame=[orderFrame lblProductCodeF]; _lblCode.text=_cartItemModel.code; _lblCode.font=orderTextFont; [self.contentView addSubview:_lblCode]; _lblCartId=[[UILabel alloc]init]; _lblCartId.frame=CGRectMake(CGRectGetMaxX(orderFrame.lblProductCodeF)+3, orderFrame.lblProductCodeF.origin.y, 20, 20); _lblCartId.text=_cartItemModel.cartId; [self.contentView addSubview:_lblCartId]; _lblCartId.hidden=YES; _lblMarkedPrice=[[UILabel alloc]init]; NSString *markedPrice=_cartItemModel.markedPrice; _lblMarkedPrice.frame=[orderFrame lblMarkedPriceF]; _lblMarkedPrice.font=orderTextFont; if(markedPrice!=nil){ _lblMarkedPrice.textColor=LabelGrayTextColor; _lblMarkedPrice.text=[NSString stringWithFormat:@"¥ %@",markedPrice]; } [self.contentView addSubview:_lblMarkedPrice]; UIView *topSeparator=[[UIView alloc]init]; topSeparator.frame=[orderFrame topSeparatorF]; topSeparator.backgroundColor=LineBackgroundColor; [self.contentView addSubview:topSeparator]; UILabel *lblTitleBrand=[[UILabel alloc]init]; NSString *titleBrand=@"品牌:"; lblTitleBrand.text=titleBrand; lblTitleBrand.font=orderTextFont; lblTitleBrand.textColor=LabelGrayTextColor; lblTitleBrand.frame=[orderFrame lblTitleBrandF]; [self.contentView addSubview: lblTitleBrand]; NSString *brand=[_cartItemModel brandName]; if(brand!=nil){ _lblBrandName=[[UILabel alloc]init]; _lblBrandName.text=brand; _lblBrandName.font=orderTextFont; _lblBrandName.frame=[orderFrame lblBrandF]; [self.contentView addSubview:_lblBrandName]; } NSString *titleOnlyCode=@"唯一编码:"; UILabel *lblTitleOnlyCode=[[UILabel alloc]init]; lblTitleOnlyCode.text=titleOnlyCode; lblTitleOnlyCode.font=orderTextFont; lblTitleOnlyCode.textColor=LabelGrayTextColor; lblTitleOnlyCode.frame=[orderFrame lblTitleOnlyCodeF]; [self.contentView addSubview: lblTitleOnlyCode]; NSString *onlyCode=[_cartItemModel onlyCode]; if(onlyCode!=nil){ _lblOnlyCode=[[UILabel alloc]init]; _lblOnlyCode.frame=[orderFrame lblOnlyCodeF]; _lblOnlyCode.font=orderTextFont; _lblOnlyCode.text=onlyCode; [self.contentView addSubview: _lblOnlyCode]; } NSString *titleColorNumber=@"色号:"; UILabel *lblTitleColorNumber=[[UILabel alloc]init]; lblTitleColorNumber.font=orderTextFont; lblTitleColorNumber.text=titleColorNumber; lblTitleColorNumber.textColor=LabelGrayTextColor; lblTitleColorNumber.frame=[orderFrame lblTitleColorNumberF]; [self.contentView addSubview: lblTitleColorNumber]; NSString *colorNumber=[_cartItemModel colorNumber]; if(colorNumber!=nil){ _lblColorNumber=[[UILabel alloc]init]; _lblColorNumber.font=orderTextFont; _lblColorNumber.frame=[orderFrame lblColorNumberF]; _lblColorNumber.text=colorNumber; [self.contentView addSubview:_lblColorNumber]; } NSString *titleSpecification=@"规格:"; UILabel *lblTitleSpecification=[[UILabel alloc]init]; lblTitleSpecification.font=orderTextFont; lblTitleSpecification.text=titleSpecification; lblTitleSpecification.textColor=LabelGrayTextColor; lblTitleSpecification.frame=[orderFrame lblTitleSpecificationF]; [self.contentView addSubview: lblTitleSpecification]; NSString *specification=[_cartItemModel specification]; if(specification!=nil){ _lblSpecification=[[UILabel alloc]init]; _lblSpecification.font=orderTextFont; _lblSpecification.frame=[orderFrame lblSpecificationF]; _lblSpecification.text=specification; [self.contentView addSubview:_lblSpecification]; } NSString *titleGrade=@"等级:"; UILabel *lblTitleGrade=[[UILabel alloc]init]; lblTitleGrade.font=orderTextFont; lblTitleGrade.text=titleGrade; lblTitleGrade.textColor=LabelGrayTextColor; lblTitleGrade.frame=[orderFrame lblTitleGradeF]; [self.contentView addSubview: lblTitleGrade]; NSString *grade=[_cartItemModel gradeName]; if(grade!=nil){ _lblGradeName=[[UILabel alloc]init]; _lblGradeName.font=orderTextFont; _lblGradeName.frame=[orderFrame lblGradeF]; _lblGradeName.text=grade; [self.contentView addSubview:_lblGradeName]; } NSString *titleWareHouse=@"库区:"; UILabel *lblTitleWareHouse=[[UILabel alloc]init]; lblTitleWareHouse.font=orderTextFont; lblTitleWareHouse.text=titleWareHouse; lblTitleWareHouse.textColor=LabelGrayTextColor; lblTitleWareHouse.frame=[orderFrame lblTitleWareHouseAreaF]; [self.contentView addSubview: lblTitleWareHouse]; NSString *warehouse=[_cartItemModel warehouseName]; if(warehouse!=nil){ _lblWarehouseName=[[UILabel alloc]init]; _lblWarehouseName.font=orderTextFont; _lblWarehouseName.frame=[orderFrame lblWareHouseAreaF]; _lblWarehouseName.text=warehouse; [self.contentView addSubview:_lblWarehouseName]; } UIView *middleSeparator=[[UIView alloc]init]; middleSeparator.frame=[orderFrame middleSeparatorF]; middleSeparator.backgroundColor=LineBackgroundColor; [self.contentView addSubview:middleSeparator]; UIView *salesPriceView=[[UIView alloc]init]; salesPriceView.layer.borderWidth=1.0f; salesPriceView.layer.borderColor=[UIColor blackColor].CGColor; salesPriceView.frame=[orderFrame vSalesPriceF]; [self.contentView addSubview: salesPriceView]; UILabel *lblSymbol=[[UILabel alloc]init]; lblSymbol.text=@"¥"; lblSymbol.textColor=LabelGrayTextColor; lblSymbol.frame=CGRectMake(5,5,15,15); lblSymbol.font=orderTextFont; lblSymbol.textAlignment=NSTextAlignmentCenter; [salesPriceView addSubview:lblSymbol]; _txtSalesPrice=[UITextField new]; _txtSalesPrice.frame=CGRectMake(CGRectGetMaxX(lblSymbol.frame)+5, 0, 50, 25); _txtSalesPrice.text=[_cartItemModel salesPrice]; _txtSalesPrice.userInteractionEnabled=YES; _txtSalesPrice.delegate=self; _txtSalesPrice.keyboardType=UIKeyboardTypeDecimalPad; _txtSalesPrice.tag=1001; _txtSalesPrice.textAlignment=NSTextAlignmentCenter; _txtSalesPrice.font=orderTextFont; [salesPriceView addSubview:_txtSalesPrice]; UIImageView *penImg= [[UIImageView alloc]init]; [penImg setImage:[UIImage imageNamed:@"icon_pen"]]; penImg.frame=CGRectMake(salesPriceView.frame.size.width-17,5,12,12); [salesPriceView addSubview:penImg]; UIButton *substractButton=[UIButton buttonWithType:UIButtonTypeCustom]; [substractButton setTitle:@"-" forState:UIControlStateNormal]; [substractButton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal]; substractButton.frame=orderFrame.btnSubstractQuantityF; substractButton.layer.borderColor=[UIColor blackColor].CGColor; substractButton.layer.borderWidth=1.0; [substractButton addTarget:self action:@selector(substractQuantity) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:substractButton]; _txtSalesQuantity=[UITextField new]; _txtSalesQuantity.frame=orderFrame.txtQuantityF; if(_cartItemModel.salesQuantity!=nil){ _txtSalesQuantity.text=_cartItemModel.salesQuantity; } _txtSalesQuantity.delegate=self; _txtSalesQuantity.keyboardType=UIKeyboardTypeDecimalPad; _txtSalesQuantity.layer.borderWidth=1.0f; _txtSalesQuantity.tag=1002; _txtSalesQuantity.textAlignment=NSTextAlignmentCenter; _txtSalesQuantity.layer.borderColor=[UIColor blackColor].CGColor; _txtSalesQuantity.font=orderTextFont; [self.contentView addSubview:_txtSalesQuantity]; UIButton *addButton=[UIButton buttonWithType:UIButtonTypeCustom]; [addButton setTitle:@"+" forState:UIControlStateNormal]; [addButton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal]; addButton.frame=orderFrame.btnAddQuantityF; addButton.layer.borderColor=[UIColor blackColor].CGColor; addButton.layer.borderWidth=1.0; [addButton addTarget:self action:@selector(addQuantity) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:addButton]; UIView *bottomSeparator=[[UIView alloc]init]; bottomSeparator.frame=[orderFrame bottomSeparatorF]; bottomSeparator.backgroundColor=LineBackgroundColor; [self.contentView addSubview:bottomSeparator]; } //订单数量增加函数 -(void)addQuantity{ NSString *quantity=_txtSalesQuantity.text; if(quantity!=nil){ double quantityValue=quantity.doubleValue; NSInteger circulateType= _cartItemModel.circulateType; if(circulateType==2){ [self.delegate alertMessage:@"请手动输入商品数量"]; return; } ++quantityValue; NSString *quantity= [NSString stringWithFormat:@"%lld",(long long)quantityValue]; _txtSalesQuantity.text=quantity; if([self.delegate respondsToSelector:@selector(textValueChange: txtField:)]) { [self.delegate textValueChange:self txtField:_txtSalesQuantity]; } } } //订单数量减少函数 -(void)substractQuantity{ NSString *quantity=_txtSalesQuantity.text; if(quantity!=nil){ double quantityValue=quantity.doubleValue; NSInteger circulateType= _cartItemModel.circulateType; if(circulateType==2){ [self.delegate alertMessage:@"请手动输入商品数量"]; return; } --quantityValue; if(quantityValue<0){ quantityValue=0; } NSString *quantity= [NSString stringWithFormat:@"%lld",(long long)quantityValue]; _txtSalesQuantity.text=quantity; if([self.delegate respondsToSelector:@selector(textValueChange: txtField:)]) { [self.delegate textValueChange:self txtField:_txtSalesQuantity]; } } } @end