|
|
@@ -0,0 +1,665 @@
|
|
|
+//
|
|
|
+// DeviceFormView.m
|
|
|
+// shiku_im
|
|
|
+//
|
|
|
+// Created by huangyp-pc on 2019/6/20.
|
|
|
+//
|
|
|
+
|
|
|
+#import "DeviceFormView.h"
|
|
|
+#import <objc/runtime.h>
|
|
|
+#import "DocumentCell.h"
|
|
|
+#import "MoreGridModel.h"
|
|
|
+
|
|
|
+@implementation UITableView(data)
|
|
|
+
|
|
|
+-(void)setDataArray:(NSMutableArray *)dataArray{
|
|
|
+ objc_setAssociatedObject(self, @"UITableViewDataArray", dataArray, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
+ [self reloadData];
|
|
|
+}
|
|
|
+
|
|
|
+-(NSMutableArray *)dataArray{
|
|
|
+ return objc_getAssociatedObject(self, @"UITableViewDataArray");
|
|
|
+}
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@interface DeviceFormView()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,HypTextViewDelegate>
|
|
|
+@property(strong,nonatomic)UIScrollView *scorlView;
|
|
|
+@property(strong,nonatomic)HMSegmentedControl *segment;
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation DeviceFormView
|
|
|
+- (instancetype)initWithFrame:(CGRect)frame
|
|
|
+{
|
|
|
+ self = [super initWithFrame:frame];
|
|
|
+ if (self) {
|
|
|
+
|
|
|
+ [self createUI];
|
|
|
+
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
+-(void)createUI{
|
|
|
+
|
|
|
+ self.backgroundColor = BGB_COLOR;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- UITableViewDelegate / DataSource
|
|
|
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
|
+{
|
|
|
+ return tableView.dataArray.count;
|
|
|
+}
|
|
|
+
|
|
|
+// 每组多少行
|
|
|
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
+{
|
|
|
+ MoreGridModel *model = tableView.dataArray[section];
|
|
|
+ return [model.showItems count];
|
|
|
+}
|
|
|
+
|
|
|
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
+{
|
|
|
+
|
|
|
+ NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%ld%ld", (long)[indexPath section], (long)[indexPath row]];//以indexPath来唯一确定cell
|
|
|
+ DocumentCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell
|
|
|
+ if (cell == nil) {
|
|
|
+ cell = [[DocumentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
|
|
|
+ }
|
|
|
+
|
|
|
+ //...其他代码
|
|
|
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
+
|
|
|
+ cell.MyTextView.tag = indexPath.row + indexPath.section*1000;
|
|
|
+
|
|
|
+ cell.MyTextView.objTag = tableView.tag;
|
|
|
+
|
|
|
+ cell.MyTextView.delegate = self;
|
|
|
+
|
|
|
+ cell.MyTextView.block = ^(NSString *textViewHeight, NSString *row) {
|
|
|
+ [tableView beginUpdates];
|
|
|
+ int a = [row integerValue] / 1000;
|
|
|
+ int b = [row integerValue] % 1000;
|
|
|
+
|
|
|
+ id obj = tableView.dataArray[a];
|
|
|
+ if ([obj isKindOfClass:[MoreGridModel class]]) {
|
|
|
+ MoreGridModel *model1 = tableView.dataArray[a];
|
|
|
+ DetailgridModel *detailModel1 = model1.showItems[b];
|
|
|
+
|
|
|
+ if ([textViewHeight isEqualToString:@"32"]) {
|
|
|
+ detailModel1.cellHeight = @"40";
|
|
|
+ }else
|
|
|
+ detailModel1.cellHeight = textViewHeight;
|
|
|
+ }else{
|
|
|
+ FormModel *model1 = tableView.dataArray[a];
|
|
|
+ DetailFormModel *detailModel1 = model1.showItems[b];
|
|
|
+
|
|
|
+ if ([textViewHeight isEqualToString:@"32"]) {
|
|
|
+ detailModel1.cellHeight = @"40";
|
|
|
+ }else
|
|
|
+ detailModel1.cellHeight = textViewHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ [tableView endUpdates];
|
|
|
+ };
|
|
|
+
|
|
|
+ id obj = tableView.dataArray[indexPath.section];
|
|
|
+
|
|
|
+ NSString *titleName = @"";//名字
|
|
|
+ NSString *str = @"";//类型
|
|
|
+ NSString *field = @"";//key值
|
|
|
+ NSString *length = @"";//长度
|
|
|
+ NSString *allowblank = @"";//是否必填(是否允许为空)
|
|
|
+ NSString *readonly = @"";//是否只读
|
|
|
+ NSString *renderer = @"";//判断是否为附件
|
|
|
+ if ([obj isKindOfClass:[MoreGridModel class]]) {
|
|
|
+ MoreGridModel *model = tableView.dataArray[indexPath.section];
|
|
|
+ DetailgridModel *detailModel = model.showItems[indexPath.row];
|
|
|
+ cell.MyTextView.text = detailModel.dg_value;
|
|
|
+
|
|
|
+ CGRect frame = cell.titleName.frame;
|
|
|
+ frame.size.height = [detailModel.cellHeight floatValue];
|
|
|
+ cell.titleName.frame = frame;
|
|
|
+
|
|
|
+ titleName = [NSString stringWithFormat:@"%@",detailModel.dg_caption];
|
|
|
+ str = [NSString stringWithFormat:@"%@",detailModel.dg_type];
|
|
|
+ field = [NSString stringWithFormat:@"%@",detailModel.dg_field];
|
|
|
+ length = [NSString stringWithFormat:@"%@",detailModel.dg_maxlength];
|
|
|
+ allowblank = [NSString stringWithFormat:@"%@",detailModel.dg_logictype];
|
|
|
+ readonly = [NSString stringWithFormat:@"%@",detailModel.dg_editable];
|
|
|
+ renderer = [NSString stringWithFormat:@"%@",detailModel.dg_renderer];
|
|
|
+ }else{
|
|
|
+ FormModel *model = tableView.dataArray[indexPath.section];
|
|
|
+ DetailFormModel *detailModel = model.showItems[indexPath.row];
|
|
|
+ cell.MyTextView.text = detailModel.fd_value;
|
|
|
+
|
|
|
+ CGRect frame = cell.titleName.frame;
|
|
|
+ frame.size.height = [detailModel.cellHeight floatValue];
|
|
|
+ cell.titleName.frame = frame;
|
|
|
+
|
|
|
+ titleName = [NSString stringWithFormat:@"%@",detailModel.fd_caption];
|
|
|
+ str = [NSString stringWithFormat:@"%@",detailModel.fd_type];
|
|
|
+ field = [NSString stringWithFormat:@"%@",detailModel.fd_field];
|
|
|
+ length = [NSString stringWithFormat:@"%@",detailModel.fd_maxlength];
|
|
|
+ allowblank = [NSString stringWithFormat:@"%@",detailModel.fd_logictype];
|
|
|
+ readonly = [NSString stringWithFormat:@"%@",detailModel.fd_readonly];
|
|
|
+ }
|
|
|
+
|
|
|
+ /*富文本,为了必填项的红色“*”*/
|
|
|
+ NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:FORMAT(@"%@*",titleName)];
|
|
|
+ [AttributedStr addAttribute:NSForegroundColorAttributeName
|
|
|
+ value:[UIColor redColor]
|
|
|
+ range:NSMakeRange(titleName.length, 1)];
|
|
|
+
|
|
|
+ if ([allowblank isEqualToString:@"F"]) {/*必填项*/
|
|
|
+ if ([str isEqualToString:@"C"] ||[str isEqualToString:@"SF"] ||[str isEqualToString:@"MF"] ||[str isEqualToString:@"D"] ||[str isEqualToString:@"DF"]) {
|
|
|
+ cell.MyTextView.placeholder = @"请选择";
|
|
|
+ }else{
|
|
|
+ cell.MyTextView.placeholder = @"请输入";
|
|
|
+ }
|
|
|
+ cell.titleName.attributedText = AttributedStr;
|
|
|
+ }
|
|
|
+ else if ([allowblank isEqualToString:@"necessaryField"]) {/*必填项*/
|
|
|
+ if ([str isEqualToString:@"C"] ||[str isEqualToString:@"SF"] ||[str isEqualToString:@"MF"] ||[str isEqualToString:@"D"] ||[str isEqualToString:@"DF"]) {
|
|
|
+ cell.MyTextView.placeholder = @"请选择";
|
|
|
+ }else{
|
|
|
+ cell.MyTextView.placeholder = @"请输入";
|
|
|
+ }
|
|
|
+ cell.titleName.attributedText = AttributedStr;
|
|
|
+ }
|
|
|
+ else if ([allowblank isEqualToString:@"T"]) {
|
|
|
+ if ([str isEqualToString:@"C"] ||[str isEqualToString:@"SF"] ||[str isEqualToString:@"MF"] ||[str isEqualToString:@"D"] ||[str isEqualToString:@"DF"]) {
|
|
|
+ cell.MyTextView.placeholder = @"请选择";
|
|
|
+ }else{
|
|
|
+ cell.MyTextView.placeholder = @"请输入";
|
|
|
+ }
|
|
|
+ cell.titleName.text = titleName;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ if ([str isEqualToString:@"C"] ||[str isEqualToString:@"SF"] ||[str isEqualToString:@"MF"] ||[str isEqualToString:@"D"] ||[str isEqualToString:@"DF"]) {
|
|
|
+ cell.MyTextView.placeholder = @"请选择";
|
|
|
+ }else{
|
|
|
+ cell.MyTextView.placeholder = @"请输入";
|
|
|
+ }
|
|
|
+ cell.titleName.text = titleName;
|
|
|
+ }
|
|
|
+
|
|
|
+ //T只读,F非只读,默认非只读
|
|
|
+ if ([readonly isEqualToString:@"T"]) {
|
|
|
+
|
|
|
+ cell.MyTextView.userInteractionEnabled = NO;
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ cell.MyTextView.userInteractionEnabled = YES;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_statuType == Editing) {
|
|
|
+ cell.MyTextView.userInteractionEnabled = NO;
|
|
|
+ cell.MyTextView.placeholder = @"";
|
|
|
+ }
|
|
|
+
|
|
|
+ //附件判断-可点击查看附件
|
|
|
+ if ([renderer isEqualToString:@"detailAttach"] || [str isEqualToString:@"FF"]) {
|
|
|
+ cell.MyTextView.userInteractionEnabled = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ SLog(@"多明细的类型:%@ -- 名字:%@ -- 第几个:%ld -- key:%@ -- 是否只读:%@ -- 长度:%@ -- 是否必填:%@",str,titleName,(long)cell.MyTextView.tag,field,readonly,length,allowblank);
|
|
|
+
|
|
|
+ return cell;
|
|
|
+}
|
|
|
+
|
|
|
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
+{
|
|
|
+ id obj = tableView.dataArray[indexPath.section];
|
|
|
+ if ([obj isKindOfClass:[MoreGridModel class]]) {
|
|
|
+ MoreGridModel *model = tableView.dataArray[indexPath.section];
|
|
|
+ DetailgridModel *detailModel = model.showItems[indexPath.row];
|
|
|
+ return [detailModel.cellHeight floatValue];
|
|
|
+ }else{
|
|
|
+ FormModel *model = tableView.dataArray[indexPath.section];
|
|
|
+ DetailFormModel *detailModel = model.showItems[indexPath.row];
|
|
|
+ return [detailModel.cellHeight floatValue];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
|
|
+{
|
|
|
+ if (_statuType == Editing) {
|
|
|
+ return 10;
|
|
|
+ }else
|
|
|
+ return 40;
|
|
|
+}
|
|
|
+
|
|
|
+-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
|
|
+{
|
|
|
+ return CGFLOAT_MIN;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
|
|
|
+{
|
|
|
+ UIView *headerView = [[UIView alloc] init];
|
|
|
+ headerView.userInteractionEnabled = YES;
|
|
|
+ headerView.backgroundColor = [UIColor clearColor];
|
|
|
+
|
|
|
+ UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 4, SCREEN_WIDTH, 40)];
|
|
|
+ lbl.text = [NSString stringWithFormat:@" 明细%ld",(long)section+1];
|
|
|
+ lbl.backgroundColor = Color(250, 249, 249, 1);
|
|
|
+ lbl.textColor = HexColor(@"#1084D1");
|
|
|
+ lbl.font = FONT_SIZE(13);
|
|
|
+// [headerView addSubview:lbl];
|
|
|
+
|
|
|
+ if (_statuType != Editing) {
|
|
|
+ if (section != 0) {
|
|
|
+ UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ deleteBtn.frame = CGRectMake(SCREEN_WIDTH-60, 4, 60, 40);
|
|
|
+ deleteBtn.tag = section;
|
|
|
+ [deleteBtn addTarget:self action:@selector(deleteMoreCongBiao:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ objc_setAssociatedObject(deleteBtn, "firstObject", tableView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
+ objc_setAssociatedObject(deleteBtn, "secondObject", @(section), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
+ [headerView addSubview:deleteBtn];
|
|
|
+
|
|
|
+ UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 40)];
|
|
|
+ lbl.text = @"删除";
|
|
|
+ lbl.backgroundColor = Color(250, 249, 249, 1);
|
|
|
+ lbl.textColor = Color(47, 149, 221, 1);
|
|
|
+ lbl.textAlignment = NSTextAlignmentRight;
|
|
|
+ lbl.font = FONT_SIZE(13);
|
|
|
+ [deleteBtn addSubview:lbl];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return headerView;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
|
|
|
+{
|
|
|
+ return nil;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- HypTextView代理
|
|
|
+- (void)HypTextView:(HypTextView *)HypTextView textDidChanged:(NSString *)text
|
|
|
+{
|
|
|
+ UITableView *tableView = [self viewWithTag:HypTextView.objTag];
|
|
|
+ DLog(@"%ld",(long)HypTextView.tag);
|
|
|
+ int a = HypTextView.tag / 1000;
|
|
|
+ int b = HypTextView.tag % 1000;
|
|
|
+
|
|
|
+ id obj = tableView.dataArray[a];
|
|
|
+
|
|
|
+ NSString *maxlength = @"";
|
|
|
+ if ([obj isKindOfClass:[MoreGridModel class]]) {
|
|
|
+ MoreGridModel *model = tableView.dataArray[a];
|
|
|
+ DetailgridModel *detailModel = model.showItems[b];
|
|
|
+ maxlength = [NSString stringWithFormat:@"%@",detailModel.dg_maxlength];
|
|
|
+ }else{
|
|
|
+ FormModel *model = tableView.dataArray[a];
|
|
|
+ DetailFormModel *detailModel = model.showItems[b];
|
|
|
+ maxlength = [NSString stringWithFormat:@"%@",detailModel.fd_maxlength];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ([maxlength isEqualToString:@"0"] || maxlength.length == 0) {
|
|
|
+ maxlength = @"300";
|
|
|
+ }
|
|
|
+
|
|
|
+ int length = [maxlength intValue];
|
|
|
+
|
|
|
+ if (HypTextView.text.length > length)
|
|
|
+ {
|
|
|
+ HypTextView.text = [HypTextView.text substringToIndex:length];
|
|
|
+ [self endEditing:YES];
|
|
|
+ if (self.msgBlock) {
|
|
|
+ self.msgBlock([NSString stringWithFormat:@"不能超过%d个字",length]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+-(BOOL)textViewShouldBeginEditing:(HypTextView *)textView
|
|
|
+{
|
|
|
+ UITableView *tableView = [self viewWithTag:textView.objTag];
|
|
|
+ int a = textView.tag / 1000;
|
|
|
+ int b = textView.tag % 1000;
|
|
|
+
|
|
|
+ id obj = tableView.dataArray[a];
|
|
|
+ NSString *typeStr = @"", *renderer = @"";
|
|
|
+ if ([obj isKindOfClass:[MoreGridModel class]]) {
|
|
|
+ MoreGridModel *model = tableView.dataArray[a];
|
|
|
+ DetailgridModel *detailModel = model.showItems[b];
|
|
|
+ typeStr = [NSString stringWithFormat:@"%@",detailModel.dg_type];
|
|
|
+ renderer = [NSString stringWithFormat:@"%@",detailModel.dg_renderer];
|
|
|
+ }else{
|
|
|
+ FormModel *model = tableView.dataArray[a];
|
|
|
+ DetailFormModel *detailModel = model.showItems[b];
|
|
|
+ typeStr = [NSString stringWithFormat:@"%@",detailModel.fd_type];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ([typeStr isEqualToString:@"C"] || [typeStr isEqualToString:@"SF"] || [typeStr isEqualToString:@"DF"] || [typeStr isEqualToString:@"MF"] || [typeStr isEqualToString:@"D"] || [typeStr isEqualToString:@"DT"] || [typeStr isEqualToString:@"FF"] || [renderer isEqualToString:@"detailAttach"]) {
|
|
|
+ if (self.block) {
|
|
|
+ self.block(textView.tag, tableView);
|
|
|
+ }
|
|
|
+ return NO;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)textView:(HypTextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
|
|
|
+
|
|
|
+ UITableView *tableView = [self viewWithTag:textView.objTag];
|
|
|
+
|
|
|
+ if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车,即按下return
|
|
|
+ //在这里做你响应return键的代码
|
|
|
+ [self endEditing:YES];
|
|
|
+ return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行
|
|
|
+ }
|
|
|
+
|
|
|
+ NSMutableString *allText = [NSMutableString stringWithString:[NSString stringWithFormat:@"%@",textView.text]];
|
|
|
+ [allText insertString:[NSString stringWithFormat:@"%@",text] atIndex:range.location];
|
|
|
+
|
|
|
+ int a = textView.tag / 1000;
|
|
|
+ int b = textView.tag % 1000;
|
|
|
+
|
|
|
+ id obj = tableView.dataArray[a];
|
|
|
+ NSString *typeStr = @"";
|
|
|
+ if ([obj isKindOfClass:[MoreGridModel class]]) {
|
|
|
+ MoreGridModel *model = tableView.dataArray[a];
|
|
|
+ DetailgridModel *detailModel = model.showItems[b];
|
|
|
+ typeStr = detailModel.dg_type;
|
|
|
+ }else{
|
|
|
+ FormModel *model = tableView.dataArray[a];
|
|
|
+ DetailFormModel *detailModel = model.showItems[b];
|
|
|
+ typeStr = [NSString stringWithFormat:@"%@",detailModel.fd_type];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ([typeStr isEqualToString:@"N"]) {
|
|
|
+ BOOL a = [self validateNumber:allText];
|
|
|
+ if (![self validateNumber:allText]) {
|
|
|
+ if (self.msgBlock) {
|
|
|
+ self.msgBlock(@"只能填写数字");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return a;
|
|
|
+ }
|
|
|
+
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+
|
|
|
+-(void)textViewDidEndEditing:(HypTextView *)textView
|
|
|
+{
|
|
|
+ UITableView *tableView = [self viewWithTag:textView.objTag];
|
|
|
+
|
|
|
+ int a = textView.tag / 1000;
|
|
|
+ int b = textView.tag % 1000;
|
|
|
+
|
|
|
+ id obj = tableView.dataArray[a];
|
|
|
+ if ([obj isKindOfClass:[MoreGridModel class]]) {
|
|
|
+ MoreGridModel *model = tableView.dataArray[a];
|
|
|
+ DetailgridModel *detailModel = model.showItems[b];
|
|
|
+ detailModel.dg_value = textView.text;
|
|
|
+ }else{
|
|
|
+ FormModel *model = tableView.dataArray[a];
|
|
|
+ DetailFormModel *detailModel = model.showItems[b];
|
|
|
+ detailModel.fd_value = textView.text;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)HypTextView:(HypTextView *)HypTextView textDidEnd:(NSString *)text
|
|
|
+{
|
|
|
+ UITableView *tableView = [self viewWithTag:HypTextView.objTag];
|
|
|
+
|
|
|
+ int a = HypTextView.tag / 1000;
|
|
|
+ int b = HypTextView.tag % 1000;
|
|
|
+
|
|
|
+ id obj = tableView.dataArray[a];
|
|
|
+ if ([obj isKindOfClass:[MoreGridModel class]]) {
|
|
|
+ MoreGridModel *model = tableView.dataArray[a];
|
|
|
+ DetailgridModel *detailModel = model.showItems[b];
|
|
|
+ detailModel.dg_value = text;
|
|
|
+ }else{
|
|
|
+ FormModel *model = tableView.dataArray[a];
|
|
|
+ DetailFormModel *detailModel = model.showItems[b];
|
|
|
+ detailModel.fd_value = text;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//只能输入数字和小数点 -- 税率
|
|
|
+- (BOOL)validateNumber:(NSString*)number {
|
|
|
+ BOOL res = YES;
|
|
|
+ NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
|
|
|
+
|
|
|
+ if (number.length != 0) {
|
|
|
+ NSString * string = [number substringWithRange:NSMakeRange(0, 1)];
|
|
|
+ if ([string isEqualToString:@"."]) {
|
|
|
+ return NO;
|
|
|
+ }
|
|
|
+
|
|
|
+ int j = 0; int z = 0;
|
|
|
+ while (j < number.length) {
|
|
|
+ NSString * string = [number substringWithRange:NSMakeRange(j, 1)];
|
|
|
+ if ([string isEqualToString:@"."]) {
|
|
|
+ z++;
|
|
|
+ }
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ if (z>1) {
|
|
|
+ return NO;
|
|
|
+ }
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ while (i < number.length) {
|
|
|
+ NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
|
|
|
+ NSRange range = [string rangeOfCharacterFromSet:tmpSet];
|
|
|
+ if (range.length == 0) {
|
|
|
+ res = NO;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+}
|
|
|
+//判断是否为整形;
|
|
|
+- (BOOL)isPureInt:(NSString *)string {
|
|
|
+ NSScanner *scan = [NSScanner scannerWithString:string];
|
|
|
+ int val;
|
|
|
+ return [scan scanInt:&val] && [scan isAtEnd];
|
|
|
+}
|
|
|
+//判断是否为浮点形
|
|
|
+- (BOOL)isPureFloat:(NSString *)string {
|
|
|
+ NSScanner *scan = [NSScanner scannerWithString:string];
|
|
|
+ float val;
|
|
|
+ return [scan scanFloat:&val] && [scan isAtEnd];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- 添加明细
|
|
|
+-(void)addMoreCongBiao:(UIButton *)sender
|
|
|
+{
|
|
|
+ UITableView *tableView = objc_getAssociatedObject(sender, "firstObject");
|
|
|
+
|
|
|
+ MoreGridModel *model = [MoreGridModel copyWithModel:_gridData[sender.tag][0]];
|
|
|
+ [tableView.dataArray addObject:model];
|
|
|
+ [tableView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- 删除明细
|
|
|
+-(void)deleteMoreCongBiao:(UIButton *)sender
|
|
|
+{
|
|
|
+ UITableView *tableView = objc_getAssociatedObject(sender, "firstObject");
|
|
|
+ int section = [objc_getAssociatedObject(sender, "secondObject") intValue];
|
|
|
+
|
|
|
+ [tableView.dataArray removeObjectAtIndex:section];
|
|
|
+
|
|
|
+ [tableView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- 多从表的数据
|
|
|
+-(void)setGridData:(NSMutableArray *)gridData
|
|
|
+{
|
|
|
+ _gridData = gridData;
|
|
|
+
|
|
|
+ [self setUpSegmentAndScrollView];
|
|
|
+
|
|
|
+ [self setUpNoConfirmTableViewWithEntering];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- 建立不确定几个的tableView
|
|
|
+-(void)setUpNoConfirmTableViewWithEntering
|
|
|
+{
|
|
|
+ for (int i = 0; i < _gridData.count; i ++) {
|
|
|
+ UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(self.width*i, 0, self.width, self.scorlView.height) style:UITableViewStyleGrouped];
|
|
|
+ tableView.delegate = self;
|
|
|
+ tableView.dataSource = self;
|
|
|
+ tableView.showsVerticalScrollIndicator = NO;
|
|
|
+ tableView.backgroundColor = BGB_COLOR;
|
|
|
+ tableView.tag = i + 88888;
|
|
|
+
|
|
|
+ tableView.dataArray = [NSMutableArray new];
|
|
|
+ NSMutableArray *daiArr = [NSMutableArray new];
|
|
|
+ NSMutableArray *dArr = _gridData[i];
|
|
|
+ for (int j = 0; j < dArr.count; j++) {
|
|
|
+ id obj = dArr[j];
|
|
|
+ if ([obj isKindOfClass:[MoreGridModel class]]) {
|
|
|
+ MoreGridModel *model = dArr[j];
|
|
|
+ for (id obj in model.showItems) {
|
|
|
+ DetailgridModel *showObj = obj;
|
|
|
+ CGFloat height = [self getSizeWithText:FORMAT(@"%@*",showObj.dg_caption)].height;
|
|
|
+ NSString *heightStr = FORMAT(@"%f",height+10);
|
|
|
+ if (height < 40) {
|
|
|
+ showObj.cellHeight = @"40";
|
|
|
+ }else{
|
|
|
+ showObj.cellHeight = heightStr;
|
|
|
+ }
|
|
|
+ showObj.dg_value = showObj.dg_value != nil ? showObj.dg_value:@"";
|
|
|
+ }
|
|
|
+ [daiArr addObject:model];
|
|
|
+ }else{
|
|
|
+ FormModel *model = dArr[j];
|
|
|
+ [daiArr addObject:model];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tableView.dataArray = daiArr;
|
|
|
+
|
|
|
+ if (_statuType != Editing) {
|
|
|
+ UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 40)];
|
|
|
+ footerView.userInteractionEnabled = YES;
|
|
|
+ footerView.backgroundColor = [UIColor clearColor];
|
|
|
+
|
|
|
+ UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ addBtn.frame = CGRectMake(0, 0, SCREEN_WIDTH, 40);
|
|
|
+ [addBtn setTitleColor:HexColor(@"#1084D1") forState:UIControlStateNormal];
|
|
|
+ [addBtn setBackgroundColor:Color(250, 249, 249, 1) forState:UIControlStateNormal];
|
|
|
+ [addBtn setTitle:@"+ 添加" forState:UIControlStateNormal];
|
|
|
+ addBtn.titleLabel.font = FONT_SIZE(13);
|
|
|
+ [addBtn addTarget:self action:@selector(addMoreCongBiao:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ objc_setAssociatedObject(addBtn, "firstObject", tableView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
+ addBtn.tag = i;
|
|
|
+ [footerView addSubview:addBtn];
|
|
|
+ tableView.tableFooterView = footerView;
|
|
|
+ }
|
|
|
+
|
|
|
+ [self.scorlView addSubview:tableView];
|
|
|
+ [self.tableViewArr addObject:tableView];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+-(NSMutableArray *)tableViewArr
|
|
|
+{
|
|
|
+ if (!_tableViewArr) {
|
|
|
+ _tableViewArr = [NSMutableArray new];
|
|
|
+ }
|
|
|
+ return _tableViewArr;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- 设置segment
|
|
|
+-(void)setUpSegmentAndScrollView
|
|
|
+{
|
|
|
+ NSMutableArray *arr = [NSMutableArray new];
|
|
|
+ for (int i = 0; i < _gridData.count; i++) {
|
|
|
+ id obj = [_gridData[i] count] == 0 ? nil : _gridData[i][0];
|
|
|
+ if ([obj isKindOfClass:[MoreGridModel class]]) {
|
|
|
+ MoreGridModel *model = [_gridData[i] count] == 0 ? nil : _gridData[i][0];
|
|
|
+ [arr addObject:FORMAT(@"%@",model.dgtitle)];
|
|
|
+ }else{
|
|
|
+ [arr addObject:@"基本信息"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _segment = [[HMSegmentedControl alloc]initWithSectionTitles:[arr mutableCopy]];
|
|
|
+
|
|
|
+ _segment.titleTextAttributes = @{NSForegroundColorAttributeName :HexColor(@"#666666"),NSFontAttributeName : FONT_SIZE(12)};
|
|
|
+ _segment.selectedTitleTextAttributes = @{NSForegroundColorAttributeName :HexColor(@"#33A2EE"),NSFontAttributeName : FONT_SIZE(12)};
|
|
|
+ _segment.selectionIndicatorColor = HexColor(@"#33A2EE");
|
|
|
+ _segment.frame = CGRectMake(0, 0, self.width, 35);;
|
|
|
+ _segment.selectionIndicatorHeight = 1.0;
|
|
|
+ _segment.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
|
|
|
+ _segment.selectionIndicatorBoxColor = HexColor(@"#33A2EE");
|
|
|
+ _segment.selectionIndicatorBoxOpacity = 1.0;
|
|
|
+
|
|
|
+ _segment.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
|
|
|
+ @weakify(self)
|
|
|
+ _segment.indexChangeBlock = ^(NSInteger index) {
|
|
|
+ @strongify(self)
|
|
|
+
|
|
|
+ [self.scorlView setContentOffset:CGPointMake(index*self.width, 0) animated:YES];
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ [self addSubview:self.segment];
|
|
|
+
|
|
|
+ self.scorlView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.segment.frame), self.width, self.height-35)];
|
|
|
+
|
|
|
+ self.scorlView.pagingEnabled = YES;
|
|
|
+
|
|
|
+ self.scorlView.contentSize = CGSizeMake(self.width*_gridData.count, self.height-35);
|
|
|
+
|
|
|
+ [self addSubview:self.scorlView];
|
|
|
+
|
|
|
+ self.scorlView.backgroundColor = BGKJ_COLOR;
|
|
|
+
|
|
|
+ self.scorlView.showsVerticalScrollIndicator = NO;
|
|
|
+
|
|
|
+ self.scorlView.showsHorizontalScrollIndicator = NO;
|
|
|
+
|
|
|
+ self.scorlView.bounces = NO;
|
|
|
+
|
|
|
+ self.scorlView.delegate = self;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
|
|
|
+
|
|
|
+ if (![scrollView isKindOfClass:UITableView.class]) {
|
|
|
+
|
|
|
+ CGFloat contentX = scrollView.contentOffset.x;
|
|
|
+
|
|
|
+ NSInteger index = contentX/scrollView.width;
|
|
|
+
|
|
|
+ self.segment.selectedSegmentIndex = index;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- 自动获取文本高度
|
|
|
+- (CGSize)getSizeWithText:(NSString *)text
|
|
|
+{
|
|
|
+ /**
|
|
|
+ 参数1:Size 文本显示的最大区域
|
|
|
+ 参数2:options 用什么来的换行模式来计算
|
|
|
+ 参数3:attributes 文字的大小
|
|
|
+ 参数4:context 上下文
|
|
|
+ */
|
|
|
+
|
|
|
+ return [FORMAT(@"%@",text) boundingRectWithSize:CGSizeMake(90, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : FONT_SIZE(14)} context:NULL].size;
|
|
|
+}
|
|
|
+
|
|
|
+@end
|