ShoppingCell.m 5.74 KB
Newer Older
zhu's avatar
zhu committed
1 2 3 4 5 6 7 8 9
//
//  ShoppingCell.m
//  Lighting
//
//  Created by mac on 16/5/23.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ShoppingCell.h"
10 11
#define Width 760
#define Height 90
zhu's avatar
zhu committed
12 13 14 15 16 17 18
#define Gap     5
@implementation ShoppingCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
19
        self.value=1;
20
        self.customGoods=[[CustomTOGoodsEntity alloc]init];
zhu's avatar
zhu committed
21 22 23 24 25 26 27 28
        [self bulidLayout];
    }
    return self;
}

- (void)bulidLayout
{
//    选中
29
    self.selectedButton=[[CustomShopingSeclectButton alloc]initWithFrame:CGRectMake(20, 25, Width/12-40, Height-50)];
zhu's avatar
zhu committed
30 31 32 33 34
    [self.selectedButton setBackgroundImage:[UIImage imageNamed:@"box-副本"] forState:UIControlStateNormal];
//    box-副本
    [self.contentView addSubview:self.selectedButton];
    
//   商品图片
35
    self.goodsImageView=[[UIImageView alloc]initWithFrame:CGRectMake(Width/12, 0, 2*Width/12, Height)];
zhu's avatar
zhu committed
36 37 38 39
    self.goodsImageView.image=[UIImage imageNamed:@"05产品库-详情_03"];
    //05产品库-详情_03
     [self.contentView addSubview:self.goodsImageView];
//     商品信息
40
    self.goodsInformationLabe=[[UILabel alloc]initWithFrame:CGRectMake(3*Width/12, 0, 4*Width/12, Height)];
zhu's avatar
zhu committed
41
    self.goodsInformationLabe.text=@"吊灯jkdsfhkdhfkdsh\n2000133434";
42
     self.goodsInformationLabe.textAlignment=NSTextAlignmentCenter;
zhu's avatar
zhu committed
43 44 45
    self.goodsInformationLabe.numberOfLines=0;
     [self.contentView addSubview:self.goodsInformationLabe];
//   吊牌价格
46 47 48
    self.tagsPriceLabe=[[UILabel alloc]initWithFrame:CGRectMake(7*Width/12, 0,2*Width/12, Height)];
    self.tagsPriceLabe.text=@"¥5500";
    self.tagsPriceLabe.textAlignment=NSTextAlignmentCenter;
zhu's avatar
zhu committed
49
     [self.contentView addSubview:self.tagsPriceLabe];
50 51 52 53
////    成交价格
//    self.clinchTextfield=[[UITextField alloc]initWithFrame:CGRectMake(8*Width/15, 0, 2*Width/15, Height)];
//    self.clinchTextfield.text=@"$5500";
//     [self.contentView addSubview:self.clinchTextfield];
zhu's avatar
zhu committed
54
//    数量减
55
    self.reduceButton=[[UIButton alloc]initWithFrame:CGRectMake(9*Width/12, 20, Width/12-5, Height-40)];
zhu's avatar
zhu committed
56
    [self.reduceButton setTitle:@"-" forState:UIControlStateNormal];
57 58
    self.reduceButton.titleLabel.font=[UIFont systemFontOfSize:18];
    self.reduceButton.backgroundColor=RGB(249, 244, 241, 1);
zhu's avatar
zhu committed
59 60
    [self.reduceButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.reduceButton.titleLabel.font= [UIFont systemFontOfSize: 18.0];
61 62
    self.reduceButton.tag=100;
    [self.reduceButton addTarget:self action:@selector(resetVale:) forControlEvents:UIControlEventTouchUpInside];
zhu's avatar
zhu committed
63 64
    [self.contentView addSubview:self.reduceButton];
//    商品数量
65 66 67 68 69 70
    self.goodsNumbersLabe=[[UILabel alloc]initWithFrame:CGRectMake(10*Width/12, 20, Width/12, Height-40)];
    self.goodsNumbersLabe.text=[NSString stringWithFormat:@"%d",self.value];
     self.goodsNumbersLabe.layer.masksToBounds = YES;
    self.goodsNumbersLabe.layer.cornerRadius=5;
    self.goodsNumbersLabe.layer.borderWidth=1;
    self.goodsNumbersLabe.layer.borderColor=[UIColor grayColor].CGColor;
zhu's avatar
zhu committed
71 72 73
    self.goodsNumbersLabe.textAlignment=NSTextAlignmentCenter;
     [self.contentView addSubview:self.goodsNumbersLabe];
//    数量加
74
    self.addButton=[[UIButton alloc]initWithFrame:CGRectMake(11*Width/12+5, 20, Width/12-5, Height-40)];
zhu's avatar
zhu committed
75
    [self.addButton setTitle:@"+" forState:UIControlStateNormal];
76 77
    self.addButton.titleLabel.font=[UIFont systemFontOfSize:18];
    self.addButton.backgroundColor=RGB(249, 244, 241, 1);
zhu's avatar
zhu committed
78 79
    [self.addButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.addButton.titleLabel.font= [UIFont systemFontOfSize: 18.0];
80 81
    self.addButton.tag=200;
    [self.addButton addTarget:self action:@selector(resetVale:) forControlEvents:UIControlEventTouchUpInside];
zhu's avatar
zhu committed
82
    [self.contentView addSubview:self.addButton];
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(15, Height-1, Width-20, 1)];
    lable.backgroundColor=[UIColor grayColor];
    [self.contentView addSubview:lable];
////    产品金额
//    self.productPriceLabe=[[UILabel alloc]initWithFrame:CGRectMake(13*Width/15, 0, 2*Width/15, Height)];
//     self.productPriceLabe.text=@"$5500";
//    self.productPriceLabe.textColor=[UIColor redColor];
//    [self.contentView addSubview:self.productPriceLabe];
}
-(void)resetVale:(UIButton *)sender
{
    switch (sender.tag) {
        case 100://减少
        {
            if (self.value<=1) {
98
                 [self ErrorMBProgressView:@"不能小于1"];
99 100 101 102 103 104 105 106 107 108 109
                return;
            }else
            {
                self.value-=1;
            }
            
        }
            
            break;
        case 200://增加
        {
110 111
//        //不能大于库存
//        [self ErrorMBProgressView:@"超过库存"];
112 113 114 115 116 117 118 119 120
            self.value+=1;
        }
            
            break;
            
        default:
            break;
    }
    self.goodsNumbersLabe.text=[NSString stringWithFormat:@"%d",self.value];
zhu's avatar
zhu committed
121
}
122 123 124 125 126 127 128 129 130 131 132 133 134
#pragma mark -显示错误的提示框
- (void)ErrorMBProgressView:(NSString *)errorString
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.superview animated:YES];
    hud.labelText = errorString;
    hud.margin = 10.f;
    hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    hud.minSize = CGSizeMake(250, 70);
    hud.animationType = MBProgressHUDAnimationZoom;
    hud.mode = MBProgressHUDModeText;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1.0f];
}
zhu's avatar
zhu committed
135 136 137 138 139 140 141 142 143 144 145 146
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end