NewRepairDetailListsCell.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. //
  2. // NewRepairDetailListsCell.m
  3. // IBOSS
  4. //
  5. // Created by apple on 16/1/19.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. //功能描述: 新增维修明细单元格类
  9. #import "NewRepairDetailListsCell.h"
  10. #define kTextFont [UIFont systemFontOfSize:LabelAndTextFontOfSize]
  11. @implementation NewRepairDetailListsCell
  12. BOOL isHaveDian;
  13. #pragma 公有函数
  14. /**
  15. 单元格选中样式
  16. @param selected <#selected description#>
  17. @param animated <#animated description#>
  18. */
  19. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  20. [super setSelected:selected animated:animated];
  21. }
  22. /**
  23. 初始化单元格
  24. @param style <#style description#>
  25. @param reuseIdentifier <#reuseIdentifier description#>
  26. @return <#return value description#>
  27. */
  28. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  29. {
  30. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  31. if (self) {
  32. CGFloat w=((Screen_Width-100-22));;
  33. ////////////////////////
  34. UILabel *lblOnlyCode = [[UILabel alloc] initWithFrame:CGRectMake(20,5,80,31)];
  35. lblOnlyCode.textColor = [UIColor blackColor];
  36. lblOnlyCode.text = @"唯一编码:";
  37. lblOnlyCode.font=kTextFont;
  38. lblOnlyCode.textAlignment = NSTextAlignmentLeft;
  39. [self.contentView addSubview:lblOnlyCode];
  40. self.onlyCode = [[UILabel alloc] initWithFrame:CGRectMake(95,5,w,31)];
  41. self.onlyCode.backgroundColor = [UIColor clearColor];
  42. self.onlyCode.textColor = [UIColor blackColor];
  43. self.onlyCode.font=kTextFont;
  44. self.onlyCode.textAlignment = NSTextAlignmentLeft;
  45. [self.contentView addSubview: self.onlyCode];
  46. ////////////////////////
  47. UILabel *lblCode = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblOnlyCode.frame),80,31)];
  48. lblCode.textColor = [UIColor blackColor];
  49. lblCode.text = @"商品编码:";
  50. lblCode.textAlignment = NSTextAlignmentLeft;
  51. lblCode.font=kTextFont;
  52. [self.contentView addSubview:lblCode];
  53. self.code = [[UILabel alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblOnlyCode.frame),w,31)];
  54. self.code.backgroundColor = [UIColor clearColor];
  55. self.code.textColor = [UIColor blackColor];
  56. self.code.font=kTextFont;
  57. self.code.textAlignment = NSTextAlignmentLeft;
  58. [self.contentView addSubview: self.code];
  59. ////////////////////////品牌
  60. UILabel *lblBrandName = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblCode.frame),80,31)];
  61. lblBrandName.backgroundColor = [UIColor clearColor];
  62. lblBrandName.textColor = [UIColor blackColor];
  63. lblBrandName.text = @"品 牌:";
  64. lblBrandName.font=kTextFont;
  65. lblBrandName.textAlignment = NSTextAlignmentLeft;
  66. [self.contentView addSubview:lblBrandName];
  67. self.brandName = [[UILabel alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblCode.frame),w,31)];
  68. self.brandName.backgroundColor = [UIColor clearColor];
  69. self.brandName.textColor = [UIColor blackColor];
  70. self.brandName.font=kTextFont;
  71. self.brandName.textAlignment = NSTextAlignmentLeft;
  72. [self.contentView addSubview: self.brandName];
  73. ////////////////////////维修数量
  74. UILabel *lblRepairQuantity = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblBrandName.frame),80,31)];
  75. lblRepairQuantity.backgroundColor = [UIColor clearColor];
  76. lblRepairQuantity.textColor = [UIColor blackColor];
  77. lblRepairQuantity.text = @"维修数量:";
  78. lblRepairQuantity.font=kTextFont;
  79. lblRepairQuantity.textAlignment = NSTextAlignmentLeft;
  80. [self.contentView addSubview:lblRepairQuantity];
  81. self.repairQuantity = [[UILabel alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblBrandName.frame),w,31)];
  82. self.repairQuantity.backgroundColor = [UIColor clearColor];
  83. self.repairQuantity.textColor = [UIColor blackColor];
  84. self.repairQuantity.font=kTextFont;
  85. self.repairQuantity.textAlignment = NSTextAlignmentLeft;
  86. [self.contentView addSubview: self.repairQuantity];
  87. ////////////////////////完成数量
  88. UILabel *lblCompleteQuantity = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/2,5+CGRectGetMaxY(lblBrandName.frame),75,31)];
  89. lblCompleteQuantity.backgroundColor = [UIColor clearColor];
  90. lblCompleteQuantity.textColor = [UIColor blackColor];
  91. lblCompleteQuantity.text = @"完成数量:";
  92. lblCompleteQuantity.font=kTextFont;
  93. lblCompleteQuantity.textAlignment = NSTextAlignmentLeft;
  94. [self.contentView addSubview:lblCompleteQuantity];
  95. self.completedQuantity = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(lblCompleteQuantity.frame),5+CGRectGetMaxY(lblBrandName.frame),w,31)];
  96. self.completedQuantity.backgroundColor = [UIColor clearColor];
  97. self.completedQuantity.textColor = [UIColor blackColor];
  98. self.completedQuantity.font=kTextFont;
  99. self.completedQuantity.textAlignment = NSTextAlignmentLeft;
  100. [self.contentView addSubview: self.completedQuantity];
  101. ////////////////////////面积
  102. UILabel *lblAcreage = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblRepairQuantity.frame),80,31)];
  103. lblAcreage.backgroundColor = [UIColor clearColor];
  104. lblAcreage.textColor = [UIColor blackColor];
  105. lblAcreage.text = @"面 积:";
  106. lblAcreage.font=kTextFont;
  107. lblAcreage.textAlignment = NSTextAlignmentLeft;
  108. [self.contentView addSubview:lblAcreage];
  109. self.acreage = [[UILabel alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblRepairQuantity.frame),w,31)];
  110. self.acreage.backgroundColor = [UIColor clearColor];
  111. self.acreage.font=kTextFont;
  112. self.acreage.textColor = [UIColor blackColor];
  113. self.acreage.textAlignment = NSTextAlignmentLeft;
  114. [self.contentView addSubview: self.acreage];
  115. ////////////////////////回执数量
  116. UILabel *lblReceiptQuantity = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblAcreage.frame),80,31)];
  117. lblReceiptQuantity.backgroundColor = [UIColor clearColor];
  118. lblReceiptQuantity.textColor = [UIColor blackColor];
  119. lblReceiptQuantity.text = @"回执数量:";
  120. lblReceiptQuantity.font=kTextFont;
  121. lblReceiptQuantity.textAlignment = NSTextAlignmentLeft;
  122. [self.contentView addSubview:lblReceiptQuantity];
  123. self.receiptQuantity = [[UITextField alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblAcreage.frame),w,31)];
  124. self.receiptQuantity.backgroundColor = [UIColor clearColor];
  125. self.receiptQuantity.textColor = [UIColor blackColor];
  126. self.receiptQuantity.font=kTextFont;
  127. self.receiptQuantity.textAlignment = NSTextAlignmentLeft;
  128. self.receiptQuantity.tag=1110;
  129. self.receiptQuantity.placeholder = @"请输入回执数量";
  130. self.receiptQuantity.keyboardType=UIKeyboardTypeDecimalPad;
  131. [self.contentView addSubview: self.receiptQuantity];
  132. ////////////////////////回执备注
  133. UILabel *lblRemark = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblReceiptQuantity.frame),80,31)];
  134. lblRemark.backgroundColor = [UIColor clearColor];
  135. lblRemark.textColor = [UIColor blackColor];
  136. lblRemark.text = @"回执备注:";
  137. lblRemark.font=kTextFont;
  138. lblRemark.textAlignment = NSTextAlignmentLeft;
  139. [self.contentView addSubview:lblRemark];
  140. self.remark = [[UITextField alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblReceiptQuantity.frame),w,31)];
  141. self.remark.backgroundColor = [UIColor clearColor];
  142. self.remark.tag=1111;
  143. self.remark.font=kTextFont;
  144. self.remark.placeholder = @"请输入回执备注";
  145. self.remark.textColor = [UIColor blackColor];
  146. self.remark.textAlignment = NSTextAlignmentLeft;
  147. [self.contentView addSubview: self.remark];
  148. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 5+CGRectGetMaxY(self.remark.frame), SCREENWIDTH, 5)];
  149. line.backgroundColor = [UIColor colorWithRed:234.0/255 green:235.0/255 blue:236.0/255 alpha:1];
  150. [self.contentView addSubview: line];
  151. _cellHeight=CGRectGetMaxY(line.frame);
  152. [self.receiptQuantity addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  153. [self.remark addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  154. self.receiptQuantity.delegate=self;
  155. self.remark.delegate=self;
  156. }
  157. return self;
  158. }
  159. #pragma 委托函数
  160. /**
  161. 文本开始编辑函数
  162. @param textField <#textField description#>
  163. */
  164. - (void)textFieldDidBeginEditing:(UITextField *)textField{
  165. if([textField isEqual:self.remark] ){
  166. if([self.delegate respondsToSelector:@selector(keyboardWillShow:)])
  167. {
  168. [self.delegate keyboardWillShow:self];
  169. }
  170. }
  171. }
  172. /**
  173. 文本结束编辑函数
  174. @param textField <#textField description#>
  175. */
  176. - (void)textFieldDidEndEditing:(UITextField *)textField{
  177. if([textField isEqual:self.remark]){
  178. //[self.remark resignFirstResponder];
  179. if([self.delegate respondsToSelector:@selector(keyboardWillHide:)])
  180. {
  181. [self.delegate keyboardWillHide:self];
  182. }
  183. return ;
  184. }
  185. if([self.delegate respondsToSelector:@selector(endEdit:)])
  186. {
  187. [self.delegate endEdit:self];
  188. }
  189. }
  190. /**
  191. 限制小数位数
  192. @param textField <#textField description#>
  193. @param range <#range description#>
  194. @param string <#string description#>
  195. @return <#return value description#>
  196. */
  197. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  198. NSLog(@"shouldChangeCharactersInRange");
  199. if([textField isEqual:self.remark]){
  200. if (range.location >= 100){
  201. return NO;
  202. }
  203. }
  204. if(textField == self.receiptQuantity)
  205. {
  206. if (range.location >= 17){
  207. return NO;
  208. }
  209. if ([textField.text rangeOfString:@"."].location == NSNotFound) {
  210. isHaveDian = NO;
  211. }else{
  212. isHaveDian=YES;
  213. }
  214. if ([string length] > 0) {
  215. unichar single = [string characterAtIndex:0];//当前输入的字符
  216. if ((single >= '0' && single <= '9') || single == '.') {//数据格式正确
  217. //首字母不能为0和小数点
  218. if([textField.text length] == 0){
  219. if(single == '.') {
  220. [self showAlertViewText:@"第一个数字不能为小数点"];
  221. [textField.text stringByReplacingCharactersInRange:range withString:@""];
  222. return NO;
  223. }
  224. }
  225. if([textField.text length] == 1 && [[textField.text substringToIndex:1] isEqualToString: @"0"]){
  226. if(!(single == '.')) {
  227. [textField.text stringByReplacingCharactersInRange:range withString:@""];
  228. return NO;
  229. }
  230. }
  231. //输入的字符是否是小数点
  232. if (single == '.') {
  233. if(!isHaveDian)//text中还没有小数点
  234. {
  235. isHaveDian = YES;
  236. return YES;
  237. }else{
  238. [self showAlertViewText:@"您已经输入过小数点了"];
  239. [textField.text stringByReplacingCharactersInRange:range withString:@""];
  240. return NO;
  241. }
  242. }else{
  243. if (isHaveDian) {//存在小数点
  244. //判断小数点的位数
  245. NSRange ran = [textField.text rangeOfString:@"."];
  246. if (range.location - ran.location <= 6) {
  247. return YES;
  248. }else{
  249. //[self showAlertViewText:@"亲,您最多输入两位小数"];
  250. return NO;
  251. }
  252. }else{
  253. return YES;
  254. }
  255. }
  256. }else{//输入的数据格式不正确
  257. [self showAlertViewText:@"您输入的格式不正确"];
  258. [textField.text stringByReplacingCharactersInRange:range withString:@""];
  259. return NO;
  260. }
  261. }
  262. else
  263. {
  264. return YES;
  265. }
  266. }
  267. return YES;
  268. }
  269. #pragma 私有函数
  270. /**
  271. 设置新增维修单元格frame
  272. @param model <#model description#>
  273. */
  274. - (void)parseInfoModel:(NewRepairItemModel*)model{
  275. if(model != nil){
  276. self.repairId=model.repairId;
  277. self.detailId=model.detailId;
  278. self.salesDetailId=model.salesDetailId;
  279. self.code.text=model.code;
  280. self.onlyCode.text=model.onlyCode;
  281. self.repairQuantity.text=model.repairQuantity;
  282. self.completedQuantity.text=model.completeQuantity;
  283. self.brandName.text=model.brandName;
  284. self.acreage.text=model.acreage;
  285. self.receiptQuantity.text=model.receiptQuantity;
  286. self.remark.text=model.remarks;
  287. self.receiptQuantity.enabled=!model.isDelay;
  288. self.remark.enabled=!model.isDelay;
  289. }
  290. }
  291. /**
  292. 文本字段变化函数
  293. @param sender <#sender description#>
  294. */
  295. - (void)textFieldDidChange:(UITextField*) sender{
  296. NSLog(@"textFieldDidChange");
  297. UITextField* txt=sender;
  298. switch (txt.tag) {
  299. case 1110:
  300. {
  301. }
  302. break;
  303. case 1111:
  304. {
  305. }
  306. break;
  307. default:
  308. break;
  309. }
  310. if([self.delegate respondsToSelector:@selector(textValueChange:txtField:qualityField:remarkField:)])
  311. {
  312. [self.delegate textValueChange:self txtField:txt qualityField:self.receiptQuantity remarkField:self.remark];
  313. }
  314. }
  315. /**
  316. 出示警告对话框
  317. @param text <#text description#>
  318. */
  319. - (void)showAlertViewText:(NSString *)text
  320. {
  321. UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
  322. message:text
  323. delegate:nil
  324. cancelButtonTitle:@"确定"
  325. otherButtonTitles:nil];
  326. [alert show];
  327. }
  328. @end