ShopDetaileViewController.m 26 KB
Newer Older
zhu's avatar
zhu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//
//  ShopDetaileViewController.m
//  XFFruit
//
//  Created by mac on 15/8/19.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "ShopDetaileViewController.h"
#import "SurveyCell.h"
#import "HPGrowingTextView.h"
#import "StartTimeView.h"
#import "ChosePersonViewController.h"
#import "ChooseProductViewController.h"
zhu's avatar
zhu committed
15
#import "ChooseProductUnitViewController.h"
zhu's avatar
zhu committed
16 17
#import "GXFSearchVendorViewController.h"
#import "GXFProductUnit.h"
Sandy's avatar
Sandy committed
18
#import "CalculateHelper.h"
zhu's avatar
zhu committed
19 20 21 22 23 24 25 26 27 28 29 30 31
#define LeftMargin 15
#define BtnHeight 44
#define TableHeight 46
#define CornerRadius 5
#define TitleSize 15
#define BtnSize 19
#define TotalHeight 432
#define KeyboardHeight 258
#define DateViewHeight 300
typedef enum : NSUInteger {
    SaveTag = 2000,
    CommitTag,
} BtnTag;
陈俊俊's avatar
陈俊俊 committed
32
@interface ShopDetaileViewController ()<UITableViewDataSource,UITableViewDelegate,HPGrowingTextViewDelegate,UITextFieldDelegate,UIAlertViewDelegate>
zhu's avatar
zhu committed
33 34 35 36
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
    UILabel *_productLabel;
zhu's avatar
zhu committed
37
    UILabel *_PackagingLable;
陈俊俊's avatar
陈俊俊 committed
38 39 40 41 42 43
    UITextField *packageSpecification;//包装规格
    UITextField *packageQuantity;     //包装数量
    UITextField *foundationQuantity;  //基础数量
    UITextField *foundationUnitPrice; //基础单价
    UITextField *packageUnitPrice;    //包装单价
    UITextField *totalMoney;          //总金额
陈俊俊's avatar
陈俊俊 committed
44 45 46 47 48
    HPGrowingTextView *remark;        //备注
    UILabel *_measureUnitLabel;  //默认规格单位
    UILabel *_packageCountLabel; //包装数量
    UILabel *_baseCountLabel;    //基础数量

zhu's avatar
zhu committed
49
}
陈俊俊's avatar
陈俊俊 committed
50 51 52 53 54 55
@property (nonatomic,strong)NSString *productCodeStr;//商品代码
@property (nonatomic,strong)NSString *productNameStr;//商品名字
@property (nonatomic,strong)NSString *productUuidStr;//商品code
@property (nonatomic,strong)NSString *productMeasureUnit;//默认规格单位
@property (nonatomic,strong)NSString *packageQpcStr;    //规格描述
@property (nonatomic,strong)NSString *packageUintStr;    //包装单位
陈俊俊's avatar
陈俊俊 committed
56 57 58 59 60 61

@property (nonatomic,strong)NSNumber *packPrice;//包装单价
@property (nonatomic,strong)NSNumber *basePrice;//基础单价
@property (nonatomic,strong)NSNumber *totalPrice;//总金额


陈俊俊's avatar
陈俊俊 committed
62 63
@property (nonatomic,strong)NSMutableArray *selectProducts;
@property (nonatomic,strong)NSString *selectUnit;
陈俊俊's avatar
陈俊俊 committed
64

zhu's avatar
zhu committed
65 66 67 68 69 70 71 72 73 74 75 76
@end

@implementation ShopDetaileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.navTitle;
    [self initData];
    [self setupSubviews];
}
- (void)initData{
    _dataArr = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
77
    self.selectProducts = [NSMutableArray array];
zhu's avatar
zhu committed
78
    [_dataArr addObject:@"商品"];
陈俊俊's avatar
陈俊俊 committed
79
    [_dataArr addObject:@"包装单位"];
zhu's avatar
zhu committed
80 81 82 83
    [_dataArr addObject:@"包装规格"];
    [_dataArr addObject:@"包装数量"];
    [_dataArr addObject:@"基础数量"];
    [_dataArr addObject:@"基础单价"];
陈俊俊's avatar
陈俊俊 committed
84
    [_dataArr addObject:@"包装单价"];
zhu's avatar
zhu committed
85 86
    [_dataArr addObject:@"总金额"];
    [_dataArr addObject:@"备注"];
zhu's avatar
zhu committed
87
    
zhu's avatar
zhu committed
88 89 90
}

