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
//
// InviterViewController.m
// Lighting
//
// Created by 曹云霄 on 2017/7/25.
// Copyright © 2017年 上海勾芒科技有限公司. All rights reserved.
//
#import "InviterViewController.h"
#import "InviterTableViewCell.h"
#import "CustomVDesignerEntity.h"
@interface InviterViewController ()
/**
邀请人
*/
@property (nonatomic,strong) NSMutableArray *inviterArray;
/**
搜索显示邀请人
*/
@property (nonatomic,strong) NSArray *displayArray;
/**
选中邀请人
*/
@property (nonatomic,strong) NSIndexPath *indexPath;
@end
@implementation InviterViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
#pragma mark -下拉刷新
- (void)loadWebDataSource
{
WS(weakSelf);
[self.inviterArray removeAllObjects];
self.displayArray = @[];
[self getInviterListcompleted:^(DesignerPageResult *result) {
if (weakSelf.pullPageIndex >= result.totalpages) {
[weakSelf endRefresh:EndRefreshNotData];
}else {
[weakSelf endRefresh:EndRefreshDefault];
}
}];
}
#pragma mark -请求数据
- (void)getInviterListcompleted:(void(^)(DesignerPageResult *result))completed
{
WS(weakSelf);
NSString *urlString = [NSString stringWithFormat:SERVERREQUESTURL(GETINVITER),[Shoppersmanager manager].shoppers.employee.currentDepart.fid];
[HTTP networkRequestWithURL:urlString withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
if (RESULT(returnValue)) {
DesignerPageResult *customerResult = [[DesignerPageResult alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
completed(customerResult);
for (VDesignerEntity *objc in customerResult.results) {
CustomVDesignerEntity *entity = [[CustomVDesignerEntity alloc] initWithDictionary:[objc toDictionary] error:nil];
[weakSelf.inviterArray addObject:entity];
}
weakSelf.displayArray = [NSMutableArray arrayWithArray:weakSelf.inviterArray];
[weakSelf.tableView reloadData];
}
else
{
[XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
}
}withFailureBlock:^(NSError *error) {
[weakSelf endRefresh:EndRefreshDefault];
[XBLoadingView showHUDViewWithText:error.localizedDescription];
}];
}
#pragma mark -取消
- (IBAction)cancelButtonItemClickAction:(UIBarButtonItem *)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark -确认
- (IBAction)sureButtonItemClickAction:(UIBarButtonItem *)sender {
if (!self.indexPath) {
return;
}
[self dismissViewControllerAnimated:YES completion:nil];
if (self.selectedBlock) {
self.selectedBlock(self.displayArray[self.indexPath.row]);
}
}
#pragma mark - searchbar delegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
searchBar.showsCancelButton = YES;
return YES;
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
searchBar.showsCancelButton = NO;
searchBar.text = nil;
[[UIApplication sharedApplication].keyWindow endEditing:YES];
self.displayArray = [NSArray arrayWithArray:self.inviterArray];
[self.tableView reloadData];
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSPredicate *pred = [NSPredicate predicateWithFormat:@"realName contains [cd] %@ OR userName contains [cd] %@", searchText, searchText];
self.displayArray = [self.inviterArray filteredArrayUsingPredicate:pred];
if (searchText.length < 1) {
self.displayArray = [NSArray arrayWithArray:self.inviterArray];
}
[self.tableView reloadData];
}
#pragma mark -<UITableVieDelegate,UITableVieDataSource>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
InviterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InviterTableViewCell" forIndexPath:indexPath];
cell.entity = self.displayArray[indexPath.row];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.displayArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
for (InviterTableViewCell *cell in tableView.visibleCells) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
for (CustomVDesignerEntity *entity in self.inviterArray) {
entity.selectedState = NO;
}
CustomVDesignerEntity *entity = self.inviterArray[indexPath.row];
InviterTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
entity.selectedState = YES;
self.indexPath = indexPath;
}
#pragma mark -lazy
- (NSMutableArray *)inviterArray
{
if (!_inviterArray) {
_inviterArray = [NSMutableArray array];
}
return _inviterArray;
}
@end