SubmitOrderTableViewCell.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. //
  2. // SubmitOrderCellTableViewCell.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2017/5/22.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. #import "SubmitOrderTableViewCell.h"
  9. #define orderTextFont [UIFont systemFontOfSize:14]
  10. @implementation SubmitOrderTableViewCell
  11. #pragma mark - 公共函数
  12. /**
  13. initWithStyle函数
  14. */
  15. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  16. {
  17. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  18. if (self) {
  19. }
  20. return self;
  21. }
  22. #pragma mark - 委托函数
  23. /**
  24. textField回调函数
  25. */
  26. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  27. {
  28. NSCharacterSet *cs;
  29. if(textField == _txtSalesQuantity)
  30. {
  31. cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERSANDDOT] invertedSet];
  32. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
  33. BOOL basicTest = [string isEqualToString:filtered];
  34. if(!basicTest)
  35. {
  36. return NO;
  37. }
  38. }
  39. if(textField == _txtSalesPrice)
  40. {
  41. cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERSANDDOT] invertedSet];
  42. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
  43. BOOL basicTest = [string isEqualToString:filtered];
  44. if(!basicTest)
  45. {
  46. return NO;
  47. }
  48. }
  49. return YES;
  50. }
  51. /**
  52. textField失去焦点回调函数
  53. */
  54. - (void) textFieldDidEndEditing:(UITextField *) field
  55. {
  56. [self endEditing:YES];
  57. if([self.delegate respondsToSelector:@selector(textValueChange: txtField:)])
  58. {
  59. [self.delegate textValueChange:self txtField:field];
  60. }
  61. }
  62. #pragma mark - 私有函数
  63. //初始化提交订单cell UI
  64. -(void)parseOrderInfo:(SubmitOrderFrame *)orderFrame{
  65. _cartItemModel= orderFrame.cartModel;
  66. _hiddenID=_cartItemModel.cartId;
  67. _lblCode=[[UILabel alloc]init];
  68. _lblCode.frame=[orderFrame lblProductCodeF];
  69. _lblCode.text=_cartItemModel.code;
  70. _lblCode.font=orderTextFont;
  71. [self.contentView addSubview:_lblCode];
  72. _lblCartId=[[UILabel alloc]init];
  73. _lblCartId.frame=CGRectMake(CGRectGetMaxX(orderFrame.lblProductCodeF)+3, orderFrame.lblProductCodeF.origin.y, 20, 20);
  74. _lblCartId.text=_cartItemModel.cartId;
  75. [self.contentView addSubview:_lblCartId];
  76. _lblCartId.hidden=YES;
  77. _lblMarkedPrice=[[UILabel alloc]init];
  78. NSString *markedPrice=_cartItemModel.markedPrice;
  79. _lblMarkedPrice.frame=[orderFrame lblMarkedPriceF];
  80. _lblMarkedPrice.font=orderTextFont;
  81. if(markedPrice!=nil){
  82. _lblMarkedPrice.textColor=LabelGrayTextColor;
  83. _lblMarkedPrice.text=[NSString stringWithFormat:@"¥ %@",markedPrice];
  84. }
  85. [self.contentView addSubview:_lblMarkedPrice];
  86. UIView *topSeparator=[[UIView alloc]init];
  87. topSeparator.frame=[orderFrame topSeparatorF];
  88. topSeparator.backgroundColor=LineBackgroundColor;
  89. [self.contentView addSubview:topSeparator];
  90. UILabel *lblTitleBrand=[[UILabel alloc]init];
  91. NSString *titleBrand=@"品牌:";
  92. lblTitleBrand.text=titleBrand;
  93. lblTitleBrand.font=orderTextFont;
  94. lblTitleBrand.textColor=LabelGrayTextColor;
  95. lblTitleBrand.frame=[orderFrame lblTitleBrandF];
  96. [self.contentView addSubview: lblTitleBrand];
  97. NSString *brand=[_cartItemModel brandName];
  98. if(brand!=nil){
  99. _lblBrandName=[[UILabel alloc]init];
  100. _lblBrandName.text=brand;
  101. _lblBrandName.font=orderTextFont;
  102. _lblBrandName.frame=[orderFrame lblBrandF];
  103. [self.contentView addSubview:_lblBrandName];
  104. }
  105. NSString *titleOnlyCode=@"唯一编码:";
  106. UILabel *lblTitleOnlyCode=[[UILabel alloc]init];
  107. lblTitleOnlyCode.text=titleOnlyCode;
  108. lblTitleOnlyCode.font=orderTextFont;
  109. lblTitleOnlyCode.textColor=LabelGrayTextColor;
  110. lblTitleOnlyCode.frame=[orderFrame lblTitleOnlyCodeF];
  111. [self.contentView addSubview: lblTitleOnlyCode];
  112. NSString *onlyCode=[_cartItemModel onlyCode];
  113. if(onlyCode!=nil){
  114. _lblOnlyCode=[[UILabel alloc]init];
  115. _lblOnlyCode.frame=[orderFrame lblOnlyCodeF];
  116. _lblOnlyCode.font=orderTextFont;
  117. _lblOnlyCode.text=onlyCode;
  118. [self.contentView addSubview: _lblOnlyCode];
  119. }
  120. NSString *titleColorNumber=@"色号:";
  121. UILabel *lblTitleColorNumber=[[UILabel alloc]init];
  122. lblTitleColorNumber.font=orderTextFont;
  123. lblTitleColorNumber.text=titleColorNumber;
  124. lblTitleColorNumber.textColor=LabelGrayTextColor;
  125. lblTitleColorNumber.frame=[orderFrame lblTitleColorNumberF];
  126. [self.contentView addSubview: lblTitleColorNumber];
  127. NSString *colorNumber=[_cartItemModel colorNumber];
  128. if(colorNumber!=nil){
  129. _lblColorNumber=[[UILabel alloc]init];
  130. _lblColorNumber.font=orderTextFont;
  131. _lblColorNumber.frame=[orderFrame lblColorNumberF];
  132. _lblColorNumber.text=colorNumber;
  133. [self.contentView addSubview:_lblColorNumber];
  134. }
  135. NSString *titleSpecification=@"规格:";
  136. UILabel *lblTitleSpecification=[[UILabel alloc]init];
  137. lblTitleSpecification.font=orderTextFont;
  138. lblTitleSpecification.text=titleSpecification;
  139. lblTitleSpecification.textColor=LabelGrayTextColor;
  140. lblTitleSpecification.frame=[orderFrame lblTitleSpecificationF];
  141. [self.contentView addSubview: lblTitleSpecification];
  142. NSString *specification=[_cartItemModel specification];
  143. if(specification!=nil){
  144. _lblSpecification=[[UILabel alloc]init];
  145. _lblSpecification.font=orderTextFont;
  146. _lblSpecification.frame=[orderFrame lblSpecificationF];
  147. _lblSpecification.text=specification;
  148. [self.contentView addSubview:_lblSpecification];
  149. }
  150. NSString *titleGrade=@"等级:";
  151. UILabel *lblTitleGrade=[[UILabel alloc]init];
  152. lblTitleGrade.font=orderTextFont;
  153. lblTitleGrade.text=titleGrade;
  154. lblTitleGrade.textColor=LabelGrayTextColor;
  155. lblTitleGrade.frame=[orderFrame lblTitleGradeF];
  156. [self.contentView addSubview: lblTitleGrade];
  157. NSString *grade=[_cartItemModel gradeName];
  158. if(grade!=nil){
  159. _lblGradeName=[[UILabel alloc]init];
  160. _lblGradeName.font=orderTextFont;
  161. _lblGradeName.frame=[orderFrame lblGradeF];
  162. _lblGradeName.text=grade;
  163. [self.contentView addSubview:_lblGradeName];
  164. }
  165. NSString *titleWareHouse=@"库区:";
  166. UILabel *lblTitleWareHouse=[[UILabel alloc]init];
  167. lblTitleWareHouse.font=orderTextFont;
  168. lblTitleWareHouse.text=titleWareHouse;
  169. lblTitleWareHouse.textColor=LabelGrayTextColor;
  170. lblTitleWareHouse.frame=[orderFrame lblTitleWareHouseAreaF];
  171. [self.contentView addSubview: lblTitleWareHouse];
  172. NSString *warehouse=[_cartItemModel warehouseName];
  173. if(warehouse!=nil){
  174. _lblWarehouseName=[[UILabel alloc]init];
  175. _lblWarehouseName.font=orderTextFont;
  176. _lblWarehouseName.frame=[orderFrame lblWareHouseAreaF];
  177. _lblWarehouseName.text=warehouse;
  178. [self.contentView addSubview:_lblWarehouseName];
  179. }
  180. UIView *middleSeparator=[[UIView alloc]init];
  181. middleSeparator.frame=[orderFrame middleSeparatorF];
  182. middleSeparator.backgroundColor=LineBackgroundColor;
  183. [self.contentView addSubview:middleSeparator];
  184. UIView *salesPriceView=[[UIView alloc]init];
  185. salesPriceView.layer.borderWidth=1.0f;
  186. salesPriceView.layer.borderColor=[UIColor blackColor].CGColor;
  187. salesPriceView.frame=[orderFrame vSalesPriceF];
  188. [self.contentView addSubview: salesPriceView];
  189. UILabel *lblSymbol=[[UILabel alloc]init];
  190. lblSymbol.text=@"¥";
  191. lblSymbol.textColor=LabelGrayTextColor;
  192. lblSymbol.frame=CGRectMake(5,5,15,15);
  193. lblSymbol.font=orderTextFont;
  194. lblSymbol.textAlignment=NSTextAlignmentCenter;
  195. [salesPriceView addSubview:lblSymbol];
  196. _txtSalesPrice=[UITextField new];
  197. _txtSalesPrice.frame=CGRectMake(CGRectGetMaxX(lblSymbol.frame)+5, 0, 50, 25);
  198. _txtSalesPrice.text=[_cartItemModel salesPrice];
  199. _txtSalesPrice.userInteractionEnabled=YES;
  200. _txtSalesPrice.delegate=self;
  201. _txtSalesPrice.keyboardType=UIKeyboardTypeDecimalPad;
  202. _txtSalesPrice.tag=1001;
  203. _txtSalesPrice.textAlignment=NSTextAlignmentCenter;
  204. _txtSalesPrice.font=orderTextFont;
  205. [salesPriceView addSubview:_txtSalesPrice];
  206. UIImageView *penImg= [[UIImageView alloc]init];
  207. [penImg setImage:[UIImage imageNamed:@"icon_pen"]];
  208. penImg.frame=CGRectMake(salesPriceView.frame.size.width-17,5,12,12);
  209. [salesPriceView addSubview:penImg];
  210. UIButton *substractButton=[UIButton buttonWithType:UIButtonTypeCustom];
  211. [substractButton setTitle:@"-" forState:UIControlStateNormal];
  212. [substractButton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
  213. substractButton.frame=orderFrame.btnSubstractQuantityF;
  214. substractButton.layer.borderColor=[UIColor blackColor].CGColor;
  215. substractButton.layer.borderWidth=1.0;
  216. [substractButton addTarget:self action:@selector(substractQuantity) forControlEvents:UIControlEventTouchUpInside];
  217. [self.contentView addSubview:substractButton];
  218. _txtSalesQuantity=[UITextField new];
  219. _txtSalesQuantity.frame=orderFrame.txtQuantityF;
  220. if(_cartItemModel.salesQuantity!=nil){
  221. _txtSalesQuantity.text=_cartItemModel.salesQuantity;
  222. }
  223. _txtSalesQuantity.delegate=self;
  224. _txtSalesQuantity.keyboardType=UIKeyboardTypeDecimalPad;
  225. _txtSalesQuantity.layer.borderWidth=1.0f;
  226. _txtSalesQuantity.tag=1002;
  227. _txtSalesQuantity.textAlignment=NSTextAlignmentCenter;
  228. _txtSalesQuantity.layer.borderColor=[UIColor blackColor].CGColor;
  229. _txtSalesQuantity.font=orderTextFont;
  230. [self.contentView addSubview:_txtSalesQuantity];
  231. UIButton *addButton=[UIButton buttonWithType:UIButtonTypeCustom];
  232. [addButton setTitle:@"+" forState:UIControlStateNormal];
  233. [addButton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
  234. addButton.frame=orderFrame.btnAddQuantityF;
  235. addButton.layer.borderColor=[UIColor blackColor].CGColor;
  236. addButton.layer.borderWidth=1.0;
  237. [addButton addTarget:self action:@selector(addQuantity) forControlEvents:UIControlEventTouchUpInside];
  238. [self.contentView addSubview:addButton];
  239. UIView *bottomSeparator=[[UIView alloc]init];
  240. bottomSeparator.frame=[orderFrame bottomSeparatorF];
  241. bottomSeparator.backgroundColor=LineBackgroundColor;
  242. [self.contentView addSubview:bottomSeparator];
  243. }
  244. //订单数量增加函数
  245. -(void)addQuantity{
  246. NSString *quantity=_txtSalesQuantity.text;
  247. if(quantity!=nil){
  248. double quantityValue=quantity.doubleValue;
  249. NSInteger circulateType= _cartItemModel.circulateType;
  250. if(circulateType==2){
  251. [self.delegate alertMessage:@"请手动输入商品数量"];
  252. return;
  253. }
  254. ++quantityValue;
  255. NSString *quantity= [NSString stringWithFormat:@"%lld",(long long)quantityValue];
  256. _txtSalesQuantity.text=quantity;
  257. if([self.delegate respondsToSelector:@selector(textValueChange: txtField:)])
  258. {
  259. [self.delegate textValueChange:self txtField:_txtSalesQuantity];
  260. }
  261. }
  262. }
  263. //订单数量减少函数
  264. -(void)substractQuantity{
  265. NSString *quantity=_txtSalesQuantity.text;
  266. if(quantity!=nil){
  267. double quantityValue=quantity.doubleValue;
  268. NSInteger circulateType= _cartItemModel.circulateType;
  269. if(circulateType==2){
  270. [self.delegate alertMessage:@"请手动输入商品数量"];
  271. return;
  272. }
  273. --quantityValue;
  274. if(quantityValue<0){
  275. quantityValue=0;
  276. }
  277. NSString *quantity= [NSString stringWithFormat:@"%lld",(long long)quantityValue];
  278. _txtSalesQuantity.text=quantity;
  279. if([self.delegate respondsToSelector:@selector(textValueChange: txtField:)])
  280. {
  281. [self.delegate textValueChange:self txtField:_txtSalesQuantity];
  282. }
  283. }
  284. }
  285. @end