-(void)setupSubviews
陈俊俊's avatar
陈俊俊 committed
91
{    
zhu's avatar
zhu committed
92 93 94 95 96 97 98 99
    _tableView = [[UITableView alloc]initWithFrame:(CGRectMake(0, 0,ScreenSize.width, ScreenSize.height - 64 - LeftMargin)) style:(UITableViewStylePlain)];
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.bounces = NO;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 50)];
    
陈俊俊's avatar
陈俊俊 committed
100
    UIButton *saveBtn =  [IBTCustomButtom creatButtonWithFrame:CGRectMake(LeftMargin, 10, (ScreenSize.width - LeftMargin*3)/2, BtnHeight) target:self sel:@selector(btnClick:) tag:SaveTag image:nil title:@"删除" titleColor: [UIColor whiteColor] isCorner:YES corner:CornerRadius bgColor:GXF_SAVE_COLOR];
zhu's avatar
zhu committed
101 102
    [footView addSubview:saveBtn];
    
陈俊俊's avatar
陈俊俊 committed
103
    UIButton *commitBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(saveBtn.frame.origin.x + saveBtn.frame.size.width + LeftMargin, 10, (ScreenSize.width - LeftMargin*3)/2, BtnHeight) target:self sel:@selector(btnClick:) tag:CommitTag image:nil title:@"保存" titleColor: [UIColor whiteColor] isCorner:YES corner:CornerRadius bgColor:GXF_COMMIT_COLOR];
zhu's avatar
zhu committed
104
    [footView addSubview:commitBtn];
陈俊俊's avatar
陈俊俊 committed
105
        _tableView.tableFooterView = footView;
zhu's avatar
zhu committed
106
    [self.view addSubview:_tableView];
陈俊俊's avatar
陈俊俊 committed
107
    
