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
//
// TransportProductViewController.m
// XFFruit
//
// Created by 陈俊俊 on 15/9/7.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "TransportProductViewController.h"
#import "FooterCell.h"
#import "HeaderCell.h"
#import "TransportCreateProductCell.h"
#import "TransportPdtDetail.h"
#import "GXFPopView.h"
#define TableHeight 44
#define ShowHeight 130
#define HeaderHeight 40
@interface TransportProductViewController ()
<UITableViewDataSource,UITableViewDelegate,FooterCellDelegate,HeaderCellDelegate,GXFPopViewDelegate>
{
CGRect _tableFrame;
NSMutableArray *_selectRowArr;//记录当前选中的cell
}
@property (nonatomic,strong)GXFPopView *popView;
//采购单号
@property (strong, nonatomic) NSMutableArray *arrBillNumber;
//按照采购单号区分之后的数据
@property (strong, nonatomic) NSMutableDictionary *dictData;
@end
@implementation TransportProductViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = XXFBgColor;
[self initData];
[self createView];
}
- (void)initData{
_selectRowArr = [[NSMutableArray alloc]init];
if (!self.transportProductArr) {
self.transportProductArr = [NSMutableArray array];
}
}
- (void)setTransportProductArr:(NSMutableArray *)transportProductArr {
_transportProductArr = transportProductArr;
[self convertData];
}
- (void)convertData {
self.arrBillNumber = [NSMutableArray array];
self.dictData = [NSMutableDictionary dictionary];
for (TransportPdtDetail *pdt in self.transportProductArr) {
if (![self.arrBillNumber containsObject:pdt.purchasebillnumber]) {
[self.arrBillNumber addObject:pdt.purchasebillnumber];
}
NSMutableArray *arrTemp = [self.dictData objectForKey:pdt.purchasebillnumber];
if (!arrTemp) {
arrTemp = [NSMutableArray array];
[self.dictData setObject:arrTemp forKey:pdt.purchasebillnumber];
}
[arrTemp addObject:pdt];
}
}
- (void)setViewFrame:(CGRect)viewFrame{
_viewFrame = viewFrame;
_tableFrame = viewFrame;
}
- (void)createView{
self.tableView = [[UITableView alloc]initWithFrame:_tableFrame style:(UITableViewStylePlain)];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:self.tableView];
NSArray *arr = @[@"商品",@"待收包装数",@"已收包装数"];
HeaderCell *headCell = [[HeaderCell alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 38) withArr:arr withHiddenEdit:self.isHiddenEdit];
[self.view addSubview:headCell];
headCell.delegate = self;
self.tableView.tableHeaderView = headCell;
// if (!self.isHiddenEdit) {
// FooterCell *footCell = [[FooterCell alloc]initWithFrame:CGRectMake(0, 0, _tableFrame.size.width, 50) withTitle:@"+点击添加商品明细" isTwo:self.twoTitle];
// [self.view addSubview:footCell];
// footCell.delegate = self;
// self.tableView.tableFooterView = footCell;
// }
}
#pragma mark - headCellDelegate
- (void)addClickList{
if (!self.popView) {
// NSArray *arr = @[@"添加商品明细",@"选择采购单"];
NSArray *arr = @[@"选择采购单"];
self.popView = [[GXFPopView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, ScreenSize.height) withArr:arr];
self.popView.delegate = self;
[AppWindow addSubview:self.popView];
}
}
#pragma mark - popViewdelegate
- (void)selectRowTitle:(NSString *)str{
if (self.popView) {
[self.popView removeFromSuperview];
self.popView= nil;
}
if ([str isEqualToString:@"添加商品明细"]) {
[[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_AddPurchaseProduct object:nil];
}else if([str isEqualToString:@"选择采购单"]){
[[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_ChoseTransportPurchase object:nil];
}
}
- (void)clearFromSuper{
if (self.popView) {
[self.popView removeFromSuperview];
self.popView = nil;
}
}
#pragma mark - footerDelegate
- (void)addClick{
[[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_AddPurchaseProduct object:nil];
}
- (void)editClick:(UIButton *)btn{
NSInteger section = btn.tag / 1000;
NSInteger row = btn.tag % 1000;
NSMutableArray *arrSection = [self.dictData objectForKey:self.arrBillNumber[section]];
TransportPdtDetail *pdDetail = arrSection[row];
NSInteger index = [self.transportProductArr indexOfObject:pdDetail];
[[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_AddPurchaseProduct object:nil userInfo:@{@"transportPdtDetail":pdDetail,@"indexTag":@(index)}];
}
- (void)refresh {
[self convertData];
[self.tableView reloadData];
}
- (void)choosePurchase{
[[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_ChoseTransportPurchase object:nil];
}
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.arrBillNumber.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return HeaderHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenSize.width, HeaderHeight)];
header.backgroundColor = [UIColor whiteColor];
UILabel *transportBillNumber = [[UILabel alloc] initWithFrame:CGRectMake(16, 0, 250, HeaderHeight)];
[header addSubview:transportBillNumber];
transportBillNumber.text = [NSString stringWithFormat:@"[采购单:%@]",
self.arrBillNumber[section]];
transportBillNumber.textColor = GXF_GREEN_COLOR;
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, HeaderHeight - 1, IBT_MAIN_SCREEN_WIDTH, 1)];
line.backgroundColor = [UIColor colorWithWhite:0.835 alpha:1.000];
[header addSubview:line];
//删除按钮
UIButton *btnDelete = [UIButton buttonWithType:UIButtonTypeCustom];
btnDelete.frame = CGRectMake(IBT_MAIN_SCREEN_WIDTH - 16 - 30, (HeaderHeight - 30)/2, 30, 30);
[btnDelete setImage:[UIImage imageNamed:@"xf_delete_pic"] forState:UIControlStateNormal];
[header addSubview:btnDelete];
btnDelete.tag = section;
[btnDelete addTarget:self action:@selector(actionDeleteBillNumber:) forControlEvents:UIControlEventTouchUpInside];
return header;
}
- (void)actionDeleteBillNumber:(UIButton *)btn {
NSString *billNumber = self.arrBillNumber[btn.tag];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"确认删除该采购单%@下的商品?", billNumber] preferredStyle:(UIAlertControllerStyleAlert)];
UIAlertAction *actionYes = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action) {
[[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_DeleteTransportPdtInPurchase object:billNumber];
}];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:nil];
[alert addAction:actionYes];
[alert addAction:actionCancel];
[self presentViewController:alert animated:YES completion:nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSMutableArray *arrSection = [self.dictData objectForKey:self.arrBillNumber[section]];
return arrSection.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"TransportPurductCell";
TransportCreateProductCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[TransportCreateProductCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID withImageName:@"edit"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (self.isHiddenEdit) {
cell.editBtn.hidden = YES;
}
}
if ([self isHaveIndexPath:indexPath]) {
cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];
CGRect Linefrmame = cell.lineLabel.frame;
Linefrmame.origin.y = ShowHeight + TableHeight -1;
cell.lineLabel.frame = Linefrmame;
CGRect showfrmame = cell.showView.frame;
showfrmame.size.height = ShowHeight;
cell.showView.frame = showfrmame;
cell.backgroundColor = XXFBgColor;
}else{
cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
CGRect Linefrmame = cell.lineLabel.frame;
Linefrmame.origin.y = TableHeight-1;
cell.lineLabel.frame = Linefrmame;
CGRect showfrmame = cell.showView.frame;
showfrmame.size.height = 0;
cell.showView.frame = showfrmame;
cell.backgroundColor = [UIColor whiteColor];
}
cell.editBtn.tag = indexPath.section * 1000 + indexPath.row;
[cell.editBtn addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventTouchUpInside];
NSMutableArray *arrSection = [self.dictData objectForKey:self.arrBillNumber[indexPath.section]];
if (arrSection.count > 0) {
TransportPdtDetail *billP = arrSection[indexPath.row];
[cell setPdtDetail:billP row:indexPath.row];
}
return cell;
}
- (BOOL)isHaveIndexPath:(NSIndexPath *)indexPath{
for (NSIndexPath *path in _selectRowArr) {
if (path.row == indexPath.row && path.section == indexPath.section) {
return YES;
}
}
return NO;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TransportCreateProductCell *cell = (TransportCreateProductCell *)[tableView cellForRowAtIndexPath:indexPath];
CGRect Linefrmame = cell.lineLabel.frame;
CGRect showfrmame = cell.showView.frame;
if (Linefrmame.origin.y == TableHeight - 1) {
cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];
Linefrmame.origin.y = ShowHeight + TableHeight - 1;
showfrmame.size.height = ShowHeight;
cell.backgroundColor = [UIColor whiteColor];
[_selectRowArr addObject:indexPath];
}else{
cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
Linefrmame.origin.y = TableHeight -1;
showfrmame.size.height = 0;
cell.backgroundColor = [UIColor whiteColor];
[_selectRowArr removeObject:indexPath];
}
cell.lineLabel.frame = Linefrmame;
cell.showView.frame = showfrmame;
[self.tableView reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([self isHaveIndexPath:indexPath]) {
return ShowHeight + TableHeight;
}
return TableHeight;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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.
}
*/
@end