TopPurchaseView.m 13.1 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"
15
#import "ChosePersonViewController.h"
陈俊俊's avatar
陈俊俊 committed
16
#import "Vendor.h"
17
#import "SurveyUser.h"
n22's avatar
n22 committed
18 19 20
#define LeftMargin 15
#define LeftWidth 80
#define SpaceHeight 10
陈俊俊's avatar
陈俊俊 committed
21 22
#define TopMargin 10
#define TableHeight 44
n22's avatar
n22 committed
23 24 25 26 27
@interface TopPurchaseView ()<UITableViewDataSource,UITableViewDelegate,HPGrowingTextViewDelegate,UITextFieldDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
}
陈俊俊's avatar
陈俊俊 committed
28 29 30 31
//选择的项目
@property (nonatomic,strong)NSString *selectType;
@property (nonatomic,strong)NSString *selectVendor;
@property (nonatomic,strong)NSString *selectWarehouse;
n22's avatar
n22 committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
@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];
Sandy's avatar
Sandy committed
50
    NSArray *arr = @[@"采购员:",@"类型:",@"供应商:",@"收货仓库:",@"其他费用:",@"总金额:",@"外部单据号:",@"备注:"];
n22's avatar
n22 committed
51 52 53 54 55 56 57
    [_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;
Sandy's avatar
Sandy committed
58
    
n22's avatar
n22 committed
59 60 61
    [self addSubview:_tableView];
}
#pragma mark - 协议方法
62 63 64 65 66 67 68
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 4) {
        return 0.01;
    }
    return 44;
}

n22's avatar
n22 committed
69 70 71 72 73 74 75 76 77 78 79 80 81
- (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;
82
        if (indexPath.row >= 0 && indexPath.row < 4) {
n22's avatar
n22 committed
83 84 85 86 87 88 89 90 91
            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
92
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight)];
n22's avatar
n22 committed
93
        textField.textAlignment = NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
94 95
        textField.textColor = GXF_CONTENT_COLOR;
        textField.font = GXF_FIFTEENTEN_SIZE;
96
        textField.keyboardType = UIKeyboardTypeDecimalPad;
n22's avatar
n22 committed
97 98 99
        textField.returnKeyType = UIReturnKeyDone;
        textField.delegate = self;
        [cell.contentView addSubview:textField];
n22's avatar
n22 committed
100
        self.otherPriceFiled = textField;
101 102
        self.otherPriceFiled.placeholder = @"其他费用";
        self.otherPriceFiled.enabled = NO;
陈俊俊's avatar
陈俊俊 committed
103
        [self.otherPriceFiled addTarget:self action:@selector(boxValueChanged:) forControlEvents:UIControlEventEditingChanged];
n22's avatar
n22 committed
104 105
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(textField.frame) + 5, 0, 20, TableHeight)];
        label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
106
        label.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
107
        label.font = GXF_FIFTEENTEN_SIZE;
108
        [cell.contentView removeAllSubViews];
n22's avatar
n22 committed
109
        [cell.contentView addSubview:label];
110
        cell.alpha = 0;
n22's avatar
n22 committed
111
        
Sandy's avatar
Sandy committed
112
    }else if ([_dataArr[indexPath.row] isEqualToString:@"备注:"]){
陈俊俊's avatar
陈俊俊 committed
113
        self.remarkTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight)];
n22's avatar
n22 committed
114 115
        self.remarkTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
        self.remarkTextView.minNumberOfLines = 1;
陈俊俊's avatar
陈俊俊 committed
116
        self.remarkTextView.maxNumberOfLines = 1;
陈俊俊's avatar
陈俊俊 committed
117
        self.remarkTextView.isScrollable = YES;
陈俊俊's avatar
陈俊俊 committed
118
        self.remarkTextView.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
119
        self.remarkTextView.textAlignment = NSTextAlignmentRight;
120
        self.remarkTextView.delegate = self;
n22's avatar
n22 committed
121 122
        self.remarkTextView.returnKeyType = UIReturnKeyDone;
        self.remarkTextView.placeholder = @"输入备注内容";
123
        
n22's avatar
n22 committed
124
        [cell.contentView addSubview:self.remarkTextView];
Sandy's avatar
Sandy committed
125 126 127 128 129 130 131 132 133
    }else if ([_dataArr[indexPath.row] isEqualToString:@"外部单据号:"]){
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight)];
        textField.textAlignment = NSTextAlignmentRight;
        textField.textColor = GXF_CONTENT_COLOR;
        textField.font = GXF_FIFTEENTEN_SIZE;
        textField.delegate = self;
        [cell.contentView addSubview:textField];
        self.purchaseExternal = textField;
        self.purchaseExternal.placeholder = @"输入外部单据号";
n22's avatar
n22 committed
134
    }else{
n22's avatar
n22 committed
135
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight))];
n22's avatar
n22 committed
136
        contentLabel.textAlignment= NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
137
        contentLabel.textColor = GXF_PLACEHOLDER_COLOR;
陈俊俊's avatar
陈俊俊 committed
138
        contentLabel.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