zhu's avatar
zhu committed
108
}
zhu's avatar
zhu committed
109 110 111
- (void)setviewsData
{
    if (self.shopDetail!=nil) {
陈俊俊's avatar
陈俊俊 committed
112 113
        //商品
        _productLabel.text = [NSString stringWithFormat:@"%@[%@]",self.shopDetail.merchandise,self.shopDetail.product_code];
陈俊俊's avatar
陈俊俊 committed
114
        [self.selectProducts addObject:_shopDetail.product_uuid];
陈俊俊's avatar
陈俊俊 committed
115 116 117
        //包装单位
        _PackagingLable.text = self.shopDetail.packageUnit;
        _packageCountLabel.text = self.shopDetail.packageUnit;
陈俊俊's avatar
陈俊俊 committed
118
        self.selectUnit = self.shopDetail.packageUnit;
陈俊俊's avatar
陈俊俊 committed
119 120 121 122 123 124 125 126 127
        
        //包装规格
        packageSpecification.text=self.shopDetail.packageSpecification;
        
        //包装规格单位
        self.shopDetail.packageQpcUnit ? (_measureUnitLabel.text =  self.shopDetail.packageQpcUnit) : (_measureUnitLabel.text = @"斤");
        self.shopDetail.packageQpcUnit ? (_baseCountLabel.text =  self.shopDetail.packageQpcUnit) : (_baseCountLabel.text = @"斤");
        
        //包装数量
陈俊俊's avatar
陈俊俊 committed
128
        if ([self.shopDetail.packageQuantity floatValue] > 0) {
陈俊俊's avatar
陈俊俊 committed
129 130
            packageQuantity.text=self.shopDetail.packageQuantity;
        }
陈俊俊's avatar
陈俊俊 committed
131 132 133
        //基础数量
        foundationQuantity.text=self.shopDetail.foundationQuantity;
        //基础单价
134
//        if ([self.shopDetail.foundationUnitPrice floatValue] > 0) {
Sandy's avatar
Sandy committed
135
            foundationUnitPrice.text= [self.shopDetail.foundationUnitPrice stringValue];
136
//        }
陈俊俊's avatar
陈俊俊 committed
137 138
        self.basePrice = self.shopDetail.foundationUnitPrice;
        
陈俊俊's avatar
陈俊俊 committed
139
        //包装单价
140
//        if ([self.shopDetail.packageUnitPrice floatValue] > 0) {
Sandy's avatar
Sandy committed
141
            packageUnitPrice.text=[self.shopDetail.packageUnitPrice stringValue];
142
//        }
陈俊俊's avatar
陈俊俊 committed
143
        self.packPrice = self.shopDetail.packageUnitPrice;
陈俊俊's avatar
陈俊俊 committed
144
        //总金额
陈俊俊's avatar
陈俊俊 committed
145
        if ([self.shopDetail.totalMoney floatValue] <= 0) {
陈俊俊's avatar
陈俊俊 committed
146
            totalMoney.text=@"0.0000";
陈俊俊's avatar
陈俊俊 committed
147
        }else{
Sandy's avatar
Sandy committed
148
            totalMoney.text=[self.shopDetail.totalMoney stringValue];
陈俊俊's avatar
陈俊俊 committed
149
        }
陈俊俊's avatar
陈俊俊 committed
150
        self.totalPrice = self.shopDetail.totalMoney;
陈俊俊's avatar
陈俊俊 committed
151
        //备注
zhu's avatar
zhu committed
152
        remark.text=self.shopDetail.remark;
陈俊俊's avatar
陈俊俊 committed
153 154 155 156
        
        _productLabel.textColor=GXF_CONTENT_COLOR;
        _PackagingLable.textColor=GXF_CONTENT_COLOR;
        
陈俊俊's avatar
陈俊俊 committed
157 158
        self.productCodeStr = self.shopDetail.product_code;
        self.productUuidStr = self.shopDetail.product_uuid;
陈俊俊's avatar
陈俊俊 committed
159 160 161 162
        self.productNameStr = self.shopDetail.merchandise;
        self.packageQpcStr =  self.shopDetail.packageQpcStr;
        self.packageUintStr = self.shopDetail.packageUnit;
        self.productMeasureUnit = self.shopDetail.packageQpcUnit.length > 0 ? self.shopDetail.packageQpcUnit : @"斤";
zhu's avatar
zhu committed
163 164
    }
}
zhu's avatar
zhu committed
165 166 167
#pragma mark - 按钮点击事件
- (void)btnClick:(UIButton *)btn{
    switch (btn.tag) {
zhu's avatar
zhu committed
168
        case SaveTag://删除
zhu's avatar
zhu committed
169
        {
陈俊俊's avatar
陈俊俊 committed
170 171 172
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认删除" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            [alertView show];
zhu's avatar
zhu committed
173 174 175 176
        }
            break;
        case CommitTag:
        {
陈俊俊's avatar
陈俊俊 committed
177 178
            if ([self informationComplete]) {
                ShopDetail *shopDetail=self.shopDetail;
zhu's avatar
zhu committed
179
                shopDetail.IsDeleted=NO;
陈俊俊's avatar
陈俊俊 committed
180 181 182
                self.choseShopDetail(shopDetail);//回调
                [self PopViewControllerAnimated:YES];
            }
zhu's avatar
zhu committed
183 184 185 186 187 188
        }
            break;
        default:
            break;
    }
}
陈俊俊's avatar
陈俊俊 committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        if (self.shopDetail!=nil) {
            ShopDetail *shopDetail=self.shopDetail;
            
            if (shopDetail.IsXiuGai==YES) {
                shopDetail.IsDeleted=YES;
                self.choseShopDetail(shopDetail);//回调
                [self PopViewControllerAnimated:YES];
            }else
            {
                [self  clearShopDetail];
            }
        }else
        {
            [self  clearShopDetail];
        }

    }
}

