1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
//
// TopPurchaseView.m
// XFFruit
//
// Created by n22 on 15/8/21.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "TopPurchaseView.h"
#import "SurveyCell.h"
#import "ChooseVendorViewController.h"
#import "ChooseTypeViewController.h"
#import "ChooseWarehouseViewController.h"
#import "ChosePersonViewController.h"
#import "Vendor.h"
#import "SurveyUser.h"
#define LeftMargin 15
#define LeftWidth 80
#define SpaceHeight 10
#define TopMargin 10
#define TableHeight 44
@interface TopPurchaseView ()<UITableViewDataSource,UITableViewDelegate,HPGrowingTextViewDelegate,UITextFieldDelegate>
{
UITableView *_tableView;
NSMutableArray *_dataArr;
}
//选择的项目
@property (nonatomic,strong)NSString *selectType;
@property (nonatomic,strong)NSString *selectVendor;
@property (nonatomic,strong)NSString *selectWarehouse;
@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];
NSArray *arr = @[@"采购员:",@"类型:",@"供应商:",@"收货仓库:",@"其他费用:",@"总金额:",@"外部单据号:",@"备注:"];
[_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 - 协议方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 4) {
return 0.01;
}
return 44;
}
- (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;
if (indexPath.row >= 0 && indexPath.row < 4) {
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 ) {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight)];
textField.textAlignment = NSTextAlignmentRight;
textField.textColor = GXF_CONTENT_COLOR;
textField.font = GXF_FIFTEENTEN_SIZE;
textField.keyboardType = UIKeyboardTypeDecimalPad;
textField.returnKeyType = UIReturnKeyDone;
textField.delegate = self;
[cell.contentView addSubview:textField];
self.otherPriceFiled = textField;
self.otherPriceFiled.placeholder = @"其他费用";
self.otherPriceFiled.enabled = NO;
[self.otherPriceFiled addTarget:self action:@selector(boxValueChanged:) forControlEvents:UIControlEventEditingChanged];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(textField.frame) + 5, 0, 20, TableHeight)];
label.text = @"元";
label.textColor = GXF_CONTENT_COLOR;
label.font = GXF_FIFTEENTEN_SIZE;
[cell.contentView removeAllSubViews];
[cell.contentView addSubview:label];
cell.alpha = 0;
}else if ([_dataArr[indexPath.row] isEqualToString:@"备注:"]){
self.remarkTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight)];
self.remarkTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
self.remarkTextView.minNumberOfLines = 1;
self.remarkTextView.maxNumberOfLines = 1;
self.remarkTextView.isScrollable = YES;
self.remarkTextView.font = GXF_FIFTEENTEN_SIZE;
self.remarkTextView.textAlignment = NSTextAlignmentRight;
self.remarkTextView.delegate = self;
self.remarkTextView.returnKeyType = UIReturnKeyDone;
self.remarkTextView.placeholder = @"输入备注内容";
[cell.contentView addSubview:self.remarkTextView];
}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 = @"输入外部单据号";
}else{
UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight))];
contentLabel.textAlignment= NSTextAlignmentRight;
contentLabel.textColor = GXF_PLACEHOLDER_COLOR;
contentLabel.font = GXF_FIFTEENTEN_SIZE;
[cell.contentView addSubview:contentLabel];
if (indexPath.row == 0) {
contentLabel.text = @"选择采购员";
self.purchaserLabel = contentLabel;
}else if(indexPath.row == 1){
contentLabel.text = @"选择类型";
self.purchaseTypeLabel = contentLabel;
}else if(indexPath.row == 2){
contentLabel.text = @"选择供应商";
self.purchaseSupplierLabel = contentLabel;
self.purchaseTypeLabel.textColor = GXF_CONTENT_COLOR;
self.purchaseTypeLabel.text = @"普通";
}else if(indexPath.row == 3){
contentLabel.text = @"选择收货仓库";
self.purchaseStoreLabel = contentLabel;
}else if(indexPath.row == 5){
contentLabel.text = @"0";
contentLabel.frame = CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight);
contentLabel.textColor = GXF_NAVIGAYION_COLOR;
self.purchasePriceLabel = contentLabel;
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(contentLabel.frame)+ 5, 0, 20, TableHeight)];
label.text = @"元";
label.textColor = GXF_CONTENT_COLOR;
label.font = GXF_FIFTEENTEN_SIZE;
[cell.contentView addSubview:label];
}
}
[self prepareDataInCell];
}
//赋值
- (void)setBill:(PurchaseBill *)bill{
if (bill) {
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;
}
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;
self.selectType = type;
}
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;
self.selectVendor = bill.vendor_uuid;
}
if (bill.receiveWrh_name.length > 0) {
self.purchaseStoreLabel.text = [NSString stringWithFormat:@"%@[%@]",bill.receiveWrh_name,bill.receiveWrh_code];
self.purchaseStoreLabel.textColor = GXF_CONTENT_COLOR;
self.receiveWrh_uuid = bill.receiveWrh_uuid;
self.receiveWrh_code = bill.receiveWrh_code;
self.receiveWrh_name = bill.receiveWrh_name;
self.selectWarehouse = bill.receiveWrh_uuid;
}
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;
}
self.purchaseExternal.text = bill.outSideBillNumber;
if (bill.remark.length > 0) {
self.remarkTextView.text = bill.remark;
self.remark = bill.remark;
}
}
}
- (void)prepareDataInCell{
if (self.total) {
self.purchasePriceLabel.text = [self.total stringValue];
}
if (self.noticeNumber.length > 0) {
self.purchaserLabel.text = self.noticeNumber;
self.purchaserLabel.textColor = GXF_CONTENT_COLOR;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row == 2){
ChooseVendorViewController *cvc = [ChooseVendorViewController new];
if (self.selectVendor.length > 0) {
cvc.selectStr = self.selectVendor;
}
cvc.choseBaseInfo = ^(NSArray *vendors){
if (vendors.count > 0) {
Vendor *vendor = vendors[0];
self.purchaseSupplierLabel.text = [NSString stringWithFormat:@"%@[%@]",vendor.name,vendor.code];
self.purchaseSupplierLabel.textColor = GXF_CONTENT_COLOR;
self.vendor_uuid = vendor.uuid;
self.vendor_code = vendor.code;
self.vendor_name = vendor.name;
self.selectVendor = vendor.uuid;
}
};
cvc.isMoreChose = NO;
[self.delegate pushNextViewController:cvc];
}else if(indexPath.row == 1){
ChooseTypeViewController *tvc = [[ChooseTypeViewController alloc]init];
if (self.selectType.length > 0) {
tvc.selectStr = self.selectType;
}
tvc.choseBaseInfo = ^(NSArray *types){
NSString *type = types[0];
self.purchaseTypeLabel.text = type;
self.selectType = type;
self.purchaseTypeLabel.textColor = GXF_CONTENT_COLOR;
if ([type isEqualToString:@"紧急"]) {
self.type = GXF_Critical;
}else{
self.type = GXF_Normal;
}
};
[self.delegate pushNextViewController:tvc];
}else if(indexPath.row == 3){
ChooseWarehouseViewController *wvc = [[ChooseWarehouseViewController alloc]init];
if (self.selectWarehouse.length > 0) {
wvc.selectStr = self.selectWarehouse;
}
wvc.choseBaseInfo = ^(NSArray *warehouses){
Warehouse *warehouse = warehouses[0];
self.purchaseStoreLabel.text = [NSString stringWithFormat:@"%@[%@]",warehouse.name,warehouse.code];
self.purchaseStoreLabel.textColor = GXF_CONTENT_COLOR;
self.receiveWrh_uuid = warehouse.uuid;
self.receiveWrh_code = warehouse.code;
self.receiveWrh_name = warehouse.name;
self.selectWarehouse = self.receiveWrh_uuid;
};
[self.delegate pushNextViewController:wvc];
}else if (indexPath.row == 0){
ChosePersonViewController *cvc = [ChosePersonViewController new];
cvc.choseBaseInfo = ^(NSArray *users){
if(users.count == 1){
self.selectPerson = users[0];
self.purchaserLabel.text = _selectPerson.userName;
self.purchaserLabel.textColor = GXF_CONTENT_COLOR;
}
};
cvc.isMoreChose = NO;
[self.delegate pushNextViewController:cvc];
}
}
- (NSString *)type {
if ([self.purchaseTypeLabel.text isEqualToString:@"紧急"]) {
_type = GXF_Critical;
}else{
_type = GXF_Normal;
}
return _type;
}
- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
[self.remarkTextView resignFirstResponder];
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[self.delegate hiddenKeyBoard];
return YES;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self.delegate hiddenKeyBoard];
}
- (void)boxValueChanged:(UITextField *)textFiled{
[[NSNotificationCenter defaultCenter] postNotificationName:SetProductTotalPrice object:nil];
}
@end