TopPurchaseView.m 8.16 KB
Newer Older
n22's avatar
n22 committed
1 2 3 4 5 6 7 8 9 10 11
//
//  TopPurchaseView.m
//  XFFruit
//
//  Created by n22 on 15/8/21.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "TopPurchaseView.h"

#import "SurveyCell.h"
陈俊俊's avatar
陈俊俊 committed
12
#import "ChooseVendorViewController.h"
n22's avatar
n22 committed
13 14
#import "ChooseTypeViewController.h"
#import "ChooseWarehouseViewController.h"
陈俊俊's avatar
陈俊俊 committed
15
#import "Vendor.h"
n22's avatar
n22 committed
16 17 18 19 20
#define LeftMargin 15
#define TopMargin 20
#define LeftWidth 80
#define TableHeight 44
#define SpaceHeight 10
陈俊俊's avatar
陈俊俊 committed
21
#define TitleSize 15
n22's avatar
n22 committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

@interface TopPurchaseView ()<UITableViewDataSource,UITableViewDelegate,HPGrowingTextViewDelegate,UITextFieldDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
}
@end


@implementation TopPurchaseView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //界面
        [self bulidLayout];
    }
    return self;
}

#pragma mark - 布局
- (void)bulidLayout
{
    self.backgroundColor  = XXFBgColor;
    _dataArr = [NSMutableArray array];
n22's avatar
n22 committed
46
    NSArray *arr = @[@"采购通知:",@"类型:",@"供应商:",@"收货仓库:",@"其他费用:",@"总金额:",@"备注:"];
n22's avatar
n22 committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    [_dataArr addObjectsFromArray:arr];
    
    _tableView = [[UITableView alloc]initWithFrame:(CGRectMake(0, TopMargin,self.frame.size.width, self.frame.size.height - TopMargin)) style:(UITableViewStylePlain)];
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.bounces = NO;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self addSubview:_tableView];
}
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}
- (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;
n22's avatar
n22 committed
70
        if (indexPath.row > 0 && indexPath.row < 4) {
n22's avatar
n22 committed
71 72 73 74 75 76 77 78 79
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        [self createViewInCell:cell indexPath:indexPath];
    }
    [cell setTitleStr:_dataArr[indexPath.row]];
    return cell;
}
-  (void)createViewInCell:(SurveyCell *)cell indexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 4 ) {
n22's avatar
n22 committed
80
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight)];
n22's avatar
n22 committed
81
        textField.textAlignment = NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
82 83
        textField.textColor = GXF_CONTENT_COLOR;
        textField.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
84
        textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
n22's avatar
n22 committed
85 86 87
        textField.returnKeyType = UIReturnKeyDone;
        textField.delegate = self;
        [cell.contentView addSubview:textField];
n22's avatar
n22 committed
88 89 90 91
        self.otherPriceFiled = textField;
        self.otherPriceFiled.placeholder = @"请输入其他费用";
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(textField.frame) + 5, 0, 20, TableHeight)];
        label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
92
        label.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
93 94
        label.font = FontSize(TitleSize);
        [cell.contentView addSubview:label];
n22's avatar
n22 committed
95 96
        
    }else if (indexPath.row == _dataArr.count -1){
n22's avatar
n22 committed
97
        self.remarkTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight)];
n22's avatar
n22 committed
98 99 100
        self.remarkTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
        self.remarkTextView.minNumberOfLines = 1;
        self.remarkTextView.maxNumberOfLines = 2;
陈俊俊's avatar
陈俊俊 committed
101
        self.remarkTextView.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
102 103 104 105 106 107
        self.remarkTextView.textAlignment = NSTextAlignmentRight;
        self.remarkTextView.delegate = self;
        self.remarkTextView.returnKeyType = UIReturnKeyDone;
        self.remarkTextView.placeholder = @"输入备注内容";
        [cell.contentView addSubview:self.remarkTextView];
    }else{
n22's avatar
n22 committed
108
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight))];
n22's avatar
n22 committed
109
        contentLabel.textAlignment= NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
110
        contentLabel.textColor = GXF_PLACEHOLDER_COLOR;