zhu's avatar
zhu committed
210 211
- (void)clearShopDetail
{
陈俊俊's avatar
陈俊俊 committed
212
    _productLabel.text = @"选择商品";//商品
zhu's avatar
zhu committed
213
    
陈俊俊's avatar
陈俊俊 committed
214 215 216
    _PackagingLable.text = @"选择包装单位";//包装单位
    packageSpecification.text = @"";//包装规格
    packageQuantity.text = @"";     //包装数量
zhu's avatar
zhu committed
217
    
陈俊俊's avatar
陈俊俊 committed
218 219 220 221 222
    foundationQuantity.text = @"0";  //基础数量
    foundationUnitPrice.text = @""; //基础单价
    packageUnitPrice.text = @"0";    //包装单价
    totalMoney.text = @"0";          //总金额
    remark.text = @"";
zhu's avatar
zhu committed
223 224 225
    _productLabel.textColor=GXF_PLACEHOLDER_COLOR;
    _PackagingLable.textColor=GXF_PLACEHOLDER_COLOR;
}
陈俊俊's avatar
陈俊俊 committed
226
- (BOOL)informationComplete{
陈俊俊's avatar
陈俊俊 committed
227 228 229
    if (!self.shopDetail) {
        self.shopDetail=[[ShopDetail alloc]init];
    }
陈俊俊's avatar
陈俊俊 committed
230 231
    self.shopDetail.product_code = self.productCodeStr;
    self.shopDetail.product_uuid = self.productUuidStr;
陈俊俊's avatar
陈俊俊 committed
232 233 234
    self.shopDetail.merchandise = self.productNameStr;
    
    self.shopDetail.packageSpecification = packageSpecification.text;
陈俊俊's avatar
陈俊俊 committed
235
    self.shopDetail.packageQpcStr = [NSString stringWithFormat:@"1*%@",packageSpecification.text];
陈俊俊's avatar
陈俊俊 committed
236 237 238 239
    self.shopDetail.packageQpcUnit = self.productMeasureUnit;

    self.shopDetail.packageUnit = self.packageUintStr;
    self.shopDetail.packageQuantity = packageQuantity.text;
陈俊俊's avatar
陈俊俊 committed
240
    self.shopDetail.packageUnitPrice = self.packPrice;
陈俊俊's avatar
陈俊俊 committed
241 242

    self.shopDetail.foundationQuantity = foundationQuantity.text;
陈俊俊's avatar
陈俊俊 committed
243
    self.shopDetail.foundationUnitPrice = self.basePrice;
Sandy's avatar
Sandy committed
244 245
    NSString *totalPrices = totalMoney.text;
    self.shopDetail.totalMoney = [NSDecimalNumber decimalNumberWithString:totalPrices];
陈俊俊's avatar
陈俊俊 committed
246 247 248
    self.shopDetail.remark = remark.text;
    
    if (self.productNameStr.length == 0 ) {
陈俊俊's avatar
陈俊俊 committed
249 250 251 252 253 254 255 256 257 258 259
        ShowMessage(@"商品不能为空");
        return NO;
    }
    if (packageSpecification.text.length == 0 ) {
        ShowMessage(@"包装规格不能为空");
        return NO;
    }
    if (packageQuantity.text.length == 0 ) {
        ShowMessage(@"包装数量不能为空");
        return NO;
    }
陈俊俊's avatar
陈俊俊 committed
260
    if (self.packageUintStr.length == 0) {
陈俊俊's avatar
陈俊俊 committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274
        ShowMessage(@"包装单位不能为空");
        return NO;
    }
    if (foundationQuantity.text.length == 0) {
        ShowMessage(@"基础数量不能为空");
        return NO;
    }
    if (foundationUnitPrice.text.length == 0) {
        ShowMessage(@"基础单价不能为空");
        return NO;
    }if (packageUnitPrice.text.length == 0) {
        ShowMessage(@"总金额不能为空");
        return NO;
    }
陈俊俊's avatar
陈俊俊 committed
275
    
陈俊俊's avatar
陈俊俊 committed
276
    if ([packageQuantity.text floatValue] <= 0 || [foundationQuantity.text floatValue] <= 0 || [packageSpecification.text floatValue] <= 0) {
陈俊俊's avatar
陈俊俊 committed
277 278 279
        ShowMessage(@"商品数量不能为0");
        return NO;
    }
280 281 282 283
//    if ([packageUnitPrice.text floatValue] <=0 || [foundationUnitPrice.text floatValue] <= 0 || [totalMoney.text floatValue]<= 0) {
//        ShowMessage(@"商品价格不能0");
//        return NO;
//    }
zhu's avatar
zhu committed
284 285 286 287 288 289 290 291 292 293
    return YES;
}
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
陈俊俊's avatar
陈俊俊 committed
294
    return TableHeight;
zhu's avatar
zhu committed
295 296 297 298 299 300 301 302
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"cellID";
    SurveyCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[SurveyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
陈俊俊's avatar
陈俊俊 committed
303
        if (indexPath.row==0||indexPath.row==1) {
zhu's avatar
zhu committed
304 305 306 307 308 309 310 311 312
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        [self createViewInCell:cell indexPath:indexPath];
    }
    [cell setTitleStr:_dataArr[indexPath.row]];
    return cell;
}

-  (void)createViewInCell:(SurveyCell *)cell indexPath:(NSIndexPath *)indexPath{
陈俊俊's avatar
陈俊俊 committed
313
    if (indexPath.row == 0||indexPath.row==1) {
陈俊俊's avatar
陈俊俊 committed
314
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight))];
zhu's avatar
zhu committed
315
        contentLabel.textAlignment= NSTextAlignmentRight;
zhu's avatar
zhu committed
316
        contentLabel.textColor = GXF_PLACEHOLDER_COLOR;
zhu's avatar
zhu committed
317 318 319 320
        contentLabel.font = FontSize(TitleSize);
        [cell.contentView addSubview:contentLabel];
        if (indexPath.row==0) {
            _productLabel = contentLabel;
陈俊俊's avatar
陈俊俊 committed
321
            contentLabel.text = @"选择商品";
陈俊俊's avatar
陈俊俊 committed
322
        }else if (indexPath.row==1)
