| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- //
- // NewRepairDetailListsCell.m
- // IBOSS
- //
- // Created by apple on 16/1/19.
- // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
- //
- //功能描述: 新增维修明细单元格类
- #import "NewRepairDetailListsCell.h"
- #define kTextFont [UIFont systemFontOfSize:LabelAndTextFontOfSize]
- @implementation NewRepairDetailListsCell
- BOOL isHaveDian;
- #pragma 公有函数
- /**
- 单元格选中样式
- @param selected <#selected description#>
- @param animated <#animated description#>
- */
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
-
- }
- /**
- 初始化单元格
- @param style <#style description#>
- @param reuseIdentifier <#reuseIdentifier description#>
- @return <#return value description#>
- */
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- CGFloat w=((Screen_Width-100-22));;
- ////////////////////////
- UILabel *lblOnlyCode = [[UILabel alloc] initWithFrame:CGRectMake(20,5,80,31)];
- lblOnlyCode.textColor = [UIColor blackColor];
- lblOnlyCode.text = @"唯一编码:";
- lblOnlyCode.font=kTextFont;
- lblOnlyCode.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview:lblOnlyCode];
- self.onlyCode = [[UILabel alloc] initWithFrame:CGRectMake(95,5,w,31)];
- self.onlyCode.backgroundColor = [UIColor clearColor];
- self.onlyCode.textColor = [UIColor blackColor];
- self.onlyCode.font=kTextFont;
- self.onlyCode.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview: self.onlyCode];
-
- ////////////////////////
- UILabel *lblCode = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblOnlyCode.frame),80,31)];
- lblCode.textColor = [UIColor blackColor];
- lblCode.text = @"商品编码:";
- lblCode.textAlignment = NSTextAlignmentLeft;
- lblCode.font=kTextFont;
- [self.contentView addSubview:lblCode];
- self.code = [[UILabel alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblOnlyCode.frame),w,31)];
- self.code.backgroundColor = [UIColor clearColor];
- self.code.textColor = [UIColor blackColor];
- self.code.font=kTextFont;
- self.code.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview: self.code];
-
- ////////////////////////品牌
- UILabel *lblBrandName = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblCode.frame),80,31)];
- lblBrandName.backgroundColor = [UIColor clearColor];
- lblBrandName.textColor = [UIColor blackColor];
- lblBrandName.text = @"品 牌:";
- lblBrandName.font=kTextFont;
- lblBrandName.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview:lblBrandName];
- self.brandName = [[UILabel alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblCode.frame),w,31)];
- self.brandName.backgroundColor = [UIColor clearColor];
- self.brandName.textColor = [UIColor blackColor];
- self.brandName.font=kTextFont;
- self.brandName.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview: self.brandName];
-
-
- ////////////////////////维修数量
- UILabel *lblRepairQuantity = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblBrandName.frame),80,31)];
- lblRepairQuantity.backgroundColor = [UIColor clearColor];
- lblRepairQuantity.textColor = [UIColor blackColor];
- lblRepairQuantity.text = @"维修数量:";
- lblRepairQuantity.font=kTextFont;
- lblRepairQuantity.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview:lblRepairQuantity];
- self.repairQuantity = [[UILabel alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblBrandName.frame),w,31)];
- self.repairQuantity.backgroundColor = [UIColor clearColor];
- self.repairQuantity.textColor = [UIColor blackColor];
- self.repairQuantity.font=kTextFont;
- self.repairQuantity.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview: self.repairQuantity];
-
- ////////////////////////完成数量
- UILabel *lblCompleteQuantity = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/2,5+CGRectGetMaxY(lblBrandName.frame),75,31)];
- lblCompleteQuantity.backgroundColor = [UIColor clearColor];
- lblCompleteQuantity.textColor = [UIColor blackColor];
- lblCompleteQuantity.text = @"完成数量:";
- lblCompleteQuantity.font=kTextFont;
- lblCompleteQuantity.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview:lblCompleteQuantity];
- self.completedQuantity = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(lblCompleteQuantity.frame),5+CGRectGetMaxY(lblBrandName.frame),w,31)];
- self.completedQuantity.backgroundColor = [UIColor clearColor];
- self.completedQuantity.textColor = [UIColor blackColor];
- self.completedQuantity.font=kTextFont;
- self.completedQuantity.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview: self.completedQuantity];
-
- ////////////////////////面积
- UILabel *lblAcreage = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblRepairQuantity.frame),80,31)];
- lblAcreage.backgroundColor = [UIColor clearColor];
- lblAcreage.textColor = [UIColor blackColor];
- lblAcreage.text = @"面 积:";
- lblAcreage.font=kTextFont;
- lblAcreage.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview:lblAcreage];
- self.acreage = [[UILabel alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblRepairQuantity.frame),w,31)];
- self.acreage.backgroundColor = [UIColor clearColor];
- self.acreage.font=kTextFont;
- self.acreage.textColor = [UIColor blackColor];
- self.acreage.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview: self.acreage];
- ////////////////////////回执数量
- UILabel *lblReceiptQuantity = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblAcreage.frame),80,31)];
- lblReceiptQuantity.backgroundColor = [UIColor clearColor];
- lblReceiptQuantity.textColor = [UIColor blackColor];
- lblReceiptQuantity.text = @"回执数量:";
- lblReceiptQuantity.font=kTextFont;
- lblReceiptQuantity.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview:lblReceiptQuantity];
- self.receiptQuantity = [[UITextField alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblAcreage.frame),w,31)];
- self.receiptQuantity.backgroundColor = [UIColor clearColor];
- self.receiptQuantity.textColor = [UIColor blackColor];
- self.receiptQuantity.font=kTextFont;
- self.receiptQuantity.textAlignment = NSTextAlignmentLeft;
- self.receiptQuantity.tag=1110;
- self.receiptQuantity.placeholder = @"请输入回执数量";
- self.receiptQuantity.keyboardType=UIKeyboardTypeDecimalPad;
- [self.contentView addSubview: self.receiptQuantity];
- ////////////////////////回执备注
- UILabel *lblRemark = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblReceiptQuantity.frame),80,31)];
- lblRemark.backgroundColor = [UIColor clearColor];
- lblRemark.textColor = [UIColor blackColor];
- lblRemark.text = @"回执备注:";
- lblRemark.font=kTextFont;
- lblRemark.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview:lblRemark];
- self.remark = [[UITextField alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblReceiptQuantity.frame),w,31)];
- self.remark.backgroundColor = [UIColor clearColor];
- self.remark.tag=1111;
- self.remark.font=kTextFont;
- self.remark.placeholder = @"请输入回执备注";
- self.remark.textColor = [UIColor blackColor];
- self.remark.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview: self.remark];
- UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 5+CGRectGetMaxY(self.remark.frame), SCREENWIDTH, 5)];
- line.backgroundColor = [UIColor colorWithRed:234.0/255 green:235.0/255 blue:236.0/255 alpha:1];
- [self.contentView addSubview: line];
-
- _cellHeight=CGRectGetMaxY(line.frame);
-
- [self.receiptQuantity addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- [self.remark addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
-
- self.receiptQuantity.delegate=self;
- self.remark.delegate=self;
-
- }
- return self;
- }
- #pragma 委托函数
- /**
- 文本开始编辑函数
- @param textField <#textField description#>
- */
- - (void)textFieldDidBeginEditing:(UITextField *)textField{
-
- if([textField isEqual:self.remark] ){
- if([self.delegate respondsToSelector:@selector(keyboardWillShow:)])
- {
- [self.delegate keyboardWillShow:self];
- }
- }
- }
- /**
- 文本结束编辑函数
- @param textField <#textField description#>
- */
- - (void)textFieldDidEndEditing:(UITextField *)textField{
-
- if([textField isEqual:self.remark]){
- //[self.remark resignFirstResponder];
- if([self.delegate respondsToSelector:@selector(keyboardWillHide:)])
- {
- [self.delegate keyboardWillHide:self];
- }
-
- return ;
- }
- if([self.delegate respondsToSelector:@selector(endEdit:)])
- {
- [self.delegate endEdit:self];
- }
- }
- /**
- 限制小数位数
- @param textField <#textField description#>
- @param range <#range description#>
- @param string <#string description#>
- @return <#return value description#>
- */
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
- NSLog(@"shouldChangeCharactersInRange");
- if([textField isEqual:self.remark]){
- if (range.location >= 100){
- return NO;
- }
- }
-
-
- if(textField == self.receiptQuantity)
- {
- if (range.location >= 17){
- return NO;
- }
-
- if ([textField.text rangeOfString:@"."].location == NSNotFound) {
- isHaveDian = NO;
- }else{
- isHaveDian=YES;
- }
- if ([string length] > 0) {
-
- unichar single = [string characterAtIndex:0];//当前输入的字符
- if ((single >= '0' && single <= '9') || single == '.') {//数据格式正确
- //首字母不能为0和小数点
- if([textField.text length] == 0){
- if(single == '.') {
- [self showAlertViewText:@"第一个数字不能为小数点"];
- [textField.text stringByReplacingCharactersInRange:range withString:@""];
- return NO;
- }
-
- }
- if([textField.text length] == 1 && [[textField.text substringToIndex:1] isEqualToString: @"0"]){
- if(!(single == '.')) {
- [textField.text stringByReplacingCharactersInRange:range withString:@""];
- return NO;
- }
-
- }
-
- //输入的字符是否是小数点
- if (single == '.') {
- if(!isHaveDian)//text中还没有小数点
- {
- isHaveDian = YES;
- return YES;
-
- }else{
- [self showAlertViewText:@"您已经输入过小数点了"];
- [textField.text stringByReplacingCharactersInRange:range withString:@""];
- return NO;
- }
- }else{
- if (isHaveDian) {//存在小数点
-
- //判断小数点的位数
- NSRange ran = [textField.text rangeOfString:@"."];
- if (range.location - ran.location <= 6) {
- return YES;
- }else{
- //[self showAlertViewText:@"亲,您最多输入两位小数"];
- return NO;
- }
- }else{
- return YES;
- }
- }
- }else{//输入的数据格式不正确
- [self showAlertViewText:@"您输入的格式不正确"];
- [textField.text stringByReplacingCharactersInRange:range withString:@""];
- return NO;
- }
- }
- else
- {
- return YES;
- }
- }
-
- return YES;
- }
- #pragma 私有函数
- /**
- 设置新增维修单元格frame
- @param model <#model description#>
- */
- - (void)parseInfoModel:(NewRepairItemModel*)model{
- if(model != nil){
- self.repairId=model.repairId;
- self.detailId=model.detailId;
- self.salesDetailId=model.salesDetailId;
- self.code.text=model.code;
- self.onlyCode.text=model.onlyCode;
- self.repairQuantity.text=model.repairQuantity;
- self.completedQuantity.text=model.completeQuantity;
- self.brandName.text=model.brandName;
- self.acreage.text=model.acreage;
- self.receiptQuantity.text=model.receiptQuantity;
- self.remark.text=model.remarks;
- self.receiptQuantity.enabled=!model.isDelay;
- self.remark.enabled=!model.isDelay;
- }
- }
- /**
- 文本字段变化函数
- @param sender <#sender description#>
- */
- - (void)textFieldDidChange:(UITextField*) sender{
- NSLog(@"textFieldDidChange");
- UITextField* txt=sender;
- switch (txt.tag) {
- case 1110:
- {
- }
- break;
- case 1111:
- {
- }
- break;
- default:
- break;
- }
- if([self.delegate respondsToSelector:@selector(textValueChange:txtField:qualityField:remarkField:)])
- {
- [self.delegate textValueChange:self txtField:txt qualityField:self.receiptQuantity remarkField:self.remark];
- }
- }
- /**
- 出示警告对话框
- @param text <#text description#>
- */
- - (void)showAlertViewText:(NSString *)text
- {
- UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
- message:text
- delegate:nil
- cancelButtonTitle:@"确定"
- otherButtonTitles:nil];
- [alert show];
- }
- @end
|