n22's avatar
n22 committed
111 112 113
        contentLabel.font = FontSize(TitleSize);
        [cell.contentView addSubview:contentLabel];
        if (indexPath.row == 0) {
n22's avatar
n22 committed
114
            contentLabel.text = @"采购通知单号";
n22's avatar
n22 committed
115 116 117 118 119 120 121 122 123 124 125 126 127
            self.purchaseNoticeLabel = contentLabel;
            
        }else if(indexPath.row == 1){
            contentLabel.text = @"选择类型";
            self.purchaseTypeLabel = contentLabel;
            
        }else if(indexPath.row == 2){
            contentLabel.text = @"选择供应商";
            self.purchaseSupplierLabel = contentLabel;
            
        }else if(indexPath.row == 3){
            contentLabel.text = @"选择收货仓库";
            self.purchaseStoreLabel = contentLabel;
n22's avatar
n22 committed
128 129 130 131 132 133 134
        }else if(indexPath.row == 5){
            contentLabel.text = @"0";
            contentLabel.frame = CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight);
            contentLabel.textColor = [UIColor redColor];
            self.purchasePriceLabel = contentLabel;
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(contentLabel.frame)+ 5, 0, 20, TableHeight)];
            label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
135
            label.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
136 137 138
            label.font = FontSize(TitleSize);
            [cell.contentView addSubview:label];

n22's avatar
n22 committed
139 140 141
        }
    }
}
陈俊俊's avatar
陈俊俊 committed
142 143 144
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 2){
        ChooseVendorViewController *cvc = [ChooseVendorViewController new];
n22's avatar
n22 committed
145
        cvc.title = @"供应商";
陈俊俊's avatar
陈俊俊 committed
146 147 148
        cvc.choseVendor = ^(NSArray *vendors){
            if (vendors.count > 0) {
                Vendor *vendor = vendors[0];
n22's avatar
n22 committed
149
                self.purchaseSupplierLabel.text = [NSString stringWithFormat:@"%@[%@]",vendor.name,vendor.code];
陈俊俊's avatar
陈俊俊 committed
150
                self.purchaseSupplierLabel.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
151 152 153
                self.vendor_uuid = vendor.uuid;
                self.vendor_code = vendor.code;
                self.vendor_name = vendor.name;
陈俊俊's avatar
陈俊俊 committed
154 155 156 157 158
            }
            
        };
        cvc.isMoreChose = NO;
        [self.delegate pushNextViewController:cvc];
n22's avatar
n22 committed
159 160 161
    }else if(indexPath.row == 1){
        ChooseTypeViewController *tvc = [[ChooseTypeViewController alloc]init];
        tvc.title = @"类型";
n22's avatar
n22 committed
162
        tvc.dataArr = @[@"普通",@"紧急"];
n22's avatar
n22 committed
163 164
        tvc.choseType = ^(NSString *type){
            self.purchaseTypeLabel.text = type;
陈俊俊's avatar
陈俊俊 committed
165
            self.purchaseTypeLabel.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
166
            self.type = type;
n22's avatar
n22 committed
167 168 169 170 171 172 173
        };
        [self.delegate pushNextViewController:tvc];
    }else if(indexPath.row == 3){
        ChooseWarehouseViewController *wvc = [[ChooseWarehouseViewController alloc]init];
        wvc.title = @"仓库";
        wvc.choseWarehouse = ^(Warehouse *warehouse){
            self.purchaseStoreLabel.text = [NSString stringWithFormat:@"%@[%@]",warehouse.name,warehouse.code];
陈俊俊's avatar
陈俊俊 committed
174
            self.purchaseStoreLabel.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
175 176 177
            self.receiveWrh_uuid = warehouse.uuid;
            self.receiveWrh_code = warehouse.code;
            self.receiveWrh_name = warehouse.name;
n22's avatar
n22 committed
178 179
        };
        [self.delegate pushNextViewController:wvc];
陈俊俊's avatar
陈俊俊 committed
180 181
    }
}
n22's avatar
n22 committed
182 183 184 185 186 187 188 189
- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
    [self.remarkTextView resignFirstResponder];
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.delegate hiddenKeyBoard];
    return YES;
}
n22's avatar
n22 committed
190 191 192
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.delegate hiddenKeyBoard];
}
n22's avatar
n22 committed
193 194 195 196 197 198 199
- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField == self.otherPriceFiled) {
        if (self.otherPriceFiled.text.length > 0) {
            [[NSNotificationCenter defaultCenter] postNotificationName:SetProductTotalPrice object:nil];
        }
    }
}
n22's avatar
n22 committed
200 201


n22's avatar
n22 committed
202 203

@end