CartTableViewCell.m 11 KB

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