zhu's avatar
zhu committed
323
        {
zhu's avatar
zhu committed
324
            _PackagingLable = contentLabel;
陈俊俊's avatar
陈俊俊 committed
325
            contentLabel.text = @"选择包装单位";
zhu's avatar
zhu committed
326 327
        }
        
陈俊俊's avatar
陈俊俊 committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
    }else if(indexPath.row == 8){
        HPGrowingTextView * remarkTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight)];
        remarkTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
        remarkTextView.minNumberOfLines = 1;
        remarkTextView.maxNumberOfLines = 1;
        remarkTextView.isScrollable = YES;
        remarkTextView.font = GXF_FIFTEENTEN_SIZE;
        remarkTextView.textAlignment = NSTextAlignmentRight;
        remarkTextView.delegate = self;
        remarkTextView.returnKeyType = UIReturnKeyDone;
        remarkTextView.placeholder = @"输入备注内容";
        [cell.contentView addSubview:remarkTextView];
        remark=remarkTextView;              //备注
    }else{
        UITextField  *textField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight)];
陈俊俊's avatar
陈俊俊 committed
343 344 345 346
        textField.textAlignment = NSTextAlignmentRight;
        textField.textColor = GXF_CONTENT_COLOR;
        textField.font = FontSize(15);
        textField.returnKeyType = UIReturnKeyDone;
陈俊俊's avatar
陈俊俊 committed
347
        textField.keyboardType = UIKeyboardTypeDecimalPad;
陈俊俊's avatar
陈俊俊 committed
348 349
        textField.delegate = self;
        [cell.contentView addSubview:textField];
陈俊俊's avatar
陈俊俊 committed
350
        
351
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(textField.frame)+ 5, 0, 30, TableHeight)];
陈俊俊's avatar
陈俊俊 committed
352 353 354
        label.textColor = GXF_CONTENT_COLOR;
        label.font = GXF_FIFTEENTEN_SIZE;
        [cell.contentView addSubview:label];
355

陈俊俊's avatar
陈俊俊 committed
356
        if (indexPath.row==2) {
陈俊俊's avatar
陈俊俊 committed
357 358 359 360 361 362 363
            UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(100+LeftMargin, 0, 50, TableHeight)];
            labelTwo.text = @"1*";
            labelTwo.textAlignment = NSTextAlignmentRight;
            [cell.contentView addSubview:labelTwo];
            textField.left = labelTwo.right;
            textField.width = textField.width - 50;
            label.left = textField.right+ 5;
陈俊俊's avatar
陈俊俊 committed
364
            _measureUnitLabel = label;
陈俊俊's avatar
陈俊俊 committed
365
            textField.placeholder = @"输入包装规格";
366
            textField.tag =111;
陈俊俊's avatar
陈俊俊 committed
367 368 369
            [textField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventAllEditingEvents];
            packageSpecification=textField;//包装规格
            
陈俊俊's avatar
陈俊俊 committed
370
        }else if (indexPath.row==3)
zhu's avatar
zhu committed
371
        {
陈俊俊's avatar
陈俊俊 committed
372
            _packageCountLabel = label;
陈俊俊's avatar
陈俊俊 committed
373
            textField.placeholder = @"输入包装数量";
陈俊俊's avatar
陈俊俊 committed
374 375
            [textField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventAllEditingEvents];
            packageQuantity=textField;     //包装数量
zhu's avatar
zhu committed
376 377
        }else if (indexPath.row==4)
        {
陈俊俊's avatar
陈俊俊 committed
378 379 380
            _baseCountLabel = label;
            [textField setEnabled:NO];
            textField.placeholder = @"基础数量";
陈俊俊's avatar
陈俊俊 committed
381
            textField.textColor = GXF_NAVIGAYION_COLOR;
陈俊俊's avatar
陈俊俊 committed
382
            foundationQuantity=textField;  //基础数量
陈俊俊's avatar
陈俊俊 committed
383
            
zhu's avatar
zhu committed
384 385
        }else if (indexPath.row==5)
        {
陈俊俊's avatar
陈俊俊 committed
386
            label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
387
            textField.placeholder = @"输入基础单价";
陈俊俊's avatar
陈俊俊 committed
388
            [textField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventAllEditingEvents];
陈俊俊's avatar
陈俊俊 committed
389
            foundationUnitPrice=textField; //基础单价
zhu's avatar
zhu committed
390 391
        }else if (indexPath.row==6)
        {
zhu's avatar
zhu committed
392
            label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
393
            [textField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventAllEditingEvents];
陈俊俊's avatar
陈俊俊 committed
394
            textField.placeholder = @"输入包装单价";
陈俊俊's avatar
陈俊俊 committed
395
            packageUnitPrice=textField;    //包装单价
zhu's avatar
zhu committed
396
            
陈俊俊's avatar
陈俊俊 committed
397
        }else if (indexPath.row==7)