139 140
        [cell.contentView addSubview:contentLabel];
        if (indexPath.row == 0) {
141
            contentLabel.text = @"选择采购员";
Sandy's avatar
Sandy committed
142
            self.purchaserLabel = contentLabel;
n22's avatar
n22 committed
143 144 145 146 147 148 149 150
            
        }else if(indexPath.row == 1){
            contentLabel.text = @"选择类型";
            self.purchaseTypeLabel = contentLabel;
            
        }else if(indexPath.row == 2){
            contentLabel.text = @"选择供应商";
            self.purchaseSupplierLabel = contentLabel;
Sandy's avatar
Sandy committed
151 152
            self.purchaseTypeLabel.textColor = GXF_CONTENT_COLOR;
            self.purchaseTypeLabel.text = @"普通";
n22's avatar
n22 committed
153 154 155 156
            
        }else if(indexPath.row == 3){
            contentLabel.text = @"选择收货仓库";
            self.purchaseStoreLabel = contentLabel;
n22's avatar
n22 committed
157 158 159
        }else if(indexPath.row == 5){
            contentLabel.text = @"0";
            contentLabel.frame = CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight);
陈俊俊's avatar
陈俊俊 committed
160
            contentLabel.textColor = GXF_NAVIGAYION_COLOR;
n22's avatar
n22 committed
161 162 163
            self.purchasePriceLabel = contentLabel;
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(contentLabel.frame)+ 5, 0, 20, TableHeight)];
            label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
164
            label.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
165
            label.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
166
            [cell.contentView addSubview:label];
n22's avatar
n22 committed
167 168
        }
    }
