GoodsSearchCell.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. //
  2. // WareHouseCell.m
  3. // IBOSSIPAD
  4. //
  5. // Created by iHope on 14-7-21.
  6. // Copyright (c) 2014年 elongtian. All rights reserved.
  7. //
  8. #import "GoodsSearchCell.h"
  9. #import "GoodsSearchModel.h"
  10. #import "GoodsSearchItemModel.h"
  11. #import "OrderQuantity.h"
  12. @interface GoodsSearchCell()<UITextFieldDelegate,UITextFieldDelegate>
  13. {
  14. }
  15. @end
  16. @implementation GoodsSearchCell
  17. #pragma mark - 公共函数
  18. /**
  19. initWithStyle函数
  20. */
  21. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  22. {
  23. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  24. if (self) {
  25. }
  26. return self;
  27. }
  28. /**
  29. setSelected函数
  30. */
  31. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  32. {
  33. [super setSelected:selected animated:animated];
  34. }
  35. #pragma mark - 委托函数
  36. /**
  37. 数量回调函数
  38. */
  39. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  40. {
  41. NSCharacterSet *cs;
  42. if(textField == _txtQuantity)
  43. {
  44. cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERSANDDOT] invertedSet];
  45. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
  46. BOOL basicTest = [string isEqualToString:filtered];
  47. if(!basicTest)
  48. {
  49. return NO;
  50. }
  51. }
  52. return YES;
  53. }
  54. /**
  55. 文本回调函数
  56. */
  57. - (void) textFieldDidEndEditing:(UITextField *) field
  58. {
  59. [self endEditing:YES];
  60. if([self.delegate respondsToSelector:@selector(textValueChange: txtField:)])
  61. {
  62. [self.delegate textValueChange:self txtField:field];
  63. }
  64. }
  65. #pragma mark - 私有函数
  66. /**
  67. 初始化订单cell UI
  68. */
  69. -(void)parseOrderInfo:(OrderSearchFrame *)orderFrame
  70. {
  71. _searchItemModel=orderFrame.searchModel;
  72. _lblCode=[[UILabel alloc]init];
  73. _lblCode.frame=orderFrame.productCodeF;
  74. _lblCode.text=_searchItemModel.code;
  75. _lblCode.font=orderTextFont;
  76. [self.contentView addSubview:_lblCode];
  77. _lblInventoryId=[[UILabel alloc]init];
  78. _lblInventoryId.frame=orderFrame.inventoryIdF;
  79. [self.contentView addSubview:_lblInventoryId];
  80. _lblInventoryId.hidden=YES;
  81. _lblInventoryId.text=_searchItemModel.inventoryID;
  82. UIButton *substractButton=[UIButton buttonWithType:UIButtonTypeCustom];
  83. [substractButton setTitle:@"-" forState:UIControlStateNormal];
  84. [substractButton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
  85. substractButton.frame=orderFrame.substractBtnF;
  86. substractButton.layer.borderColor=[UIColor blackColor].CGColor;
  87. substractButton.layer.borderWidth=1.0;
  88. [substractButton addTarget:self action:@selector(substractQuantity) forControlEvents:UIControlEventTouchUpInside];
  89. [self.contentView addSubview:substractButton];
  90. _txtQuantity=[UITextField new];
  91. _txtQuantity.frame=orderFrame.salesQuantityF;
  92. _txtQuantity.text=_searchItemModel.salesQuantity;
  93. _txtQuantity.delegate=self;
  94. _txtQuantity.keyboardType= UIKeyboardTypeDecimalPad;
  95. _txtQuantity.layer.borderWidth=1.0f;
  96. _txtQuantity.tag=1002;
  97. _txtQuantity.textAlignment=NSTextAlignmentCenter;
  98. _txtQuantity.layer.borderColor=[UIColor blackColor].CGColor;
  99. _txtQuantity.font=orderTextFont;
  100. [self.contentView addSubview:_txtQuantity];
  101. UIButton *addButton=[UIButton buttonWithType:UIButtonTypeCustom];
  102. [addButton setTitle:@"+" forState:UIControlStateNormal];
  103. [addButton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
  104. addButton.frame=orderFrame.addBtnF;
  105. addButton.layer.borderColor=[UIColor blackColor].CGColor;
  106. addButton.layer.borderWidth=1.0;
  107. [addButton addTarget:self action:@selector(addQuantity) forControlEvents:UIControlEventTouchUpInside];
  108. [self.contentView addSubview:addButton];
  109. UIButton *joinCartBtn=[UIButton buttonWithType:UIButtonTypeCustom];
  110. joinCartBtn.frame=orderFrame.joinCartBtnF;
  111. [joinCartBtn setImage:[UIImage imageNamed:@"bt_cart"] forState:UIControlStateNormal];
  112. [self.contentView addSubview:joinCartBtn];
  113. [ joinCartBtn addTarget:self action:@selector(goCart) forControlEvents:UIControlEventTouchUpInside];
  114. UIView *middleView=[[UIView alloc]init];
  115. middleView.frame=orderFrame.middleSeparatorF;
  116. middleView.backgroundColor=LineBackgroundColor;
  117. [self.contentView addSubview:middleView];
  118. UILabel *titleBrandLbl=[[UILabel alloc]init];
  119. titleBrandLbl.text=@"品牌:";
  120. titleBrandLbl.textColor=LabelGrayTextColor;
  121. titleBrandLbl.font=orderTextFont;
  122. titleBrandLbl.frame=orderFrame.titleBrandF;
  123. [self.contentView addSubview:titleBrandLbl];
  124. _lblBrandName=[[UILabel alloc]init];
  125. if(_searchItemModel.brandName!=nil){
  126. _lblBrandName.text=_searchItemModel.brandName;
  127. _lblBrandName.frame=orderFrame.brandF;
  128. _lblBrandName.font=orderTextFont;
  129. [self.contentView addSubview:_lblBrandName];
  130. }
  131. UILabel *titleOnlyCodeLbl=[[UILabel alloc]init];
  132. titleOnlyCodeLbl.text=@"唯一编码:";
  133. titleOnlyCodeLbl.font=orderTextFont;
  134. titleOnlyCodeLbl.textColor=LabelGrayTextColor;
  135. titleOnlyCodeLbl.frame=orderFrame.titleOnlyCodeF;
  136. [self.contentView addSubview:titleOnlyCodeLbl];
  137. _lblOnlyCode=[[UILabel alloc]init];
  138. NSString *onlyCode=[_searchItemModel onlyCode];
  139. if(onlyCode!=nil){
  140. _lblOnlyCode.text=onlyCode;
  141. _lblOnlyCode.frame=orderFrame.onlyCodeF;
  142. _lblOnlyCode.font=orderTextFont;
  143. [self.contentView addSubview:_lblOnlyCode];
  144. }
  145. UILabel *titleColorNumber=[[UILabel alloc]init];
  146. titleColorNumber.text=@"色号:";
  147. titleColorNumber.font=orderTextFont;
  148. titleColorNumber.textColor=LabelGrayTextColor;
  149. titleColorNumber.frame=orderFrame.titleColorNumberF;
  150. [self.contentView addSubview:titleColorNumber];
  151. _lblColorNumber=[[UILabel alloc]init];
  152. if(_searchItemModel.colorNumber!=nil){
  153. _lblColorNumber.frame=orderFrame.colorNumberF;
  154. _lblColorNumber.text=_searchItemModel.colorNumber;
  155. _lblColorNumber.font=orderTextFont;
  156. [self.contentView addSubview:_lblColorNumber];
  157. }
  158. UILabel *titleSpecificationLbl=[[UILabel alloc]init];
  159. titleSpecificationLbl.text=@"规格:";
  160. titleSpecificationLbl.font=orderTextFont;
  161. titleSpecificationLbl.textColor=LabelGrayTextColor;
  162. titleSpecificationLbl.font=orderTextFont;
  163. titleSpecificationLbl.frame=orderFrame.titleSpecificationF;
  164. [self.contentView addSubview:titleSpecificationLbl];
  165. _lblSpecification=[[UILabel alloc]init];
  166. if(_searchItemModel.specification!=nil){
  167. _lblSpecification.text=_searchItemModel.specification;
  168. _lblSpecification.frame=orderFrame.specificationF;
  169. _lblSpecification.font=orderTextFont;
  170. [self.contentView addSubview:_lblSpecification];
  171. }
  172. UILabel *titleLevelLbl=[[UILabel alloc]init];
  173. titleLevelLbl.text=@"等级:";
  174. titleLevelLbl.font=orderTextFont;
  175. titleLevelLbl.textColor=LabelGrayTextColor;
  176. titleLevelLbl.frame=orderFrame.titleLevelF;
  177. [self.contentView addSubview:titleLevelLbl];
  178. _lblGradeName=[[UILabel alloc]init];
  179. if(_searchItemModel.gradeName!=nil){
  180. _lblGradeName.frame=orderFrame.levelF;
  181. _lblGradeName.text=_searchItemModel.gradeName;
  182. _lblGradeName.font=orderTextFont;
  183. [self.contentView addSubview:_lblGradeName];
  184. }
  185. UILabel *titleWarehouseAreaLbl=[[UILabel alloc]init];
  186. titleWarehouseAreaLbl.text=@"库区:";
  187. titleWarehouseAreaLbl.font=orderTextFont;
  188. titleWarehouseAreaLbl.textColor=LabelGrayTextColor;
  189. titleWarehouseAreaLbl.frame=orderFrame.titleWarehouseAreaF;
  190. [self.contentView addSubview:titleWarehouseAreaLbl];
  191. _lblWareHouseName=[[UILabel alloc]init];
  192. if(_searchItemModel.warehouseName!=nil){
  193. _lblWareHouseName.text=_searchItemModel.warehouseName;
  194. _lblWareHouseName.frame=orderFrame.warehouseAreaF;
  195. _lblWareHouseName.font=orderTextFont;
  196. [self.contentView addSubview:_lblWareHouseName];
  197. }
  198. UIView *bottomline= [[UIView alloc]init];
  199. bottomline.frame = orderFrame.separatorF;
  200. bottomline.backgroundColor = LineBackgroundColor;
  201. [self.contentView addSubview:bottomline];
  202. UILabel *lbBottomText = [[UILabel alloc] init];
  203. lbBottomText.frame = orderFrame.bottomTextF;
  204. lbBottomText.textAlignment = NSTextAlignmentRight;
  205. lbBottomText.textColor =[UIColor blackColor];
  206. lbBottomText.text = [NSString stringWithFormat:@"可售量:%@ 结存量:%@",_searchItemModel.balanceQuantity,_searchItemModel.inventoryQuantity];
  207. lbBottomText.font = orderTextFont;
  208. [self.contentView addSubview:lbBottomText];
  209. UIView *bottomSeparatorView=[[UIView alloc]init];
  210. bottomSeparatorView.frame=orderFrame.bottomSeparatorF;
  211. bottomSeparatorView.backgroundColor=LineBackgroundColor;
  212. [self.contentView addSubview:bottomSeparatorView];
  213. }
  214. //订单数量减少函数
  215. -(void)substractQuantity{
  216. NSString *quantity=_txtQuantity.text;
  217. if(quantity!=nil){
  218. double quantityValue=quantity.doubleValue;
  219. NSInteger circulateType= _searchItemModel.circulateType;
  220. if(circulateType==2){
  221. [self.delegate alertMessage:@"请手动输入商品数量"];
  222. return;
  223. }
  224. --quantityValue;
  225. if(quantityValue<0){
  226. quantityValue=0;
  227. }
  228. NSString *quantity= [NSString stringWithFormat:@"%lld",(long long)quantityValue];
  229. _txtQuantity.text=quantity;
  230. if([self.delegate respondsToSelector:@selector(textValueChange: txtField:)])
  231. {
  232. [self.delegate textValueChange:self txtField:_txtQuantity];
  233. }
  234. }
  235. }
  236. //订单数量增加函数
  237. -(void)addQuantity{
  238. NSString *quantity=_txtQuantity.text;
  239. if(quantity!=nil){
  240. double quantityValue=quantity.doubleValue;
  241. NSInteger circulateType= _searchItemModel.circulateType;
  242. if(circulateType==2){
  243. [self.delegate alertMessage:@"请手动输入商品数量"];
  244. return;
  245. }
  246. ++quantityValue;
  247. NSString *quantity= [NSString stringWithFormat:@"%lld",(long long)quantityValue];
  248. _txtQuantity.text=quantity;
  249. if([self.delegate respondsToSelector:@selector(textValueChange: txtField:)])
  250. {
  251. [self.delegate textValueChange:self txtField:_txtQuantity];
  252. }
  253. }
  254. }
  255. //加入购物车函数
  256. -(void)goCart{
  257. [self endEditing:YES];
  258. if([self.delegate respondsToSelector:@selector(joinCart:)])
  259. {
  260. [self.delegate joinCart:_searchItemModel];
  261. }
  262. }
  263. @end