| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- //
- // NewSalesExternalCoordinateCell.m
- // IBOSSmini
- //
- // Created by ssl on 2018/2/27.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "NewSalesExternalCoordinateCell.h"
- #define orderTextFont [UIFont systemFontOfSize:13]
- @implementation NewSalesExternalCoordinateCell
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
-
- return self;
- }
- - (void)setNewExternalCoordinateGoodsCell:(ExternalCoordinateGoodsModel *)externalCoordinateGoodsModel editStatus:(NSInteger) editStatus editFlag:(NSInteger) editFlag{
- _externalCoordinateModel=externalCoordinateGoodsModel;
- CGFloat heightLine = 1;
- CGFloat lblx = 20;
- CGFloat valuey = 10;
- CGFloat valueheight = 25;
-
- _lblSupplier = [UILabel new];
- _lblSupplier.frame=CGRectMake(lblx, valuey, Screen_Width- lblx- 70, valueheight);
- _lblSupplier.font =orderTextFont;
- [self addSubview:_lblSupplier];
- _lblSupplier.text = _externalCoordinateModel.supplierName;
-
- _vDelete=[UIView new];
- _vDelete.frame=CGRectMake(Screen_Width-65, valuey,70 , valueheight);
-
- UIButton *btnDelete=[UIButton buttonWithType:UIButtonTypeCustom];
- btnDelete.frame=CGRectMake(0, 4,15, 15);
- UIImageView *deleteImg=[[UIImageView alloc]init];
- deleteImg.frame=CGRectMake(0,0,15,15);
- [deleteImg setImage:[UIImage imageNamed:@"icon_delete"]];
- deleteImg.userInteractionEnabled=NO;
- [btnDelete addSubview:deleteImg];
- [_vDelete addSubview:btnDelete];
- UILabel *lblDelete=[UILabel new];
- lblDelete.text=@"删除";
- lblDelete.frame=CGRectMake(CGRectGetMaxX(btnDelete.frame)+3, 0,30, 25);
- lblDelete.font=orderTextFont;
- [_vDelete addSubview:lblDelete];
- [self addSubview:_vDelete];
- UITapGestureRecognizer *tapRecognizerDelete=[[UITapGestureRecognizer alloc] initWithTarget:self
- action:@selector(deleteOrder)];
- _vDelete.userInteractionEnabled=YES;
- [_vDelete addGestureRecognizer:tapRecognizerDelete];
- _vDelete.userInteractionEnabled=YES;
- _topSeparator=[UIView new];
- _topSeparator.frame=CGRectMake(0, CGRectGetMaxY(_vDelete.frame)+valuey, Screen_Width, heightLine);
- _topSeparator.backgroundColor=LineBackgroundColor;
- [self addSubview:_topSeparator];
-
- UILabel *lblGoodsCodeTitle=[UILabel new];
- lblGoodsCodeTitle.frame=CGRectMake(lblx,CGRectGetMaxY(_topSeparator.frame)+valuey,70, valueheight);
- lblGoodsCodeTitle.text=@"商品编码:";
- lblGoodsCodeTitle.font=orderTextFont;
- lblGoodsCodeTitle.textColor=LabelGrayTextColor;
- [self addSubview:lblGoodsCodeTitle];
- _lblGoodsCode=[UILabel new];
- NSString *goodsCode=_externalCoordinateModel.goodsCode;
- if(goodsCode!=nil){
- _lblGoodsCode.frame=CGRectMake(CGRectGetMaxX(lblGoodsCodeTitle.frame), CGRectGetMaxY(_topSeparator.frame)+valuey,Screen_Width/2-CGRectGetMaxX(lblGoodsCodeTitle.frame)-3, valueheight);
- _lblGoodsCode.text=goodsCode;
- _lblGoodsCode.font=orderTextFont;
- [self addSubview:_lblGoodsCode];
- }
-
- UILabel *lblOnlyCodeTitle=[UILabel new];
- lblOnlyCodeTitle.frame=CGRectMake(Screen_Width/2,CGRectGetMaxY(_topSeparator.frame)+valuey,70, valueheight);
- lblOnlyCodeTitle.text=@"唯一编码:";
- lblOnlyCodeTitle.font=orderTextFont;
- lblOnlyCodeTitle.textColor=LabelGrayTextColor;
- [self addSubview:lblOnlyCodeTitle];
- NSString *onlyCode=_externalCoordinateModel.onlyCode;
- if(onlyCode!=nil){
- _lblOnlyCode=[UILabel new];
- _lblOnlyCode.frame=CGRectMake(CGRectGetMaxX(lblOnlyCodeTitle.frame),CGRectGetMaxY(_topSeparator.frame)+valuey , Screen_Width/2-lblOnlyCodeTitle.frame.size.width-3, valueheight);
- _lblOnlyCode.text=onlyCode;
- _lblOnlyCode.font=orderTextFont;
- [self addSubview:_lblOnlyCode];
- }
-
- UILabel *lblColorNumberTitle=[UILabel new];
- lblColorNumberTitle.frame=CGRectMake(lblx, CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey,70, valueheight);
- lblColorNumberTitle.text=@"色号:";
- lblColorNumberTitle.font=orderTextFont;
- [lblColorNumberTitle sizeToFit];
- lblColorNumberTitle.textColor=LabelGrayTextColor;
- [self addSubview:lblColorNumberTitle];
- NSString *colorNumber=[_externalCoordinateModel colorNumber];
- if(colorNumber!=nil){
- _lblColorNumber=[UILabel new];
- _lblColorNumber.frame=CGRectMake(CGRectGetMaxX(lblColorNumberTitle.frame), CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey/2,Screen_Width/3-CGRectGetMaxX(lblColorNumberTitle.frame), valueheight);
- _lblColorNumber.font=orderTextFont;
- _lblColorNumber.text=colorNumber;
- [self addSubview:_lblColorNumber];
- }
-
- UILabel *lblSpecificationTitle=[UILabel new];
- lblSpecificationTitle.frame=CGRectMake(Screen_Width/3,CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey,70, valueheight);
- lblSpecificationTitle.text=@"规格:";
- lblSpecificationTitle.font=orderTextFont;
- [lblSpecificationTitle sizeToFit];
- lblSpecificationTitle.textColor=LabelGrayTextColor;
- [self addSubview:lblSpecificationTitle];
-
- NSString *specification=_externalCoordinateModel.specification;
- if(specification!=nil){
- _lblSpecification=[UILabel new];
- _lblSpecification.frame=CGRectMake(CGRectGetMaxX(lblSpecificationTitle.frame), CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey/2, Screen_Width/3-lblSpecificationTitle.frame.size.width-3, valueheight);
- _lblSpecification.text=specification;
- _lblSpecification.font=orderTextFont;
- [self addSubview:_lblSpecification];
- }
-
-
- UILabel *lblGradeTitle=[UILabel new];
- lblGradeTitle.frame=CGRectMake(Screen_Width/3*2,CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey,70, valueheight);
- lblGradeTitle.text=@"等级:";
- lblGradeTitle.font=orderTextFont;
- [lblGradeTitle sizeToFit];
- lblGradeTitle.textColor=LabelGrayTextColor;
- [self addSubview:lblGradeTitle];
-
- NSString *grade=_externalCoordinateModel.gradeName;
- if(grade!=nil){
- _lblGrade=[UILabel new];
- _lblGrade.frame=CGRectMake(CGRectGetMaxX(lblGradeTitle.frame), CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey/2, Screen_Width/3-lblGradeTitle.frame.size.width-3, valueheight);
- _lblGrade.text=grade;
- _lblGrade.font=orderTextFont;
- [self addSubview:_lblGrade];
- }
-
- _middleSeparator=[UIView new];
- _middleSeparator.frame=CGRectMake(0, CGRectGetMaxY(lblColorNumberTitle.frame)+valuey, Screen_Width, heightLine);
- _middleSeparator.backgroundColor=LineBackgroundColor;
- [self addSubview:_middleSeparator];
-
- _lblDiscount= [[UILabel alloc] init];
- [self updateFrame];
- [self addSubview:_lblDiscount];
-
- UIView *salesPriceView=[[UIView alloc]init];
- salesPriceView.layer.borderWidth=1.0f;
- salesPriceView.layer.borderColor=[LabelGrayTextColor CGColor];
- salesPriceView.frame=CGRectMake(Screen_Width-300, CGRectGetMaxY(_lblDiscount.frame)+10, 130,25 );
- [self 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];
- NSString *salesPrice=_externalCoordinateModel.salesPrice;
- _txtSalesPrice=[UITextField new];
- _txtSalesPrice.frame=CGRectMake(CGRectGetMaxX(lblSymbol.frame), 0, 100, 25);
- _txtSalesPrice.text=salesPrice;
- _txtSalesPrice.userInteractionEnabled=YES;
- _txtSalesPrice.delegate=self;
- _txtSalesPrice.keyboardType=UIKeyboardTypeDecimalPad;
- _txtSalesPrice.tag=1001;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFocusPeopleEditingChanged:) name:@"UITextFieldTextDidChangeNotification" object:_txtSalesPrice ];
- _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=CGRectMake(CGRectGetMaxX(salesPriceView.frame)+10,CGRectGetMaxY(_lblDiscount.frame)+10,25,25);
- substractButton.layer.borderColor=[LabelGrayTextColor CGColor];
- substractButton.layer.borderWidth=1.0;
- [substractButton addTarget:self action:@selector(substractQuantity) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:substractButton];
- _txtSalesQuantity=[UITextField new];
- _txtSalesQuantity.frame=CGRectMake(CGRectGetMaxX(substractButton.frame)-1,CGRectGetMaxY(_lblDiscount.frame)+10,100,25);
- double salesQuantity= _externalCoordinateModel.salesQuantity;
- _txtSalesQuantity.text=[NSString stringWithFormat:@"%.2lf",salesQuantity];
- _txtSalesQuantity.delegate=self;
- _txtSalesQuantity.keyboardType=UIKeyboardTypeDecimalPad;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFocusPeopleEditingChanged:) name:@"UITextFieldTextDidChangeNotification" object:_txtSalesQuantity ];
- _txtSalesQuantity.layer.borderWidth=1.0f;
- _txtSalesQuantity.tag=1002;
- _txtSalesQuantity.textAlignment=NSTextAlignmentCenter;
- _txtSalesQuantity.layer.borderColor=[LabelGrayTextColor CGColor];
- _txtSalesQuantity.font=orderTextFont;
- [self addSubview:_txtSalesQuantity];
-
- UIButton *addButton=[UIButton buttonWithType:UIButtonTypeCustom];
- [addButton setTitle:@"+" forState:UIControlStateNormal];
- [addButton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
- addButton.frame=CGRectMake(CGRectGetMaxX(_txtSalesQuantity.frame)-1,CGRectGetMaxY(_lblDiscount.frame)+10,25,25);;
- addButton.layer.borderColor=[LabelGrayTextColor CGColor];
- addButton.layer.borderWidth=1.0;
- [addButton addTarget:self action:@selector(addQuantity) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:addButton];
-
- UIView *bottomSeparator=[[UIView alloc]init];
- bottomSeparator.frame=CGRectMake(0,CGRectGetMaxY(salesPriceView.frame)+10,Screen_Width, 10);
- bottomSeparator.backgroundColor=LineBackgroundColor;
- [self addSubview:bottomSeparator];
-
- if(editStatus==5){
- _txtSalesPrice.enabled=NO;
- _vDelete.userInteractionEnabled=NO;
- addButton.userInteractionEnabled=NO;
- substractButton.userInteractionEnabled=NO;
- _txtSalesQuantity.enabled=NO;
- }
- else if(editStatus==7||editStatus==10){
- _txtSalesPrice.enabled=NO;
- _vDelete.userInteractionEnabled=NO;
- addButton.userInteractionEnabled=NO;
- substractButton.userInteractionEnabled=NO;
- _txtSalesQuantity.enabled=NO;
- }else if (editStatus==4){
- _txtSalesPrice.enabled=NO;
- _vDelete.userInteractionEnabled=NO;
- addButton.userInteractionEnabled=NO;
- substractButton.userInteractionEnabled=NO;
- _txtSalesQuantity.enabled=NO;
- }
- if (editFlag==3){
- _txtSalesPrice.enabled=NO;
- _vDelete.userInteractionEnabled=NO;
- }
- }
- /**
- textField失去焦点回调函数
- */
- - (void) textFieldDidEndEditing:(UITextField *) field
- {
- [self endEditing:YES];
-
- if(field.tag==1001){
- NSString *salesPrice=field.text;
- if(salesPrice==nil||[salesPrice isEqualToString:@""]||[salesPrice isEqualToString:@"."]){
- field.text = _externalCoordinateModel.salesPrice;
- return;
- }
- _externalCoordinateModel.salesPrice=salesPrice;
-
- double markedPrice= [ _externalCoordinateModel.markedPrice doubleValue];
- if(salesPrice!=nil){
- if(markedPrice!=0){
- double discountValue=[salesPrice doubleValue]/markedPrice*100;
- _externalCoordinateModel.discount=[NSString stringWithFormat:@"%.2f",discountValue];
- }
-
- else{
- _externalCoordinateModel.discount=@"100";
- }
- }
- else{
- if(markedPrice!=0){
- _externalCoordinateModel.discount=@"0.0";
- }
- else{
- _externalCoordinateModel.discount=@"100";
- }
- }
-
- [self updateFrame];
-
- }
- else if(field.tag==1002){
- NSString *salesQuantity=field.text;
- if(salesQuantity==nil||[salesQuantity isEqualToString:@""]||[salesQuantity isEqualToString:@"."]){
- field.text = [NSString stringWithFormat:@"%.2f",_externalCoordinateModel.salesQuantity];
- return;
- }
- _externalCoordinateModel.salesQuantity=[salesQuantity doubleValue];
- field.text = salesQuantity;
- }
-
- if([self.orderDelegate respondsToSelector:@selector(updateNewSalesExternalCoordinateGoodsCell:textField:)])
- {
- [self.orderDelegate updateNewSalesExternalCoordinateGoodsCell:self textField:field];
-
- }
-
-
-
- }
- -(void)deleteOrder{
- if([self.orderDelegate respondsToSelector:@selector(deleteOrderDetail:)])
- {
- [self.orderDelegate deleteOrderDetail:_cellIndex];
-
- }
-
- }
- -(void)addQuantity{
- [self endEditing:YES];
- NSString *salesQuantity=_txtSalesQuantity.text;
- if(salesQuantity!=nil){
- double quantity=[salesQuantity doubleValue];
- ++quantity;
- NSString *salesQuantityStr= [NSString stringWithFormat:@"%.2f",quantity];
- _txtSalesQuantity.text=salesQuantityStr;
- _externalCoordinateModel.salesQuantity=quantity;
- if([self.orderDelegate respondsToSelector:@selector(updateNewSalesExternalCoordinateGoodsCell:textField:)])
- {
- [self.orderDelegate updateNewSalesExternalCoordinateGoodsCell:self textField:_txtSalesQuantity];
-
- }
- }
- }
- -(void)substractQuantity{
- [self endEditing:YES];
- NSString *salesQuantity=_txtSalesQuantity.text;
- if(salesQuantity!=nil){
- double quantity=[salesQuantity doubleValue];
- --quantity;
- if(quantity<0){
- quantity=0;
- }
- NSString *salesQuantityStr= [NSString stringWithFormat:@"%.2f",quantity];
- _txtSalesQuantity.text=salesQuantityStr;
- _externalCoordinateModel.salesQuantity=quantity;
- if([self.orderDelegate respondsToSelector:@selector(updateNewSalesExternalCoordinateGoodsCell:textField:)])
- {
- [self.orderDelegate updateNewSalesExternalCoordinateGoodsCell:self textField:_txtSalesQuantity];
-
- }
- }
- }
- /**
- 文本框的长度限制 实现监听方法
-
- @param sender <#sender description#>
- */
- - (void)onFocusPeopleEditingChanged:(NSNotification *)sender
- {
-
- UITextField *textField = (UITextField *)sender.object;
- NSString *toBeString = textField.text;
-
- NSString *lang = [[UIApplication sharedApplication]textInputMode].primaryLanguage;
- int kMaxLength = 0;
- if([textField isEqual:_txtSalesQuantity]){
- kMaxLength = 9;
-
- if (toBeString != nil && toBeString.length > 0 && [toBeString floatValue] -999999.99 > 0.0000000001f) {
- textField.text =@"999999.99";
- toBeString =@"999999.99" ;
- }
-
- }
-
- if([textField isEqual:_txtSalesPrice]){
- kMaxLength = 11;
-
- if (toBeString != nil && toBeString.length > 0 && [toBeString floatValue] -999999.9999 > 0.0000000001f) {
- textField.text =@"999999.9999";
- toBeString =@"999999.9999" ;
- }
-
- }
-
-
- if ([lang isEqualToString:@"zh-Hans"]) {
- UITextRange *selectedRange = [textField markedTextRange];
- UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
-
- if (!position) {
- if (toBeString.length > kMaxLength) {
- textField.text = [toBeString substringToIndex:kMaxLength];
- }
- }
- }else{
- if (toBeString.length > kMaxLength) {
- textField.text = [toBeString substringToIndex:kMaxLength];
- }
- }
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
-
- }
- /**
- 更新标价和折扣
- */
- - (void) updateFrame{
- NSString *discount=_externalCoordinateModel.discount;
- if(discount==nil){
- discount=@"0.0%";
- }
- else{
- discount=[NSString stringWithFormat:@"%@%@",discount,@"%"];
- }
-
- NSString *markedPrice=_externalCoordinateModel.markedPrice;
-
- _lblDiscount.text = [NSString stringWithFormat:@"标价:%@ 折扣:%@",markedPrice,discount];
- _lblDiscount.font = [UIFont systemFontOfSize:13];
- _lblDiscount.textColor = [UIColor redColor];
- [_lblDiscount sizeToFit];
-
- _lblDiscount.frame = CGRectMake(Screen_Width-CGRectGetWidth(_lblDiscount.frame)-10, CGRectGetMaxY(_middleSeparator.frame)+10, CGRectGetWidth(_lblDiscount.frame), CGRectGetHeight(_lblDiscount.frame));
- }
- @end
|