ShoppingTableViewCell.m 4.6 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//
//  ShoppingTableViewCell.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/29.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ShoppingTableViewCell.h"

@implementation ShoppingTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
勾芒's avatar
勾芒 committed
16 17
    
    [self uiConfigAction];
曹云霄's avatar
曹云霄 committed
18 19 20
}


勾芒's avatar
勾芒 committed
21 22 23 24 25
#pragma mark -UI
- (void)uiConfigAction
{
    self.ClinchPriceBackView.layer.masksToBounds = YES;
    self.ClinchPriceBackView.layer.cornerRadius = kCornerRadius;
勾芒's avatar
勾芒 committed
26
    self.clinchTextfield.delegate = self;
勾芒's avatar
勾芒 committed
27 28
}

勾芒's avatar
勾芒 committed
29 30 31 32
#pragma mark -赋值
- (void)setModel:(ShopcarModel *)model
{
    _model = model;
勾芒's avatar
勾芒 committed
33
    self.selectedButton.selected = _model.isSelected;
勾芒's avatar
勾芒 committed
34 35
    NSArray *images = [_model.goods.pictures componentsSeparatedByString:@","];
    [self.goodsImageView sd_setImageWithURL:[NSURL URLWithString:[images firstObject]] placeholderImage:REPLACEIMAGE];
勾芒's avatar
勾芒 committed
36
    self.goodsInformationLabe.text = _model.goods.name;
polo2013's avatar
polo2013 committed
37 38
    self.specifications.text = _model.goods.size;
    self.goodsCode.text = _model.goods.code;
勾芒's avatar
勾芒 committed
39
    self.tagsPriceLabe.text = [_model.goods.tagPrice stringValue];
勾芒's avatar
勾芒 committed
40
    self.clinchTextfield.text = [NSString stringWithFormat:@"%.2f",[_model.costPrice floatValue]?[_model.costPrice floatValue]:[_model.goods.tagPrice floatValue]];
勾芒's avatar
勾芒 committed
41
    self.goodsNumbersLabe.text = [NSString stringWithFormat:@"%d",_model.goodsNum];
勾芒's avatar
勾芒 committed
42 43 44 45
    if ([_model.costPrice integerValue] == 0) {
        _model.costPrice = _model.goods.tagPrice;
    }
    self.productPriceLabe.text = [NSString stringWithFormat:@"¥%.2f",[self.goodsNumbersLabe.text integerValue]*[_model.costPrice floatValue]];;
勾芒's avatar
勾芒 committed
46
}
曹云霄's avatar
曹云霄 committed
47 48 49 50 51 52

#pragma mark -增加或者减少商品
- (IBAction)reduceAndaddButtonClick:(UIButton *)sender {
    
    //sender.tag == 100   减少
    //sender.tag == 101   增加
勾芒's avatar
勾芒 committed
53 54 55 56 57 58 59 60 61
    NSLog(@"%ld",sender.tag);
    
    
    NSInteger goodsNumber = [self.goodsNumbersLabe.text integerValue];
    switch (sender.tag) {
        case 100://减少
        {
            if (goodsNumber <= 1) {
                
勾芒's avatar
勾芒 committed
62 63 64
                if (self.promptStringBlock) {
                    self.promptStringBlock(@"个数不能小于1");
                }
勾芒's avatar
勾芒 committed
65 66 67 68 69 70 71 72 73 74 75 76 77
                //不能小于1
                return;
            }
            goodsNumber --;
            self.goodsNumbersLabe.text = [NSString stringWithFormat:@"%ld",goodsNumber];
            
        }
            break;
        case 101://增加
        {
            if (goodsNumber >= [_model.goods.number integerValue]) {
                
                //不能大于库存
勾芒's avatar
勾芒 committed
78 79 80
                if (self.promptStringBlock) {
                    self.promptStringBlock(@"个数不能大于库存");
                }
勾芒's avatar
勾芒 committed
81 82 83 84 85 86 87 88 89 90 91
                return;
            }
            goodsNumber ++;
            self.goodsNumbersLabe.text = [NSString stringWithFormat:@"%ld",goodsNumber];
            
        }
            break;
            
        default:
            break;
    }
勾芒's avatar
勾芒 committed
92
    //改变价格
曹云霄's avatar
曹云霄 committed
93
    self.productPriceLabe.text = [NSString stringWithFormat:@"¥%.2f",[self.goodsNumbersLabe.text integerValue]*[self.clinchTextfield.text floatValue]];
勾芒's avatar
勾芒 committed
94
    if ([self.delegate respondsToSelector:@selector(ChangeGoodsNumber:WithcostPrice:Withcellindex:)]) {
勾芒's avatar
勾芒 committed
95
        [self.delegate ChangeGoodsNumber:[self.goodsNumbersLabe.text intValue] WithcostPrice:[self.clinchTextfield.text floatValue]Withcellindex:_cellindex];
勾芒's avatar
勾芒 committed
96
    }
曹云霄's avatar
曹云霄 committed
97 98 99 100 101 102
}


#pragma mark -商品选中
- (IBAction)selectedButtonClick:(UIButton *)sender {
    
勾芒's avatar
勾芒 committed
103 104 105 106
    if (self.returnCellblock) {
        
        self.returnCellblock(_cellindex);
    }
勾芒's avatar
勾芒 committed
107
    sender.selected = !sender.selected;
曹云霄's avatar
曹云霄 committed
108 109 110
}


勾芒's avatar
勾芒 committed
111 112 113 114 115 116 117
#pragma mark -成交价完成修改
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    if (![self isPureInt:textField.text]) {
        if (self.promptStringBlock) {
            self.promptStringBlock(@"输入格式错误");
        }
勾芒's avatar
勾芒 committed
118 119 120
    }else
    {
        //改变价格
勾芒's avatar
勾芒 committed
121
        self.productPriceLabe.text = [NSString stringWithFormat:@"¥%.2f",[self.goodsNumbersLabe.text integerValue]*[textField.text floatValue]];
勾芒's avatar
勾芒 committed
122 123
        
        if ([self.delegate respondsToSelector:@selector(ChangeGoodsNumber:WithcostPrice:Withcellindex:)]) {
勾芒's avatar
勾芒 committed
124
            [self.delegate ChangeGoodsNumber:[self.goodsNumbersLabe.text intValue] WithcostPrice:[self.clinchTextfield.text floatValue]Withcellindex:_cellindex];
勾芒's avatar
勾芒 committed
125
        }
勾芒's avatar
勾芒 committed
126 127 128 129 130
    }
    return YES;
}


勾芒's avatar
勾芒 committed
131
#pragma mark - 判断是否是浮点数
勾芒's avatar
勾芒 committed
132 133
- (BOOL)isPureInt:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
勾芒's avatar
勾芒 committed
134 135
    float val;
    return[scan scanFloat:&val] && [scan isAtEnd];
勾芒's avatar
勾芒 committed
136 137 138
}


曹云霄's avatar
曹云霄 committed
139 140 141 142 143 144 145 146 147 148 149




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

    // Configure the view for the selected state
}

@end