zhu's avatar
zhu committed
398
        {
陈俊俊's avatar
陈俊俊 committed
399
            label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
400
            [textField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventAllEditingEvents];
陈俊俊's avatar
陈俊俊 committed
401
            textField.placeholder = @"输入总金额";
陈俊俊's avatar
陈俊俊 committed
402
            totalMoney=textField;          //总金额
zhu's avatar
zhu committed
403 404
        }
    }
zhu's avatar
zhu committed
405
     [self  setviewsData];
zhu's avatar
zhu committed
406 407 408
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
Sandy's avatar
Sandy committed
409
    //选择商品
陈俊俊's avatar
陈俊俊 committed
410
    if(indexPath.row == 0){
zhu's avatar
zhu committed
411
        ChooseProductViewController *cvc = [ChooseProductViewController new];
陈俊俊's avatar
陈俊俊 committed
412 413 414
        if (self.selectProducts.count > 0) {
            cvc.selectArr = self.selectProducts;
        }
zhu's avatar
zhu committed
415 416
        cvc.choseBaseInfo = ^(NSArray  *products){
            Product *product=products [0];
zhu's avatar
zhu committed
417
            _productLabel.text = [NSString stringWithFormat:@"%@[%@]",product.name,product.code];
zhu's avatar
zhu committed
418
            _productLabel.textColor = GXF_CONTENT_COLOR;
zhu's avatar
zhu committed
419 420 421
            self.productNameStr = product.name;
            self.productUuidStr = product.uuid;
            self.productCodeStr = product.code;
陈俊俊's avatar
陈俊俊 committed
422
            self.productMeasureUnit = product.measureUnit;
陈俊俊's avatar
陈俊俊 committed
423 424 425 426 427
            if (self.selectProducts.count > 0) {
                [self.selectProducts removeAllObjects];
            }
            [self.selectProducts addObject:product.uuid];
            
陈俊俊's avatar
陈俊俊 committed
428 429 430 431 432 433 434
            if (self.productMeasureUnit.length == 0) {
                _measureUnitLabel.text = @"斤";
                _baseCountLabel.text = @"斤";
            }else{
                _measureUnitLabel.text = self.productMeasureUnit;
                _baseCountLabel.text = self.productMeasureUnit;
            }
Sandy's avatar
Sandy committed
435
            [self setPackageUnit:product.purMeasureUnit];
zhu's avatar
zhu committed
436 437 438
        };
        cvc.isMoreChose = NO;
        [self PushViewController:cvc animated:YES];
陈俊俊's avatar
陈俊俊 committed
439
    }else if (indexPath.row ==1)
zhu's avatar
zhu committed
440
    {
zhu's avatar
zhu committed
441
        ChooseProductUnitViewController *cvc = [ChooseProductUnitViewController new];
陈俊俊's avatar
陈俊俊 committed
442 443 444
        if (self.selectUnit.length > 0) {
            cvc.selectStr = self.selectUnit;
        }
zhu's avatar
zhu committed
445
        cvc.choseBaseInfo = ^(NSArray  *products){
陈俊俊's avatar
陈俊俊 committed
446 447
            if (products.count > 0) {
                GXFProductUnit *productUnit=products [0];
Sandy's avatar
Sandy committed
448
                [self setPackageUnit:productUnit.name];
陈俊俊's avatar
陈俊俊 committed
449
            }
zhu's avatar
zhu committed
450
        };
zhu's avatar
zhu committed
451
        cvc.isMoreChose = NO;
zhu's avatar
zhu committed
452
        [self PushViewController:cvc animated:YES];
zhu's avatar
zhu committed
453 454 455
    }
}

Sandy's avatar
Sandy committed
456 457 458 459 460 461 462 463 464 465 466 467 468
/**
 *  设置包装单位
 *
 *  @param packageUnit 包装单位
 */
- (void)setPackageUnit:(NSString *)packageUnit {
    _PackagingLable.text = packageUnit;
    _PackagingLable.textColor = GXF_CONTENT_COLOR;
    _packageCountLabel.text = packageUnit;
    self.packageUintStr = packageUnit;
    self.selectUnit = packageUnit;
}

