/chooseGoods_Attr/ShoppingCar(购物车)/View/ShoppingCarTableViewCell.m

https://github.com/huazhixi/chooseGoodsAttributesDemo · Objective C · 99 lines · 76 code · 16 blank · 7 comment · 12 complexity · 134e9a299a56b44aa28ff9040ae7a149 MD5 · raw file

  1. //
  2. // ShoppingCarTableViewCell.m
  3. // AiMeiBang
  4. //
  5. // Created by Lingxiu on 16/1/27.
  6. // Copyright © 2016年 zym. All rights reserved.
  7. //
  8. #import "ShoppingCarTableViewCell.h"
  9. #import "BuyCarModel.h"
  10. #import "UIImageView+WebCache.h"
  11. #import "ACMacros.h"
  12. @interface ShoppingCarTableViewCell ()
  13. @property (weak, nonatomic) IBOutlet UIImageView *goodImgView;
  14. @property (weak, nonatomic) IBOutlet UILabel *goodNameLbl;
  15. @property (weak, nonatomic) IBOutlet UILabel *buyNumLbl;
  16. @property (weak, nonatomic) IBOutlet UILabel *goodPriceLbl;
  17. @property (weak, nonatomic) IBOutlet UILabel *calculateLbl;
  18. @end
  19. @implementation ShoppingCarTableViewCell
  20. + (instancetype)cellWithTableView:(UITableView *)tableView {
  21. static NSString *ShoppingCarTableViewCellID = @"ShoppingCarTableViewCell";
  22. ShoppingCarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ShoppingCarTableViewCellID];
  23. if (!cell) {
  24. cell = [[NSBundle mainBundle] loadNibNamed:@"ShoppingCarTableViewCell" owner:self options:nil].lastObject;
  25. }
  26. return cell;
  27. }
  28. - (void)awakeFromNib {
  29. self.calculateView.hidden = YES;
  30. self.deleteBtn.hidden = YES;
  31. self.calculateView.layer.borderWidth = 1;
  32. self.calculateView.layer.borderColor = LXBorderColor.CGColor;
  33. }
  34. - (void)setBuyCarModel:(BuyCarModel *)buyCarModel {
  35. _buyCarModel = buyCarModel;
  36. [_goodImgView sd_setImageWithURL:[NSURL URLWithString:buyCarModel.goods_img] placeholderImage:nil];
  37. _goodNameLbl.text = buyCarModel.goods_name;
  38. _calculateLbl.text = buyCarModel.num;
  39. _buyNumLbl.text = [NSString stringWithFormat:@"x%@", buyCarModel.num];
  40. _goodPriceLbl.text = [NSString stringWithFormat:@"¥%@", buyCarModel.shop_price];
  41. float totalPrice = [buyCarModel.shop_price floatValue] * [buyCarModel.num intValue];
  42. _totalPriceLbl.text = [NSString stringWithFormat:@"¥%.2f", totalPrice];
  43. if (buyCarModel.isSelected) {//判断cell的选中状态
  44. self.selectBtn.selected = YES;
  45. } else {
  46. self.selectBtn.selected = NO;
  47. }
  48. if (buyCarModel.isCalculateViewHidden) {
  49. self.calculateView.hidden = YES;
  50. _buyNumLbl.text = [NSString stringWithFormat:@"x%@", _calculateLbl.text];
  51. float totalPrice = [buyCarModel.shop_price floatValue] * [_calculateLbl.text intValue];
  52. _totalPriceLbl.text = [NSString stringWithFormat:@"¥%.2f", totalPrice];
  53. } else {
  54. self.calculateView.hidden = NO;
  55. _buyNumLbl.text = [NSString stringWithFormat:@"x%@", _calculateLbl.text];
  56. float totalPrice = [buyCarModel.shop_price floatValue] * [_calculateLbl.text intValue];
  57. _totalPriceLbl.text = [NSString stringWithFormat:@"¥%.2f", totalPrice];
  58. }
  59. }
  60. - (IBAction)downBtnClick:(UIButton *)sender {
  61. sender.selected = !sender.selected;
  62. if (self.selectBtnClick) {
  63. self.selectBtnClick(sender.selected);
  64. }
  65. }
  66. - (IBAction)pmBtnClick:(UIButton *)sender {
  67. int num = [self.calculateLbl.text intValue];
  68. if (sender.tag == 2) {
  69. num += 1;
  70. self.calculateLbl.text = [NSString stringWithFormat:@"%d", num];
  71. } else {
  72. num -=1;
  73. if (num <= 0) {
  74. return;
  75. } else {
  76. self.calculateLbl.text = [NSString stringWithFormat:@"%d", num];
  77. }
  78. }
  79. if (self.pmBtnClick) {
  80. self.pmBtnClick(_calculateLbl.text);
  81. }
  82. }
  83. @end