NewSalesExternalCoordinateCell.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. //
  2. // NewSalesExternalCoordinateCell.m
  3. // IBOSSmini
  4. //
  5. // Created by ssl on 2018/2/27.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "NewSalesExternalCoordinateCell.h"
  9. #define orderTextFont [UIFont systemFontOfSize:13]
  10. @implementation NewSalesExternalCoordinateCell
  11. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  12. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  13. return self;
  14. }
  15. - (void)setNewExternalCoordinateGoodsCell:(ExternalCoordinateGoodsModel *)externalCoordinateGoodsModel editStatus:(NSInteger) editStatus editFlag:(NSInteger) editFlag{
  16. _externalCoordinateModel=externalCoordinateGoodsModel;
  17. CGFloat heightLine = 1;
  18. CGFloat lblx = 20;
  19. CGFloat valuey = 10;
  20. CGFloat valueheight = 25;
  21. _lblSupplier = [UILabel new];
  22. _lblSupplier.frame=CGRectMake(lblx, valuey, Screen_Width- lblx- 70, valueheight);
  23. _lblSupplier.font =orderTextFont;
  24. [self addSubview:_lblSupplier];
  25. _lblSupplier.text = _externalCoordinateModel.supplierName;
  26. _vDelete=[UIView new];
  27. _vDelete.frame=CGRectMake(Screen_Width-65, valuey,70 , valueheight);
  28. UIButton *btnDelete=[UIButton buttonWithType:UIButtonTypeCustom];
  29. btnDelete.frame=CGRectMake(0, 4,15, 15);
  30. UIImageView *deleteImg=[[UIImageView alloc]init];
  31. deleteImg.frame=CGRectMake(0,0,15,15);
  32. [deleteImg setImage:[UIImage imageNamed:@"icon_delete"]];
  33. deleteImg.userInteractionEnabled=NO;
  34. [btnDelete addSubview:deleteImg];
  35. [_vDelete addSubview:btnDelete];
  36. UILabel *lblDelete=[UILabel new];
  37. lblDelete.text=@"删除";
  38. lblDelete.frame=CGRectMake(CGRectGetMaxX(btnDelete.frame)+3, 0,30, 25);
  39. lblDelete.font=orderTextFont;
  40. [_vDelete addSubview:lblDelete];
  41. [self addSubview:_vDelete];
  42. UITapGestureRecognizer *tapRecognizerDelete=[[UITapGestureRecognizer alloc] initWithTarget:self
  43. action:@selector(deleteOrder)];
  44. _vDelete.userInteractionEnabled=YES;
  45. [_vDelete addGestureRecognizer:tapRecognizerDelete];
  46. _vDelete.userInteractionEnabled=YES;
  47. _topSeparator=[UIView new];
  48. _topSeparator.frame=CGRectMake(0, CGRectGetMaxY(_vDelete.frame)+valuey, Screen_Width, heightLine);
  49. _topSeparator.backgroundColor=LineBackgroundColor;
  50. [self addSubview:_topSeparator];
  51. UILabel *lblGoodsCodeTitle=[UILabel new];
  52. lblGoodsCodeTitle.frame=CGRectMake(lblx,CGRectGetMaxY(_topSeparator.frame)+valuey,70, valueheight);
  53. lblGoodsCodeTitle.text=@"商品编码:";
  54. lblGoodsCodeTitle.font=orderTextFont;
  55. lblGoodsCodeTitle.textColor=LabelGrayTextColor;
  56. [self addSubview:lblGoodsCodeTitle];
  57. _lblGoodsCode=[UILabel new];
  58. NSString *goodsCode=_externalCoordinateModel.goodsCode;
  59. if(goodsCode!=nil){
  60. _lblGoodsCode.frame=CGRectMake(CGRectGetMaxX(lblGoodsCodeTitle.frame), CGRectGetMaxY(_topSeparator.frame)+valuey,Screen_Width/2-CGRectGetMaxX(lblGoodsCodeTitle.frame)-3, valueheight);
  61. _lblGoodsCode.text=goodsCode;
  62. _lblGoodsCode.font=orderTextFont;
  63. [self addSubview:_lblGoodsCode];
  64. }
  65. UILabel *lblOnlyCodeTitle=[UILabel new];
  66. lblOnlyCodeTitle.frame=CGRectMake(Screen_Width/2,CGRectGetMaxY(_topSeparator.frame)+valuey,70, valueheight);
  67. lblOnlyCodeTitle.text=@"唯一编码:";
  68. lblOnlyCodeTitle.font=orderTextFont;
  69. lblOnlyCodeTitle.textColor=LabelGrayTextColor;
  70. [self addSubview:lblOnlyCodeTitle];
  71. NSString *onlyCode=_externalCoordinateModel.onlyCode;
  72. if(onlyCode!=nil){
  73. _lblOnlyCode=[UILabel new];
  74. _lblOnlyCode.frame=CGRectMake(CGRectGetMaxX(lblOnlyCodeTitle.frame),CGRectGetMaxY(_topSeparator.frame)+valuey , Screen_Width/2-lblOnlyCodeTitle.frame.size.width-3, valueheight);
  75. _lblOnlyCode.text=onlyCode;
  76. _lblOnlyCode.font=orderTextFont;
  77. [self addSubview:_lblOnlyCode];
  78. }
  79. UILabel *lblColorNumberTitle=[UILabel new];
  80. lblColorNumberTitle.frame=CGRectMake(lblx, CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey,70, valueheight);
  81. lblColorNumberTitle.text=@"色号:";
  82. lblColorNumberTitle.font=orderTextFont;
  83. [lblColorNumberTitle sizeToFit];
  84. lblColorNumberTitle.textColor=LabelGrayTextColor;
  85. [self addSubview:lblColorNumberTitle];
  86. NSString *colorNumber=[_externalCoordinateModel colorNumber];
  87. if(colorNumber!=nil){
  88. _lblColorNumber=[UILabel new];
  89. _lblColorNumber.frame=CGRectMake(CGRectGetMaxX(lblColorNumberTitle.frame), CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey/2,Screen_Width/3-CGRectGetMaxX(lblColorNumberTitle.frame), valueheight);
  90. _lblColorNumber.font=orderTextFont;
  91. _lblColorNumber.text=colorNumber;
  92. [self addSubview:_lblColorNumber];
  93. }
  94. UILabel *lblSpecificationTitle=[UILabel new];
  95. lblSpecificationTitle.frame=CGRectMake(Screen_Width/3,CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey,70, valueheight);
  96. lblSpecificationTitle.text=@"规格:";
  97. lblSpecificationTitle.font=orderTextFont;
  98. [lblSpecificationTitle sizeToFit];
  99. lblSpecificationTitle.textColor=LabelGrayTextColor;
  100. [self addSubview:lblSpecificationTitle];
  101. NSString *specification=_externalCoordinateModel.specification;
  102. if(specification!=nil){
  103. _lblSpecification=[UILabel new];
  104. _lblSpecification.frame=CGRectMake(CGRectGetMaxX(lblSpecificationTitle.frame), CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey/2, Screen_Width/3-lblSpecificationTitle.frame.size.width-3, valueheight);
  105. _lblSpecification.text=specification;
  106. _lblSpecification.font=orderTextFont;
  107. [self addSubview:_lblSpecification];
  108. }
  109. UILabel *lblGradeTitle=[UILabel new];
  110. lblGradeTitle.frame=CGRectMake(Screen_Width/3*2,CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey,70, valueheight);
  111. lblGradeTitle.text=@"等级:";
  112. lblGradeTitle.font=orderTextFont;
  113. [lblGradeTitle sizeToFit];
  114. lblGradeTitle.textColor=LabelGrayTextColor;
  115. [self addSubview:lblGradeTitle];
  116. NSString *grade=_externalCoordinateModel.gradeName;
  117. if(grade!=nil){
  118. _lblGrade=[UILabel new];
  119. _lblGrade.frame=CGRectMake(CGRectGetMaxX(lblGradeTitle.frame), CGRectGetMaxY(lblGoodsCodeTitle.frame)+valuey/2, Screen_Width/3-lblGradeTitle.frame.size.width-3, valueheight);
  120. _lblGrade.text=grade;
  121. _lblGrade.font=orderTextFont;
  122. [self addSubview:_lblGrade];
  123. }
  124. _middleSeparator=[UIView new];
  125. _middleSeparator.frame=CGRectMake(0, CGRectGetMaxY(lblColorNumberTitle.frame)+valuey, Screen_Width, heightLine);
  126. _middleSeparator.backgroundColor=LineBackgroundColor;
  127. [self addSubview:_middleSeparator];
  128. _lblDiscount= [[UILabel alloc] init];
  129. [self updateFrame];
  130. [self addSubview:_lblDiscount];
  131. UIView *salesPriceView=[[UIView alloc]init];
  132. salesPriceView.layer.borderWidth=1.0f;
  133. salesPriceView.layer.borderColor=[LabelGrayTextColor CGColor];
  134. salesPriceView.frame=CGRectMake(Screen_Width-300, CGRectGetMaxY(_lblDiscount.frame)+10, 130,25 );
  135. [self addSubview: salesPriceView];
  136. UILabel *lblSymbol=[[UILabel alloc]init];
  137. lblSymbol.text=@"¥";
  138. lblSymbol.textColor=LabelGrayTextColor;
  139. lblSymbol.frame=CGRectMake(5,5,15,15);
  140. lblSymbol.font=orderTextFont;
  141. lblSymbol.textAlignment=NSTextAlignmentCenter;
  142. [salesPriceView addSubview:lblSymbol];
  143. NSString *salesPrice=_externalCoordinateModel.salesPrice;
  144. _txtSalesPrice=[UITextField new];
  145. _txtSalesPrice.frame=CGRectMake(CGRectGetMaxX(lblSymbol.frame), 0, 100, 25);
  146. _txtSalesPrice.text=salesPrice;
  147. _txtSalesPrice.userInteractionEnabled=YES;
  148. _txtSalesPrice.delegate=self;
  149. _txtSalesPrice.keyboardType=UIKeyboardTypeDecimalPad;
  150. _txtSalesPrice.tag=1001;
  151. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFocusPeopleEditingChanged:) name:@"UITextFieldTextDidChangeNotification" object:_txtSalesPrice ];
  152. _txtSalesPrice.textAlignment=NSTextAlignmentCenter;
  153. _txtSalesPrice.font=orderTextFont;
  154. [salesPriceView addSubview:_txtSalesPrice];
  155. UIImageView *penImg= [[UIImageView alloc]init];
  156. [penImg setImage:[UIImage imageNamed:@"icon_pen"]];
  157. penImg.frame=CGRectMake(salesPriceView.frame.size.width-17,5,12,12);
  158. [salesPriceView addSubview:penImg];
  159. UIButton *substractButton=[UIButton buttonWithType:UIButtonTypeCustom];
  160. [substractButton setTitle:@"-" forState:UIControlStateNormal];
  161. [substractButton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
  162. substractButton.frame=CGRectMake(CGRectGetMaxX(salesPriceView.frame)+10,CGRectGetMaxY(_lblDiscount.frame)+10,25,25);
  163. substractButton.layer.borderColor=[LabelGrayTextColor CGColor];
  164. substractButton.layer.borderWidth=1.0;
  165. [substractButton addTarget:self action:@selector(substractQuantity) forControlEvents:UIControlEventTouchUpInside];
  166. [self addSubview:substractButton];
  167. _txtSalesQuantity=[UITextField new];
  168. _txtSalesQuantity.frame=CGRectMake(CGRectGetMaxX(substractButton.frame)-1,CGRectGetMaxY(_lblDiscount.frame)+10,100,25);
  169. double salesQuantity= _externalCoordinateModel.salesQuantity;
  170. _txtSalesQuantity.text=[NSString stringWithFormat:@"%.2lf",salesQuantity];
  171. _txtSalesQuantity.delegate=self;
  172. _txtSalesQuantity.keyboardType=UIKeyboardTypeDecimalPad;
  173. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFocusPeopleEditingChanged:) name:@"UITextFieldTextDidChangeNotification" object:_txtSalesQuantity ];
  174. _txtSalesQuantity.layer.borderWidth=1.0f;
  175. _txtSalesQuantity.tag=1002;
  176. _txtSalesQuantity.textAlignment=NSTextAlignmentCenter;
  177. _txtSalesQuantity.layer.borderColor=[LabelGrayTextColor CGColor];
  178. _txtSalesQuantity.font=orderTextFont;
  179. [self addSubview:_txtSalesQuantity];
  180. UIButton *addButton=[UIButton buttonWithType:UIButtonTypeCustom];
  181. [addButton setTitle:@"+" forState:UIControlStateNormal];
  182. [addButton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
  183. addButton.frame=CGRectMake(CGRectGetMaxX(_txtSalesQuantity.frame)-1,CGRectGetMaxY(_lblDiscount.frame)+10,25,25);;
  184. addButton.layer.borderColor=[LabelGrayTextColor CGColor];
  185. addButton.layer.borderWidth=1.0;
  186. [addButton addTarget:self action:@selector(addQuantity) forControlEvents:UIControlEventTouchUpInside];
  187. [self addSubview:addButton];
  188. UIView *bottomSeparator=[[UIView alloc]init];
  189. bottomSeparator.frame=CGRectMake(0,CGRectGetMaxY(salesPriceView.frame)+10,Screen_Width, 10);
  190. bottomSeparator.backgroundColor=LineBackgroundColor;
  191. [self addSubview:bottomSeparator];
  192. if(editStatus==5){
  193. _txtSalesPrice.enabled=NO;
  194. _vDelete.userInteractionEnabled=NO;
  195. addButton.userInteractionEnabled=NO;
  196. substractButton.userInteractionEnabled=NO;
  197. _txtSalesQuantity.enabled=NO;
  198. }
  199. else if(editStatus==7||editStatus==10){
  200. _txtSalesPrice.enabled=NO;
  201. _vDelete.userInteractionEnabled=NO;
  202. addButton.userInteractionEnabled=NO;
  203. substractButton.userInteractionEnabled=NO;
  204. _txtSalesQuantity.enabled=NO;
  205. }else if (editStatus==4){
  206. _txtSalesPrice.enabled=NO;
  207. _vDelete.userInteractionEnabled=NO;
  208. addButton.userInteractionEnabled=NO;
  209. substractButton.userInteractionEnabled=NO;
  210. _txtSalesQuantity.enabled=NO;
  211. }
  212. if (editFlag==3){
  213. _txtSalesPrice.enabled=NO;
  214. _vDelete.userInteractionEnabled=NO;
  215. }
  216. }
  217. /**
  218. textField失去焦点回调函数
  219. */
  220. - (void) textFieldDidEndEditing:(UITextField *) field
  221. {
  222. [self endEditing:YES];
  223. if(field.tag==1001){
  224. NSString *salesPrice=field.text;
  225. if(salesPrice==nil||[salesPrice isEqualToString:@""]||[salesPrice isEqualToString:@"."]){
  226. field.text = _externalCoordinateModel.salesPrice;
  227. return;
  228. }
  229. _externalCoordinateModel.salesPrice=salesPrice;
  230. double markedPrice= [ _externalCoordinateModel.markedPrice doubleValue];
  231. if(salesPrice!=nil){
  232. if(markedPrice!=0){
  233. double discountValue=[salesPrice doubleValue]/markedPrice*100;
  234. _externalCoordinateModel.discount=[NSString stringWithFormat:@"%.2f",discountValue];
  235. }
  236. else{
  237. _externalCoordinateModel.discount=@"100";
  238. }
  239. }
  240. else{
  241. if(markedPrice!=0){
  242. _externalCoordinateModel.discount=@"0.0";
  243. }
  244. else{
  245. _externalCoordinateModel.discount=@"100";
  246. }
  247. }
  248. [self updateFrame];
  249. }
  250. else if(field.tag==1002){
  251. NSString *salesQuantity=field.text;
  252. if(salesQuantity==nil||[salesQuantity isEqualToString:@""]||[salesQuantity isEqualToString:@"."]){
  253. field.text = [NSString stringWithFormat:@"%.2f",_externalCoordinateModel.salesQuantity];
  254. return;
  255. }
  256. _externalCoordinateModel.salesQuantity=[salesQuantity doubleValue];
  257. field.text = salesQuantity;
  258. }
  259. if([self.orderDelegate respondsToSelector:@selector(updateNewSalesExternalCoordinateGoodsCell:textField:)])
  260. {
  261. [self.orderDelegate updateNewSalesExternalCoordinateGoodsCell:self textField:field];
  262. }
  263. }
  264. -(void)deleteOrder{
  265. if([self.orderDelegate respondsToSelector:@selector(deleteOrderDetail:)])
  266. {
  267. [self.orderDelegate deleteOrderDetail:_cellIndex];
  268. }
  269. }
  270. -(void)addQuantity{
  271. [self endEditing:YES];
  272. NSString *salesQuantity=_txtSalesQuantity.text;
  273. if(salesQuantity!=nil){
  274. double quantity=[salesQuantity doubleValue];
  275. ++quantity;
  276. NSString *salesQuantityStr= [NSString stringWithFormat:@"%.2f",quantity];
  277. _txtSalesQuantity.text=salesQuantityStr;
  278. _externalCoordinateModel.salesQuantity=quantity;
  279. if([self.orderDelegate respondsToSelector:@selector(updateNewSalesExternalCoordinateGoodsCell:textField:)])
  280. {
  281. [self.orderDelegate updateNewSalesExternalCoordinateGoodsCell:self textField:_txtSalesQuantity];
  282. }
  283. }
  284. }
  285. -(void)substractQuantity{
  286. [self endEditing:YES];
  287. NSString *salesQuantity=_txtSalesQuantity.text;
  288. if(salesQuantity!=nil){
  289. double quantity=[salesQuantity doubleValue];
  290. --quantity;
  291. if(quantity<0){
  292. quantity=0;
  293. }
  294. NSString *salesQuantityStr= [NSString stringWithFormat:@"%.2f",quantity];
  295. _txtSalesQuantity.text=salesQuantityStr;
  296. _externalCoordinateModel.salesQuantity=quantity;
  297. if([self.orderDelegate respondsToSelector:@selector(updateNewSalesExternalCoordinateGoodsCell:textField:)])
  298. {
  299. [self.orderDelegate updateNewSalesExternalCoordinateGoodsCell:self textField:_txtSalesQuantity];
  300. }
  301. }
  302. }
  303. /**
  304. 文本框的长度限制 实现监听方法
  305. @param sender <#sender description#>
  306. */
  307. - (void)onFocusPeopleEditingChanged:(NSNotification *)sender
  308. {
  309. UITextField *textField = (UITextField *)sender.object;
  310. NSString *toBeString = textField.text;
  311. NSString *lang = [[UIApplication sharedApplication]textInputMode].primaryLanguage;
  312. int kMaxLength = 0;
  313. if([textField isEqual:_txtSalesQuantity]){
  314. kMaxLength = 9;
  315. if (toBeString != nil && toBeString.length > 0 && [toBeString floatValue] -999999.99 > 0.0000000001f) {
  316. textField.text =@"999999.99";
  317. toBeString =@"999999.99" ;
  318. }
  319. }
  320. if([textField isEqual:_txtSalesPrice]){
  321. kMaxLength = 11;
  322. if (toBeString != nil && toBeString.length > 0 && [toBeString floatValue] -999999.9999 > 0.0000000001f) {
  323. textField.text =@"999999.9999";
  324. toBeString =@"999999.9999" ;
  325. }
  326. }
  327. if ([lang isEqualToString:@"zh-Hans"]) {
  328. UITextRange *selectedRange = [textField markedTextRange];
  329. UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
  330. if (!position) {
  331. if (toBeString.length > kMaxLength) {
  332. textField.text = [toBeString substringToIndex:kMaxLength];
  333. }
  334. }
  335. }else{
  336. if (toBeString.length > kMaxLength) {
  337. textField.text = [toBeString substringToIndex:kMaxLength];
  338. }
  339. }
  340. }
  341. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  342. [super setSelected:selected animated:animated];
  343. }
  344. /**
  345. 更新标价和折扣
  346. */
  347. - (void) updateFrame{
  348. NSString *discount=_externalCoordinateModel.discount;
  349. if(discount==nil){
  350. discount=@"0.0%";
  351. }
  352. else{
  353. discount=[NSString stringWithFormat:@"%@%@",discount,@"%"];
  354. }
  355. NSString *markedPrice=_externalCoordinateModel.markedPrice;
  356. _lblDiscount.text = [NSString stringWithFormat:@"标价:%@ 折扣:%@",markedPrice,discount];
  357. _lblDiscount.font = [UIFont systemFontOfSize:13];
  358. _lblDiscount.textColor = [UIColor redColor];
  359. [_lblDiscount sizeToFit];
  360. _lblDiscount.frame = CGRectMake(Screen_Width-CGRectGetWidth(_lblDiscount.frame)-10, CGRectGetMaxY(_middleSeparator.frame)+10, CGRectGetWidth(_lblDiscount.frame), CGRectGetHeight(_lblDiscount.frame));
  361. }
  362. @end