469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (textField.tag != 111) {
        return YES;
    }
    
    NSMutableString * futureString = [NSMutableString stringWithString:textField.text];
//    kLOG(@"%@", futureString);
    [futureString  insertString:string atIndex:range.location];
//    kLOG(@"----%@", futureString);
    NSInteger flag = 0;
    NSInteger pointNum = 0;//用于标记小数点的数量,只能有一个小数点
    const NSInteger limited = 2;//限制小数点后面的位数
    
    for (int i = (int)futureString.length - 1; i>=0; i--) {
        
        if ([futureString characterAtIndex:i] == '.') {
            pointNum++;
//            kLOG(@"----->>>%ld",pointNum);
            if (pointNum == 2) {
                
                return NO;
                
            }
        }
    }
    
    for (int i = (int)futureString.length - 1; i>=0; i--) {
        
        if ([futureString characterAtIndex:i] == '.') {
            
            if (flag > limited) {
                
                return NO;
                
            }
            
            break;
            
        }
        
        flag++;
        
    }
    
    
    return YES;
}

陈俊俊's avatar
陈俊俊 committed
517 518
#pragma mark - textFiled事件
- (void)textChange:(UITextField *)textField{
陈俊俊's avatar
陈俊俊 committed
519
    //包装规格和包装数量
陈俊俊's avatar
陈俊俊 committed
520 521
    if (textField == packageSpecification || textField == packageQuantity) {
        if (packageSpecification.text.length > 0 && packageQuantity.text.length > 0 ) {
陈俊俊's avatar
陈俊俊 committed
522
            //计算基础数量  和 总金额和包装单价
陈俊俊's avatar
陈俊俊 committed
523 524
            float baseCount = [packageSpecification.text floatValue] * [packageQuantity.text floatValue];
            foundationQuantity.text = [NSString stringWithFormat:@"%.2f",baseCount];
陈俊俊's avatar
陈俊俊 committed
525 526
            //如果基础单价有  会计算出包装单价和总价
            //如果包装单价有 会计算出基础单价和总价
陈俊俊's avatar
陈俊俊 committed
527 528 529
            [self setTotalMoney];
        }
    }else if(textField == foundationUnitPrice){
陈俊俊's avatar
陈俊俊 committed
530
        //基础单价
陈俊俊's avatar
陈俊俊 committed
531
        self.basePrice = [NSNumber numberWithFloat:foundationUnitPrice.text.floatValue];
陈俊俊's avatar
陈俊俊 committed
532 533 534 535
        [self setPacktAndTotalPrice];
        //如果基础数量和包装数量有的话计算出包装单价和和总价
    }else if (textField == packageUnitPrice){
        //包装单价
陈俊俊's avatar
陈俊俊 committed
536
        self.packPrice = [NSNumber numberWithFloat:packageUnitPrice.text.floatValue];
陈俊俊's avatar
陈俊俊 committed
537 538 539
        [self setUnitAndTotalPrice];
    }else if(textField == totalMoney){
        //总金额
陈俊俊's avatar
陈俊俊 committed
540
        self.totalPrice = [NSNumber numberWithFloat:totalMoney.text.floatValue];
陈俊俊's avatar
陈俊俊 committed
541
        [self setUnitAndPackPrice];
陈俊俊's avatar
陈俊俊 committed
542 543 544 545
    }
}

