NewInstallDetailListsCell.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. //
  2. // NewInstallDetailListsCell.m
  3. // IBOSS
  4. //
  5. // Created by apple on 16/1/12.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:新增安装明细单元格
  9. #import "NewInstallDetailListsCell.h"
  10. #import "StatusInfoTextVC.h"
  11. #import "ArgumentSetting.h"
  12. #import "OrderQuantity.h"
  13. #define kTextFont [UIFont systemFontOfSize:LabelAndTextFontOfSize]
  14. @implementation NewInstallDetailListsCell
  15. #pragma mark - 公有函数
  16. /**
  17. cell点击函数
  18. @param selected <#selected description#>
  19. @param animated <#animated description#>
  20. */
  21. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  22. [super setSelected:selected animated:animated];
  23. }
  24. /**
  25. 初始化 cell style
  26. @param style <#style description#>
  27. @param reuseIdentifier <#reuseIdentifier description#>
  28. @return <#return value description#>
  29. */
  30. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  31. {
  32. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  33. if (self) {
  34. CGFloat w=((Screen_Width-100-22));;
  35. UILabel *lblTitleOnlyCode = [[UILabel alloc] initWithFrame:CGRectMake(20,5,80,31)];
  36. lblTitleOnlyCode.textColor = [UIColor blackColor];
  37. lblTitleOnlyCode.text = @"唯一编码:";
  38. lblTitleOnlyCode.font=kTextFont;
  39. lblTitleOnlyCode.textAlignment = NSTextAlignmentLeft;
  40. [self.contentView addSubview:lblTitleOnlyCode];
  41. self.lblOnlyCode = [[UILabel alloc] initWithFrame:CGRectMake(95,5,w,31)];
  42. self.lblOnlyCode.backgroundColor = [UIColor clearColor];
  43. self.lblOnlyCode.textColor = [UIColor blackColor];
  44. self.lblOnlyCode.font=kTextFont;
  45. self.lblOnlyCode.textAlignment = NSTextAlignmentLeft;
  46. [self.contentView addSubview: self.lblOnlyCode];
  47. UILabel *lblTitleCode = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblTitleOnlyCode.frame),80,31)];
  48. lblTitleCode.textColor = [UIColor blackColor];
  49. lblTitleCode.text = @"商品编码:";
  50. lblTitleCode.font=kTextFont;
  51. lblTitleCode.textAlignment = NSTextAlignmentLeft;
  52. [self.contentView addSubview:lblTitleCode];
  53. self.code = [[UILabel alloc] initWithFrame:CGRectMake(95,CGRectGetMaxY(lblTitleOnlyCode.frame)+5,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 *lblgoodsname = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblTitleCode.frame),80,31)];
  61. lblgoodsname.backgroundColor = [UIColor clearColor];
  62. lblgoodsname.textColor = [UIColor blackColor];
  63. lblgoodsname.text = @"商品名称:";
  64. lblgoodsname.font=kTextFont;
  65. lblgoodsname.textAlignment = NSTextAlignmentLeft;
  66. [self.contentView addSubview:lblgoodsname];
  67. self.goodsName = [[UILabel alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblTitleCode.frame),w,31)];
  68. self.goodsName.backgroundColor = [UIColor clearColor];
  69. self.goodsName.textColor = [UIColor blackColor];
  70. self.goodsName.font=kTextFont;
  71. self.goodsName.textAlignment = NSTextAlignmentLeft;
  72. [self.contentView addSubview: self.goodsName];
  73. ////////////////////////计量单位
  74. UILabel *lblunit = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/2,5+CGRectGetMaxY(lblTitleCode.frame),70,31)];
  75. lblunit.backgroundColor = [UIColor clearColor];
  76. lblunit.textColor = [UIColor blackColor];
  77. lblunit.text = @"计量单位:";
  78. lblunit.font=kTextFont;
  79. lblunit.textAlignment = NSTextAlignmentLeft;
  80. [self.contentView addSubview:lblunit];
  81. self.unit = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(lblunit.frame),5+CGRectGetMaxY(lblTitleCode.frame),w,31)];
  82. self.unit.backgroundColor = [UIColor clearColor];
  83. self.unit.textColor = [UIColor blackColor];
  84. self.unit.font=kTextFont;
  85. self.unit.textAlignment = NSTextAlignmentLeft;
  86. [self.contentView addSubview: self.unit];
  87. ////////////////////////安装数量
  88. UILabel *lblinstallquality = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblgoodsname.frame),80,31)];
  89. lblinstallquality.backgroundColor = [UIColor clearColor];
  90. lblinstallquality.textColor = [UIColor blackColor];
  91. lblinstallquality.text = @"安装数量:";
  92. lblinstallquality.font=kTextFont;
  93. lblinstallquality.textAlignment = NSTextAlignmentLeft;
  94. [self.contentView addSubview:lblinstallquality];
  95. self.installQuantity = [[UILabel alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblgoodsname.frame),w,31)];
  96. self.installQuantity.backgroundColor = [UIColor clearColor];
  97. self.installQuantity.textColor = [UIColor blackColor];
  98. self.installQuantity.font=kTextFont;
  99. self.installQuantity.textAlignment = NSTextAlignmentLeft;
  100. [self.contentView addSubview: self.installQuantity];
  101. ////////////////////////完成数量
  102. UILabel *lblcompletedquality = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/2,5+CGRectGetMaxY(lblgoodsname.frame),70,31)];
  103. lblcompletedquality.backgroundColor = [UIColor clearColor];
  104. lblcompletedquality.textColor = [UIColor blackColor];
  105. lblcompletedquality.text = @"完成数量:";
  106. lblcompletedquality.font=kTextFont;
  107. lblcompletedquality.textAlignment = NSTextAlignmentLeft;
  108. [self.contentView addSubview:lblcompletedquality];
  109. self.completedQuantity = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(lblcompletedquality.frame),5+CGRectGetMaxY(lblgoodsname.frame),w,31)];
  110. self.completedQuantity.backgroundColor = [UIColor clearColor];
  111. self.completedQuantity.textColor = [UIColor blackColor];
  112. self.completedQuantity.font=kTextFont;
  113. self.completedQuantity.textAlignment = NSTextAlignmentLeft;
  114. [self.contentView addSubview: self.completedQuantity];
  115. ////////////////////////回执数量
  116. UILabel *lblreceiptquality = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(_completedQuantity.frame),80,31)];
  117. lblreceiptquality.backgroundColor = [UIColor clearColor];
  118. lblreceiptquality.textColor = [UIColor blackColor];
  119. lblreceiptquality.font=kTextFont;
  120. lblreceiptquality.text = @"回执数量:";
  121. lblreceiptquality.textAlignment = NSTextAlignmentLeft;
  122. [self.contentView addSubview:lblreceiptquality];
  123. self.receiptQuantity = [[UITextField alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(_completedQuantity.frame),w,31)];
  124. self.receiptQuantity.backgroundColor = [UIColor clearColor];
  125. self.receiptQuantity.textColor = [UIColor blackColor];
  126. self.receiptQuantity.textAlignment = NSTextAlignmentLeft;
  127. self.receiptQuantity.tag=1110;
  128. self.receiptQuantity.font=kTextFont;
  129. self.receiptQuantity.placeholder = @"请输入回执数量";
  130. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFocusPeopleEditingChanged:) name:@"UITextFieldTextDidChangeNotification" object: self.receiptQuantity];
  131. self.receiptQuantity.keyboardType=UIKeyboardTypeDecimalPad;
  132. [self.contentView addSubview: self.receiptQuantity];
  133. ////////////////////////出库数量
  134. UILabel *lblOutqualityTitle = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/2,5+CGRectGetMaxY(_completedQuantity.frame),70,31)];
  135. lblOutqualityTitle.backgroundColor = [UIColor clearColor];
  136. lblOutqualityTitle.textColor = [UIColor blackColor];
  137. lblOutqualityTitle.font=kTextFont;
  138. lblOutqualityTitle.text = @"出库数量:";
  139. lblOutqualityTitle.textAlignment = NSTextAlignmentLeft;
  140. [self.contentView addSubview:lblOutqualityTitle];
  141. self.lblOutquality = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(lblOutqualityTitle.frame),5+CGRectGetMaxY(_completedQuantity.frame),80,31)];
  142. _lblOutquality.backgroundColor = [UIColor clearColor];
  143. _lblOutquality.textColor = [UIColor blackColor];
  144. _lblOutquality.font=kTextFont;
  145. _lblOutquality.textAlignment = NSTextAlignmentLeft;
  146. [self.contentView addSubview:_lblOutquality];
  147. ////////////////////////回执类型
  148. UILabel *lblreceipttype = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblreceiptquality.frame),80,31)];
  149. lblreceipttype.backgroundColor = [UIColor clearColor];
  150. lblreceipttype.textColor = [UIColor blackColor];
  151. lblreceipttype.text = @"回执类型:";
  152. lblreceipttype.font=kTextFont;
  153. lblreceipttype.textAlignment = NSTextAlignmentLeft;
  154. [self.contentView addSubview:lblreceipttype];
  155. self.btnReceiptType = [[UIButton alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblreceiptquality.frame),w-20,31)];
  156. [self.btnReceiptType setTitle:@"请选择回执类型" forState:UIControlStateNormal];
  157. self.btnReceiptType.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
  158. self.btnReceiptType.titleLabel.font=kTextFont;
  159. [self.btnReceiptType setTitleColor:[UIColor colorWithWhite:0 alpha:1] forState:UIControlStateNormal];
  160. self.btnReceiptType.tag=1000;
  161. [self.contentView addSubview: self.btnReceiptType];
  162. ////////////////////////回执备注
  163. UILabel *lblremark = [[UILabel alloc] initWithFrame:CGRectMake(20,5+CGRectGetMaxY(lblreceipttype.frame),80,31)];
  164. lblremark.backgroundColor = [UIColor clearColor];
  165. lblremark.textColor = [UIColor blackColor];
  166. lblremark.text = @"回执备注:";
  167. lblremark.font=kTextFont;
  168. lblremark.textAlignment = NSTextAlignmentLeft;
  169. [self.contentView addSubview:lblremark];
  170. self.remark = [[UITextField alloc] initWithFrame:CGRectMake(95,5+CGRectGetMaxY(lblreceipttype.frame),w,31)];
  171. self.remark.backgroundColor = [UIColor clearColor];
  172. self.remark.tag=1111;
  173. self.remark.textColor = [UIColor blackColor];
  174. self.remark.textAlignment = NSTextAlignmentLeft;
  175. self.remark.font=kTextFont;
  176. self.remark.placeholder = @"请输入回执备注";
  177. [self.contentView addSubview: self.remark];
  178. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 5+CGRectGetMaxY(self.remark.frame), SCREENWIDTH, 5)];
  179. line.backgroundColor = [UIColor colorWithRed:234.0/255 green:235.0/255 blue:236.0/255 alpha:1];
  180. [self.contentView addSubview: line];
  181. self.cellHeight=CGRectGetMaxY(line.frame);
  182. [self.receiptQuantity addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  183. [self.remark addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  184. self.receiptQuantity.delegate=self;
  185. self.remark.delegate=self;
  186. }
  187. return self;
  188. }
  189. #pragma mark - 委托函数
  190. /**
  191. textfield回调函数
  192. @param textField <#textField description#>
  193. */
  194. - (void)textFieldDidBeginEditing:(UITextField *)textField{
  195. if([textField isEqual:self.remark] ){
  196. if([self.installDelegate respondsToSelector:@selector(keyboardWillShow:)])
  197. {
  198. [self.installDelegate keyboardWillShow:self];
  199. }
  200. }
  201. }
  202. /**
  203. textfield回调函数
  204. @param textField <#textField description#>
  205. */
  206. - (void)textFieldDidEndEditing:(UITextField *)textField{
  207. NSLog(@"textFieldDidEndEditing");
  208. if([textField isEqual:self.remark]){
  209. if([self.installDelegate respondsToSelector:@selector(keyboardWillHide:)])
  210. {
  211. [self.installDelegate keyboardWillHide:self];
  212. }
  213. return ;
  214. }else{
  215. OrderQuantity *quantity = [OrderQuantity new];
  216. NSInteger decimalPlaces= [_model.decimalPlaces integerValue];
  217. NSString *receiptQuantity = [quantity calculateReceiptQuantity:[self.model.circulateType integerValue] decimalPlaces:[NSString stringWithFormat:@"%ld",(long)decimalPlaces] quantity:self.receiptQuantity.text acreage:[self.model.acreage doubleValue]];
  218. self.receiptQuantity.text = receiptQuantity;
  219. self.model.receiptQuantity = receiptQuantity;
  220. }
  221. if([self.installDelegate respondsToSelector:@selector(endEdit:)])
  222. {
  223. [self.installDelegate endEdit:self];
  224. }
  225. }
  226. /**
  227. textfield回调函数
  228. @param textField <#textField description#>
  229. @param range <#range description#>
  230. @param string <#string description#>
  231. @return <#return value description#>
  232. */
  233. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  234. if([textField isEqual:self.remark]){
  235. if (range.location >= 100){
  236. return NO;
  237. }
  238. }
  239. if(textField == self.receiptQuantity)
  240. {
  241. if (range.location >= 17){
  242. return NO;
  243. } // return NO to not change text
  244. if ([textField.text rangeOfString:@"."].location == NSNotFound) {
  245. self.isHaveDian = NO;
  246. }else{
  247. self.isHaveDian=YES;
  248. }
  249. if ([string length] > 0) {
  250. unichar single = [string characterAtIndex:0];//当前输入的字符
  251. if ((single >= '0' && single <= '9') || single == '.') {//数据格式正确
  252. //首字母不能为0和小数点
  253. if([textField.text length] == 0){
  254. if(single == '.') {
  255. [self showAlertViewText:@"第一个数字不能为小数点"];
  256. [textField.text stringByReplacingCharactersInRange:range withString:@""];
  257. return NO;
  258. }
  259. }
  260. if([textField.text length] == 1 && [[textField.text substringToIndex:1] isEqualToString: @"0"]){
  261. if(!(single == '.')) {
  262. [textField.text stringByReplacingCharactersInRange:range withString:@""];
  263. return NO;
  264. }
  265. }
  266. //输入的字符是否是小数点
  267. if (single == '.') {
  268. if(!self.isHaveDian)//text中还没有小数点
  269. {
  270. self.isHaveDian = YES;
  271. return YES;
  272. }else{
  273. [self showAlertViewText:@"您已经输入过小数点了"];
  274. [textField.text stringByReplacingCharactersInRange:range withString:@""];
  275. return NO;
  276. }
  277. }else{
  278. if (self.isHaveDian) {//存在小数点
  279. //判断小数点的位数
  280. NSRange ran = [textField.text rangeOfString:@"."];
  281. if (range.location - ran.location <= 6) {
  282. return YES;
  283. }else{
  284. //[self showAlertViewText:@"亲,您最多输入两位小数"];
  285. return NO;
  286. }
  287. }else{
  288. return YES;
  289. }
  290. }
  291. }else{//输入的数据格式不正确
  292. [self showAlertViewText:@"您输入的格式不正确"];
  293. [textField.text stringByReplacingCharactersInRange:range withString:@""];
  294. return NO;
  295. }
  296. }
  297. else
  298. {
  299. return YES;
  300. }
  301. }
  302. return YES;
  303. }
  304. #pragma mark - 私有函数
  305. /**
  306. 设置cell数据
  307. @param model <#model description#>
  308. */
  309. - (void)parseInfoModel:(NewInstallIItemModel*)model type:(NSString *) type{
  310. if(model != nil){
  311. _model =model;
  312. self.installId=model.installationId;
  313. self.detailId=model.detailId;
  314. self.salesDetailId=model.salesDetailId;
  315. self.code.text=model.code;
  316. self.lblOnlyCode.text=model.onlyCode;
  317. self.installQuantity.text=model.installQuantity;
  318. self.completedQuantity.text=model.completeQuantity;
  319. self.unit.text=model.unitName;
  320. if(model.payStyle == nil|| model.payStyle.length == 0)
  321. {
  322. self.payStyle = @"";
  323. [self.btnPayStyle setTitle:@"请选择铺贴方式" forState:UIControlStateNormal];
  324. }
  325. else{
  326. self.payStyle=model.payStyle;
  327. [self.btnPayStyle setTitle:model.payStyleValue forState:UIControlStateNormal];
  328. }
  329. _lblOutquality.text = model.outQuantity;
  330. self.receiptQuantity.text=model.receiptQuantity;
  331. self.receiptBox.text=model.box;
  332. self.receiptPiece.text=model.piece;
  333. self.mm.text=model.mm;
  334. self.package.text=model.package;
  335. self.remark.text=model.remarks;
  336. self.receiptType=model.receiptType;
  337. self.goodsName.text = model.goodsName;
  338. self.receiptQuantity.enabled=model.isDelay;
  339. self.remark.enabled=model.isDelay;
  340. if ([model.receiptType isEqualToString:@"5"]) {
  341. [self.btnReceiptType setTitle:@"再安装" forState:UIControlStateNormal];
  342. self.receiptQuantity.enabled= YES;
  343. self.receiptQuantity.text = model.receiptQuantity;
  344. }
  345. if([model.receiptType isEqualToString:@"1"]){
  346. if([type intValue] == 3){
  347. [self.btnReceiptType setTitle:@"完成" forState:UIControlStateNormal];
  348. self.receiptQuantity.enabled= NO;
  349. self.receiptQuantity.text = model.receiptQuantity;
  350. model.receiptQuantity = model.receiptQuantity;
  351. }else{
  352. [self.btnReceiptType setTitle:@"完成" forState:UIControlStateNormal];
  353. self.receiptQuantity.enabled= NO;
  354. self.receiptQuantity.text = model.maxReceiptQuantity;
  355. model.receiptQuantity = model.maxReceiptQuantity;
  356. }
  357. }
  358. [self.btnReceiptType addTarget:self action:@selector(btnCilck:) forControlEvents:UIControlEventTouchUpInside];
  359. }
  360. }
  361. /**
  362. 文本字段变化函数
  363. @param sender <#sender description#>
  364. */
  365. - (void)textFieldDidChange:(UITextField*) sender{
  366. UITextField* txt=sender;
  367. switch (txt.tag) {
  368. case 1110:
  369. {
  370. }
  371. break;
  372. case 1111:
  373. {
  374. }
  375. break;
  376. default:
  377. break;
  378. }
  379. if([self.installDelegate respondsToSelector:@selector(textValueChange:txtField:qualityField:remarkField:)])
  380. {
  381. [self.installDelegate textValueChange:self txtField:txt qualityField:self.receiptQuantity remarkField:self.remark];
  382. }
  383. }
  384. /**
  385. 按钮点击函数
  386. @param sender <#sender description#>
  387. */
  388. - (void)btnCilck:(UIButton*)sender{
  389. UIButton *btn=sender;
  390. [self endEditing:YES];
  391. switch (btn.tag) {
  392. case 1000:
  393. {
  394. if([self.installDelegate respondsToSelector:@selector(btnGoReceiptType:)])
  395. {
  396. [self.installDelegate btnGoReceiptType:self];
  397. }
  398. }
  399. break;
  400. case 1001:
  401. {
  402. if([self.installDelegate respondsToSelector:@selector(btnGoPayStyle:)])
  403. {
  404. [self.installDelegate btnGoPayStyle:self];
  405. }
  406. }
  407. break;
  408. default:
  409. break;
  410. }
  411. }
  412. /**
  413. 文本框的长度限制 实现监听方法
  414. @param sender <#sender description#>
  415. */
  416. - (void)onFocusPeopleEditingChanged:(NSNotification *)sender
  417. {
  418. UITextField *textField = (UITextField *)sender.object;
  419. NSString *toBeString = textField.text;
  420. NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage];
  421. int kMaxLength=0;
  422. if([textField isEqual:self.receiptQuantity]){
  423. kMaxLength=17;
  424. if (toBeString!= nil && toBeString.length>0 && [toBeString floatValue]-9999999999.999999f>0.0000000001f) {
  425. textField.text = @"9999999999.999999";
  426. toBeString = @"9999999999.999999";
  427. }
  428. }
  429. if ([lang isEqualToString:@"zh-Hans"]) {
  430. UITextRange *selectedRange = [textField markedTextRange];
  431. UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
  432. if (!position) {
  433. if (toBeString.length > kMaxLength) {
  434. textField.text = [toBeString substringToIndex:kMaxLength];
  435. }
  436. }
  437. }else{
  438. if (toBeString.length > kMaxLength) {
  439. textField.text = [toBeString substringToIndex:kMaxLength];
  440. }
  441. }
  442. }
  443. /**
  444. 警告对话框
  445. @param text <#text description#>
  446. */
  447. - (void)showAlertViewText:(NSString *)text
  448. {
  449. UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
  450. message:text
  451. delegate:nil
  452. cancelButtonTitle:@"确定"
  453. otherButtonTitles:nil];
  454. [alert show];
  455. }
  456. @end