陈俊俊's avatar
陈俊俊 committed
169 170
    [self prepareDataInCell];
}
陈俊俊's avatar
陈俊俊 committed
171 172 173
//赋值
- (void)setBill:(PurchaseBill *)bill{
    if (bill) {
Sandy's avatar
Sandy committed
174 175 176 177 178 179 180 181
        
        if (bill.purchaserName.length > 0) {
            self.selectPerson = [SurveyUser new];
            self.selectPerson.userCode = bill.purchaserCode;
            self.selectPerson.userName = bill.purchaserName;
            self.selectPerson.userUuid = bill.purchaserUuid;
            self.purchaserLabel.text = bill.purchaserName;
            self.purchaserLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
182 183 184 185 186 187
        }
        if (bill.type.length > 0) {
            NSString *type = [bill.type isEqualToString:GXF_Critical] ? @"紧急" : @"普通";
            self.purchaseTypeLabel.text = type;
            self.purchaseTypeLabel.textColor = GXF_CONTENT_COLOR;
            self.type = bill.type;
陈俊俊's avatar
陈俊俊 committed
188 189
            self.selectType = type;
            
陈俊俊's avatar
陈俊俊 committed
190 191 192 193 194 195 196
        }
        if (bill.vendor_name.length > 0) {
            self.purchaseSupplierLabel.text = [NSString stringWithFormat:@"%@[%@]",bill.vendor_name,bill.vendor_code];
            self.purchaseSupplierLabel.textColor = GXF_CONTENT_COLOR;
            self.vendor_uuid = bill.uuid;
            self.vendor_code = bill.vendor_code;
            self.vendor_name = bill.vendor_name;
陈俊俊's avatar
陈俊俊 committed
197
            self.selectVendor = bill.vendor_uuid;
陈俊俊's avatar
陈俊俊 committed
198 199 200 201
        }
        if (bill.receiveWrh_name.length > 0) {
            self.purchaseStoreLabel.text = [NSString stringWithFormat:@"%@[%@]",bill.receiveWrh_name,bill.receiveWrh_code];
            self.purchaseStoreLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
202

陈俊俊's avatar
陈俊俊 committed
203 204 205
            self.receiveWrh_uuid = bill.receiveWrh_uuid;
            self.receiveWrh_code = bill.receiveWrh_code;
            self.receiveWrh_name = bill.receiveWrh_name;
陈俊俊's avatar
陈俊俊 committed
206 207
            self.selectWarehouse = bill.receiveWrh_uuid;

陈俊俊's avatar
陈俊俊 committed
208 209 210 211 212 213 214 215 216
        }
        if (bill.charge) {
            self.otherPriceFiled.text = [bill.charge stringValue];
            self.chargePurchase = bill.charge;
        }
        if (bill.total) {
            self.purchasePriceLabel.text = [bill.total stringValue];
            self.total = bill.total;
        }
Sandy's avatar
Sandy committed
217 218
        
        self.purchaseExternal.text = bill.outSideBillNumber;
陈俊俊's avatar
陈俊俊 committed
219 220 221 222 223 224
        if (bill.remark.length > 0) {
            self.remarkTextView.text = bill.remark;
            self.remark = bill.remark;
        }
    }
}
陈俊俊's avatar
陈俊俊 committed
225 226 227 228
- (void)prepareDataInCell{
    if (self.total) {
        self.purchasePriceLabel.text = [self.total stringValue];
    }
陈俊俊's avatar
陈俊俊 committed
229
    if (self.noticeNumber.length > 0) {
Sandy's avatar
Sandy committed
230 231
        self.purchaserLabel.text = self.noticeNumber;
        self.purchaserLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
232
    }
n22's avatar
n22 committed
233
}
陈俊俊's avatar
陈俊俊 committed
234 235 236
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 2){
        ChooseVendorViewController *cvc = [ChooseVendorViewController new];
陈俊俊's avatar
陈俊俊 committed
237 238 239
        if (self.selectVendor.length > 0) {
            cvc.selectStr = self.selectVendor;
        }
陈俊俊's avatar
陈俊俊 committed
240
        cvc.choseBaseInfo = ^(NSArray *vendors){
陈俊俊's avatar
陈俊俊 committed
241 242
            if (vendors.count > 0) {
                Vendor *vendor = vendors[0];
n22's avatar
n22 committed
243
                self.purchaseSupplierLabel.text = [NSString stringWithFormat:@"%@[%@]",vendor.name,vendor.code];
陈俊俊's avatar
陈俊俊 committed
244
                self.purchaseSupplierLabel.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
245 246 247
                self.vendor_uuid = vendor.uuid;
                self.vendor_code = vendor.code;
                self.vendor_name = vendor.name;
陈俊俊's avatar
陈俊俊 committed
248
                self.selectVendor = vendor.uuid;
陈俊俊's avatar
陈俊俊 committed
249 250 251 252 253
            }
            
        };
        cvc.isMoreChose = NO;
        [self.delegate pushNextViewController:cvc];
n22's avatar
n22 committed
254 255
    }else if(indexPath.row == 1){
        ChooseTypeViewController *tvc = [[ChooseTypeViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
256 257 258
        if (self.selectType.length > 0) {
            tvc.selectStr = self.selectType;
        }
陈俊俊's avatar
陈俊俊 committed
259 260
        tvc.choseBaseInfo = ^(NSArray *types){
            NSString *type = types[0];
n22's avatar
n22 committed
261
            self.purchaseTypeLabel.text = type;
陈俊俊's avatar
陈俊俊 committed
262
            self.selectType = type;
陈俊俊's avatar
陈俊俊 committed
263
            self.purchaseTypeLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
264 265 266 267 268
            if ([type isEqualToString:@"紧急"]) {
                self.type = GXF_Critical;
            }else{
                self.type = GXF_Normal;
            }
n22's avatar
n22 committed
269 270 271 272
        };
        [self.delegate pushNextViewController:tvc];
    }else if(indexPath.row == 3){
        ChooseWarehouseViewController *wvc = [[ChooseWarehouseViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
273 274 275
        if (self.selectWarehouse.length > 0) {
            wvc.selectStr = self.selectWarehouse;
        }
陈俊俊's avatar
陈俊俊 committed
276 277
        wvc.choseBaseInfo = ^(NSArray *warehouses){
            Warehouse *warehouse = warehouses[0];
n22's avatar
n22 committed
278
            self.purchaseStoreLabel.text = [NSString stringWithFormat:@"%@[%@]",warehouse.name,warehouse.code];
陈俊俊's avatar
陈俊俊 committed
279
            self.purchaseStoreLabel.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
280 281 282
            self.receiveWrh_uuid = warehouse.uuid;
            self.receiveWrh_code = warehouse.code;
            self.receiveWrh_name = warehouse.name;
陈俊俊's avatar
陈俊俊 committed
283
            self.selectWarehouse = self.receiveWrh_uuid;
n22's avatar
n22 committed
284 285
        };
        [self.delegate pushNextViewController:wvc];
286 287 288 289 290 291
    }else if (indexPath.row == 0){
        
        ChosePersonViewController *cvc = [ChosePersonViewController new];
        cvc.choseBaseInfo = ^(NSArray *users){
            if(users.count == 1){
                self.selectPerson = users[0];
Sandy's avatar
Sandy committed
292 293
                self.purchaserLabel.text = _selectPerson.userName;
                self.purchaserLabel.textColor = GXF_CONTENT_COLOR;
294 295 296 297 298
            }
        };
        cvc.isMoreChose = NO;
        [self.delegate pushNextViewController:cvc];

陈俊俊's avatar
陈俊俊 committed
299 300
    }
}
Sandy's avatar
Sandy committed
301 302 303 304 305 306 307 308 309

- (NSString *)type {
    if ([self.purchaseTypeLabel.text isEqualToString:@"紧急"]) {
        _type = GXF_Critical;
    }else{
        _type = GXF_Normal;
    }
    return _type;
}
n22's avatar
n22 committed
310 311 312 313 314 315 316 317
- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
    [self.remarkTextView resignFirstResponder];
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.delegate hiddenKeyBoard];
    return YES;
}
n22's avatar
n22 committed
318 319 320
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.delegate hiddenKeyBoard];
}
陈俊俊's avatar
陈俊俊 committed
321 322 323

- (void)boxValueChanged:(UITextField *)textFiled{
        [[NSNotificationCenter defaultCenter] postNotificationName:SetProductTotalPrice object:nil];
n22's avatar
n22 committed
324
}
n22's avatar
n22 committed
325 326


n22's avatar
n22 committed
327
@end