ShoppingTableViewCell.m 4.33 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
    [self.goodsImageView sd_setImageWithURL:[NSURL URLWithString:_model.goods.pictures] placeholderImage:REPLACEIMAGE];
勾芒's avatar
勾芒 committed
35
    self.goodsInformationLabe.text = _model.goods.name;
polo2013's avatar
polo2013 committed
36 37
    self.specifications.text = _model.goods.size;
    self.goodsCode.text = _model.goods.code;
勾芒's avatar
勾芒 committed
38 39 40
    self.tagsPriceLabe.text = [_model.goods.tagPrice stringValue];
    self.clinchTextfield.text = [_model.goods.costPrice stringValue];
    self.goodsNumbersLabe.text = [NSString stringWithFormat:@"%d",_model.goodsNum];
勾芒's avatar
勾芒 committed
41
    self.productPriceLabe.text = [NSString stringWithFormat:@"¥%.2f",[self.goodsNumbersLabe.text floatValue]*[_model.goods.costPrice floatValue]];;
勾芒's avatar
勾芒 committed
42
}
曹云霄's avatar
曹云霄 committed
43 44 45 46 47 48

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


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


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


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


曹云霄's avatar
曹云霄 committed
136 137 138 139 140 141 142 143 144 145 146




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

    // Configure the view for the selected state
}

@end