- (void)setTotalMoney{
陈俊俊's avatar
陈俊俊 committed
546 547 548 549 550
    //计算总金额和包装单价
    [self setPacktAndTotalPrice];
    [self setUnitAndTotalPrice];
}
- (void)setPacktAndTotalPrice{
陈俊俊's avatar
陈俊俊 committed
551
    if (self.basePrice && foundationUnitPrice.text.length > 0) {
陈俊俊's avatar
陈俊俊 committed
552
        if (foundationQuantity.text.length > 0) {
Sandy's avatar
Sandy committed
553 554 555 556 557 558 559 560 561 562 563 564
//            float basePrice = [self.basePrice floatValue] * 100;
//            int intBasePrice = (int)basePrice;
//            int foundationQtt = [foundationQuantity.text intValue];
//            double price = (intBasePrice * foundationQtt * 1.0);
//            double totalPrice = price  / 100;
            
//            NSDecimalNumber *basePrice = [NSDecimalNumber decimalNumberWithDecimal:[self.basePrice decimalValue]];
//            NSDecimalNumber *foundationQty = [NSDecimalNumber decimalNumberWithString:foundationQuantity.text];
//            NSDecimalNumber *multiplyResult = [basePrice decimalNumberByMultiplyingBy:foundationQty];
            NSDecimalNumber *multiplyResult = [CalculateHelper calculateNum1:self.basePrice num2:foundationQuantity.text type:CalculateTypeMul roundingType:NSRoundBankers cutLenth:2];
            totalMoney.text = [multiplyResult stringValue];
            self.totalPrice = multiplyResult;
陈俊俊's avatar
陈俊俊 committed
565
            if (packageQuantity.text.length > 0 && [packageQuantity.text floatValue] > 0) {
Sandy's avatar
Sandy committed
566 567 568 569 570
                
                NSDecimalNumber *packagePrice = [CalculateHelper calculateNum1:multiplyResult num2:packageQuantity.text type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:2] ;
                
                packageUnitPrice.text = [packagePrice stringValue];
                self.packPrice = packagePrice;
陈俊俊's avatar
陈俊俊 committed
571 572 573 574 575 576
            }
        }
    }
}
//输入包装单价(包装数量和基础数量)计算基础单价和总金额
- (void)setUnitAndTotalPrice{
陈俊俊's avatar
陈俊俊 committed
577
    if (self.packPrice&&packageUnitPrice.text.length > 0) {
陈俊俊's avatar
陈俊俊 committed
578
        if (packageQuantity.text.length > 0) {
Sandy's avatar
Sandy committed
579 580 581 582 583 584 585 586 587 588
//            float pakePrice = [self.packPrice floatValue] * 100;
//            int intPakePrice = (int)pakePrice;
//            int pakageQty = [packageQuantity.text intValue];
//            
//            double price = (intPakePrice * pakageQty * 1.0);
//            double totalPrice = price  / 100;
//            float totalPrice = pakePrice * 100 * pakageQty / 100;
            NSDecimalNumber *totalPrice = [CalculateHelper calculateNum1:self.packPrice num2:packageQuantity.text type:CalculateTypeMul roundingType:NSRoundBankers cutLenth:2];
            totalMoney.text = [totalPrice stringValue];
            self.totalPrice = totalPrice;
陈俊俊's avatar
陈俊俊 committed
589
            if (foundationQuantity.text.length > 0 && [foundationQuantity.text integerValue] > 0) {
Sandy's avatar
Sandy committed
590 591 592 593
                NSDecimalNumber *packagePrice = [CalculateHelper calculateNum1:totalPrice num2:foundationQuantity.text type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:2];
//                float packagePrice = totalPrice / [foundationQuantity.text floatValue];
                foundationUnitPrice.text = packagePrice.stringValue;
                self.basePrice = packagePrice;            }
陈俊俊's avatar
陈俊俊 committed
594 595 596 597 598 599 600
        }
    }
}
//输入总金额(包装数量和基础数量)计算基础单价和包装单价
- (void)setUnitAndPackPrice{
    if (totalMoney.text.length > 0) {
        if (packageQuantity.text.length > 0 && [packageQuantity.text floatValue] > 0) {
Sandy's avatar
Sandy committed
601 602 603 604 605 606
            
//            float packagePrice = [self.totalPrice floatValue] / [packageQuantity.text floatValue];
            NSDecimalNumber *packagePrice = [CalculateHelper calculateNum1:self.totalPrice num2:packageQuantity.text type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:2];
            
            packageUnitPrice.text = packagePrice.stringValue;
            self.packPrice = packagePrice;
陈俊俊's avatar
陈俊俊 committed
607 608
        }
        if (foundationQuantity.text.length > 0 && [foundationQuantity.text floatValue] > 0) {
Sandy's avatar
Sandy committed
609 610 611 612
//            float packagePrice = [self.totalPrice floatValue] / [foundationQuantity.text floatValue];
            NSDecimalNumber *packagePrice = [CalculateHelper calculateNum1:self.totalPrice num2:foundationQuantity.text type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:2];
            foundationUnitPrice.text = packagePrice.stringValue;
            self.basePrice = packagePrice;
陈俊俊's avatar
陈俊俊 committed
613
        }
陈俊俊's avatar
陈俊俊 committed
614 615
    }
}
zhu's avatar
zhu committed
616 617
#pragma mark delegate
- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
陈俊俊's avatar
陈俊俊 committed
618
    [remark resignFirstResponder];
zhu's avatar
zhu committed
619 620 621
    return YES;
}
- (void)keyboardHidden{
陈俊俊's avatar
陈俊俊 committed
622
    [remark resignFirstResponder];
zhu's avatar
zhu committed
623 624 625 626 627 628 629 630
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
}

/*
陈俊俊's avatar
陈俊俊 committed
631 632 633 634 635 636 637 638
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
zhu's avatar
zhu committed
639 640

@end